blob: 19d0a1069a03b16ee001ed22593a535213e462d7 [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 }
Rene Lindsayacbf5e62016-12-15 18:47:11 -0700473 // Viewport and scissors must stay in sync or other errors will occur than
Karl Schultz6addd812016-02-02 17:17:23 -0700474 // 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;
Rene Lindsayd14f5572016-12-16 14:57:18 -07001347 VkMemoryRequirements buff_mem_reqs2, img_mem_reqs2;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001348
1349 VkBufferCreateInfo buf_info = {};
1350 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1351 buf_info.pNext = NULL;
1352 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
1353 buf_info.size = 256;
1354 buf_info.queueFamilyIndexCount = 0;
1355 buf_info.pQueueFamilyIndices = NULL;
1356 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1357 buf_info.flags = 0;
1358 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1359 ASSERT_VK_SUCCESS(err);
1360
Tobin Ehlis077ded32016-05-12 17:39:13 -06001361 vkGetBufferMemoryRequirements(m_device->device(), buffer, &buff_mem_reqs);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001362
1363 VkImageCreateInfo image_create_info = {};
1364 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1365 image_create_info.pNext = NULL;
1366 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1367 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
1368 image_create_info.extent.width = 64;
1369 image_create_info.extent.height = 64;
1370 image_create_info.extent.depth = 1;
1371 image_create_info.mipLevels = 1;
1372 image_create_info.arrayLayers = 1;
1373 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehlis12a4b5e2016-08-08 12:33:11 -06001374 // Image tiling must be optimal to trigger error when aliasing linear buffer
1375 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001376 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
1377 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
1378 image_create_info.queueFamilyIndexCount = 0;
1379 image_create_info.pQueueFamilyIndices = NULL;
1380 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1381 image_create_info.flags = 0;
1382
Tobin Ehlisf11be982016-05-11 13:52:53 -06001383 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1384 ASSERT_VK_SUCCESS(err);
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001385 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image2);
1386 ASSERT_VK_SUCCESS(err);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001387
Tobin Ehlis077ded32016-05-12 17:39:13 -06001388 vkGetImageMemoryRequirements(m_device->device(), image, &img_mem_reqs);
1389
1390 VkMemoryAllocateInfo alloc_info = {};
1391 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1392 alloc_info.pNext = NULL;
1393 alloc_info.memoryTypeIndex = 0;
1394 // Ensure memory is big enough for both bindings
1395 alloc_info.allocationSize = buff_mem_reqs.size + img_mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001396 pass = m_device->phy().set_memory_type(buff_mem_reqs.memoryTypeBits & img_mem_reqs.memoryTypeBits, &alloc_info,
1397 VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001398 if (!pass) {
Tobin Ehlis077ded32016-05-12 17:39:13 -06001399 vkDestroyBuffer(m_device->device(), buffer, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001400 vkDestroyImage(m_device->device(), image, NULL);
1401 return;
1402 }
Tobin Ehlis077ded32016-05-12 17:39:13 -06001403 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
1404 ASSERT_VK_SUCCESS(err);
1405 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
1406 ASSERT_VK_SUCCESS(err);
1407
Rene Lindsayd14f5572016-12-16 14:57:18 -07001408 vkGetImageMemoryRequirements(m_device->device(), image2, &img_mem_reqs2);
1409
Tobin Ehlis32b2bbc2016-12-13 17:33:41 -07001410 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, " is aliased with linear buffer 0x");
Tobin Ehlis077ded32016-05-12 17:39:13 -06001411 // VALIDATION FAILURE due to image mapping overlapping buffer mapping
Tobin Ehlisf11be982016-05-11 13:52:53 -06001412 err = vkBindImageMemory(m_device->device(), image, mem, 0);
1413 m_errorMonitor->VerifyFound();
1414
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001415 // Now correctly bind image2 to second mem allocation before incorrectly
Tobin Ehlis077ded32016-05-12 17:39:13 -06001416 // aliasing buffer2
1417 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer2);
1418 ASSERT_VK_SUCCESS(err);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001419 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem_img);
1420 ASSERT_VK_SUCCESS(err);
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001421 err = vkBindImageMemory(m_device->device(), image2, mem_img, 0);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001422 ASSERT_VK_SUCCESS(err);
Tobin Ehlis32b2bbc2016-12-13 17:33:41 -07001423 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "is aliased with non-linear image 0x");
Rene Lindsayd14f5572016-12-16 14:57:18 -07001424 vkGetBufferMemoryRequirements(m_device->device(), buffer2, &buff_mem_reqs2);
Tobin Ehlis077ded32016-05-12 17:39:13 -06001425 err = vkBindBufferMemory(m_device->device(), buffer2, mem_img, 0);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001426 m_errorMonitor->VerifyFound();
1427
1428 vkDestroyBuffer(m_device->device(), buffer, NULL);
Tobin Ehlis077ded32016-05-12 17:39:13 -06001429 vkDestroyBuffer(m_device->device(), buffer2, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001430 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001431 vkDestroyImage(m_device->device(), image2, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001432 vkFreeMemory(m_device->device(), mem, NULL);
1433 vkFreeMemory(m_device->device(), mem_img, NULL);
1434}
1435
Tobin Ehlis35372522016-05-12 08:32:31 -06001436TEST_F(VkLayerTest, InvalidMemoryMapping) {
1437 TEST_DESCRIPTION("Attempt to map memory in a number of incorrect ways");
1438 VkResult err;
1439 bool pass;
1440 ASSERT_NO_FATAL_FAILURE(InitState());
1441
1442 VkBuffer buffer;
1443 VkDeviceMemory mem;
1444 VkMemoryRequirements mem_reqs;
1445
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001446 const VkDeviceSize atom_size = m_device->props.limits.nonCoherentAtomSize;
1447
Tobin Ehlis35372522016-05-12 08:32:31 -06001448 VkBufferCreateInfo buf_info = {};
1449 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1450 buf_info.pNext = NULL;
1451 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
1452 buf_info.size = 256;
1453 buf_info.queueFamilyIndexCount = 0;
1454 buf_info.pQueueFamilyIndices = NULL;
1455 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1456 buf_info.flags = 0;
1457 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1458 ASSERT_VK_SUCCESS(err);
1459
1460 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
1461 VkMemoryAllocateInfo alloc_info = {};
1462 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1463 alloc_info.pNext = NULL;
1464 alloc_info.memoryTypeIndex = 0;
1465
1466 // Ensure memory is big enough for both bindings
1467 static const VkDeviceSize allocation_size = 0x10000;
1468 alloc_info.allocationSize = allocation_size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001469 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 -06001470 if (!pass) {
1471 vkDestroyBuffer(m_device->device(), buffer, NULL);
1472 return;
1473 }
1474 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
1475 ASSERT_VK_SUCCESS(err);
1476
1477 uint8_t *pData;
1478 // Attempt to map memory size 0 is invalid
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001479 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 -06001480 err = vkMapMemory(m_device->device(), mem, 0, 0, 0, (void **)&pData);
1481 m_errorMonitor->VerifyFound();
1482 // Map memory twice
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001483 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001484 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001485 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1486 "VkMapMemory: Attempting to map memory on an already-mapped object ");
1487 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001488 m_errorMonitor->VerifyFound();
1489
1490 // Unmap the memory to avoid re-map error
1491 vkUnmapMemory(m_device->device(), mem);
1492 // overstep allocation with VK_WHOLE_SIZE
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001493 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1494 " with size of VK_WHOLE_SIZE oversteps total array size 0x");
1495 err = vkMapMemory(m_device->device(), mem, allocation_size + 1, VK_WHOLE_SIZE, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001496 m_errorMonitor->VerifyFound();
1497 // overstep allocation w/o VK_WHOLE_SIZE
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001498 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " oversteps total array size 0x");
1499 err = vkMapMemory(m_device->device(), mem, 1, allocation_size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001500 m_errorMonitor->VerifyFound();
1501 // Now error due to unmapping memory that's not mapped
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001502 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Unmapping Memory without memory being mapped: ");
Tobin Ehlis35372522016-05-12 08:32:31 -06001503 vkUnmapMemory(m_device->device(), mem);
1504 m_errorMonitor->VerifyFound();
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001505
Tobin Ehlis35372522016-05-12 08:32:31 -06001506 // Now map memory and cause errors due to flushing invalid ranges
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001507 err = vkMapMemory(m_device->device(), mem, 4 * atom_size, VK_WHOLE_SIZE, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001508 ASSERT_VK_SUCCESS(err);
1509 VkMappedMemoryRange mmr = {};
Chris Forbes3aec0892016-06-13 10:29:26 +12001510 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
Tobin Ehlis35372522016-05-12 08:32:31 -06001511 mmr.memory = mem;
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001512 mmr.offset = atom_size; // Error b/c offset less than offset of mapped mem
Mark Lobodzinskib3c675e2016-11-15 08:56:03 -07001513 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00642);
Tobin Ehlis35372522016-05-12 08:32:31 -06001514 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1515 m_errorMonitor->VerifyFound();
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001516
Tobin Ehlis35372522016-05-12 08:32:31 -06001517 // Now flush range that oversteps mapped range
1518 vkUnmapMemory(m_device->device(), mem);
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001519 err = vkMapMemory(m_device->device(), mem, 0, 4 * atom_size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001520 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001521 mmr.offset = atom_size;
1522 mmr.size = 4 * atom_size; // Flushing bounds exceed mapped bounds
Mark Lobodzinskib3c675e2016-11-15 08:56:03 -07001523 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00642);
1524 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1525 m_errorMonitor->VerifyFound();
1526
1527 // Now flush range with VK_WHOLE_SIZE that oversteps offset
1528 vkUnmapMemory(m_device->device(), mem);
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001529 err = vkMapMemory(m_device->device(), mem, 2 * atom_size, 4 * atom_size, 0, (void **)&pData);
Mark Lobodzinskib3c675e2016-11-15 08:56:03 -07001530 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001531 mmr.offset = atom_size;
Mark Lobodzinskib3c675e2016-11-15 08:56:03 -07001532 mmr.size = VK_WHOLE_SIZE;
1533 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00643);
Tobin Ehlis35372522016-05-12 08:32:31 -06001534 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1535 m_errorMonitor->VerifyFound();
1536
Tony Barboure3975eb2016-12-15 14:52:44 -07001537#if 0 // Planning discussion with working group on this validation check.
Mark Lobodzinski3826a4f2016-11-15 09:38:51 -07001538 // Some platforms have an atomsize of 1 which makes the test meaningless
1539 if (atom_size > 3) {
1540 // Now with an offset NOT a multiple of the device limit
1541 vkUnmapMemory(m_device->device(), mem);
1542 err = vkMapMemory(m_device->device(), mem, 0, 4 * atom_size, 0, (void **)&pData);
1543 ASSERT_VK_SUCCESS(err);
1544 mmr.offset = 3; // Not a multiple of atom_size
1545 mmr.size = VK_WHOLE_SIZE;
1546 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00644);
1547 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1548 m_errorMonitor->VerifyFound();
1549
1550 // Now with a size NOT a multiple of the device limit
1551 vkUnmapMemory(m_device->device(), mem);
1552 err = vkMapMemory(m_device->device(), mem, 0, 4 * atom_size, 0, (void **)&pData);
1553 ASSERT_VK_SUCCESS(err);
1554 mmr.offset = atom_size;
1555 mmr.size = 2 * atom_size + 1; // Not a multiple of atom_size
1556 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00645);
1557 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1558 m_errorMonitor->VerifyFound();
1559 }
Tony Barboure3975eb2016-12-15 14:52:44 -07001560#endif
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001561 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT,
1562 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Tobin Ehlis35372522016-05-12 08:32:31 -06001563 if (!pass) {
1564 vkFreeMemory(m_device->device(), mem, NULL);
1565 vkDestroyBuffer(m_device->device(), buffer, NULL);
1566 return;
1567 }
1568 // TODO : If we can get HOST_VISIBLE w/o HOST_COHERENT we can test cases of
1569 // MEMTRACK_INVALID_MAP in validateAndCopyNoncoherentMemoryToDriver()
1570
1571 vkDestroyBuffer(m_device->device(), buffer, NULL);
1572 vkFreeMemory(m_device->device(), mem, NULL);
1573}
1574
Chris Forbes09368e42016-10-13 11:59:22 +13001575#if 0 // disabled until PV gets real extension enable checks
Ian Elliott1c32c772016-04-28 14:47:13 -06001576TEST_F(VkLayerTest, EnableWsiBeforeUse) {
1577 VkResult err;
1578 bool pass;
1579
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001580 // FIXME: After we turn on this code for non-Linux platforms, uncomment the
1581 // following declaration (which is temporarily being moved below):
1582 // VkSurfaceKHR surface = VK_NULL_HANDLE;
Ian Elliott1c32c772016-04-28 14:47:13 -06001583 VkSwapchainKHR swapchain = VK_NULL_HANDLE;
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001584 VkSwapchainCreateInfoKHR swapchain_create_info = {VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR};
Ian Elliott1c32c772016-04-28 14:47:13 -06001585 uint32_t swapchain_image_count = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001586 // VkImage swapchain_images[1] = {VK_NULL_HANDLE};
Ian Elliott1c32c772016-04-28 14:47:13 -06001587 uint32_t image_index = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001588 // VkPresentInfoKHR present_info = {};
Ian Elliott1c32c772016-04-28 14:47:13 -06001589
1590 ASSERT_NO_FATAL_FAILURE(InitState());
1591
Ian Elliott3f06ce52016-04-29 14:46:21 -06001592#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
1593#if defined(VK_USE_PLATFORM_ANDROID_KHR)
1594 // Use the functions from the VK_KHR_android_surface extension without
1595 // enabling that extension:
1596
1597 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001598 VkAndroidSurfaceCreateInfoKHR android_create_info = {VK_STRUCTURE_TYPE_ANDROID_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001599 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1600 err = vkCreateAndroidSurfaceKHR(instance(), &android_create_info, NULL, &surface);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001601 pass = (err != VK_SUCCESS);
1602 ASSERT_TRUE(pass);
1603 m_errorMonitor->VerifyFound();
1604#endif // VK_USE_PLATFORM_ANDROID_KHR
1605
Ian Elliott3f06ce52016-04-29 14:46:21 -06001606#if defined(VK_USE_PLATFORM_MIR_KHR)
1607 // Use the functions from the VK_KHR_mir_surface extension without enabling
1608 // that extension:
1609
1610 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001611 VkMirSurfaceCreateInfoKHR mir_create_info = {VK_STRUCTURE_TYPE_MIR_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001612 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott3f06ce52016-04-29 14:46:21 -06001613 err = vkCreateMirSurfaceKHR(instance(), &mir_create_info, NULL, &surface);
1614 pass = (err != VK_SUCCESS);
1615 ASSERT_TRUE(pass);
1616 m_errorMonitor->VerifyFound();
1617
1618 // Tell whether an mir_connection supports presentation:
1619 MirConnection *mir_connection = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001620 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1621 vkGetPhysicalDeviceMirPresentationSupportKHR(gpu(), 0, mir_connection, visual_id);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001622 m_errorMonitor->VerifyFound();
1623#endif // VK_USE_PLATFORM_MIR_KHR
1624
Ian Elliott3f06ce52016-04-29 14:46:21 -06001625#if defined(VK_USE_PLATFORM_WAYLAND_KHR)
1626 // Use the functions from the VK_KHR_wayland_surface extension without
1627 // enabling that extension:
1628
1629 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001630 VkWaylandSurfaceCreateInfoKHR wayland_create_info = {VK_STRUCTURE_TYPE_WAYLAND_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001631 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1632 err = vkCreateWaylandSurfaceKHR(instance(), &wayland_create_info, NULL, &surface);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001633 pass = (err != VK_SUCCESS);
1634 ASSERT_TRUE(pass);
1635 m_errorMonitor->VerifyFound();
1636
1637 // Tell whether an wayland_display supports presentation:
1638 struct wl_display wayland_display = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001639 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1640 vkGetPhysicalDeviceWaylandPresentationSupportKHR(gpu(), 0, &wayland_display);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001641 m_errorMonitor->VerifyFound();
1642#endif // VK_USE_PLATFORM_WAYLAND_KHR
Ian Elliott489eec02016-05-05 14:12:44 -06001643#endif // NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott3f06ce52016-04-29 14:46:21 -06001644
Ian Elliott3f06ce52016-04-29 14:46:21 -06001645#if defined(VK_USE_PLATFORM_WIN32_KHR)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001646 // FIXME: REMOVE THIS HERE, AND UNCOMMENT ABOVE, WHEN THIS TEST HAS BEEN PORTED
1647 // TO NON-LINUX PLATFORMS:
1648 VkSurfaceKHR surface = VK_NULL_HANDLE;
Ian Elliott3f06ce52016-04-29 14:46:21 -06001649 // Use the functions from the VK_KHR_win32_surface extension without
1650 // enabling that extension:
1651
1652 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001653 VkWin32SurfaceCreateInfoKHR win32_create_info = {VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001654 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1655 err = vkCreateWin32SurfaceKHR(instance(), &win32_create_info, NULL, &surface);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001656 pass = (err != VK_SUCCESS);
1657 ASSERT_TRUE(pass);
1658 m_errorMonitor->VerifyFound();
1659
1660 // Tell whether win32 supports presentation:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001661 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott489eec02016-05-05 14:12:44 -06001662 vkGetPhysicalDeviceWin32PresentationSupportKHR(gpu(), 0);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001663 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001664// Set this (for now, until all platforms are supported and tested):
1665#define NEED_TO_TEST_THIS_ON_PLATFORM
1666#endif // VK_USE_PLATFORM_WIN32_KHR
Tony Barbour2e7bd402016-11-14 14:46:33 -07001667#if defined(VK_USE_PLATFORM_XCB_KHR) || defined (VK_USE_PLATFORM_XLIB_KHR)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001668 // FIXME: REMOVE THIS HERE, AND UNCOMMENT ABOVE, WHEN THIS TEST HAS BEEN PORTED
1669 // TO NON-LINUX PLATFORMS:
1670 VkSurfaceKHR surface = VK_NULL_HANDLE;
Tony Barbour2e7bd402016-11-14 14:46:33 -07001671#endif
1672#if defined(VK_USE_PLATFORM_XCB_KHR)
Ian Elliott1c32c772016-04-28 14:47:13 -06001673 // Use the functions from the VK_KHR_xcb_surface extension without enabling
1674 // that extension:
1675
1676 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001677 VkXcbSurfaceCreateInfoKHR xcb_create_info = {VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001678 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001679 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
1680 pass = (err != VK_SUCCESS);
1681 ASSERT_TRUE(pass);
1682 m_errorMonitor->VerifyFound();
1683
1684 // Tell whether an xcb_visualid_t supports presentation:
Ian Elliott3f06ce52016-04-29 14:46:21 -06001685 xcb_connection_t *xcb_connection = NULL;
Ian Elliott1c32c772016-04-28 14:47:13 -06001686 xcb_visualid_t visual_id = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001687 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1688 vkGetPhysicalDeviceXcbPresentationSupportKHR(gpu(), 0, xcb_connection, visual_id);
Ian Elliott1c32c772016-04-28 14:47:13 -06001689 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001690// Set this (for now, until all platforms are supported and tested):
1691#define NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06001692#endif // VK_USE_PLATFORM_XCB_KHR
1693
Ian Elliott12630812016-04-29 14:35:43 -06001694#if defined(VK_USE_PLATFORM_XLIB_KHR)
1695 // Use the functions from the VK_KHR_xlib_surface extension without enabling
1696 // that extension:
1697
1698 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001699 VkXlibSurfaceCreateInfoKHR xlib_create_info = {VK_STRUCTURE_TYPE_XLIB_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001700 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott12630812016-04-29 14:35:43 -06001701 err = vkCreateXlibSurfaceKHR(instance(), &xlib_create_info, NULL, &surface);
1702 pass = (err != VK_SUCCESS);
1703 ASSERT_TRUE(pass);
1704 m_errorMonitor->VerifyFound();
1705
1706 // Tell whether an Xlib VisualID supports presentation:
1707 Display *dpy = NULL;
1708 VisualID visual = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001709 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott12630812016-04-29 14:35:43 -06001710 vkGetPhysicalDeviceXlibPresentationSupportKHR(gpu(), 0, dpy, visual);
1711 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001712// Set this (for now, until all platforms are supported and tested):
1713#define NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott12630812016-04-29 14:35:43 -06001714#endif // VK_USE_PLATFORM_XLIB_KHR
1715
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001716// Use the functions from the VK_KHR_surface extension without enabling
1717// that extension:
Ian Elliott1c32c772016-04-28 14:47:13 -06001718
Ian Elliott489eec02016-05-05 14:12:44 -06001719#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06001720 // Destroy a surface:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001721 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001722 vkDestroySurfaceKHR(instance(), surface, NULL);
1723 m_errorMonitor->VerifyFound();
1724
1725 // Check if surface supports presentation:
1726 VkBool32 supported = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001727 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001728 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
1729 pass = (err != VK_SUCCESS);
1730 ASSERT_TRUE(pass);
1731 m_errorMonitor->VerifyFound();
1732
1733 // Check surface capabilities:
1734 VkSurfaceCapabilitiesKHR capabilities = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001735 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1736 err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), surface, &capabilities);
Ian Elliott1c32c772016-04-28 14:47:13 -06001737 pass = (err != VK_SUCCESS);
1738 ASSERT_TRUE(pass);
1739 m_errorMonitor->VerifyFound();
1740
1741 // Check surface formats:
1742 uint32_t format_count = 0;
1743 VkSurfaceFormatKHR *formats = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001744 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1745 err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &format_count, formats);
Ian Elliott1c32c772016-04-28 14:47:13 -06001746 pass = (err != VK_SUCCESS);
1747 ASSERT_TRUE(pass);
1748 m_errorMonitor->VerifyFound();
1749
1750 // Check surface present modes:
1751 uint32_t present_mode_count = 0;
1752 VkSurfaceFormatKHR *present_modes = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001753 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1754 err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &present_mode_count, present_modes);
Ian Elliott1c32c772016-04-28 14:47:13 -06001755 pass = (err != VK_SUCCESS);
1756 ASSERT_TRUE(pass);
1757 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001758#endif // NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06001759
Ian Elliott1c32c772016-04-28 14:47:13 -06001760 // Use the functions from the VK_KHR_swapchain extension without enabling
1761 // that extension:
1762
1763 // Create a swapchain:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001764 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001765 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
1766 swapchain_create_info.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001767 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
Ian Elliott1c32c772016-04-28 14:47:13 -06001768 pass = (err != VK_SUCCESS);
1769 ASSERT_TRUE(pass);
1770 m_errorMonitor->VerifyFound();
1771
1772 // Get the images from the swapchain:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001773 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1774 err = vkGetSwapchainImagesKHR(m_device->device(), swapchain, &swapchain_image_count, NULL);
Ian Elliott1c32c772016-04-28 14:47:13 -06001775 pass = (err != VK_SUCCESS);
1776 ASSERT_TRUE(pass);
1777 m_errorMonitor->VerifyFound();
1778
Chris Forbeseb7d5502016-09-13 18:19:21 +12001779 // Add a fence to avoid (justifiable) error about not providing fence OR semaphore
1780 VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
1781 VkFence fence;
1782 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
1783
Ian Elliott1c32c772016-04-28 14:47:13 -06001784 // Try to acquire an image:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001785 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Chris Forbeseb7d5502016-09-13 18:19:21 +12001786 err = vkAcquireNextImageKHR(m_device->device(), swapchain, 0, VK_NULL_HANDLE, fence, &image_index);
Ian Elliott1c32c772016-04-28 14:47:13 -06001787 pass = (err != VK_SUCCESS);
1788 ASSERT_TRUE(pass);
1789 m_errorMonitor->VerifyFound();
1790
Chris Forbeseb7d5502016-09-13 18:19:21 +12001791 vkDestroyFence(m_device->device(), fence, nullptr);
1792
Ian Elliott1c32c772016-04-28 14:47:13 -06001793 // Try to present an image:
Ian Elliott2c1daf52016-05-12 09:41:46 -06001794 //
1795 // NOTE: Currently can't test this because a real swapchain is needed (as
1796 // opposed to the fake one we created) in order for the layer to lookup the
1797 // VkDevice used to enable the extension:
Ian Elliott1c32c772016-04-28 14:47:13 -06001798
1799 // Destroy the swapchain:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001800 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001801 vkDestroySwapchainKHR(m_device->device(), swapchain, NULL);
1802 m_errorMonitor->VerifyFound();
1803}
Chris Forbes09368e42016-10-13 11:59:22 +13001804#endif
Ian Elliott1c32c772016-04-28 14:47:13 -06001805
Karl Schultz6addd812016-02-02 17:17:23 -07001806TEST_F(VkLayerTest, MapMemWithoutHostVisibleBit) {
1807 VkResult err;
1808 bool pass;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001809
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001810 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1811 "Mapping Memory without VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001812
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001813 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001814
1815 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07001816 VkImage image;
1817 VkDeviceMemory mem;
1818 VkMemoryRequirements mem_reqs;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001819
Karl Schultz6addd812016-02-02 17:17:23 -07001820 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
1821 const int32_t tex_width = 32;
1822 const int32_t tex_height = 32;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001823
Tony Barboureb254902015-07-15 12:50:33 -06001824 VkImageCreateInfo image_create_info = {};
1825 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07001826 image_create_info.pNext = NULL;
1827 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1828 image_create_info.format = tex_format;
1829 image_create_info.extent.width = tex_width;
1830 image_create_info.extent.height = tex_height;
1831 image_create_info.extent.depth = 1;
1832 image_create_info.mipLevels = 1;
1833 image_create_info.arrayLayers = 1;
1834 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
1835 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
1836 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
1837 image_create_info.flags = 0;
Chris Forbese65e4d02016-09-13 17:39:18 +12001838 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001839
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001840 VkMemoryAllocateInfo mem_alloc = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08001841 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07001842 mem_alloc.pNext = NULL;
1843 mem_alloc.allocationSize = 0;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001844
Chia-I Wuf7458c52015-10-26 21:10:41 +08001845 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001846 ASSERT_VK_SUCCESS(err);
1847
Karl Schultz6addd812016-02-02 17:17:23 -07001848 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001849
Mark Lobodzinski23065352015-05-29 09:32:35 -05001850 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001851
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001852 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 -07001853 if (!pass) { // If we can't find any unmappable memory this test doesn't
1854 // make sense
Chia-I Wuf7458c52015-10-26 21:10:41 +08001855 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbour02fdc7d2015-08-04 16:13:01 -06001856 return;
Mike Stroyand1c84a52015-08-18 14:40:24 -06001857 }
Mike Stroyan713b2d72015-08-04 10:49:29 -06001858
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001859 // allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001860 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001861 ASSERT_VK_SUCCESS(err);
1862
1863 // Try to bind free memory that has been freed
Tony Barbour67e99152015-07-10 14:10:27 -06001864 err = vkBindImageMemory(m_device->device(), image, mem, 0);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001865 ASSERT_VK_SUCCESS(err);
1866
1867 // Map memory as if to initialize the image
1868 void *mappedAddress = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001869 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, &mappedAddress);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001870
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001871 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06001872
Chia-I Wuf7458c52015-10-26 21:10:41 +08001873 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06001874 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001875}
1876
Karl Schultz6addd812016-02-02 17:17:23 -07001877TEST_F(VkLayerTest, RebindMemory) {
1878 VkResult err;
1879 bool pass;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001880
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001881 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "which has already been bound to mem object");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001882
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001883 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001884
1885 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07001886 VkImage image;
1887 VkDeviceMemory mem1;
1888 VkDeviceMemory mem2;
1889 VkMemoryRequirements mem_reqs;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001890
Karl Schultz6addd812016-02-02 17:17:23 -07001891 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
1892 const int32_t tex_width = 32;
1893 const int32_t tex_height = 32;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001894
Tony Barboureb254902015-07-15 12:50:33 -06001895 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07001896 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1897 image_create_info.pNext = NULL;
1898 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1899 image_create_info.format = tex_format;
1900 image_create_info.extent.width = tex_width;
1901 image_create_info.extent.height = tex_height;
1902 image_create_info.extent.depth = 1;
1903 image_create_info.mipLevels = 1;
1904 image_create_info.arrayLayers = 1;
1905 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
1906 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
1907 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
1908 image_create_info.flags = 0;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001909
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001910 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07001911 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1912 mem_alloc.pNext = NULL;
1913 mem_alloc.allocationSize = 0;
1914 mem_alloc.memoryTypeIndex = 0;
Tony Barboureb254902015-07-15 12:50:33 -06001915
Karl Schultz6addd812016-02-02 17:17:23 -07001916 // Introduce failure, do NOT set memProps to
1917 // VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
Tony Barboureb254902015-07-15 12:50:33 -06001918 mem_alloc.memoryTypeIndex = 1;
Chia-I Wuf7458c52015-10-26 21:10:41 +08001919 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001920 ASSERT_VK_SUCCESS(err);
1921
Karl Schultz6addd812016-02-02 17:17:23 -07001922 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001923
1924 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001925 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06001926 ASSERT_TRUE(pass);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001927
1928 // allocate 2 memory objects
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001929 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem1);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001930 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001931 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem2);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001932 ASSERT_VK_SUCCESS(err);
1933
1934 // Bind first memory object to Image object
Tony Barbour67e99152015-07-10 14:10:27 -06001935 err = vkBindImageMemory(m_device->device(), image, mem1, 0);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001936 ASSERT_VK_SUCCESS(err);
1937
Karl Schultz6addd812016-02-02 17:17:23 -07001938 // Introduce validation failure, try to bind a different memory object to
1939 // the same image object
Tony Barbour67e99152015-07-10 14:10:27 -06001940 err = vkBindImageMemory(m_device->device(), image, mem2, 0);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001941
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001942 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06001943
Chia-I Wuf7458c52015-10-26 21:10:41 +08001944 vkDestroyImage(m_device->device(), image, NULL);
1945 vkFreeMemory(m_device->device(), mem1, NULL);
1946 vkFreeMemory(m_device->device(), mem2, NULL);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001947}
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001948
Karl Schultz6addd812016-02-02 17:17:23 -07001949TEST_F(VkLayerTest, SubmitSignaledFence) {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001950 vk_testing::Fence testFence;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001951
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001952 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "submitted in SIGNALED state. Fences "
1953 "must be reset before being submitted");
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001954
1955 VkFenceCreateInfo fenceInfo = {};
Tony Barbour0b4d9562015-04-09 10:48:04 -06001956 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1957 fenceInfo.pNext = NULL;
1958 fenceInfo.flags = VK_FENCE_CREATE_SIGNALED_BIT;
Tony Barbour300a6082015-04-07 13:44:53 -06001959
Tony Barbour300a6082015-04-07 13:44:53 -06001960 ASSERT_NO_FATAL_FAILURE(InitState());
1961 ASSERT_NO_FATAL_FAILURE(InitViewport());
1962 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1963
Tony Barbourfe3351b2015-07-28 10:17:20 -06001964 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001965 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbourfe3351b2015-07-28 10:17:20 -06001966 EndCommandBuffer();
Tony Barbour300a6082015-04-07 13:44:53 -06001967
1968 testFence.init(*m_device, fenceInfo);
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001969
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001970 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08001971 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1972 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001973 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001974 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07001975 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001976 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001977 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08001978 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001979 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06001980
1981 vkQueueSubmit(m_device->m_queue, 1, &submit_info, testFence.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07001982 vkQueueWaitIdle(m_device->m_queue);
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001983
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001984 m_errorMonitor->VerifyFound();
Tony Barbour0b4d9562015-04-09 10:48:04 -06001985}
Chris Forbes4e44c912016-06-16 10:20:00 +12001986
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001987TEST_F(VkLayerTest, InvalidUsageBits) {
1988 TEST_DESCRIPTION("Specify wrong usage for image then create conflicting view of image "
1989 "Initialize buffer with wrong usage then perform copy expecting errors "
1990 "from both the image and the buffer (2 calls)");
1991 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid usage flag for image ");
Tobin Ehlis41376e12015-07-03 08:45:14 -06001992
1993 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesd2b5fe42016-11-28 18:00:00 +13001994
1995 auto format = VK_FORMAT_D24_UNORM_S8_UINT;
1996
Tony Barbourf92621a2016-05-02 14:28:12 -06001997 VkImageObj image(m_device);
Tony Barbour75d79f02016-08-30 09:39:07 -06001998 // Initialize image with USAGE_TRANSIENT_ATTACHMENT
Chris Forbesd2b5fe42016-11-28 18:00:00 +13001999 image.init(128, 128, format, VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
Karl Schultzb5bc11e2016-05-04 08:36:08 -06002000 ASSERT_TRUE(image.initialized());
Tobin Ehlis41376e12015-07-03 08:45:14 -06002001
Tony Barbourf92621a2016-05-02 14:28:12 -06002002 VkImageView dsv;
2003 VkImageViewCreateInfo dsvci = {};
2004 dsvci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
2005 dsvci.image = image.handle();
2006 dsvci.viewType = VK_IMAGE_VIEW_TYPE_2D;
Chris Forbesd2b5fe42016-11-28 18:00:00 +13002007 dsvci.format = format;
Tony Barbourf92621a2016-05-02 14:28:12 -06002008 dsvci.subresourceRange.layerCount = 1;
2009 dsvci.subresourceRange.baseMipLevel = 0;
2010 dsvci.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002011 dsvci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
Tobin Ehlis41376e12015-07-03 08:45:14 -06002012
Tony Barbourf92621a2016-05-02 14:28:12 -06002013 // Create a view with depth / stencil aspect for image with different usage
2014 vkCreateImageView(m_device->device(), &dsvci, NULL, &dsv);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002015
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002016 m_errorMonitor->VerifyFound();
Tony Barbourf92621a2016-05-02 14:28:12 -06002017
2018 // Initialize buffer with TRANSFER_DST usage
2019 vk_testing::Buffer buffer;
2020 VkMemoryPropertyFlags reqs = 0;
2021 buffer.init_as_dst(*m_device, 128 * 128, reqs);
2022 VkBufferImageCopy region = {};
2023 region.bufferRowLength = 128;
2024 region.bufferImageHeight = 128;
2025 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2026 region.imageSubresource.layerCount = 1;
2027 region.imageExtent.height = 16;
2028 region.imageExtent.width = 16;
2029 region.imageExtent.depth = 1;
2030
Tony Barbourf92621a2016-05-02 14:28:12 -06002031 // Buffer usage not set to TRANSFER_SRC and image usage not set to
2032 // TRANSFER_DST
2033 BeginCommandBuffer();
Tony Barbourf92621a2016-05-02 14:28:12 -06002034
Chris Forbesda581202016-10-06 18:25:26 +13002035 // two separate errors from this call:
2036 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "image should have VK_IMAGE_USAGE_TRANSFER_DST_BIT");
2037 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "buffer should have VK_BUFFER_USAGE_TRANSFER_SRC_BIT");
2038
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002039 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
2040 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Tony Barbourf92621a2016-05-02 14:28:12 -06002041 m_errorMonitor->VerifyFound();
Tobin Ehlis41376e12015-07-03 08:45:14 -06002042}
Tony Barbour75d79f02016-08-30 09:39:07 -06002043
Tony Barbour75d79f02016-08-30 09:39:07 -06002044
Mark Lobodzinski209b5292015-09-17 09:44:05 -06002045#endif // MEM_TRACKER_TESTS
2046
Tobin Ehlis4bf96d12015-06-25 11:58:41 -06002047#if OBJ_TRACKER_TESTS
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002048
2049TEST_F(VkLayerTest, LeakAnObject) {
2050 VkResult err;
2051
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002052 TEST_DESCRIPTION("Create a fence and destroy its device without first destroying the fence.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002053
2054 // Note that we have to create a new device since destroying the
2055 // framework's device causes Teardown() to fail and just calling Teardown
2056 // will destroy the errorMonitor.
2057
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002058 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "has not been destroyed.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002059
2060 ASSERT_NO_FATAL_FAILURE(InitState());
2061
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002062 const std::vector<VkQueueFamilyProperties> queue_props = m_device->queue_props;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002063 std::vector<VkDeviceQueueCreateInfo> queue_info;
2064 queue_info.reserve(queue_props.size());
2065 std::vector<std::vector<float>> queue_priorities;
2066 for (uint32_t i = 0; i < (uint32_t)queue_props.size(); i++) {
2067 VkDeviceQueueCreateInfo qi = {};
2068 qi.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
2069 qi.pNext = NULL;
2070 qi.queueFamilyIndex = i;
2071 qi.queueCount = queue_props[i].queueCount;
2072 queue_priorities.emplace_back(qi.queueCount, 0.0f);
2073 qi.pQueuePriorities = queue_priorities[i].data();
2074 queue_info.push_back(qi);
2075 }
2076
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002077 std::vector<const char *> device_extension_names;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002078
2079 // The sacrificial device object
2080 VkDevice testDevice;
2081 VkDeviceCreateInfo device_create_info = {};
2082 auto features = m_device->phy().features();
2083 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
2084 device_create_info.pNext = NULL;
2085 device_create_info.queueCreateInfoCount = queue_info.size();
2086 device_create_info.pQueueCreateInfos = queue_info.data();
Tony Barbour4c70d102016-08-08 16:06:56 -06002087 device_create_info.enabledLayerCount = 0;
2088 device_create_info.ppEnabledLayerNames = NULL;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002089 device_create_info.pEnabledFeatures = &features;
2090 err = vkCreateDevice(gpu(), &device_create_info, NULL, &testDevice);
2091 ASSERT_VK_SUCCESS(err);
2092
2093 VkFence fence;
2094 VkFenceCreateInfo fence_create_info = {};
2095 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
2096 fence_create_info.pNext = NULL;
2097 fence_create_info.flags = 0;
2098 err = vkCreateFence(testDevice, &fence_create_info, NULL, &fence);
2099 ASSERT_VK_SUCCESS(err);
2100
2101 // Induce failure by not calling vkDestroyFence
2102 vkDestroyDevice(testDevice, NULL);
2103 m_errorMonitor->VerifyFound();
2104}
2105
2106TEST_F(VkLayerTest, InvalidCommandPoolConsistency) {
2107
2108 TEST_DESCRIPTION("Allocate command buffers from one command pool and "
2109 "attempt to delete them from another.");
2110
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002111 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "FreeCommandBuffers is attempting to free Command Buffer");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002112
Cody Northropc31a84f2016-08-22 10:41:47 -06002113 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002114 VkCommandPool command_pool_one;
2115 VkCommandPool command_pool_two;
2116
2117 VkCommandPoolCreateInfo pool_create_info{};
2118 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
2119 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
2120 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
2121
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002122 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool_one);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002123
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002124 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool_two);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002125
Chris Forbes5ab04ec2016-11-28 18:03:11 +13002126 VkCommandBuffer cb;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002127 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002128 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002129 command_buffer_allocate_info.commandPool = command_pool_one;
Chris Forbes5ab04ec2016-11-28 18:03:11 +13002130 command_buffer_allocate_info.commandBufferCount = 1;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002131 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Chris Forbes5ab04ec2016-11-28 18:03:11 +13002132 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &cb);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002133
Chris Forbes5ab04ec2016-11-28 18:03:11 +13002134 vkFreeCommandBuffers(m_device->device(), command_pool_two, 1, &cb);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002135
2136 m_errorMonitor->VerifyFound();
2137
2138 vkDestroyCommandPool(m_device->device(), command_pool_one, NULL);
2139 vkDestroyCommandPool(m_device->device(), command_pool_two, NULL);
2140}
2141
2142TEST_F(VkLayerTest, InvalidDescriptorPoolConsistency) {
2143 VkResult err;
2144
2145 TEST_DESCRIPTION("Allocate descriptor sets from one DS pool and "
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002146 "attempt to delete them from another.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002147
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002148 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "FreeDescriptorSets is attempting to free descriptorSet");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002149
2150 ASSERT_NO_FATAL_FAILURE(InitState());
2151 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2152
2153 VkDescriptorPoolSize ds_type_count = {};
2154 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
2155 ds_type_count.descriptorCount = 1;
2156
2157 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2158 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2159 ds_pool_ci.pNext = NULL;
2160 ds_pool_ci.flags = 0;
2161 ds_pool_ci.maxSets = 1;
2162 ds_pool_ci.poolSizeCount = 1;
2163 ds_pool_ci.pPoolSizes = &ds_type_count;
2164
2165 VkDescriptorPool ds_pool_one;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002166 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool_one);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002167 ASSERT_VK_SUCCESS(err);
2168
2169 // Create a second descriptor pool
2170 VkDescriptorPool ds_pool_two;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002171 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool_two);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002172 ASSERT_VK_SUCCESS(err);
2173
2174 VkDescriptorSetLayoutBinding dsl_binding = {};
2175 dsl_binding.binding = 0;
2176 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
2177 dsl_binding.descriptorCount = 1;
2178 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2179 dsl_binding.pImmutableSamplers = NULL;
2180
2181 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2182 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2183 ds_layout_ci.pNext = NULL;
2184 ds_layout_ci.bindingCount = 1;
2185 ds_layout_ci.pBindings = &dsl_binding;
2186
2187 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002188 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002189 ASSERT_VK_SUCCESS(err);
2190
2191 VkDescriptorSet descriptorSet;
2192 VkDescriptorSetAllocateInfo alloc_info = {};
2193 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
2194 alloc_info.descriptorSetCount = 1;
2195 alloc_info.descriptorPool = ds_pool_one;
2196 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002197 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002198 ASSERT_VK_SUCCESS(err);
2199
2200 err = vkFreeDescriptorSets(m_device->device(), ds_pool_two, 1, &descriptorSet);
2201
2202 m_errorMonitor->VerifyFound();
2203
2204 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2205 vkDestroyDescriptorPool(m_device->device(), ds_pool_one, NULL);
2206 vkDestroyDescriptorPool(m_device->device(), ds_pool_two, NULL);
2207}
2208
2209TEST_F(VkLayerTest, CreateUnknownObject) {
Karl Schultzf78bcdd2016-11-30 12:36:01 -07002210 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00788);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002211
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002212 TEST_DESCRIPTION("Pass an invalid image object handle into a Vulkan API call.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002213
2214 ASSERT_NO_FATAL_FAILURE(InitState());
2215
2216 // Pass bogus handle into GetImageMemoryRequirements
2217 VkMemoryRequirements mem_reqs;
2218 uint64_t fakeImageHandle = 0xCADECADE;
2219 VkImage fauxImage = reinterpret_cast<VkImage &>(fakeImageHandle);
2220
2221 vkGetImageMemoryRequirements(m_device->device(), fauxImage, &mem_reqs);
2222
2223 m_errorMonitor->VerifyFound();
2224}
2225
Karl Schultz6addd812016-02-02 17:17:23 -07002226TEST_F(VkLayerTest, PipelineNotBound) {
2227 VkResult err;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002228
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002229 TEST_DESCRIPTION("Pass in an invalid pipeline object handle into a Vulkan API call.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002230
Karl Schultzf78bcdd2016-11-30 12:36:01 -07002231 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00601);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002232
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002233 ASSERT_NO_FATAL_FAILURE(InitState());
2234 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002235
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002236 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002237 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2238 ds_type_count.descriptorCount = 1;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002239
2240 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002241 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2242 ds_pool_ci.pNext = NULL;
2243 ds_pool_ci.maxSets = 1;
2244 ds_pool_ci.poolSizeCount = 1;
2245 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002246
2247 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002248 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002249 ASSERT_VK_SUCCESS(err);
2250
2251 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002252 dsl_binding.binding = 0;
2253 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2254 dsl_binding.descriptorCount = 1;
2255 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2256 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002257
2258 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002259 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2260 ds_layout_ci.pNext = NULL;
2261 ds_layout_ci.bindingCount = 1;
2262 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002263
2264 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002265 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002266 ASSERT_VK_SUCCESS(err);
2267
2268 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002269 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08002270 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07002271 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06002272 alloc_info.descriptorPool = ds_pool;
2273 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002274 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002275 ASSERT_VK_SUCCESS(err);
2276
2277 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002278 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
2279 pipeline_layout_ci.pNext = NULL;
2280 pipeline_layout_ci.setLayoutCount = 1;
2281 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002282
2283 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002284 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002285 ASSERT_VK_SUCCESS(err);
2286
Mark Youngad779052016-01-06 14:26:04 -07002287 VkPipeline badPipeline = (VkPipeline)((size_t)0xbaadb1be);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002288
2289 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002290 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, badPipeline);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002291
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002292 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002293
Chia-I Wuf7458c52015-10-26 21:10:41 +08002294 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
2295 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2296 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002297}
Mike Stroyan80fc6c32016-06-20 15:42:29 -06002298
Mark Lobodzinskibc185762016-06-15 16:28:53 -06002299TEST_F(VkLayerTest, BindImageInvalidMemoryType) {
2300 VkResult err;
2301
2302 TEST_DESCRIPTION("Test validation check for an invalid memory type index "
2303 "during bind[Buffer|Image]Memory time");
2304
Mark Lobodzinskibc185762016-06-15 16:28:53 -06002305 ASSERT_NO_FATAL_FAILURE(InitState());
2306
2307 // Create an image, allocate memory, set a bad typeIndex and then try to
2308 // bind it
2309 VkImage image;
2310 VkDeviceMemory mem;
2311 VkMemoryRequirements mem_reqs;
2312 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2313 const int32_t tex_width = 32;
2314 const int32_t tex_height = 32;
2315
2316 VkImageCreateInfo image_create_info = {};
2317 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2318 image_create_info.pNext = NULL;
2319 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2320 image_create_info.format = tex_format;
2321 image_create_info.extent.width = tex_width;
2322 image_create_info.extent.height = tex_height;
2323 image_create_info.extent.depth = 1;
2324 image_create_info.mipLevels = 1;
2325 image_create_info.arrayLayers = 1;
2326 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2327 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
2328 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2329 image_create_info.flags = 0;
2330
2331 VkMemoryAllocateInfo mem_alloc = {};
2332 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2333 mem_alloc.pNext = NULL;
2334 mem_alloc.allocationSize = 0;
2335 mem_alloc.memoryTypeIndex = 0;
2336
2337 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
2338 ASSERT_VK_SUCCESS(err);
2339
2340 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
2341 mem_alloc.allocationSize = mem_reqs.size;
Mike Stroyan80fc6c32016-06-20 15:42:29 -06002342
2343 // Introduce Failure, select invalid TypeIndex
2344 VkPhysicalDeviceMemoryProperties memory_info;
2345
2346 vkGetPhysicalDeviceMemoryProperties(gpu(), &memory_info);
2347 unsigned int i;
2348 for (i = 0; i < memory_info.memoryTypeCount; i++) {
2349 if ((mem_reqs.memoryTypeBits & (1 << i)) == 0) {
2350 mem_alloc.memoryTypeIndex = i;
2351 break;
2352 }
2353 }
2354 if (i >= memory_info.memoryTypeCount) {
2355 printf("No invalid memory type index could be found; skipped.\n");
2356 vkDestroyImage(m_device->device(), image, NULL);
2357 return;
2358 }
2359
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002360 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 -06002361
2362 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
2363 ASSERT_VK_SUCCESS(err);
2364
2365 err = vkBindImageMemory(m_device->device(), image, mem, 0);
2366 (void)err;
2367
2368 m_errorMonitor->VerifyFound();
2369
2370 vkDestroyImage(m_device->device(), image, NULL);
2371 vkFreeMemory(m_device->device(), mem, NULL);
2372}
Mike Stroyan80fc6c32016-06-20 15:42:29 -06002373
Karl Schultz6addd812016-02-02 17:17:23 -07002374TEST_F(VkLayerTest, BindInvalidMemory) {
2375 VkResult err;
2376 bool pass;
Tobin Ehlisec598302015-09-15 15:02:17 -06002377
Karl Schultzf78bcdd2016-11-30 12:36:01 -07002378 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00809);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002379
Tobin Ehlisec598302015-09-15 15:02:17 -06002380 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisec598302015-09-15 15:02:17 -06002381
2382 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07002383 VkImage image;
2384 VkDeviceMemory mem;
2385 VkMemoryRequirements mem_reqs;
Tobin Ehlisec598302015-09-15 15:02:17 -06002386
Karl Schultz6addd812016-02-02 17:17:23 -07002387 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2388 const int32_t tex_width = 32;
2389 const int32_t tex_height = 32;
Tobin Ehlisec598302015-09-15 15:02:17 -06002390
2391 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002392 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2393 image_create_info.pNext = NULL;
2394 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2395 image_create_info.format = tex_format;
2396 image_create_info.extent.width = tex_width;
2397 image_create_info.extent.height = tex_height;
2398 image_create_info.extent.depth = 1;
2399 image_create_info.mipLevels = 1;
2400 image_create_info.arrayLayers = 1;
2401 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2402 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2403 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2404 image_create_info.flags = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002405
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002406 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002407 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2408 mem_alloc.pNext = NULL;
2409 mem_alloc.allocationSize = 0;
2410 mem_alloc.memoryTypeIndex = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002411
Chia-I Wuf7458c52015-10-26 21:10:41 +08002412 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlisec598302015-09-15 15:02:17 -06002413 ASSERT_VK_SUCCESS(err);
2414
Karl Schultz6addd812016-02-02 17:17:23 -07002415 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Tobin Ehlisec598302015-09-15 15:02:17 -06002416
2417 mem_alloc.allocationSize = mem_reqs.size;
2418
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002419 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06002420 ASSERT_TRUE(pass);
Tobin Ehlisec598302015-09-15 15:02:17 -06002421
2422 // allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002423 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlisec598302015-09-15 15:02:17 -06002424 ASSERT_VK_SUCCESS(err);
2425
2426 // Introduce validation failure, free memory before binding
Chia-I Wuf7458c52015-10-26 21:10:41 +08002427 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002428
2429 // Try to bind free memory that has been freed
2430 err = vkBindImageMemory(m_device->device(), image, mem, 0);
2431 // This may very well return an error.
2432 (void)err;
2433
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002434 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002435
Chia-I Wuf7458c52015-10-26 21:10:41 +08002436 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002437}
2438
Karl Schultz6addd812016-02-02 17:17:23 -07002439TEST_F(VkLayerTest, BindMemoryToDestroyedObject) {
2440 VkResult err;
2441 bool pass;
Tobin Ehlisec598302015-09-15 15:02:17 -06002442
Karl Schultzf78bcdd2016-11-30 12:36:01 -07002443 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00808);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002444
Tobin Ehlisec598302015-09-15 15:02:17 -06002445 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisec598302015-09-15 15:02:17 -06002446
Karl Schultz6addd812016-02-02 17:17:23 -07002447 // Create an image object, allocate memory, destroy the object and then try
2448 // to bind it
2449 VkImage image;
2450 VkDeviceMemory mem;
2451 VkMemoryRequirements mem_reqs;
Tobin Ehlisec598302015-09-15 15:02:17 -06002452
Karl Schultz6addd812016-02-02 17:17:23 -07002453 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2454 const int32_t tex_width = 32;
2455 const int32_t tex_height = 32;
Tobin Ehlisec598302015-09-15 15:02:17 -06002456
2457 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002458 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2459 image_create_info.pNext = NULL;
2460 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2461 image_create_info.format = tex_format;
2462 image_create_info.extent.width = tex_width;
2463 image_create_info.extent.height = tex_height;
2464 image_create_info.extent.depth = 1;
2465 image_create_info.mipLevels = 1;
2466 image_create_info.arrayLayers = 1;
2467 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2468 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2469 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2470 image_create_info.flags = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002471
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002472 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002473 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2474 mem_alloc.pNext = NULL;
2475 mem_alloc.allocationSize = 0;
2476 mem_alloc.memoryTypeIndex = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002477
Chia-I Wuf7458c52015-10-26 21:10:41 +08002478 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlisec598302015-09-15 15:02:17 -06002479 ASSERT_VK_SUCCESS(err);
2480
Karl Schultz6addd812016-02-02 17:17:23 -07002481 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Tobin Ehlisec598302015-09-15 15:02:17 -06002482
2483 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002484 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06002485 ASSERT_TRUE(pass);
Tobin Ehlisec598302015-09-15 15:02:17 -06002486
2487 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002488 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlisec598302015-09-15 15:02:17 -06002489 ASSERT_VK_SUCCESS(err);
2490
2491 // Introduce validation failure, destroy Image object before binding
Chia-I Wuf7458c52015-10-26 21:10:41 +08002492 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002493 ASSERT_VK_SUCCESS(err);
2494
2495 // Now Try to bind memory to this destroyed object
2496 err = vkBindImageMemory(m_device->device(), image, mem, 0);
2497 // This may very well return an error.
Karl Schultz6addd812016-02-02 17:17:23 -07002498 (void)err;
Tobin Ehlisec598302015-09-15 15:02:17 -06002499
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002500 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002501
Chia-I Wuf7458c52015-10-26 21:10:41 +08002502 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002503}
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002504
Mark Lobodzinski209b5292015-09-17 09:44:05 -06002505#endif // OBJ_TRACKER_TESTS
2506
Tobin Ehlis0788f522015-05-26 16:11:58 -06002507#if DRAW_STATE_TESTS
Mark Lobodzinskic808d442016-04-14 10:57:23 -06002508
Mark Lobodzinski66e5eab2016-11-15 13:30:38 -07002509TEST_F(VkLayerTest, CreatePipelineBadVertexAttributeFormat) {
2510 TEST_DESCRIPTION("Test that pipeline validation catches invalid vertex attribute formats");
2511
2512 ASSERT_NO_FATAL_FAILURE(InitState());
2513 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2514
2515 VkVertexInputBindingDescription input_binding;
2516 memset(&input_binding, 0, sizeof(input_binding));
2517
2518 VkVertexInputAttributeDescription input_attribs;
2519 memset(&input_attribs, 0, sizeof(input_attribs));
2520
2521 // Pick a really bad format for this purpose and make sure it should fail
2522 input_attribs.format = VK_FORMAT_BC2_UNORM_BLOCK;
2523 VkFormatProperties format_props = m_device->format_properties(input_attribs.format);
2524 if ((format_props.bufferFeatures & VK_FORMAT_FEATURE_VERTEX_BUFFER_BIT) != 0) {
2525 printf("Format unsuitable for test; skipped.\n");
2526 return;
2527 }
2528
2529 input_attribs.location = 0;
2530 char const *vsSource = "#version 450\n"
2531 "\n"
2532 "out gl_PerVertex {\n"
2533 " vec4 gl_Position;\n"
2534 "};\n"
2535 "void main(){\n"
2536 " gl_Position = vec4(1);\n"
2537 "}\n";
2538 char const *fsSource = "#version 450\n"
2539 "\n"
2540 "layout(location=0) out vec4 color;\n"
2541 "void main(){\n"
2542 " color = vec4(1);\n"
2543 "}\n";
2544
2545 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01413);
2546 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
2547 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
2548
2549 VkPipelineObj pipe(m_device);
2550 pipe.AddColorAttachment();
2551 pipe.AddShader(&vs);
2552 pipe.AddShader(&fs);
2553
2554 pipe.AddVertexInputBindings(&input_binding, 1);
2555 pipe.AddVertexInputAttribs(&input_attribs, 1);
2556
2557 VkDescriptorSetObj descriptorSet(m_device);
2558 descriptorSet.AppendDummy();
2559 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
2560
2561 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
2562
2563 m_errorMonitor->VerifyFound();
2564}
2565
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002566TEST_F(VkLayerTest, ImageSampleCounts) {
2567
2568 TEST_DESCRIPTION("Use bad sample counts in image transfer calls to trigger "
2569 "validation errors.");
2570 ASSERT_NO_FATAL_FAILURE(InitState());
2571
2572 VkMemoryPropertyFlags reqs = 0;
2573 VkImageCreateInfo image_create_info = {};
2574 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2575 image_create_info.pNext = NULL;
2576 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2577 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
2578 image_create_info.extent.width = 256;
2579 image_create_info.extent.height = 256;
2580 image_create_info.extent.depth = 1;
2581 image_create_info.mipLevels = 1;
2582 image_create_info.arrayLayers = 1;
2583 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
2584 image_create_info.flags = 0;
2585
2586 VkImageBlit blit_region = {};
2587 blit_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2588 blit_region.srcSubresource.baseArrayLayer = 0;
2589 blit_region.srcSubresource.layerCount = 1;
2590 blit_region.srcSubresource.mipLevel = 0;
2591 blit_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2592 blit_region.dstSubresource.baseArrayLayer = 0;
2593 blit_region.dstSubresource.layerCount = 1;
2594 blit_region.dstSubresource.mipLevel = 0;
2595
2596 // Create two images, the source with sampleCount = 2, and attempt to blit
2597 // between them
2598 {
2599 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002600 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002601 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002602 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002603 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002604 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002605 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002606 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002607 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002608 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "was created with a sample count "
2609 "of VK_SAMPLE_COUNT_2_BIT but "
2610 "must be VK_SAMPLE_COUNT_1_BIT");
2611 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
2612 dst_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, 1, &blit_region, VK_FILTER_NEAREST);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002613 m_errorMonitor->VerifyFound();
2614 m_commandBuffer->EndCommandBuffer();
2615 }
2616
2617 // Create two images, the dest with sampleCount = 4, and attempt to blit
2618 // between them
2619 {
2620 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002621 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002622 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002623 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002624 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002625 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002626 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002627 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002628 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002629 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "was created with a sample count "
2630 "of VK_SAMPLE_COUNT_4_BIT but "
2631 "must be VK_SAMPLE_COUNT_1_BIT");
2632 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
2633 dst_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, 1, &blit_region, VK_FILTER_NEAREST);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002634 m_errorMonitor->VerifyFound();
2635 m_commandBuffer->EndCommandBuffer();
2636 }
2637
2638 VkBufferImageCopy copy_region = {};
2639 copy_region.bufferRowLength = 128;
2640 copy_region.bufferImageHeight = 128;
2641 copy_region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2642 copy_region.imageSubresource.layerCount = 1;
2643 copy_region.imageExtent.height = 64;
2644 copy_region.imageExtent.width = 64;
2645 copy_region.imageExtent.depth = 1;
2646
2647 // Create src buffer and dst image with sampleCount = 4 and attempt to copy
2648 // buffer to image
2649 {
2650 vk_testing::Buffer src_buffer;
2651 VkMemoryPropertyFlags reqs = 0;
2652 src_buffer.init_as_src(*m_device, 128 * 128 * 4, reqs);
2653 image_create_info.samples = VK_SAMPLE_COUNT_8_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002654 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002655 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002656 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002657 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002658 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "was created with a sample count "
2659 "of VK_SAMPLE_COUNT_8_BIT but "
2660 "must be VK_SAMPLE_COUNT_1_BIT");
2661 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), src_buffer.handle(), dst_image.handle(),
2662 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &copy_region);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002663 m_errorMonitor->VerifyFound();
2664 m_commandBuffer->EndCommandBuffer();
2665 }
2666
2667 // Create dst buffer and src image with sampleCount = 2 and attempt to copy
2668 // image to buffer
2669 {
2670 vk_testing::Buffer dst_buffer;
2671 dst_buffer.init_as_dst(*m_device, 128 * 128 * 4, reqs);
2672 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002673 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002674 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002675 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002676 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002677 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "was created with a sample count "
2678 "of VK_SAMPLE_COUNT_2_BIT but "
2679 "must be VK_SAMPLE_COUNT_1_BIT");
2680 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002681 dst_buffer.handle(), 1, &copy_region);
2682 m_errorMonitor->VerifyFound();
2683 m_commandBuffer->EndCommandBuffer();
2684 }
2685}
2686
Mike Stroyanac5afeb2016-10-17 13:58:10 -06002687TEST_F(VkLayerTest, BlitImageFormats) {
Mike Stroyanac5afeb2016-10-17 13:58:10 -06002688 ASSERT_NO_FATAL_FAILURE(InitState());
2689
2690 VkImageObj src_image(m_device);
2691 src_image.init(64, 64, VK_FORMAT_A2B10G10R10_UINT_PACK32, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_LINEAR, 0);
2692 VkImageObj dst_image(m_device);
2693 dst_image.init(64, 64, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
2694 VkImageObj dst_image2(m_device);
Mike Stroyan131f3e72016-10-18 11:10:23 -06002695 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 -06002696
2697 VkImageBlit blitRegion = {};
2698 blitRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2699 blitRegion.srcSubresource.baseArrayLayer = 0;
2700 blitRegion.srcSubresource.layerCount = 1;
2701 blitRegion.srcSubresource.mipLevel = 0;
2702 blitRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2703 blitRegion.dstSubresource.baseArrayLayer = 0;
2704 blitRegion.dstSubresource.layerCount = 1;
2705 blitRegion.dstSubresource.mipLevel = 0;
2706
Dave Houlton34df4cb2016-12-01 16:43:06 -07002707 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02191);
2708
2709 // TODO: there are 9 permutations of signed, unsigned, & other for source and dest
2710 // this test is only checking 2 of them at the moment
Mike Stroyanac5afeb2016-10-17 13:58:10 -06002711
2712 // Unsigned int vs not an int
2713 BeginCommandBuffer();
2714 vkCmdBlitImage(m_commandBuffer->handle(), src_image.image(), src_image.layout(), dst_image.image(),
2715 dst_image.layout(), 1, &blitRegion, VK_FILTER_NEAREST);
2716
2717 m_errorMonitor->VerifyFound();
2718
Dave Houlton34df4cb2016-12-01 16:43:06 -07002719 // Test should generate 2 VU failures
2720 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02190);
2721 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02191);
Mike Stroyanac5afeb2016-10-17 13:58:10 -06002722
2723 // Unsigned int vs signed int
2724 vkCmdBlitImage(m_commandBuffer->handle(), src_image.image(), src_image.layout(), dst_image2.image(),
2725 dst_image2.layout(), 1, &blitRegion, VK_FILTER_NEAREST);
2726
Dave Houlton34df4cb2016-12-01 16:43:06 -07002727 // TODO: Note that this only verifies that at least one of the VU enums was found
2728 // Also, if any were not seen, they'll remain in the target list (Soln TBD, JIRA task: VL-72)
Mike Stroyanac5afeb2016-10-17 13:58:10 -06002729 m_errorMonitor->VerifyFound();
2730
2731 EndCommandBuffer();
2732}
2733
2734
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002735TEST_F(VkLayerTest, DSImageTransferGranularityTests) {
2736 VkResult err;
2737 bool pass;
2738
2739 TEST_DESCRIPTION("Tests for validaiton of Queue Family property minImageTransferGranularity.");
2740 ASSERT_NO_FATAL_FAILURE(InitState());
2741
2742 // If w/d/h granularity is 1, test is not meaningful
2743 // TODO: When virtual device limits are available, create a set of limits for this test that
2744 // will always have a granularity of > 1 for w, h, and d
2745 auto index = m_device->graphics_queue_node_index_;
2746 auto queue_family_properties = m_device->phy().queue_properties();
2747
2748 if ((queue_family_properties[index].minImageTransferGranularity.depth < 4) ||
2749 (queue_family_properties[index].minImageTransferGranularity.width < 4) ||
2750 (queue_family_properties[index].minImageTransferGranularity.height < 4)) {
2751 return;
2752 }
2753
2754 // Create two images of different types and try to copy between them
2755 VkImage srcImage;
2756 VkImage dstImage;
2757 VkDeviceMemory srcMem;
2758 VkDeviceMemory destMem;
2759 VkMemoryRequirements memReqs;
2760
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002761 VkImageCreateInfo image_create_info = {};
2762 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2763 image_create_info.pNext = NULL;
2764 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2765 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
2766 image_create_info.extent.width = 32;
2767 image_create_info.extent.height = 32;
2768 image_create_info.extent.depth = 1;
2769 image_create_info.mipLevels = 1;
2770 image_create_info.arrayLayers = 4;
2771 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2772 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
2773 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
2774 image_create_info.flags = 0;
2775
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002776 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002777 ASSERT_VK_SUCCESS(err);
2778
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002779 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002780 ASSERT_VK_SUCCESS(err);
2781
2782 // Allocate memory
2783 VkMemoryAllocateInfo memAlloc = {};
2784 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2785 memAlloc.pNext = NULL;
2786 memAlloc.allocationSize = 0;
2787 memAlloc.memoryTypeIndex = 0;
2788
2789 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
2790 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002791 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002792 ASSERT_TRUE(pass);
2793 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
2794 ASSERT_VK_SUCCESS(err);
2795
2796 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
2797 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002798 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002799 ASSERT_VK_SUCCESS(err);
2800 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
2801 ASSERT_VK_SUCCESS(err);
2802
2803 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
2804 ASSERT_VK_SUCCESS(err);
2805 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
2806 ASSERT_VK_SUCCESS(err);
2807
2808 BeginCommandBuffer();
2809 VkImageCopy copyRegion;
2810 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2811 copyRegion.srcSubresource.mipLevel = 0;
2812 copyRegion.srcSubresource.baseArrayLayer = 0;
2813 copyRegion.srcSubresource.layerCount = 1;
2814 copyRegion.srcOffset.x = 0;
2815 copyRegion.srcOffset.y = 0;
2816 copyRegion.srcOffset.z = 0;
2817 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2818 copyRegion.dstSubresource.mipLevel = 0;
2819 copyRegion.dstSubresource.baseArrayLayer = 0;
2820 copyRegion.dstSubresource.layerCount = 1;
2821 copyRegion.dstOffset.x = 0;
2822 copyRegion.dstOffset.y = 0;
2823 copyRegion.dstOffset.z = 0;
2824 copyRegion.extent.width = 1;
2825 copyRegion.extent.height = 1;
2826 copyRegion.extent.depth = 1;
2827
2828 // Introduce failure by setting srcOffset to a bad granularity value
2829 copyRegion.srcOffset.y = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002830 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2831 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002832 m_errorMonitor->VerifyFound();
2833
2834 // Introduce failure by setting extent to a bad granularity value
2835 copyRegion.srcOffset.y = 0;
2836 copyRegion.extent.width = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002837 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2838 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002839 m_errorMonitor->VerifyFound();
2840
2841 // Now do some buffer/image copies
2842 vk_testing::Buffer buffer;
2843 VkMemoryPropertyFlags reqs = 0;
2844 buffer.init_as_dst(*m_device, 128 * 128, reqs);
2845 VkBufferImageCopy region = {};
2846 region.bufferOffset = 0;
2847 region.bufferRowLength = 3;
2848 region.bufferImageHeight = 128;
2849 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2850 region.imageSubresource.layerCount = 1;
2851 region.imageExtent.height = 16;
2852 region.imageExtent.width = 16;
2853 region.imageExtent.depth = 1;
2854 region.imageOffset.x = 0;
2855 region.imageOffset.y = 0;
2856 region.imageOffset.z = 0;
2857
2858 // Introduce failure by setting bufferRowLength to a bad granularity value
2859 region.bufferRowLength = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002860 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2861 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
2862 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002863 m_errorMonitor->VerifyFound();
2864 region.bufferRowLength = 128;
2865
2866 // Introduce failure by setting bufferOffset to a bad granularity value
2867 region.bufferOffset = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002868 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2869 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
2870 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002871 m_errorMonitor->VerifyFound();
2872 region.bufferOffset = 0;
2873
2874 // Introduce failure by setting bufferImageHeight to a bad granularity value
2875 region.bufferImageHeight = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002876 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2877 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
2878 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002879 m_errorMonitor->VerifyFound();
2880 region.bufferImageHeight = 128;
2881
2882 // Introduce failure by setting imageExtent to a bad granularity value
2883 region.imageExtent.width = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002884 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2885 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
2886 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002887 m_errorMonitor->VerifyFound();
2888 region.imageExtent.width = 16;
2889
2890 // Introduce failure by setting imageOffset to a bad granularity value
2891 region.imageOffset.z = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002892 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2893 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
2894 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002895 m_errorMonitor->VerifyFound();
2896
2897 EndCommandBuffer();
2898
2899 vkDestroyImage(m_device->device(), srcImage, NULL);
2900 vkDestroyImage(m_device->device(), dstImage, NULL);
2901 vkFreeMemory(m_device->device(), srcMem, NULL);
2902 vkFreeMemory(m_device->device(), destMem, NULL);
2903}
2904
Mark Lobodzinski570efc62016-08-09 16:43:19 -06002905TEST_F(VkLayerTest, MismatchedQueueFamiliesOnSubmit) {
Mark Lobodzinski570efc62016-08-09 16:43:19 -06002906 TEST_DESCRIPTION("Submit command buffer created using one queue family and "
2907 "attempt to submit them on a queue created in a different "
2908 "queue family.");
2909
Cody Northropc31a84f2016-08-22 10:41:47 -06002910 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski570efc62016-08-09 16:43:19 -06002911 // This test is meaningless unless we have multiple queue families
2912 auto queue_family_properties = m_device->phy().queue_properties();
2913 if (queue_family_properties.size() < 2) {
2914 return;
2915 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002916 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is being submitted on queue ");
Mark Lobodzinski570efc62016-08-09 16:43:19 -06002917 // Get safe index of another queue family
2918 uint32_t other_queue_family = (m_device->graphics_queue_node_index_ == 0) ? 1 : 0;
2919 ASSERT_NO_FATAL_FAILURE(InitState());
2920 // Create a second queue using a different queue family
2921 VkQueue other_queue;
2922 vkGetDeviceQueue(m_device->device(), other_queue_family, 0, &other_queue);
2923
2924 // Record an empty cmd buffer
2925 VkCommandBufferBeginInfo cmdBufBeginDesc = {};
2926 cmdBufBeginDesc.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
2927 vkBeginCommandBuffer(m_commandBuffer->handle(), &cmdBufBeginDesc);
2928 vkEndCommandBuffer(m_commandBuffer->handle());
2929
2930 // And submit on the wrong queue
2931 VkSubmitInfo submit_info = {};
2932 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
2933 submit_info.commandBufferCount = 1;
2934 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Tobin Ehlisfd213ea2016-08-10 17:10:46 -06002935 vkQueueSubmit(other_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Lobodzinski570efc62016-08-09 16:43:19 -06002936
2937 m_errorMonitor->VerifyFound();
Mark Lobodzinski570efc62016-08-09 16:43:19 -06002938}
2939
Chris Forbes4c24a922016-11-16 08:59:10 +13002940TEST_F(VkLayerTest, RenderPassAttachmentIndexOutOfRange) {
2941 ASSERT_NO_FATAL_FAILURE(InitState());
2942
Chris Forbes2d9b2a82016-11-21 10:45:39 +13002943 // There are no attachments, but refer to attachment 0.
2944 VkAttachmentReference ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Chris Forbes4c24a922016-11-16 08:59:10 +13002945 VkSubpassDescription subpasses[] = {
Chris Forbes2d9b2a82016-11-21 10:45:39 +13002946 {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &ref, nullptr,
2947 nullptr, 0, nullptr},
Chris Forbes4c24a922016-11-16 08:59:10 +13002948 };
2949
Chris Forbes2d9b2a82016-11-21 10:45:39 +13002950 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO,
2951 nullptr,
2952 0,
2953 0,
2954 nullptr,
2955 1,
2956 subpasses,
2957 0,
2958 nullptr};
Chris Forbes4c24a922016-11-16 08:59:10 +13002959 VkRenderPass rp;
2960
Chris Forbes2d9b2a82016-11-21 10:45:39 +13002961 // "... must be less than the total number of attachments ..."
Chris Forbes4c24a922016-11-16 08:59:10 +13002962 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbes2d9b2a82016-11-21 10:45:39 +13002963 VALIDATION_ERROR_00325);
Chris Forbes4c24a922016-11-16 08:59:10 +13002964 vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
2965 m_errorMonitor->VerifyFound();
2966}
2967
Chris Forbesa58c4522016-09-28 15:19:39 +13002968TEST_F(VkLayerTest, RenderPassPipelineSubpassMismatch) {
2969 TEST_DESCRIPTION("Use a pipeline for the wrong subpass in a render pass instance");
2970 ASSERT_NO_FATAL_FAILURE(InitState());
2971
2972 // A renderpass with two subpasses, both writing the same attachment.
2973 VkAttachmentDescription attach[] = {
2974 { 0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT,
2975 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
2976 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
2977 VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL
2978 },
2979 };
2980 VkAttachmentReference ref = { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
2981 VkSubpassDescription subpasses[] = {
2982 { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr,
2983 1, &ref, nullptr, nullptr, 0, nullptr },
2984 { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr,
2985 1, &ref, nullptr, nullptr, 0, nullptr },
2986 };
2987 VkSubpassDependency dep = {
2988 0, 1,
2989 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
2990 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
2991 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
2992 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
2993 VK_DEPENDENCY_BY_REGION_BIT
2994 };
2995 VkRenderPassCreateInfo rpci = {
2996 VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr,
2997 0, 1, attach, 2, subpasses, 1, &dep
2998 };
2999 VkRenderPass rp;
3000 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3001 ASSERT_VK_SUCCESS(err);
3002
3003 VkImageObj image(m_device);
3004 image.init_no_layout(32, 32, VK_FORMAT_R8G8B8A8_UNORM,
3005 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT,
3006 VK_IMAGE_TILING_OPTIMAL, 0);
3007 VkImageView imageView = image.targetView(VK_FORMAT_R8G8B8A8_UNORM);
3008
3009 VkFramebufferCreateInfo fbci = {
3010 VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr,
3011 0, rp, 1, &imageView, 32, 32, 1
3012 };
3013 VkFramebuffer fb;
3014 err = vkCreateFramebuffer(m_device->device(), &fbci, nullptr, &fb);
3015 ASSERT_VK_SUCCESS(err);
3016
3017 char const *vsSource =
3018 "#version 450\n"
3019 "void main() { gl_Position = vec4(1); }\n";
3020 char const *fsSource =
3021 "#version 450\n"
3022 "layout(location=0) out vec4 color;\n"
3023 "void main() { color = vec4(1); }\n";
3024
3025 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
3026 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
3027 VkPipelineObj pipe(m_device);
3028 pipe.AddColorAttachment();
3029 pipe.AddShader(&vs);
3030 pipe.AddShader(&fs);
3031 VkViewport view_port = {};
3032 m_viewports.push_back(view_port);
3033 pipe.SetViewport(m_viewports);
3034 VkRect2D rect = {};
3035 m_scissors.push_back(rect);
3036 pipe.SetScissor(m_scissors);
3037
3038 VkPipelineLayoutCreateInfo plci = {
3039 VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr,
3040 0, 0, nullptr, 0, nullptr
3041 };
3042 VkPipelineLayout pl;
3043 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
3044 ASSERT_VK_SUCCESS(err);
3045 pipe.CreateVKPipeline(pl, rp);
3046
3047 BeginCommandBuffer();
3048
3049 VkRenderPassBeginInfo rpbi = {
3050 VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr,
3051 rp, fb, { { 0, 0, }, { 32, 32 } }, 0, nullptr
3052 };
3053
3054 // subtest 1: bind in the wrong subpass
3055 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
3056 vkCmdNextSubpass(m_commandBuffer->handle(), VK_SUBPASS_CONTENTS_INLINE);
3057 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3058 "built for subpass 0 but used in subpass 1");
3059 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
3060 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
3061 m_errorMonitor->VerifyFound();
3062
3063 vkCmdEndRenderPass(m_commandBuffer->handle());
3064
3065 // subtest 2: bind in correct subpass, then transition to next subpass
3066 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
3067 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
3068 vkCmdNextSubpass(m_commandBuffer->handle(), VK_SUBPASS_CONTENTS_INLINE);
3069 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3070 "built for subpass 0 but used in subpass 1");
3071 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
3072 m_errorMonitor->VerifyFound();
3073
3074 vkCmdEndRenderPass(m_commandBuffer->handle());
3075
3076 EndCommandBuffer();
3077
3078 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
3079 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
3080 vkDestroyRenderPass(m_device->device(), rp, nullptr);
3081}
3082
Tony Barbour4e919972016-08-09 13:27:40 -06003083TEST_F(VkLayerTest, RenderPassInvalidRenderArea) {
3084 TEST_DESCRIPTION("Generate INVALID_RENDER_AREA error by beginning renderpass"
3085 "with extent outside of framebuffer");
3086 ASSERT_NO_FATAL_FAILURE(InitState());
3087 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3088
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003089 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot execute a render pass with renderArea "
3090 "not within the bound of the framebuffer.");
Tony Barbour4e919972016-08-09 13:27:40 -06003091
3092 // Framebuffer for render target is 256x256, exceed that for INVALID_RENDER_AREA
3093 m_renderPassBeginInfo.renderArea.extent.width = 257;
3094 m_renderPassBeginInfo.renderArea.extent.height = 257;
3095 BeginCommandBuffer();
3096 m_errorMonitor->VerifyFound();
3097}
3098
3099TEST_F(VkLayerTest, DisabledIndependentBlend) {
3100 TEST_DESCRIPTION("Generate INDEPENDENT_BLEND by disabling independent "
3101 "blend and then specifying different blend states for two "
3102 "attachements");
Cody Northrop5703cc72016-08-19 09:57:10 -06003103 VkPhysicalDeviceFeatures features = {};
3104 features.independentBlend = VK_FALSE;
Cody Northropc31a84f2016-08-22 10:41:47 -06003105 ASSERT_NO_FATAL_FAILURE(InitState(&features));
Tony Barbour4e919972016-08-09 13:27:40 -06003106
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003107 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3108 "Invalid Pipeline CreateInfo: If independent blend feature not "
3109 "enabled, all elements of pAttachments must be identical");
Tony Barbour4e919972016-08-09 13:27:40 -06003110
Cody Northropc31a84f2016-08-22 10:41:47 -06003111 VkDescriptorSetObj descriptorSet(m_device);
3112 descriptorSet.AppendDummy();
3113 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Tony Barbour4e919972016-08-09 13:27:40 -06003114
Cody Northropc31a84f2016-08-22 10:41:47 -06003115 VkPipelineObj pipeline(m_device);
3116 VkRenderpassObj renderpass(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003117 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Cody Northropc31a84f2016-08-22 10:41:47 -06003118 pipeline.AddShader(&vs);
Cody Northrop5703cc72016-08-19 09:57:10 -06003119
Cody Northropc31a84f2016-08-22 10:41:47 -06003120 VkPipelineColorBlendAttachmentState att_state1 = {}, att_state2 = {};
3121 att_state1.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
3122 att_state1.blendEnable = VK_TRUE;
3123 att_state2.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
3124 att_state2.blendEnable = VK_FALSE;
3125 pipeline.AddColorAttachment(0, &att_state1);
3126 pipeline.AddColorAttachment(1, &att_state2);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003127 pipeline.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderpass.handle());
Cody Northropc31a84f2016-08-22 10:41:47 -06003128 m_errorMonitor->VerifyFound();
Tony Barbour4e919972016-08-09 13:27:40 -06003129}
3130
Chris Forbes26ec2122016-11-29 08:58:33 +13003131#if 0
Tony Barbour4e919972016-08-09 13:27:40 -06003132TEST_F(VkLayerTest, RenderPassDepthStencilAttachmentUnused) {
3133 TEST_DESCRIPTION("Specify no depth attachement in renderpass then specify "
3134 "depth attachments in subpass");
Cody Northropc31a84f2016-08-22 10:41:47 -06003135 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbour4e919972016-08-09 13:27:40 -06003136
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003137 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3138 "vkCreateRenderPass has no depth/stencil attachment, yet subpass");
Tony Barbour4e919972016-08-09 13:27:40 -06003139
3140 // Create a renderPass with a single color attachment
3141 VkAttachmentReference attach = {};
3142 attach.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
3143 VkSubpassDescription subpass = {};
3144 VkRenderPassCreateInfo rpci = {};
3145 rpci.subpassCount = 1;
3146 rpci.pSubpasses = &subpass;
3147 rpci.attachmentCount = 1;
3148 VkAttachmentDescription attach_desc = {};
3149 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
3150 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
3151 rpci.pAttachments = &attach_desc;
3152 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3153 VkRenderPass rp;
3154 subpass.pDepthStencilAttachment = &attach;
3155 subpass.pColorAttachments = NULL;
3156 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3157 m_errorMonitor->VerifyFound();
3158}
Chris Forbes26ec2122016-11-29 08:58:33 +13003159#endif
Tony Barbour4e919972016-08-09 13:27:40 -06003160
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003161TEST_F(VkLayerTest, UnusedPreserveAttachment) {
3162 TEST_DESCRIPTION("Create a framebuffer where a subpass has a preserve "
3163 "attachment reference of VK_ATTACHMENT_UNUSED");
3164
3165 ASSERT_NO_FATAL_FAILURE(InitState());
3166 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3167
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003168 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "must not be VK_ATTACHMENT_UNUSED");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003169
3170 VkAttachmentReference color_attach = {};
3171 color_attach.layout = VK_IMAGE_LAYOUT_GENERAL;
3172 color_attach.attachment = 0;
3173 uint32_t preserve_attachment = VK_ATTACHMENT_UNUSED;
3174 VkSubpassDescription subpass = {};
3175 subpass.colorAttachmentCount = 1;
3176 subpass.pColorAttachments = &color_attach;
3177 subpass.preserveAttachmentCount = 1;
3178 subpass.pPreserveAttachments = &preserve_attachment;
3179
3180 VkRenderPassCreateInfo rpci = {};
3181 rpci.subpassCount = 1;
3182 rpci.pSubpasses = &subpass;
3183 rpci.attachmentCount = 1;
3184 VkAttachmentDescription attach_desc = {};
3185 attach_desc.format = VK_FORMAT_UNDEFINED;
3186 rpci.pAttachments = &attach_desc;
3187 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3188 VkRenderPass rp;
Mark Lobodzinskia4feeeb2016-06-17 12:00:46 -06003189 VkResult result = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003190
3191 m_errorMonitor->VerifyFound();
3192
Mark Lobodzinskia4feeeb2016-06-17 12:00:46 -06003193 if (result == VK_SUCCESS) {
3194 vkDestroyRenderPass(m_device->device(), rp, NULL);
3195 }
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003196}
3197
Chris Forbesc5389742016-06-29 11:49:23 +12003198TEST_F(VkLayerTest, CreateRenderPassResolveRequiresColorMsaa) {
Chris Forbes6655bb32016-07-01 18:27:30 +12003199 TEST_DESCRIPTION("Ensure that CreateRenderPass produces a validation error "
3200 "when the source of a subpass multisample resolve "
3201 "does not have multiple samples.");
3202
Chris Forbesc5389742016-06-29 11:49:23 +12003203 ASSERT_NO_FATAL_FAILURE(InitState());
3204
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003205 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3206 "Subpass 0 requests multisample resolve from attachment 0 which has "
3207 "VK_SAMPLE_COUNT_1_BIT");
Chris Forbesc5389742016-06-29 11:49:23 +12003208
3209 VkAttachmentDescription attachments[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003210 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3211 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3212 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3213 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3214 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3215 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbesc5389742016-06-29 11:49:23 +12003216 };
3217
3218 VkAttachmentReference color = {
3219 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3220 };
3221
3222 VkAttachmentReference resolve = {
3223 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3224 };
3225
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003226 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &color, &resolve, nullptr, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003227
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003228 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003229
3230 VkRenderPass rp;
3231 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3232
3233 m_errorMonitor->VerifyFound();
3234
3235 if (err == VK_SUCCESS)
3236 vkDestroyRenderPass(m_device->device(), rp, nullptr);
3237}
3238
3239TEST_F(VkLayerTest, CreateRenderPassResolveRequiresSingleSampleDest) {
Chris Forbes6655bb32016-07-01 18:27:30 +12003240 TEST_DESCRIPTION("Ensure CreateRenderPass produces a validation error "
3241 "when a subpass multisample resolve operation is "
3242 "requested, and the destination of that resolve has "
3243 "multiple samples.");
3244
Chris Forbesc5389742016-06-29 11:49:23 +12003245 ASSERT_NO_FATAL_FAILURE(InitState());
3246
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003247 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3248 "Subpass 0 requests multisample resolve into attachment 1, which "
3249 "must have VK_SAMPLE_COUNT_1_BIT but has VK_SAMPLE_COUNT_4_BIT");
Chris Forbesc5389742016-06-29 11:49:23 +12003250
3251 VkAttachmentDescription attachments[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003252 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3253 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3254 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3255 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3256 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3257 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbesc5389742016-06-29 11:49:23 +12003258 };
3259
3260 VkAttachmentReference color = {
3261 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3262 };
3263
3264 VkAttachmentReference resolve = {
3265 1, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3266 };
3267
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003268 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &color, &resolve, nullptr, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003269
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003270 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003271
3272 VkRenderPass rp;
3273 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3274
3275 m_errorMonitor->VerifyFound();
3276
3277 if (err == VK_SUCCESS)
3278 vkDestroyRenderPass(m_device->device(), rp, nullptr);
3279}
3280
Chris Forbes3f128ef2016-06-29 14:58:53 +12003281TEST_F(VkLayerTest, CreateRenderPassSubpassSampleCountConsistency) {
Chris Forbes6655bb32016-07-01 18:27:30 +12003282 TEST_DESCRIPTION("Ensure CreateRenderPass produces a validation error "
3283 "when the color and depth attachments used by a subpass "
3284 "have inconsistent sample counts");
3285
Chris Forbes3f128ef2016-06-29 14:58:53 +12003286 ASSERT_NO_FATAL_FAILURE(InitState());
3287
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003288 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3289 "Subpass 0 attempts to render to attachments with inconsistent sample counts");
Chris Forbes3f128ef2016-06-29 14:58:53 +12003290
3291 VkAttachmentDescription attachments[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003292 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3293 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3294 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3295 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3296 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3297 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbes3f128ef2016-06-29 14:58:53 +12003298 };
3299
3300 VkAttachmentReference color[] = {
3301 {
3302 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3303 },
3304 {
3305 1, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3306 },
3307 };
3308
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003309 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 2, color, nullptr, nullptr, 0, nullptr};
Chris Forbes3f128ef2016-06-29 14:58:53 +12003310
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003311 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbes3f128ef2016-06-29 14:58:53 +12003312
3313 VkRenderPass rp;
3314 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3315
3316 m_errorMonitor->VerifyFound();
3317
3318 if (err == VK_SUCCESS)
3319 vkDestroyRenderPass(m_device->device(), rp, nullptr);
3320}
3321
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003322TEST_F(VkLayerTest, FramebufferCreateErrors) {
3323 TEST_DESCRIPTION("Hit errors when attempting to create a framebuffer :\n"
Mike Weiblencce7ec72016-10-17 19:33:05 -06003324 " 1. Mismatch between framebuffer & renderPass attachmentCount\n"
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003325 " 2. Use a color image as depthStencil attachment\n"
Mike Weiblencce7ec72016-10-17 19:33:05 -06003326 " 3. Mismatch framebuffer & renderPass attachment formats\n"
3327 " 4. Mismatch framebuffer & renderPass attachment #samples\n"
3328 " 5. Framebuffer attachment w/ non-1 mip-levels\n"
3329 " 6. Framebuffer attachment where dimensions don't match\n"
3330 " 7. Framebuffer attachment w/o identity swizzle\n"
3331 " 8. framebuffer dimensions exceed physical device limits\n");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003332
3333 ASSERT_NO_FATAL_FAILURE(InitState());
3334 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3335
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003336 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3337 "vkCreateFramebuffer(): VkFramebufferCreateInfo attachmentCount of 2 "
3338 "does not match attachmentCount of 1 of ");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003339
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003340 // Create a renderPass with a single color attachment
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003341 VkAttachmentReference attach = {};
3342 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
3343 VkSubpassDescription subpass = {};
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003344 subpass.pColorAttachments = &attach;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003345 VkRenderPassCreateInfo rpci = {};
3346 rpci.subpassCount = 1;
3347 rpci.pSubpasses = &subpass;
3348 rpci.attachmentCount = 1;
3349 VkAttachmentDescription attach_desc = {};
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003350 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis77d717c2016-06-22 14:19:19 -06003351 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003352 rpci.pAttachments = &attach_desc;
3353 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3354 VkRenderPass rp;
3355 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3356 ASSERT_VK_SUCCESS(err);
3357
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003358 VkImageView ivs[2];
3359 ivs[0] = m_renderTargets[0]->targetView(VK_FORMAT_B8G8R8A8_UNORM);
3360 ivs[1] = m_renderTargets[0]->targetView(VK_FORMAT_B8G8R8A8_UNORM);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003361 VkFramebufferCreateInfo fb_info = {};
3362 fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
3363 fb_info.pNext = NULL;
3364 fb_info.renderPass = rp;
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003365 // Set mis-matching attachmentCount
3366 fb_info.attachmentCount = 2;
3367 fb_info.pAttachments = ivs;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003368 fb_info.width = 100;
3369 fb_info.height = 100;
3370 fb_info.layers = 1;
3371
3372 VkFramebuffer fb;
3373 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3374
3375 m_errorMonitor->VerifyFound();
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003376 if (err == VK_SUCCESS) {
3377 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3378 }
3379 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003380
3381 // Create a renderPass with a depth-stencil attachment created with
3382 // IMAGE_USAGE_COLOR_ATTACHMENT
3383 // Add our color attachment to pDepthStencilAttachment
3384 subpass.pDepthStencilAttachment = &attach;
3385 subpass.pColorAttachments = NULL;
3386 VkRenderPass rp_ds;
3387 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp_ds);
3388 ASSERT_VK_SUCCESS(err);
3389 // Set correct attachment count, but attachment has COLOR usage bit set
3390 fb_info.attachmentCount = 1;
3391 fb_info.renderPass = rp_ds;
3392
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003393 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " conflicts with the image's IMAGE_USAGE flags ");
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003394 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3395
3396 m_errorMonitor->VerifyFound();
3397 if (err == VK_SUCCESS) {
3398 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3399 }
3400 vkDestroyRenderPass(m_device->device(), rp_ds, NULL);
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003401
3402 // Create new renderpass with alternate attachment format from fb
3403 attach_desc.format = VK_FORMAT_R8G8B8A8_UNORM;
3404 subpass.pDepthStencilAttachment = NULL;
3405 subpass.pColorAttachments = &attach;
3406 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3407 ASSERT_VK_SUCCESS(err);
3408
3409 // Cause error due to mis-matched formats between rp & fb
3410 // rp attachment 0 now has RGBA8 but corresponding fb attach is BGRA8
3411 fb_info.renderPass = rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003412 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3413 " has format of VK_FORMAT_B8G8R8A8_UNORM that does not match ");
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003414 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3415
3416 m_errorMonitor->VerifyFound();
3417 if (err == VK_SUCCESS) {
3418 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3419 }
Tobin Ehlis77d717c2016-06-22 14:19:19 -06003420 vkDestroyRenderPass(m_device->device(), rp, NULL);
3421
3422 // Create new renderpass with alternate sample count from fb
3423 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
3424 attach_desc.samples = VK_SAMPLE_COUNT_4_BIT;
3425 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3426 ASSERT_VK_SUCCESS(err);
3427
3428 // Cause error due to mis-matched sample count between rp & fb
3429 fb_info.renderPass = rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003430 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has VK_SAMPLE_COUNT_1_BIT samples "
3431 "that do not match the "
3432 "VK_SAMPLE_COUNT_4_BIT ");
Tobin Ehlis77d717c2016-06-22 14:19:19 -06003433 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3434
3435 m_errorMonitor->VerifyFound();
3436 if (err == VK_SUCCESS) {
3437 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3438 }
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003439
3440 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003441
3442 // Create a custom imageView with non-1 mip levels
3443 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003444 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 -06003445 ASSERT_TRUE(image.initialized());
3446
3447 VkImageView view;
3448 VkImageViewCreateInfo ivci = {};
3449 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
3450 ivci.image = image.handle();
3451 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
3452 ivci.format = VK_FORMAT_B8G8R8A8_UNORM;
3453 ivci.subresourceRange.layerCount = 1;
3454 ivci.subresourceRange.baseMipLevel = 0;
3455 // Set level count 2 (only 1 is allowed for FB attachment)
3456 ivci.subresourceRange.levelCount = 2;
3457 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3458 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
3459 ASSERT_VK_SUCCESS(err);
3460 // Re-create renderpass to have matching sample count
3461 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
3462 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3463 ASSERT_VK_SUCCESS(err);
3464
3465 fb_info.renderPass = rp;
3466 fb_info.pAttachments = &view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003467 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has mip levelCount of 2 but only ");
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003468 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3469
3470 m_errorMonitor->VerifyFound();
3471 if (err == VK_SUCCESS) {
3472 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3473 }
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003474 vkDestroyImageView(m_device->device(), view, NULL);
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06003475 // Update view to original color buffer and grow FB dimensions too big
3476 fb_info.pAttachments = ivs;
3477 fb_info.height = 1024;
3478 fb_info.width = 1024;
3479 fb_info.layers = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003480 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " Attachment dimensions must be at "
3481 "least as large. ");
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06003482 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3483
3484 m_errorMonitor->VerifyFound();
3485 if (err == VK_SUCCESS) {
3486 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3487 }
Tobin Ehlisb1f303b2016-06-23 08:19:55 -06003488 // Create view attachment with non-identity swizzle
3489 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
3490 ivci.image = image.handle();
3491 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
3492 ivci.format = VK_FORMAT_B8G8R8A8_UNORM;
3493 ivci.subresourceRange.layerCount = 1;
3494 ivci.subresourceRange.baseMipLevel = 0;
3495 ivci.subresourceRange.levelCount = 1;
3496 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3497 ivci.components.r = VK_COMPONENT_SWIZZLE_G;
3498 ivci.components.g = VK_COMPONENT_SWIZZLE_R;
3499 ivci.components.b = VK_COMPONENT_SWIZZLE_A;
3500 ivci.components.a = VK_COMPONENT_SWIZZLE_B;
3501 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
3502 ASSERT_VK_SUCCESS(err);
3503
3504 fb_info.pAttachments = &view;
3505 fb_info.height = 100;
3506 fb_info.width = 100;
3507 fb_info.layers = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003508 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has non-identy swizzle. All "
3509 "framebuffer attachments must have "
3510 "been created with the identity "
3511 "swizzle. ");
Tobin Ehlisb1f303b2016-06-23 08:19:55 -06003512 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3513
3514 m_errorMonitor->VerifyFound();
3515 if (err == VK_SUCCESS) {
3516 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3517 }
3518 vkDestroyImageView(m_device->device(), view, NULL);
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06003519 // reset attachment to color attachment
3520 fb_info.pAttachments = ivs;
Mike Schuchardt8fb38062016-12-08 15:36:24 -07003521
3522 // Request fb that exceeds max width
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06003523 fb_info.width = m_device->props.limits.maxFramebufferWidth + 1;
Mike Schuchardt8fb38062016-12-08 15:36:24 -07003524 fb_info.height = 100;
3525 fb_info.layers = 1;
3526 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00413);
3527 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3528
3529 m_errorMonitor->VerifyFound();
3530 if (err == VK_SUCCESS) {
3531 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3532 }
3533
3534 // Request fb that exceeds max height
3535 fb_info.width = 100;
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06003536 fb_info.height = m_device->props.limits.maxFramebufferHeight + 1;
Mike Schuchardt8fb38062016-12-08 15:36:24 -07003537 fb_info.layers = 1;
3538 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00414);
3539 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3540
3541 m_errorMonitor->VerifyFound();
3542 if (err == VK_SUCCESS) {
3543 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3544 }
3545
3546 // Request fb that exceeds max layers
3547 fb_info.width = 100;
3548 fb_info.height = 100;
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06003549 fb_info.layers = m_device->props.limits.maxFramebufferLayers + 1;
Mike Schuchardt8fb38062016-12-08 15:36:24 -07003550 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00415);
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06003551 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3552
3553 m_errorMonitor->VerifyFound();
3554 if (err == VK_SUCCESS) {
3555 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3556 }
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06003557
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003558 vkDestroyRenderPass(m_device->device(), rp, NULL);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003559}
3560
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003561TEST_F(VkLayerTest, DynamicDepthBiasNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003562 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Depth Bias dynamic "
3563 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003564
Cody Northropc31a84f2016-08-22 10:41:47 -06003565 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003566 // Dynamic depth bias
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003567 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic depth bias state not set for this command buffer");
3568 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthBias);
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003569 m_errorMonitor->VerifyFound();
3570}
3571
3572TEST_F(VkLayerTest, DynamicLineWidthNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003573 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Line Width dynamic "
3574 "state is required but not correctly bound.");
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003575
Cody Northropc31a84f2016-08-22 10:41:47 -06003576 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003577 // Dynamic line width
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003578 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic line width state not set for this command buffer");
3579 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailLineWidth);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003580 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003581}
3582
3583TEST_F(VkLayerTest, DynamicViewportNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003584 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Viewport dynamic "
3585 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003586
Cody Northropc31a84f2016-08-22 10:41:47 -06003587 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003588 // Dynamic viewport state
Mike Weiblen95dd0f92016-10-19 12:28:27 -06003589 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 -06003590 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailViewport);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003591 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003592}
3593
3594TEST_F(VkLayerTest, DynamicScissorNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003595 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Scissor dynamic "
3596 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003597
Cody Northropc31a84f2016-08-22 10:41:47 -06003598 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003599 // Dynamic scissor state
Mike Weiblen95dd0f92016-10-19 12:28:27 -06003600 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 -06003601 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailScissor);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003602 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003603}
3604
Cortd713fe82016-07-27 09:51:27 -07003605TEST_F(VkLayerTest, DynamicBlendConstantsNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003606 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Blend Constants "
3607 "dynamic state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003608
3609 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis21c88352016-05-26 06:15:45 -06003610 // Dynamic blend constant state
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003611 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3612 "Dynamic blend constants state not set for this command buffer");
3613 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailBlend);
Tobin Ehlis21c88352016-05-26 06:15:45 -06003614 m_errorMonitor->VerifyFound();
3615}
3616
3617TEST_F(VkLayerTest, DynamicDepthBoundsNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003618 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Depth Bounds dynamic "
3619 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003620
3621 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis21c88352016-05-26 06:15:45 -06003622 if (!m_device->phy().features().depthBounds) {
3623 printf("Device does not support depthBounds test; skipped.\n");
3624 return;
3625 }
3626 // Dynamic depth bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003627 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3628 "Dynamic depth bounds state not set for this command buffer");
3629 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthBounds);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003630 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003631}
3632
3633TEST_F(VkLayerTest, DynamicStencilReadNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003634 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Stencil Read dynamic "
3635 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003636
3637 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003638 // Dynamic stencil read mask
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003639 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3640 "Dynamic stencil read mask state not set for this command buffer");
3641 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilReadMask);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003642 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003643}
3644
3645TEST_F(VkLayerTest, DynamicStencilWriteNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003646 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Stencil Write dynamic"
3647 " state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003648
3649 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003650 // Dynamic stencil write mask
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003651 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3652 "Dynamic stencil write mask state not set for this command buffer");
3653 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilWriteMask);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003654 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003655}
3656
3657TEST_F(VkLayerTest, DynamicStencilRefNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003658 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Stencil Ref dynamic "
3659 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003660
3661 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003662 // Dynamic stencil reference
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003663 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3664 "Dynamic stencil reference state not set for this command buffer");
3665 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilReference);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003666 m_errorMonitor->VerifyFound();
Tobin Ehlis963a4042015-09-29 08:18:34 -06003667}
3668
Tobin Ehlis379ba3b2016-07-19 11:22:29 -06003669TEST_F(VkLayerTest, IndexBufferNotBound) {
3670 TEST_DESCRIPTION("Run an indexed draw call without an index buffer bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003671
3672 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003673 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3674 "Index buffer object not bound to this command buffer when Indexed ");
3675 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailIndexBuffer);
Tobin Ehlis379ba3b2016-07-19 11:22:29 -06003676 m_errorMonitor->VerifyFound();
3677}
3678
Karl Schultz6addd812016-02-02 17:17:23 -07003679TEST_F(VkLayerTest, CommandBufferTwoSubmits) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003680 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3681 "was begun w/ VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set, but has "
3682 "been submitted");
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003683
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003684 ASSERT_NO_FATAL_FAILURE(InitState());
3685 ASSERT_NO_FATAL_FAILURE(InitViewport());
3686 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3687
Karl Schultz6addd812016-02-02 17:17:23 -07003688 // We luck out b/c by default the framework creates CB w/ the
3689 // VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003690 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003691 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003692 EndCommandBuffer();
3693
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003694 // Bypass framework since it does the waits automatically
3695 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06003696 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08003697 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3698 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003699 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06003700 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07003701 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003702 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003703 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08003704 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06003705 submit_info.pSignalSemaphores = NULL;
3706
Chris Forbes40028e22016-06-13 09:59:34 +12003707 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Karl Schultz6addd812016-02-02 17:17:23 -07003708 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski89cad1a2016-11-11 15:51:31 -07003709 vkQueueWaitIdle(m_device->m_queue);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003710
Karl Schultz6addd812016-02-02 17:17:23 -07003711 // Cause validation error by re-submitting cmd buffer that should only be
3712 // submitted once
Chris Forbes40028e22016-06-13 09:59:34 +12003713 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Lobodzinski89cad1a2016-11-11 15:51:31 -07003714 vkQueueWaitIdle(m_device->m_queue);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003715
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003716 m_errorMonitor->VerifyFound();
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003717}
3718
Karl Schultz6addd812016-02-02 17:17:23 -07003719TEST_F(VkLayerTest, AllocDescriptorFromEmptyPool) {
Tobin Ehlis14cd5852016-11-23 12:52:48 -07003720 TEST_DESCRIPTION("Attempt to allocate more sets and descriptors than descriptor pool has available.");
Karl Schultz6addd812016-02-02 17:17:23 -07003721 VkResult err;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003722
3723 ASSERT_NO_FATAL_FAILURE(InitState());
3724 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003725
Karl Schultz6addd812016-02-02 17:17:23 -07003726 // Create Pool w/ 1 Sampler descriptor, but try to alloc Uniform Buffer
3727 // descriptor from it
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003728 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003729 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
Tobin Ehlis14cd5852016-11-23 12:52:48 -07003730 ds_type_count.descriptorCount = 2;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003731
3732 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003733 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3734 ds_pool_ci.pNext = NULL;
3735 ds_pool_ci.flags = 0;
3736 ds_pool_ci.maxSets = 1;
3737 ds_pool_ci.poolSizeCount = 1;
3738 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003739
3740 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003741 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003742 ASSERT_VK_SUCCESS(err);
3743
Tobin Ehlis14cd5852016-11-23 12:52:48 -07003744 VkDescriptorSetLayoutBinding dsl_binding_samp = {};
3745 dsl_binding_samp.binding = 0;
3746 dsl_binding_samp.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
3747 dsl_binding_samp.descriptorCount = 1;
3748 dsl_binding_samp.stageFlags = VK_SHADER_STAGE_ALL;
3749 dsl_binding_samp.pImmutableSamplers = NULL;
3750
3751 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3752 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3753 ds_layout_ci.pNext = NULL;
3754 ds_layout_ci.bindingCount = 1;
3755 ds_layout_ci.pBindings = &dsl_binding_samp;
3756
3757 VkDescriptorSetLayout ds_layout_samp;
3758 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout_samp);
3759 ASSERT_VK_SUCCESS(err);
3760
3761 // Try to allocate 2 sets when pool only has 1 set
3762 VkDescriptorSet descriptor_sets[2];
3763 VkDescriptorSetLayout set_layouts[2] = {ds_layout_samp, ds_layout_samp};
3764 VkDescriptorSetAllocateInfo alloc_info = {};
3765 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
3766 alloc_info.descriptorSetCount = 2;
3767 alloc_info.descriptorPool = ds_pool;
3768 alloc_info.pSetLayouts = set_layouts;
3769 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00911);
3770 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptor_sets);
3771 m_errorMonitor->VerifyFound();
3772
3773 alloc_info.descriptorSetCount = 1;
3774 // Create layout w/ descriptor type not available in pool
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003775 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003776 dsl_binding.binding = 0;
3777 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3778 dsl_binding.descriptorCount = 1;
3779 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3780 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003781
Karl Schultz6addd812016-02-02 17:17:23 -07003782 ds_layout_ci.bindingCount = 1;
3783 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003784
Tobin Ehlis14cd5852016-11-23 12:52:48 -07003785 VkDescriptorSetLayout ds_layout_ub;
3786 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout_ub);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003787 ASSERT_VK_SUCCESS(err);
3788
Tobin Ehlis14cd5852016-11-23 12:52:48 -07003789 VkDescriptorSet descriptor_set;
Jon Ashburnf19916e2016-01-11 13:12:43 -07003790 alloc_info.descriptorSetCount = 1;
Tobin Ehlis14cd5852016-11-23 12:52:48 -07003791 alloc_info.pSetLayouts = &ds_layout_ub;
3792 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00912);
3793 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003794
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003795 m_errorMonitor->VerifyFound();
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003796
Karl Schultz2825ab92016-12-02 08:23:14 -07003797 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_samp, NULL);
Tobin Ehlis14cd5852016-11-23 12:52:48 -07003798 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_ub, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +08003799 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003800}
3801
Karl Schultz6addd812016-02-02 17:17:23 -07003802TEST_F(VkLayerTest, FreeDescriptorFromOneShotPool) {
3803 VkResult err;
Tobin Ehlise735c692015-10-08 13:13:50 -06003804
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003805 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3806 "It is invalid to call vkFreeDescriptorSets() with a pool created "
3807 "without setting VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003808
Tobin Ehlise735c692015-10-08 13:13:50 -06003809 ASSERT_NO_FATAL_FAILURE(InitState());
3810 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise735c692015-10-08 13:13:50 -06003811
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003812 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003813 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3814 ds_type_count.descriptorCount = 1;
Tobin Ehlise735c692015-10-08 13:13:50 -06003815
3816 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003817 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3818 ds_pool_ci.pNext = NULL;
3819 ds_pool_ci.maxSets = 1;
3820 ds_pool_ci.poolSizeCount = 1;
3821 ds_pool_ci.flags = 0;
3822 // Not specifying VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT means
3823 // app can only call vkResetDescriptorPool on this pool.;
3824 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise735c692015-10-08 13:13:50 -06003825
3826 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003827 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise735c692015-10-08 13:13:50 -06003828 ASSERT_VK_SUCCESS(err);
3829
3830 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003831 dsl_binding.binding = 0;
3832 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3833 dsl_binding.descriptorCount = 1;
3834 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3835 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlise735c692015-10-08 13:13:50 -06003836
3837 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003838 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3839 ds_layout_ci.pNext = NULL;
3840 ds_layout_ci.bindingCount = 1;
3841 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise735c692015-10-08 13:13:50 -06003842
3843 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003844 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise735c692015-10-08 13:13:50 -06003845 ASSERT_VK_SUCCESS(err);
3846
3847 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003848 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08003849 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07003850 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06003851 alloc_info.descriptorPool = ds_pool;
3852 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003853 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise735c692015-10-08 13:13:50 -06003854 ASSERT_VK_SUCCESS(err);
3855
3856 err = vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003857 m_errorMonitor->VerifyFound();
Tobin Ehlise735c692015-10-08 13:13:50 -06003858
Chia-I Wuf7458c52015-10-26 21:10:41 +08003859 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3860 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise735c692015-10-08 13:13:50 -06003861}
3862
Karl Schultz6addd812016-02-02 17:17:23 -07003863TEST_F(VkLayerTest, InvalidDescriptorPool) {
Karl Schultzbdb75952016-04-19 11:36:49 -06003864 // Attempt to clear Descriptor Pool with bad object.
3865 // ObjectTracker should catch this.
Cody Northropc31a84f2016-08-22 10:41:47 -06003866
3867 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultzf78bcdd2016-11-30 12:36:01 -07003868 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00930);
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06003869 uint64_t fake_pool_handle = 0xbaad6001;
3870 VkDescriptorPool bad_pool = reinterpret_cast<VkDescriptorPool &>(fake_pool_handle);
3871 vkResetDescriptorPool(device(), bad_pool, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -06003872 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003873}
3874
Karl Schultzf78bcdd2016-11-30 12:36:01 -07003875TEST_F(VkLayerTest, InvalidDescriptorSet) {
Karl Schultzbdb75952016-04-19 11:36:49 -06003876 // Attempt to bind an invalid Descriptor Set to a valid Command Buffer
3877 // ObjectTracker should catch this.
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003878 // Create a valid cmd buffer
Karl Schultzbdb75952016-04-19 11:36:49 -06003879 // call vkCmdBindDescriptorSets w/ false Descriptor Set
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06003880
3881 uint64_t fake_set_handle = 0xbaad6001;
3882 VkDescriptorSet bad_set = reinterpret_cast<VkDescriptorSet &>(fake_set_handle);
Karl Schultzbdb75952016-04-19 11:36:49 -06003883 VkResult err;
Karl Schultzf78bcdd2016-11-30 12:36:01 -07003884 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00982);
Karl Schultzbdb75952016-04-19 11:36:49 -06003885
3886 ASSERT_NO_FATAL_FAILURE(InitState());
3887
3888 VkDescriptorSetLayoutBinding layout_bindings[1] = {};
3889 layout_bindings[0].binding = 0;
3890 layout_bindings[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3891 layout_bindings[0].descriptorCount = 1;
3892 layout_bindings[0].stageFlags = VK_SHADER_STAGE_VERTEX_BIT;
3893 layout_bindings[0].pImmutableSamplers = NULL;
3894
3895 VkDescriptorSetLayout descriptor_set_layout;
3896 VkDescriptorSetLayoutCreateInfo dslci = {};
3897 dslci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3898 dslci.pNext = NULL;
3899 dslci.bindingCount = 1;
3900 dslci.pBindings = layout_bindings;
3901 err = vkCreateDescriptorSetLayout(device(), &dslci, NULL, &descriptor_set_layout);
Karl Schultz5cb21112016-04-21 17:17:40 -06003902 ASSERT_VK_SUCCESS(err);
Karl Schultzbdb75952016-04-19 11:36:49 -06003903
3904 VkPipelineLayout pipeline_layout;
3905 VkPipelineLayoutCreateInfo plci = {};
3906 plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
3907 plci.pNext = NULL;
3908 plci.setLayoutCount = 1;
3909 plci.pSetLayouts = &descriptor_set_layout;
3910 err = vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout);
Karl Schultz5cb21112016-04-21 17:17:40 -06003911 ASSERT_VK_SUCCESS(err);
Karl Schultzbdb75952016-04-19 11:36:49 -06003912
3913 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003914 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1, &bad_set, 0,
3915 NULL);
Karl Schultzbdb75952016-04-19 11:36:49 -06003916 m_errorMonitor->VerifyFound();
3917 EndCommandBuffer();
3918 vkDestroyPipelineLayout(device(), pipeline_layout, NULL);
3919 vkDestroyDescriptorSetLayout(device(), descriptor_set_layout, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003920}
3921
Karl Schultz6addd812016-02-02 17:17:23 -07003922TEST_F(VkLayerTest, InvalidDescriptorSetLayout) {
Karl Schultzbdb75952016-04-19 11:36:49 -06003923 // Attempt to create a Pipeline Layout with an invalid Descriptor Set Layout.
3924 // ObjectTracker should catch this.
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06003925 uint64_t fake_layout_handle = 0xbaad6001;
3926 VkDescriptorSetLayout bad_layout = reinterpret_cast<VkDescriptorSetLayout &>(fake_layout_handle);
Karl Schultzf78bcdd2016-11-30 12:36:01 -07003927 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00875);
Cody Northropc31a84f2016-08-22 10:41:47 -06003928 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultzbdb75952016-04-19 11:36:49 -06003929 VkPipelineLayout pipeline_layout;
3930 VkPipelineLayoutCreateInfo plci = {};
3931 plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
3932 plci.pNext = NULL;
3933 plci.setLayoutCount = 1;
3934 plci.pSetLayouts = &bad_layout;
3935 vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout);
3936
3937 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003938}
3939
Mark Muellerd4914412016-06-13 17:52:06 -06003940TEST_F(VkLayerTest, WriteDescriptorSetIntegrityCheck) {
3941 TEST_DESCRIPTION("This test verifies some requirements of chapter 13.2.3 of the Vulkan Spec "
3942 "1) A uniform buffer update must have a valid buffer index."
3943 "2) When using an array of descriptors in a single WriteDescriptor,"
3944 " the descriptor types and stageflags must all be the same."
3945 "3) Immutable Sampler state must match across descriptors");
3946
3947 const char *invalid_BufferInfo_ErrorMessage =
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003948 "vkUpdateDescriptorSets: if pDescriptorWrites[0].descriptorType is VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, "
3949 "VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC or "
3950 "VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC, pDescriptorWrites[0].pBufferInfo must not be NULL";
3951 const char *stateFlag_ErrorMessage = "Attempting write update to descriptor set ";
3952 const char *immutable_ErrorMessage = "Attempting write update to descriptor set ";
Mark Muellerd4914412016-06-13 17:52:06 -06003953
Mark Muellerd4914412016-06-13 17:52:06 -06003954 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_BufferInfo_ErrorMessage);
3955
3956 ASSERT_NO_FATAL_FAILURE(InitState());
3957 VkDescriptorPoolSize ds_type_count[4] = {};
3958 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3959 ds_type_count[0].descriptorCount = 1;
Tony Barboure132c5f2016-12-12 11:50:20 -07003960 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLER;
Mark Muellerd4914412016-06-13 17:52:06 -06003961 ds_type_count[1].descriptorCount = 1;
Tony Barboure132c5f2016-12-12 11:50:20 -07003962 ds_type_count[2].type = VK_DESCRIPTOR_TYPE_SAMPLER;
Mark Muellerd4914412016-06-13 17:52:06 -06003963 ds_type_count[2].descriptorCount = 1;
3964 ds_type_count[3].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
3965 ds_type_count[3].descriptorCount = 1;
3966
3967 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3968 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3969 ds_pool_ci.maxSets = 1;
3970 ds_pool_ci.poolSizeCount = sizeof(ds_type_count) / sizeof(VkDescriptorPoolSize);
3971 ds_pool_ci.pPoolSizes = ds_type_count;
3972
3973 VkDescriptorPool ds_pool;
3974 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
3975 ASSERT_VK_SUCCESS(err);
3976
Mark Muellerb9896722016-06-16 09:54:29 -06003977 VkDescriptorSetLayoutBinding layout_binding[3] = {};
Mark Muellerd4914412016-06-13 17:52:06 -06003978 layout_binding[0].binding = 0;
3979 layout_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3980 layout_binding[0].descriptorCount = 1;
3981 layout_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
3982 layout_binding[0].pImmutableSamplers = NULL;
3983
3984 layout_binding[1].binding = 1;
3985 layout_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
3986 layout_binding[1].descriptorCount = 1;
3987 layout_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
3988 layout_binding[1].pImmutableSamplers = NULL;
3989
3990 VkSamplerCreateInfo sampler_ci = {};
3991 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
3992 sampler_ci.pNext = NULL;
3993 sampler_ci.magFilter = VK_FILTER_NEAREST;
3994 sampler_ci.minFilter = VK_FILTER_NEAREST;
3995 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
3996 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3997 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3998 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3999 sampler_ci.mipLodBias = 1.0;
4000 sampler_ci.anisotropyEnable = VK_FALSE;
4001 sampler_ci.maxAnisotropy = 1;
4002 sampler_ci.compareEnable = VK_FALSE;
4003 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
4004 sampler_ci.minLod = 1.0;
4005 sampler_ci.maxLod = 1.0;
4006 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
4007 sampler_ci.unnormalizedCoordinates = VK_FALSE;
4008 VkSampler sampler;
4009
4010 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
4011 ASSERT_VK_SUCCESS(err);
4012
4013 layout_binding[2].binding = 2;
4014 layout_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
4015 layout_binding[2].descriptorCount = 1;
4016 layout_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
4017 layout_binding[2].pImmutableSamplers = static_cast<VkSampler *>(&sampler);
4018
Mark Muellerd4914412016-06-13 17:52:06 -06004019 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
4020 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4021 ds_layout_ci.bindingCount = sizeof(layout_binding) / sizeof(VkDescriptorSetLayoutBinding);
4022 ds_layout_ci.pBindings = layout_binding;
4023 VkDescriptorSetLayout ds_layout;
4024 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
4025 ASSERT_VK_SUCCESS(err);
4026
4027 VkDescriptorSetAllocateInfo alloc_info = {};
4028 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
4029 alloc_info.descriptorSetCount = 1;
4030 alloc_info.descriptorPool = ds_pool;
4031 alloc_info.pSetLayouts = &ds_layout;
4032 VkDescriptorSet descriptorSet;
4033 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
4034 ASSERT_VK_SUCCESS(err);
4035
4036 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4037 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4038 pipeline_layout_ci.pNext = NULL;
4039 pipeline_layout_ci.setLayoutCount = 1;
4040 pipeline_layout_ci.pSetLayouts = &ds_layout;
4041
4042 VkPipelineLayout pipeline_layout;
4043 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
4044 ASSERT_VK_SUCCESS(err);
4045
Mark Mueller5c838ce2016-06-16 09:54:29 -06004046 VkWriteDescriptorSet descriptor_write = {};
Mark Muellerd4914412016-06-13 17:52:06 -06004047 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
4048 descriptor_write.dstSet = descriptorSet;
4049 descriptor_write.dstBinding = 0;
4050 descriptor_write.descriptorCount = 1;
4051 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4052
Mark Mueller5c838ce2016-06-16 09:54:29 -06004053 // 1) The uniform buffer is intentionally invalid here
Mark Muellerd4914412016-06-13 17:52:06 -06004054 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4055 m_errorMonitor->VerifyFound();
4056
4057 // Create a buffer to update the descriptor with
4058 uint32_t qfi = 0;
4059 VkBufferCreateInfo buffCI = {};
4060 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
4061 buffCI.size = 1024;
4062 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
4063 buffCI.queueFamilyIndexCount = 1;
4064 buffCI.pQueueFamilyIndices = &qfi;
4065
4066 VkBuffer dyub;
4067 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
4068 ASSERT_VK_SUCCESS(err);
Mark Muellerd4914412016-06-13 17:52:06 -06004069
Tony Barboure132c5f2016-12-12 11:50:20 -07004070 VkDeviceMemory mem;
4071 VkMemoryRequirements mem_reqs;
4072 vkGetBufferMemoryRequirements(m_device->device(), dyub, &mem_reqs);
4073
4074 VkMemoryAllocateInfo mem_alloc_info = {};
4075 mem_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4076 mem_alloc_info.allocationSize = mem_reqs.size;
4077 m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
4078 err = vkAllocateMemory(m_device->device(), &mem_alloc_info, NULL, &mem);
4079 ASSERT_VK_SUCCESS(err);
4080
4081 err = vkBindBufferMemory(m_device->device(), dyub, mem, 0);
4082 ASSERT_VK_SUCCESS(err);
4083
4084 VkDescriptorBufferInfo buffInfo[2] = {};
4085 buffInfo[0].buffer = dyub;
4086 buffInfo[0].offset = 0;
4087 buffInfo[0].range = 1024;
4088 buffInfo[1].buffer = dyub;
4089 buffInfo[1].offset = 0;
4090 buffInfo[1].range = 1024;
4091 descriptor_write.pBufferInfo = buffInfo;
Mark Muellerd4914412016-06-13 17:52:06 -06004092 descriptor_write.descriptorCount = 2;
4093
Mark Mueller5c838ce2016-06-16 09:54:29 -06004094 // 2) The stateFlags don't match between the first and second descriptor
Mark Muellerd4914412016-06-13 17:52:06 -06004095 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, stateFlag_ErrorMessage);
4096 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4097 m_errorMonitor->VerifyFound();
4098
Mark Mueller5c838ce2016-06-16 09:54:29 -06004099 // 3) The second descriptor has a null_ptr pImmutableSamplers and
4100 // the third descriptor contains an immutable sampler
Mark Muellerd4914412016-06-13 17:52:06 -06004101 descriptor_write.dstBinding = 1;
4102 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Mark Mueller5c838ce2016-06-16 09:54:29 -06004103
Mark Mueller5c838ce2016-06-16 09:54:29 -06004104 // Make pImageInfo index non-null to avoid complaints of it missing
4105 VkDescriptorImageInfo imageInfo = {};
4106 imageInfo.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
4107 descriptor_write.pImageInfo = &imageInfo;
Mark Muellerd4914412016-06-13 17:52:06 -06004108 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, immutable_ErrorMessage);
4109 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4110 m_errorMonitor->VerifyFound();
4111
Mark Muellerd4914412016-06-13 17:52:06 -06004112 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tony Barboure132c5f2016-12-12 11:50:20 -07004113 vkFreeMemory(m_device->device(), mem, NULL);
Mark Muellerd4914412016-06-13 17:52:06 -06004114 vkDestroySampler(m_device->device(), sampler, NULL);
4115 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4116 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4117 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
4118}
4119
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004120TEST_F(VkLayerTest, InvalidCmdBufferBufferDestroyed) {
4121 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4122 "due to a buffer dependency being destroyed.");
4123 ASSERT_NO_FATAL_FAILURE(InitState());
4124
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004125 VkBuffer buffer;
4126 VkDeviceMemory mem;
4127 VkMemoryRequirements mem_reqs;
4128
4129 VkBufferCreateInfo buf_info = {};
4130 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes3d5882f2016-09-16 17:37:17 +12004131 buf_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004132 buf_info.size = 256;
4133 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
4134 VkResult err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
4135 ASSERT_VK_SUCCESS(err);
4136
4137 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
4138
4139 VkMemoryAllocateInfo alloc_info = {};
4140 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4141 alloc_info.allocationSize = 256;
4142 bool pass = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004143 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 -06004144 if (!pass) {
4145 vkDestroyBuffer(m_device->device(), buffer, NULL);
4146 return;
4147 }
4148 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
4149 ASSERT_VK_SUCCESS(err);
4150
4151 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
4152 ASSERT_VK_SUCCESS(err);
4153
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004154 m_commandBuffer->BeginCommandBuffer();
Chris Forbes3d5882f2016-09-16 17:37:17 +12004155 vkCmdFillBuffer(m_commandBuffer->GetBufferHandle(), buffer, 0, VK_WHOLE_SIZE, 0);
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004156 m_commandBuffer->EndCommandBuffer();
4157
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004158 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound buffer ");
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004159 // Destroy buffer dependency prior to submit to cause ERROR
4160 vkDestroyBuffer(m_device->device(), buffer, NULL);
4161
4162 VkSubmitInfo submit_info = {};
4163 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4164 submit_info.commandBufferCount = 1;
4165 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4166 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4167
4168 m_errorMonitor->VerifyFound();
Rene Lindsayab6c5cd2016-12-20 14:05:37 -07004169 vkQueueWaitIdle(m_device->m_queue);
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004170 vkFreeMemory(m_device->handle(), mem, NULL);
4171}
4172
Tobin Ehlisea413442016-09-28 10:23:59 -06004173TEST_F(VkLayerTest, InvalidCmdBufferBufferViewDestroyed) {
4174 TEST_DESCRIPTION("Delete bufferView bound to cmd buffer, then attempt to submit cmd buffer.");
4175
4176 ASSERT_NO_FATAL_FAILURE(InitState());
4177 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4178
4179 VkDescriptorPoolSize ds_type_count;
4180 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
4181 ds_type_count.descriptorCount = 1;
4182
4183 VkDescriptorPoolCreateInfo ds_pool_ci = {};
4184 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4185 ds_pool_ci.maxSets = 1;
4186 ds_pool_ci.poolSizeCount = 1;
4187 ds_pool_ci.pPoolSizes = &ds_type_count;
4188
4189 VkDescriptorPool ds_pool;
4190 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
4191 ASSERT_VK_SUCCESS(err);
4192
4193 VkDescriptorSetLayoutBinding layout_binding;
4194 layout_binding.binding = 0;
4195 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
4196 layout_binding.descriptorCount = 1;
4197 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
4198 layout_binding.pImmutableSamplers = NULL;
4199
4200 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
4201 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4202 ds_layout_ci.bindingCount = 1;
4203 ds_layout_ci.pBindings = &layout_binding;
4204 VkDescriptorSetLayout ds_layout;
4205 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
4206 ASSERT_VK_SUCCESS(err);
4207
4208 VkDescriptorSetAllocateInfo alloc_info = {};
4209 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
4210 alloc_info.descriptorSetCount = 1;
4211 alloc_info.descriptorPool = ds_pool;
4212 alloc_info.pSetLayouts = &ds_layout;
4213 VkDescriptorSet descriptor_set;
4214 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
4215 ASSERT_VK_SUCCESS(err);
4216
4217 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4218 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4219 pipeline_layout_ci.pNext = NULL;
4220 pipeline_layout_ci.setLayoutCount = 1;
4221 pipeline_layout_ci.pSetLayouts = &ds_layout;
4222
4223 VkPipelineLayout pipeline_layout;
4224 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
4225 ASSERT_VK_SUCCESS(err);
4226
4227 VkBuffer buffer;
4228 uint32_t queue_family_index = 0;
4229 VkBufferCreateInfo buffer_create_info = {};
4230 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
4231 buffer_create_info.size = 1024;
4232 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
4233 buffer_create_info.queueFamilyIndexCount = 1;
4234 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
4235
4236 err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
4237 ASSERT_VK_SUCCESS(err);
4238
4239 VkMemoryRequirements memory_reqs;
4240 VkDeviceMemory buffer_memory;
4241
4242 VkMemoryAllocateInfo memory_info = {};
4243 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4244 memory_info.allocationSize = 0;
4245 memory_info.memoryTypeIndex = 0;
4246
4247 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
4248 memory_info.allocationSize = memory_reqs.size;
4249 bool pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
4250 ASSERT_TRUE(pass);
4251
4252 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
4253 ASSERT_VK_SUCCESS(err);
4254 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
4255 ASSERT_VK_SUCCESS(err);
4256
4257 VkBufferView view;
4258 VkBufferViewCreateInfo bvci = {};
4259 bvci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
4260 bvci.buffer = buffer;
4261 bvci.format = VK_FORMAT_R8_UNORM;
4262 bvci.range = VK_WHOLE_SIZE;
4263
4264 err = vkCreateBufferView(m_device->device(), &bvci, NULL, &view);
4265 ASSERT_VK_SUCCESS(err);
4266
4267 VkWriteDescriptorSet descriptor_write = {};
4268 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
4269 descriptor_write.dstSet = descriptor_set;
4270 descriptor_write.dstBinding = 0;
4271 descriptor_write.descriptorCount = 1;
4272 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
4273 descriptor_write.pTexelBufferView = &view;
4274
4275 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4276
4277 char const *vsSource = "#version 450\n"
4278 "\n"
4279 "out gl_PerVertex { \n"
4280 " vec4 gl_Position;\n"
4281 "};\n"
4282 "void main(){\n"
4283 " gl_Position = vec4(1);\n"
4284 "}\n";
4285 char const *fsSource = "#version 450\n"
4286 "\n"
4287 "layout(set=0, binding=0, r8) uniform imageBuffer s;\n"
4288 "layout(location=0) out vec4 x;\n"
4289 "void main(){\n"
4290 " x = imageLoad(s, 0);\n"
4291 "}\n";
4292 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4293 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
4294 VkPipelineObj pipe(m_device);
4295 pipe.AddShader(&vs);
4296 pipe.AddShader(&fs);
4297 pipe.AddColorAttachment();
4298 pipe.CreateVKPipeline(pipeline_layout, renderPass());
4299
4300 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot submit cmd buffer using deleted buffer view ");
4301 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound buffer view ");
4302
4303 BeginCommandBuffer();
4304 VkViewport viewport = {0, 0, 16, 16, 0, 1};
4305 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
4306 VkRect2D scissor = {{0, 0}, {16, 16}};
4307 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
4308 // Bind pipeline to cmd buffer
4309 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
4310 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
4311 &descriptor_set, 0, nullptr);
4312 Draw(1, 0, 0, 0);
4313 EndCommandBuffer();
4314
4315 // Delete BufferView in order to invalidate cmd buffer
4316 vkDestroyBufferView(m_device->device(), view, NULL);
4317 // Now attempt submit of cmd buffer
4318 VkSubmitInfo submit_info = {};
4319 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4320 submit_info.commandBufferCount = 1;
4321 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4322 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4323 m_errorMonitor->VerifyFound();
4324
4325 // Clean-up
4326 vkDestroyBuffer(m_device->device(), buffer, NULL);
4327 vkFreeMemory(m_device->device(), buffer_memory, NULL);
4328 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4329 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4330 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
4331}
4332
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004333TEST_F(VkLayerTest, InvalidCmdBufferImageDestroyed) {
4334 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4335 "due to an image dependency being destroyed.");
4336 ASSERT_NO_FATAL_FAILURE(InitState());
4337
4338 VkImage image;
4339 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
4340 VkImageCreateInfo image_create_info = {};
4341 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4342 image_create_info.pNext = NULL;
4343 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4344 image_create_info.format = tex_format;
4345 image_create_info.extent.width = 32;
4346 image_create_info.extent.height = 32;
4347 image_create_info.extent.depth = 1;
4348 image_create_info.mipLevels = 1;
4349 image_create_info.arrayLayers = 1;
4350 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
4351 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004352 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004353 image_create_info.flags = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004354 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004355 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004356 // Have to bind memory to image before recording cmd in cmd buffer using it
4357 VkMemoryRequirements mem_reqs;
4358 VkDeviceMemory image_mem;
4359 bool pass;
4360 VkMemoryAllocateInfo mem_alloc = {};
4361 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4362 mem_alloc.pNext = NULL;
4363 mem_alloc.memoryTypeIndex = 0;
4364 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
4365 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004366 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004367 ASSERT_TRUE(pass);
4368 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
4369 ASSERT_VK_SUCCESS(err);
4370 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
4371 ASSERT_VK_SUCCESS(err);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004372
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004373 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlis764d7072016-07-01 12:54:29 -06004374 VkClearColorValue ccv;
4375 ccv.float32[0] = 1.0f;
4376 ccv.float32[1] = 1.0f;
4377 ccv.float32[2] = 1.0f;
4378 ccv.float32[3] = 1.0f;
4379 VkImageSubresourceRange isr = {};
4380 isr.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004381 isr.baseArrayLayer = 0;
4382 isr.baseMipLevel = 0;
Tobin Ehlis764d7072016-07-01 12:54:29 -06004383 isr.layerCount = 1;
4384 isr.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004385 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), image, VK_IMAGE_LAYOUT_GENERAL, &ccv, 1, &isr);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004386 m_commandBuffer->EndCommandBuffer();
4387
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004388 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004389 // Destroy image dependency prior to submit to cause ERROR
4390 vkDestroyImage(m_device->device(), image, NULL);
4391
4392 VkSubmitInfo submit_info = {};
4393 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4394 submit_info.commandBufferCount = 1;
4395 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4396 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4397
4398 m_errorMonitor->VerifyFound();
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004399 vkFreeMemory(m_device->device(), image_mem, nullptr);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004400}
4401
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004402TEST_F(VkLayerTest, InvalidCmdBufferFramebufferImageDestroyed) {
4403 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4404 "due to a framebuffer image dependency being destroyed.");
4405 VkFormatProperties format_properties;
4406 VkResult err = VK_SUCCESS;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004407 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
4408 if (!(format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)) {
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004409 return;
4410 }
4411
4412 ASSERT_NO_FATAL_FAILURE(InitState());
4413 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4414
4415 VkImageCreateInfo image_ci = {};
4416 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4417 image_ci.pNext = NULL;
4418 image_ci.imageType = VK_IMAGE_TYPE_2D;
4419 image_ci.format = VK_FORMAT_B8G8R8A8_UNORM;
4420 image_ci.extent.width = 32;
4421 image_ci.extent.height = 32;
4422 image_ci.extent.depth = 1;
4423 image_ci.mipLevels = 1;
4424 image_ci.arrayLayers = 1;
4425 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
4426 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004427 image_ci.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_SAMPLED_BIT;
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004428 image_ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
4429 image_ci.flags = 0;
4430 VkImage image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004431 ASSERT_VK_SUCCESS(vkCreateImage(m_device->handle(), &image_ci, NULL, &image));
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004432
4433 VkMemoryRequirements memory_reqs;
4434 VkDeviceMemory image_memory;
4435 bool pass;
4436 VkMemoryAllocateInfo memory_info = {};
4437 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4438 memory_info.pNext = NULL;
4439 memory_info.allocationSize = 0;
4440 memory_info.memoryTypeIndex = 0;
4441 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
4442 memory_info.allocationSize = memory_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004443 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004444 ASSERT_TRUE(pass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004445 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004446 ASSERT_VK_SUCCESS(err);
4447 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
4448 ASSERT_VK_SUCCESS(err);
4449
4450 VkImageViewCreateInfo ivci = {
4451 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
4452 nullptr,
4453 0,
4454 image,
4455 VK_IMAGE_VIEW_TYPE_2D,
4456 VK_FORMAT_B8G8R8A8_UNORM,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004457 {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A},
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004458 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
4459 };
4460 VkImageView view;
4461 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
4462 ASSERT_VK_SUCCESS(err);
4463
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004464 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 32, 32, 1};
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004465 VkFramebuffer fb;
4466 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
4467 ASSERT_VK_SUCCESS(err);
4468
4469 // Just use default renderpass with our framebuffer
4470 m_renderPassBeginInfo.framebuffer = fb;
4471 // Create Null cmd buffer for submit
4472 BeginCommandBuffer();
4473 EndCommandBuffer();
4474 // Destroy image attached to framebuffer to invalidate cmd buffer
4475 vkDestroyImage(m_device->device(), image, NULL);
4476 // Now attempt to submit cmd buffer and verify error
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004477 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004478 QueueCommandBuffer(false);
4479 m_errorMonitor->VerifyFound();
4480
4481 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
4482 vkDestroyImageView(m_device->device(), view, nullptr);
4483 vkFreeMemory(m_device->device(), image_memory, nullptr);
4484}
4485
Tobin Ehlisb329f992016-10-12 13:20:29 -06004486TEST_F(VkLayerTest, FramebufferInUseDestroyedSignaled) {
4487 TEST_DESCRIPTION("Delete in-use framebuffer.");
4488 VkFormatProperties format_properties;
4489 VkResult err = VK_SUCCESS;
4490 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
4491
4492 ASSERT_NO_FATAL_FAILURE(InitState());
4493 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4494
4495 VkImageObj image(m_device);
4496 image.init(256, 256, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
4497 ASSERT_TRUE(image.initialized());
4498 VkImageView view = image.targetView(VK_FORMAT_B8G8R8A8_UNORM);
4499
4500 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 256, 256, 1};
4501 VkFramebuffer fb;
4502 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
4503 ASSERT_VK_SUCCESS(err);
4504
4505 // Just use default renderpass with our framebuffer
4506 m_renderPassBeginInfo.framebuffer = fb;
4507 // Create Null cmd buffer for submit
4508 BeginCommandBuffer();
4509 EndCommandBuffer();
4510 // Submit cmd buffer to put it in-flight
4511 VkSubmitInfo submit_info = {};
4512 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4513 submit_info.commandBufferCount = 1;
4514 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4515 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4516 // Destroy framebuffer while in-flight
4517 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete framebuffer 0x");
4518 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4519 m_errorMonitor->VerifyFound();
4520 // Wait for queue to complete so we can safely destroy everything
4521 vkQueueWaitIdle(m_device->m_queue);
4522 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
4523}
4524
Tobin Ehlis88becd72016-09-21 14:33:41 -06004525TEST_F(VkLayerTest, FramebufferImageInUseDestroyedSignaled) {
4526 TEST_DESCRIPTION("Delete in-use image that's child of framebuffer.");
4527 VkFormatProperties format_properties;
4528 VkResult err = VK_SUCCESS;
4529 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
Tobin Ehlis88becd72016-09-21 14:33:41 -06004530
4531 ASSERT_NO_FATAL_FAILURE(InitState());
4532 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4533
4534 VkImageCreateInfo image_ci = {};
4535 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4536 image_ci.pNext = NULL;
4537 image_ci.imageType = VK_IMAGE_TYPE_2D;
4538 image_ci.format = VK_FORMAT_B8G8R8A8_UNORM;
4539 image_ci.extent.width = 256;
4540 image_ci.extent.height = 256;
4541 image_ci.extent.depth = 1;
4542 image_ci.mipLevels = 1;
4543 image_ci.arrayLayers = 1;
4544 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
4545 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
Tobin Ehlisc8ca0312016-09-22 07:30:05 -06004546 image_ci.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Tobin Ehlis88becd72016-09-21 14:33:41 -06004547 image_ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
4548 image_ci.flags = 0;
4549 VkImage image;
4550 ASSERT_VK_SUCCESS(vkCreateImage(m_device->handle(), &image_ci, NULL, &image));
4551
4552 VkMemoryRequirements memory_reqs;
4553 VkDeviceMemory image_memory;
4554 bool pass;
4555 VkMemoryAllocateInfo memory_info = {};
4556 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4557 memory_info.pNext = NULL;
4558 memory_info.allocationSize = 0;
4559 memory_info.memoryTypeIndex = 0;
4560 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
4561 memory_info.allocationSize = memory_reqs.size;
4562 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
4563 ASSERT_TRUE(pass);
4564 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
4565 ASSERT_VK_SUCCESS(err);
4566 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
4567 ASSERT_VK_SUCCESS(err);
4568
4569 VkImageViewCreateInfo ivci = {
4570 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
4571 nullptr,
4572 0,
4573 image,
4574 VK_IMAGE_VIEW_TYPE_2D,
4575 VK_FORMAT_B8G8R8A8_UNORM,
4576 {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A},
4577 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
4578 };
4579 VkImageView view;
4580 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
4581 ASSERT_VK_SUCCESS(err);
4582
4583 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 256, 256, 1};
4584 VkFramebuffer fb;
4585 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
4586 ASSERT_VK_SUCCESS(err);
4587
4588 // Just use default renderpass with our framebuffer
4589 m_renderPassBeginInfo.framebuffer = fb;
4590 // Create Null cmd buffer for submit
4591 BeginCommandBuffer();
4592 EndCommandBuffer();
4593 // Submit cmd buffer to put it (and attached imageView) in-flight
4594 VkSubmitInfo submit_info = {};
4595 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4596 submit_info.commandBufferCount = 1;
4597 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4598 // Submit cmd buffer to put framebuffer and children in-flight
4599 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4600 // Destroy image attached to framebuffer while in-flight
4601 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete image 0x");
4602 vkDestroyImage(m_device->device(), image, NULL);
4603 m_errorMonitor->VerifyFound();
4604 // Wait for queue to complete so we can safely destroy image and other objects
4605 vkQueueWaitIdle(m_device->m_queue);
4606 vkDestroyImage(m_device->device(), image, NULL);
4607 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
4608 vkDestroyImageView(m_device->device(), view, nullptr);
4609 vkFreeMemory(m_device->device(), image_memory, nullptr);
4610}
4611
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06004612TEST_F(VkLayerTest, RenderPassInUseDestroyedSignaled) {
4613 TEST_DESCRIPTION("Delete in-use renderPass.");
4614
4615 ASSERT_NO_FATAL_FAILURE(InitState());
4616 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4617
4618 // Create simple renderpass
4619 VkAttachmentReference attach = {};
4620 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
4621 VkSubpassDescription subpass = {};
4622 subpass.pColorAttachments = &attach;
4623 VkRenderPassCreateInfo rpci = {};
4624 rpci.subpassCount = 1;
4625 rpci.pSubpasses = &subpass;
4626 rpci.attachmentCount = 1;
4627 VkAttachmentDescription attach_desc = {};
4628 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
4629 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
4630 rpci.pAttachments = &attach_desc;
4631 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
4632 VkRenderPass rp;
4633 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
4634 ASSERT_VK_SUCCESS(err);
4635
4636 // Create a pipeline that uses the given renderpass
4637 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4638 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4639
4640 VkPipelineLayout pipeline_layout;
4641 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
4642 ASSERT_VK_SUCCESS(err);
4643
4644 VkPipelineViewportStateCreateInfo vp_state_ci = {};
4645 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
4646 vp_state_ci.viewportCount = 1;
4647 VkViewport vp = {}; // Just need dummy vp to point to
4648 vp_state_ci.pViewports = &vp;
4649 vp_state_ci.scissorCount = 1;
4650 VkRect2D scissors = {}; // Dummy scissors to point to
4651 vp_state_ci.pScissors = &scissors;
4652
4653 VkPipelineShaderStageCreateInfo shaderStages[2];
4654 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
4655
4656 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
4657 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
4658 // but add it to be able to run on more devices
4659 shaderStages[0] = vs.GetStageCreateInfo();
4660 shaderStages[1] = fs.GetStageCreateInfo();
4661
4662 VkPipelineVertexInputStateCreateInfo vi_ci = {};
4663 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
4664
4665 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
4666 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
4667 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
4668
4669 VkPipelineRasterizationStateCreateInfo rs_ci = {};
4670 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
4671 rs_ci.rasterizerDiscardEnable = true;
4672 rs_ci.lineWidth = 1.0f;
4673
4674 VkPipelineColorBlendAttachmentState att = {};
4675 att.blendEnable = VK_FALSE;
4676 att.colorWriteMask = 0xf;
4677
4678 VkPipelineColorBlendStateCreateInfo cb_ci = {};
4679 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
4680 cb_ci.attachmentCount = 1;
4681 cb_ci.pAttachments = &att;
4682
4683 VkGraphicsPipelineCreateInfo gp_ci = {};
4684 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
4685 gp_ci.stageCount = 2;
4686 gp_ci.pStages = shaderStages;
4687 gp_ci.pVertexInputState = &vi_ci;
4688 gp_ci.pInputAssemblyState = &ia_ci;
4689 gp_ci.pViewportState = &vp_state_ci;
4690 gp_ci.pRasterizationState = &rs_ci;
4691 gp_ci.pColorBlendState = &cb_ci;
4692 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
4693 gp_ci.layout = pipeline_layout;
4694 gp_ci.renderPass = rp;
4695
4696 VkPipelineCacheCreateInfo pc_ci = {};
4697 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
4698
4699 VkPipeline pipeline;
4700 VkPipelineCache pipe_cache;
4701 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipe_cache);
4702 ASSERT_VK_SUCCESS(err);
4703
4704 err = vkCreateGraphicsPipelines(m_device->device(), pipe_cache, 1, &gp_ci, NULL, &pipeline);
4705 ASSERT_VK_SUCCESS(err);
4706 // Bind pipeline to cmd buffer, will also bind renderpass
4707 m_commandBuffer->BeginCommandBuffer();
4708 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
4709 m_commandBuffer->EndCommandBuffer();
4710
4711 VkSubmitInfo submit_info = {};
4712 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4713 submit_info.commandBufferCount = 1;
4714 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4715 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4716
4717 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00393);
4718 vkDestroyRenderPass(m_device->device(), rp, nullptr);
4719 m_errorMonitor->VerifyFound();
4720
4721 // Wait for queue to complete so we can safely destroy everything
4722 vkQueueWaitIdle(m_device->m_queue);
4723 vkDestroyRenderPass(m_device->device(), rp, nullptr);
4724 vkDestroyPipeline(m_device->device(), pipeline, nullptr);
4725 vkDestroyPipelineCache(m_device->device(), pipe_cache, nullptr);
4726 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
4727}
4728
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004729TEST_F(VkLayerTest, ImageMemoryNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004730 TEST_DESCRIPTION("Attempt to draw with an image which has not had memory bound to it.");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004731 ASSERT_NO_FATAL_FAILURE(InitState());
4732
4733 VkImage image;
4734 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
4735 VkImageCreateInfo image_create_info = {};
4736 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4737 image_create_info.pNext = NULL;
4738 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4739 image_create_info.format = tex_format;
4740 image_create_info.extent.width = 32;
4741 image_create_info.extent.height = 32;
4742 image_create_info.extent.depth = 1;
4743 image_create_info.mipLevels = 1;
4744 image_create_info.arrayLayers = 1;
4745 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
4746 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004747 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004748 image_create_info.flags = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004749 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004750 ASSERT_VK_SUCCESS(err);
4751 // Have to bind memory to image before recording cmd in cmd buffer using it
4752 VkMemoryRequirements mem_reqs;
4753 VkDeviceMemory image_mem;
4754 bool pass;
4755 VkMemoryAllocateInfo mem_alloc = {};
4756 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4757 mem_alloc.pNext = NULL;
4758 mem_alloc.memoryTypeIndex = 0;
4759 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
4760 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004761 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004762 ASSERT_TRUE(pass);
4763 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
4764 ASSERT_VK_SUCCESS(err);
4765
Tobin Ehlisfed999f2016-09-21 15:09:45 -06004766 // Introduce error, do not call vkBindImageMemory(m_device->device(), image, image_mem, 0);
4767 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06004768 " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004769
4770 m_commandBuffer->BeginCommandBuffer();
4771 VkClearColorValue ccv;
4772 ccv.float32[0] = 1.0f;
4773 ccv.float32[1] = 1.0f;
4774 ccv.float32[2] = 1.0f;
4775 ccv.float32[3] = 1.0f;
4776 VkImageSubresourceRange isr = {};
4777 isr.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
4778 isr.baseArrayLayer = 0;
4779 isr.baseMipLevel = 0;
4780 isr.layerCount = 1;
4781 isr.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004782 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), image, VK_IMAGE_LAYOUT_GENERAL, &ccv, 1, &isr);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004783 m_commandBuffer->EndCommandBuffer();
4784
4785 m_errorMonitor->VerifyFound();
4786 vkDestroyImage(m_device->device(), image, NULL);
4787 vkFreeMemory(m_device->device(), image_mem, nullptr);
4788}
4789
4790TEST_F(VkLayerTest, BufferMemoryNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004791 TEST_DESCRIPTION("Attempt to copy from a buffer which has not had memory bound to it.");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004792 ASSERT_NO_FATAL_FAILURE(InitState());
4793
4794 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004795 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 -06004796 VK_IMAGE_TILING_OPTIMAL, 0);
4797 ASSERT_TRUE(image.initialized());
4798
4799 VkBuffer buffer;
4800 VkDeviceMemory mem;
4801 VkMemoryRequirements mem_reqs;
4802
4803 VkBufferCreateInfo buf_info = {};
4804 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes8d260dd2016-09-16 17:42:42 +12004805 buf_info.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004806 buf_info.size = 256;
4807 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
4808 VkResult err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
4809 ASSERT_VK_SUCCESS(err);
4810
4811 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
4812
4813 VkMemoryAllocateInfo alloc_info = {};
4814 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4815 alloc_info.allocationSize = 256;
4816 bool pass = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004817 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 -06004818 if (!pass) {
4819 vkDestroyBuffer(m_device->device(), buffer, NULL);
4820 return;
4821 }
4822 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
4823 ASSERT_VK_SUCCESS(err);
4824
Tobin Ehlisfed999f2016-09-21 15:09:45 -06004825 // Introduce failure by not calling vkBindBufferMemory(m_device->device(), buffer, mem, 0);
4826 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06004827 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004828 VkBufferImageCopy region = {};
4829 region.bufferRowLength = 128;
4830 region.bufferImageHeight = 128;
4831 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
4832
4833 region.imageSubresource.layerCount = 1;
4834 region.imageExtent.height = 4;
4835 region.imageExtent.width = 4;
4836 region.imageExtent.depth = 1;
4837 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004838 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer, image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
4839 &region);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004840 m_commandBuffer->EndCommandBuffer();
4841
4842 m_errorMonitor->VerifyFound();
4843
4844 vkDestroyBuffer(m_device->device(), buffer, NULL);
4845 vkFreeMemory(m_device->handle(), mem, NULL);
4846}
4847
Tobin Ehlis85940f52016-07-07 16:57:21 -06004848TEST_F(VkLayerTest, InvalidCmdBufferEventDestroyed) {
4849 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4850 "due to an event dependency being destroyed.");
4851 ASSERT_NO_FATAL_FAILURE(InitState());
4852
4853 VkEvent event;
4854 VkEventCreateInfo evci = {};
4855 evci.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
4856 VkResult result = vkCreateEvent(m_device->device(), &evci, NULL, &event);
4857 ASSERT_VK_SUCCESS(result);
4858
4859 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004860 vkCmdSetEvent(m_commandBuffer->GetBufferHandle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Tobin Ehlis85940f52016-07-07 16:57:21 -06004861 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 event ");
Tobin Ehlis85940f52016-07-07 16:57:21 -06004864 // Destroy event dependency prior to submit to cause ERROR
4865 vkDestroyEvent(m_device->device(), event, 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 Ehlisdbea7552016-07-08 14:33:31 -06004876TEST_F(VkLayerTest, InvalidCmdBufferQueryPoolDestroyed) {
4877 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4878 "due to a query pool dependency being destroyed.");
4879 ASSERT_NO_FATAL_FAILURE(InitState());
4880
4881 VkQueryPool query_pool;
4882 VkQueryPoolCreateInfo qpci{};
4883 qpci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
4884 qpci.queryType = VK_QUERY_TYPE_TIMESTAMP;
4885 qpci.queryCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004886 VkResult result = vkCreateQueryPool(m_device->device(), &qpci, nullptr, &query_pool);
Tobin Ehlisdbea7552016-07-08 14:33:31 -06004887 ASSERT_VK_SUCCESS(result);
4888
4889 m_commandBuffer->BeginCommandBuffer();
4890 vkCmdResetQueryPool(m_commandBuffer->GetBufferHandle(), query_pool, 0, 1);
4891 m_commandBuffer->EndCommandBuffer();
4892
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004893 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound query pool ");
Tobin Ehlisdbea7552016-07-08 14:33:31 -06004894 // Destroy query pool dependency prior to submit to cause ERROR
4895 vkDestroyQueryPool(m_device->device(), query_pool, NULL);
4896
4897 VkSubmitInfo submit_info = {};
4898 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4899 submit_info.commandBufferCount = 1;
4900 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4901 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4902
4903 m_errorMonitor->VerifyFound();
4904}
4905
Tobin Ehlis24130d92016-07-08 15:50:53 -06004906TEST_F(VkLayerTest, InvalidCmdBufferPipelineDestroyed) {
4907 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4908 "due to a pipeline dependency being destroyed.");
4909 ASSERT_NO_FATAL_FAILURE(InitState());
4910 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4911
4912 VkResult err;
4913
4914 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4915 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4916
4917 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004918 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis24130d92016-07-08 15:50:53 -06004919 ASSERT_VK_SUCCESS(err);
4920
4921 VkPipelineViewportStateCreateInfo vp_state_ci = {};
4922 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
4923 vp_state_ci.viewportCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004924 VkViewport vp = {}; // Just need dummy vp to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -06004925 vp_state_ci.pViewports = &vp;
Tobin Ehlis24130d92016-07-08 15:50:53 -06004926 vp_state_ci.scissorCount = 1;
4927 VkRect2D scissors = {}; // Dummy scissors to point to
4928 vp_state_ci.pScissors = &scissors;
Tobin Ehlis24130d92016-07-08 15:50:53 -06004929
4930 VkPipelineShaderStageCreateInfo shaderStages[2];
4931 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
4932
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004933 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
4934 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
4935 // but add it to be able to run on more devices
Tobin Ehlis24130d92016-07-08 15:50:53 -06004936 shaderStages[0] = vs.GetStageCreateInfo();
4937 shaderStages[1] = fs.GetStageCreateInfo();
4938
4939 VkPipelineVertexInputStateCreateInfo vi_ci = {};
4940 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
4941
4942 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
4943 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
4944 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
4945
4946 VkPipelineRasterizationStateCreateInfo rs_ci = {};
4947 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Chris Forbese06ba252016-09-16 17:48:53 +12004948 rs_ci.rasterizerDiscardEnable = true;
4949 rs_ci.lineWidth = 1.0f;
Tobin Ehlis24130d92016-07-08 15:50:53 -06004950
4951 VkPipelineColorBlendAttachmentState att = {};
4952 att.blendEnable = VK_FALSE;
4953 att.colorWriteMask = 0xf;
4954
4955 VkPipelineColorBlendStateCreateInfo cb_ci = {};
4956 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
4957 cb_ci.attachmentCount = 1;
4958 cb_ci.pAttachments = &att;
4959
4960 VkGraphicsPipelineCreateInfo gp_ci = {};
4961 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
4962 gp_ci.stageCount = 2;
4963 gp_ci.pStages = shaderStages;
4964 gp_ci.pVertexInputState = &vi_ci;
4965 gp_ci.pInputAssemblyState = &ia_ci;
4966 gp_ci.pViewportState = &vp_state_ci;
4967 gp_ci.pRasterizationState = &rs_ci;
4968 gp_ci.pColorBlendState = &cb_ci;
Tobin Ehlis24130d92016-07-08 15:50:53 -06004969 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
4970 gp_ci.layout = pipeline_layout;
4971 gp_ci.renderPass = renderPass();
4972
4973 VkPipelineCacheCreateInfo pc_ci = {};
4974 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
4975
4976 VkPipeline pipeline;
4977 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004978 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis24130d92016-07-08 15:50:53 -06004979 ASSERT_VK_SUCCESS(err);
4980
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004981 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis24130d92016-07-08 15:50:53 -06004982 ASSERT_VK_SUCCESS(err);
4983
4984 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004985 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Tobin Ehlis24130d92016-07-08 15:50:53 -06004986 m_commandBuffer->EndCommandBuffer();
4987 // Now destroy pipeline in order to cause error when submitting
4988 vkDestroyPipeline(m_device->device(), pipeline, nullptr);
4989
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004990 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound pipeline ");
Tobin Ehlis24130d92016-07-08 15:50:53 -06004991
4992 VkSubmitInfo submit_info = {};
4993 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4994 submit_info.commandBufferCount = 1;
4995 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4996 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4997
4998 m_errorMonitor->VerifyFound();
4999 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
5000 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5001}
5002
Tobin Ehlis31289162016-08-17 14:57:58 -06005003TEST_F(VkLayerTest, InvalidCmdBufferDescriptorSetBufferDestroyed) {
5004 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
5005 "due to a bound descriptor set with a buffer dependency "
5006 "being destroyed.");
5007 ASSERT_NO_FATAL_FAILURE(InitState());
5008 ASSERT_NO_FATAL_FAILURE(InitViewport());
5009 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5010
5011 VkDescriptorPoolSize ds_type_count = {};
5012 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5013 ds_type_count.descriptorCount = 1;
5014
5015 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5016 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5017 ds_pool_ci.pNext = NULL;
5018 ds_pool_ci.maxSets = 1;
5019 ds_pool_ci.poolSizeCount = 1;
5020 ds_pool_ci.pPoolSizes = &ds_type_count;
5021
5022 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005023 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis31289162016-08-17 14:57:58 -06005024 ASSERT_VK_SUCCESS(err);
5025
5026 VkDescriptorSetLayoutBinding dsl_binding = {};
5027 dsl_binding.binding = 0;
5028 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5029 dsl_binding.descriptorCount = 1;
5030 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5031 dsl_binding.pImmutableSamplers = NULL;
5032
5033 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5034 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5035 ds_layout_ci.pNext = NULL;
5036 ds_layout_ci.bindingCount = 1;
5037 ds_layout_ci.pBindings = &dsl_binding;
5038 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005039 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis31289162016-08-17 14:57:58 -06005040 ASSERT_VK_SUCCESS(err);
5041
5042 VkDescriptorSet descriptorSet;
5043 VkDescriptorSetAllocateInfo alloc_info = {};
5044 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
5045 alloc_info.descriptorSetCount = 1;
5046 alloc_info.descriptorPool = ds_pool;
5047 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005048 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis31289162016-08-17 14:57:58 -06005049 ASSERT_VK_SUCCESS(err);
5050
5051 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5052 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5053 pipeline_layout_ci.pNext = NULL;
5054 pipeline_layout_ci.setLayoutCount = 1;
5055 pipeline_layout_ci.pSetLayouts = &ds_layout;
5056
5057 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005058 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis31289162016-08-17 14:57:58 -06005059 ASSERT_VK_SUCCESS(err);
5060
5061 // Create a buffer to update the descriptor with
5062 uint32_t qfi = 0;
5063 VkBufferCreateInfo buffCI = {};
5064 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
5065 buffCI.size = 1024;
5066 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
5067 buffCI.queueFamilyIndexCount = 1;
5068 buffCI.pQueueFamilyIndices = &qfi;
5069
5070 VkBuffer buffer;
5071 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &buffer);
5072 ASSERT_VK_SUCCESS(err);
5073 // Allocate memory and bind to buffer so we can make it to the appropriate
5074 // error
5075 VkMemoryAllocateInfo mem_alloc = {};
5076 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5077 mem_alloc.pNext = NULL;
5078 mem_alloc.allocationSize = 1024;
5079 mem_alloc.memoryTypeIndex = 0;
5080
5081 VkMemoryRequirements memReqs;
5082 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005083 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis31289162016-08-17 14:57:58 -06005084 if (!pass) {
5085 vkDestroyBuffer(m_device->device(), buffer, NULL);
5086 return;
5087 }
5088
5089 VkDeviceMemory mem;
5090 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
5091 ASSERT_VK_SUCCESS(err);
5092 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
5093 ASSERT_VK_SUCCESS(err);
5094 // Correctly update descriptor to avoid "NOT_UPDATED" error
5095 VkDescriptorBufferInfo buffInfo = {};
5096 buffInfo.buffer = buffer;
5097 buffInfo.offset = 0;
5098 buffInfo.range = 1024;
5099
5100 VkWriteDescriptorSet descriptor_write;
5101 memset(&descriptor_write, 0, sizeof(descriptor_write));
5102 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5103 descriptor_write.dstSet = descriptorSet;
5104 descriptor_write.dstBinding = 0;
5105 descriptor_write.descriptorCount = 1;
5106 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5107 descriptor_write.pBufferInfo = &buffInfo;
5108
5109 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5110
5111 // Create PSO to be used for draw-time errors below
5112 char const *vsSource = "#version 450\n"
5113 "\n"
5114 "out gl_PerVertex { \n"
5115 " vec4 gl_Position;\n"
5116 "};\n"
5117 "void main(){\n"
5118 " gl_Position = vec4(1);\n"
5119 "}\n";
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005120 char const *fsSource = "#version 450\n"
5121 "\n"
5122 "layout(location=0) out vec4 x;\n"
5123 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
5124 "void main(){\n"
5125 " x = vec4(bar.y);\n"
5126 "}\n";
Tobin Ehlis31289162016-08-17 14:57:58 -06005127 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5128 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5129 VkPipelineObj pipe(m_device);
5130 pipe.AddShader(&vs);
5131 pipe.AddShader(&fs);
5132 pipe.AddColorAttachment();
5133 pipe.CreateVKPipeline(pipeline_layout, renderPass());
5134
5135 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005136 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5137 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5138 &descriptorSet, 0, NULL);
Tobin Ehlis31289162016-08-17 14:57:58 -06005139 Draw(1, 0, 0, 0);
5140 EndCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005141 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound buffer ");
Tobin Ehlis31289162016-08-17 14:57:58 -06005142 // Destroy buffer should invalidate the cmd buffer, causing error on submit
5143 vkDestroyBuffer(m_device->device(), buffer, NULL);
5144 // Attempt to submit cmd buffer
5145 VkSubmitInfo submit_info = {};
5146 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5147 submit_info.commandBufferCount = 1;
5148 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5149 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5150 m_errorMonitor->VerifyFound();
5151 // Cleanup
5152 vkFreeMemory(m_device->device(), mem, NULL);
5153
5154 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5155 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5156 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5157}
5158
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005159TEST_F(VkLayerTest, InvalidCmdBufferDescriptorSetImageSamplerDestroyed) {
5160 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
5161 "due to a bound descriptor sets with a combined image "
5162 "sampler having their image, sampler, and descriptor set "
5163 "each respectively destroyed and then attempting to "
Mark Mueller917f6bc2016-08-30 10:57:19 -06005164 "submit associated cmd buffers. Attempt to destroy a "
5165 "DescriptorSet that is in use.");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005166 ASSERT_NO_FATAL_FAILURE(InitState());
5167 ASSERT_NO_FATAL_FAILURE(InitViewport());
5168 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5169
5170 VkDescriptorPoolSize ds_type_count = {};
5171 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5172 ds_type_count.descriptorCount = 1;
5173
5174 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5175 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5176 ds_pool_ci.pNext = NULL;
5177 ds_pool_ci.maxSets = 1;
5178 ds_pool_ci.poolSizeCount = 1;
5179 ds_pool_ci.pPoolSizes = &ds_type_count;
5180
5181 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005182 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005183 ASSERT_VK_SUCCESS(err);
5184
5185 VkDescriptorSetLayoutBinding dsl_binding = {};
5186 dsl_binding.binding = 0;
5187 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5188 dsl_binding.descriptorCount = 1;
5189 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5190 dsl_binding.pImmutableSamplers = NULL;
5191
5192 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5193 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5194 ds_layout_ci.pNext = NULL;
5195 ds_layout_ci.bindingCount = 1;
5196 ds_layout_ci.pBindings = &dsl_binding;
5197 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005198 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005199 ASSERT_VK_SUCCESS(err);
5200
5201 VkDescriptorSet descriptorSet;
5202 VkDescriptorSetAllocateInfo alloc_info = {};
5203 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
5204 alloc_info.descriptorSetCount = 1;
5205 alloc_info.descriptorPool = ds_pool;
5206 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005207 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005208 ASSERT_VK_SUCCESS(err);
5209
5210 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5211 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5212 pipeline_layout_ci.pNext = NULL;
5213 pipeline_layout_ci.setLayoutCount = 1;
5214 pipeline_layout_ci.pSetLayouts = &ds_layout;
5215
5216 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005217 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005218 ASSERT_VK_SUCCESS(err);
5219
5220 // Create images to update the descriptor with
5221 VkImage image;
5222 VkImage image2;
5223 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
5224 const int32_t tex_width = 32;
5225 const int32_t tex_height = 32;
5226 VkImageCreateInfo image_create_info = {};
5227 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5228 image_create_info.pNext = NULL;
5229 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5230 image_create_info.format = tex_format;
5231 image_create_info.extent.width = tex_width;
5232 image_create_info.extent.height = tex_height;
5233 image_create_info.extent.depth = 1;
5234 image_create_info.mipLevels = 1;
5235 image_create_info.arrayLayers = 1;
5236 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
5237 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
5238 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
5239 image_create_info.flags = 0;
5240 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
5241 ASSERT_VK_SUCCESS(err);
5242 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image2);
5243 ASSERT_VK_SUCCESS(err);
5244
5245 VkMemoryRequirements memory_reqs;
5246 VkDeviceMemory image_memory;
5247 bool pass;
5248 VkMemoryAllocateInfo memory_info = {};
5249 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5250 memory_info.pNext = NULL;
5251 memory_info.allocationSize = 0;
5252 memory_info.memoryTypeIndex = 0;
5253 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
5254 // Allocate enough memory for both images
5255 memory_info.allocationSize = memory_reqs.size * 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005256 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005257 ASSERT_TRUE(pass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005258 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005259 ASSERT_VK_SUCCESS(err);
5260 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
5261 ASSERT_VK_SUCCESS(err);
5262 // Bind second image to memory right after first image
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005263 err = vkBindImageMemory(m_device->device(), image2, image_memory, memory_reqs.size);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005264 ASSERT_VK_SUCCESS(err);
5265
5266 VkImageViewCreateInfo image_view_create_info = {};
5267 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
5268 image_view_create_info.image = image;
5269 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
5270 image_view_create_info.format = tex_format;
5271 image_view_create_info.subresourceRange.layerCount = 1;
5272 image_view_create_info.subresourceRange.baseMipLevel = 0;
5273 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005274 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005275
5276 VkImageView view;
5277 VkImageView view2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005278 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005279 ASSERT_VK_SUCCESS(err);
5280 image_view_create_info.image = image2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005281 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view2);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005282 ASSERT_VK_SUCCESS(err);
5283 // Create Samplers
5284 VkSamplerCreateInfo sampler_ci = {};
5285 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
5286 sampler_ci.pNext = NULL;
5287 sampler_ci.magFilter = VK_FILTER_NEAREST;
5288 sampler_ci.minFilter = VK_FILTER_NEAREST;
5289 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
5290 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5291 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5292 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5293 sampler_ci.mipLodBias = 1.0;
5294 sampler_ci.anisotropyEnable = VK_FALSE;
5295 sampler_ci.maxAnisotropy = 1;
5296 sampler_ci.compareEnable = VK_FALSE;
5297 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
5298 sampler_ci.minLod = 1.0;
5299 sampler_ci.maxLod = 1.0;
5300 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
5301 sampler_ci.unnormalizedCoordinates = VK_FALSE;
5302 VkSampler sampler;
5303 VkSampler sampler2;
5304 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
5305 ASSERT_VK_SUCCESS(err);
5306 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler2);
5307 ASSERT_VK_SUCCESS(err);
5308 // Update descriptor with image and sampler
5309 VkDescriptorImageInfo img_info = {};
5310 img_info.sampler = sampler;
5311 img_info.imageView = view;
5312 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
5313
5314 VkWriteDescriptorSet descriptor_write;
5315 memset(&descriptor_write, 0, sizeof(descriptor_write));
5316 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5317 descriptor_write.dstSet = descriptorSet;
5318 descriptor_write.dstBinding = 0;
5319 descriptor_write.descriptorCount = 1;
5320 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5321 descriptor_write.pImageInfo = &img_info;
5322
5323 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5324
5325 // Create PSO to be used for draw-time errors below
5326 char const *vsSource = "#version 450\n"
5327 "\n"
5328 "out gl_PerVertex { \n"
5329 " vec4 gl_Position;\n"
5330 "};\n"
5331 "void main(){\n"
5332 " gl_Position = vec4(1);\n"
5333 "}\n";
5334 char const *fsSource = "#version 450\n"
5335 "\n"
5336 "layout(set=0, binding=0) uniform sampler2D s;\n"
5337 "layout(location=0) out vec4 x;\n"
5338 "void main(){\n"
5339 " x = texture(s, vec2(1));\n"
5340 "}\n";
5341 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5342 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5343 VkPipelineObj pipe(m_device);
5344 pipe.AddShader(&vs);
5345 pipe.AddShader(&fs);
5346 pipe.AddColorAttachment();
5347 pipe.CreateVKPipeline(pipeline_layout, renderPass());
5348
5349 // First error case is destroying sampler prior to cmd buffer submission
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005350 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot submit cmd buffer using deleted sampler ");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005351 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005352 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5353 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5354 &descriptorSet, 0, NULL);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005355 Draw(1, 0, 0, 0);
5356 EndCommandBuffer();
5357 // Destroy sampler invalidates the cmd buffer, causing error on submit
5358 vkDestroySampler(m_device->device(), sampler, NULL);
5359 // Attempt to submit cmd buffer
5360 VkSubmitInfo submit_info = {};
5361 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5362 submit_info.commandBufferCount = 1;
5363 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5364 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5365 m_errorMonitor->VerifyFound();
5366 // Now re-update descriptor with valid sampler and delete image
5367 img_info.sampler = sampler2;
5368 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005369 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005370 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005371 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5372 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5373 &descriptorSet, 0, NULL);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005374 Draw(1, 0, 0, 0);
5375 EndCommandBuffer();
5376 // Destroy image invalidates the cmd buffer, causing error on submit
5377 vkDestroyImage(m_device->device(), image, NULL);
5378 // Attempt to submit cmd buffer
5379 submit_info = {};
5380 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5381 submit_info.commandBufferCount = 1;
5382 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5383 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5384 m_errorMonitor->VerifyFound();
5385 // Now update descriptor to be valid, but then free descriptor
5386 img_info.imageView = view2;
5387 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005388 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound descriptor set ");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005389 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005390 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5391 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5392 &descriptorSet, 0, NULL);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005393 Draw(1, 0, 0, 0);
5394 EndCommandBuffer();
5395 // Destroy descriptor set invalidates the cb, causing error on submit
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005396 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot call vkFreeDescriptorSets() on descriptor set 0x");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005397 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
Mark Mueller917f6bc2016-08-30 10:57:19 -06005398 m_errorMonitor->VerifyFound();
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005399 // Attempt to submit cmd buffer
5400 submit_info = {};
5401 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5402 submit_info.commandBufferCount = 1;
5403 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5404 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5405 m_errorMonitor->VerifyFound();
5406 // Cleanup
5407 vkFreeMemory(m_device->device(), image_memory, NULL);
5408 vkDestroySampler(m_device->device(), sampler2, NULL);
5409 vkDestroyImage(m_device->device(), image2, NULL);
5410 vkDestroyImageView(m_device->device(), view, NULL);
5411 vkDestroyImageView(m_device->device(), view2, NULL);
5412 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5413 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5414 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5415}
5416
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06005417TEST_F(VkLayerTest, DescriptorPoolInUseDestroyedSignaled) {
5418 TEST_DESCRIPTION("Delete a DescriptorPool with a DescriptorSet that is in use.");
5419 ASSERT_NO_FATAL_FAILURE(InitState());
5420 ASSERT_NO_FATAL_FAILURE(InitViewport());
5421 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5422
5423 VkDescriptorPoolSize ds_type_count = {};
5424 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5425 ds_type_count.descriptorCount = 1;
5426
5427 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5428 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5429 ds_pool_ci.pNext = NULL;
5430 ds_pool_ci.maxSets = 1;
5431 ds_pool_ci.poolSizeCount = 1;
5432 ds_pool_ci.pPoolSizes = &ds_type_count;
5433
5434 VkDescriptorPool ds_pool;
5435 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
5436 ASSERT_VK_SUCCESS(err);
5437
5438 VkDescriptorSetLayoutBinding dsl_binding = {};
5439 dsl_binding.binding = 0;
5440 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5441 dsl_binding.descriptorCount = 1;
5442 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5443 dsl_binding.pImmutableSamplers = NULL;
5444
5445 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5446 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5447 ds_layout_ci.pNext = NULL;
5448 ds_layout_ci.bindingCount = 1;
5449 ds_layout_ci.pBindings = &dsl_binding;
5450 VkDescriptorSetLayout ds_layout;
5451 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
5452 ASSERT_VK_SUCCESS(err);
5453
5454 VkDescriptorSet descriptor_set;
5455 VkDescriptorSetAllocateInfo alloc_info = {};
5456 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
5457 alloc_info.descriptorSetCount = 1;
5458 alloc_info.descriptorPool = ds_pool;
5459 alloc_info.pSetLayouts = &ds_layout;
5460 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
5461 ASSERT_VK_SUCCESS(err);
5462
5463 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5464 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5465 pipeline_layout_ci.pNext = NULL;
5466 pipeline_layout_ci.setLayoutCount = 1;
5467 pipeline_layout_ci.pSetLayouts = &ds_layout;
5468
5469 VkPipelineLayout pipeline_layout;
5470 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
5471 ASSERT_VK_SUCCESS(err);
5472
5473 // Create image to update the descriptor with
5474 VkImageObj image(m_device);
5475 image.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
5476 ASSERT_TRUE(image.initialized());
5477
5478 VkImageView view = image.targetView(VK_FORMAT_B8G8R8A8_UNORM);
5479 // Create Sampler
5480 VkSamplerCreateInfo sampler_ci = {};
5481 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
5482 sampler_ci.pNext = NULL;
5483 sampler_ci.magFilter = VK_FILTER_NEAREST;
5484 sampler_ci.minFilter = VK_FILTER_NEAREST;
5485 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
5486 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5487 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5488 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5489 sampler_ci.mipLodBias = 1.0;
5490 sampler_ci.anisotropyEnable = VK_FALSE;
5491 sampler_ci.maxAnisotropy = 1;
5492 sampler_ci.compareEnable = VK_FALSE;
5493 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
5494 sampler_ci.minLod = 1.0;
5495 sampler_ci.maxLod = 1.0;
5496 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
5497 sampler_ci.unnormalizedCoordinates = VK_FALSE;
5498 VkSampler sampler;
5499 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
5500 ASSERT_VK_SUCCESS(err);
5501 // Update descriptor with image and sampler
5502 VkDescriptorImageInfo img_info = {};
5503 img_info.sampler = sampler;
5504 img_info.imageView = view;
5505 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
5506
5507 VkWriteDescriptorSet descriptor_write;
5508 memset(&descriptor_write, 0, sizeof(descriptor_write));
5509 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5510 descriptor_write.dstSet = descriptor_set;
5511 descriptor_write.dstBinding = 0;
5512 descriptor_write.descriptorCount = 1;
5513 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5514 descriptor_write.pImageInfo = &img_info;
5515
5516 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5517
5518 // Create PSO to be used for draw-time errors below
5519 char const *vsSource = "#version 450\n"
5520 "\n"
5521 "out gl_PerVertex { \n"
5522 " vec4 gl_Position;\n"
5523 "};\n"
5524 "void main(){\n"
5525 " gl_Position = vec4(1);\n"
5526 "}\n";
5527 char const *fsSource = "#version 450\n"
5528 "\n"
5529 "layout(set=0, binding=0) uniform sampler2D s;\n"
5530 "layout(location=0) out vec4 x;\n"
5531 "void main(){\n"
5532 " x = texture(s, vec2(1));\n"
5533 "}\n";
5534 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5535 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5536 VkPipelineObj pipe(m_device);
5537 pipe.AddShader(&vs);
5538 pipe.AddShader(&fs);
5539 pipe.AddColorAttachment();
5540 pipe.CreateVKPipeline(pipeline_layout, renderPass());
5541
5542 BeginCommandBuffer();
5543 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5544 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5545 &descriptor_set, 0, NULL);
5546 Draw(1, 0, 0, 0);
5547 EndCommandBuffer();
5548 // Submit cmd buffer to put pool in-flight
5549 VkSubmitInfo submit_info = {};
5550 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5551 submit_info.commandBufferCount = 1;
5552 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5553 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5554 // Destroy pool while in-flight, causing error
5555 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete descriptor pool ");
5556 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5557 m_errorMonitor->VerifyFound();
5558 vkQueueWaitIdle(m_device->m_queue);
5559 // Cleanup
5560 vkDestroySampler(m_device->device(), sampler, NULL);
5561 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5562 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5563 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5564}
5565
Tobin Ehlis50a095d2016-09-21 17:32:49 -06005566TEST_F(VkLayerTest, DescriptorImageUpdateNoMemoryBound) {
5567 TEST_DESCRIPTION("Attempt an image descriptor set update where image's bound memory has been freed.");
5568 ASSERT_NO_FATAL_FAILURE(InitState());
5569 ASSERT_NO_FATAL_FAILURE(InitViewport());
5570 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5571
5572 VkDescriptorPoolSize ds_type_count = {};
5573 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5574 ds_type_count.descriptorCount = 1;
5575
5576 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5577 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5578 ds_pool_ci.pNext = NULL;
5579 ds_pool_ci.maxSets = 1;
5580 ds_pool_ci.poolSizeCount = 1;
5581 ds_pool_ci.pPoolSizes = &ds_type_count;
5582
5583 VkDescriptorPool ds_pool;
5584 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
5585 ASSERT_VK_SUCCESS(err);
5586
5587 VkDescriptorSetLayoutBinding dsl_binding = {};
5588 dsl_binding.binding = 0;
5589 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5590 dsl_binding.descriptorCount = 1;
5591 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5592 dsl_binding.pImmutableSamplers = NULL;
5593
5594 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5595 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5596 ds_layout_ci.pNext = NULL;
5597 ds_layout_ci.bindingCount = 1;
5598 ds_layout_ci.pBindings = &dsl_binding;
5599 VkDescriptorSetLayout ds_layout;
5600 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
5601 ASSERT_VK_SUCCESS(err);
5602
5603 VkDescriptorSet descriptorSet;
5604 VkDescriptorSetAllocateInfo alloc_info = {};
5605 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
5606 alloc_info.descriptorSetCount = 1;
5607 alloc_info.descriptorPool = ds_pool;
5608 alloc_info.pSetLayouts = &ds_layout;
5609 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
5610 ASSERT_VK_SUCCESS(err);
5611
5612 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5613 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5614 pipeline_layout_ci.pNext = NULL;
5615 pipeline_layout_ci.setLayoutCount = 1;
5616 pipeline_layout_ci.pSetLayouts = &ds_layout;
5617
5618 VkPipelineLayout pipeline_layout;
5619 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
5620 ASSERT_VK_SUCCESS(err);
5621
5622 // Create images to update the descriptor with
5623 VkImage image;
5624 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
5625 const int32_t tex_width = 32;
5626 const int32_t tex_height = 32;
5627 VkImageCreateInfo image_create_info = {};
5628 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5629 image_create_info.pNext = NULL;
5630 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5631 image_create_info.format = tex_format;
5632 image_create_info.extent.width = tex_width;
5633 image_create_info.extent.height = tex_height;
5634 image_create_info.extent.depth = 1;
5635 image_create_info.mipLevels = 1;
5636 image_create_info.arrayLayers = 1;
5637 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
5638 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
5639 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
5640 image_create_info.flags = 0;
5641 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
5642 ASSERT_VK_SUCCESS(err);
5643 // Initially bind memory to avoid error at bind view time. We'll break binding before update.
5644 VkMemoryRequirements memory_reqs;
5645 VkDeviceMemory image_memory;
5646 bool pass;
5647 VkMemoryAllocateInfo memory_info = {};
5648 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5649 memory_info.pNext = NULL;
5650 memory_info.allocationSize = 0;
5651 memory_info.memoryTypeIndex = 0;
5652 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
5653 // Allocate enough memory for image
5654 memory_info.allocationSize = memory_reqs.size;
5655 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
5656 ASSERT_TRUE(pass);
5657 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
5658 ASSERT_VK_SUCCESS(err);
5659 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
5660 ASSERT_VK_SUCCESS(err);
5661
5662 VkImageViewCreateInfo image_view_create_info = {};
5663 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
5664 image_view_create_info.image = image;
5665 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
5666 image_view_create_info.format = tex_format;
5667 image_view_create_info.subresourceRange.layerCount = 1;
5668 image_view_create_info.subresourceRange.baseMipLevel = 0;
5669 image_view_create_info.subresourceRange.levelCount = 1;
5670 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
5671
5672 VkImageView view;
5673 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
5674 ASSERT_VK_SUCCESS(err);
5675 // Create Samplers
5676 VkSamplerCreateInfo sampler_ci = {};
5677 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
5678 sampler_ci.pNext = NULL;
5679 sampler_ci.magFilter = VK_FILTER_NEAREST;
5680 sampler_ci.minFilter = VK_FILTER_NEAREST;
5681 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
5682 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5683 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5684 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5685 sampler_ci.mipLodBias = 1.0;
5686 sampler_ci.anisotropyEnable = VK_FALSE;
5687 sampler_ci.maxAnisotropy = 1;
5688 sampler_ci.compareEnable = VK_FALSE;
5689 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
5690 sampler_ci.minLod = 1.0;
5691 sampler_ci.maxLod = 1.0;
5692 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
5693 sampler_ci.unnormalizedCoordinates = VK_FALSE;
5694 VkSampler sampler;
5695 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
5696 ASSERT_VK_SUCCESS(err);
5697 // Update descriptor with image and sampler
5698 VkDescriptorImageInfo img_info = {};
5699 img_info.sampler = sampler;
5700 img_info.imageView = view;
5701 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
5702
5703 VkWriteDescriptorSet descriptor_write;
5704 memset(&descriptor_write, 0, sizeof(descriptor_write));
5705 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5706 descriptor_write.dstSet = descriptorSet;
5707 descriptor_write.dstBinding = 0;
5708 descriptor_write.descriptorCount = 1;
5709 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5710 descriptor_write.pImageInfo = &img_info;
5711 // Break memory binding and attempt update
5712 vkFreeMemory(m_device->device(), image_memory, nullptr);
5713 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06005714 " previously bound memory was freed. Memory must not be freed prior to this operation.");
Tobin Ehlis50a095d2016-09-21 17:32:49 -06005715 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
5716 "vkUpdateDescriptorsSets() failed write update validation for Descriptor Set 0x");
5717 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5718 m_errorMonitor->VerifyFound();
5719 // Cleanup
5720 vkDestroyImage(m_device->device(), image, NULL);
5721 vkDestroySampler(m_device->device(), sampler, NULL);
5722 vkDestroyImageView(m_device->device(), view, NULL);
5723 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5724 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5725 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5726}
5727
Karl Schultz6addd812016-02-02 17:17:23 -07005728TEST_F(VkLayerTest, InvalidPipeline) {
Karl Schultzbdb75952016-04-19 11:36:49 -06005729 // Attempt to bind an invalid Pipeline to a valid Command Buffer
5730 // ObjectTracker should catch this.
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06005731 // Create a valid cmd buffer
5732 // call vkCmdBindPipeline w/ false Pipeline
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06005733 uint64_t fake_pipeline_handle = 0xbaad6001;
5734 VkPipeline bad_pipeline = reinterpret_cast<VkPipeline &>(fake_pipeline_handle);
Karl Schultzbdb75952016-04-19 11:36:49 -06005735 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes4dbf70f2016-09-16 17:58:00 +12005736 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5737
Karl Schultzf78bcdd2016-11-30 12:36:01 -07005738 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00601);
Karl Schultzbdb75952016-04-19 11:36:49 -06005739 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005740 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, bad_pipeline);
Karl Schultzbdb75952016-04-19 11:36:49 -06005741 m_errorMonitor->VerifyFound();
Chris Forbes4dbf70f2016-09-16 17:58:00 +12005742
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06005743 // Now issue a draw call with no pipeline bound
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005744 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 -06005745 Draw(1, 0, 0, 0);
5746 m_errorMonitor->VerifyFound();
Chris Forbes4dbf70f2016-09-16 17:58:00 +12005747
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06005748 // Finally same check once more but with Dispatch/Compute
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005749 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 +12005750 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle()); // must be outside renderpass
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06005751 vkCmdDispatch(m_commandBuffer->GetBufferHandle(), 0, 0, 0);
5752 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06005753}
5754
Karl Schultz6addd812016-02-02 17:17:23 -07005755TEST_F(VkLayerTest, DescriptorSetNotUpdated) {
Tobin Ehlis5a5f5ef2016-08-17 13:56:55 -06005756 TEST_DESCRIPTION("Bind a descriptor set that hasn't been updated.");
Karl Schultz6addd812016-02-02 17:17:23 -07005757 VkResult err;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005758
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005759 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, " bound but it was never updated. ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005760
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005761 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyan713b2d72015-08-04 10:49:29 -06005762 ASSERT_NO_FATAL_FAILURE(InitViewport());
5763 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08005764 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005765 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5766 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06005767
5768 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005769 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5770 ds_pool_ci.pNext = NULL;
5771 ds_pool_ci.maxSets = 1;
5772 ds_pool_ci.poolSizeCount = 1;
5773 ds_pool_ci.pPoolSizes = &ds_type_count;
Mike Stroyan713b2d72015-08-04 10:49:29 -06005774
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005775 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005776 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005777 ASSERT_VK_SUCCESS(err);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005778
Tony Barboureb254902015-07-15 12:50:33 -06005779 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005780 dsl_binding.binding = 0;
5781 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5782 dsl_binding.descriptorCount = 1;
5783 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5784 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005785
Tony Barboureb254902015-07-15 12:50:33 -06005786 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005787 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5788 ds_layout_ci.pNext = NULL;
5789 ds_layout_ci.bindingCount = 1;
5790 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005791 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005792 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005793 ASSERT_VK_SUCCESS(err);
5794
5795 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005796 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08005797 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07005798 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06005799 alloc_info.descriptorPool = ds_pool;
5800 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005801 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005802 ASSERT_VK_SUCCESS(err);
5803
Tony Barboureb254902015-07-15 12:50:33 -06005804 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005805 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5806 pipeline_layout_ci.pNext = NULL;
5807 pipeline_layout_ci.setLayoutCount = 1;
5808 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005809
5810 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005811 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005812 ASSERT_VK_SUCCESS(err);
5813
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005814 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -06005815 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -07005816 // on more devices
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005817 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005818
Tony Barbourc95e4ac2015-08-04 17:05:26 -06005819 VkPipelineObj pipe(m_device);
5820 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06005821 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -06005822 pipe.AddColorAttachment();
Tony Barbourc95e4ac2015-08-04 17:05:26 -06005823 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06005824
5825 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005826 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5827 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5828 &descriptorSet, 0, NULL);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005829
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005830 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06005831
Chia-I Wuf7458c52015-10-26 21:10:41 +08005832 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5833 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5834 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06005835}
5836
Karl Schultz6addd812016-02-02 17:17:23 -07005837TEST_F(VkLayerTest, InvalidBufferViewObject) {
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005838 // Create a single TEXEL_BUFFER descriptor and send it an invalid bufferView
Karl Schultz6addd812016-02-02 17:17:23 -07005839 VkResult err;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005840
Karl Schultzf78bcdd2016-11-30 12:36:01 -07005841 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00940);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005842
5843 ASSERT_NO_FATAL_FAILURE(InitState());
5844 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005845 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
5846 ds_type_count.descriptorCount = 1;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005847
5848 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005849 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5850 ds_pool_ci.pNext = NULL;
5851 ds_pool_ci.maxSets = 1;
5852 ds_pool_ci.poolSizeCount = 1;
5853 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005854
5855 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005856 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005857 ASSERT_VK_SUCCESS(err);
5858
5859 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005860 dsl_binding.binding = 0;
5861 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
5862 dsl_binding.descriptorCount = 1;
5863 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5864 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005865
5866 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005867 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5868 ds_layout_ci.pNext = NULL;
5869 ds_layout_ci.bindingCount = 1;
5870 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005871 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005872 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005873 ASSERT_VK_SUCCESS(err);
5874
5875 VkDescriptorSet descriptorSet;
5876 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08005877 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07005878 alloc_info.descriptorSetCount = 1;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005879 alloc_info.descriptorPool = ds_pool;
5880 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005881 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005882 ASSERT_VK_SUCCESS(err);
5883
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005884 VkBufferView view = (VkBufferView)((size_t)0xbaadbeef); // invalid bufferView object
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005885 VkWriteDescriptorSet descriptor_write;
5886 memset(&descriptor_write, 0, sizeof(descriptor_write));
5887 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5888 descriptor_write.dstSet = descriptorSet;
5889 descriptor_write.dstBinding = 0;
5890 descriptor_write.descriptorCount = 1;
5891 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
5892 descriptor_write.pTexelBufferView = &view;
5893
5894 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5895
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005896 m_errorMonitor->VerifyFound();
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005897
5898 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5899 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5900}
5901
Mark Youngd339ba32016-05-30 13:28:35 -06005902TEST_F(VkLayerTest, CreateBufferViewNoMemoryBoundToBuffer) {
Tobin Ehlis4ff58172016-09-22 10:52:00 -06005903 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 -06005904
5905 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -06005906 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06005907 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Mark Youngd339ba32016-05-30 13:28:35 -06005908
5909 ASSERT_NO_FATAL_FAILURE(InitState());
5910
5911 // Create a buffer with no bound memory and then attempt to create
5912 // a buffer view.
5913 VkBufferCreateInfo buff_ci = {};
5914 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes4538d242016-09-13 18:13:58 +12005915 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT;
Mark Youngd339ba32016-05-30 13:28:35 -06005916 buff_ci.size = 256;
5917 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
5918 VkBuffer buffer;
5919 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
5920 ASSERT_VK_SUCCESS(err);
5921
5922 VkBufferViewCreateInfo buff_view_ci = {};
5923 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
5924 buff_view_ci.buffer = buffer;
5925 buff_view_ci.format = VK_FORMAT_R8_UNORM;
5926 buff_view_ci.range = VK_WHOLE_SIZE;
5927 VkBufferView buff_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005928 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buff_view);
Mark Youngd339ba32016-05-30 13:28:35 -06005929
5930 m_errorMonitor->VerifyFound();
5931 vkDestroyBuffer(m_device->device(), buffer, NULL);
5932 // If last error is success, it still created the view, so delete it.
5933 if (err == VK_SUCCESS) {
5934 vkDestroyBufferView(m_device->device(), buff_view, NULL);
5935 }
5936}
5937
Karl Schultz6addd812016-02-02 17:17:23 -07005938TEST_F(VkLayerTest, InvalidDynamicOffsetCases) {
5939 // Create a descriptorSet w/ dynamic descriptor and then hit 3 offset error
5940 // cases:
Tobin Ehlisf6585052015-12-17 11:48:42 -07005941 // 1. No dynamicOffset supplied
5942 // 2. Too many dynamicOffsets supplied
5943 // 3. Dynamic offset oversteps buffer being updated
Karl Schultz6addd812016-02-02 17:17:23 -07005944 VkResult err;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005945 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " requires 1 dynamicOffsets, but only "
5946 "0 dynamicOffsets are left in "
5947 "pDynamicOffsets ");
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005948
5949 ASSERT_NO_FATAL_FAILURE(InitState());
5950 ASSERT_NO_FATAL_FAILURE(InitViewport());
5951 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5952
5953 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005954 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
5955 ds_type_count.descriptorCount = 1;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005956
5957 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005958 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5959 ds_pool_ci.pNext = NULL;
5960 ds_pool_ci.maxSets = 1;
5961 ds_pool_ci.poolSizeCount = 1;
5962 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005963
5964 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005965 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005966 ASSERT_VK_SUCCESS(err);
5967
5968 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005969 dsl_binding.binding = 0;
5970 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
5971 dsl_binding.descriptorCount = 1;
5972 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5973 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005974
5975 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005976 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5977 ds_layout_ci.pNext = NULL;
5978 ds_layout_ci.bindingCount = 1;
5979 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005980 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005981 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005982 ASSERT_VK_SUCCESS(err);
5983
5984 VkDescriptorSet descriptorSet;
5985 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08005986 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07005987 alloc_info.descriptorSetCount = 1;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005988 alloc_info.descriptorPool = ds_pool;
5989 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005990 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005991 ASSERT_VK_SUCCESS(err);
5992
5993 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005994 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5995 pipeline_layout_ci.pNext = NULL;
5996 pipeline_layout_ci.setLayoutCount = 1;
5997 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005998
5999 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006000 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006001 ASSERT_VK_SUCCESS(err);
6002
6003 // Create a buffer to update the descriptor with
6004 uint32_t qfi = 0;
6005 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006006 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
6007 buffCI.size = 1024;
6008 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
6009 buffCI.queueFamilyIndexCount = 1;
6010 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006011
6012 VkBuffer dyub;
6013 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
6014 ASSERT_VK_SUCCESS(err);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06006015 // Allocate memory and bind to buffer so we can make it to the appropriate
6016 // error
6017 VkMemoryAllocateInfo mem_alloc = {};
6018 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
6019 mem_alloc.pNext = NULL;
6020 mem_alloc.allocationSize = 1024;
Chris Forbesb6116cc2016-05-08 11:39:59 +12006021 mem_alloc.memoryTypeIndex = 0;
6022
6023 VkMemoryRequirements memReqs;
6024 vkGetBufferMemoryRequirements(m_device->device(), dyub, &memReqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006025 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
Chris Forbesb6116cc2016-05-08 11:39:59 +12006026 if (!pass) {
6027 vkDestroyBuffer(m_device->device(), dyub, NULL);
6028 return;
6029 }
6030
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06006031 VkDeviceMemory mem;
6032 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
6033 ASSERT_VK_SUCCESS(err);
6034 err = vkBindBufferMemory(m_device->device(), dyub, mem, 0);
6035 ASSERT_VK_SUCCESS(err);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006036 // Correctly update descriptor to avoid "NOT_UPDATED" error
6037 VkDescriptorBufferInfo buffInfo = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006038 buffInfo.buffer = dyub;
6039 buffInfo.offset = 0;
6040 buffInfo.range = 1024;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006041
6042 VkWriteDescriptorSet descriptor_write;
6043 memset(&descriptor_write, 0, sizeof(descriptor_write));
6044 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6045 descriptor_write.dstSet = descriptorSet;
6046 descriptor_write.dstBinding = 0;
6047 descriptor_write.descriptorCount = 1;
6048 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6049 descriptor_write.pBufferInfo = &buffInfo;
6050
6051 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6052
6053 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006054 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6055 &descriptorSet, 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006056 m_errorMonitor->VerifyFound();
Tobin Ehlisf6585052015-12-17 11:48:42 -07006057 uint32_t pDynOff[2] = {512, 756};
6058 // Now cause error b/c too many dynOffsets in array for # of dyn descriptors
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006059 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6060 "Attempting to bind 1 descriptorSets with 1 dynamic descriptors, but ");
6061 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6062 &descriptorSet, 2, pDynOff);
Chris Forbes7b342802016-04-07 13:20:10 +12006063 m_errorMonitor->VerifyFound();
Tobin Ehlisf6585052015-12-17 11:48:42 -07006064 // Finally cause error due to dynamicOffset being too big
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006065 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " dynamic offset 512 combined with "
6066 "offset 0 and range 1024 that "
6067 "oversteps the buffer size of 1024");
Tobin Ehlisf6585052015-12-17 11:48:42 -07006068 // Create PSO to be used for draw-time errors below
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006069 char const *vsSource = "#version 450\n"
6070 "\n"
6071 "out gl_PerVertex { \n"
6072 " vec4 gl_Position;\n"
6073 "};\n"
6074 "void main(){\n"
6075 " gl_Position = vec4(1);\n"
6076 "}\n";
6077 char const *fsSource = "#version 450\n"
6078 "\n"
6079 "layout(location=0) out vec4 x;\n"
6080 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
6081 "void main(){\n"
6082 " x = vec4(bar.y);\n"
6083 "}\n";
Tobin Ehlisf6585052015-12-17 11:48:42 -07006084 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
6085 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
6086 VkPipelineObj pipe(m_device);
6087 pipe.AddShader(&vs);
6088 pipe.AddShader(&fs);
6089 pipe.AddColorAttachment();
6090 pipe.CreateVKPipeline(pipeline_layout, renderPass());
6091
Rene Lindsayacbf5e62016-12-15 18:47:11 -07006092 VkViewport viewport = {0, 0, 16, 16, 0, 1};
6093 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
6094 VkRect2D scissor = {{0, 0}, {16, 16}};
6095 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
6096
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006097 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07006098 // This update should succeed, but offset size of 512 will overstep buffer
6099 // /w range 1024 & size 1024
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006100 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6101 &descriptorSet, 1, pDynOff);
Tobin Ehlisf6585052015-12-17 11:48:42 -07006102 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006103 m_errorMonitor->VerifyFound();
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006104
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06006105 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tobin Ehlis512098e2016-05-05 09:06:12 -06006106 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06006107
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006108 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06006109 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006110 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6111}
6112
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006113TEST_F(VkLayerTest, DescriptorBufferUpdateNoMemoryBound) {
6114 TEST_DESCRIPTION("Attempt to update a descriptor with a non-sparse buffer "
6115 "that doesn't have memory bound");
6116 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -06006117 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06006118 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Tobin Ehlisfed999f2016-09-21 15:09:45 -06006119 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6120 "vkUpdateDescriptorsSets() failed write update validation for Descriptor Set 0x");
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006121
6122 ASSERT_NO_FATAL_FAILURE(InitState());
6123 ASSERT_NO_FATAL_FAILURE(InitViewport());
6124 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6125
6126 VkDescriptorPoolSize ds_type_count = {};
6127 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6128 ds_type_count.descriptorCount = 1;
6129
6130 VkDescriptorPoolCreateInfo ds_pool_ci = {};
6131 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6132 ds_pool_ci.pNext = NULL;
6133 ds_pool_ci.maxSets = 1;
6134 ds_pool_ci.poolSizeCount = 1;
6135 ds_pool_ci.pPoolSizes = &ds_type_count;
6136
6137 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006138 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006139 ASSERT_VK_SUCCESS(err);
6140
6141 VkDescriptorSetLayoutBinding dsl_binding = {};
6142 dsl_binding.binding = 0;
6143 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6144 dsl_binding.descriptorCount = 1;
6145 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6146 dsl_binding.pImmutableSamplers = NULL;
6147
6148 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
6149 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6150 ds_layout_ci.pNext = NULL;
6151 ds_layout_ci.bindingCount = 1;
6152 ds_layout_ci.pBindings = &dsl_binding;
6153 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006154 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006155 ASSERT_VK_SUCCESS(err);
6156
6157 VkDescriptorSet descriptorSet;
6158 VkDescriptorSetAllocateInfo alloc_info = {};
6159 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
6160 alloc_info.descriptorSetCount = 1;
6161 alloc_info.descriptorPool = ds_pool;
6162 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006163 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006164 ASSERT_VK_SUCCESS(err);
6165
6166 // Create a buffer to update the descriptor with
6167 uint32_t qfi = 0;
6168 VkBufferCreateInfo buffCI = {};
6169 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
6170 buffCI.size = 1024;
6171 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
6172 buffCI.queueFamilyIndexCount = 1;
6173 buffCI.pQueueFamilyIndices = &qfi;
6174
6175 VkBuffer dyub;
6176 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
6177 ASSERT_VK_SUCCESS(err);
6178
6179 // Attempt to update descriptor without binding memory to it
6180 VkDescriptorBufferInfo buffInfo = {};
6181 buffInfo.buffer = dyub;
6182 buffInfo.offset = 0;
6183 buffInfo.range = 1024;
6184
6185 VkWriteDescriptorSet descriptor_write;
6186 memset(&descriptor_write, 0, sizeof(descriptor_write));
6187 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6188 descriptor_write.dstSet = descriptorSet;
6189 descriptor_write.dstBinding = 0;
6190 descriptor_write.descriptorCount = 1;
6191 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6192 descriptor_write.pBufferInfo = &buffInfo;
6193
6194 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6195 m_errorMonitor->VerifyFound();
6196
6197 vkDestroyBuffer(m_device->device(), dyub, NULL);
6198 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6199 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6200}
6201
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006202TEST_F(VkLayerTest, InvalidPushConstants) {
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006203 VkResult err;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006204 ASSERT_NO_FATAL_FAILURE(InitState());
6205 ASSERT_NO_FATAL_FAILURE(InitViewport());
6206 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6207
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006208 VkPipelineLayout pipeline_layout;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006209 VkPushConstantRange pc_range = {};
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006210 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
6211 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6212 pipeline_layout_ci.pushConstantRangeCount = 1;
6213 pipeline_layout_ci.pPushConstantRanges = &pc_range;
6214
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006215 //
6216 // Check for invalid push constant ranges in pipeline layouts.
6217 //
6218 struct PipelineLayoutTestCase {
Karl Schultzc81037d2016-05-12 08:11:23 -06006219 VkPushConstantRange const range;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006220 char const *msg;
6221 };
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006222
Karl Schultzc81037d2016-05-12 08:11:23 -06006223 const uint32_t too_big = m_device->props.limits.maxPushConstantsSize + 0x4;
6224 const std::array<PipelineLayoutTestCase, 10> range_tests = {{
6225 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 0},
6226 "vkCreatePipelineLayout() call has push constants index 0 with "
6227 "size 0."},
6228 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 1},
6229 "vkCreatePipelineLayout() call has push constants index 0 with "
6230 "size 1."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006231 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 1},
Karl Schultzc81037d2016-05-12 08:11:23 -06006232 "vkCreatePipelineLayout() call has push constants index 0 with "
6233 "size 1."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006234 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 0},
Karl Schultzc81037d2016-05-12 08:11:23 -06006235 "vkCreatePipelineLayout() call has push constants index 0 with "
6236 "size 0."},
6237 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
6238 "vkCreatePipelineLayout() call has push constants index 0 with "
6239 "offset 1. Offset must"},
6240 {{VK_SHADER_STAGE_VERTEX_BIT, 0, too_big},
6241 "vkCreatePipelineLayout() call has push constants index 0 "
6242 "with offset "},
6243 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, too_big},
6244 "vkCreatePipelineLayout() call has push constants "
6245 "index 0 with offset "},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006246 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, 4},
Karl Schultzc81037d2016-05-12 08:11:23 -06006247 "vkCreatePipelineLayout() call has push constants index 0 "
6248 "with offset "},
6249 {{VK_SHADER_STAGE_VERTEX_BIT, 0xFFFFFFF0, 0x00000020},
6250 "vkCreatePipelineLayout() call has push "
6251 "constants index 0 with offset "},
6252 {{VK_SHADER_STAGE_VERTEX_BIT, 0x00000020, 0xFFFFFFF0},
6253 "vkCreatePipelineLayout() call has push "
6254 "constants index 0 with offset "},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006255 }};
6256
6257 // Check for invalid offset and size
Karl Schultzc81037d2016-05-12 08:11:23 -06006258 for (const auto &iter : range_tests) {
6259 pc_range = iter.range;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006260 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
6261 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006262 m_errorMonitor->VerifyFound();
6263 if (VK_SUCCESS == err) {
6264 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6265 }
6266 }
6267
6268 // Check for invalid stage flag
6269 pc_range.offset = 0;
6270 pc_range.size = 16;
6271 pc_range.stageFlags = 0;
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006272 m_errorMonitor->SetDesiredFailureMsg(
6273 VK_DEBUG_REPORT_ERROR_BIT_EXT,
6274 "vkCreatePipelineLayout: value of pCreateInfo->pPushConstantRanges[0].stageFlags must not be 0");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006275 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006276 m_errorMonitor->VerifyFound();
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006277 if (VK_SUCCESS == err) {
6278 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6279 }
6280
6281 // Check for overlapping ranges
Karl Schultzc81037d2016-05-12 08:11:23 -06006282 const uint32_t ranges_per_test = 5;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006283 struct OverlappingRangeTestCase {
Karl Schultzc81037d2016-05-12 08:11:23 -06006284 VkPushConstantRange const ranges[ranges_per_test];
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006285 char const *msg;
6286 };
6287
Karl Schultzc81037d2016-05-12 08:11:23 -06006288 const std::array<OverlappingRangeTestCase, 5> overlapping_range_tests = {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006289 {{{{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6290 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6291 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6292 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6293 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006294 "vkCreatePipelineLayout() call has push constants with overlapping ranges:"},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006295 {
6296 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6297 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
6298 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
6299 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
6300 {VK_SHADER_STAGE_VERTEX_BIT, 16, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006301 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 3:[12, 20), 4:[16, 20)",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006302 },
6303 {
6304 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
6305 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
6306 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
6307 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
6308 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006309 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 0:[16, 20), 1:[12, 20)",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006310 },
6311 {
6312 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
6313 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
6314 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
6315 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
6316 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006317 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 0:[16, 20), 3:[12, 20)",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006318 },
6319 {
6320 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
6321 {VK_SHADER_STAGE_VERTEX_BIT, 32, 4},
6322 {VK_SHADER_STAGE_VERTEX_BIT, 4, 96},
6323 {VK_SHADER_STAGE_VERTEX_BIT, 40, 8},
6324 {VK_SHADER_STAGE_VERTEX_BIT, 52, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006325 "vkCreatePipelineLayout() call has push constants with overlapping ranges:",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006326 }}};
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006327
Karl Schultzc81037d2016-05-12 08:11:23 -06006328 for (const auto &iter : overlapping_range_tests) {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006329 pipeline_layout_ci.pPushConstantRanges = iter.ranges;
Karl Schultzc81037d2016-05-12 08:11:23 -06006330 pipeline_layout_ci.pushConstantRangeCount = ranges_per_test;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006331 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, iter.msg);
6332 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006333 m_errorMonitor->VerifyFound();
6334 if (VK_SUCCESS == err) {
6335 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6336 }
6337 }
6338
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006339 //
6340 // CmdPushConstants tests
6341 //
Karl Schultzc81037d2016-05-12 08:11:23 -06006342 const uint8_t dummy_values[100] = {};
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006343
6344 // Check for invalid offset and size and if range is within layout range(s)
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006345 const std::array<PipelineLayoutTestCase, 11> cmd_range_tests = {{
6346 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 0}, "vkCmdPushConstants: parameter size must be greater than 0"},
Karl Schultzc81037d2016-05-12 08:11:23 -06006347 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 1},
Dave Houlton197211a2016-12-23 15:26:29 -07006348 "vkCmdPushConstants() call has push constants index 0 with size 1. "
6349 "Size must be a multiple of 4."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006350 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 1},
Dave Houlton197211a2016-12-23 15:26:29 -07006351 "vkCmdPushConstants() call has push constants index 0 with size 1. "
6352 "Size must be a multiple of 4."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006353 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
Karl Schultzc81037d2016-05-12 08:11:23 -06006354 "vkCmdPushConstants() call has push constants with offset 1. "
6355 "Offset must be a multiple of 4."},
6356 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
6357 "vkCmdPushConstants() call has push constants with offset 1. "
6358 "Offset must be a multiple of 4."},
6359 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 20},
6360 "vkCmdPushConstants() Push constant range [0, 20) with stageFlags = "
6361 "0x1 not within flag-matching ranges in pipeline layout"},
6362 {{VK_SHADER_STAGE_VERTEX_BIT, 60, 8},
6363 "vkCmdPushConstants() Push constant range [60, 68) with stageFlags = "
6364 "0x1 not within flag-matching ranges in pipeline layout"},
6365 {{VK_SHADER_STAGE_VERTEX_BIT, 76, 8},
6366 "vkCmdPushConstants() Push constant range [76, 84) with stageFlags = "
6367 "0x1 not within flag-matching ranges in pipeline layout"},
6368 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 80},
6369 "vkCmdPushConstants() Push constant range [0, 80) with stageFlags = "
6370 "0x1 not within flag-matching ranges in pipeline layout"},
6371 {{VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, 0, 4},
6372 "vkCmdPushConstants() stageFlags = 0x2 do not match the stageFlags in "
6373 "any of the ranges in pipeline layout"},
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006374 {{VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, 0, 16},
Karl Schultzc81037d2016-05-12 08:11:23 -06006375 "vkCmdPushConstants() stageFlags = 0x3 do not match the stageFlags in "
6376 "any of the ranges in pipeline layout"},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006377 }};
6378
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006379 BeginCommandBuffer();
6380
6381 // Setup ranges: [0,16) [64,80)
Karl Schultzc81037d2016-05-12 08:11:23 -06006382 const VkPushConstantRange pc_range2[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006383 {VK_SHADER_STAGE_VERTEX_BIT, 64, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 0, 16},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006384 };
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006385 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range2) / sizeof(VkPushConstantRange);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006386 pipeline_layout_ci.pPushConstantRanges = pc_range2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006387 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006388 ASSERT_VK_SUCCESS(err);
Karl Schultzc81037d2016-05-12 08:11:23 -06006389 for (const auto &iter : cmd_range_tests) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006390 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
6391 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.range.stageFlags, iter.range.offset,
Karl Schultzc81037d2016-05-12 08:11:23 -06006392 iter.range.size, dummy_values);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006393 m_errorMonitor->VerifyFound();
6394 }
6395
6396 // Check for invalid stage flag
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006397 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdPushConstants: value of stageFlags must not be 0");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006398 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, 0, 0, 16, dummy_values);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006399 m_errorMonitor->VerifyFound();
Karl Schultzc81037d2016-05-12 08:11:23 -06006400 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006401
Karl Schultzc81037d2016-05-12 08:11:23 -06006402 // overlapping range tests with cmd
6403 const std::array<PipelineLayoutTestCase, 3> cmd_overlap_tests = {{
6404 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 20},
6405 "vkCmdPushConstants() Push constant range [0, 20) with stageFlags = "
6406 "0x1 not within flag-matching ranges in pipeline layout"},
6407 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
6408 "vkCmdPushConstants() Push constant range [16, 20) with stageFlags = "
6409 "0x1 not within flag-matching ranges in pipeline layout"},
6410 {{VK_SHADER_STAGE_VERTEX_BIT, 40, 16},
6411 "vkCmdPushConstants() Push constant range [40, 56) with stageFlags = "
6412 "0x1 not within flag-matching ranges in pipeline layout"},
6413 }};
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006414 // Setup ranges: [0,16), [20,36), [36,44), [44,52), [80,92)
Karl Schultzc81037d2016-05-12 08:11:23 -06006415 const VkPushConstantRange pc_range3[] = {
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006416 {VK_SHADER_STAGE_VERTEX_BIT, 20, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 0, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 44, 8},
6417 {VK_SHADER_STAGE_VERTEX_BIT, 80, 12}, {VK_SHADER_STAGE_VERTEX_BIT, 36, 8},
Karl Schultzc81037d2016-05-12 08:11:23 -06006418 };
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006419 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range3) / sizeof(VkPushConstantRange);
Karl Schultzc81037d2016-05-12 08:11:23 -06006420 pipeline_layout_ci.pPushConstantRanges = pc_range3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006421 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzc81037d2016-05-12 08:11:23 -06006422 ASSERT_VK_SUCCESS(err);
Karl Schultzc81037d2016-05-12 08:11:23 -06006423 for (const auto &iter : cmd_overlap_tests) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006424 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
6425 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.range.stageFlags, iter.range.offset,
Karl Schultzc81037d2016-05-12 08:11:23 -06006426 iter.range.size, dummy_values);
6427 m_errorMonitor->VerifyFound();
6428 }
Karl Schultzc81037d2016-05-12 08:11:23 -06006429 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6430
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006431 EndCommandBuffer();
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006432}
6433
Karl Schultz6addd812016-02-02 17:17:23 -07006434TEST_F(VkLayerTest, DescriptorSetCompatibility) {
Tobin Ehlis559c6382015-11-05 09:52:49 -07006435 // Test various desriptorSet errors with bad binding combinations
Karl Schultz6addd812016-02-02 17:17:23 -07006436 VkResult err;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006437
6438 ASSERT_NO_FATAL_FAILURE(InitState());
6439 ASSERT_NO_FATAL_FAILURE(InitViewport());
6440 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6441
Mike Stroyanb8a61002016-06-20 16:00:28 -06006442 const VkFormat tex_format = VK_FORMAT_R8G8B8A8_UNORM;
6443 VkImageTiling tiling;
6444 VkFormatProperties format_properties;
6445 vkGetPhysicalDeviceFormatProperties(gpu(), tex_format, &format_properties);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006446 if (format_properties.linearTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
Mike Stroyanb8a61002016-06-20 16:00:28 -06006447 tiling = VK_IMAGE_TILING_LINEAR;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006448 } else if (format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
Mike Stroyanb8a61002016-06-20 16:00:28 -06006449 tiling = VK_IMAGE_TILING_OPTIMAL;
6450 } else {
6451 printf("Device does not support VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT; "
6452 "skipped.\n");
6453 return;
6454 }
6455
Tobin Ehlis559c6382015-11-05 09:52:49 -07006456 static const uint32_t NUM_DESCRIPTOR_TYPES = 5;
6457 VkDescriptorPoolSize ds_type_count[NUM_DESCRIPTOR_TYPES] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006458 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6459 ds_type_count[0].descriptorCount = 10;
6460 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
6461 ds_type_count[1].descriptorCount = 2;
6462 ds_type_count[2].type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
6463 ds_type_count[2].descriptorCount = 2;
6464 ds_type_count[3].type = VK_DESCRIPTOR_TYPE_SAMPLER;
6465 ds_type_count[3].descriptorCount = 5;
6466 // TODO : LunarG ILO driver currently asserts in desc.c w/ INPUT_ATTACHMENT
6467 // type
6468 // ds_type_count[4].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
6469 ds_type_count[4].type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
6470 ds_type_count[4].descriptorCount = 2;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006471
6472 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006473 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6474 ds_pool_ci.pNext = NULL;
6475 ds_pool_ci.maxSets = 5;
6476 ds_pool_ci.poolSizeCount = NUM_DESCRIPTOR_TYPES;
6477 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006478
6479 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006480 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006481 ASSERT_VK_SUCCESS(err);
6482
6483 static const uint32_t MAX_DS_TYPES_IN_LAYOUT = 2;
6484 VkDescriptorSetLayoutBinding dsl_binding[MAX_DS_TYPES_IN_LAYOUT] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006485 dsl_binding[0].binding = 0;
6486 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6487 dsl_binding[0].descriptorCount = 5;
6488 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
6489 dsl_binding[0].pImmutableSamplers = NULL;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006490
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006491 // Create layout identical to set0 layout but w/ different stageFlags
6492 VkDescriptorSetLayoutBinding dsl_fs_stage_only = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006493 dsl_fs_stage_only.binding = 0;
6494 dsl_fs_stage_only.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6495 dsl_fs_stage_only.descriptorCount = 5;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006496 dsl_fs_stage_only.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT; // Different stageFlags to cause error at
6497 // bind time
Karl Schultz6addd812016-02-02 17:17:23 -07006498 dsl_fs_stage_only.pImmutableSamplers = NULL;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006499 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006500 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6501 ds_layout_ci.pNext = NULL;
6502 ds_layout_ci.bindingCount = 1;
6503 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006504 static const uint32_t NUM_LAYOUTS = 4;
6505 VkDescriptorSetLayout ds_layout[NUM_LAYOUTS] = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006506 VkDescriptorSetLayout ds_layout_fs_only = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006507 // Create 4 unique layouts for full pipelineLayout, and 1 special fs-only
6508 // layout for error case
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006509 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[0]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006510 ASSERT_VK_SUCCESS(err);
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07006511 ds_layout_ci.pBindings = &dsl_fs_stage_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006512 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006513 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006514 dsl_binding[0].binding = 0;
6515 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006516 dsl_binding[0].descriptorCount = 2;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07006517 dsl_binding[1].binding = 1;
6518 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
6519 dsl_binding[1].descriptorCount = 2;
6520 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
6521 dsl_binding[1].pImmutableSamplers = NULL;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07006522 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006523 ds_layout_ci.bindingCount = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006524 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[1]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006525 ASSERT_VK_SUCCESS(err);
6526 dsl_binding[0].binding = 0;
6527 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006528 dsl_binding[0].descriptorCount = 5;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006529 ds_layout_ci.bindingCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006530 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[2]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006531 ASSERT_VK_SUCCESS(err);
6532 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006533 dsl_binding[0].descriptorCount = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006534 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[3]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006535 ASSERT_VK_SUCCESS(err);
6536
6537 static const uint32_t NUM_SETS = 4;
6538 VkDescriptorSet descriptorSet[NUM_SETS] = {};
6539 VkDescriptorSetAllocateInfo alloc_info = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006540 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006541 alloc_info.descriptorSetCount = NUM_LAYOUTS;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006542 alloc_info.descriptorPool = ds_pool;
6543 alloc_info.pSetLayouts = ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006544 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptorSet);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006545 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006546 VkDescriptorSet ds0_fs_only = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07006547 alloc_info.descriptorSetCount = 1;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006548 alloc_info.pSetLayouts = &ds_layout_fs_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006549 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &ds0_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006550 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006551
6552 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006553 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6554 pipeline_layout_ci.pNext = NULL;
6555 pipeline_layout_ci.setLayoutCount = NUM_LAYOUTS;
6556 pipeline_layout_ci.pSetLayouts = ds_layout;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006557
6558 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006559 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006560 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006561 // Create pipelineLayout with only one setLayout
6562 pipeline_layout_ci.setLayoutCount = 1;
6563 VkPipelineLayout single_pipe_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006564 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &single_pipe_layout);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006565 ASSERT_VK_SUCCESS(err);
6566 // Create pipelineLayout with 2 descriptor setLayout at index 0
6567 pipeline_layout_ci.pSetLayouts = &ds_layout[3];
6568 VkPipelineLayout pipe_layout_one_desc;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006569 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_one_desc);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006570 ASSERT_VK_SUCCESS(err);
6571 // Create pipelineLayout with 5 SAMPLER descriptor setLayout at index 0
6572 pipeline_layout_ci.pSetLayouts = &ds_layout[2];
6573 VkPipelineLayout pipe_layout_five_samp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006574 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_five_samp);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006575 ASSERT_VK_SUCCESS(err);
6576 // Create pipelineLayout with UB type, but stageFlags for FS only
6577 pipeline_layout_ci.pSetLayouts = &ds_layout_fs_only;
6578 VkPipelineLayout pipe_layout_fs_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006579 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006580 ASSERT_VK_SUCCESS(err);
6581 // Create pipelineLayout w/ incompatible set0 layout, but set1 is fine
6582 VkDescriptorSetLayout pl_bad_s0[2] = {};
6583 pl_bad_s0[0] = ds_layout_fs_only;
6584 pl_bad_s0[1] = ds_layout[1];
6585 pipeline_layout_ci.setLayoutCount = 2;
6586 pipeline_layout_ci.pSetLayouts = pl_bad_s0;
6587 VkPipelineLayout pipe_layout_bad_set0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006588 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_bad_set0);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006589 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006590
6591 // Create a buffer to update the descriptor with
6592 uint32_t qfi = 0;
6593 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006594 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
6595 buffCI.size = 1024;
6596 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
6597 buffCI.queueFamilyIndexCount = 1;
6598 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006599
6600 VkBuffer dyub;
6601 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
6602 ASSERT_VK_SUCCESS(err);
6603 // Correctly update descriptor to avoid "NOT_UPDATED" error
6604 static const uint32_t NUM_BUFFS = 5;
6605 VkDescriptorBufferInfo buffInfo[NUM_BUFFS] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006606 for (uint32_t i = 0; i < NUM_BUFFS; ++i) {
Tobin Ehlis559c6382015-11-05 09:52:49 -07006607 buffInfo[i].buffer = dyub;
6608 buffInfo[i].offset = 0;
6609 buffInfo[i].range = 1024;
6610 }
Karl Schultz6addd812016-02-02 17:17:23 -07006611 VkImage image;
Karl Schultz6addd812016-02-02 17:17:23 -07006612 const int32_t tex_width = 32;
6613 const int32_t tex_height = 32;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006614 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006615 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
6616 image_create_info.pNext = NULL;
6617 image_create_info.imageType = VK_IMAGE_TYPE_2D;
6618 image_create_info.format = tex_format;
6619 image_create_info.extent.width = tex_width;
6620 image_create_info.extent.height = tex_height;
6621 image_create_info.extent.depth = 1;
6622 image_create_info.mipLevels = 1;
6623 image_create_info.arrayLayers = 1;
6624 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyanb8a61002016-06-20 16:00:28 -06006625 image_create_info.tiling = tiling;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006626 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_STORAGE_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -07006627 image_create_info.flags = 0;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006628 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
6629 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006630
Karl Schultz6addd812016-02-02 17:17:23 -07006631 VkMemoryRequirements memReqs;
6632 VkDeviceMemory imageMem;
6633 bool pass;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07006634 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006635 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
6636 memAlloc.pNext = NULL;
6637 memAlloc.allocationSize = 0;
6638 memAlloc.memoryTypeIndex = 0;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07006639 vkGetImageMemoryRequirements(m_device->device(), image, &memReqs);
6640 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006641 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07006642 ASSERT_TRUE(pass);
6643 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &imageMem);
6644 ASSERT_VK_SUCCESS(err);
6645 err = vkBindImageMemory(m_device->device(), image, imageMem, 0);
6646 ASSERT_VK_SUCCESS(err);
6647
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006648 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006649 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
6650 image_view_create_info.image = image;
6651 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
6652 image_view_create_info.format = tex_format;
6653 image_view_create_info.subresourceRange.layerCount = 1;
6654 image_view_create_info.subresourceRange.baseMipLevel = 0;
6655 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006656 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006657
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006658 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006659 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006660 ASSERT_VK_SUCCESS(err);
Tobin Ehlis991d45a2016-01-06 08:48:41 -07006661 VkDescriptorImageInfo imageInfo[4] = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006662 imageInfo[0].imageView = view;
6663 imageInfo[0].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
6664 imageInfo[1].imageView = view;
6665 imageInfo[1].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
Tobin Ehlis991d45a2016-01-06 08:48:41 -07006666 imageInfo[2].imageView = view;
Tobin Ehlisa1fccbc2016-10-10 14:54:43 -06006667 imageInfo[2].imageLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis991d45a2016-01-06 08:48:41 -07006668 imageInfo[3].imageView = view;
Tobin Ehlisa1fccbc2016-10-10 14:54:43 -06006669 imageInfo[3].imageLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006670
6671 static const uint32_t NUM_SET_UPDATES = 3;
6672 VkWriteDescriptorSet descriptor_write[NUM_SET_UPDATES] = {};
6673 descriptor_write[0].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6674 descriptor_write[0].dstSet = descriptorSet[0];
6675 descriptor_write[0].dstBinding = 0;
6676 descriptor_write[0].descriptorCount = 5;
6677 descriptor_write[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6678 descriptor_write[0].pBufferInfo = buffInfo;
6679 descriptor_write[1].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6680 descriptor_write[1].dstSet = descriptorSet[1];
6681 descriptor_write[1].dstBinding = 0;
6682 descriptor_write[1].descriptorCount = 2;
6683 descriptor_write[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
6684 descriptor_write[1].pImageInfo = imageInfo;
6685 descriptor_write[2].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6686 descriptor_write[2].dstSet = descriptorSet[1];
6687 descriptor_write[2].dstBinding = 1;
6688 descriptor_write[2].descriptorCount = 2;
6689 descriptor_write[2].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
Tobin Ehlis991d45a2016-01-06 08:48:41 -07006690 descriptor_write[2].pImageInfo = &imageInfo[2];
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006691
6692 vkUpdateDescriptorSets(m_device->device(), 3, descriptor_write, 0, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006693
Tobin Ehlis88452832015-12-03 09:40:56 -07006694 // Create PSO to be used for draw-time errors below
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006695 char const *vsSource = "#version 450\n"
6696 "\n"
6697 "out gl_PerVertex {\n"
6698 " vec4 gl_Position;\n"
6699 "};\n"
6700 "void main(){\n"
6701 " gl_Position = vec4(1);\n"
6702 "}\n";
6703 char const *fsSource = "#version 450\n"
6704 "\n"
6705 "layout(location=0) out vec4 x;\n"
6706 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
6707 "void main(){\n"
6708 " x = vec4(bar.y);\n"
6709 "}\n";
Tobin Ehlis88452832015-12-03 09:40:56 -07006710 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
6711 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006712 VkPipelineObj pipe(m_device);
6713 pipe.AddShader(&vs);
6714 pipe.AddShader(&fs);
Tobin Ehlis88452832015-12-03 09:40:56 -07006715 pipe.AddColorAttachment();
6716 pipe.CreateVKPipeline(pipe_layout_fs_only, renderPass());
Tobin Ehlis559c6382015-11-05 09:52:49 -07006717
6718 BeginCommandBuffer();
Tobin Ehlis88452832015-12-03 09:40:56 -07006719
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006720 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07006721 // NOTE : I believe LunarG ilo driver has bug (LX#189) that requires binding
6722 // of PSO
6723 // here before binding DSs. Otherwise we assert in cmd_copy_dset_data() of
6724 // cmd_pipeline.c
6725 // due to the fact that cmd_alloc_dset_data() has not been called in
6726 // cmd_bind_graphics_pipeline()
6727 // TODO : Want to cause various binding incompatibility issues here to test
6728 // DrawState
Tobin Ehlis559c6382015-11-05 09:52:49 -07006729 // First cause various verify_layout_compatibility() fails
6730 // Second disturb early and late sets and verify INFO msgs
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006731 // verify_set_layout_compatibility fail cases:
6732 // 1. invalid VkPipelineLayout (layout) passed into vkCmdBindDescriptorSets
Karl Schultzf78bcdd2016-11-30 12:36:01 -07006733 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00981);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006734 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS,
6735 (VkPipelineLayout)((size_t)0xbaadb1be), 0, 1, &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006736 m_errorMonitor->VerifyFound();
6737
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006738 // 2. layoutIndex exceeds # of layouts in layout
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006739 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " attempting to bind set to index 1");
6740 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, single_pipe_layout, 0, 2,
6741 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006742 m_errorMonitor->VerifyFound();
6743
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006744 vkDestroyPipelineLayout(m_device->device(), single_pipe_layout, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07006745 // 3. Pipeline setLayout[0] has 2 descriptors, but set being bound has 5
6746 // descriptors
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006747 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has 2 descriptors, but DescriptorSetLayout ");
6748 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_one_desc, 0, 1,
6749 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006750 m_errorMonitor->VerifyFound();
6751
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006752 vkDestroyPipelineLayout(m_device->device(), pipe_layout_one_desc, NULL);
6753 // 4. same # of descriptors but mismatch in type
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006754 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is type 'VK_DESCRIPTOR_TYPE_SAMPLER' but binding ");
6755 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_five_samp, 0, 1,
6756 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006757 m_errorMonitor->VerifyFound();
6758
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006759 vkDestroyPipelineLayout(m_device->device(), pipe_layout_five_samp, NULL);
6760 // 5. same # of descriptors but mismatch in stageFlags
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006761 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6762 " has stageFlags 16 but binding 0 for DescriptorSetLayout ");
6763 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_fs_only, 0, 1,
6764 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006765 m_errorMonitor->VerifyFound();
6766
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006767 // Cause INFO messages due to disturbing previously bound Sets
6768 // First bind sets 0 & 1
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006769 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
6770 &descriptorSet[0], 0, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006771 // 1. Disturb bound set0 by re-binding set1 w/ updated pipelineLayout
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006772 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, " previously bound as set #0 was disturbed ");
6773 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_bad_set0, 1, 1,
6774 &descriptorSet[1], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006775 m_errorMonitor->VerifyFound();
6776
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006777 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
6778 &descriptorSet[0], 0, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006779 // 2. Disturb set after last bound set
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006780 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, " newly bound as set #0 so set #1 and "
6781 "any subsequent sets were disturbed ");
6782 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_fs_only, 0, 1,
6783 &ds0_fs_only, 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006784 m_errorMonitor->VerifyFound();
6785
Tobin Ehlis10fad692016-07-07 12:00:36 -06006786 // Now that we're done actively using the pipelineLayout that gfx pipeline
6787 // was created with, we should be able to delete it. Do that now to verify
6788 // that validation obeys pipelineLayout lifetime
6789 vkDestroyPipelineLayout(m_device->device(), pipe_layout_fs_only, NULL);
6790
Tobin Ehlis88452832015-12-03 09:40:56 -07006791 // Cause draw-time errors due to PSO incompatibilities
Karl Schultz6addd812016-02-02 17:17:23 -07006792 // 1. Error due to not binding required set (we actually use same code as
6793 // above to disturb set0)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006794 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
6795 &descriptorSet[0], 0, NULL);
6796 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_bad_set0, 1, 1,
6797 &descriptorSet[1], 0, NULL);
6798 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 -07006799 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006800 m_errorMonitor->VerifyFound();
6801
Tobin Ehlis991d45a2016-01-06 08:48:41 -07006802 vkDestroyPipelineLayout(m_device->device(), pipe_layout_bad_set0, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07006803 // 2. Error due to bound set not being compatible with PSO's
6804 // VkPipelineLayout (diff stageFlags in this case)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006805 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
6806 &descriptorSet[0], 0, NULL);
6807 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " bound as set #0 is not compatible with ");
Tobin Ehlis88452832015-12-03 09:40:56 -07006808 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006809 m_errorMonitor->VerifyFound();
6810
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006811 // Remaining clean-up
Karl Schultz6addd812016-02-02 17:17:23 -07006812 for (uint32_t i = 0; i < NUM_LAYOUTS; ++i) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006813 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout[i], NULL);
6814 }
6815 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_fs_only, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006816 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006817 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6818 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06006819 vkFreeMemory(m_device->device(), imageMem, NULL);
6820 vkDestroyImage(m_device->device(), image, NULL);
6821 vkDestroyImageView(m_device->device(), view, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006822}
Tobin Ehlis559c6382015-11-05 09:52:49 -07006823
Karl Schultz6addd812016-02-02 17:17:23 -07006824TEST_F(VkLayerTest, NoBeginCommandBuffer) {
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006825
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006826 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6827 "You must call vkBeginCommandBuffer() before this call to ");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006828
6829 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006830 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006831 // Call EndCommandBuffer() w/o calling BeginCommandBuffer()
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006832 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006833
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006834 m_errorMonitor->VerifyFound();
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006835}
6836
Karl Schultz6addd812016-02-02 17:17:23 -07006837TEST_F(VkLayerTest, SecondaryCommandBufferNullRenderpass) {
6838 VkResult err;
6839 VkCommandBuffer draw_cmd;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006840
Karl Schultzf78bcdd2016-11-30 12:36:01 -07006841 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00110);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006842
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006843 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006844
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006845 VkCommandBufferAllocateInfo cmd = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006846 cmd.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06006847 cmd.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006848 cmd.commandPool = m_commandPool;
6849 cmd.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006850 cmd.commandBufferCount = 1;
Cody Northropb4569702015-08-04 17:35:57 -06006851
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006852 err = vkAllocateCommandBuffers(m_device->device(), &cmd, &draw_cmd);
Mike Stroyand1c84a52015-08-18 14:40:24 -06006853 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006854
6855 // Force the failure by not setting the Renderpass and Framebuffer fields
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006856 VkCommandBufferBeginInfo cmd_buf_info = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07006857 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006858 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06006859 cmd_buf_info.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006860 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 -07006861 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006862
6863 // The error should be caught by validation of the BeginCommandBuffer call
6864 vkBeginCommandBuffer(draw_cmd, &cmd_buf_info);
6865
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006866 m_errorMonitor->VerifyFound();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006867 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &draw_cmd);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006868}
6869
Karl Schultz6addd812016-02-02 17:17:23 -07006870TEST_F(VkLayerTest, CommandBufferResetErrors) {
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006871 // Cause error due to Begin while recording CB
6872 // Then cause 2 errors for attempting to reset CB w/o having
6873 // VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT set for the pool from
6874 // which CBs were allocated. Note that this bit is off by default.
Mike Weiblencce7ec72016-10-17 19:33:05 -06006875 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot call Begin on command buffer");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006876
6877 ASSERT_NO_FATAL_FAILURE(InitState());
6878
6879 // Calls AllocateCommandBuffers
6880 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
6881
Karl Schultz6addd812016-02-02 17:17:23 -07006882 // Force the failure by setting the Renderpass and Framebuffer fields with
6883 // (fake) data
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006884 VkCommandBufferBeginInfo cmd_buf_info = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07006885 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006886 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
6887 cmd_buf_info.pNext = NULL;
6888 cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006889 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006890
6891 // Begin CB to transition to recording state
6892 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
6893 // Can't re-begin. This should trigger error
6894 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006895 m_errorMonitor->VerifyFound();
6896
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006897 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to reset command buffer ");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006898 VkCommandBufferResetFlags flags = 0; // Don't care about flags for this test
6899 // Reset attempt will trigger error due to incorrect CommandPool state
6900 vkResetCommandBuffer(commandBuffer.GetBufferHandle(), flags);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006901 m_errorMonitor->VerifyFound();
6902
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006903 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " attempts to implicitly reset cmdBuffer created from ");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006904 // Transition CB to RECORDED state
6905 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
6906 // Now attempting to Begin will implicitly reset, which triggers error
6907 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006908 m_errorMonitor->VerifyFound();
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006909}
6910
Karl Schultz6addd812016-02-02 17:17:23 -07006911TEST_F(VkLayerTest, InvalidPipelineCreateState) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006912 // Attempt to Create Gfx Pipeline w/o a VS
Karl Schultz6addd812016-02-02 17:17:23 -07006913 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006914
Mike Weiblencce7ec72016-10-17 19:33:05 -06006915 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Pipeline CreateInfo State: Vertex Shader required");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006916
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006917 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06006918 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinski209b5292015-09-17 09:44:05 -06006919
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006920 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006921 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6922 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06006923
6924 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006925 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6926 ds_pool_ci.pNext = NULL;
6927 ds_pool_ci.maxSets = 1;
6928 ds_pool_ci.poolSizeCount = 1;
6929 ds_pool_ci.pPoolSizes = &ds_type_count;
Mark Lobodzinski209b5292015-09-17 09:44:05 -06006930
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006931 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006932 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006933 ASSERT_VK_SUCCESS(err);
6934
Tony Barboureb254902015-07-15 12:50:33 -06006935 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006936 dsl_binding.binding = 0;
6937 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6938 dsl_binding.descriptorCount = 1;
6939 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6940 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006941
Tony Barboureb254902015-07-15 12:50:33 -06006942 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006943 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6944 ds_layout_ci.pNext = NULL;
6945 ds_layout_ci.bindingCount = 1;
6946 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06006947
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006948 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006949 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006950 ASSERT_VK_SUCCESS(err);
6951
6952 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006953 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006954 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006955 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06006956 alloc_info.descriptorPool = ds_pool;
6957 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006958 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006959 ASSERT_VK_SUCCESS(err);
6960
Tony Barboureb254902015-07-15 12:50:33 -06006961 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006962 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6963 pipeline_layout_ci.setLayoutCount = 1;
6964 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006965
6966 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006967 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006968 ASSERT_VK_SUCCESS(err);
6969
Tobin Ehlise68360f2015-10-01 11:15:13 -06006970 VkViewport vp = {}; // Just need dummy vp to point to
Karl Schultz6addd812016-02-02 17:17:23 -07006971 VkRect2D sc = {}; // dummy scissor to point to
Tobin Ehlise68360f2015-10-01 11:15:13 -06006972
6973 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006974 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
6975 vp_state_ci.scissorCount = 1;
6976 vp_state_ci.pScissors = &sc;
6977 vp_state_ci.viewportCount = 1;
6978 vp_state_ci.pViewports = &vp;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006979
Karl Schultzdfdb8d42016-03-08 10:30:21 -07006980 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
6981 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
6982 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
6983 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
6984 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
6985 rs_state_ci.depthClampEnable = VK_FALSE;
6986 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
6987 rs_state_ci.depthBiasEnable = VK_FALSE;
6988
Tony Barboureb254902015-07-15 12:50:33 -06006989 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006990 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
6991 gp_ci.pViewportState = &vp_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07006992 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07006993 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
6994 gp_ci.layout = pipeline_layout;
6995 gp_ci.renderPass = renderPass();
Tony Barboureb254902015-07-15 12:50:33 -06006996
6997 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006998 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
6999 pc_ci.initialDataSize = 0;
7000 pc_ci.pInitialData = 0;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007001
7002 VkPipeline pipeline;
Jon Ashburnc669cc62015-07-09 15:02:25 -06007003 VkPipelineCache pipelineCache;
7004
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007005 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Jon Ashburnc669cc62015-07-09 15:02:25 -06007006 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007007 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06007008
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007009 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06007010
Chia-I Wuf7458c52015-10-26 21:10:41 +08007011 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7012 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7013 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7014 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007015}
Tobin Ehlis912df022015-09-17 08:46:18 -06007016/*// TODO : This test should be good, but needs Tess support in compiler to run
7017TEST_F(VkLayerTest, InvalidPatchControlPoints)
7018{
7019 // Attempt to Create Gfx Pipeline w/o a VS
Tobin Ehlis912df022015-09-17 08:46:18 -06007020 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007021
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07007022 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07007023 "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH
7024primitive ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007025
Tobin Ehlis912df022015-09-17 08:46:18 -06007026 ASSERT_NO_FATAL_FAILURE(InitState());
7027 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis912df022015-09-17 08:46:18 -06007028
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007029 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlis912df022015-09-17 08:46:18 -06007030 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007031 ds_type_count.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06007032
7033 VkDescriptorPoolCreateInfo ds_pool_ci = {};
7034 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7035 ds_pool_ci.pNext = NULL;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007036 ds_pool_ci.poolSizeCount = 1;
7037 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis912df022015-09-17 08:46:18 -06007038
7039 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07007040 err = vkCreateDescriptorPool(m_device->device(),
7041VK_DESCRIPTOR_POOL_USAGE_NON_FREE, 1, &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis912df022015-09-17 08:46:18 -06007042 ASSERT_VK_SUCCESS(err);
7043
7044 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08007045 dsl_binding.binding = 0;
Tobin Ehlis912df022015-09-17 08:46:18 -06007046 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08007047 dsl_binding.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06007048 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7049 dsl_binding.pImmutableSamplers = NULL;
7050
7051 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007052 ds_layout_ci.sType =
7053VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06007054 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007055 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07007056 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis912df022015-09-17 08:46:18 -06007057
7058 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007059 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
7060&ds_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06007061 ASSERT_VK_SUCCESS(err);
7062
7063 VkDescriptorSet descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -07007064 err = vkAllocateDescriptorSets(m_device->device(), ds_pool,
7065VK_DESCRIPTOR_SET_USAGE_NON_FREE, 1, &ds_layout, &descriptorSet);
Tobin Ehlis912df022015-09-17 08:46:18 -06007066 ASSERT_VK_SUCCESS(err);
7067
7068 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007069 pipeline_layout_ci.sType =
7070VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06007071 pipeline_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007072 pipeline_layout_ci.setLayoutCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06007073 pipeline_layout_ci.pSetLayouts = &ds_layout;
7074
7075 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007076 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
7077&pipeline_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06007078 ASSERT_VK_SUCCESS(err);
7079
7080 VkPipelineShaderStageCreateInfo shaderStages[3];
7081 memset(&shaderStages, 0, 3 * sizeof(VkPipelineShaderStageCreateInfo));
7082
Karl Schultz6addd812016-02-02 17:17:23 -07007083 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT,
7084this);
Tobin Ehlis912df022015-09-17 08:46:18 -06007085 // Just using VS txt for Tess shaders as we don't care about functionality
Karl Schultz6addd812016-02-02 17:17:23 -07007086 VkShaderObj
7087tc(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT,
7088this);
7089 VkShaderObj
7090te(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT,
7091this);
Tobin Ehlis912df022015-09-17 08:46:18 -06007092
Karl Schultz6addd812016-02-02 17:17:23 -07007093 shaderStages[0].sType =
7094VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06007095 shaderStages[0].stage = VK_SHADER_STAGE_VERTEX_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06007096 shaderStages[0].shader = vs.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07007097 shaderStages[1].sType =
7098VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06007099 shaderStages[1].stage = VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06007100 shaderStages[1].shader = tc.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07007101 shaderStages[2].sType =
7102VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06007103 shaderStages[2].stage = VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06007104 shaderStages[2].shader = te.handle();
7105
7106 VkPipelineInputAssemblyStateCreateInfo iaCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007107 iaCI.sType =
7108VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
Chia-I Wu515eb8f2015-10-31 00:31:16 +08007109 iaCI.topology = VK_PRIMITIVE_TOPOLOGY_PATCH_LIST;
Tobin Ehlis912df022015-09-17 08:46:18 -06007110
7111 VkPipelineTessellationStateCreateInfo tsCI = {};
7112 tsCI.sType = VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO;
7113 tsCI.patchControlPoints = 0; // This will cause an error
7114
7115 VkGraphicsPipelineCreateInfo gp_ci = {};
7116 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7117 gp_ci.pNext = NULL;
7118 gp_ci.stageCount = 3;
7119 gp_ci.pStages = shaderStages;
7120 gp_ci.pVertexInputState = NULL;
7121 gp_ci.pInputAssemblyState = &iaCI;
7122 gp_ci.pTessellationState = &tsCI;
7123 gp_ci.pViewportState = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007124 gp_ci.pRasterizationState = NULL;
Tobin Ehlis912df022015-09-17 08:46:18 -06007125 gp_ci.pMultisampleState = NULL;
7126 gp_ci.pDepthStencilState = NULL;
7127 gp_ci.pColorBlendState = NULL;
7128 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7129 gp_ci.layout = pipeline_layout;
7130 gp_ci.renderPass = renderPass();
7131
7132 VkPipelineCacheCreateInfo pc_ci = {};
7133 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
7134 pc_ci.pNext = NULL;
7135 pc_ci.initialSize = 0;
7136 pc_ci.initialData = 0;
7137 pc_ci.maxSize = 0;
7138
7139 VkPipeline pipeline;
7140 VkPipelineCache pipelineCache;
7141
Karl Schultz6addd812016-02-02 17:17:23 -07007142 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL,
7143&pipelineCache);
Tobin Ehlis912df022015-09-17 08:46:18 -06007144 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07007145 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
7146&gp_ci, NULL, &pipeline);
Tobin Ehlis912df022015-09-17 08:46:18 -06007147
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007148 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06007149
Chia-I Wuf7458c52015-10-26 21:10:41 +08007150 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7151 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7152 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7153 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis912df022015-09-17 08:46:18 -06007154}
7155*/
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007156
Mark Lobodzinski510aa5c2016-12-19 07:59:10 -07007157TEST_F(VkLayerTest, PSOViewportScissorCountTests) {
Karl Schultz6addd812016-02-02 17:17:23 -07007158 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007159
Mark Lobodzinski510aa5c2016-12-19 07:59:10 -07007160 TEST_DESCRIPTION("Test various cases of viewport and scissor count validation");
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007161
Tobin Ehlise68360f2015-10-01 11:15:13 -06007162 ASSERT_NO_FATAL_FAILURE(InitState());
7163 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06007164
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007165 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007166 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7167 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007168
7169 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007170 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7171 ds_pool_ci.maxSets = 1;
7172 ds_pool_ci.poolSizeCount = 1;
7173 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007174
7175 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007176 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007177 ASSERT_VK_SUCCESS(err);
7178
7179 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007180 dsl_binding.binding = 0;
7181 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7182 dsl_binding.descriptorCount = 1;
7183 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007184
7185 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007186 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7187 ds_layout_ci.bindingCount = 1;
7188 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007189
7190 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007191 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007192 ASSERT_VK_SUCCESS(err);
7193
7194 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007195 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007196 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007197 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007198 alloc_info.descriptorPool = ds_pool;
7199 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007200 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007201 ASSERT_VK_SUCCESS(err);
7202
7203 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007204 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7205 pipeline_layout_ci.setLayoutCount = 1;
7206 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007207
7208 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007209 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007210 ASSERT_VK_SUCCESS(err);
7211
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007212 VkViewport vp = {};
Tobin Ehlise68360f2015-10-01 11:15:13 -06007213 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007214 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
Mark Lobodzinski510aa5c2016-12-19 07:59:10 -07007215 vp_state_ci.scissorCount = 1;
Mark Lobodzinskif0eab4a2016-12-19 08:43:21 -07007216 vp_state_ci.viewportCount = 1;
Karl Schultz6addd812016-02-02 17:17:23 -07007217 vp_state_ci.pViewports = &vp;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007218
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007219 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
7220 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7221 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
7222 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
7223 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
7224 rs_state_ci.depthClampEnable = VK_FALSE;
7225 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
7226 rs_state_ci.depthBiasEnable = VK_FALSE;
7227
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007228 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7229 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7230 vi_ci.pNext = nullptr;
7231 vi_ci.vertexBindingDescriptionCount = 0;
7232 vi_ci.pVertexBindingDescriptions = nullptr;
7233 vi_ci.vertexAttributeDescriptionCount = 0;
7234 vi_ci.pVertexAttributeDescriptions = nullptr;
7235
7236 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7237 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7238 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7239
7240 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
7241 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
7242 pipe_ms_state_ci.pNext = NULL;
7243 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
7244 pipe_ms_state_ci.sampleShadingEnable = 0;
7245 pipe_ms_state_ci.minSampleShading = 1.0;
7246 pipe_ms_state_ci.pSampleMask = NULL;
7247
Cody Northropeb3a6c12015-10-05 14:44:45 -06007248 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07007249 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06007250
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007251 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinskid04c7862016-12-16 13:17:49 -07007252 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chia-I Wu28e06912015-10-31 00:31:16 +08007253 shaderStages[0] = vs.GetStageCreateInfo();
7254 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007255
7256 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007257 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7258 gp_ci.stageCount = 2;
7259 gp_ci.pStages = shaderStages;
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007260 gp_ci.pVertexInputState = &vi_ci;
7261 gp_ci.pInputAssemblyState = &ia_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007262 gp_ci.pViewportState = &vp_state_ci;
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007263 gp_ci.pMultisampleState = &pipe_ms_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007264 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007265 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7266 gp_ci.layout = pipeline_layout;
7267 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007268
7269 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007270 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007271
7272 VkPipeline pipeline;
7273 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007274 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007275 ASSERT_VK_SUCCESS(err);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007276
Mark Lobodzinskif0eab4a2016-12-19 08:43:21 -07007277 if (!m_device->phy().features().multiViewport) {
7278 printf("MultiViewport feature is disabled -- skipping enabled-state checks.\n");
7279
7280 // Check case where multiViewport is disabled and viewport count is not 1
7281 // We check scissor/viewport simultaneously since separating them would trigger the mismatch error, 1434.
7282 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01430);
7283 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01431);
7284 vp_state_ci.scissorCount = 0;
7285 vp_state_ci.viewportCount = 0;
7286 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
7287 m_errorMonitor->VerifyFound();
7288 } else {
7289 if (m_device->props.limits.maxViewports == 1) {
7290 printf("Device limit maxViewports is 1, skipping tests that require higher limits.\n");
7291 } else {
7292 printf("MultiViewport feature is enabled -- skipping disabled-state checks.\n");
7293
7294 // Check is that viewportcount and scissorcount match
7295 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01434);
7296 vp_state_ci.scissorCount = 1;
7297 vp_state_ci.viewportCount = m_device->props.limits.maxViewports;
7298 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
7299 m_errorMonitor->VerifyFound();
7300
7301
7302 // Check case where multiViewport is enabled and viewport count is greater than max
7303 // We check scissor/viewport simultaneously since separating them would trigger the mismatch error, 1434.
7304 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01432);
7305 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01433);
7306 vp_state_ci.scissorCount = m_device->props.limits.maxViewports + 1;
7307 vp_state_ci.viewportCount = m_device->props.limits.maxViewports + 1;
7308 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
7309 m_errorMonitor->VerifyFound();
7310 }
7311 }
Tobin Ehlise68360f2015-10-01 11:15:13 -06007312
Chia-I Wuf7458c52015-10-26 21:10:41 +08007313 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7314 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7315 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7316 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007317}
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007318
7319// Don't set viewport state in PSO. This is an error b/c we always need this state for the counts even if the data is going to be
7320// set dynamically.
Karl Schultz6addd812016-02-02 17:17:23 -07007321TEST_F(VkLayerTest, PSOViewportStateNotSet) {
Karl Schultz6addd812016-02-02 17:17:23 -07007322 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007323
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007324 TEST_DESCRIPTION("Create a graphics pipeline with rasterization enabled but no viewport state.");
7325
Mark Lobodzinskid04c7862016-12-16 13:17:49 -07007326 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02113);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007327
Tobin Ehlise68360f2015-10-01 11:15:13 -06007328 ASSERT_NO_FATAL_FAILURE(InitState());
7329 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06007330
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007331 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007332 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7333 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007334
7335 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007336 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7337 ds_pool_ci.maxSets = 1;
7338 ds_pool_ci.poolSizeCount = 1;
7339 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007340
7341 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007342 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007343 ASSERT_VK_SUCCESS(err);
7344
7345 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007346 dsl_binding.binding = 0;
7347 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7348 dsl_binding.descriptorCount = 1;
7349 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007350
7351 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007352 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7353 ds_layout_ci.bindingCount = 1;
7354 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007355
7356 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007357 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007358 ASSERT_VK_SUCCESS(err);
7359
7360 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007361 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007362 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007363 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007364 alloc_info.descriptorPool = ds_pool;
7365 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007366 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007367 ASSERT_VK_SUCCESS(err);
7368
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007369 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7370 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7371 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7372
7373 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7374 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7375 vi_ci.pNext = nullptr;
7376 vi_ci.vertexBindingDescriptionCount = 0;
7377 vi_ci.pVertexBindingDescriptions = nullptr;
7378 vi_ci.vertexAttributeDescriptionCount = 0;
7379 vi_ci.pVertexAttributeDescriptions = nullptr;
7380
7381 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
7382 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
7383 pipe_ms_state_ci.pNext = NULL;
7384 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
7385 pipe_ms_state_ci.sampleShadingEnable = 0;
7386 pipe_ms_state_ci.minSampleShading = 1.0;
7387 pipe_ms_state_ci.pSampleMask = NULL;
7388
Tobin Ehlise68360f2015-10-01 11:15:13 -06007389 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007390 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7391 pipeline_layout_ci.setLayoutCount = 1;
7392 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007393
7394 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007395 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007396 ASSERT_VK_SUCCESS(err);
7397
7398 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
7399 // Set scissor as dynamic to avoid second error
7400 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007401 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
7402 dyn_state_ci.dynamicStateCount = 1;
7403 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007404
Cody Northropeb3a6c12015-10-05 14:44:45 -06007405 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07007406 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06007407
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007408 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007409 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
7410 // We shouldn't need a fragment shader but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08007411 shaderStages[0] = vs.GetStageCreateInfo();
7412 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007413
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007414 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
7415 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7416 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
7417 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
7418 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
7419 rs_state_ci.depthClampEnable = VK_FALSE;
7420 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
7421 rs_state_ci.depthBiasEnable = VK_FALSE;
7422
Tobin Ehlise68360f2015-10-01 11:15:13 -06007423 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007424 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7425 gp_ci.stageCount = 2;
7426 gp_ci.pStages = shaderStages;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007427 gp_ci.pRasterizationState = &rs_state_ci;
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007428 // Not setting VP state w/o dynamic vp state should cause validation error
7429 gp_ci.pViewportState = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -07007430 gp_ci.pDynamicState = &dyn_state_ci;
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007431 gp_ci.pVertexInputState = &vi_ci;
7432 gp_ci.pInputAssemblyState = &ia_ci;
7433 gp_ci.pMultisampleState = &pipe_ms_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007434 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7435 gp_ci.layout = pipeline_layout;
7436 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007437
7438 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007439 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007440
7441 VkPipeline pipeline;
7442 VkPipelineCache pipelineCache;
7443
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007444 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007445 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007446 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007447
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007448 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007449
Chia-I Wuf7458c52015-10-26 21:10:41 +08007450 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7451 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7452 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7453 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007454}
Mark Lobodzinski73169e22016-12-16 14:01:17 -07007455
7456// Create PSO w/o non-zero viewportCount but no viewport data, then run second test where dynamic scissor count doesn't match PSO
7457// scissor count
Karl Schultz6addd812016-02-02 17:17:23 -07007458TEST_F(VkLayerTest, PSOViewportCountWithoutDataAndDynScissorMismatch) {
7459 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007460
Mark Lobodzinskid04c7862016-12-16 13:17:49 -07007461 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02110);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007462
Tobin Ehlise68360f2015-10-01 11:15:13 -06007463 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007464
7465 if (!m_device->phy().features().multiViewport) {
7466 printf("Device does not support multiple viewports/scissors; skipped.\n");
7467 return;
7468 }
7469
Tobin Ehlise68360f2015-10-01 11:15:13 -06007470 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06007471
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007472 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007473 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7474 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007475
7476 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007477 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7478 ds_pool_ci.maxSets = 1;
7479 ds_pool_ci.poolSizeCount = 1;
7480 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007481
7482 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007483 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007484 ASSERT_VK_SUCCESS(err);
7485
7486 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007487 dsl_binding.binding = 0;
7488 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7489 dsl_binding.descriptorCount = 1;
7490 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007491
7492 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007493 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7494 ds_layout_ci.bindingCount = 1;
7495 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007496
7497 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007498 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007499 ASSERT_VK_SUCCESS(err);
7500
7501 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007502 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007503 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007504 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007505 alloc_info.descriptorPool = ds_pool;
7506 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007507 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007508 ASSERT_VK_SUCCESS(err);
7509
7510 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007511 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7512 pipeline_layout_ci.setLayoutCount = 1;
7513 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007514
7515 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007516 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007517 ASSERT_VK_SUCCESS(err);
7518
7519 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007520 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
7521 vp_state_ci.viewportCount = 1;
7522 vp_state_ci.pViewports = NULL; // Null vp w/ count of 1 should cause error
7523 vp_state_ci.scissorCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007524 vp_state_ci.pScissors = NULL; // Scissor is dynamic (below) so this won't cause error
Tobin Ehlise68360f2015-10-01 11:15:13 -06007525
7526 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
7527 // Set scissor as dynamic to avoid that error
7528 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007529 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
7530 dyn_state_ci.dynamicStateCount = 1;
7531 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007532
Mark Lobodzinski73169e22016-12-16 14:01:17 -07007533 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
7534 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
7535 pipe_ms_state_ci.pNext = NULL;
7536 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
7537 pipe_ms_state_ci.sampleShadingEnable = 0;
7538 pipe_ms_state_ci.minSampleShading = 1.0;
7539 pipe_ms_state_ci.pSampleMask = NULL;
7540
Cody Northropeb3a6c12015-10-05 14:44:45 -06007541 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07007542 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06007543
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007544 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski73169e22016-12-16 14:01:17 -07007545 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
7546 // We shouldn't need a fragment shader but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08007547 shaderStages[0] = vs.GetStageCreateInfo();
7548 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007549
Cody Northropf6622dc2015-10-06 10:33:21 -06007550 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7551 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7552 vi_ci.pNext = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007553 vi_ci.vertexBindingDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06007554 vi_ci.pVertexBindingDescriptions = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007555 vi_ci.vertexAttributeDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06007556 vi_ci.pVertexAttributeDescriptions = nullptr;
7557
7558 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7559 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7560 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7561
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007562 VkPipelineRasterizationStateCreateInfo rs_ci = {};
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007563 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Mark Lobodzinski73169e22016-12-16 14:01:17 -07007564 rs_ci.lineWidth = m_device->props.limits.lineWidthRange[0];
Cody Northropf6622dc2015-10-06 10:33:21 -06007565 rs_ci.pNext = nullptr;
7566
Mark Youngc89c6312016-03-31 16:03:20 -06007567 VkPipelineColorBlendAttachmentState att = {};
7568 att.blendEnable = VK_FALSE;
7569 att.colorWriteMask = 0xf;
7570
Cody Northropf6622dc2015-10-06 10:33:21 -06007571 VkPipelineColorBlendStateCreateInfo cb_ci = {};
7572 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
7573 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06007574 cb_ci.attachmentCount = 1;
7575 cb_ci.pAttachments = &att;
Cody Northropf6622dc2015-10-06 10:33:21 -06007576
Tobin Ehlise68360f2015-10-01 11:15:13 -06007577 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007578 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7579 gp_ci.stageCount = 2;
7580 gp_ci.pStages = shaderStages;
7581 gp_ci.pVertexInputState = &vi_ci;
7582 gp_ci.pInputAssemblyState = &ia_ci;
7583 gp_ci.pViewportState = &vp_state_ci;
7584 gp_ci.pRasterizationState = &rs_ci;
7585 gp_ci.pColorBlendState = &cb_ci;
7586 gp_ci.pDynamicState = &dyn_state_ci;
Mark Lobodzinski73169e22016-12-16 14:01:17 -07007587 gp_ci.pMultisampleState = &pipe_ms_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007588 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7589 gp_ci.layout = pipeline_layout;
7590 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007591
7592 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007593 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007594
7595 VkPipeline pipeline;
7596 VkPipelineCache pipelineCache;
7597
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007598 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007599 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007600 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007601
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007602 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007603
Tobin Ehlisd332f282015-10-02 11:00:56 -06007604 // Now hit second fail case where we set scissor w/ different count than PSO
Karl Schultz6addd812016-02-02 17:17:23 -07007605 // First need to successfully create the PSO from above by setting
7606 // pViewports
Mike Weiblen95dd0f92016-10-19 12:28:27 -06007607 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 -07007608
7609 VkViewport vp = {}; // Just need dummy vp to point to
7610 vp_state_ci.pViewports = &vp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007611 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Karl Schultz6addd812016-02-02 17:17:23 -07007612 ASSERT_VK_SUCCESS(err);
7613 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007614 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007615 VkRect2D scissors[1] = {}; // don't care about data
Karl Schultz6addd812016-02-02 17:17:23 -07007616 // Count of 2 doesn't match PSO count of 1
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007617 vkCmdSetScissor(m_commandBuffer->GetBufferHandle(), 1, 1, scissors);
Karl Schultz6addd812016-02-02 17:17:23 -07007618 Draw(1, 0, 0, 0);
7619
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007620 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07007621
7622 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7623 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7624 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7625 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06007626 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07007627}
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07007628
7629// Create PSO w/o non-zero scissorCount but no scissor data, then run second test where dynamic viewportCount doesn't match PSO
Karl Schultz6addd812016-02-02 17:17:23 -07007630// viewportCount
7631TEST_F(VkLayerTest, PSOScissorCountWithoutDataAndDynViewportMismatch) {
7632 VkResult err;
7633
Mark Lobodzinskid04c7862016-12-16 13:17:49 -07007634 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02111);
Karl Schultz6addd812016-02-02 17:17:23 -07007635
7636 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007637
7638 if (!m_device->phy().features().multiViewport) {
7639 printf("Device does not support multiple viewports/scissors; skipped.\n");
7640 return;
7641 }
7642
Karl Schultz6addd812016-02-02 17:17:23 -07007643 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7644
7645 VkDescriptorPoolSize ds_type_count = {};
7646 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7647 ds_type_count.descriptorCount = 1;
7648
7649 VkDescriptorPoolCreateInfo ds_pool_ci = {};
7650 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7651 ds_pool_ci.maxSets = 1;
7652 ds_pool_ci.poolSizeCount = 1;
7653 ds_pool_ci.pPoolSizes = &ds_type_count;
7654
7655 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007656 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Karl Schultz6addd812016-02-02 17:17:23 -07007657 ASSERT_VK_SUCCESS(err);
7658
7659 VkDescriptorSetLayoutBinding dsl_binding = {};
7660 dsl_binding.binding = 0;
7661 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7662 dsl_binding.descriptorCount = 1;
7663 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7664
7665 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
7666 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7667 ds_layout_ci.bindingCount = 1;
7668 ds_layout_ci.pBindings = &dsl_binding;
7669
7670 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007671 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Karl Schultz6addd812016-02-02 17:17:23 -07007672 ASSERT_VK_SUCCESS(err);
7673
7674 VkDescriptorSet descriptorSet;
7675 VkDescriptorSetAllocateInfo alloc_info = {};
7676 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
7677 alloc_info.descriptorSetCount = 1;
7678 alloc_info.descriptorPool = ds_pool;
7679 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007680 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Karl Schultz6addd812016-02-02 17:17:23 -07007681 ASSERT_VK_SUCCESS(err);
7682
7683 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
7684 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7685 pipeline_layout_ci.setLayoutCount = 1;
7686 pipeline_layout_ci.pSetLayouts = &ds_layout;
7687
7688 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007689 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultz6addd812016-02-02 17:17:23 -07007690 ASSERT_VK_SUCCESS(err);
7691
7692 VkPipelineViewportStateCreateInfo vp_state_ci = {};
7693 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
7694 vp_state_ci.scissorCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007695 vp_state_ci.pScissors = NULL; // Null scissor w/ count of 1 should cause error
Karl Schultz6addd812016-02-02 17:17:23 -07007696 vp_state_ci.viewportCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007697 vp_state_ci.pViewports = NULL; // vp is dynamic (below) so this won't cause error
Karl Schultz6addd812016-02-02 17:17:23 -07007698
7699 VkDynamicState vp_state = VK_DYNAMIC_STATE_VIEWPORT;
7700 // Set scissor as dynamic to avoid that error
7701 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
7702 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
7703 dyn_state_ci.dynamicStateCount = 1;
7704 dyn_state_ci.pDynamicStates = &vp_state;
7705
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07007706 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
7707 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
7708 pipe_ms_state_ci.pNext = NULL;
7709 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
7710 pipe_ms_state_ci.sampleShadingEnable = 0;
7711 pipe_ms_state_ci.minSampleShading = 1.0;
7712 pipe_ms_state_ci.pSampleMask = NULL;
7713
Karl Schultz6addd812016-02-02 17:17:23 -07007714 VkPipelineShaderStageCreateInfo shaderStages[2];
7715 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
7716
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007717 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07007718 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
7719 // We shouldn't need a fragment shader but add it to be able to run on more devices
Karl Schultz6addd812016-02-02 17:17:23 -07007720 shaderStages[0] = vs.GetStageCreateInfo();
7721 shaderStages[1] = fs.GetStageCreateInfo();
7722
7723 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7724 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7725 vi_ci.pNext = nullptr;
7726 vi_ci.vertexBindingDescriptionCount = 0;
7727 vi_ci.pVertexBindingDescriptions = nullptr;
7728 vi_ci.vertexAttributeDescriptionCount = 0;
7729 vi_ci.pVertexAttributeDescriptions = nullptr;
7730
7731 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7732 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7733 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7734
7735 VkPipelineRasterizationStateCreateInfo rs_ci = {};
7736 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07007737 rs_ci.lineWidth = m_device->props.limits.lineWidthRange[0];
Karl Schultz6addd812016-02-02 17:17:23 -07007738 rs_ci.pNext = nullptr;
7739
Mark Youngc89c6312016-03-31 16:03:20 -06007740 VkPipelineColorBlendAttachmentState att = {};
7741 att.blendEnable = VK_FALSE;
7742 att.colorWriteMask = 0xf;
7743
Karl Schultz6addd812016-02-02 17:17:23 -07007744 VkPipelineColorBlendStateCreateInfo cb_ci = {};
7745 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
7746 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06007747 cb_ci.attachmentCount = 1;
7748 cb_ci.pAttachments = &att;
Karl Schultz6addd812016-02-02 17:17:23 -07007749
7750 VkGraphicsPipelineCreateInfo gp_ci = {};
7751 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7752 gp_ci.stageCount = 2;
7753 gp_ci.pStages = shaderStages;
7754 gp_ci.pVertexInputState = &vi_ci;
7755 gp_ci.pInputAssemblyState = &ia_ci;
7756 gp_ci.pViewportState = &vp_state_ci;
7757 gp_ci.pRasterizationState = &rs_ci;
7758 gp_ci.pColorBlendState = &cb_ci;
7759 gp_ci.pDynamicState = &dyn_state_ci;
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07007760 gp_ci.pMultisampleState = &pipe_ms_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007761 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7762 gp_ci.layout = pipeline_layout;
7763 gp_ci.renderPass = renderPass();
7764
7765 VkPipelineCacheCreateInfo pc_ci = {};
7766 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
7767
7768 VkPipeline pipeline;
7769 VkPipelineCache pipelineCache;
7770
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007771 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Karl Schultz6addd812016-02-02 17:17:23 -07007772 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007773 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Karl Schultz6addd812016-02-02 17:17:23 -07007774
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007775 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07007776
7777 // Now hit second fail case where we set scissor w/ different count than PSO
7778 // First need to successfully create the PSO from above by setting
7779 // pViewports
Mike Weiblen95dd0f92016-10-19 12:28:27 -06007780 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 -06007781
Tobin Ehlisd332f282015-10-02 11:00:56 -06007782 VkRect2D sc = {}; // Just need dummy vp to point to
7783 vp_state_ci.pScissors = &sc;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007784 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlisd332f282015-10-02 11:00:56 -06007785 ASSERT_VK_SUCCESS(err);
7786 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007787 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07007788 VkViewport viewports[1] = {};
7789 viewports[0].width = 8;
7790 viewports[0].height = 8;
Tobin Ehlisd332f282015-10-02 11:00:56 -06007791 // Count of 2 doesn't match PSO count of 1
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007792 vkCmdSetViewport(m_commandBuffer->GetBufferHandle(), 1, 1, viewports);
Tobin Ehlisd332f282015-10-02 11:00:56 -06007793 Draw(1, 0, 0, 0);
7794
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007795 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007796
Chia-I Wuf7458c52015-10-26 21:10:41 +08007797 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7798 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7799 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7800 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06007801 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007802}
7803
Mark Young7394fdd2016-03-31 14:56:43 -06007804TEST_F(VkLayerTest, PSOLineWidthInvalid) {
7805 VkResult err;
7806
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007807 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to -1");
Mark Young7394fdd2016-03-31 14:56:43 -06007808
7809 ASSERT_NO_FATAL_FAILURE(InitState());
7810 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7811
7812 VkDescriptorPoolSize ds_type_count = {};
7813 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7814 ds_type_count.descriptorCount = 1;
7815
7816 VkDescriptorPoolCreateInfo ds_pool_ci = {};
7817 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7818 ds_pool_ci.maxSets = 1;
7819 ds_pool_ci.poolSizeCount = 1;
7820 ds_pool_ci.pPoolSizes = &ds_type_count;
7821
7822 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007823 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Mark Young7394fdd2016-03-31 14:56:43 -06007824 ASSERT_VK_SUCCESS(err);
7825
7826 VkDescriptorSetLayoutBinding dsl_binding = {};
7827 dsl_binding.binding = 0;
7828 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7829 dsl_binding.descriptorCount = 1;
7830 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7831
7832 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
7833 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7834 ds_layout_ci.bindingCount = 1;
7835 ds_layout_ci.pBindings = &dsl_binding;
7836
7837 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007838 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Young7394fdd2016-03-31 14:56:43 -06007839 ASSERT_VK_SUCCESS(err);
7840
7841 VkDescriptorSet descriptorSet;
7842 VkDescriptorSetAllocateInfo alloc_info = {};
7843 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
7844 alloc_info.descriptorSetCount = 1;
7845 alloc_info.descriptorPool = ds_pool;
7846 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007847 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Young7394fdd2016-03-31 14:56:43 -06007848 ASSERT_VK_SUCCESS(err);
7849
7850 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
7851 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7852 pipeline_layout_ci.setLayoutCount = 1;
7853 pipeline_layout_ci.pSetLayouts = &ds_layout;
7854
7855 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007856 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Mark Young7394fdd2016-03-31 14:56:43 -06007857 ASSERT_VK_SUCCESS(err);
7858
7859 VkPipelineViewportStateCreateInfo vp_state_ci = {};
7860 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
7861 vp_state_ci.scissorCount = 1;
7862 vp_state_ci.pScissors = NULL;
7863 vp_state_ci.viewportCount = 1;
7864 vp_state_ci.pViewports = NULL;
7865
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007866 VkDynamicState dynamic_states[3] = {VK_DYNAMIC_STATE_VIEWPORT, VK_DYNAMIC_STATE_SCISSOR, VK_DYNAMIC_STATE_LINE_WIDTH};
Mark Young7394fdd2016-03-31 14:56:43 -06007867 // Set scissor as dynamic to avoid that error
7868 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
7869 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
7870 dyn_state_ci.dynamicStateCount = 2;
7871 dyn_state_ci.pDynamicStates = dynamic_states;
7872
7873 VkPipelineShaderStageCreateInfo shaderStages[2];
7874 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
7875
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007876 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
7877 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT,
Mark Young7394fdd2016-03-31 14:56:43 -06007878 this); // TODO - We shouldn't need a fragment shader
7879 // but add it to be able to run on more devices
7880 shaderStages[0] = vs.GetStageCreateInfo();
7881 shaderStages[1] = fs.GetStageCreateInfo();
7882
7883 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7884 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7885 vi_ci.pNext = nullptr;
7886 vi_ci.vertexBindingDescriptionCount = 0;
7887 vi_ci.pVertexBindingDescriptions = nullptr;
7888 vi_ci.vertexAttributeDescriptionCount = 0;
7889 vi_ci.pVertexAttributeDescriptions = nullptr;
7890
7891 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7892 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7893 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7894
7895 VkPipelineRasterizationStateCreateInfo rs_ci = {};
7896 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7897 rs_ci.pNext = nullptr;
7898
Mark Young47107952016-05-02 15:59:55 -06007899 // Check too low (line width of -1.0f).
7900 rs_ci.lineWidth = -1.0f;
Mark Young7394fdd2016-03-31 14:56:43 -06007901
7902 VkPipelineColorBlendAttachmentState att = {};
7903 att.blendEnable = VK_FALSE;
7904 att.colorWriteMask = 0xf;
7905
7906 VkPipelineColorBlendStateCreateInfo cb_ci = {};
7907 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
7908 cb_ci.pNext = nullptr;
7909 cb_ci.attachmentCount = 1;
7910 cb_ci.pAttachments = &att;
7911
7912 VkGraphicsPipelineCreateInfo gp_ci = {};
7913 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7914 gp_ci.stageCount = 2;
7915 gp_ci.pStages = shaderStages;
7916 gp_ci.pVertexInputState = &vi_ci;
7917 gp_ci.pInputAssemblyState = &ia_ci;
7918 gp_ci.pViewportState = &vp_state_ci;
7919 gp_ci.pRasterizationState = &rs_ci;
7920 gp_ci.pColorBlendState = &cb_ci;
7921 gp_ci.pDynamicState = &dyn_state_ci;
7922 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7923 gp_ci.layout = pipeline_layout;
7924 gp_ci.renderPass = renderPass();
7925
7926 VkPipelineCacheCreateInfo pc_ci = {};
7927 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
7928
7929 VkPipeline pipeline;
7930 VkPipelineCache pipelineCache;
7931
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007932 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06007933 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007934 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06007935
7936 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06007937 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06007938
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007939 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to 65536");
Mark Young7394fdd2016-03-31 14:56:43 -06007940
7941 // Check too high (line width of 65536.0f).
7942 rs_ci.lineWidth = 65536.0f;
7943
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007944 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06007945 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007946 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06007947
7948 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06007949 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06007950
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007951 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to -1");
Mark Young7394fdd2016-03-31 14:56:43 -06007952
7953 dyn_state_ci.dynamicStateCount = 3;
7954
7955 rs_ci.lineWidth = 1.0f;
7956
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007957 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06007958 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007959 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06007960 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007961 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06007962
7963 // Check too low with dynamic setting.
Mark Young47107952016-05-02 15:59:55 -06007964 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), -1.0f);
Mark Young7394fdd2016-03-31 14:56:43 -06007965 m_errorMonitor->VerifyFound();
7966
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007967 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to 65536");
Mark Young7394fdd2016-03-31 14:56:43 -06007968
7969 // Check too high with dynamic setting.
7970 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), 65536.0f);
7971 m_errorMonitor->VerifyFound();
7972 EndCommandBuffer();
7973
7974 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7975 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7976 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7977 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06007978 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06007979}
7980
Karl Schultz6addd812016-02-02 17:17:23 -07007981TEST_F(VkLayerTest, NullRenderPass) {
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007982 // Bind a NULL RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007983 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mike Schuchardt0b1f2f82016-12-28 15:11:20 -07007984 "vkCmdBeginRenderPass: required parameter pRenderPassBegin specified as NULL");
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007985
7986 ASSERT_NO_FATAL_FAILURE(InitState());
7987 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007988
Tony Barbourfe3351b2015-07-28 10:17:20 -06007989 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07007990 // Don't care about RenderPass handle b/c error should be flagged before
7991 // that
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007992 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), NULL, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007993
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007994 m_errorMonitor->VerifyFound();
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007995}
7996
Karl Schultz6addd812016-02-02 17:17:23 -07007997TEST_F(VkLayerTest, RenderPassWithinRenderPass) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007998 // Bind a BeginRenderPass within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007999 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8000 "It is invalid to issue this call inside an active render pass");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008001
8002 ASSERT_NO_FATAL_FAILURE(InitState());
8003 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008004
Tony Barbourfe3351b2015-07-28 10:17:20 -06008005 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07008006 // Just create a dummy Renderpass that's non-NULL so we can get to the
8007 // proper error
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008008 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008009
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008010 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06008011}
8012
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008013TEST_F(VkLayerTest, RenderPassClearOpMismatch) {
8014 TEST_DESCRIPTION("Begin a renderPass where clearValueCount is less than"
8015 "the number of renderPass attachments that use loadOp"
8016 "VK_ATTACHMENT_LOAD_OP_CLEAR.");
8017
8018 ASSERT_NO_FATAL_FAILURE(InitState());
8019 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8020
8021 // Create a renderPass with a single attachment that uses loadOp CLEAR
8022 VkAttachmentReference attach = {};
8023 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
8024 VkSubpassDescription subpass = {};
8025 subpass.inputAttachmentCount = 1;
8026 subpass.pInputAttachments = &attach;
8027 VkRenderPassCreateInfo rpci = {};
8028 rpci.subpassCount = 1;
8029 rpci.pSubpasses = &subpass;
8030 rpci.attachmentCount = 1;
8031 VkAttachmentDescription attach_desc = {};
8032 attach_desc.format = VK_FORMAT_UNDEFINED;
8033 // Set loadOp to CLEAR
8034 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
8035 rpci.pAttachments = &attach_desc;
8036 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
8037 VkRenderPass rp;
8038 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
8039
8040 VkCommandBufferInheritanceInfo hinfo = {};
8041 hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
8042 hinfo.renderPass = VK_NULL_HANDLE;
8043 hinfo.subpass = 0;
8044 hinfo.framebuffer = VK_NULL_HANDLE;
8045 hinfo.occlusionQueryEnable = VK_FALSE;
8046 hinfo.queryFlags = 0;
8047 hinfo.pipelineStatistics = 0;
8048 VkCommandBufferBeginInfo info = {};
8049 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
8050 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
8051 info.pInheritanceInfo = &hinfo;
8052
8053 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
8054 VkRenderPassBeginInfo rp_begin = {};
8055 rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
8056 rp_begin.pNext = NULL;
8057 rp_begin.renderPass = renderPass();
8058 rp_begin.framebuffer = framebuffer();
8059 rp_begin.clearValueCount = 0; // Should be 1
8060
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008061 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has a clearValueCount of 0 but "
8062 "there must be at least 1 entries in "
8063 "pClearValues array to account for ");
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008064
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008065 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rp_begin, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008066
8067 m_errorMonitor->VerifyFound();
Mark Lobodzinski5c70ebd2016-06-09 13:45:00 -06008068
8069 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008070}
8071
Slawomir Cygan0808f392016-11-28 17:53:23 +01008072TEST_F(VkLayerTest, RenderPassClearOpTooManyValues) {
8073 TEST_DESCRIPTION("Begin a renderPass where clearValueCount is greater than"
8074 "the number of renderPass attachments that use loadOp"
8075 "VK_ATTACHMENT_LOAD_OP_CLEAR.");
8076
8077 ASSERT_NO_FATAL_FAILURE(InitState());
8078 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8079
8080 // Create a renderPass with a single attachment that uses loadOp CLEAR
8081 VkAttachmentReference attach = {};
8082 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
8083 VkSubpassDescription subpass = {};
8084 subpass.inputAttachmentCount = 1;
8085 subpass.pInputAttachments = &attach;
8086 VkRenderPassCreateInfo rpci = {};
8087 rpci.subpassCount = 1;
8088 rpci.pSubpasses = &subpass;
8089 rpci.attachmentCount = 1;
8090 VkAttachmentDescription attach_desc = {};
8091 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
8092 // Set loadOp to CLEAR
8093 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
8094 rpci.pAttachments = &attach_desc;
8095 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
8096 VkRenderPass rp;
8097 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
8098
8099 VkCommandBufferBeginInfo info = {};
8100 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
8101 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
8102
8103 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
8104 VkRenderPassBeginInfo rp_begin = {};
8105 rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
8106 rp_begin.pNext = NULL;
8107 rp_begin.renderPass = renderPass();
8108 rp_begin.framebuffer = framebuffer();
8109 rp_begin.clearValueCount = 2; // Should be 1
8110
8111 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, " has a clearValueCount of"
8112 " 2 but only first 1 entries in pClearValues array are used");
8113
8114 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rp_begin, VK_SUBPASS_CONTENTS_INLINE);
8115
8116 m_errorMonitor->VerifyFound();
8117
8118 vkDestroyRenderPass(m_device->device(), rp, NULL);
8119}
8120
8121
Cody Northrop3bb4d962016-05-09 16:15:57 -06008122TEST_F(VkLayerTest, EndCommandBufferWithinRenderPass) {
8123
8124 TEST_DESCRIPTION("End a command buffer with an active render pass");
8125
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008126 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8127 "It is invalid to issue this call inside an active render pass");
Cody Northrop3bb4d962016-05-09 16:15:57 -06008128
8129 ASSERT_NO_FATAL_FAILURE(InitState());
8130 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8131
8132 // The framework's BeginCommandBuffer calls CreateRenderPass
8133 BeginCommandBuffer();
8134
8135 // Call directly into vkEndCommandBuffer instead of the
8136 // the framework's EndCommandBuffer, which inserts a
8137 // vkEndRenderPass
8138 vkEndCommandBuffer(m_commandBuffer->GetBufferHandle());
8139
8140 m_errorMonitor->VerifyFound();
8141
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008142 // TODO: Add test for VK_COMMAND_BUFFER_LEVEL_SECONDARY
8143 // TODO: Add test for VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT
Cody Northrop3bb4d962016-05-09 16:15:57 -06008144}
8145
Karl Schultz6addd812016-02-02 17:17:23 -07008146TEST_F(VkLayerTest, FillBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008147 // Call CmdFillBuffer within an active renderpass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008148 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8149 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008150
8151 ASSERT_NO_FATAL_FAILURE(InitState());
8152 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008153
8154 // Renderpass is started here
8155 BeginCommandBuffer();
8156
8157 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008158 vk_testing::Buffer dstBuffer;
8159 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008160
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008161 m_commandBuffer->FillBuffer(dstBuffer.handle(), 0, 4, 0x11111111);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008162
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008163 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008164}
8165
Karl Schultz6addd812016-02-02 17:17:23 -07008166TEST_F(VkLayerTest, UpdateBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008167 // Call CmdUpdateBuffer within an active renderpass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008168 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8169 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008170
8171 ASSERT_NO_FATAL_FAILURE(InitState());
8172 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008173
8174 // Renderpass is started here
8175 BeginCommandBuffer();
8176
8177 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008178 vk_testing::Buffer dstBuffer;
8179 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008180
Karl Schultz6addd812016-02-02 17:17:23 -07008181 VkDeviceSize dstOffset = 0;
8182 VkDeviceSize dataSize = 1024;
Karl Schultzee344492016-07-11 15:09:57 -06008183 const void *pData = NULL;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008184
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008185 vkCmdUpdateBuffer(m_commandBuffer->GetBufferHandle(), dstBuffer.handle(), dstOffset, dataSize, pData);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008186
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008187 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008188}
8189
Karl Schultz6addd812016-02-02 17:17:23 -07008190TEST_F(VkLayerTest, ClearColorImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008191 // Call CmdClearColorImage within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008192 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8193 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008194
8195 ASSERT_NO_FATAL_FAILURE(InitState());
8196 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008197
8198 // Renderpass is started here
8199 BeginCommandBuffer();
8200
Michael Lentine0a369f62016-02-03 16:51:46 -06008201 VkClearColorValue clear_color;
8202 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
Karl Schultz6addd812016-02-02 17:17:23 -07008203 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
8204 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
8205 const int32_t tex_width = 32;
8206 const int32_t tex_height = 32;
8207 VkImageCreateInfo image_create_info = {};
8208 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
8209 image_create_info.pNext = NULL;
8210 image_create_info.imageType = VK_IMAGE_TYPE_2D;
8211 image_create_info.format = tex_format;
8212 image_create_info.extent.width = tex_width;
8213 image_create_info.extent.height = tex_height;
8214 image_create_info.extent.depth = 1;
8215 image_create_info.mipLevels = 1;
8216 image_create_info.arrayLayers = 1;
8217 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
8218 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
8219 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008220
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008221 vk_testing::Image dstImage;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008222 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008223
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008224 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008225
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008226 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1, &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008227
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008228 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008229}
8230
Karl Schultz6addd812016-02-02 17:17:23 -07008231TEST_F(VkLayerTest, ClearDepthStencilImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008232 // Call CmdClearDepthStencilImage within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008233 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8234 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008235
8236 ASSERT_NO_FATAL_FAILURE(InitState());
8237 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008238
8239 // Renderpass is started here
8240 BeginCommandBuffer();
8241
8242 VkClearDepthStencilValue clear_value = {0};
Dustin Gravesa2e5c942016-02-11 18:28:06 -07008243 VkMemoryPropertyFlags reqs = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07008244 VkImageCreateInfo image_create_info = vk_testing::Image::create_info();
8245 image_create_info.imageType = VK_IMAGE_TYPE_2D;
8246 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
8247 image_create_info.extent.width = 64;
8248 image_create_info.extent.height = 64;
8249 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
8250 image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008251
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008252 vk_testing::Image dstImage;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008253 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008254
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008255 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_DEPTH_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008256
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008257 vkCmdClearDepthStencilImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(),
8258 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, &clear_value, 1, &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008259
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008260 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008261}
8262
Karl Schultz6addd812016-02-02 17:17:23 -07008263TEST_F(VkLayerTest, ClearColorAttachmentsOutsideRenderPass) {
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06008264 // Call CmdClearAttachmentss outside of an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07008265 VkResult err;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008266
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008267 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdClearAttachments(): This call "
8268 "must be issued inside an active "
8269 "render pass");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008270
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008271 ASSERT_NO_FATAL_FAILURE(InitState());
8272 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008273
8274 // Start no RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008275 err = m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008276 ASSERT_VK_SUCCESS(err);
8277
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06008278 VkClearAttachment color_attachment;
8279 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8280 color_attachment.clearValue.color.float32[0] = 0;
8281 color_attachment.clearValue.color.float32[1] = 0;
8282 color_attachment.clearValue.color.float32[2] = 0;
8283 color_attachment.clearValue.color.float32[3] = 0;
8284 color_attachment.colorAttachment = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07008285 VkClearRect clear_rect = {{{0, 0}, {32, 32}}};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008286 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008287
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008288 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008289}
8290
Chris Forbes3b97e932016-09-07 11:29:24 +12008291TEST_F(VkLayerTest, RenderPassExcessiveNextSubpass) {
8292 TEST_DESCRIPTION("Test that an error is produced when CmdNextSubpass is "
8293 "called too many times in a renderpass instance");
8294
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008295 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdNextSubpass(): Attempted to advance "
8296 "beyond final subpass");
Chris Forbes3b97e932016-09-07 11:29:24 +12008297
8298 ASSERT_NO_FATAL_FAILURE(InitState());
8299 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8300
8301 BeginCommandBuffer();
8302
8303 // error here.
8304 vkCmdNextSubpass(m_commandBuffer->GetBufferHandle(), VK_SUBPASS_CONTENTS_INLINE);
8305 m_errorMonitor->VerifyFound();
8306
8307 EndCommandBuffer();
8308}
8309
Chris Forbes6d624702016-09-07 13:57:05 +12008310TEST_F(VkLayerTest, RenderPassEndedBeforeFinalSubpass) {
8311 TEST_DESCRIPTION("Test that an error is produced when CmdEndRenderPass is "
8312 "called before the final subpass has been reached");
8313
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008314 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdEndRenderPass(): Called before reaching "
8315 "final subpass");
Chris Forbes6d624702016-09-07 13:57:05 +12008316
8317 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008318 VkSubpassDescription sd[2] = {{0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr},
8319 {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr}};
Chris Forbes6d624702016-09-07 13:57:05 +12008320
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008321 VkRenderPassCreateInfo rcpi = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 2, sd, 0, nullptr};
Chris Forbes6d624702016-09-07 13:57:05 +12008322
8323 VkRenderPass rp;
8324 VkResult err = vkCreateRenderPass(m_device->device(), &rcpi, nullptr, &rp);
8325 ASSERT_VK_SUCCESS(err);
8326
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008327 VkFramebufferCreateInfo fbci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 0, nullptr, 16, 16, 1};
Chris Forbes6d624702016-09-07 13:57:05 +12008328
8329 VkFramebuffer fb;
8330 err = vkCreateFramebuffer(m_device->device(), &fbci, nullptr, &fb);
8331 ASSERT_VK_SUCCESS(err);
8332
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008333 m_commandBuffer->BeginCommandBuffer(); // no implicit RP begin
Chris Forbes6d624702016-09-07 13:57:05 +12008334
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008335 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 +12008336
8337 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
8338
8339 // Error here.
8340 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
8341 m_errorMonitor->VerifyFound();
8342
8343 // Clean up.
8344 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
8345 vkDestroyRenderPass(m_device->device(), rp, nullptr);
8346}
8347
Karl Schultz9e66a292016-04-21 15:57:51 -06008348TEST_F(VkLayerTest, BufferMemoryBarrierNoBuffer) {
8349 // Try to add a buffer memory barrier with no buffer.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008350 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8351 "required parameter pBufferMemoryBarriers[0].buffer specified as VK_NULL_HANDLE");
Karl Schultz9e66a292016-04-21 15:57:51 -06008352
8353 ASSERT_NO_FATAL_FAILURE(InitState());
8354 BeginCommandBuffer();
8355
8356 VkBufferMemoryBarrier buf_barrier = {};
8357 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
8358 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8359 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
8360 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8361 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8362 buf_barrier.buffer = VK_NULL_HANDLE;
8363 buf_barrier.offset = 0;
8364 buf_barrier.size = VK_WHOLE_SIZE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008365 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8366 nullptr, 1, &buf_barrier, 0, nullptr);
Karl Schultz9e66a292016-04-21 15:57:51 -06008367
8368 m_errorMonitor->VerifyFound();
8369}
8370
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008371TEST_F(VkLayerTest, InvalidBarriers) {
8372 TEST_DESCRIPTION("A variety of ways to get VK_INVALID_BARRIER ");
8373
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008374 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Barriers cannot be set during subpass");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008375
8376 ASSERT_NO_FATAL_FAILURE(InitState());
8377 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8378
8379 VkMemoryBarrier mem_barrier = {};
8380 mem_barrier.sType = VK_STRUCTURE_TYPE_MEMORY_BARRIER;
8381 mem_barrier.pNext = NULL;
8382 mem_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8383 mem_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
8384 BeginCommandBuffer();
8385 // BeginCommandBuffer() starts a render pass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008386 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 1,
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008387 &mem_barrier, 0, nullptr, 0, nullptr);
8388 m_errorMonitor->VerifyFound();
8389
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008390 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Image Layout cannot be transitioned to UNDEFINED");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008391 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008392 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 -06008393 ASSERT_TRUE(image.initialized());
8394 VkImageMemoryBarrier img_barrier = {};
8395 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
8396 img_barrier.pNext = NULL;
8397 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8398 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
8399 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8400 // New layout can't be UNDEFINED
8401 img_barrier.newLayout = VK_IMAGE_LAYOUT_UNDEFINED;
8402 img_barrier.image = image.handle();
8403 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8404 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8405 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8406 img_barrier.subresourceRange.baseArrayLayer = 0;
8407 img_barrier.subresourceRange.baseMipLevel = 0;
8408 img_barrier.subresourceRange.layerCount = 1;
8409 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008410 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8411 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008412 m_errorMonitor->VerifyFound();
8413 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8414
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008415 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Subresource must have the sum of the "
8416 "baseArrayLayer");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008417 // baseArrayLayer + layerCount must be <= image's arrayLayers
8418 img_barrier.subresourceRange.baseArrayLayer = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008419 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8420 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008421 m_errorMonitor->VerifyFound();
8422 img_barrier.subresourceRange.baseArrayLayer = 0;
8423
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008424 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Subresource must have the sum of the baseMipLevel");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008425 // baseMipLevel + levelCount must be <= image's mipLevels
8426 img_barrier.subresourceRange.baseMipLevel = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008427 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8428 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008429 m_errorMonitor->VerifyFound();
8430 img_barrier.subresourceRange.baseMipLevel = 0;
8431
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008432 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 -06008433 vk_testing::Buffer buffer;
Mark Lobodzinskibdf378a2016-12-12 17:11:50 -07008434 VkMemoryPropertyFlags mem_reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
8435 buffer.init_as_src_and_dst(*m_device, 256, mem_reqs);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008436 VkBufferMemoryBarrier buf_barrier = {};
8437 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
8438 buf_barrier.pNext = NULL;
8439 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8440 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
8441 buf_barrier.buffer = buffer.handle();
8442 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8443 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8444 buf_barrier.offset = 0;
8445 buf_barrier.size = VK_WHOLE_SIZE;
8446 // Can't send buffer barrier during a render pass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008447 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8448 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008449 m_errorMonitor->VerifyFound();
8450 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
8451
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008452 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "which is not less than total size");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008453 buf_barrier.offset = 257;
8454 // Offset greater than total size
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008455 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8456 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008457 m_errorMonitor->VerifyFound();
8458 buf_barrier.offset = 0;
8459
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008460 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "whose sum is greater than total size");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008461 buf_barrier.size = 257;
8462 // Size greater than total size
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008463 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8464 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008465 m_errorMonitor->VerifyFound();
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008466
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008467 // Now exercise barrier aspect bit errors, first DS
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06008468 m_errorMonitor->SetDesiredFailureMsg(
8469 VK_DEBUG_REPORT_ERROR_BIT_EXT,
8470 "Combination depth/stencil image formats can have only the VK_IMAGE_ASPECT_DEPTH_BIT and VK_IMAGE_ASPECT_STENCIL_BIT set.");
8471 m_errorMonitor->SetDesiredFailureMsg(
8472 VK_DEBUG_REPORT_ERROR_BIT_EXT,
8473 "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 -06008474 VkDepthStencilObj ds_image(m_device);
8475 ds_image.Init(m_device, 128, 128, VK_FORMAT_D24_UNORM_S8_UINT);
8476 ASSERT_TRUE(ds_image.initialized());
Tobin Ehlis15684a02016-07-21 14:55:26 -06008477 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
8478 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008479 img_barrier.image = ds_image.handle();
Tobin Ehlis15684a02016-07-21 14:55:26 -06008480 // Use of COLOR aspect on DS image is error
8481 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008482 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8483 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008484 m_errorMonitor->VerifyFound();
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008485 // Now test depth-only
8486 VkFormatProperties format_props;
8487
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008488 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_D16_UNORM, &format_props);
8489 if (format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) {
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06008490 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8491 "Depth-only image formats must have the VK_IMAGE_ASPECT_DEPTH_BIT set.");
8492 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8493 "Depth-only image formats can have only the VK_IMAGE_ASPECT_DEPTH_BIT set.");
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008494 VkDepthStencilObj d_image(m_device);
8495 d_image.Init(m_device, 128, 128, VK_FORMAT_D16_UNORM);
8496 ASSERT_TRUE(d_image.initialized());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008497 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
Tobin Ehlis15684a02016-07-21 14:55:26 -06008498 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008499 img_barrier.image = d_image.handle();
Tobin Ehlis15684a02016-07-21 14:55:26 -06008500 // Use of COLOR aspect on depth image is error
8501 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008502 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
8503 0, nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008504 m_errorMonitor->VerifyFound();
8505 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008506 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_S8_UINT, &format_props);
8507 if (format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) {
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008508 // Now test stencil-only
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06008509 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8510 "Stencil-only image formats must have the VK_IMAGE_ASPECT_STENCIL_BIT set.");
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008511 VkDepthStencilObj s_image(m_device);
8512 s_image.Init(m_device, 128, 128, VK_FORMAT_S8_UINT);
8513 ASSERT_TRUE(s_image.initialized());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008514 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
Tobin Ehlis15684a02016-07-21 14:55:26 -06008515 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008516 img_barrier.image = s_image.handle();
Tobin Ehlis15684a02016-07-21 14:55:26 -06008517 // Use of COLOR aspect on depth image is error
8518 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008519 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
8520 0, nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008521 m_errorMonitor->VerifyFound();
8522 }
8523 // Finally test color
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06008524 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8525 "Color image formats must have the VK_IMAGE_ASPECT_COLOR_BIT set.");
8526 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8527 "Color image formats must have ONLY the VK_IMAGE_ASPECT_COLOR_BIT set.");
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008528 VkImageObj c_image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008529 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 -06008530 ASSERT_TRUE(c_image.initialized());
8531 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8532 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
8533 img_barrier.image = c_image.handle();
8534 // Set aspect to depth (non-color)
8535 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008536 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8537 nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008538 m_errorMonitor->VerifyFound();
Mark Lobodzinskibdf378a2016-12-12 17:11:50 -07008539
8540 // Attempt to mismatch barriers/waitEvents calls with incompatible queues
8541
8542 // Create command pool with incompatible queueflags
8543 const std::vector<VkQueueFamilyProperties> queue_props = m_device->queue_props;
8544 uint32_t queue_family_index = UINT32_MAX;
8545 for (uint32_t i = 0; i < queue_props.size(); i++) {
8546 if ((queue_props[i].queueFlags & VK_QUEUE_COMPUTE_BIT) == 0) {
8547 queue_family_index = i;
8548 break;
8549 }
8550 }
8551 if (queue_family_index == UINT32_MAX) {
8552 printf("No non-compute queue found; skipped.\n");
8553 return;
8554 }
8555 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02513);
8556
8557 VkCommandPool command_pool;
8558 VkCommandPoolCreateInfo pool_create_info{};
8559 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
8560 pool_create_info.queueFamilyIndex = queue_family_index;
8561 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
8562 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
8563
8564 // Allocate a command buffer
8565 VkCommandBuffer bad_command_buffer;
8566 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
8567 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
8568 command_buffer_allocate_info.commandPool = command_pool;
8569 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
8570 command_buffer_allocate_info.commandBufferCount = 1;
8571 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &bad_command_buffer));
8572
8573 VkCommandBufferBeginInfo cbbi = {};
8574 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
8575 vkBeginCommandBuffer(bad_command_buffer, &cbbi);
8576 buf_barrier.offset = 0;
8577 buf_barrier.size = VK_WHOLE_SIZE;
8578 vkCmdPipelineBarrier(bad_command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 1,
8579 &buf_barrier, 0, nullptr);
8580 m_errorMonitor->VerifyFound();
8581
8582 if ((queue_props[queue_family_index].queueFlags & VK_QUEUE_GRAPHICS_BIT) == 0) {
8583 vkEndCommandBuffer(bad_command_buffer);
8584 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
8585 printf("The non-compute queue does not support graphics; skipped.\n");
8586 return;
8587 }
8588 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02510);
8589 VkEvent event;
8590 VkEventCreateInfo event_create_info{};
8591 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
8592 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
8593 vkCmdWaitEvents(bad_command_buffer, 1, &event, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, nullptr, 0,
8594 nullptr, 0, nullptr);
8595 m_errorMonitor->VerifyFound();
8596
8597 vkEndCommandBuffer(bad_command_buffer);
8598 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008599}
8600
Tony Barbour18ba25c2016-09-29 13:42:40 -06008601TEST_F(VkLayerTest, LayoutFromPresentWithoutAccessMemoryRead) {
8602 // Transition an image away from PRESENT_SRC_KHR without ACCESS_MEMORY_READ in srcAccessMask
8603
8604 m_errorMonitor->SetDesiredFailureMsg(
8605 VK_DEBUG_REPORT_WARNING_BIT_EXT,
8606 "must have required access bit");
8607 ASSERT_NO_FATAL_FAILURE(InitState());
8608 VkImageObj image(m_device);
Tony Barbour256c80a2016-10-05 13:23:46 -06008609 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 -06008610 ASSERT_TRUE(image.initialized());
8611
8612 VkImageMemoryBarrier barrier = {};
8613 VkImageSubresourceRange range;
8614 barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
8615 barrier.srcAccessMask = 0;
8616 barrier.srcAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
8617 barrier.dstAccessMask = VK_ACCESS_MEMORY_READ_BIT;
8618 barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8619 barrier.newLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
8620 barrier.image = image.handle();
8621 range.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8622 range.baseMipLevel = 0;
8623 range.levelCount = 1;
8624 range.baseArrayLayer = 0;
8625 range.layerCount = 1;
8626 barrier.subresourceRange = range;
8627 VkCommandBufferObj cmdbuf(m_device, m_commandPool);
8628 cmdbuf.BeginCommandBuffer();
8629 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
8630 &barrier);
8631 barrier.oldLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
8632 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
8633 barrier.srcAccessMask = 0;
8634 barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
8635 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
8636 &barrier);
8637
8638 m_errorMonitor->VerifyFound();
8639}
8640
Karl Schultz6addd812016-02-02 17:17:23 -07008641TEST_F(VkLayerTest, IdxBufferAlignmentError) {
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008642 // Bind a BeginRenderPass within an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07008643 VkResult err;
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008644
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008645 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdBindIndexBuffer() offset (0x7) does not fall on ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008646
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008647 ASSERT_NO_FATAL_FAILURE(InitState());
8648 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008649 uint32_t qfi = 0;
8650 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008651 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
8652 buffCI.size = 1024;
8653 buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
8654 buffCI.queueFamilyIndexCount = 1;
8655 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008656
8657 VkBuffer ib;
Chia-I Wuf7458c52015-10-26 21:10:41 +08008658 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008659 ASSERT_VK_SUCCESS(err);
8660
8661 BeginCommandBuffer();
8662 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07008663 // vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
8664 // VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008665 // Should error before calling to driver so don't care about actual data
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008666 vkCmdBindIndexBuffer(m_commandBuffer->GetBufferHandle(), ib, 7, VK_INDEX_TYPE_UINT16);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008667
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008668 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06008669
Chia-I Wuf7458c52015-10-26 21:10:41 +08008670 vkDestroyBuffer(m_device->device(), ib, NULL);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008671}
8672
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07008673TEST_F(VkLayerTest, InvalidQueueFamilyIndex) {
8674 // Create an out-of-range queueFamilyIndex
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008675 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8676 "vkCreateBuffer: pCreateInfo->pQueueFamilyIndices[0] (777) must be one "
8677 "of the indices specified when the device was created, via the "
8678 "VkDeviceQueueCreateInfo structure.");
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07008679
8680 ASSERT_NO_FATAL_FAILURE(InitState());
8681 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8682 VkBufferCreateInfo buffCI = {};
8683 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
8684 buffCI.size = 1024;
8685 buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
8686 buffCI.queueFamilyIndexCount = 1;
8687 // Introduce failure by specifying invalid queue_family_index
8688 uint32_t qfi = 777;
8689 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis24aab042016-03-24 10:54:18 -06008690 buffCI.sharingMode = VK_SHARING_MODE_CONCURRENT; // qfi only matters in CONCURRENT mode
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07008691
8692 VkBuffer ib;
8693 vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
8694
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008695 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06008696 vkDestroyBuffer(m_device->device(), ib, NULL);
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07008697}
8698
Karl Schultz6addd812016-02-02 17:17:23 -07008699TEST_F(VkLayerTest, ExecuteCommandsPrimaryCB) {
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -06008700TEST_DESCRIPTION("Attempt vkCmdExecuteCommands with a primary command buffer"
Tobin Ehlis0c94db02016-07-19 10:49:32 -06008701 " (should only be secondary)");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008702
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06008703 ASSERT_NO_FATAL_FAILURE(InitState());
8704 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06008705
Chris Forbesf29a84f2016-10-06 18:39:28 +13008706 // An empty primary command buffer
8707 VkCommandBufferObj cb(m_device, m_commandPool);
8708 cb.BeginCommandBuffer();
8709 cb.EndCommandBuffer();
Tobin Ehlis0c94db02016-07-19 10:49:32 -06008710
Chris Forbesf29a84f2016-10-06 18:39:28 +13008711 m_commandBuffer->BeginCommandBuffer();
8712 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
8713 VkCommandBuffer handle = cb.handle();
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06008714
Chris Forbesf29a84f2016-10-06 18:39:28 +13008715 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdExecuteCommands() called w/ Primary Cmd Buffer ");
8716 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &handle);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008717 m_errorMonitor->VerifyFound();
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06008718}
8719
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008720TEST_F(VkLayerTest, DSUsageBitsErrors) {
8721 TEST_DESCRIPTION("Attempt to update descriptor sets for images and buffers "
8722 "that do not have correct usage bits sets.");
8723 VkResult err;
8724
8725 ASSERT_NO_FATAL_FAILURE(InitState());
8726 VkDescriptorPoolSize ds_type_count[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
8727 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
8728 ds_type_count[i].type = VkDescriptorType(i);
8729 ds_type_count[i].descriptorCount = 1;
8730 }
8731 VkDescriptorPoolCreateInfo ds_pool_ci = {};
8732 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8733 ds_pool_ci.pNext = NULL;
8734 ds_pool_ci.maxSets = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
8735 ds_pool_ci.poolSizeCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
8736 ds_pool_ci.pPoolSizes = ds_type_count;
8737
8738 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008739 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008740 ASSERT_VK_SUCCESS(err);
8741
8742 // Create 10 layouts where each has a single descriptor of different type
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008743 VkDescriptorSetLayoutBinding dsl_binding[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008744 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
8745 dsl_binding[i].binding = 0;
8746 dsl_binding[i].descriptorType = VkDescriptorType(i);
8747 dsl_binding[i].descriptorCount = 1;
8748 dsl_binding[i].stageFlags = VK_SHADER_STAGE_ALL;
8749 dsl_binding[i].pImmutableSamplers = NULL;
8750 }
8751
8752 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
8753 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8754 ds_layout_ci.pNext = NULL;
8755 ds_layout_ci.bindingCount = 1;
8756 VkDescriptorSetLayout ds_layouts[VK_DESCRIPTOR_TYPE_RANGE_SIZE];
8757 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
8758 ds_layout_ci.pBindings = dsl_binding + i;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008759 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, ds_layouts + i);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008760 ASSERT_VK_SUCCESS(err);
8761 }
8762 VkDescriptorSet descriptor_sets[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
8763 VkDescriptorSetAllocateInfo alloc_info = {};
8764 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
8765 alloc_info.descriptorSetCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
8766 alloc_info.descriptorPool = ds_pool;
8767 alloc_info.pSetLayouts = ds_layouts;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008768 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptor_sets);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008769 ASSERT_VK_SUCCESS(err);
8770
8771 // Create a buffer & bufferView to be used for invalid updates
8772 VkBufferCreateInfo buff_ci = {};
8773 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
8774 // This usage is not valid for any descriptor type
8775 buff_ci.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
8776 buff_ci.size = 256;
8777 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
8778 VkBuffer buffer;
8779 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
8780 ASSERT_VK_SUCCESS(err);
8781
8782 VkBufferViewCreateInfo buff_view_ci = {};
8783 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
8784 buff_view_ci.buffer = buffer;
8785 buff_view_ci.format = VK_FORMAT_R8_UNORM;
8786 buff_view_ci.range = VK_WHOLE_SIZE;
8787 VkBufferView buff_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008788 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buff_view);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008789 ASSERT_VK_SUCCESS(err);
8790
8791 // Create an image to be used for invalid updates
8792 VkImageCreateInfo image_ci = {};
8793 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
8794 image_ci.imageType = VK_IMAGE_TYPE_2D;
8795 image_ci.format = VK_FORMAT_R8G8B8A8_UNORM;
8796 image_ci.extent.width = 64;
8797 image_ci.extent.height = 64;
8798 image_ci.extent.depth = 1;
8799 image_ci.mipLevels = 1;
8800 image_ci.arrayLayers = 1;
8801 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
8802 image_ci.tiling = VK_IMAGE_TILING_LINEAR;
8803 image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
8804 // This usage is not valid for any descriptor type
8805 image_ci.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
8806 image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
8807 VkImage image;
8808 err = vkCreateImage(m_device->device(), &image_ci, NULL, &image);
8809 ASSERT_VK_SUCCESS(err);
8810 // Bind memory to image
8811 VkMemoryRequirements mem_reqs;
8812 VkDeviceMemory image_mem;
8813 bool pass;
8814 VkMemoryAllocateInfo mem_alloc = {};
8815 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
8816 mem_alloc.pNext = NULL;
8817 mem_alloc.allocationSize = 0;
8818 mem_alloc.memoryTypeIndex = 0;
8819 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
8820 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008821 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008822 ASSERT_TRUE(pass);
8823 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
8824 ASSERT_VK_SUCCESS(err);
8825 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
8826 ASSERT_VK_SUCCESS(err);
8827 // Now create view for image
8828 VkImageViewCreateInfo image_view_ci = {};
8829 image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
8830 image_view_ci.image = image;
8831 image_view_ci.format = VK_FORMAT_R8G8B8A8_UNORM;
8832 image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D;
8833 image_view_ci.subresourceRange.layerCount = 1;
8834 image_view_ci.subresourceRange.baseArrayLayer = 0;
8835 image_view_ci.subresourceRange.levelCount = 1;
8836 image_view_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8837 VkImageView image_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008838 err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, &image_view);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008839 ASSERT_VK_SUCCESS(err);
8840
8841 VkDescriptorBufferInfo buff_info = {};
8842 buff_info.buffer = buffer;
8843 VkDescriptorImageInfo img_info = {};
8844 img_info.imageView = image_view;
8845 VkWriteDescriptorSet descriptor_write = {};
8846 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
8847 descriptor_write.dstBinding = 0;
8848 descriptor_write.descriptorCount = 1;
8849 descriptor_write.pTexelBufferView = &buff_view;
8850 descriptor_write.pBufferInfo = &buff_info;
8851 descriptor_write.pImageInfo = &img_info;
8852
8853 // These error messages align with VkDescriptorType struct
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008854 const char *error_msgs[] = {"", // placeholder, no error for SAMPLER descriptor
8855 " does not have VK_IMAGE_USAGE_SAMPLED_BIT set.",
8856 " does not have VK_IMAGE_USAGE_SAMPLED_BIT set.",
8857 " does not have VK_IMAGE_USAGE_STORAGE_BIT set.",
8858 " does not have VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT set.",
8859 " does not have VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT set.",
8860 " does not have VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT set.",
8861 " does not have VK_BUFFER_USAGE_STORAGE_BUFFER_BIT set.",
8862 " does not have VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT set.",
8863 " does not have VK_BUFFER_USAGE_STORAGE_BUFFER_BIT set.",
8864 " does not have VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT set."};
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008865 // Start loop at 1 as SAMPLER desc type has no usage bit error
8866 for (uint32_t i = 1; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
8867 descriptor_write.descriptorType = VkDescriptorType(i);
8868 descriptor_write.dstSet = descriptor_sets[i];
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008869 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, error_msgs[i]);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008870
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008871 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008872
8873 m_errorMonitor->VerifyFound();
8874 vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[i], NULL);
8875 }
8876 vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[0], NULL);
8877 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06008878 vkFreeMemory(m_device->device(), image_mem, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008879 vkDestroyImageView(m_device->device(), image_view, NULL);
8880 vkDestroyBuffer(m_device->device(), buffer, NULL);
8881 vkDestroyBufferView(m_device->device(), buff_view, NULL);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008882 vkFreeDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_TYPE_RANGE_SIZE, descriptor_sets);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008883 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
8884}
8885
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008886TEST_F(VkLayerTest, DSBufferInfoErrors) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008887 TEST_DESCRIPTION("Attempt to update buffer descriptor set that has incorrect "
8888 "parameters in VkDescriptorBufferInfo struct. This includes:\n"
8889 "1. offset value greater than buffer size\n"
8890 "2. range value of 0\n"
8891 "3. range value greater than buffer (size - offset)");
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008892 VkResult err;
8893
8894 ASSERT_NO_FATAL_FAILURE(InitState());
8895 VkDescriptorPoolSize ds_type_count = {};
8896 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8897 ds_type_count.descriptorCount = 1;
8898
8899 VkDescriptorPoolCreateInfo ds_pool_ci = {};
8900 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8901 ds_pool_ci.pNext = NULL;
8902 ds_pool_ci.maxSets = 1;
8903 ds_pool_ci.poolSizeCount = 1;
8904 ds_pool_ci.pPoolSizes = &ds_type_count;
8905
8906 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008907 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008908 ASSERT_VK_SUCCESS(err);
8909
8910 // Create layout with single uniform buffer descriptor
8911 VkDescriptorSetLayoutBinding dsl_binding = {};
8912 dsl_binding.binding = 0;
8913 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8914 dsl_binding.descriptorCount = 1;
8915 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8916 dsl_binding.pImmutableSamplers = NULL;
8917
8918 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
8919 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8920 ds_layout_ci.pNext = NULL;
8921 ds_layout_ci.bindingCount = 1;
8922 ds_layout_ci.pBindings = &dsl_binding;
8923 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008924 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008925 ASSERT_VK_SUCCESS(err);
8926
8927 VkDescriptorSet descriptor_set = {};
8928 VkDescriptorSetAllocateInfo alloc_info = {};
8929 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
8930 alloc_info.descriptorSetCount = 1;
8931 alloc_info.descriptorPool = ds_pool;
8932 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008933 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008934 ASSERT_VK_SUCCESS(err);
8935
8936 // Create a buffer to be used for invalid updates
8937 VkBufferCreateInfo buff_ci = {};
8938 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
8939 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
8940 buff_ci.size = 256;
8941 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
8942 VkBuffer buffer;
8943 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
8944 ASSERT_VK_SUCCESS(err);
8945 // Have to bind memory to buffer before descriptor update
8946 VkMemoryAllocateInfo mem_alloc = {};
8947 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
8948 mem_alloc.pNext = NULL;
8949 mem_alloc.allocationSize = 256;
8950 mem_alloc.memoryTypeIndex = 0;
8951
8952 VkMemoryRequirements mem_reqs;
8953 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008954 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008955 if (!pass) {
8956 vkDestroyBuffer(m_device->device(), buffer, NULL);
8957 return;
8958 }
8959
8960 VkDeviceMemory mem;
8961 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
8962 ASSERT_VK_SUCCESS(err);
8963 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
8964 ASSERT_VK_SUCCESS(err);
8965
8966 VkDescriptorBufferInfo buff_info = {};
8967 buff_info.buffer = buffer;
8968 // First make offset 1 larger than buffer size
8969 buff_info.offset = 257;
8970 buff_info.range = VK_WHOLE_SIZE;
8971 VkWriteDescriptorSet descriptor_write = {};
8972 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
8973 descriptor_write.dstBinding = 0;
8974 descriptor_write.descriptorCount = 1;
8975 descriptor_write.pTexelBufferView = nullptr;
8976 descriptor_write.pBufferInfo = &buff_info;
8977 descriptor_write.pImageInfo = nullptr;
8978
8979 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8980 descriptor_write.dstSet = descriptor_set;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008981 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " offset of 257 is greater than buffer ");
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008982
8983 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8984
8985 m_errorMonitor->VerifyFound();
8986 // Now cause error due to range of 0
8987 buff_info.offset = 0;
8988 buff_info.range = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008989 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8990 " range is not VK_WHOLE_SIZE and is zero, which is not allowed.");
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008991
8992 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8993
8994 m_errorMonitor->VerifyFound();
8995 // Now cause error due to range exceeding buffer size - offset
8996 buff_info.offset = 128;
8997 buff_info.range = 200;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008998 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 -06008999
9000 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9001
9002 m_errorMonitor->VerifyFound();
Mark Lobodzinski4bb54092016-07-06 14:27:19 -06009003 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009004 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9005 vkDestroyBuffer(m_device->device(), buffer, NULL);
9006 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
9007 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9008}
9009
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009010TEST_F(VkLayerTest, DSAspectBitsErrors) {
9011 // TODO : Initially only catching case where DEPTH & STENCIL aspect bits
9012 // are set, but could expand this test to hit more cases.
9013 TEST_DESCRIPTION("Attempt to update descriptor sets for images "
9014 "that do not have correct aspect bits sets.");
9015 VkResult err;
9016
9017 ASSERT_NO_FATAL_FAILURE(InitState());
9018 VkDescriptorPoolSize ds_type_count = {};
9019 ds_type_count.type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
9020 ds_type_count.descriptorCount = 1;
9021
9022 VkDescriptorPoolCreateInfo ds_pool_ci = {};
9023 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9024 ds_pool_ci.pNext = NULL;
9025 ds_pool_ci.maxSets = 5;
9026 ds_pool_ci.poolSizeCount = 1;
9027 ds_pool_ci.pPoolSizes = &ds_type_count;
9028
9029 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009030 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009031 ASSERT_VK_SUCCESS(err);
9032
9033 VkDescriptorSetLayoutBinding dsl_binding = {};
9034 dsl_binding.binding = 0;
9035 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
9036 dsl_binding.descriptorCount = 1;
9037 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9038 dsl_binding.pImmutableSamplers = NULL;
9039
9040 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9041 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9042 ds_layout_ci.pNext = NULL;
9043 ds_layout_ci.bindingCount = 1;
9044 ds_layout_ci.pBindings = &dsl_binding;
9045 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009046 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009047 ASSERT_VK_SUCCESS(err);
9048
9049 VkDescriptorSet descriptor_set = {};
9050 VkDescriptorSetAllocateInfo alloc_info = {};
9051 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
9052 alloc_info.descriptorSetCount = 1;
9053 alloc_info.descriptorPool = ds_pool;
9054 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009055 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009056 ASSERT_VK_SUCCESS(err);
9057
9058 // Create an image to be used for invalid updates
9059 VkImageCreateInfo image_ci = {};
9060 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
9061 image_ci.imageType = VK_IMAGE_TYPE_2D;
9062 image_ci.format = VK_FORMAT_D24_UNORM_S8_UINT;
9063 image_ci.extent.width = 64;
9064 image_ci.extent.height = 64;
9065 image_ci.extent.depth = 1;
9066 image_ci.mipLevels = 1;
9067 image_ci.arrayLayers = 1;
9068 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
9069 image_ci.tiling = VK_IMAGE_TILING_LINEAR;
9070 image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
9071 image_ci.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
9072 image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
9073 VkImage image;
9074 err = vkCreateImage(m_device->device(), &image_ci, NULL, &image);
9075 ASSERT_VK_SUCCESS(err);
9076 // Bind memory to image
9077 VkMemoryRequirements mem_reqs;
9078 VkDeviceMemory image_mem;
9079 bool pass;
9080 VkMemoryAllocateInfo mem_alloc = {};
9081 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
9082 mem_alloc.pNext = NULL;
9083 mem_alloc.allocationSize = 0;
9084 mem_alloc.memoryTypeIndex = 0;
9085 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
9086 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009087 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009088 ASSERT_TRUE(pass);
9089 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
9090 ASSERT_VK_SUCCESS(err);
9091 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
9092 ASSERT_VK_SUCCESS(err);
9093 // Now create view for image
9094 VkImageViewCreateInfo image_view_ci = {};
9095 image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
9096 image_view_ci.image = image;
9097 image_view_ci.format = VK_FORMAT_D24_UNORM_S8_UINT;
9098 image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D;
9099 image_view_ci.subresourceRange.layerCount = 1;
9100 image_view_ci.subresourceRange.baseArrayLayer = 0;
9101 image_view_ci.subresourceRange.levelCount = 1;
9102 // Setting both depth & stencil aspect bits is illegal for descriptor
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009103 image_view_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009104
9105 VkImageView image_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009106 err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, &image_view);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009107 ASSERT_VK_SUCCESS(err);
9108
9109 VkDescriptorImageInfo img_info = {};
9110 img_info.imageView = image_view;
9111 VkWriteDescriptorSet descriptor_write = {};
9112 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
9113 descriptor_write.dstBinding = 0;
9114 descriptor_write.descriptorCount = 1;
9115 descriptor_write.pTexelBufferView = NULL;
9116 descriptor_write.pBufferInfo = NULL;
9117 descriptor_write.pImageInfo = &img_info;
9118 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
9119 descriptor_write.dstSet = descriptor_set;
9120 const char *error_msg = " please only set either VK_IMAGE_ASPECT_DEPTH_BIT "
9121 "or VK_IMAGE_ASPECT_STENCIL_BIT ";
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009122 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, error_msg);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009123
9124 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9125
9126 m_errorMonitor->VerifyFound();
9127 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9128 vkDestroyImage(m_device->device(), image, NULL);
9129 vkFreeMemory(m_device->device(), image_mem, NULL);
9130 vkDestroyImageView(m_device->device(), image_view, NULL);
9131 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
9132 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9133}
9134
Karl Schultz6addd812016-02-02 17:17:23 -07009135TEST_F(VkLayerTest, DSTypeMismatch) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009136 // Create DS w/ layout of one type and attempt Update w/ mis-matched type
Karl Schultz6addd812016-02-02 17:17:23 -07009137 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009138
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009139 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9140 " binding #0 with type VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER but update "
9141 "type is VK_DESCRIPTOR_TYPE_SAMPLER");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009142
Tobin Ehlis3b780662015-05-28 12:11:26 -06009143 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07009144 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009145 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009146 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9147 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009148
9149 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009150 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9151 ds_pool_ci.pNext = NULL;
9152 ds_pool_ci.maxSets = 1;
9153 ds_pool_ci.poolSizeCount = 1;
9154 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06009155
Tobin Ehlis3b780662015-05-28 12:11:26 -06009156 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009157 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009158 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -06009159 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009160 dsl_binding.binding = 0;
9161 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9162 dsl_binding.descriptorCount = 1;
9163 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9164 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009165
Tony Barboureb254902015-07-15 12:50:33 -06009166 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009167 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9168 ds_layout_ci.pNext = NULL;
9169 ds_layout_ci.bindingCount = 1;
9170 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06009171
Tobin Ehlis3b780662015-05-28 12:11:26 -06009172 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009173 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009174 ASSERT_VK_SUCCESS(err);
9175
9176 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009177 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009178 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009179 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009180 alloc_info.descriptorPool = ds_pool;
9181 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009182 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009183 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009184
Tobin Ehlis30db8f82016-05-05 08:19:48 -06009185 VkSamplerCreateInfo sampler_ci = {};
9186 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9187 sampler_ci.pNext = NULL;
9188 sampler_ci.magFilter = VK_FILTER_NEAREST;
9189 sampler_ci.minFilter = VK_FILTER_NEAREST;
9190 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9191 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9192 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9193 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9194 sampler_ci.mipLodBias = 1.0;
9195 sampler_ci.anisotropyEnable = VK_FALSE;
9196 sampler_ci.maxAnisotropy = 1;
9197 sampler_ci.compareEnable = VK_FALSE;
9198 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9199 sampler_ci.minLod = 1.0;
9200 sampler_ci.maxLod = 1.0;
9201 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9202 sampler_ci.unnormalizedCoordinates = VK_FALSE;
9203 VkSampler sampler;
9204 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
9205 ASSERT_VK_SUCCESS(err);
9206
9207 VkDescriptorImageInfo info = {};
9208 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009209
9210 VkWriteDescriptorSet descriptor_write;
9211 memset(&descriptor_write, 0, sizeof(descriptor_write));
9212 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009213 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009214 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009215 // This is a mismatched type for the layout which expects BUFFER
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009216 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06009217 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009218
9219 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9220
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009221 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009222
Chia-I Wuf7458c52015-10-26 21:10:41 +08009223 vkDestroySampler(m_device->device(), sampler, NULL);
9224 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9225 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009226}
9227
Karl Schultz6addd812016-02-02 17:17:23 -07009228TEST_F(VkLayerTest, DSUpdateOutOfBounds) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009229 // For overlapping Update, have arrayIndex exceed that of layout
Karl Schultz6addd812016-02-02 17:17:23 -07009230 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009231
Tobin Ehlisf922ef82016-11-30 10:19:14 -07009232 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00938);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009233
Tobin Ehlis3b780662015-05-28 12:11:26 -06009234 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07009235 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009236 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009237 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9238 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009239
9240 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009241 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9242 ds_pool_ci.pNext = NULL;
9243 ds_pool_ci.maxSets = 1;
9244 ds_pool_ci.poolSizeCount = 1;
9245 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06009246
Tobin Ehlis3b780662015-05-28 12:11:26 -06009247 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009248 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009249 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009250
Tony Barboureb254902015-07-15 12:50:33 -06009251 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009252 dsl_binding.binding = 0;
9253 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9254 dsl_binding.descriptorCount = 1;
9255 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9256 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -06009257
9258 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009259 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9260 ds_layout_ci.pNext = NULL;
9261 ds_layout_ci.bindingCount = 1;
9262 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06009263
Tobin Ehlis3b780662015-05-28 12:11:26 -06009264 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009265 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009266 ASSERT_VK_SUCCESS(err);
9267
9268 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009269 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009270 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009271 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009272 alloc_info.descriptorPool = ds_pool;
9273 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009274 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009275 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009276
Tobin Ehlis30db8f82016-05-05 08:19:48 -06009277 // Correctly update descriptor to avoid "NOT_UPDATED" error
9278 VkDescriptorBufferInfo buff_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009279 buff_info.buffer = VkBuffer(0); // Don't care about buffer handle for this test
Tobin Ehlis30db8f82016-05-05 08:19:48 -06009280 buff_info.offset = 0;
9281 buff_info.range = 1024;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009282
9283 VkWriteDescriptorSet descriptor_write;
9284 memset(&descriptor_write, 0, sizeof(descriptor_write));
9285 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009286 descriptor_write.dstSet = descriptorSet;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009287 descriptor_write.dstArrayElement = 1; /* This index out of bounds for the update */
Chia-I Wud50a7d72015-10-26 20:48:51 +08009288 descriptor_write.descriptorCount = 1;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06009289 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9290 descriptor_write.pBufferInfo = &buff_info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009291
9292 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9293
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009294 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009295
Chia-I Wuf7458c52015-10-26 21:10:41 +08009296 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9297 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009298}
9299
Karl Schultz6addd812016-02-02 17:17:23 -07009300TEST_F(VkLayerTest, InvalidDSUpdateIndex) {
Tobin Ehlisc8d352d2016-11-21 10:33:40 -07009301 // Create layout w/ count of 1 and attempt update to that layout w/ binding index 2
Karl Schultz6addd812016-02-02 17:17:23 -07009302 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009303
Tobin Ehlisc8d352d2016-11-21 10:33:40 -07009304 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00936);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009305
Tobin Ehlis3b780662015-05-28 12:11:26 -06009306 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07009307 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009308 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009309 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9310 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009311
9312 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009313 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9314 ds_pool_ci.pNext = NULL;
9315 ds_pool_ci.maxSets = 1;
9316 ds_pool_ci.poolSizeCount = 1;
9317 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06009318
Tobin Ehlis3b780662015-05-28 12:11:26 -06009319 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009320 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009321 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009322
Tony Barboureb254902015-07-15 12:50:33 -06009323 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009324 dsl_binding.binding = 0;
9325 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9326 dsl_binding.descriptorCount = 1;
9327 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9328 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -06009329
9330 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009331 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9332 ds_layout_ci.pNext = NULL;
9333 ds_layout_ci.bindingCount = 1;
9334 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009335 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009336 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009337 ASSERT_VK_SUCCESS(err);
9338
9339 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009340 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009341 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009342 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009343 alloc_info.descriptorPool = ds_pool;
9344 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009345 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009346 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009347
Tony Barboureb254902015-07-15 12:50:33 -06009348 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009349 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9350 sampler_ci.pNext = NULL;
9351 sampler_ci.magFilter = VK_FILTER_NEAREST;
9352 sampler_ci.minFilter = VK_FILTER_NEAREST;
9353 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9354 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9355 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9356 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9357 sampler_ci.mipLodBias = 1.0;
9358 sampler_ci.anisotropyEnable = VK_FALSE;
9359 sampler_ci.maxAnisotropy = 1;
9360 sampler_ci.compareEnable = VK_FALSE;
9361 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9362 sampler_ci.minLod = 1.0;
9363 sampler_ci.maxLod = 1.0;
9364 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9365 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tony Barboureb254902015-07-15 12:50:33 -06009366
Tobin Ehlis3b780662015-05-28 12:11:26 -06009367 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009368 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009369 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009370
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06009371 VkDescriptorImageInfo info = {};
9372 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009373
9374 VkWriteDescriptorSet descriptor_write;
9375 memset(&descriptor_write, 0, sizeof(descriptor_write));
9376 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009377 descriptor_write.dstSet = descriptorSet;
9378 descriptor_write.dstBinding = 2;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009379 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009380 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009381 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06009382 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009383
9384 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9385
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009386 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009387
Chia-I Wuf7458c52015-10-26 21:10:41 +08009388 vkDestroySampler(m_device->device(), sampler, NULL);
9389 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9390 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009391}
9392
Tobin Ehlise202b2d2016-11-21 10:36:16 -07009393TEST_F(VkLayerTest, DSUpdateEmptyBinding) {
9394 // Create layout w/ empty binding and attempt to update it
9395 VkResult err;
9396
9397 ASSERT_NO_FATAL_FAILURE(InitState());
9398
9399 VkDescriptorPoolSize ds_type_count = {};
9400 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
9401 ds_type_count.descriptorCount = 1;
9402
9403 VkDescriptorPoolCreateInfo ds_pool_ci = {};
9404 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9405 ds_pool_ci.pNext = NULL;
9406 ds_pool_ci.maxSets = 1;
9407 ds_pool_ci.poolSizeCount = 1;
9408 ds_pool_ci.pPoolSizes = &ds_type_count;
9409
9410 VkDescriptorPool ds_pool;
9411 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
9412 ASSERT_VK_SUCCESS(err);
9413
9414 VkDescriptorSetLayoutBinding dsl_binding = {};
9415 dsl_binding.binding = 0;
9416 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9417 dsl_binding.descriptorCount = 0;
9418 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9419 dsl_binding.pImmutableSamplers = NULL;
9420
9421 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9422 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9423 ds_layout_ci.pNext = NULL;
9424 ds_layout_ci.bindingCount = 1;
9425 ds_layout_ci.pBindings = &dsl_binding;
9426 VkDescriptorSetLayout ds_layout;
9427 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
9428 ASSERT_VK_SUCCESS(err);
9429
9430 VkDescriptorSet descriptor_set;
9431 VkDescriptorSetAllocateInfo alloc_info = {};
9432 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
9433 alloc_info.descriptorSetCount = 1;
9434 alloc_info.descriptorPool = ds_pool;
9435 alloc_info.pSetLayouts = &ds_layout;
9436 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
9437 ASSERT_VK_SUCCESS(err);
9438
9439 VkSamplerCreateInfo sampler_ci = {};
9440 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9441 sampler_ci.magFilter = VK_FILTER_NEAREST;
9442 sampler_ci.minFilter = VK_FILTER_NEAREST;
9443 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9444 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9445 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9446 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9447 sampler_ci.mipLodBias = 1.0;
9448 sampler_ci.maxAnisotropy = 1;
9449 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9450 sampler_ci.minLod = 1.0;
9451 sampler_ci.maxLod = 1.0;
9452 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9453
9454 VkSampler sampler;
9455 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
9456 ASSERT_VK_SUCCESS(err);
9457
9458 VkDescriptorImageInfo info = {};
9459 info.sampler = sampler;
9460
9461 VkWriteDescriptorSet descriptor_write;
9462 memset(&descriptor_write, 0, sizeof(descriptor_write));
9463 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
9464 descriptor_write.dstSet = descriptor_set;
9465 descriptor_write.dstBinding = 0;
9466 descriptor_write.descriptorCount = 1; // Lie here to avoid parameter_validation error
9467 // This is the wrong type, but empty binding error will be flagged first
9468 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9469 descriptor_write.pImageInfo = &info;
9470
9471 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02348);
9472 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9473 m_errorMonitor->VerifyFound();
9474
9475 vkDestroySampler(m_device->device(), sampler, NULL);
9476 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9477 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9478}
9479
Karl Schultz6addd812016-02-02 17:17:23 -07009480TEST_F(VkLayerTest, InvalidDSUpdateStruct) {
9481 // Call UpdateDS w/ struct type other than valid VK_STRUCTUR_TYPE_UPDATE_*
9482 // types
9483 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009484
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009485 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 -06009486
Tobin Ehlis3b780662015-05-28 12:11:26 -06009487 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski209b5292015-09-17 09:44:05 -06009488
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009489 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009490 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9491 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009492
9493 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009494 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9495 ds_pool_ci.pNext = NULL;
9496 ds_pool_ci.maxSets = 1;
9497 ds_pool_ci.poolSizeCount = 1;
9498 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06009499
Tobin Ehlis3b780662015-05-28 12:11:26 -06009500 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009501 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009502 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -06009503 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009504 dsl_binding.binding = 0;
9505 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9506 dsl_binding.descriptorCount = 1;
9507 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9508 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009509
Tony Barboureb254902015-07-15 12:50:33 -06009510 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009511 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9512 ds_layout_ci.pNext = NULL;
9513 ds_layout_ci.bindingCount = 1;
9514 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06009515
Tobin Ehlis3b780662015-05-28 12:11:26 -06009516 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009517 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009518 ASSERT_VK_SUCCESS(err);
9519
9520 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009521 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009522 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009523 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009524 alloc_info.descriptorPool = ds_pool;
9525 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009526 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009527 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009528
Tony Barboureb254902015-07-15 12:50:33 -06009529 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009530 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9531 sampler_ci.pNext = NULL;
9532 sampler_ci.magFilter = VK_FILTER_NEAREST;
9533 sampler_ci.minFilter = VK_FILTER_NEAREST;
9534 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9535 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9536 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9537 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9538 sampler_ci.mipLodBias = 1.0;
9539 sampler_ci.anisotropyEnable = VK_FALSE;
9540 sampler_ci.maxAnisotropy = 1;
9541 sampler_ci.compareEnable = VK_FALSE;
9542 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9543 sampler_ci.minLod = 1.0;
9544 sampler_ci.maxLod = 1.0;
9545 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9546 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009547 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009548 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009549 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009550
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06009551 VkDescriptorImageInfo info = {};
9552 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009553
9554 VkWriteDescriptorSet descriptor_write;
9555 memset(&descriptor_write, 0, sizeof(descriptor_write));
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009556 descriptor_write.sType = (VkStructureType)0x99999999; /* Intentionally broken struct type */
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009557 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009558 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009559 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009560 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06009561 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009562
9563 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9564
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009565 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009566
Chia-I Wuf7458c52015-10-26 21:10:41 +08009567 vkDestroySampler(m_device->device(), sampler, NULL);
9568 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9569 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009570}
9571
Karl Schultz6addd812016-02-02 17:17:23 -07009572TEST_F(VkLayerTest, SampleDescriptorUpdateError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009573 // Create a single Sampler descriptor and send it an invalid Sampler
Karl Schultz6addd812016-02-02 17:17:23 -07009574 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009575
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009576 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9577 "Attempted write update to sampler descriptor with invalid sampler");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009578
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009579 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07009580 // TODO : Farm Descriptor setup code to helper function(s) to reduce copied
9581 // code
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009582 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009583 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
9584 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009585
9586 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009587 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9588 ds_pool_ci.pNext = NULL;
9589 ds_pool_ci.maxSets = 1;
9590 ds_pool_ci.poolSizeCount = 1;
9591 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009592
9593 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009594 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009595 ASSERT_VK_SUCCESS(err);
9596
9597 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009598 dsl_binding.binding = 0;
9599 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9600 dsl_binding.descriptorCount = 1;
9601 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9602 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009603
9604 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009605 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9606 ds_layout_ci.pNext = NULL;
9607 ds_layout_ci.bindingCount = 1;
9608 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009609 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009610 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009611 ASSERT_VK_SUCCESS(err);
9612
9613 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009614 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009615 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009616 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009617 alloc_info.descriptorPool = ds_pool;
9618 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009619 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009620 ASSERT_VK_SUCCESS(err);
9621
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009622 VkSampler sampler = (VkSampler)((size_t)0xbaadbeef); // Sampler with invalid handle
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009623
9624 VkDescriptorImageInfo descriptor_info;
9625 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
9626 descriptor_info.sampler = sampler;
9627
9628 VkWriteDescriptorSet descriptor_write;
9629 memset(&descriptor_write, 0, sizeof(descriptor_write));
9630 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009631 descriptor_write.dstSet = descriptorSet;
9632 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009633 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009634 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9635 descriptor_write.pImageInfo = &descriptor_info;
9636
9637 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9638
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009639 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009640
Chia-I Wuf7458c52015-10-26 21:10:41 +08009641 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9642 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009643}
9644
Karl Schultz6addd812016-02-02 17:17:23 -07009645TEST_F(VkLayerTest, ImageViewDescriptorUpdateError) {
9646 // Create a single combined Image/Sampler descriptor and send it an invalid
9647 // imageView
9648 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009649
Karl Schultzf78bcdd2016-11-30 12:36:01 -07009650 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00943);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009651
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009652 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009653 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009654 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
9655 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009656
9657 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009658 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9659 ds_pool_ci.pNext = NULL;
9660 ds_pool_ci.maxSets = 1;
9661 ds_pool_ci.poolSizeCount = 1;
9662 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009663
9664 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009665 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009666 ASSERT_VK_SUCCESS(err);
9667
9668 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009669 dsl_binding.binding = 0;
9670 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
9671 dsl_binding.descriptorCount = 1;
9672 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9673 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009674
9675 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009676 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9677 ds_layout_ci.pNext = NULL;
9678 ds_layout_ci.bindingCount = 1;
9679 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009680 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009681 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009682 ASSERT_VK_SUCCESS(err);
9683
9684 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009685 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009686 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009687 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009688 alloc_info.descriptorPool = ds_pool;
9689 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009690 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009691 ASSERT_VK_SUCCESS(err);
9692
9693 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009694 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9695 sampler_ci.pNext = NULL;
9696 sampler_ci.magFilter = VK_FILTER_NEAREST;
9697 sampler_ci.minFilter = VK_FILTER_NEAREST;
9698 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9699 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9700 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9701 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9702 sampler_ci.mipLodBias = 1.0;
9703 sampler_ci.anisotropyEnable = VK_FALSE;
9704 sampler_ci.maxAnisotropy = 1;
9705 sampler_ci.compareEnable = VK_FALSE;
9706 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9707 sampler_ci.minLod = 1.0;
9708 sampler_ci.maxLod = 1.0;
9709 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9710 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009711
9712 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009713 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009714 ASSERT_VK_SUCCESS(err);
9715
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009716 VkImageView view = (VkImageView)((size_t)0xbaadbeef); // invalid imageView object
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009717
9718 VkDescriptorImageInfo descriptor_info;
9719 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
9720 descriptor_info.sampler = sampler;
9721 descriptor_info.imageView = view;
9722
9723 VkWriteDescriptorSet descriptor_write;
9724 memset(&descriptor_write, 0, sizeof(descriptor_write));
9725 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009726 descriptor_write.dstSet = descriptorSet;
9727 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009728 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009729 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
9730 descriptor_write.pImageInfo = &descriptor_info;
9731
9732 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9733
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009734 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009735
Chia-I Wuf7458c52015-10-26 21:10:41 +08009736 vkDestroySampler(m_device->device(), sampler, NULL);
9737 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9738 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009739}
9740
Karl Schultz6addd812016-02-02 17:17:23 -07009741TEST_F(VkLayerTest, CopyDescriptorUpdateErrors) {
9742 // Create DS w/ layout of 2 types, write update 1 and attempt to copy-update
9743 // into the other
9744 VkResult err;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009745
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009746 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " binding #1 with type "
9747 "VK_DESCRIPTOR_TYPE_SAMPLER. Types do "
9748 "not match.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009749
Tobin Ehlis04356f92015-10-27 16:35:27 -06009750 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07009751 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009752 VkDescriptorPoolSize ds_type_count[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009753 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9754 ds_type_count[0].descriptorCount = 1;
9755 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLER;
9756 ds_type_count[1].descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009757
9758 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009759 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9760 ds_pool_ci.pNext = NULL;
9761 ds_pool_ci.maxSets = 1;
9762 ds_pool_ci.poolSizeCount = 2;
9763 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009764
9765 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009766 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis04356f92015-10-27 16:35:27 -06009767 ASSERT_VK_SUCCESS(err);
9768 VkDescriptorSetLayoutBinding dsl_binding[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009769 dsl_binding[0].binding = 0;
9770 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9771 dsl_binding[0].descriptorCount = 1;
9772 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
9773 dsl_binding[0].pImmutableSamplers = NULL;
9774 dsl_binding[1].binding = 1;
9775 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9776 dsl_binding[1].descriptorCount = 1;
9777 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
9778 dsl_binding[1].pImmutableSamplers = NULL;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009779
9780 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009781 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9782 ds_layout_ci.pNext = NULL;
9783 ds_layout_ci.bindingCount = 2;
9784 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009785
9786 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009787 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis04356f92015-10-27 16:35:27 -06009788 ASSERT_VK_SUCCESS(err);
9789
9790 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009791 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009792 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009793 alloc_info.descriptorSetCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009794 alloc_info.descriptorPool = ds_pool;
9795 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009796 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis04356f92015-10-27 16:35:27 -06009797 ASSERT_VK_SUCCESS(err);
9798
9799 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009800 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9801 sampler_ci.pNext = NULL;
9802 sampler_ci.magFilter = VK_FILTER_NEAREST;
9803 sampler_ci.minFilter = VK_FILTER_NEAREST;
9804 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9805 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9806 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9807 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9808 sampler_ci.mipLodBias = 1.0;
9809 sampler_ci.anisotropyEnable = VK_FALSE;
9810 sampler_ci.maxAnisotropy = 1;
9811 sampler_ci.compareEnable = VK_FALSE;
9812 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9813 sampler_ci.minLod = 1.0;
9814 sampler_ci.maxLod = 1.0;
9815 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9816 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009817
9818 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009819 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis04356f92015-10-27 16:35:27 -06009820 ASSERT_VK_SUCCESS(err);
9821
9822 VkDescriptorImageInfo info = {};
9823 info.sampler = sampler;
9824
9825 VkWriteDescriptorSet descriptor_write;
9826 memset(&descriptor_write, 0, sizeof(VkWriteDescriptorSet));
9827 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009828 descriptor_write.dstSet = descriptorSet;
9829 descriptor_write.dstBinding = 1; // SAMPLER binding from layout above
Chia-I Wud50a7d72015-10-26 20:48:51 +08009830 descriptor_write.descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009831 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9832 descriptor_write.pImageInfo = &info;
9833 // This write update should succeed
9834 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9835 // Now perform a copy update that fails due to type mismatch
9836 VkCopyDescriptorSet copy_ds_update;
9837 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
9838 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
9839 copy_ds_update.srcSet = descriptorSet;
Mark Young29927482016-05-04 14:38:51 -06009840 copy_ds_update.srcBinding = 1; // Copy from SAMPLER binding
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009841 copy_ds_update.dstSet = descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -07009842 copy_ds_update.dstBinding = 0; // ERROR : copy to UNIFORM binding
Chia-I Wud50a7d72015-10-26 20:48:51 +08009843 copy_ds_update.descriptorCount = 1; // copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -06009844 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
9845
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009846 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -06009847 // Now perform a copy update that fails due to binding out of bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009848 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 -06009849 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
9850 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
9851 copy_ds_update.srcSet = descriptorSet;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009852 copy_ds_update.srcBinding = 3; // ERROR : Invalid binding for matching layout
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009853 copy_ds_update.dstSet = descriptorSet;
9854 copy_ds_update.dstBinding = 0;
Mark Young29927482016-05-04 14:38:51 -06009855 copy_ds_update.descriptorCount = 1; // Copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -06009856 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
9857
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009858 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009859
Tobin Ehlis04356f92015-10-27 16:35:27 -06009860 // Now perform a copy update that fails due to binding out of bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009861 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " binding#1 with offset index of 1 plus "
9862 "update array offset of 0 and update of "
9863 "5 descriptors oversteps total number "
9864 "of descriptors in set: 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009865
Tobin Ehlis04356f92015-10-27 16:35:27 -06009866 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
9867 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
9868 copy_ds_update.srcSet = descriptorSet;
9869 copy_ds_update.srcBinding = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009870 copy_ds_update.dstSet = descriptorSet;
9871 copy_ds_update.dstBinding = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009872 copy_ds_update.descriptorCount = 5; // ERROR copy 5 descriptors (out of bounds for layout)
Tobin Ehlis04356f92015-10-27 16:35:27 -06009873 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
9874
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009875 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -06009876
Chia-I Wuf7458c52015-10-26 21:10:41 +08009877 vkDestroySampler(m_device->device(), sampler, NULL);
9878 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9879 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis04356f92015-10-27 16:35:27 -06009880}
9881
Karl Schultz6addd812016-02-02 17:17:23 -07009882TEST_F(VkLayerTest, NumSamplesMismatch) {
9883 // Create CommandBuffer where MSAA samples doesn't match RenderPass
9884 // sampleCount
9885 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009886
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009887 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Num samples mismatch! ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009888
Tobin Ehlis3b780662015-05-28 12:11:26 -06009889 ASSERT_NO_FATAL_FAILURE(InitState());
9890 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009891 VkDescriptorPoolSize ds_type_count = {};
Tony Barboureb254902015-07-15 12:50:33 -06009892 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009893 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009894
9895 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009896 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9897 ds_pool_ci.pNext = NULL;
9898 ds_pool_ci.maxSets = 1;
9899 ds_pool_ci.poolSizeCount = 1;
9900 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06009901
Tobin Ehlis3b780662015-05-28 12:11:26 -06009902 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009903 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009904 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009905
Tony Barboureb254902015-07-15 12:50:33 -06009906 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08009907 dsl_binding.binding = 0;
Tony Barboureb254902015-07-15 12:50:33 -06009908 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08009909 dsl_binding.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009910 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9911 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009912
Tony Barboureb254902015-07-15 12:50:33 -06009913 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9914 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9915 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009916 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07009917 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06009918
Tobin Ehlis3b780662015-05-28 12:11:26 -06009919 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009920 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009921 ASSERT_VK_SUCCESS(err);
9922
9923 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009924 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009925 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009926 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009927 alloc_info.descriptorPool = ds_pool;
9928 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009929 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009930 ASSERT_VK_SUCCESS(err);
9931
Tony Barboureb254902015-07-15 12:50:33 -06009932 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009933 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07009934 pipe_ms_state_ci.pNext = NULL;
9935 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
9936 pipe_ms_state_ci.sampleShadingEnable = 0;
9937 pipe_ms_state_ci.minSampleShading = 1.0;
9938 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009939
Tony Barboureb254902015-07-15 12:50:33 -06009940 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009941 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9942 pipeline_layout_ci.pNext = NULL;
9943 pipeline_layout_ci.setLayoutCount = 1;
9944 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009945
9946 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009947 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009948 ASSERT_VK_SUCCESS(err);
9949
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009950 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
9951 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
9952 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -06009953 VkPipelineObj pipe(m_device);
9954 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06009955 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -06009956 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -06009957 pipe.SetMSAA(&pipe_ms_state_ci);
9958 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tobin Ehlis3b780662015-05-28 12:11:26 -06009959
Tony Barbourfe3351b2015-07-28 10:17:20 -06009960 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009961 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis3b780662015-05-28 12:11:26 -06009962
Mark Young29927482016-05-04 14:38:51 -06009963 // Render triangle (the error should trigger on the attempt to draw).
9964 Draw(3, 1, 0, 0);
9965
9966 // Finalize recording of the command buffer
9967 EndCommandBuffer();
9968
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009969 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009970
Chia-I Wuf7458c52015-10-26 21:10:41 +08009971 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9972 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9973 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009974}
Mark Young29927482016-05-04 14:38:51 -06009975
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009976TEST_F(VkLayerTest, RenderPassIncompatible) {
9977 TEST_DESCRIPTION("Hit RenderPass incompatible cases. "
9978 "Initial case is drawing with an active renderpass that's "
Mike Weiblencce7ec72016-10-17 19:33:05 -06009979 "not compatible with the bound pipeline state object's creation renderpass");
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009980 VkResult err;
9981
9982 ASSERT_NO_FATAL_FAILURE(InitState());
9983 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9984
9985 VkDescriptorSetLayoutBinding dsl_binding = {};
9986 dsl_binding.binding = 0;
9987 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9988 dsl_binding.descriptorCount = 1;
9989 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9990 dsl_binding.pImmutableSamplers = NULL;
9991
9992 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9993 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9994 ds_layout_ci.pNext = NULL;
9995 ds_layout_ci.bindingCount = 1;
9996 ds_layout_ci.pBindings = &dsl_binding;
9997
9998 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009999 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010000 ASSERT_VK_SUCCESS(err);
10001
10002 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
10003 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10004 pipeline_layout_ci.pNext = NULL;
10005 pipeline_layout_ci.setLayoutCount = 1;
10006 pipeline_layout_ci.pSetLayouts = &ds_layout;
10007
10008 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010009 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010010 ASSERT_VK_SUCCESS(err);
10011
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010012 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
10013 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
10014 // but add it to be able to run on more devices
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010015 // Create a renderpass that will be incompatible with default renderpass
10016 VkAttachmentReference attach = {};
10017 attach.layout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
10018 VkAttachmentReference color_att = {};
10019 color_att.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
10020 VkSubpassDescription subpass = {};
10021 subpass.inputAttachmentCount = 1;
10022 subpass.pInputAttachments = &attach;
10023 subpass.colorAttachmentCount = 1;
10024 subpass.pColorAttachments = &color_att;
10025 VkRenderPassCreateInfo rpci = {};
10026 rpci.subpassCount = 1;
10027 rpci.pSubpasses = &subpass;
10028 rpci.attachmentCount = 1;
10029 VkAttachmentDescription attach_desc = {};
10030 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
Cody Northropbd16af12016-06-21 09:25:48 -060010031 // Format incompatible with PSO RP color attach format B8G8R8A8_UNORM
10032 attach_desc.format = VK_FORMAT_R8G8B8A8_UNORM;
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010033 rpci.pAttachments = &attach_desc;
10034 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
10035 VkRenderPass rp;
10036 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10037 VkPipelineObj pipe(m_device);
10038 pipe.AddShader(&vs);
10039 pipe.AddShader(&fs);
10040 pipe.AddColorAttachment();
10041 VkViewport view_port = {};
10042 m_viewports.push_back(view_port);
10043 pipe.SetViewport(m_viewports);
10044 VkRect2D rect = {};
10045 m_scissors.push_back(rect);
10046 pipe.SetScissor(m_scissors);
10047 pipe.CreateVKPipeline(pipeline_layout, renderPass());
10048
10049 VkCommandBufferInheritanceInfo cbii = {};
10050 cbii.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
10051 cbii.renderPass = rp;
10052 cbii.subpass = 0;
10053 VkCommandBufferBeginInfo cbbi = {};
10054 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
10055 cbbi.pInheritanceInfo = &cbii;
10056 vkBeginCommandBuffer(m_commandBuffer->handle(), &cbbi);
10057 VkRenderPassBeginInfo rpbi = {};
10058 rpbi.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
10059 rpbi.framebuffer = m_framebuffer;
10060 rpbi.renderPass = rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010061 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
10062 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010063
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010064 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is incompatible w/ gfx pipeline ");
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010065 // Render triangle (the error should trigger on the attempt to draw).
10066 Draw(3, 1, 0, 0);
10067
10068 // Finalize recording of the command buffer
10069 EndCommandBuffer();
10070
10071 m_errorMonitor->VerifyFound();
10072
10073 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10074 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10075 vkDestroyRenderPass(m_device->device(), rp, NULL);
10076}
10077
Mark Youngc89c6312016-03-31 16:03:20 -060010078TEST_F(VkLayerTest, NumBlendAttachMismatch) {
10079 // Create Pipeline where the number of blend attachments doesn't match the
10080 // number of color attachments. In this case, we don't add any color
10081 // blend attachments even though we have a color attachment.
10082 VkResult err;
10083
10084 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010085 "Render pass subpass 0 mismatch with blending state defined and blend state attachment");
Mark Youngc89c6312016-03-31 16:03:20 -060010086
10087 ASSERT_NO_FATAL_FAILURE(InitState());
10088 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10089 VkDescriptorPoolSize ds_type_count = {};
10090 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10091 ds_type_count.descriptorCount = 1;
10092
10093 VkDescriptorPoolCreateInfo ds_pool_ci = {};
10094 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10095 ds_pool_ci.pNext = NULL;
10096 ds_pool_ci.maxSets = 1;
10097 ds_pool_ci.poolSizeCount = 1;
10098 ds_pool_ci.pPoolSizes = &ds_type_count;
10099
10100 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010101 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Mark Youngc89c6312016-03-31 16:03:20 -060010102 ASSERT_VK_SUCCESS(err);
10103
10104 VkDescriptorSetLayoutBinding dsl_binding = {};
10105 dsl_binding.binding = 0;
10106 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10107 dsl_binding.descriptorCount = 1;
10108 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10109 dsl_binding.pImmutableSamplers = NULL;
10110
10111 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10112 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10113 ds_layout_ci.pNext = NULL;
10114 ds_layout_ci.bindingCount = 1;
10115 ds_layout_ci.pBindings = &dsl_binding;
10116
10117 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010118 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Youngc89c6312016-03-31 16:03:20 -060010119 ASSERT_VK_SUCCESS(err);
10120
10121 VkDescriptorSet descriptorSet;
10122 VkDescriptorSetAllocateInfo alloc_info = {};
10123 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
10124 alloc_info.descriptorSetCount = 1;
10125 alloc_info.descriptorPool = ds_pool;
10126 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010127 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Youngc89c6312016-03-31 16:03:20 -060010128 ASSERT_VK_SUCCESS(err);
10129
10130 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010131 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Mark Youngc89c6312016-03-31 16:03:20 -060010132 pipe_ms_state_ci.pNext = NULL;
10133 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
10134 pipe_ms_state_ci.sampleShadingEnable = 0;
10135 pipe_ms_state_ci.minSampleShading = 1.0;
10136 pipe_ms_state_ci.pSampleMask = NULL;
10137
10138 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
10139 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10140 pipeline_layout_ci.pNext = NULL;
10141 pipeline_layout_ci.setLayoutCount = 1;
10142 pipeline_layout_ci.pSetLayouts = &ds_layout;
10143
10144 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010145 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Mark Youngc89c6312016-03-31 16:03:20 -060010146 ASSERT_VK_SUCCESS(err);
10147
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010148 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
10149 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
10150 // but add it to be able to run on more devices
Mark Youngc89c6312016-03-31 16:03:20 -060010151 VkPipelineObj pipe(m_device);
10152 pipe.AddShader(&vs);
10153 pipe.AddShader(&fs);
10154 pipe.SetMSAA(&pipe_ms_state_ci);
10155 pipe.CreateVKPipeline(pipeline_layout, renderPass());
10156
10157 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010158 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Mark Youngc89c6312016-03-31 16:03:20 -060010159
Mark Young29927482016-05-04 14:38:51 -060010160 // Render triangle (the error should trigger on the attempt to draw).
10161 Draw(3, 1, 0, 0);
10162
10163 // Finalize recording of the command buffer
10164 EndCommandBuffer();
10165
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010166 m_errorMonitor->VerifyFound();
Mark Youngc89c6312016-03-31 16:03:20 -060010167
10168 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10169 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10170 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
10171}
Mark Young29927482016-05-04 14:38:51 -060010172
Mark Muellerd4914412016-06-13 17:52:06 -060010173TEST_F(VkLayerTest, MissingClearAttachment) {
10174 TEST_DESCRIPTION("Points to a wrong colorAttachment index in a VkClearAttachment "
10175 "structure passed to vkCmdClearAttachments");
Cody Northropc31a84f2016-08-22 10:41:47 -060010176 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesda6ae6f2016-09-09 14:36:33 +120010177 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbesfa79fc72016-11-01 10:18:12 +130010178 "vkCmdClearAttachments() color attachment index 1 out of range for active subpass 0");
Mark Muellerd4914412016-06-13 17:52:06 -060010179
10180 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailCmdClearAttachments);
10181 m_errorMonitor->VerifyFound();
10182}
10183
Karl Schultz6addd812016-02-02 17:17:23 -070010184TEST_F(VkLayerTest, ClearCmdNoDraw) {
10185 // Create CommandBuffer where we add ClearCmd for FB Color attachment prior
10186 // to issuing a Draw
10187 VkResult err;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010188
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010189 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Mike Weiblencce7ec72016-10-17 19:33:05 -060010190 "vkCmdClearAttachments() issued on command buffer object ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010191
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010192 ASSERT_NO_FATAL_FAILURE(InitState());
10193 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -060010194
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010195 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010196 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10197 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010198
10199 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010200 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10201 ds_pool_ci.pNext = NULL;
10202 ds_pool_ci.maxSets = 1;
10203 ds_pool_ci.poolSizeCount = 1;
10204 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060010205
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010206 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010207 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010208 ASSERT_VK_SUCCESS(err);
10209
Tony Barboureb254902015-07-15 12:50:33 -060010210 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010211 dsl_binding.binding = 0;
10212 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10213 dsl_binding.descriptorCount = 1;
10214 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10215 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010216
Tony Barboureb254902015-07-15 12:50:33 -060010217 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010218 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10219 ds_layout_ci.pNext = NULL;
10220 ds_layout_ci.bindingCount = 1;
10221 ds_layout_ci.pBindings = &dsl_binding;
Mark Lobodzinski209b5292015-09-17 09:44:05 -060010222
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010223 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010224 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010225 ASSERT_VK_SUCCESS(err);
10226
10227 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010228 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010229 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010230 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060010231 alloc_info.descriptorPool = ds_pool;
10232 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010233 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010234 ASSERT_VK_SUCCESS(err);
10235
Tony Barboureb254902015-07-15 12:50:33 -060010236 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010237 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070010238 pipe_ms_state_ci.pNext = NULL;
10239 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
10240 pipe_ms_state_ci.sampleShadingEnable = 0;
10241 pipe_ms_state_ci.minSampleShading = 1.0;
10242 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010243
Tony Barboureb254902015-07-15 12:50:33 -060010244 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010245 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10246 pipeline_layout_ci.pNext = NULL;
10247 pipeline_layout_ci.setLayoutCount = 1;
10248 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010249
10250 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010251 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010252 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski209b5292015-09-17 09:44:05 -060010253
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010254 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -060010255 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -070010256 // on more devices
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010257 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010258
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010259 VkPipelineObj pipe(m_device);
10260 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -060010261 pipe.AddShader(&fs);
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010262 pipe.SetMSAA(&pipe_ms_state_ci);
10263 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -060010264
10265 BeginCommandBuffer();
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010266
Karl Schultz6addd812016-02-02 17:17:23 -070010267 // Main thing we care about for this test is that the VkImage obj we're
10268 // clearing matches Color Attachment of FB
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010269 // Also pass down other dummy params to keep driver and paramchecker happy
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -060010270 VkClearAttachment color_attachment;
10271 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10272 color_attachment.clearValue.color.float32[0] = 1.0;
10273 color_attachment.clearValue.color.float32[1] = 1.0;
10274 color_attachment.clearValue.color.float32[2] = 1.0;
10275 color_attachment.clearValue.color.float32[3] = 1.0;
10276 color_attachment.colorAttachment = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010277 VkClearRect clear_rect = {{{0, 0}, {(uint32_t)m_width, (uint32_t)m_height}}};
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010278
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010279 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010280
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010281 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010282
Chia-I Wuf7458c52015-10-26 21:10:41 +080010283 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10284 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10285 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010286}
10287
Karl Schultz6addd812016-02-02 17:17:23 -070010288TEST_F(VkLayerTest, VtxBufferBadIndex) {
10289 VkResult err;
Tobin Ehlis502480b2015-06-24 15:53:07 -060010290
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010291 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10292 "but no vertex buffers are attached to this Pipeline State Object");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010293
Tobin Ehlis502480b2015-06-24 15:53:07 -060010294 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisd332f282015-10-02 11:00:56 -060010295 ASSERT_NO_FATAL_FAILURE(InitViewport());
Tobin Ehlis502480b2015-06-24 15:53:07 -060010296 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -060010297
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010298 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010299 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10300 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010301
10302 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010303 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10304 ds_pool_ci.pNext = NULL;
10305 ds_pool_ci.maxSets = 1;
10306 ds_pool_ci.poolSizeCount = 1;
10307 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060010308
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -060010309 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010310 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis502480b2015-06-24 15:53:07 -060010311 ASSERT_VK_SUCCESS(err);
10312
Tony Barboureb254902015-07-15 12:50:33 -060010313 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010314 dsl_binding.binding = 0;
10315 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10316 dsl_binding.descriptorCount = 1;
10317 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10318 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -060010319
Tony Barboureb254902015-07-15 12:50:33 -060010320 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010321 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10322 ds_layout_ci.pNext = NULL;
10323 ds_layout_ci.bindingCount = 1;
10324 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060010325
Tobin Ehlis502480b2015-06-24 15:53:07 -060010326 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010327 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -060010328 ASSERT_VK_SUCCESS(err);
10329
10330 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010331 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010332 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010333 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060010334 alloc_info.descriptorPool = ds_pool;
10335 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010336 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis502480b2015-06-24 15:53:07 -060010337 ASSERT_VK_SUCCESS(err);
10338
Tony Barboureb254902015-07-15 12:50:33 -060010339 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010340 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070010341 pipe_ms_state_ci.pNext = NULL;
10342 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
10343 pipe_ms_state_ci.sampleShadingEnable = 0;
10344 pipe_ms_state_ci.minSampleShading = 1.0;
10345 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -060010346
Tony Barboureb254902015-07-15 12:50:33 -060010347 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010348 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10349 pipeline_layout_ci.pNext = NULL;
10350 pipeline_layout_ci.setLayoutCount = 1;
10351 pipeline_layout_ci.pSetLayouts = &ds_layout;
10352 VkPipelineLayout pipeline_layout;
Tobin Ehlis502480b2015-06-24 15:53:07 -060010353
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010354 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -060010355 ASSERT_VK_SUCCESS(err);
10356
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010357 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
10358 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
10359 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010360 VkPipelineObj pipe(m_device);
10361 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -060010362 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -060010363 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010364 pipe.SetMSAA(&pipe_ms_state_ci);
Tobin Ehlisd332f282015-10-02 11:00:56 -060010365 pipe.SetViewport(m_viewports);
10366 pipe.SetScissor(m_scissors);
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010367 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -060010368
10369 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010370 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisf7bf4502015-09-09 15:12:35 -060010371 // Don't care about actual data, just need to get to draw to flag error
10372 static const float vbo_data[3] = {1.f, 0.f, 1.f};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010373 VkConstantBufferObj vbo(m_device, sizeof(vbo_data), sizeof(float), (const void *)&vbo_data);
Tobin Ehlisf7bf4502015-09-09 15:12:35 -060010374 BindVertexBuffer(&vbo, (VkDeviceSize)0, 1); // VBO idx 1, but no VBO in PSO
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -060010375 Draw(1, 0, 0, 0);
Tobin Ehlis502480b2015-06-24 15:53:07 -060010376
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010377 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010378
Chia-I Wuf7458c52015-10-26 21:10:41 +080010379 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10380 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10381 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis502480b2015-06-24 15:53:07 -060010382}
Mark Muellerdfe37552016-07-07 14:47:42 -060010383
Mark Mueller2ee294f2016-08-04 12:59:48 -060010384TEST_F(VkLayerTest, MismatchCountQueueCreateRequestedFeature) {
10385 TEST_DESCRIPTION("Use an invalid count in a vkEnumeratePhysicalDevices call."
10386 "Use invalid Queue Family Index in vkCreateDevice");
Cody Northropc31a84f2016-08-22 10:41:47 -060010387 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Mueller2ee294f2016-08-04 12:59:48 -060010388
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010389 const char *mismatch_count_message = "Call to vkEnumeratePhysicalDevices() "
10390 "w/ pPhysicalDeviceCount value ";
Mark Mueller2ee294f2016-08-04 12:59:48 -060010391
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010392 const char *invalid_queueFamilyIndex_message = "Invalid queue create request in vkCreateDevice(). Invalid "
10393 "queueFamilyIndex ";
Mark Mueller2ee294f2016-08-04 12:59:48 -060010394
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010395 const char *unavailable_feature_message = "While calling vkCreateDevice(), requesting feature #";
Mark Mueller2ee294f2016-08-04 12:59:48 -060010396
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010397 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, mismatch_count_message);
Mark Mueller880fce52016-08-17 15:23:23 -060010398 // The following test fails with recent NVidia drivers.
10399 // By the time core_validation is reached, the NVidia
10400 // driver has sanitized the invalid condition and core_validation
10401 // is not introduced to the failure condition. This is not the case
10402 // with AMD and Mesa drivers. Futher investigation is required
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010403 // uint32_t count = static_cast<uint32_t>(~0);
10404 // VkPhysicalDevice physical_device;
10405 // vkEnumeratePhysicalDevices(instance(), &count, &physical_device);
10406 // m_errorMonitor->VerifyFound();
Mark Mueller2ee294f2016-08-04 12:59:48 -060010407
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010408 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_queueFamilyIndex_message);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010409 float queue_priority = 0.0;
10410
10411 VkDeviceQueueCreateInfo queue_create_info = {};
10412 queue_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
10413 queue_create_info.queueCount = 1;
10414 queue_create_info.pQueuePriorities = &queue_priority;
10415 queue_create_info.queueFamilyIndex = static_cast<uint32_t>(~0);
10416
10417 VkPhysicalDeviceFeatures features = m_device->phy().features();
10418 VkDevice testDevice;
10419 VkDeviceCreateInfo device_create_info = {};
10420 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
10421 device_create_info.queueCreateInfoCount = 1;
10422 device_create_info.pQueueCreateInfos = &queue_create_info;
10423 device_create_info.pEnabledFeatures = &features;
10424 vkCreateDevice(gpu(), &device_create_info, nullptr, &testDevice);
10425 m_errorMonitor->VerifyFound();
10426
10427 queue_create_info.queueFamilyIndex = 1;
10428
10429 unsigned feature_count = sizeof(VkPhysicalDeviceFeatures) / sizeof(VkBool32);
10430 VkBool32 *feature_array = reinterpret_cast<VkBool32 *>(&features);
10431 for (unsigned i = 0; i < feature_count; i++) {
10432 if (VK_FALSE == feature_array[i]) {
10433 feature_array[i] = VK_TRUE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010434 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, unavailable_feature_message);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010435 device_create_info.pEnabledFeatures = &features;
10436 vkCreateDevice(gpu(), &device_create_info, nullptr, &testDevice);
10437 m_errorMonitor->VerifyFound();
10438 break;
10439 }
10440 }
10441}
10442
Tobin Ehlis16edf082016-11-21 12:33:49 -070010443TEST_F(VkLayerTest, InvalidQueryPoolCreate) {
10444 TEST_DESCRIPTION("Attempt to create a query pool for PIPELINE_STATISTICS without enabling pipeline stats for the device.");
10445
10446 ASSERT_NO_FATAL_FAILURE(InitState());
10447
10448 const std::vector<VkQueueFamilyProperties> queue_props = m_device->queue_props;
10449 std::vector<VkDeviceQueueCreateInfo> queue_info;
10450 queue_info.reserve(queue_props.size());
10451 std::vector<std::vector<float>> queue_priorities;
10452 for (uint32_t i = 0; i < (uint32_t)queue_props.size(); i++) {
10453 VkDeviceQueueCreateInfo qi{};
10454 qi.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
10455 qi.queueFamilyIndex = i;
10456 qi.queueCount = queue_props[i].queueCount;
10457 queue_priorities.emplace_back(qi.queueCount, 0.0f);
10458 qi.pQueuePriorities = queue_priorities[i].data();
10459 queue_info.push_back(qi);
10460 }
10461
10462 std::vector<const char *> device_extension_names;
10463
10464 VkDevice local_device;
10465 VkDeviceCreateInfo device_create_info = {};
10466 auto features = m_device->phy().features();
10467 // Intentionally disable pipeline stats
10468 features.pipelineStatisticsQuery = VK_FALSE;
10469 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
10470 device_create_info.pNext = NULL;
10471 device_create_info.queueCreateInfoCount = queue_info.size();
10472 device_create_info.pQueueCreateInfos = queue_info.data();
10473 device_create_info.enabledLayerCount = 0;
10474 device_create_info.ppEnabledLayerNames = NULL;
10475 device_create_info.pEnabledFeatures = &features;
10476 VkResult err = vkCreateDevice(gpu(), &device_create_info, nullptr, &local_device);
10477 ASSERT_VK_SUCCESS(err);
10478
10479 VkQueryPoolCreateInfo qpci{};
10480 qpci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
10481 qpci.queryType = VK_QUERY_TYPE_PIPELINE_STATISTICS;
10482 qpci.queryCount = 1;
10483 VkQueryPool query_pool;
10484
10485 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01006);
10486 vkCreateQueryPool(local_device, &qpci, nullptr, &query_pool);
10487 m_errorMonitor->VerifyFound();
10488
10489 vkDestroyDevice(local_device, nullptr);
10490}
10491
Mark Mueller2ee294f2016-08-04 12:59:48 -060010492TEST_F(VkLayerTest, InvalidQueueIndexInvalidQuery) {
10493 TEST_DESCRIPTION("Use an invalid queue index in a vkCmdWaitEvents call."
10494 "End a command buffer with a query still in progress.");
10495
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010496 const char *invalid_queue_index = "was created with sharingMode of VK_SHARING_MODE_EXCLUSIVE. If one "
10497 "of src- or dstQueueFamilyIndex is VK_QUEUE_FAMILY_IGNORED, both "
10498 "must be.";
Mark Mueller2ee294f2016-08-04 12:59:48 -060010499
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010500 const char *invalid_query = "Ending command buffer with in progress query: queryPool 0x";
Mark Mueller2ee294f2016-08-04 12:59:48 -060010501
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010502 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_queue_index);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010503
10504 ASSERT_NO_FATAL_FAILURE(InitState());
10505
10506 VkEvent event;
10507 VkEventCreateInfo event_create_info{};
10508 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
10509 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
10510
Mark Mueller2ee294f2016-08-04 12:59:48 -060010511 VkQueue queue = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010512 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010513
10514 BeginCommandBuffer();
10515
10516 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010517 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 -060010518 ASSERT_TRUE(image.initialized());
10519 VkImageMemoryBarrier img_barrier = {};
10520 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
10521 img_barrier.pNext = NULL;
10522 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
10523 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
10524 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
10525 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
10526 img_barrier.image = image.handle();
10527 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
Mark Lobodzinski2a74c5c2016-08-17 13:26:28 -060010528
10529 // QueueFamilyIndex must be VK_QUEUE_FAMILY_IGNORED, this verifies
10530 // that layer validation catches the case when it is not.
10531 img_barrier.dstQueueFamilyIndex = 0;
Mark Mueller2ee294f2016-08-04 12:59:48 -060010532 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10533 img_barrier.subresourceRange.baseArrayLayer = 0;
10534 img_barrier.subresourceRange.baseMipLevel = 0;
10535 img_barrier.subresourceRange.layerCount = 1;
10536 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010537 vkCmdWaitEvents(m_commandBuffer->handle(), 1, &event, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0,
10538 nullptr, 0, nullptr, 1, &img_barrier);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010539 m_errorMonitor->VerifyFound();
10540
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010541 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_query);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010542
10543 VkQueryPool query_pool;
10544 VkQueryPoolCreateInfo query_pool_create_info = {};
10545 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
10546 query_pool_create_info.queryType = VK_QUERY_TYPE_OCCLUSION;
10547 query_pool_create_info.queryCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010548 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010549
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010550 vkCmdResetQueryPool(m_commandBuffer->handle(), query_pool, 0 /*startQuery*/, 1 /*queryCount*/);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010551 vkCmdBeginQuery(m_commandBuffer->handle(), query_pool, 0, 0);
10552
10553 vkEndCommandBuffer(m_commandBuffer->handle());
10554 m_errorMonitor->VerifyFound();
10555
10556 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
10557 vkDestroyEvent(m_device->device(), event, nullptr);
10558}
10559
Mark Muellerdfe37552016-07-07 14:47:42 -060010560TEST_F(VkLayerTest, VertexBufferInvalid) {
10561 TEST_DESCRIPTION("Submit a command buffer using deleted vertex buffer, "
10562 "delete a buffer twice, use an invalid offset for each "
10563 "buffer type, and attempt to bind a null buffer");
10564
10565 const char *deleted_buffer_in_command_buffer = "Cannot submit cmd buffer "
10566 "using deleted buffer ";
Mark Muellerdfe37552016-07-07 14:47:42 -060010567 const char *invalid_offset_message = "vkBindBufferMemory(): "
10568 "memoryOffset is 0x";
10569 const char *invalid_storage_buffer_offset_message = "vkBindBufferMemory(): "
10570 "storage memoryOffset "
10571 "is 0x";
10572 const char *invalid_texel_buffer_offset_message = "vkBindBufferMemory(): "
10573 "texel memoryOffset "
10574 "is 0x";
10575 const char *invalid_uniform_buffer_offset_message = "vkBindBufferMemory(): "
10576 "uniform memoryOffset "
10577 "is 0x";
Mark Muellerdfe37552016-07-07 14:47:42 -060010578
10579 ASSERT_NO_FATAL_FAILURE(InitState());
10580 ASSERT_NO_FATAL_FAILURE(InitViewport());
10581 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10582
10583 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010584 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Mark Muellerdfe37552016-07-07 14:47:42 -060010585 pipe_ms_state_ci.pNext = NULL;
10586 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
10587 pipe_ms_state_ci.sampleShadingEnable = 0;
10588 pipe_ms_state_ci.minSampleShading = 1.0;
10589 pipe_ms_state_ci.pSampleMask = nullptr;
10590
10591 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
10592 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10593 VkPipelineLayout pipeline_layout;
10594
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010595 VkResult err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, nullptr, &pipeline_layout);
Mark Muellerdfe37552016-07-07 14:47:42 -060010596 ASSERT_VK_SUCCESS(err);
10597
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010598 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
10599 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Muellerdfe37552016-07-07 14:47:42 -060010600 VkPipelineObj pipe(m_device);
10601 pipe.AddShader(&vs);
10602 pipe.AddShader(&fs);
10603 pipe.AddColorAttachment();
10604 pipe.SetMSAA(&pipe_ms_state_ci);
10605 pipe.SetViewport(m_viewports);
10606 pipe.SetScissor(m_scissors);
10607 pipe.CreateVKPipeline(pipeline_layout, renderPass());
10608
10609 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010610 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Mark Muellerdfe37552016-07-07 14:47:42 -060010611
10612 {
10613 // Create and bind a vertex buffer in a reduced scope, which will cause
10614 // it to be deleted upon leaving this scope
10615 const float vbo_data[3] = {1.f, 0.f, 1.f};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010616 VkVerticesObj draw_verticies(m_device, 1, 1, sizeof(vbo_data), 3, vbo_data);
Mark Muellerdfe37552016-07-07 14:47:42 -060010617 draw_verticies.BindVertexBuffers(m_commandBuffer->handle());
10618 draw_verticies.AddVertexInputToPipe(pipe);
10619 }
10620
10621 Draw(1, 0, 0, 0);
10622
10623 EndCommandBuffer();
10624
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010625 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, deleted_buffer_in_command_buffer);
Mark Muellerdfe37552016-07-07 14:47:42 -060010626 QueueCommandBuffer(false);
10627 m_errorMonitor->VerifyFound();
10628
10629 {
10630 // Create and bind a vertex buffer in a reduced scope, and delete it
10631 // twice, the second through the destructor
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010632 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eDoubleDelete);
Karl Schultzf78bcdd2016-11-30 12:36:01 -070010633 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00680);
Mark Muellerdfe37552016-07-07 14:47:42 -060010634 buffer_test.TestDoubleDestroy();
10635 }
10636 m_errorMonitor->VerifyFound();
10637
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010638 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidMemoryOffset)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060010639 // Create and bind a memory buffer with an invalid offset.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010640 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_offset_message);
10641 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT, VkBufferTest::eInvalidMemoryOffset);
10642 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010643 m_errorMonitor->VerifyFound();
10644 }
10645
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010646 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset,
10647 VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060010648 // Create and bind a memory buffer with an invalid offset again,
10649 // but look for a texel buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010650 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_texel_buffer_offset_message);
10651 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
10652 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010653 m_errorMonitor->VerifyFound();
10654 }
10655
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010656 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060010657 // Create and bind a memory buffer with an invalid offset again, but
10658 // look for a uniform buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010659 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_uniform_buffer_offset_message);
10660 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
10661 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010662 m_errorMonitor->VerifyFound();
10663 }
10664
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010665 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060010666 // Create and bind a memory buffer with an invalid offset again, but
10667 // look for a storage buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010668 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_storage_buffer_offset_message);
10669 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
10670 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010671 m_errorMonitor->VerifyFound();
10672 }
10673
10674 {
10675 // Attempt to bind a null buffer.
Karl Schultzf78bcdd2016-11-30 12:36:01 -070010676 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00799);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010677 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eBindNullBuffer);
10678 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010679 m_errorMonitor->VerifyFound();
10680 }
10681
10682 {
10683 // Attempt to use an invalid handle to delete a buffer.
Karl Schultzf78bcdd2016-11-30 12:36:01 -070010684 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00622);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010685 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eFreeInvalidHandle);
10686 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010687 }
10688 m_errorMonitor->VerifyFound();
10689
10690 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10691}
10692
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010693// INVALID_IMAGE_LAYOUT tests (one other case is hit by MapMemWithoutHostVisibleBit and not here)
10694TEST_F(VkLayerTest, InvalidImageLayout) {
10695 TEST_DESCRIPTION("Hit all possible validation checks associated with the "
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010696 "DRAWSTATE_INVALID_IMAGE_LAYOUT enum. Generally these involve having"
10697 "images in the wrong layout when they're copied or transitioned.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010698 // 3 in ValidateCmdBufImageLayouts
10699 // * -1 Attempt to submit cmd buf w/ deleted image
10700 // * -2 Cmd buf submit of image w/ layout not matching first use w/ subresource
10701 // * -3 Cmd buf submit of image w/ layout not matching first use w/o subresource
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010702
10703 ASSERT_NO_FATAL_FAILURE(InitState());
10704 // Create src & dst images to use for copy operations
10705 VkImage src_image;
10706 VkImage dst_image;
Cort3b021012016-12-07 12:00:57 -080010707 VkImage depth_image;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010708
10709 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
10710 const int32_t tex_width = 32;
10711 const int32_t tex_height = 32;
10712
10713 VkImageCreateInfo image_create_info = {};
10714 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
10715 image_create_info.pNext = NULL;
10716 image_create_info.imageType = VK_IMAGE_TYPE_2D;
10717 image_create_info.format = tex_format;
10718 image_create_info.extent.width = tex_width;
10719 image_create_info.extent.height = tex_height;
10720 image_create_info.extent.depth = 1;
10721 image_create_info.mipLevels = 1;
10722 image_create_info.arrayLayers = 4;
10723 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
10724 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
10725 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Cort3b021012016-12-07 12:00:57 -080010726 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010727 image_create_info.flags = 0;
10728
10729 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &src_image);
10730 ASSERT_VK_SUCCESS(err);
Cort3b021012016-12-07 12:00:57 -080010731 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010732 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dst_image);
10733 ASSERT_VK_SUCCESS(err);
Cort3b021012016-12-07 12:00:57 -080010734 image_create_info.format = VK_FORMAT_D32_SFLOAT;
10735 image_create_info.usage |= VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
10736 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &depth_image);
10737 ASSERT_VK_SUCCESS(err);
10738
10739 // Allocate memory
10740 VkMemoryRequirements img_mem_reqs = {};
Cort530cf382016-12-08 09:59:47 -080010741 VkMemoryAllocateInfo mem_alloc = {};
Cort3b021012016-12-07 12:00:57 -080010742 VkDeviceMemory src_image_mem, dst_image_mem, depth_image_mem;
Cort530cf382016-12-08 09:59:47 -080010743 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
10744 mem_alloc.pNext = NULL;
10745 mem_alloc.allocationSize = 0;
10746 mem_alloc.memoryTypeIndex = 0;
Cort3b021012016-12-07 12:00:57 -080010747
10748 vkGetImageMemoryRequirements(m_device->device(), src_image, &img_mem_reqs);
Cort530cf382016-12-08 09:59:47 -080010749 mem_alloc.allocationSize = img_mem_reqs.size;
10750 bool pass = m_device->phy().set_memory_type(img_mem_reqs.memoryTypeBits, &mem_alloc, 0);
Cort3b021012016-12-07 12:00:57 -080010751 ASSERT_TRUE(pass);
Cort530cf382016-12-08 09:59:47 -080010752 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &src_image_mem);
Cort3b021012016-12-07 12:00:57 -080010753 ASSERT_VK_SUCCESS(err);
10754
10755 vkGetImageMemoryRequirements(m_device->device(), dst_image, &img_mem_reqs);
Cort530cf382016-12-08 09:59:47 -080010756 mem_alloc.allocationSize = img_mem_reqs.size;
10757 pass = m_device->phy().set_memory_type(img_mem_reqs.memoryTypeBits, &mem_alloc, 0);
Cort3b021012016-12-07 12:00:57 -080010758 ASSERT_VK_SUCCESS(err);
Cort530cf382016-12-08 09:59:47 -080010759 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &dst_image_mem);
Cort3b021012016-12-07 12:00:57 -080010760 ASSERT_VK_SUCCESS(err);
10761
10762 vkGetImageMemoryRequirements(m_device->device(), depth_image, &img_mem_reqs);
Cort530cf382016-12-08 09:59:47 -080010763 mem_alloc.allocationSize = img_mem_reqs.size;
10764 pass = m_device->phy().set_memory_type(img_mem_reqs.memoryTypeBits, &mem_alloc, 0);
Cort3b021012016-12-07 12:00:57 -080010765 ASSERT_VK_SUCCESS(err);
Cort530cf382016-12-08 09:59:47 -080010766 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &depth_image_mem);
Cort3b021012016-12-07 12:00:57 -080010767 ASSERT_VK_SUCCESS(err);
10768
10769 err = vkBindImageMemory(m_device->device(), src_image, src_image_mem, 0);
10770 ASSERT_VK_SUCCESS(err);
10771 err = vkBindImageMemory(m_device->device(), dst_image, dst_image_mem, 0);
10772 ASSERT_VK_SUCCESS(err);
10773 err = vkBindImageMemory(m_device->device(), depth_image, depth_image_mem, 0);
10774 ASSERT_VK_SUCCESS(err);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010775
10776 BeginCommandBuffer();
Cort530cf382016-12-08 09:59:47 -080010777 VkImageCopy copy_region;
10778 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10779 copy_region.srcSubresource.mipLevel = 0;
10780 copy_region.srcSubresource.baseArrayLayer = 0;
10781 copy_region.srcSubresource.layerCount = 1;
10782 copy_region.srcOffset.x = 0;
10783 copy_region.srcOffset.y = 0;
10784 copy_region.srcOffset.z = 0;
10785 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10786 copy_region.dstSubresource.mipLevel = 0;
10787 copy_region.dstSubresource.baseArrayLayer = 0;
10788 copy_region.dstSubresource.layerCount = 1;
10789 copy_region.dstOffset.x = 0;
10790 copy_region.dstOffset.y = 0;
10791 copy_region.dstOffset.z = 0;
10792 copy_region.extent.width = 1;
10793 copy_region.extent.height = 1;
10794 copy_region.extent.depth = 1;
10795
10796 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10797 "Layout for input image should be TRANSFER_SRC_OPTIMAL instead of GENERAL.");
10798 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 -060010799 m_errorMonitor->VerifyFound();
10800 // Now cause error due to src image layout changing
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010801 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot copy from an image whose source layout is "
10802 "VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current "
10803 "layout VK_IMAGE_LAYOUT_GENERAL.");
Cort530cf382016-12-08 09:59:47 -080010804 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 -060010805 m_errorMonitor->VerifyFound();
10806 // Final src error is due to bad layout type
10807 m_errorMonitor->SetDesiredFailureMsg(
10808 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10809 "Layout for input image is VK_IMAGE_LAYOUT_UNDEFINED but can only be TRANSFER_SRC_OPTIMAL or GENERAL.");
Cort530cf382016-12-08 09:59:47 -080010810 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 -060010811 m_errorMonitor->VerifyFound();
10812 // Now verify same checks for dst
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010813 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10814 "Layout for output image should be TRANSFER_DST_OPTIMAL instead of GENERAL.");
Cort530cf382016-12-08 09:59:47 -080010815 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 -060010816 m_errorMonitor->VerifyFound();
10817 // Now cause error due to src image layout changing
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010818 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot copy from an image whose dest layout is "
10819 "VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current "
10820 "layout VK_IMAGE_LAYOUT_GENERAL.");
Cort530cf382016-12-08 09:59:47 -080010821 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 -060010822 m_errorMonitor->VerifyFound();
10823 m_errorMonitor->SetDesiredFailureMsg(
10824 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10825 "Layout for output image is VK_IMAGE_LAYOUT_UNDEFINED but can only be TRANSFER_DST_OPTIMAL or GENERAL.");
Cort530cf382016-12-08 09:59:47 -080010826 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 -060010827 m_errorMonitor->VerifyFound();
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010010828
Cort3b021012016-12-07 12:00:57 -080010829 // Convert dst and depth images to TRANSFER_DST for subsequent tests
10830 VkImageMemoryBarrier transfer_dst_image_barrier[1] = {};
10831 transfer_dst_image_barrier[0].sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
10832 transfer_dst_image_barrier[0].oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
10833 transfer_dst_image_barrier[0].newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
10834 transfer_dst_image_barrier[0].srcAccessMask = 0;
10835 transfer_dst_image_barrier[0].dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
10836 transfer_dst_image_barrier[0].image = dst_image;
10837 transfer_dst_image_barrier[0].subresourceRange.layerCount = image_create_info.arrayLayers;
10838 transfer_dst_image_barrier[0].subresourceRange.levelCount = image_create_info.mipLevels;
10839 transfer_dst_image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10840 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
10841 NULL, 0, NULL, 1, transfer_dst_image_barrier);
10842 transfer_dst_image_barrier[0].image = depth_image;
10843 transfer_dst_image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
10844 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
10845 NULL, 0, NULL, 1, transfer_dst_image_barrier);
10846
10847 // Cause errors due to clearing with invalid image layouts
Cort530cf382016-12-08 09:59:47 -080010848 VkClearColorValue color_clear_value = {};
10849 VkImageSubresourceRange clear_range;
10850 clear_range.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10851 clear_range.baseMipLevel = 0;
10852 clear_range.baseArrayLayer = 0;
10853 clear_range.layerCount = 1;
10854 clear_range.levelCount = 1;
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010010855
Cort3b021012016-12-07 12:00:57 -080010856 // Fail due to explicitly prohibited layout for color clear (only GENERAL and TRANSFER_DST are permitted).
10857 // Since the image is currently not in UNDEFINED layout, this will emit two errors.
10858 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01086);
10859 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01085);
Cort530cf382016-12-08 09:59:47 -080010860 m_commandBuffer->ClearColorImage(dst_image, VK_IMAGE_LAYOUT_UNDEFINED, &color_clear_value, 1, &clear_range);
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010010861 m_errorMonitor->VerifyFound();
Cort3b021012016-12-07 12:00:57 -080010862 // Fail due to provided layout not matching actual current layout for color clear.
10863 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01085);
Cort530cf382016-12-08 09:59:47 -080010864 m_commandBuffer->ClearColorImage(dst_image, VK_IMAGE_LAYOUT_GENERAL, &color_clear_value, 1, &clear_range);
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010010865 m_errorMonitor->VerifyFound();
Cort3b021012016-12-07 12:00:57 -080010866
Cort530cf382016-12-08 09:59:47 -080010867 VkClearDepthStencilValue depth_clear_value = {};
10868 clear_range.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
Cort3b021012016-12-07 12:00:57 -080010869
10870 // Fail due to explicitly prohibited layout for depth clear (only GENERAL and TRANSFER_DST are permitted).
10871 // Since the image is currently not in UNDEFINED layout, this will emit two errors.
10872 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01101);
10873 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01100);
Cort530cf382016-12-08 09:59:47 -080010874 m_commandBuffer->ClearDepthStencilImage(depth_image, VK_IMAGE_LAYOUT_UNDEFINED, &depth_clear_value, 1, &clear_range);
Cort3b021012016-12-07 12:00:57 -080010875 m_errorMonitor->VerifyFound();
10876 // Fail due to provided layout not matching actual current layout for depth clear.
10877 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01100);
Cort530cf382016-12-08 09:59:47 -080010878 m_commandBuffer->ClearDepthStencilImage(depth_image, VK_IMAGE_LAYOUT_GENERAL, &depth_clear_value, 1, &clear_range);
Cort3b021012016-12-07 12:00:57 -080010879 m_errorMonitor->VerifyFound();
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010010880
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010881 // Now cause error due to bad image layout transition in PipelineBarrier
10882 VkImageMemoryBarrier image_barrier[1] = {};
Cort3b021012016-12-07 12:00:57 -080010883 image_barrier[0].sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010884 image_barrier[0].oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
Cort3b021012016-12-07 12:00:57 -080010885 image_barrier[0].newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010886 image_barrier[0].image = src_image;
Cort3b021012016-12-07 12:00:57 -080010887 image_barrier[0].subresourceRange.layerCount = image_create_info.arrayLayers;
10888 image_barrier[0].subresourceRange.levelCount = image_create_info.mipLevels;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010889 image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010890 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "You cannot transition the layout from "
10891 "VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL when "
10892 "current layout is VK_IMAGE_LAYOUT_GENERAL.");
10893 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
10894 NULL, 0, NULL, 1, image_barrier);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010895 m_errorMonitor->VerifyFound();
10896
10897 // Finally some layout errors at RenderPass create time
10898 // Just hacking in specific state to get to the errors we want so don't copy this unless you know what you're doing.
10899 VkAttachmentReference attach = {};
10900 // perf warning for GENERAL layout w/ non-DS input attachment
10901 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
10902 VkSubpassDescription subpass = {};
10903 subpass.inputAttachmentCount = 1;
10904 subpass.pInputAttachments = &attach;
10905 VkRenderPassCreateInfo rpci = {};
10906 rpci.subpassCount = 1;
10907 rpci.pSubpasses = &subpass;
10908 rpci.attachmentCount = 1;
10909 VkAttachmentDescription attach_desc = {};
10910 attach_desc.format = VK_FORMAT_UNDEFINED;
10911 rpci.pAttachments = &attach_desc;
Tobin Ehlis1efce022016-05-11 10:40:34 -060010912 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010913 VkRenderPass rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010914 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10915 "Layout for input attachment is GENERAL but should be READ_ONLY_OPTIMAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010916 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10917 m_errorMonitor->VerifyFound();
10918 // error w/ non-general layout
10919 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
10920
10921 m_errorMonitor->SetDesiredFailureMsg(
10922 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10923 "Layout for input attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be READ_ONLY_OPTIMAL or GENERAL.");
10924 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10925 m_errorMonitor->VerifyFound();
10926 subpass.inputAttachmentCount = 0;
10927 subpass.colorAttachmentCount = 1;
10928 subpass.pColorAttachments = &attach;
10929 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
10930 // perf warning for GENERAL layout on color attachment
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010931 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10932 "Layout for color attachment is GENERAL but should be COLOR_ATTACHMENT_OPTIMAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010933 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10934 m_errorMonitor->VerifyFound();
10935 // error w/ non-color opt or GENERAL layout for color attachment
10936 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
10937 m_errorMonitor->SetDesiredFailureMsg(
10938 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10939 "Layout for color attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be COLOR_ATTACHMENT_OPTIMAL or GENERAL.");
10940 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10941 m_errorMonitor->VerifyFound();
10942 subpass.colorAttachmentCount = 0;
10943 subpass.pDepthStencilAttachment = &attach;
10944 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
10945 // perf warning for GENERAL layout on DS attachment
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010946 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10947 "GENERAL layout for depth attachment may not give optimal performance.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010948 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10949 m_errorMonitor->VerifyFound();
10950 // error w/ non-ds opt or GENERAL layout for color attachment
10951 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010952 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10953 "Layout for depth attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be "
10954 "DEPTH_STENCIL_ATTACHMENT_OPTIMAL, DEPTH_STENCIL_READ_ONLY_OPTIMAL or GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010955 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10956 m_errorMonitor->VerifyFound();
Tobin Ehlis1efce022016-05-11 10:40:34 -060010957 // For this error we need a valid renderpass so create default one
10958 attach.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
10959 attach.attachment = 0;
10960 attach_desc.format = VK_FORMAT_D24_UNORM_S8_UINT;
10961 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
10962 attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
10963 attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
10964 attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
10965 // Can't do a CLEAR load on READ_ONLY initialLayout
10966 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
10967 attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
10968 attach_desc.finalLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010969 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " with invalid first layout "
10970 "VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_"
10971 "ONLY_OPTIMAL");
Tobin Ehlis1efce022016-05-11 10:40:34 -060010972 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10973 m_errorMonitor->VerifyFound();
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010974
Cort3b021012016-12-07 12:00:57 -080010975 vkFreeMemory(m_device->device(), src_image_mem, NULL);
10976 vkFreeMemory(m_device->device(), dst_image_mem, NULL);
10977 vkFreeMemory(m_device->device(), depth_image_mem, NULL);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010978 vkDestroyImage(m_device->device(), src_image, NULL);
10979 vkDestroyImage(m_device->device(), dst_image, NULL);
Cort3b021012016-12-07 12:00:57 -080010980 vkDestroyImage(m_device->device(), depth_image, NULL);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010981}
Tobin Ehlisd8d89182016-07-18 20:13:11 -060010982
Tobin Ehlise0936662016-10-11 08:10:51 -060010983TEST_F(VkLayerTest, InvalidStorageImageLayout) {
10984 TEST_DESCRIPTION("Attempt to update a STORAGE_IMAGE descriptor w/o GENERAL layout.");
10985 VkResult err;
10986
10987 ASSERT_NO_FATAL_FAILURE(InitState());
10988
10989 const VkFormat tex_format = VK_FORMAT_R8G8B8A8_UNORM;
10990 VkImageTiling tiling;
10991 VkFormatProperties format_properties;
10992 vkGetPhysicalDeviceFormatProperties(gpu(), tex_format, &format_properties);
10993 if (format_properties.linearTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
10994 tiling = VK_IMAGE_TILING_LINEAR;
10995 } else if (format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
10996 tiling = VK_IMAGE_TILING_OPTIMAL;
10997 } else {
10998 printf("Device does not support VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT; "
10999 "skipped.\n");
11000 return;
11001 }
11002
11003 VkDescriptorPoolSize ds_type = {};
11004 ds_type.type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
11005 ds_type.descriptorCount = 1;
11006
11007 VkDescriptorPoolCreateInfo ds_pool_ci = {};
11008 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11009 ds_pool_ci.maxSets = 1;
11010 ds_pool_ci.poolSizeCount = 1;
11011 ds_pool_ci.pPoolSizes = &ds_type;
11012 ds_pool_ci.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
11013
11014 VkDescriptorPool ds_pool;
11015 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
11016 ASSERT_VK_SUCCESS(err);
11017
11018 VkDescriptorSetLayoutBinding dsl_binding = {};
11019 dsl_binding.binding = 0;
11020 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
11021 dsl_binding.descriptorCount = 1;
11022 dsl_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
11023 dsl_binding.pImmutableSamplers = NULL;
11024
11025 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11026 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11027 ds_layout_ci.pNext = NULL;
11028 ds_layout_ci.bindingCount = 1;
11029 ds_layout_ci.pBindings = &dsl_binding;
11030
11031 VkDescriptorSetLayout ds_layout;
11032 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
11033 ASSERT_VK_SUCCESS(err);
11034
11035 VkDescriptorSetAllocateInfo alloc_info = {};
11036 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11037 alloc_info.descriptorSetCount = 1;
11038 alloc_info.descriptorPool = ds_pool;
11039 alloc_info.pSetLayouts = &ds_layout;
11040 VkDescriptorSet descriptor_set;
11041 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
11042 ASSERT_VK_SUCCESS(err);
11043
11044 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11045 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11046 pipeline_layout_ci.pNext = NULL;
11047 pipeline_layout_ci.setLayoutCount = 1;
11048 pipeline_layout_ci.pSetLayouts = &ds_layout;
11049 VkPipelineLayout pipeline_layout;
11050 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
11051 ASSERT_VK_SUCCESS(err);
11052
11053 VkImageObj image(m_device);
11054 image.init(32, 32, tex_format, VK_IMAGE_USAGE_STORAGE_BIT, tiling, 0);
11055 ASSERT_TRUE(image.initialized());
11056 VkImageView view = image.targetView(tex_format);
11057
11058 VkDescriptorImageInfo image_info = {};
11059 image_info.imageView = view;
11060 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
11061
11062 VkWriteDescriptorSet descriptor_write = {};
11063 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
11064 descriptor_write.dstSet = descriptor_set;
11065 descriptor_write.dstBinding = 0;
11066 descriptor_write.descriptorCount = 1;
11067 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
11068 descriptor_write.pImageInfo = &image_info;
11069
11070 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11071 " of VK_DESCRIPTOR_TYPE_STORAGE_IMAGE type is being updated with layout "
11072 "VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL but according to spec ");
11073 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11074 m_errorMonitor->VerifyFound();
11075
11076 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11077 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11078 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
11079 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
11080}
11081
Mark Mueller93b938f2016-08-18 10:27:40 -060011082TEST_F(VkLayerTest, SimultaneousUse) {
11083 TEST_DESCRIPTION("Use vkCmdExecuteCommands with invalid state "
11084 "in primary and secondary command buffers.");
11085
11086 ASSERT_NO_FATAL_FAILURE(InitState());
11087 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11088
Mike Weiblen95dd0f92016-10-19 12:28:27 -060011089 const char *simultaneous_use_message1 = "without VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set!";
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011090 const char *simultaneous_use_message2 = "does not have VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set and "
11091 "will cause primary command buffer";
Mark Mueller93b938f2016-08-18 10:27:40 -060011092
11093 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011094 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Mueller93b938f2016-08-18 10:27:40 -060011095 command_buffer_allocate_info.commandPool = m_commandPool;
11096 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
11097 command_buffer_allocate_info.commandBufferCount = 1;
11098
11099 VkCommandBuffer secondary_command_buffer;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011100 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer));
Mark Mueller93b938f2016-08-18 10:27:40 -060011101 VkCommandBufferBeginInfo command_buffer_begin_info = {};
11102 VkCommandBufferInheritanceInfo command_buffer_inheritance_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011103 command_buffer_inheritance_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
Mark Mueller93b938f2016-08-18 10:27:40 -060011104 command_buffer_inheritance_info.renderPass = m_renderPass;
11105 command_buffer_inheritance_info.framebuffer = m_framebuffer;
11106 command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011107 command_buffer_begin_info.flags =
11108 VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT | VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT;
Mark Mueller93b938f2016-08-18 10:27:40 -060011109 command_buffer_begin_info.pInheritanceInfo = &command_buffer_inheritance_info;
11110
11111 vkBeginCommandBuffer(secondary_command_buffer, &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011112 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
11113 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller4042b652016-09-05 22:52:21 -060011114 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
Mark Mueller93b938f2016-08-18 10:27:40 -060011115 vkEndCommandBuffer(secondary_command_buffer);
11116
Mark Mueller93b938f2016-08-18 10:27:40 -060011117 VkSubmitInfo submit_info = {};
11118 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11119 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011120 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Mueller4042b652016-09-05 22:52:21 -060011121 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Mueller93b938f2016-08-18 10:27:40 -060011122
Mark Mueller4042b652016-09-05 22:52:21 -060011123 vkBeginCommandBuffer(m_commandBuffer->handle(), &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011124 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
11125 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, simultaneous_use_message1);
11126 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller93b938f2016-08-18 10:27:40 -060011127 m_errorMonitor->VerifyFound();
Mark Mueller4042b652016-09-05 22:52:21 -060011128 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
11129 vkEndCommandBuffer(m_commandBuffer->handle());
Mark Mueller93b938f2016-08-18 10:27:40 -060011130
11131 m_errorMonitor->SetDesiredFailureMsg(0, "");
Mark Mueller93b938f2016-08-18 10:27:40 -060011132 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11133
Mark Mueller4042b652016-09-05 22:52:21 -060011134 command_buffer_begin_info.flags = VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT;
Mark Mueller93b938f2016-08-18 10:27:40 -060011135 vkBeginCommandBuffer(m_commandBuffer->handle(), &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011136 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
Mark Mueller4042b652016-09-05 22:52:21 -060011137
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011138 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, simultaneous_use_message2);
11139 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller93b938f2016-08-18 10:27:40 -060011140 m_errorMonitor->VerifyFound();
Mark Mueller4042b652016-09-05 22:52:21 -060011141 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
11142 vkEndCommandBuffer(m_commandBuffer->handle());
Mark Mueller93b938f2016-08-18 10:27:40 -060011143}
11144
Mark Mueller917f6bc2016-08-30 10:57:19 -060011145TEST_F(VkLayerTest, InUseDestroyedSignaled) {
11146 TEST_DESCRIPTION("Use vkCmdExecuteCommands with invalid state "
11147 "in primary and secondary command buffers. "
Mark Muellerc8d441e2016-08-23 17:36:00 -060011148 "Delete objects that are inuse. Call VkQueueSubmit "
11149 "with an event that has been deleted.");
Mark Mueller917f6bc2016-08-30 10:57:19 -060011150
11151 ASSERT_NO_FATAL_FAILURE(InitState());
11152 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11153
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011154 const char *submit_with_deleted_event_message = "Cannot submit cmd buffer using deleted event 0x";
11155 const char *cannot_delete_event_message = "Cannot delete event 0x";
11156 const char *cannot_delete_semaphore_message = "Cannot delete semaphore 0x";
11157 const char *cannot_destroy_fence_message = "Fence 0x";
Mark Mueller917f6bc2016-08-30 10:57:19 -060011158
11159 BeginCommandBuffer();
11160
11161 VkEvent event;
11162 VkEventCreateInfo event_create_info = {};
11163 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
11164 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011165 vkCmdSetEvent(m_commandBuffer->handle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Mark Mueller917f6bc2016-08-30 10:57:19 -060011166
Mark Muellerc8d441e2016-08-23 17:36:00 -060011167 EndCommandBuffer();
11168 vkDestroyEvent(m_device->device(), event, nullptr);
11169
11170 VkSubmitInfo submit_info = {};
11171 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11172 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011173 submit_info.pCommandBuffers = &m_commandBuffer->handle();
11174 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, submit_with_deleted_event_message);
Mark Muellerc8d441e2016-08-23 17:36:00 -060011175 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11176 m_errorMonitor->VerifyFound();
11177
11178 m_errorMonitor->SetDesiredFailureMsg(0, "");
11179 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
11180
11181 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
11182
Mark Mueller917f6bc2016-08-30 10:57:19 -060011183 VkSemaphoreCreateInfo semaphore_create_info = {};
11184 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
11185 VkSemaphore semaphore;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011186 ASSERT_VK_SUCCESS(vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore));
Mark Mueller917f6bc2016-08-30 10:57:19 -060011187 VkFenceCreateInfo fence_create_info = {};
11188 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
11189 VkFence fence;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011190 ASSERT_VK_SUCCESS(vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence));
Mark Mueller917f6bc2016-08-30 10:57:19 -060011191
11192 VkDescriptorPoolSize descriptor_pool_type_count = {};
Mark Mueller4042b652016-09-05 22:52:21 -060011193 descriptor_pool_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Mark Mueller917f6bc2016-08-30 10:57:19 -060011194 descriptor_pool_type_count.descriptorCount = 1;
11195
11196 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
11197 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11198 descriptor_pool_create_info.maxSets = 1;
11199 descriptor_pool_create_info.poolSizeCount = 1;
11200 descriptor_pool_create_info.pPoolSizes = &descriptor_pool_type_count;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011201 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
Mark Mueller917f6bc2016-08-30 10:57:19 -060011202
11203 VkDescriptorPool descriptorset_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011204 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
Mark Mueller917f6bc2016-08-30 10:57:19 -060011205
11206 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
Mark Mueller4042b652016-09-05 22:52:21 -060011207 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Mark Mueller917f6bc2016-08-30 10:57:19 -060011208 descriptorset_layout_binding.descriptorCount = 1;
11209 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_ALL;
11210
11211 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011212 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060011213 descriptorset_layout_create_info.bindingCount = 1;
11214 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
11215
11216 VkDescriptorSetLayout descriptorset_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011217 ASSERT_VK_SUCCESS(
11218 vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
Mark Mueller917f6bc2016-08-30 10:57:19 -060011219
11220 VkDescriptorSet descriptorset;
11221 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011222 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060011223 descriptorset_allocate_info.descriptorSetCount = 1;
11224 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
11225 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011226 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
Mark Mueller917f6bc2016-08-30 10:57:19 -060011227
Mark Mueller4042b652016-09-05 22:52:21 -060011228 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
11229
11230 VkDescriptorBufferInfo buffer_info = {};
11231 buffer_info.buffer = buffer_test.GetBuffer();
11232 buffer_info.offset = 0;
11233 buffer_info.range = 1024;
11234
11235 VkWriteDescriptorSet write_descriptor_set = {};
11236 write_descriptor_set.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
11237 write_descriptor_set.dstSet = descriptorset;
11238 write_descriptor_set.descriptorCount = 1;
11239 write_descriptor_set.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11240 write_descriptor_set.pBufferInfo = &buffer_info;
11241
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011242 vkUpdateDescriptorSets(m_device->device(), 1, &write_descriptor_set, 0, nullptr);
Mark Mueller4042b652016-09-05 22:52:21 -060011243
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011244 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
11245 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Mueller917f6bc2016-08-30 10:57:19 -060011246
11247 VkPipelineObj pipe(m_device);
11248 pipe.AddColorAttachment();
11249 pipe.AddShader(&vs);
11250 pipe.AddShader(&fs);
11251
11252 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011253 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060011254 pipeline_layout_create_info.setLayoutCount = 1;
11255 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
11256
11257 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011258 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
Mark Mueller917f6bc2016-08-30 10:57:19 -060011259
11260 pipe.CreateVKPipeline(pipeline_layout, m_renderPass);
11261
Mark Muellerc8d441e2016-08-23 17:36:00 -060011262 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011263 vkCmdSetEvent(m_commandBuffer->handle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Mark Muellerc8d441e2016-08-23 17:36:00 -060011264
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011265 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
11266 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
11267 &descriptorset, 0, NULL);
Mark Mueller917f6bc2016-08-30 10:57:19 -060011268
Mark Muellerc8d441e2016-08-23 17:36:00 -060011269 EndCommandBuffer();
Mark Mueller917f6bc2016-08-30 10:57:19 -060011270
Mark Mueller917f6bc2016-08-30 10:57:19 -060011271 submit_info.signalSemaphoreCount = 1;
11272 submit_info.pSignalSemaphores = &semaphore;
11273 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
Mark Muellerc8d441e2016-08-23 17:36:00 -060011274
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011275 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, cannot_delete_event_message);
Mark Mueller917f6bc2016-08-30 10:57:19 -060011276 vkDestroyEvent(m_device->device(), event, nullptr);
11277 m_errorMonitor->VerifyFound();
11278
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011279 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, cannot_delete_semaphore_message);
Mark Mueller917f6bc2016-08-30 10:57:19 -060011280 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
11281 m_errorMonitor->VerifyFound();
11282
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011283 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, cannot_destroy_fence_message);
Mark Mueller917f6bc2016-08-30 10:57:19 -060011284 vkDestroyFence(m_device->device(), fence, nullptr);
11285 m_errorMonitor->VerifyFound();
11286
Tobin Ehlis122207b2016-09-01 08:50:06 -070011287 vkQueueWaitIdle(m_device->m_queue);
Mark Mueller917f6bc2016-08-30 10:57:19 -060011288 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
11289 vkDestroyFence(m_device->device(), fence, nullptr);
11290 vkDestroyEvent(m_device->device(), event, nullptr);
11291 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011292 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
Mark Mueller917f6bc2016-08-30 10:57:19 -060011293 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
11294}
11295
Tobin Ehlis2adda372016-09-01 08:51:06 -070011296TEST_F(VkLayerTest, QueryPoolInUseDestroyedSignaled) {
11297 TEST_DESCRIPTION("Delete in-use query pool.");
11298
11299 ASSERT_NO_FATAL_FAILURE(InitState());
11300 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11301
11302 VkQueryPool query_pool;
11303 VkQueryPoolCreateInfo query_pool_ci{};
11304 query_pool_ci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
11305 query_pool_ci.queryType = VK_QUERY_TYPE_TIMESTAMP;
11306 query_pool_ci.queryCount = 1;
11307 vkCreateQueryPool(m_device->device(), &query_pool_ci, nullptr, &query_pool);
11308 BeginCommandBuffer();
11309 // Reset query pool to create binding with cmd buffer
11310 vkCmdResetQueryPool(m_commandBuffer->handle(), query_pool, 0, 1);
11311
11312 EndCommandBuffer();
11313
11314 VkSubmitInfo submit_info = {};
11315 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11316 submit_info.commandBufferCount = 1;
11317 submit_info.pCommandBuffers = &m_commandBuffer->handle();
11318 // Submit cmd buffer and then destroy query pool while in-flight
11319 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11320
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011321 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete query pool 0x");
Tobin Ehlis2adda372016-09-01 08:51:06 -070011322 vkDestroyQueryPool(m_device->handle(), query_pool, NULL);
11323 m_errorMonitor->VerifyFound();
11324
11325 vkQueueWaitIdle(m_device->m_queue);
11326 // Now that cmd buffer done we can safely destroy query_pool
11327 vkDestroyQueryPool(m_device->handle(), query_pool, NULL);
11328}
11329
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060011330TEST_F(VkLayerTest, PipelineInUseDestroyedSignaled) {
11331 TEST_DESCRIPTION("Delete in-use pipeline.");
11332
11333 ASSERT_NO_FATAL_FAILURE(InitState());
11334 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11335
11336 // Empty pipeline layout used for binding PSO
11337 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11338 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11339 pipeline_layout_ci.setLayoutCount = 0;
11340 pipeline_layout_ci.pSetLayouts = NULL;
11341
11342 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011343 VkResult err = vkCreatePipelineLayout(m_device->handle(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060011344 ASSERT_VK_SUCCESS(err);
11345
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011346 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete pipeline 0x");
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060011347 // Create PSO to be used for draw-time errors below
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011348 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
11349 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060011350 // Store pipeline handle so we can actually delete it before test finishes
11351 VkPipeline delete_this_pipeline;
11352 { // Scope pipeline so it will be auto-deleted
11353 VkPipelineObj pipe(m_device);
11354 pipe.AddShader(&vs);
11355 pipe.AddShader(&fs);
11356 pipe.AddColorAttachment();
11357 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11358 delete_this_pipeline = pipe.handle();
11359
11360 BeginCommandBuffer();
11361 // Bind pipeline to cmd buffer
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011362 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060011363
11364 EndCommandBuffer();
11365
11366 VkSubmitInfo submit_info = {};
11367 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11368 submit_info.commandBufferCount = 1;
11369 submit_info.pCommandBuffers = &m_commandBuffer->handle();
11370 // Submit cmd buffer and then pipeline destroyed while in-flight
11371 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11372 } // Pipeline deletion triggered here
11373 m_errorMonitor->VerifyFound();
11374 // Make sure queue finished and then actually delete pipeline
11375 vkQueueWaitIdle(m_device->m_queue);
11376 vkDestroyPipeline(m_device->handle(), delete_this_pipeline, nullptr);
11377 vkDestroyPipelineLayout(m_device->handle(), pipeline_layout, nullptr);
11378}
11379
Tobin Ehlis7d965da2016-09-19 16:15:45 -060011380TEST_F(VkLayerTest, ImageViewInUseDestroyedSignaled) {
11381 TEST_DESCRIPTION("Delete in-use imageView.");
11382
11383 ASSERT_NO_FATAL_FAILURE(InitState());
11384 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11385
11386 VkDescriptorPoolSize ds_type_count;
11387 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11388 ds_type_count.descriptorCount = 1;
11389
11390 VkDescriptorPoolCreateInfo ds_pool_ci = {};
11391 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11392 ds_pool_ci.maxSets = 1;
11393 ds_pool_ci.poolSizeCount = 1;
11394 ds_pool_ci.pPoolSizes = &ds_type_count;
11395
11396 VkDescriptorPool ds_pool;
11397 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
11398 ASSERT_VK_SUCCESS(err);
11399
11400 VkSamplerCreateInfo sampler_ci = {};
11401 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
11402 sampler_ci.pNext = NULL;
11403 sampler_ci.magFilter = VK_FILTER_NEAREST;
11404 sampler_ci.minFilter = VK_FILTER_NEAREST;
11405 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
11406 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11407 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11408 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11409 sampler_ci.mipLodBias = 1.0;
11410 sampler_ci.anisotropyEnable = VK_FALSE;
11411 sampler_ci.maxAnisotropy = 1;
11412 sampler_ci.compareEnable = VK_FALSE;
11413 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
11414 sampler_ci.minLod = 1.0;
11415 sampler_ci.maxLod = 1.0;
11416 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
11417 sampler_ci.unnormalizedCoordinates = VK_FALSE;
11418 VkSampler sampler;
11419
11420 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
11421 ASSERT_VK_SUCCESS(err);
11422
11423 VkDescriptorSetLayoutBinding layout_binding;
11424 layout_binding.binding = 0;
11425 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11426 layout_binding.descriptorCount = 1;
11427 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
11428 layout_binding.pImmutableSamplers = NULL;
11429
11430 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11431 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11432 ds_layout_ci.bindingCount = 1;
11433 ds_layout_ci.pBindings = &layout_binding;
11434 VkDescriptorSetLayout ds_layout;
11435 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
11436 ASSERT_VK_SUCCESS(err);
11437
11438 VkDescriptorSetAllocateInfo alloc_info = {};
11439 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11440 alloc_info.descriptorSetCount = 1;
11441 alloc_info.descriptorPool = ds_pool;
11442 alloc_info.pSetLayouts = &ds_layout;
11443 VkDescriptorSet descriptor_set;
11444 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
11445 ASSERT_VK_SUCCESS(err);
11446
11447 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11448 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11449 pipeline_layout_ci.pNext = NULL;
11450 pipeline_layout_ci.setLayoutCount = 1;
11451 pipeline_layout_ci.pSetLayouts = &ds_layout;
11452
11453 VkPipelineLayout pipeline_layout;
11454 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
11455 ASSERT_VK_SUCCESS(err);
11456
11457 VkImageObj image(m_device);
11458 image.init(128, 128, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
11459 ASSERT_TRUE(image.initialized());
11460
11461 VkImageView view;
11462 VkImageViewCreateInfo ivci = {};
11463 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
11464 ivci.image = image.handle();
11465 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
11466 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
11467 ivci.subresourceRange.layerCount = 1;
11468 ivci.subresourceRange.baseMipLevel = 0;
11469 ivci.subresourceRange.levelCount = 1;
11470 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11471
11472 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
11473 ASSERT_VK_SUCCESS(err);
11474
11475 VkDescriptorImageInfo image_info{};
11476 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
11477 image_info.imageView = view;
11478 image_info.sampler = sampler;
11479
11480 VkWriteDescriptorSet descriptor_write = {};
11481 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
11482 descriptor_write.dstSet = descriptor_set;
11483 descriptor_write.dstBinding = 0;
11484 descriptor_write.descriptorCount = 1;
11485 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11486 descriptor_write.pImageInfo = &image_info;
11487
11488 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11489
11490 // Create PSO to use the sampler
11491 char const *vsSource = "#version 450\n"
11492 "\n"
11493 "out gl_PerVertex { \n"
11494 " vec4 gl_Position;\n"
11495 "};\n"
11496 "void main(){\n"
11497 " gl_Position = vec4(1);\n"
11498 "}\n";
11499 char const *fsSource = "#version 450\n"
11500 "\n"
11501 "layout(set=0, binding=0) uniform sampler2D s;\n"
11502 "layout(location=0) out vec4 x;\n"
11503 "void main(){\n"
11504 " x = texture(s, vec2(1));\n"
11505 "}\n";
11506 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
11507 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
11508 VkPipelineObj pipe(m_device);
11509 pipe.AddShader(&vs);
11510 pipe.AddShader(&fs);
11511 pipe.AddColorAttachment();
11512 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11513
11514 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete image view 0x");
11515
11516 BeginCommandBuffer();
11517 // Bind pipeline to cmd buffer
11518 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
11519 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
11520 &descriptor_set, 0, nullptr);
11521 Draw(1, 0, 0, 0);
11522 EndCommandBuffer();
11523 // Submit cmd buffer then destroy sampler
11524 VkSubmitInfo submit_info = {};
11525 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11526 submit_info.commandBufferCount = 1;
11527 submit_info.pCommandBuffers = &m_commandBuffer->handle();
11528 // Submit cmd buffer and then destroy imageView while in-flight
11529 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11530
11531 vkDestroyImageView(m_device->device(), view, nullptr);
11532 m_errorMonitor->VerifyFound();
11533 vkQueueWaitIdle(m_device->m_queue);
11534 // Now we can actually destroy imageView
11535 vkDestroyImageView(m_device->device(), view, NULL);
11536 vkDestroySampler(m_device->device(), sampler, nullptr);
11537 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11538 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11539 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
11540}
11541
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060011542TEST_F(VkLayerTest, BufferViewInUseDestroyedSignaled) {
11543 TEST_DESCRIPTION("Delete in-use bufferView.");
11544
11545 ASSERT_NO_FATAL_FAILURE(InitState());
11546 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11547
11548 VkDescriptorPoolSize ds_type_count;
11549 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
11550 ds_type_count.descriptorCount = 1;
11551
11552 VkDescriptorPoolCreateInfo ds_pool_ci = {};
11553 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11554 ds_pool_ci.maxSets = 1;
11555 ds_pool_ci.poolSizeCount = 1;
11556 ds_pool_ci.pPoolSizes = &ds_type_count;
11557
11558 VkDescriptorPool ds_pool;
11559 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
11560 ASSERT_VK_SUCCESS(err);
11561
11562 VkDescriptorSetLayoutBinding layout_binding;
11563 layout_binding.binding = 0;
11564 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
11565 layout_binding.descriptorCount = 1;
11566 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
11567 layout_binding.pImmutableSamplers = NULL;
11568
11569 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11570 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11571 ds_layout_ci.bindingCount = 1;
11572 ds_layout_ci.pBindings = &layout_binding;
11573 VkDescriptorSetLayout ds_layout;
11574 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
11575 ASSERT_VK_SUCCESS(err);
11576
11577 VkDescriptorSetAllocateInfo alloc_info = {};
11578 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11579 alloc_info.descriptorSetCount = 1;
11580 alloc_info.descriptorPool = ds_pool;
11581 alloc_info.pSetLayouts = &ds_layout;
11582 VkDescriptorSet descriptor_set;
11583 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
11584 ASSERT_VK_SUCCESS(err);
11585
11586 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11587 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11588 pipeline_layout_ci.pNext = NULL;
11589 pipeline_layout_ci.setLayoutCount = 1;
11590 pipeline_layout_ci.pSetLayouts = &ds_layout;
11591
11592 VkPipelineLayout pipeline_layout;
11593 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
11594 ASSERT_VK_SUCCESS(err);
11595
11596 VkBuffer buffer;
11597 uint32_t queue_family_index = 0;
11598 VkBufferCreateInfo buffer_create_info = {};
11599 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
11600 buffer_create_info.size = 1024;
11601 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
11602 buffer_create_info.queueFamilyIndexCount = 1;
11603 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
11604
11605 err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
11606 ASSERT_VK_SUCCESS(err);
11607
11608 VkMemoryRequirements memory_reqs;
11609 VkDeviceMemory buffer_memory;
11610
11611 VkMemoryAllocateInfo memory_info = {};
11612 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
11613 memory_info.allocationSize = 0;
11614 memory_info.memoryTypeIndex = 0;
11615
11616 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
11617 memory_info.allocationSize = memory_reqs.size;
11618 bool pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
11619 ASSERT_TRUE(pass);
11620
11621 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
11622 ASSERT_VK_SUCCESS(err);
11623 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
11624 ASSERT_VK_SUCCESS(err);
11625
11626 VkBufferView view;
11627 VkBufferViewCreateInfo bvci = {};
11628 bvci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
11629 bvci.buffer = buffer;
11630 bvci.format = VK_FORMAT_R8_UNORM;
11631 bvci.range = VK_WHOLE_SIZE;
11632
11633 err = vkCreateBufferView(m_device->device(), &bvci, NULL, &view);
11634 ASSERT_VK_SUCCESS(err);
11635
11636 VkWriteDescriptorSet descriptor_write = {};
11637 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
11638 descriptor_write.dstSet = descriptor_set;
11639 descriptor_write.dstBinding = 0;
11640 descriptor_write.descriptorCount = 1;
11641 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
11642 descriptor_write.pTexelBufferView = &view;
11643
11644 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11645
11646 char const *vsSource = "#version 450\n"
11647 "\n"
11648 "out gl_PerVertex { \n"
11649 " vec4 gl_Position;\n"
11650 "};\n"
11651 "void main(){\n"
11652 " gl_Position = vec4(1);\n"
11653 "}\n";
11654 char const *fsSource = "#version 450\n"
11655 "\n"
11656 "layout(set=0, binding=0, r8) uniform imageBuffer s;\n"
11657 "layout(location=0) out vec4 x;\n"
11658 "void main(){\n"
11659 " x = imageLoad(s, 0);\n"
11660 "}\n";
11661 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
11662 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
11663 VkPipelineObj pipe(m_device);
11664 pipe.AddShader(&vs);
11665 pipe.AddShader(&fs);
11666 pipe.AddColorAttachment();
11667 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11668
11669 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete buffer view 0x");
11670
11671 BeginCommandBuffer();
11672 VkViewport viewport = {0, 0, 16, 16, 0, 1};
11673 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
11674 VkRect2D scissor = {{0, 0}, {16, 16}};
11675 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
11676 // Bind pipeline to cmd buffer
11677 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
11678 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
11679 &descriptor_set, 0, nullptr);
11680 Draw(1, 0, 0, 0);
11681 EndCommandBuffer();
11682
11683 VkSubmitInfo submit_info = {};
11684 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11685 submit_info.commandBufferCount = 1;
11686 submit_info.pCommandBuffers = &m_commandBuffer->handle();
11687 // Submit cmd buffer and then destroy bufferView while in-flight
11688 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11689
11690 vkDestroyBufferView(m_device->device(), view, nullptr);
11691 m_errorMonitor->VerifyFound();
11692 vkQueueWaitIdle(m_device->m_queue);
11693 // Now we can actually destroy bufferView
11694 vkDestroyBufferView(m_device->device(), view, NULL);
11695 vkDestroyBuffer(m_device->device(), buffer, NULL);
11696 vkFreeMemory(m_device->device(), buffer_memory, NULL);
11697 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11698 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11699 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
11700}
11701
Tobin Ehlis209532e2016-09-07 13:52:18 -060011702TEST_F(VkLayerTest, SamplerInUseDestroyedSignaled) {
11703 TEST_DESCRIPTION("Delete in-use sampler.");
11704
11705 ASSERT_NO_FATAL_FAILURE(InitState());
11706 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11707
11708 VkDescriptorPoolSize ds_type_count;
11709 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11710 ds_type_count.descriptorCount = 1;
11711
11712 VkDescriptorPoolCreateInfo ds_pool_ci = {};
11713 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11714 ds_pool_ci.maxSets = 1;
11715 ds_pool_ci.poolSizeCount = 1;
11716 ds_pool_ci.pPoolSizes = &ds_type_count;
11717
11718 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011719 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis209532e2016-09-07 13:52:18 -060011720 ASSERT_VK_SUCCESS(err);
11721
11722 VkSamplerCreateInfo sampler_ci = {};
11723 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
11724 sampler_ci.pNext = NULL;
11725 sampler_ci.magFilter = VK_FILTER_NEAREST;
11726 sampler_ci.minFilter = VK_FILTER_NEAREST;
11727 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
11728 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11729 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11730 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11731 sampler_ci.mipLodBias = 1.0;
11732 sampler_ci.anisotropyEnable = VK_FALSE;
11733 sampler_ci.maxAnisotropy = 1;
11734 sampler_ci.compareEnable = VK_FALSE;
11735 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
11736 sampler_ci.minLod = 1.0;
11737 sampler_ci.maxLod = 1.0;
11738 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
11739 sampler_ci.unnormalizedCoordinates = VK_FALSE;
11740 VkSampler sampler;
11741
11742 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
11743 ASSERT_VK_SUCCESS(err);
11744
11745 VkDescriptorSetLayoutBinding layout_binding;
11746 layout_binding.binding = 0;
Tobin Ehlis94fc0ad2016-09-19 16:23:01 -060011747 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
Tobin Ehlis209532e2016-09-07 13:52:18 -060011748 layout_binding.descriptorCount = 1;
11749 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
11750 layout_binding.pImmutableSamplers = NULL;
11751
11752 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11753 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11754 ds_layout_ci.bindingCount = 1;
11755 ds_layout_ci.pBindings = &layout_binding;
11756 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011757 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis209532e2016-09-07 13:52:18 -060011758 ASSERT_VK_SUCCESS(err);
11759
11760 VkDescriptorSetAllocateInfo alloc_info = {};
11761 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11762 alloc_info.descriptorSetCount = 1;
11763 alloc_info.descriptorPool = ds_pool;
11764 alloc_info.pSetLayouts = &ds_layout;
11765 VkDescriptorSet descriptor_set;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011766 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis209532e2016-09-07 13:52:18 -060011767 ASSERT_VK_SUCCESS(err);
11768
11769 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11770 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11771 pipeline_layout_ci.pNext = NULL;
11772 pipeline_layout_ci.setLayoutCount = 1;
11773 pipeline_layout_ci.pSetLayouts = &ds_layout;
11774
11775 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011776 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis209532e2016-09-07 13:52:18 -060011777 ASSERT_VK_SUCCESS(err);
11778
11779 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011780 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 -060011781 ASSERT_TRUE(image.initialized());
11782
11783 VkImageView view;
11784 VkImageViewCreateInfo ivci = {};
11785 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
11786 ivci.image = image.handle();
11787 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
11788 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
11789 ivci.subresourceRange.layerCount = 1;
11790 ivci.subresourceRange.baseMipLevel = 0;
11791 ivci.subresourceRange.levelCount = 1;
11792 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11793
11794 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
11795 ASSERT_VK_SUCCESS(err);
11796
11797 VkDescriptorImageInfo image_info{};
11798 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
11799 image_info.imageView = view;
11800 image_info.sampler = sampler;
11801
11802 VkWriteDescriptorSet descriptor_write = {};
11803 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
11804 descriptor_write.dstSet = descriptor_set;
11805 descriptor_write.dstBinding = 0;
11806 descriptor_write.descriptorCount = 1;
11807 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11808 descriptor_write.pImageInfo = &image_info;
11809
11810 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11811
11812 // Create PSO to use the sampler
11813 char const *vsSource = "#version 450\n"
11814 "\n"
11815 "out gl_PerVertex { \n"
11816 " vec4 gl_Position;\n"
11817 "};\n"
11818 "void main(){\n"
11819 " gl_Position = vec4(1);\n"
11820 "}\n";
11821 char const *fsSource = "#version 450\n"
11822 "\n"
11823 "layout(set=0, binding=0) uniform sampler2D s;\n"
11824 "layout(location=0) out vec4 x;\n"
11825 "void main(){\n"
11826 " x = texture(s, vec2(1));\n"
11827 "}\n";
11828 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
11829 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
11830 VkPipelineObj pipe(m_device);
11831 pipe.AddShader(&vs);
11832 pipe.AddShader(&fs);
11833 pipe.AddColorAttachment();
11834 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11835
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011836 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete sampler 0x");
Tobin Ehlis209532e2016-09-07 13:52:18 -060011837
11838 BeginCommandBuffer();
11839 // Bind pipeline to cmd buffer
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011840 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
11841 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
11842 &descriptor_set, 0, nullptr);
Tobin Ehlis209532e2016-09-07 13:52:18 -060011843 Draw(1, 0, 0, 0);
11844 EndCommandBuffer();
11845 // Submit cmd buffer then destroy sampler
11846 VkSubmitInfo submit_info = {};
11847 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11848 submit_info.commandBufferCount = 1;
11849 submit_info.pCommandBuffers = &m_commandBuffer->handle();
11850 // Submit cmd buffer and then destroy sampler while in-flight
11851 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11852
11853 vkDestroySampler(m_device->device(), sampler, nullptr);
11854 m_errorMonitor->VerifyFound();
11855 vkQueueWaitIdle(m_device->m_queue);
11856 // Now we can actually destroy sampler
11857 vkDestroySampler(m_device->device(), sampler, nullptr);
11858 vkDestroyImageView(m_device->device(), view, NULL);
11859 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11860 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11861 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
11862}
11863
Mark Mueller1cd9f412016-08-25 13:23:52 -060011864TEST_F(VkLayerTest, QueueForwardProgressFenceWait) {
Mark Mueller96a56d52016-08-24 10:28:05 -060011865 TEST_DESCRIPTION("Call VkQueueSubmit with a semaphore that is already "
Mark Mueller1cd9f412016-08-25 13:23:52 -060011866 "signaled but not waited on by the queue. Wait on a "
11867 "fence that has not yet been submitted to a queue.");
Mark Mueller96a56d52016-08-24 10:28:05 -060011868
11869 ASSERT_NO_FATAL_FAILURE(InitState());
11870 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11871
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011872 const char *queue_forward_progress_message = " that has already been signaled but not waited on by queue 0x";
11873 const char *invalid_fence_wait_message = " which has not been submitted on a Queue or during "
11874 "acquire next image.";
Mark Mueller96a56d52016-08-24 10:28:05 -060011875
11876 BeginCommandBuffer();
11877 EndCommandBuffer();
11878
11879 VkSemaphoreCreateInfo semaphore_create_info = {};
11880 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
11881 VkSemaphore semaphore;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011882 ASSERT_VK_SUCCESS(vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore));
Mark Mueller96a56d52016-08-24 10:28:05 -060011883 VkSubmitInfo submit_info = {};
11884 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11885 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011886 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Mueller96a56d52016-08-24 10:28:05 -060011887 submit_info.signalSemaphoreCount = 1;
11888 submit_info.pSignalSemaphores = &semaphore;
11889 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11890 m_errorMonitor->SetDesiredFailureMsg(0, "");
11891 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
11892 BeginCommandBuffer();
11893 EndCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011894 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, queue_forward_progress_message);
Mark Mueller96a56d52016-08-24 10:28:05 -060011895 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11896 m_errorMonitor->VerifyFound();
11897
Mark Mueller1cd9f412016-08-25 13:23:52 -060011898 VkFenceCreateInfo fence_create_info = {};
11899 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
11900 VkFence fence;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011901 ASSERT_VK_SUCCESS(vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence));
Mark Mueller1cd9f412016-08-25 13:23:52 -060011902
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011903 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, invalid_fence_wait_message);
Mark Mueller1cd9f412016-08-25 13:23:52 -060011904 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
11905 m_errorMonitor->VerifyFound();
11906
Mark Mueller4042b652016-09-05 22:52:21 -060011907 vkDeviceWaitIdle(m_device->device());
Mark Mueller1cd9f412016-08-25 13:23:52 -060011908 vkDestroyFence(m_device->device(), fence, nullptr);
Mark Mueller96a56d52016-08-24 10:28:05 -060011909 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
11910}
11911
Tobin Ehlis4af23302016-07-19 10:50:30 -060011912TEST_F(VkLayerTest, FramebufferIncompatible) {
11913 TEST_DESCRIPTION("Bind a secondary command buffer with with a framebuffer "
11914 "that does not match the framebuffer for the active "
11915 "renderpass.");
11916 ASSERT_NO_FATAL_FAILURE(InitState());
11917 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11918
11919 // A renderpass with one color attachment.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011920 VkAttachmentDescription attachment = {0,
11921 VK_FORMAT_B8G8R8A8_UNORM,
11922 VK_SAMPLE_COUNT_1_BIT,
11923 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
11924 VK_ATTACHMENT_STORE_OP_STORE,
11925 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
11926 VK_ATTACHMENT_STORE_OP_DONT_CARE,
11927 VK_IMAGE_LAYOUT_UNDEFINED,
11928 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis4af23302016-07-19 10:50:30 -060011929
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011930 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis4af23302016-07-19 10:50:30 -060011931
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011932 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Tobin Ehlis4af23302016-07-19 10:50:30 -060011933
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011934 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
Tobin Ehlis4af23302016-07-19 10:50:30 -060011935
11936 VkRenderPass rp;
11937 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
11938 ASSERT_VK_SUCCESS(err);
11939
11940 // A compatible framebuffer.
11941 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011942 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 -060011943 ASSERT_TRUE(image.initialized());
11944
11945 VkImageViewCreateInfo ivci = {
11946 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
11947 nullptr,
11948 0,
11949 image.handle(),
11950 VK_IMAGE_VIEW_TYPE_2D,
11951 VK_FORMAT_B8G8R8A8_UNORM,
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011952 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
11953 VK_COMPONENT_SWIZZLE_IDENTITY},
Tobin Ehlis4af23302016-07-19 10:50:30 -060011954 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
11955 };
11956 VkImageView view;
11957 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
11958 ASSERT_VK_SUCCESS(err);
11959
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011960 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Tobin Ehlis4af23302016-07-19 10:50:30 -060011961 VkFramebuffer fb;
11962 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
11963 ASSERT_VK_SUCCESS(err);
11964
11965 VkCommandBufferAllocateInfo cbai = {};
11966 cbai.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
11967 cbai.commandPool = m_commandPool;
11968 cbai.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
11969 cbai.commandBufferCount = 1;
11970
11971 VkCommandBuffer sec_cb;
11972 err = vkAllocateCommandBuffers(m_device->device(), &cbai, &sec_cb);
11973 ASSERT_VK_SUCCESS(err);
11974 VkCommandBufferBeginInfo cbbi = {};
11975 VkCommandBufferInheritanceInfo cbii = {};
Chris Forbes98420382016-11-28 17:56:51 +130011976 cbii.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
Tobin Ehlis4af23302016-07-19 10:50:30 -060011977 cbii.renderPass = renderPass();
11978 cbii.framebuffer = fb;
11979 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
11980 cbbi.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011981 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 -060011982 cbbi.pInheritanceInfo = &cbii;
11983 vkBeginCommandBuffer(sec_cb, &cbbi);
11984 vkEndCommandBuffer(sec_cb);
11985
Chris Forbes3400bc52016-09-13 18:10:34 +120011986 VkCommandBufferBeginInfo cbbi2 = {
11987 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr,
11988 0, nullptr
11989 };
11990 vkBeginCommandBuffer(m_commandBuffer->GetBufferHandle(), &cbbi2);
11991 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
Tobin Ehlis4af23302016-07-19 10:50:30 -060011992
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011993 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mike Weiblencce7ec72016-10-17 19:33:05 -060011994 " that is not the same as the primary command buffer's current active framebuffer ");
Tobin Ehlis4af23302016-07-19 10:50:30 -060011995 vkCmdExecuteCommands(m_commandBuffer->GetBufferHandle(), 1, &sec_cb);
11996 m_errorMonitor->VerifyFound();
11997 // Cleanup
11998 vkDestroyImageView(m_device->device(), view, NULL);
11999 vkDestroyRenderPass(m_device->device(), rp, NULL);
12000 vkDestroyFramebuffer(m_device->device(), fb, NULL);
12001}
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012002
12003TEST_F(VkLayerTest, ColorBlendLogicOpTests) {
12004 TEST_DESCRIPTION("If logicOp is available on the device, set it to an "
12005 "invalid value. If logicOp is not available, attempt to "
12006 "use it and verify that we see the correct error.");
12007 ASSERT_NO_FATAL_FAILURE(InitState());
12008 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12009
12010 auto features = m_device->phy().features();
12011 // Set the expected error depending on whether or not logicOp available
12012 if (VK_FALSE == features.logicOp) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012013 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "If logic operations feature not "
12014 "enabled, logicOpEnable must be "
12015 "VK_FALSE");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012016 } else {
Chris Forbes34797bc2016-10-03 15:28:49 +130012017 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "pColorBlendState->logicOp (16)");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012018 }
12019 // Create a pipeline using logicOp
12020 VkResult err;
12021
12022 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
12023 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12024
12025 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012026 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012027 ASSERT_VK_SUCCESS(err);
12028
12029 VkPipelineViewportStateCreateInfo vp_state_ci = {};
12030 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
12031 vp_state_ci.viewportCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012032 VkViewport vp = {}; // Just need dummy vp to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012033 vp_state_ci.pViewports = &vp;
12034 vp_state_ci.scissorCount = 1;
12035 VkRect2D scissors = {}; // Dummy scissors to point to
12036 vp_state_ci.pScissors = &scissors;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012037
12038 VkPipelineShaderStageCreateInfo shaderStages[2];
12039 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
12040
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012041 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
12042 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012043 shaderStages[0] = vs.GetStageCreateInfo();
12044 shaderStages[1] = fs.GetStageCreateInfo();
12045
12046 VkPipelineVertexInputStateCreateInfo vi_ci = {};
12047 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
12048
12049 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
12050 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
12051 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
12052
12053 VkPipelineRasterizationStateCreateInfo rs_ci = {};
12054 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Chris Forbes14088512016-10-03 14:28:00 +130012055 rs_ci.lineWidth = 1.0f;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012056
12057 VkPipelineColorBlendAttachmentState att = {};
12058 att.blendEnable = VK_FALSE;
12059 att.colorWriteMask = 0xf;
12060
12061 VkPipelineColorBlendStateCreateInfo cb_ci = {};
12062 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
12063 // Enable logicOp & set logicOp to value 1 beyond allowed entries
12064 cb_ci.logicOpEnable = VK_TRUE;
12065 cb_ci.logicOp = VK_LOGIC_OP_RANGE_SIZE; // This should cause an error
12066 cb_ci.attachmentCount = 1;
12067 cb_ci.pAttachments = &att;
12068
Chris Forbes8aeacbf2016-10-03 14:25:08 +130012069 VkPipelineMultisampleStateCreateInfo ms_ci = {};
12070 ms_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
12071 ms_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
12072
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012073 VkGraphicsPipelineCreateInfo gp_ci = {};
12074 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
12075 gp_ci.stageCount = 2;
12076 gp_ci.pStages = shaderStages;
12077 gp_ci.pVertexInputState = &vi_ci;
12078 gp_ci.pInputAssemblyState = &ia_ci;
12079 gp_ci.pViewportState = &vp_state_ci;
12080 gp_ci.pRasterizationState = &rs_ci;
12081 gp_ci.pColorBlendState = &cb_ci;
Chris Forbes8aeacbf2016-10-03 14:25:08 +130012082 gp_ci.pMultisampleState = &ms_ci;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012083 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
12084 gp_ci.layout = pipeline_layout;
12085 gp_ci.renderPass = renderPass();
12086
12087 VkPipelineCacheCreateInfo pc_ci = {};
12088 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
12089
12090 VkPipeline pipeline;
12091 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012092 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012093 ASSERT_VK_SUCCESS(err);
12094
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012095 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012096 m_errorMonitor->VerifyFound();
12097 if (VK_SUCCESS == err) {
12098 vkDestroyPipeline(m_device->device(), pipeline, NULL);
12099 }
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012100 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
12101 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
12102}
Mark Lobodzinski209b5292015-09-17 09:44:05 -060012103#endif // DRAW_STATE_TESTS
12104
Tobin Ehlis0788f522015-05-26 16:11:58 -060012105#if THREADING_TESTS
Mike Stroyanaccf7692015-05-12 16:00:45 -060012106#if GTEST_IS_THREADSAFE
12107struct thread_data_struct {
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012108 VkCommandBuffer commandBuffer;
Mike Stroyanaccf7692015-05-12 16:00:45 -060012109 VkEvent event;
12110 bool bailout;
12111};
12112
Karl Schultz6addd812016-02-02 17:17:23 -070012113extern "C" void *AddToCommandBuffer(void *arg) {
12114 struct thread_data_struct *data = (struct thread_data_struct *)arg;
Mike Stroyanaccf7692015-05-12 16:00:45 -060012115
Mike Stroyana6d14942016-07-13 15:10:05 -060012116 for (int i = 0; i < 80000; i++) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012117 vkCmdSetEvent(data->commandBuffer, data->event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Mike Stroyanaccf7692015-05-12 16:00:45 -060012118 if (data->bailout) {
12119 break;
12120 }
12121 }
12122 return NULL;
12123}
12124
Karl Schultz6addd812016-02-02 17:17:23 -070012125TEST_F(VkLayerTest, ThreadCommandBufferCollision) {
Mike Stroyan4268d1f2015-07-13 14:45:35 -060012126 test_platform_thread thread;
Mike Stroyanaccf7692015-05-12 16:00:45 -060012127
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012128 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "THREADING ERROR");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012129
Mike Stroyanaccf7692015-05-12 16:00:45 -060012130 ASSERT_NO_FATAL_FAILURE(InitState());
12131 ASSERT_NO_FATAL_FAILURE(InitViewport());
12132 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12133
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012134 // Calls AllocateCommandBuffers
12135 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Mark Lobodzinski5495d132015-09-30 16:19:16 -060012136
12137 // Avoid creating RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012138 commandBuffer.BeginCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -060012139
12140 VkEventCreateInfo event_info;
12141 VkEvent event;
Mike Stroyanaccf7692015-05-12 16:00:45 -060012142 VkResult err;
12143
12144 memset(&event_info, 0, sizeof(event_info));
12145 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
12146
Chia-I Wuf7458c52015-10-26 21:10:41 +080012147 err = vkCreateEvent(device(), &event_info, NULL, &event);
Mike Stroyanaccf7692015-05-12 16:00:45 -060012148 ASSERT_VK_SUCCESS(err);
12149
Mike Stroyanaccf7692015-05-12 16:00:45 -060012150 err = vkResetEvent(device(), event);
12151 ASSERT_VK_SUCCESS(err);
12152
12153 struct thread_data_struct data;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012154 data.commandBuffer = commandBuffer.GetBufferHandle();
Mike Stroyanaccf7692015-05-12 16:00:45 -060012155 data.event = event;
12156 data.bailout = false;
12157 m_errorMonitor->SetBailout(&data.bailout);
Mike Stroyana6d14942016-07-13 15:10:05 -060012158
12159 // First do some correct operations using multiple threads.
12160 // Add many entries to command buffer from another thread.
12161 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
12162 // Make non-conflicting calls from this thread at the same time.
12163 for (int i = 0; i < 80000; i++) {
Mike Stroyand6343902016-07-14 08:56:16 -060012164 uint32_t count;
12165 vkEnumeratePhysicalDevices(instance(), &count, NULL);
Mike Stroyana6d14942016-07-13 15:10:05 -060012166 }
12167 test_platform_thread_join(thread, NULL);
12168
12169 // Then do some incorrect operations using multiple threads.
Mike Stroyanaccf7692015-05-12 16:00:45 -060012170 // Add many entries to command buffer from another thread.
Mike Stroyan4268d1f2015-07-13 14:45:35 -060012171 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
Mike Stroyanaccf7692015-05-12 16:00:45 -060012172 // Add many entries to command buffer from this thread at the same time.
12173 AddToCommandBuffer(&data);
Mark Lobodzinski5495d132015-09-30 16:19:16 -060012174
Mike Stroyan4268d1f2015-07-13 14:45:35 -060012175 test_platform_thread_join(thread, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012176 commandBuffer.EndCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -060012177
Mike Stroyan10b8cb72016-01-22 15:22:03 -070012178 m_errorMonitor->SetBailout(NULL);
12179
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012180 m_errorMonitor->VerifyFound();
Mike Stroyanaccf7692015-05-12 16:00:45 -060012181
Chia-I Wuf7458c52015-10-26 21:10:41 +080012182 vkDestroyEvent(device(), event, NULL);
Mike Stroyanaccf7692015-05-12 16:00:45 -060012183}
Mark Lobodzinski209b5292015-09-17 09:44:05 -060012184#endif // GTEST_IS_THREADSAFE
12185#endif // THREADING_TESTS
12186
Chris Forbes9f7ff632015-05-25 11:13:08 +120012187#if SHADER_CHECKER_TESTS
Karl Schultz6addd812016-02-02 17:17:23 -070012188TEST_F(VkLayerTest, InvalidSPIRVCodeSize) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012189 TEST_DESCRIPTION("Test that an error is produced for a spirv module "
12190 "with an impossible code size");
12191
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012192 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012193
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012194 ASSERT_NO_FATAL_FAILURE(InitState());
12195 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12196
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012197 VkShaderModule module;
12198 VkShaderModuleCreateInfo moduleCreateInfo;
12199 struct icd_spv_header spv;
12200
12201 spv.magic = ICD_SPV_MAGIC;
12202 spv.version = ICD_SPV_VERSION;
12203 spv.gen_magic = 0;
12204
12205 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
12206 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -070012207 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012208 moduleCreateInfo.codeSize = 4;
12209 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080012210 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012211
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012212 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012213}
12214
Karl Schultz6addd812016-02-02 17:17:23 -070012215TEST_F(VkLayerTest, InvalidSPIRVMagic) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012216 TEST_DESCRIPTION("Test that an error is produced for a spirv module "
12217 "with a bad magic number");
12218
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012219 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid SPIR-V magic number");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012220
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012221 ASSERT_NO_FATAL_FAILURE(InitState());
12222 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12223
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012224 VkShaderModule module;
12225 VkShaderModuleCreateInfo moduleCreateInfo;
12226 struct icd_spv_header spv;
12227
12228 spv.magic = ~ICD_SPV_MAGIC;
12229 spv.version = ICD_SPV_VERSION;
12230 spv.gen_magic = 0;
12231
12232 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
12233 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -070012234 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012235 moduleCreateInfo.codeSize = sizeof(spv) + 10;
12236 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080012237 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012238
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012239 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012240}
12241
Chris Forbesb4afd0f2016-04-04 10:48:35 +120012242#if 0
12243// Not currently covered by SPIRV-Tools validator
Karl Schultz6addd812016-02-02 17:17:23 -070012244TEST_F(VkLayerTest, InvalidSPIRVVersion) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -070012245 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbesb4afd0f2016-04-04 10:48:35 +120012246 "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012247
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012248 ASSERT_NO_FATAL_FAILURE(InitState());
12249 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12250
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012251 VkShaderModule module;
12252 VkShaderModuleCreateInfo moduleCreateInfo;
12253 struct icd_spv_header spv;
12254
12255 spv.magic = ICD_SPV_MAGIC;
12256 spv.version = ~ICD_SPV_VERSION;
12257 spv.gen_magic = 0;
12258
12259 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
12260 moduleCreateInfo.pNext = NULL;
12261
Karl Schultz6addd812016-02-02 17:17:23 -070012262 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012263 moduleCreateInfo.codeSize = sizeof(spv) + 10;
12264 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080012265 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012266
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012267 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012268}
Chris Forbesb4afd0f2016-04-04 10:48:35 +120012269#endif
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012270
Karl Schultz6addd812016-02-02 17:17:23 -070012271TEST_F(VkLayerTest, CreatePipelineVertexOutputNotConsumed) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012272 TEST_DESCRIPTION("Test that a warning is produced for a vertex output that "
12273 "is not consumed by the fragment stage");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012274 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "not consumed by fragment shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012275
Chris Forbes9f7ff632015-05-25 11:13:08 +120012276 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060012277 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes9f7ff632015-05-25 11:13:08 +120012278
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012279 char const *vsSource = "#version 450\n"
12280 "\n"
12281 "layout(location=0) out float x;\n"
12282 "out gl_PerVertex {\n"
12283 " vec4 gl_Position;\n"
12284 "};\n"
12285 "void main(){\n"
12286 " gl_Position = vec4(1);\n"
12287 " x = 0;\n"
12288 "}\n";
12289 char const *fsSource = "#version 450\n"
12290 "\n"
12291 "layout(location=0) out vec4 color;\n"
12292 "void main(){\n"
12293 " color = vec4(1);\n"
12294 "}\n";
Chris Forbes9f7ff632015-05-25 11:13:08 +120012295
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012296 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12297 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes9f7ff632015-05-25 11:13:08 +120012298
12299 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080012300 pipe.AddColorAttachment();
Chris Forbes9f7ff632015-05-25 11:13:08 +120012301 pipe.AddShader(&vs);
12302 pipe.AddShader(&fs);
12303
Chris Forbes9f7ff632015-05-25 11:13:08 +120012304 VkDescriptorSetObj descriptorSet(m_device);
12305 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012306 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes9f7ff632015-05-25 11:13:08 +120012307
Tony Barbour5781e8f2015-08-04 16:23:11 -060012308 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes9f7ff632015-05-25 11:13:08 +120012309
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012310 m_errorMonitor->VerifyFound();
Chris Forbes9f7ff632015-05-25 11:13:08 +120012311}
Chris Forbes9f7ff632015-05-25 11:13:08 +120012312
Mark Mueller098c9cb2016-09-08 09:01:57 -060012313TEST_F(VkLayerTest, CreatePipelineCheckShaderBadSpecialization) {
12314 TEST_DESCRIPTION("Challenge core_validation with shader validation issues related to vkCreateGraphicsPipelines.");
12315
12316 ASSERT_NO_FATAL_FAILURE(InitState());
12317 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12318
12319 const char *bad_specialization_message =
12320 "Specialization entry 0 (for constant id 0) references memory outside provided specialization data ";
12321
12322 char const *vsSource =
12323 "#version 450\n"
12324 "\n"
12325 "out gl_PerVertex {\n"
12326 " vec4 gl_Position;\n"
12327 "};\n"
12328 "void main(){\n"
12329 " gl_Position = vec4(1);\n"
12330 "}\n";
12331
12332 char const *fsSource =
12333 "#version 450\n"
12334 "\n"
12335 "layout (constant_id = 0) const float r = 0.0f;\n"
12336 "layout(location = 0) out vec4 uFragColor;\n"
12337 "void main(){\n"
12338 " uFragColor = vec4(r,1,0,1);\n"
12339 "}\n";
12340
12341 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12342 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12343
12344 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
12345 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12346
12347 VkPipelineLayout pipeline_layout;
12348 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
12349
12350 VkPipelineViewportStateCreateInfo vp_state_create_info = {};
12351 vp_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
12352 vp_state_create_info.viewportCount = 1;
12353 VkViewport viewport = {};
12354 vp_state_create_info.pViewports = &viewport;
12355 vp_state_create_info.scissorCount = 1;
12356 VkRect2D scissors = {};
12357 vp_state_create_info.pScissors = &scissors;
12358
12359 VkDynamicState scissor_state = VK_DYNAMIC_STATE_SCISSOR;
12360
12361 VkPipelineDynamicStateCreateInfo pipeline_dynamic_state_create_info = {};
12362 pipeline_dynamic_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
12363 pipeline_dynamic_state_create_info.dynamicStateCount = 1;
12364 pipeline_dynamic_state_create_info.pDynamicStates = &scissor_state;
12365
12366 VkPipelineShaderStageCreateInfo shader_stage_create_info[2] = {
12367 vs.GetStageCreateInfo(),
12368 fs.GetStageCreateInfo()
12369 };
12370
12371 VkPipelineVertexInputStateCreateInfo vertex_input_create_info = {};
12372 vertex_input_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
12373
12374 VkPipelineInputAssemblyStateCreateInfo input_assembly_create_info = {};
12375 input_assembly_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
12376 input_assembly_create_info.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
12377
12378 VkPipelineRasterizationStateCreateInfo rasterization_state_create_info = {};
12379 rasterization_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
12380 rasterization_state_create_info.pNext = nullptr;
12381 rasterization_state_create_info.lineWidth = 1.0f;
12382 rasterization_state_create_info.rasterizerDiscardEnable = true;
12383
12384 VkPipelineColorBlendAttachmentState color_blend_attachment_state = {};
12385 color_blend_attachment_state.blendEnable = VK_FALSE;
12386 color_blend_attachment_state.colorWriteMask = 0xf;
12387
12388 VkPipelineColorBlendStateCreateInfo color_blend_state_create_info = {};
12389 color_blend_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
12390 color_blend_state_create_info.attachmentCount = 1;
12391 color_blend_state_create_info.pAttachments = &color_blend_attachment_state;
12392
12393 VkGraphicsPipelineCreateInfo graphicspipe_create_info = {};
12394 graphicspipe_create_info.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
12395 graphicspipe_create_info.stageCount = 2;
12396 graphicspipe_create_info.pStages = shader_stage_create_info;
12397 graphicspipe_create_info.pVertexInputState = &vertex_input_create_info;
12398 graphicspipe_create_info.pInputAssemblyState = &input_assembly_create_info;
12399 graphicspipe_create_info.pViewportState = &vp_state_create_info;
12400 graphicspipe_create_info.pRasterizationState = &rasterization_state_create_info;
12401 graphicspipe_create_info.pColorBlendState = &color_blend_state_create_info;
12402 graphicspipe_create_info.pDynamicState = &pipeline_dynamic_state_create_info;
12403 graphicspipe_create_info.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
12404 graphicspipe_create_info.layout = pipeline_layout;
12405 graphicspipe_create_info.renderPass = renderPass();
12406
12407 VkPipelineCacheCreateInfo pipeline_cache_create_info = {};
12408 pipeline_cache_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
12409
12410 VkPipelineCache pipelineCache;
12411 ASSERT_VK_SUCCESS(vkCreatePipelineCache(m_device->device(), &pipeline_cache_create_info, nullptr, &pipelineCache));
12412
12413 // This structure maps constant ids to data locations.
12414 const VkSpecializationMapEntry entry =
12415 // id, offset, size
12416 {0, 4, sizeof(uint32_t)}; // Challenge core validation by using a bogus offset.
12417
12418 uint32_t data = 1;
12419
12420 // Set up the info describing spec map and data
12421 const VkSpecializationInfo specialization_info = {
12422 1,
12423 &entry,
12424 1 * sizeof(float),
12425 &data,
12426 };
12427 shader_stage_create_info[0].pSpecializationInfo = &specialization_info;
12428
12429 VkPipeline pipeline;
12430 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bad_specialization_message);
12431 vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &graphicspipe_create_info, nullptr, &pipeline);
12432 m_errorMonitor->VerifyFound();
12433
12434 vkDestroyPipelineCache(m_device->device(), pipelineCache, nullptr);
12435 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
12436}
12437
12438TEST_F(VkLayerTest, CreatePipelineCheckShaderDescriptorTypeMismatch) {
12439 TEST_DESCRIPTION("Challenge core_validation with shader validation issues related to vkCreateGraphicsPipelines.");
12440
12441 ASSERT_NO_FATAL_FAILURE(InitState());
12442 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12443
12444 const char *descriptor_type_mismatch_message = "Type mismatch on descriptor slot 0.0 (used as type ";
12445
12446 VkDescriptorPoolSize descriptor_pool_type_count[2] = {};
12447 descriptor_pool_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
12448 descriptor_pool_type_count[0].descriptorCount = 1;
12449 descriptor_pool_type_count[1].type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
12450 descriptor_pool_type_count[1].descriptorCount = 1;
12451
12452 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
12453 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12454 descriptor_pool_create_info.maxSets = 1;
12455 descriptor_pool_create_info.poolSizeCount = 2;
12456 descriptor_pool_create_info.pPoolSizes = descriptor_pool_type_count;
12457 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
12458
12459 VkDescriptorPool descriptorset_pool;
12460 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
12461
12462 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
12463 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
12464 descriptorset_layout_binding.descriptorCount = 1;
12465 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_ALL;
12466
12467 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
12468 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
12469 descriptorset_layout_create_info.bindingCount = 1;
12470 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
12471
12472 VkDescriptorSetLayout descriptorset_layout;
12473 ASSERT_VK_SUCCESS(vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
12474
12475 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
12476 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
12477 descriptorset_allocate_info.descriptorSetCount = 1;
12478 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
12479 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
12480 VkDescriptorSet descriptorset;
12481 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
12482
12483 // Challenge core_validation with a non uniform buffer type.
12484 VkBufferTest storage_buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT);
12485
Mark Mueller098c9cb2016-09-08 09:01:57 -060012486 char const *vsSource =
12487 "#version 450\n"
12488 "\n"
12489 "layout (std140, set = 0, binding = 0) uniform buf {\n"
12490 " mat4 mvp;\n"
12491 "} ubuf;\n"
12492 "out gl_PerVertex {\n"
12493 " vec4 gl_Position;\n"
12494 "};\n"
12495 "void main(){\n"
12496 " gl_Position = ubuf.mvp * vec4(1);\n"
12497 "}\n";
12498
12499 char const *fsSource =
12500 "#version 450\n"
12501 "\n"
12502 "layout(location = 0) out vec4 uFragColor;\n"
12503 "void main(){\n"
12504 " uFragColor = vec4(0,1,0,1);\n"
12505 "}\n";
12506
12507 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12508 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12509
12510 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
12511 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12512 pipeline_layout_create_info.setLayoutCount = 1;
12513 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
12514
12515 VkPipelineLayout pipeline_layout;
12516 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
12517
12518 VkPipelineObj pipe(m_device);
12519 pipe.AddColorAttachment();
12520 pipe.AddShader(&vs);
12521 pipe.AddShader(&fs);
12522
12523 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, descriptor_type_mismatch_message);
12524 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12525 m_errorMonitor->VerifyFound();
12526
12527 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
12528 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
12529 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
12530}
12531
12532TEST_F(VkLayerTest, CreatePipelineCheckShaderDescriptorNotAccessible) {
12533 TEST_DESCRIPTION(
12534 "Create a pipeline in which a descriptor used by a shader stage does not include that stage in its stageFlags.");
12535
12536 ASSERT_NO_FATAL_FAILURE(InitState());
12537 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12538
12539 const char *descriptor_not_accessible_message = "Shader uses descriptor slot 0.0 (used as type ";
12540
12541 VkDescriptorPoolSize descriptor_pool_type_count = {};
12542 descriptor_pool_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
12543 descriptor_pool_type_count.descriptorCount = 1;
12544
12545 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
12546 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12547 descriptor_pool_create_info.maxSets = 1;
12548 descriptor_pool_create_info.poolSizeCount = 1;
12549 descriptor_pool_create_info.pPoolSizes = &descriptor_pool_type_count;
12550 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
12551
12552 VkDescriptorPool descriptorset_pool;
12553 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
12554
12555 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
12556 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
12557 descriptorset_layout_binding.descriptorCount = 1;
12558 // Intentionally make the uniform buffer inaccessible to the vertex shader to challenge core_validation
12559 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
12560
12561 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
12562 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
12563 descriptorset_layout_create_info.bindingCount = 1;
12564 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
12565
12566 VkDescriptorSetLayout descriptorset_layout;
12567 ASSERT_VK_SUCCESS(vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info,
12568 nullptr, &descriptorset_layout));
12569
12570 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
12571 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
12572 descriptorset_allocate_info.descriptorSetCount = 1;
12573 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
12574 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
12575 VkDescriptorSet descriptorset;
12576 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
12577
12578 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
12579
Mark Mueller098c9cb2016-09-08 09:01:57 -060012580 char const *vsSource =
12581 "#version 450\n"
12582 "\n"
12583 "layout (std140, set = 0, binding = 0) uniform buf {\n"
12584 " mat4 mvp;\n"
12585 "} ubuf;\n"
12586 "out gl_PerVertex {\n"
12587 " vec4 gl_Position;\n"
12588 "};\n"
12589 "void main(){\n"
12590 " gl_Position = ubuf.mvp * vec4(1);\n"
12591 "}\n";
12592
12593 char const *fsSource =
12594 "#version 450\n"
12595 "\n"
12596 "layout(location = 0) out vec4 uFragColor;\n"
12597 "void main(){\n"
12598 " uFragColor = vec4(0,1,0,1);\n"
12599 "}\n";
12600
12601 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12602 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12603
12604 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
12605 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12606 pipeline_layout_create_info.setLayoutCount = 1;
12607 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
12608
12609 VkPipelineLayout pipeline_layout;
12610 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
12611
12612 VkPipelineObj pipe(m_device);
12613 pipe.AddColorAttachment();
12614 pipe.AddShader(&vs);
12615 pipe.AddShader(&fs);
12616
12617 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, descriptor_not_accessible_message);
12618 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12619 m_errorMonitor->VerifyFound();
12620
12621 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
12622 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
12623 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
12624}
12625
12626TEST_F(VkLayerTest, CreatePipelineCheckShaderPushConstantNotAccessible) {
12627 TEST_DESCRIPTION("Create a graphics pipleine in which a push constant range containing a push constant block member is not "
12628 "accessible from the current shader stage.");
12629
12630 ASSERT_NO_FATAL_FAILURE(InitState());
12631 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12632
12633 const char *push_constant_not_accessible_message =
12634 "Push constant range covering variable starting at offset 0 not accessible from stage VK_SHADER_STAGE_VERTEX_BIT";
12635
12636 char const *vsSource =
12637 "#version 450\n"
12638 "\n"
12639 "layout(push_constant, std430) uniform foo { float x; } consts;\n"
12640 "out gl_PerVertex {\n"
12641 " vec4 gl_Position;\n"
12642 "};\n"
12643 "void main(){\n"
12644 " gl_Position = vec4(consts.x);\n"
12645 "}\n";
12646
12647 char const *fsSource =
12648 "#version 450\n"
12649 "\n"
12650 "layout(location = 0) out vec4 uFragColor;\n"
12651 "void main(){\n"
12652 " uFragColor = vec4(0,1,0,1);\n"
12653 "}\n";
12654
12655 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12656 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12657
12658 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
12659 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12660
12661 // Set up a push constant range
12662 VkPushConstantRange push_constant_ranges = {};
12663 // Set to the wrong stage to challenge core_validation
12664 push_constant_ranges.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
12665 push_constant_ranges.size = 4;
12666
12667 pipeline_layout_create_info.pPushConstantRanges = &push_constant_ranges;
12668 pipeline_layout_create_info.pushConstantRangeCount = 1;
12669
12670 VkPipelineLayout pipeline_layout;
12671 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
12672
12673 VkPipelineObj pipe(m_device);
12674 pipe.AddColorAttachment();
12675 pipe.AddShader(&vs);
12676 pipe.AddShader(&fs);
12677
12678 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, push_constant_not_accessible_message);
12679 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12680 m_errorMonitor->VerifyFound();
12681
12682 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
12683}
12684
12685TEST_F(VkLayerTest, CreatePipelineCheckShaderNotEnabled) {
12686 TEST_DESCRIPTION(
12687 "Create a graphics pipeline in which a capability declared by the shader requires a feature not enabled on the device.");
12688
12689 ASSERT_NO_FATAL_FAILURE(InitState());
12690 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12691
12692 const char *feature_not_enabled_message =
12693 "Shader requires VkPhysicalDeviceFeatures::shaderFloat64 but is not enabled on the device";
12694
12695 // Some awkward steps are required to test with custom device features.
12696 std::vector<const char *> device_extension_names;
12697 auto features = m_device->phy().features();
12698 // Disable support for 64 bit floats
12699 features.shaderFloat64 = false;
12700 // The sacrificial device object
12701 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
12702
12703 char const *vsSource = "#version 450\n"
12704 "\n"
12705 "out gl_PerVertex {\n"
12706 " vec4 gl_Position;\n"
12707 "};\n"
12708 "void main(){\n"
12709 " gl_Position = vec4(1);\n"
12710 "}\n";
12711 char const *fsSource = "#version 450\n"
12712 "\n"
12713 "layout(location=0) out vec4 color;\n"
12714 "void main(){\n"
12715 " dvec4 green = vec4(0.0, 1.0, 0.0, 1.0);\n"
12716 " color = vec4(green);\n"
12717 "}\n";
12718
12719 VkShaderObj vs(&test_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12720 VkShaderObj fs(&test_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12721
12722 VkRenderpassObj render_pass(&test_device);
Mark Mueller098c9cb2016-09-08 09:01:57 -060012723
12724 VkPipelineObj pipe(&test_device);
12725 pipe.AddColorAttachment();
12726 pipe.AddShader(&vs);
12727 pipe.AddShader(&fs);
12728
12729 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
12730 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12731 VkPipelineLayout pipeline_layout;
12732 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(test_device.device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
12733
12734 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, feature_not_enabled_message);
12735 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
12736 m_errorMonitor->VerifyFound();
12737
12738 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, nullptr);
12739}
12740
12741TEST_F(VkLayerTest, CreatePipelineCheckShaderBadCapability) {
12742 TEST_DESCRIPTION("Create a graphics pipeline in which a capability declared by the shader is not supported by Vulkan shaders.");
12743
12744 ASSERT_NO_FATAL_FAILURE(InitState());
12745 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12746
12747 const char *bad_capability_message = "Shader declares capability 53, not supported in Vulkan.";
12748
12749 char const *vsSource = "#version 450\n"
12750 "\n"
12751 "out gl_PerVertex {\n"
12752 " vec4 gl_Position;\n"
12753 "};\n"
12754 "layout(xfb_buffer = 1) out;"
12755 "void main(){\n"
12756 " gl_Position = vec4(1);\n"
12757 "}\n";
12758 char const *fsSource = "#version 450\n"
12759 "\n"
12760 "layout(location=0) out vec4 color;\n"
12761 "void main(){\n"
12762 " dvec4 green = vec4(0.0, 1.0, 0.0, 1.0);\n"
12763 " color = vec4(green);\n"
12764 "}\n";
12765
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 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
12775 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12776 VkPipelineLayout pipeline_layout;
12777 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
12778
12779 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bad_capability_message);
12780 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12781 m_errorMonitor->VerifyFound();
12782
12783 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
12784}
12785
Karl Schultz6addd812016-02-02 17:17:23 -070012786TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvided) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012787 TEST_DESCRIPTION("Test that an error is produced for a fragment shader input "
12788 "which is not present in the outputs of the previous stage");
12789
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012790 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not written by vertex shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012791
Chris Forbes59cb88d2015-05-25 11:13:13 +120012792 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060012793 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes59cb88d2015-05-25 11:13:13 +120012794
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012795 char const *vsSource = "#version 450\n"
12796 "\n"
12797 "out gl_PerVertex {\n"
12798 " vec4 gl_Position;\n"
12799 "};\n"
12800 "void main(){\n"
12801 " gl_Position = vec4(1);\n"
12802 "}\n";
12803 char const *fsSource = "#version 450\n"
12804 "\n"
12805 "layout(location=0) in float x;\n"
12806 "layout(location=0) out vec4 color;\n"
12807 "void main(){\n"
12808 " color = vec4(x);\n"
12809 "}\n";
Chris Forbes59cb88d2015-05-25 11:13:13 +120012810
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012811 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12812 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes59cb88d2015-05-25 11:13:13 +120012813
12814 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080012815 pipe.AddColorAttachment();
Chris Forbes59cb88d2015-05-25 11:13:13 +120012816 pipe.AddShader(&vs);
12817 pipe.AddShader(&fs);
12818
Chris Forbes59cb88d2015-05-25 11:13:13 +120012819 VkDescriptorSetObj descriptorSet(m_device);
12820 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012821 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes59cb88d2015-05-25 11:13:13 +120012822
Tony Barbour5781e8f2015-08-04 16:23:11 -060012823 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes59cb88d2015-05-25 11:13:13 +120012824
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012825 m_errorMonitor->VerifyFound();
Chris Forbes59cb88d2015-05-25 11:13:13 +120012826}
12827
Karl Schultz6addd812016-02-02 17:17:23 -070012828TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvidedInBlock) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012829 TEST_DESCRIPTION("Test that an error is produced for a fragment shader input "
12830 "within an interace block, which is not present in the outputs "
12831 "of the previous stage.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012832 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not written by vertex shader");
Chris Forbesa3e85f62016-01-15 14:53:11 +130012833
12834 ASSERT_NO_FATAL_FAILURE(InitState());
12835 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12836
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012837 char const *vsSource = "#version 450\n"
12838 "\n"
12839 "out gl_PerVertex {\n"
12840 " vec4 gl_Position;\n"
12841 "};\n"
12842 "void main(){\n"
12843 " gl_Position = vec4(1);\n"
12844 "}\n";
12845 char const *fsSource = "#version 450\n"
12846 "\n"
12847 "in block { layout(location=0) float x; } ins;\n"
12848 "layout(location=0) out vec4 color;\n"
12849 "void main(){\n"
12850 " color = vec4(ins.x);\n"
12851 "}\n";
Chris Forbesa3e85f62016-01-15 14:53:11 +130012852
12853 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12854 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12855
12856 VkPipelineObj pipe(m_device);
12857 pipe.AddColorAttachment();
12858 pipe.AddShader(&vs);
12859 pipe.AddShader(&fs);
12860
12861 VkDescriptorSetObj descriptorSet(m_device);
12862 descriptorSet.AppendDummy();
12863 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12864
12865 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12866
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012867 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +130012868}
12869
Karl Schultz6addd812016-02-02 17:17:23 -070012870TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchArraySize) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012871 TEST_DESCRIPTION("Test that an error is produced for mismatched array sizes "
Mike Weiblencce7ec72016-10-17 19:33:05 -060012872 "across the vertex->fragment shader interface");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012873 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0.0: 'ptr to "
12874 "output arr[2] of float32' vs 'ptr to "
12875 "input arr[3] of float32'");
Chris Forbes0036fd12016-01-26 14:19:49 +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 "layout(location=0) out float x[2];\n"
12883 "out gl_PerVertex {\n"
12884 " vec4 gl_Position;\n"
12885 "};\n"
12886 "void main(){\n"
12887 " x[0] = 0; x[1] = 0;\n"
12888 " gl_Position = vec4(1);\n"
12889 "}\n";
12890 char const *fsSource = "#version 450\n"
12891 "\n"
12892 "layout(location=0) in float x[3];\n"
12893 "layout(location=0) out vec4 color;\n"
12894 "void main(){\n"
12895 " color = vec4(x[0] + x[1] + x[2]);\n"
12896 "}\n";
Chris Forbes0036fd12016-01-26 14:19:49 +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 Forbes0036fd12016-01-26 14:19:49 +130012913}
12914
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060012915
Karl Schultz6addd812016-02-02 17:17:23 -070012916TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012917 TEST_DESCRIPTION("Test that an error is produced for mismatched types across "
Mike Weiblencce7ec72016-10-17 19:33:05 -060012918 "the vertex->fragment shader interface");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012919 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012920
Chris Forbesb56af562015-05-25 11:13:17 +120012921 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060012922 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesb56af562015-05-25 11:13:17 +120012923
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012924 char const *vsSource = "#version 450\n"
12925 "\n"
12926 "layout(location=0) out int x;\n"
12927 "out gl_PerVertex {\n"
12928 " vec4 gl_Position;\n"
12929 "};\n"
12930 "void main(){\n"
12931 " x = 0;\n"
12932 " gl_Position = vec4(1);\n"
12933 "}\n";
12934 char const *fsSource = "#version 450\n"
12935 "\n"
12936 "layout(location=0) in float x;\n" /* VS writes int */
12937 "layout(location=0) out vec4 color;\n"
12938 "void main(){\n"
12939 " color = vec4(x);\n"
12940 "}\n";
Chris Forbesb56af562015-05-25 11:13:17 +120012941
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012942 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12943 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesb56af562015-05-25 11:13:17 +120012944
12945 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080012946 pipe.AddColorAttachment();
Chris Forbesb56af562015-05-25 11:13:17 +120012947 pipe.AddShader(&vs);
12948 pipe.AddShader(&fs);
12949
Chris Forbesb56af562015-05-25 11:13:17 +120012950 VkDescriptorSetObj descriptorSet(m_device);
12951 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012952 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesb56af562015-05-25 11:13:17 +120012953
Tony Barbour5781e8f2015-08-04 16:23:11 -060012954 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesb56af562015-05-25 11:13:17 +120012955
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012956 m_errorMonitor->VerifyFound();
Chris Forbesb56af562015-05-25 11:13:17 +120012957}
12958
Karl Schultz6addd812016-02-02 17:17:23 -070012959TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchInBlock) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012960 TEST_DESCRIPTION("Test that an error is produced for mismatched types across "
Mike Weiblencce7ec72016-10-17 19:33:05 -060012961 "the vertex->fragment shader interface, when the variable is contained within "
Chris Forbes1cc79542016-07-20 11:13:44 +120012962 "an interface block");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012963 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0");
Chris Forbesa3e85f62016-01-15 14:53:11 +130012964
12965 ASSERT_NO_FATAL_FAILURE(InitState());
12966 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12967
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012968 char const *vsSource = "#version 450\n"
12969 "\n"
12970 "out block { layout(location=0) int x; } outs;\n"
12971 "out gl_PerVertex {\n"
12972 " vec4 gl_Position;\n"
12973 "};\n"
12974 "void main(){\n"
12975 " outs.x = 0;\n"
12976 " gl_Position = vec4(1);\n"
12977 "}\n";
12978 char const *fsSource = "#version 450\n"
12979 "\n"
12980 "in block { layout(location=0) float x; } ins;\n" /* VS writes int */
12981 "layout(location=0) out vec4 color;\n"
12982 "void main(){\n"
12983 " color = vec4(ins.x);\n"
12984 "}\n";
Chris Forbesa3e85f62016-01-15 14:53:11 +130012985
12986 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12987 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12988
12989 VkPipelineObj pipe(m_device);
12990 pipe.AddColorAttachment();
12991 pipe.AddShader(&vs);
12992 pipe.AddShader(&fs);
12993
12994 VkDescriptorSetObj descriptorSet(m_device);
12995 descriptorSet.AppendDummy();
12996 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12997
12998 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12999
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013000 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +130013001}
13002
13003TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByLocation) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013004 TEST_DESCRIPTION("Test that an error is produced for location mismatches across "
Mike Weiblencce7ec72016-10-17 19:33:05 -060013005 "the vertex->fragment shader interface; This should manifest as a not-written/not-consumed "
Chris Forbes1cc79542016-07-20 11:13:44 +120013006 "pair, but flushes out broken walking of the interfaces");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013007 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 +130013008
13009 ASSERT_NO_FATAL_FAILURE(InitState());
13010 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13011
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013012 char const *vsSource = "#version 450\n"
13013 "\n"
13014 "out block { layout(location=1) float x; } outs;\n"
13015 "out gl_PerVertex {\n"
13016 " vec4 gl_Position;\n"
13017 "};\n"
13018 "void main(){\n"
13019 " outs.x = 0;\n"
13020 " gl_Position = vec4(1);\n"
13021 "}\n";
13022 char const *fsSource = "#version 450\n"
13023 "\n"
13024 "in block { layout(location=0) float x; } ins;\n"
13025 "layout(location=0) out vec4 color;\n"
13026 "void main(){\n"
13027 " color = vec4(ins.x);\n"
13028 "}\n";
Chris Forbese9928822016-02-17 14:44:52 +130013029
13030 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13031 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13032
13033 VkPipelineObj pipe(m_device);
13034 pipe.AddColorAttachment();
13035 pipe.AddShader(&vs);
13036 pipe.AddShader(&fs);
13037
13038 VkDescriptorSetObj descriptorSet(m_device);
13039 descriptorSet.AppendDummy();
13040 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13041
13042 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13043
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013044 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +130013045}
13046
13047TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByComponent) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013048 TEST_DESCRIPTION("Test that an error is produced for component mismatches across the "
Mike Weiblencce7ec72016-10-17 19:33:05 -060013049 "vertex->fragment shader interface. It's not enough to have the same set of locations in "
Chris Forbes1cc79542016-07-20 11:13:44 +120013050 "use; matching is defined in terms of spirv variables.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013051 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 +130013052
13053 ASSERT_NO_FATAL_FAILURE(InitState());
13054 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13055
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013056 char const *vsSource = "#version 450\n"
13057 "\n"
13058 "out block { layout(location=0, component=0) float x; } outs;\n"
13059 "out gl_PerVertex {\n"
13060 " vec4 gl_Position;\n"
13061 "};\n"
13062 "void main(){\n"
13063 " outs.x = 0;\n"
13064 " gl_Position = vec4(1);\n"
13065 "}\n";
13066 char const *fsSource = "#version 450\n"
13067 "\n"
13068 "in block { layout(location=0, component=1) float x; } ins;\n"
13069 "layout(location=0) out vec4 color;\n"
13070 "void main(){\n"
13071 " color = vec4(ins.x);\n"
13072 "}\n";
Chris Forbese9928822016-02-17 14:44:52 +130013073
13074 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13075 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13076
13077 VkPipelineObj pipe(m_device);
13078 pipe.AddColorAttachment();
13079 pipe.AddShader(&vs);
13080 pipe.AddShader(&fs);
13081
13082 VkDescriptorSetObj descriptorSet(m_device);
13083 descriptorSet.AppendDummy();
13084 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13085
13086 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13087
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013088 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +130013089}
13090
Chris Forbes1f3b0152016-11-30 12:48:40 +130013091TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByPrecision) {
13092 TEST_DESCRIPTION("Test that the RelaxedPrecision decoration is validated to match");
13093
13094 ASSERT_NO_FATAL_FAILURE(InitState());
13095 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13096
13097 char const *vsSource = "#version 450\n"
13098 "layout(location=0) out mediump float x;\n"
13099 "void main() { gl_Position = vec4(0); x = 1.0; }\n";
13100 char const *fsSource = "#version 450\n"
13101 "layout(location=0) in highp float x;\n"
13102 "layout(location=0) out vec4 color;\n"
13103 "void main() { color = vec4(x); }\n";
13104
13105 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13106 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13107
13108 VkPipelineObj pipe(m_device);
13109 pipe.AddColorAttachment();
13110 pipe.AddShader(&vs);
13111 pipe.AddShader(&fs);
13112
13113 VkDescriptorSetObj descriptorSet(m_device);
13114 descriptorSet.AppendDummy();
13115 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13116
13117 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "differ in precision");
13118
13119 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13120
13121 m_errorMonitor->VerifyFound();
13122}
13123
Chris Forbes870a39e2016-11-30 12:55:56 +130013124TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByPrecisionBlock) {
13125 TEST_DESCRIPTION("Test that the RelaxedPrecision decoration is validated to match");
13126
13127 ASSERT_NO_FATAL_FAILURE(InitState());
13128 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13129
13130 char const *vsSource = "#version 450\n"
13131 "out block { layout(location=0) mediump float x; };\n"
13132 "void main() { gl_Position = vec4(0); x = 1.0; }\n";
13133 char const *fsSource = "#version 450\n"
13134 "in block { layout(location=0) highp float x; };\n"
13135 "layout(location=0) out vec4 color;\n"
13136 "void main() { color = vec4(x); }\n";
13137
13138 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13139 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13140
13141 VkPipelineObj pipe(m_device);
13142 pipe.AddColorAttachment();
13143 pipe.AddShader(&vs);
13144 pipe.AddShader(&fs);
13145
13146 VkDescriptorSetObj descriptorSet(m_device);
13147 descriptorSet.AppendDummy();
13148 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13149
13150 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "differ in precision");
13151
13152 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13153
13154 m_errorMonitor->VerifyFound();
13155}
13156
Karl Schultz6addd812016-02-02 17:17:23 -070013157TEST_F(VkLayerTest, CreatePipelineAttribNotConsumed) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013158 TEST_DESCRIPTION("Test that a warning is produced for a vertex attribute which is "
13159 "not consumed by the vertex shader");
Mike Weiblencce7ec72016-10-17 19:33:05 -060013160 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "location 0 not consumed by vertex shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013161
Chris Forbesde136e02015-05-25 11:13:28 +120013162 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013163 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesde136e02015-05-25 11:13:28 +120013164
13165 VkVertexInputBindingDescription input_binding;
13166 memset(&input_binding, 0, sizeof(input_binding));
13167
13168 VkVertexInputAttributeDescription input_attrib;
13169 memset(&input_attrib, 0, sizeof(input_attrib));
13170 input_attrib.format = VK_FORMAT_R32_SFLOAT;
13171
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013172 char const *vsSource = "#version 450\n"
13173 "\n"
13174 "out gl_PerVertex {\n"
13175 " vec4 gl_Position;\n"
13176 "};\n"
13177 "void main(){\n"
13178 " gl_Position = vec4(1);\n"
13179 "}\n";
13180 char const *fsSource = "#version 450\n"
13181 "\n"
13182 "layout(location=0) out vec4 color;\n"
13183 "void main(){\n"
13184 " color = vec4(1);\n"
13185 "}\n";
Chris Forbesde136e02015-05-25 11:13:28 +120013186
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013187 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13188 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesde136e02015-05-25 11:13:28 +120013189
13190 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013191 pipe.AddColorAttachment();
Chris Forbesde136e02015-05-25 11:13:28 +120013192 pipe.AddShader(&vs);
13193 pipe.AddShader(&fs);
13194
13195 pipe.AddVertexInputBindings(&input_binding, 1);
13196 pipe.AddVertexInputAttribs(&input_attrib, 1);
13197
Chris Forbesde136e02015-05-25 11:13:28 +120013198 VkDescriptorSetObj descriptorSet(m_device);
13199 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013200 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesde136e02015-05-25 11:13:28 +120013201
Tony Barbour5781e8f2015-08-04 16:23:11 -060013202 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesde136e02015-05-25 11:13:28 +120013203
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013204 m_errorMonitor->VerifyFound();
Chris Forbesde136e02015-05-25 11:13:28 +120013205}
13206
Karl Schultz6addd812016-02-02 17:17:23 -070013207TEST_F(VkLayerTest, CreatePipelineAttribLocationMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013208 TEST_DESCRIPTION("Test that a warning is produced for a location mismatch on "
13209 "vertex attributes. This flushes out bad behavior in the interface walker");
Mike Weiblencce7ec72016-10-17 19:33:05 -060013210 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "location 0 not consumed by vertex shader");
Chris Forbes7d83cd52016-01-15 11:32:03 +130013211
13212 ASSERT_NO_FATAL_FAILURE(InitState());
13213 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13214
13215 VkVertexInputBindingDescription input_binding;
13216 memset(&input_binding, 0, sizeof(input_binding));
13217
13218 VkVertexInputAttributeDescription input_attrib;
13219 memset(&input_attrib, 0, sizeof(input_attrib));
13220 input_attrib.format = VK_FORMAT_R32_SFLOAT;
13221
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013222 char const *vsSource = "#version 450\n"
13223 "\n"
13224 "layout(location=1) in float x;\n"
13225 "out gl_PerVertex {\n"
13226 " vec4 gl_Position;\n"
13227 "};\n"
13228 "void main(){\n"
13229 " gl_Position = vec4(x);\n"
13230 "}\n";
13231 char const *fsSource = "#version 450\n"
13232 "\n"
13233 "layout(location=0) out vec4 color;\n"
13234 "void main(){\n"
13235 " color = vec4(1);\n"
13236 "}\n";
Chris Forbes7d83cd52016-01-15 11:32:03 +130013237
13238 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13239 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13240
13241 VkPipelineObj pipe(m_device);
13242 pipe.AddColorAttachment();
13243 pipe.AddShader(&vs);
13244 pipe.AddShader(&fs);
13245
13246 pipe.AddVertexInputBindings(&input_binding, 1);
13247 pipe.AddVertexInputAttribs(&input_attrib, 1);
13248
13249 VkDescriptorSetObj descriptorSet(m_device);
13250 descriptorSet.AppendDummy();
13251 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13252
13253 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13254
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013255 m_errorMonitor->VerifyFound();
Chris Forbes7d83cd52016-01-15 11:32:03 +130013256}
13257
Karl Schultz6addd812016-02-02 17:17:23 -070013258TEST_F(VkLayerTest, CreatePipelineAttribNotProvided) {
Mike Weiblen15bd38e2016-10-03 19:19:41 -060013259 TEST_DESCRIPTION("Test that an error is produced for a vertex shader input which is not "
Chris Forbes1cc79542016-07-20 11:13:44 +120013260 "provided by a vertex attribute");
Mike Weiblen15bd38e2016-10-03 19:19:41 -060013261 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 -060013262
Chris Forbes62e8e502015-05-25 11:13:29 +120013263 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013264 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes62e8e502015-05-25 11:13:29 +120013265
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013266 char const *vsSource = "#version 450\n"
13267 "\n"
13268 "layout(location=0) in vec4 x;\n" /* not provided */
13269 "out gl_PerVertex {\n"
13270 " vec4 gl_Position;\n"
13271 "};\n"
13272 "void main(){\n"
13273 " gl_Position = x;\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";
Chris Forbes62e8e502015-05-25 11:13:29 +120013281
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013282 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13283 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes62e8e502015-05-25 11:13:29 +120013284
13285 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013286 pipe.AddColorAttachment();
Chris Forbes62e8e502015-05-25 11:13:29 +120013287 pipe.AddShader(&vs);
13288 pipe.AddShader(&fs);
13289
Chris Forbes62e8e502015-05-25 11:13:29 +120013290 VkDescriptorSetObj descriptorSet(m_device);
13291 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013292 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes62e8e502015-05-25 11:13:29 +120013293
Tony Barbour5781e8f2015-08-04 16:23:11 -060013294 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes62e8e502015-05-25 11:13:29 +120013295
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013296 m_errorMonitor->VerifyFound();
Chris Forbes62e8e502015-05-25 11:13:29 +120013297}
13298
Karl Schultz6addd812016-02-02 17:17:23 -070013299TEST_F(VkLayerTest, CreatePipelineAttribTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013300 TEST_DESCRIPTION("Test that an error is produced for a mismatch between the "
13301 "fundamental type (float/int/uint) of an attribute and the "
Mike Weiblen15bd38e2016-10-03 19:19:41 -060013302 "vertex shader input that consumes it");
13303 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 -060013304
Chris Forbesc97d98e2015-05-25 11:13:31 +120013305 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013306 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesc97d98e2015-05-25 11:13:31 +120013307
13308 VkVertexInputBindingDescription input_binding;
13309 memset(&input_binding, 0, sizeof(input_binding));
13310
13311 VkVertexInputAttributeDescription input_attrib;
13312 memset(&input_attrib, 0, sizeof(input_attrib));
13313 input_attrib.format = VK_FORMAT_R32_SFLOAT;
13314
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013315 char const *vsSource = "#version 450\n"
13316 "\n"
13317 "layout(location=0) in int x;\n" /* attrib provided float */
13318 "out gl_PerVertex {\n"
13319 " vec4 gl_Position;\n"
13320 "};\n"
13321 "void main(){\n"
13322 " gl_Position = vec4(x);\n"
13323 "}\n";
13324 char const *fsSource = "#version 450\n"
13325 "\n"
13326 "layout(location=0) out vec4 color;\n"
13327 "void main(){\n"
13328 " color = vec4(1);\n"
13329 "}\n";
Chris Forbesc97d98e2015-05-25 11:13:31 +120013330
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013331 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13332 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesc97d98e2015-05-25 11:13:31 +120013333
13334 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013335 pipe.AddColorAttachment();
Chris Forbesc97d98e2015-05-25 11:13:31 +120013336 pipe.AddShader(&vs);
13337 pipe.AddShader(&fs);
13338
13339 pipe.AddVertexInputBindings(&input_binding, 1);
13340 pipe.AddVertexInputAttribs(&input_attrib, 1);
13341
Chris Forbesc97d98e2015-05-25 11:13:31 +120013342 VkDescriptorSetObj descriptorSet(m_device);
13343 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013344 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesc97d98e2015-05-25 11:13:31 +120013345
Tony Barbour5781e8f2015-08-04 16:23:11 -060013346 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesc97d98e2015-05-25 11:13:31 +120013347
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013348 m_errorMonitor->VerifyFound();
Chris Forbesc97d98e2015-05-25 11:13:31 +120013349}
13350
Chris Forbesc68b43c2016-04-06 11:18:47 +120013351TEST_F(VkLayerTest, CreatePipelineDuplicateStage) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013352 TEST_DESCRIPTION("Test that an error is produced for a pipeline containing multiple "
13353 "shaders for the same stage");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013354 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13355 "Multiple shaders provided for stage VK_SHADER_STAGE_VERTEX_BIT");
Chris Forbesc68b43c2016-04-06 11:18:47 +120013356
13357 ASSERT_NO_FATAL_FAILURE(InitState());
13358 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13359
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013360 char const *vsSource = "#version 450\n"
13361 "\n"
13362 "out gl_PerVertex {\n"
13363 " vec4 gl_Position;\n"
13364 "};\n"
13365 "void main(){\n"
13366 " gl_Position = vec4(1);\n"
13367 "}\n";
13368 char const *fsSource = "#version 450\n"
13369 "\n"
13370 "layout(location=0) out vec4 color;\n"
13371 "void main(){\n"
13372 " color = vec4(1);\n"
13373 "}\n";
Chris Forbesc68b43c2016-04-06 11:18:47 +120013374
13375 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13376 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13377
13378 VkPipelineObj pipe(m_device);
13379 pipe.AddColorAttachment();
13380 pipe.AddShader(&vs);
Mike Weiblencce7ec72016-10-17 19:33:05 -060013381 pipe.AddShader(&vs); // intentionally duplicate vertex shader attachment
Chris Forbesc68b43c2016-04-06 11:18:47 +120013382 pipe.AddShader(&fs);
13383
13384 VkDescriptorSetObj descriptorSet(m_device);
13385 descriptorSet.AppendDummy();
13386 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13387
13388 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13389
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013390 m_errorMonitor->VerifyFound();
Chris Forbesc68b43c2016-04-06 11:18:47 +120013391}
13392
Chris Forbes82ff92a2016-09-09 10:50:24 +120013393TEST_F(VkLayerTest, CreatePipelineMissingEntrypoint) {
13394 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13395 "No entrypoint found named `foo`");
13396
13397 ASSERT_NO_FATAL_FAILURE(InitState());
13398 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13399
13400 char const *vsSource = "#version 450\n"
13401 "out gl_PerVertex {\n"
13402 " vec4 gl_Position;\n"
13403 "};\n"
13404 "void main(){\n"
13405 " gl_Position = vec4(0);\n"
13406 "}\n";
13407 char const *fsSource = "#version 450\n"
13408 "\n"
13409 "layout(location=0) out vec4 color;\n"
13410 "void main(){\n"
13411 " color = vec4(1);\n"
13412 "}\n";
13413
13414 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13415 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this, "foo");
13416
13417 VkPipelineObj pipe(m_device);
13418 pipe.AddColorAttachment();
13419 pipe.AddShader(&vs);
13420 pipe.AddShader(&fs);
13421
13422 VkDescriptorSetObj descriptorSet(m_device);
13423 descriptorSet.AppendDummy();
13424 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13425
13426 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13427
13428 m_errorMonitor->VerifyFound();
13429}
13430
Chris Forbesae9d8cd2016-09-13 16:32:57 +120013431TEST_F(VkLayerTest, CreatePipelineDepthStencilRequired) {
13432 m_errorMonitor->SetDesiredFailureMsg(
13433 VK_DEBUG_REPORT_ERROR_BIT_EXT,
13434 "pDepthStencilState is NULL when rasterization is enabled and subpass "
13435 "uses a depth/stencil attachment");
13436
13437 ASSERT_NO_FATAL_FAILURE(InitState());
13438 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13439
13440 char const *vsSource = "#version 450\n"
13441 "void main(){ gl_Position = vec4(0); }\n";
13442 char const *fsSource = "#version 450\n"
13443 "\n"
13444 "layout(location=0) out vec4 color;\n"
13445 "void main(){\n"
13446 " color = vec4(1);\n"
13447 "}\n";
13448
13449 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13450 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13451
13452 VkPipelineObj pipe(m_device);
13453 pipe.AddColorAttachment();
13454 pipe.AddShader(&vs);
13455 pipe.AddShader(&fs);
13456
13457 VkDescriptorSetObj descriptorSet(m_device);
13458 descriptorSet.AppendDummy();
13459 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13460
13461 VkAttachmentDescription attachments[] = {
13462 { 0, VK_FORMAT_B8G8R8A8_UNORM, VK_SAMPLE_COUNT_1_BIT,
13463 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
13464 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
13465 VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
13466 },
13467 { 0, VK_FORMAT_D16_UNORM, VK_SAMPLE_COUNT_1_BIT,
13468 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
13469 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
13470 VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
13471 },
13472 };
13473 VkAttachmentReference refs[] = {
13474 { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL },
13475 { 1, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL },
13476 };
13477 VkSubpassDescription subpass = {
13478 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr,
13479 1, &refs[0], nullptr, &refs[1],
13480 0, nullptr
13481 };
13482 VkRenderPassCreateInfo rpci = {
13483 VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr,
13484 0, 2, attachments, 1, &subpass, 0, nullptr
13485 };
13486 VkRenderPass rp;
13487 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
13488 ASSERT_VK_SUCCESS(err);
13489
13490 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), rp);
13491
13492 m_errorMonitor->VerifyFound();
13493
13494 vkDestroyRenderPass(m_device->device(), rp, nullptr);
13495}
13496
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013497TEST_F(VkLayerTest, CreatePipelineTessPatchDecorationMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013498 TEST_DESCRIPTION("Test that an error is produced for a variable output from "
13499 "the TCS without the patch decoration, but consumed in the TES "
13500 "with the decoration.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013501 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is per-vertex in tessellation control shader stage "
13502 "but per-patch in tessellation evaluation shader stage");
Chris Forbesa0193bc2016-04-04 19:19:47 +120013503
13504 ASSERT_NO_FATAL_FAILURE(InitState());
13505 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13506
Chris Forbesc1e852d2016-04-04 19:26:42 +120013507 if (!m_device->phy().features().tessellationShader) {
13508 printf("Device does not support tessellation shaders; skipped.\n");
13509 return;
13510 }
13511
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013512 char const *vsSource = "#version 450\n"
13513 "void main(){}\n";
13514 char const *tcsSource = "#version 450\n"
13515 "layout(location=0) out int x[];\n"
13516 "layout(vertices=3) out;\n"
13517 "void main(){\n"
13518 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
13519 " gl_TessLevelInner[0] = 1;\n"
13520 " x[gl_InvocationID] = gl_InvocationID;\n"
13521 "}\n";
13522 char const *tesSource = "#version 450\n"
13523 "layout(triangles, equal_spacing, cw) in;\n"
13524 "layout(location=0) patch in int x;\n"
13525 "out gl_PerVertex { vec4 gl_Position; };\n"
13526 "void main(){\n"
13527 " gl_Position.xyz = gl_TessCoord;\n"
13528 " gl_Position.w = x;\n"
13529 "}\n";
13530 char const *fsSource = "#version 450\n"
13531 "layout(location=0) out vec4 color;\n"
13532 "void main(){\n"
13533 " color = vec4(1);\n"
13534 "}\n";
Chris Forbesa0193bc2016-04-04 19:19:47 +120013535
13536 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13537 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
13538 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
13539 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13540
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013541 VkPipelineInputAssemblyStateCreateInfo iasci{VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, nullptr, 0,
13542 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, VK_FALSE};
Chris Forbesa0193bc2016-04-04 19:19:47 +120013543
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013544 VkPipelineTessellationStateCreateInfo tsci{VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, nullptr, 0, 3};
Chris Forbesa0193bc2016-04-04 19:19:47 +120013545
13546 VkPipelineObj pipe(m_device);
13547 pipe.SetInputAssembly(&iasci);
13548 pipe.SetTessellation(&tsci);
13549 pipe.AddColorAttachment();
13550 pipe.AddShader(&vs);
13551 pipe.AddShader(&tcs);
13552 pipe.AddShader(&tes);
13553 pipe.AddShader(&fs);
13554
13555 VkDescriptorSetObj descriptorSet(m_device);
13556 descriptorSet.AppendDummy();
13557 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13558
13559 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13560
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013561 m_errorMonitor->VerifyFound();
Chris Forbesa0193bc2016-04-04 19:19:47 +120013562}
13563
Karl Schultz6addd812016-02-02 17:17:23 -070013564TEST_F(VkLayerTest, CreatePipelineAttribBindingConflict) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013565 TEST_DESCRIPTION("Test that an error is produced for a vertex attribute setup where multiple "
13566 "bindings provide the same location");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013567 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13568 "Duplicate vertex input binding descriptions for binding 0");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013569
Chris Forbes280ba2c2015-06-12 11:16:41 +120013570 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013571 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes280ba2c2015-06-12 11:16:41 +120013572
13573 /* Two binding descriptions for binding 0 */
13574 VkVertexInputBindingDescription input_bindings[2];
13575 memset(input_bindings, 0, sizeof(input_bindings));
13576
13577 VkVertexInputAttributeDescription input_attrib;
13578 memset(&input_attrib, 0, sizeof(input_attrib));
13579 input_attrib.format = VK_FORMAT_R32_SFLOAT;
13580
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013581 char const *vsSource = "#version 450\n"
13582 "\n"
13583 "layout(location=0) in float x;\n" /* attrib provided float */
13584 "out gl_PerVertex {\n"
13585 " vec4 gl_Position;\n"
13586 "};\n"
13587 "void main(){\n"
13588 " gl_Position = vec4(x);\n"
13589 "}\n";
13590 char const *fsSource = "#version 450\n"
13591 "\n"
13592 "layout(location=0) out vec4 color;\n"
13593 "void main(){\n"
13594 " color = vec4(1);\n"
13595 "}\n";
Chris Forbes280ba2c2015-06-12 11:16:41 +120013596
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013597 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13598 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes280ba2c2015-06-12 11:16:41 +120013599
13600 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013601 pipe.AddColorAttachment();
Chris Forbes280ba2c2015-06-12 11:16:41 +120013602 pipe.AddShader(&vs);
13603 pipe.AddShader(&fs);
13604
13605 pipe.AddVertexInputBindings(input_bindings, 2);
13606 pipe.AddVertexInputAttribs(&input_attrib, 1);
13607
Chris Forbes280ba2c2015-06-12 11:16:41 +120013608 VkDescriptorSetObj descriptorSet(m_device);
13609 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013610 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes280ba2c2015-06-12 11:16:41 +120013611
Tony Barbour5781e8f2015-08-04 16:23:11 -060013612 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes280ba2c2015-06-12 11:16:41 +120013613
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013614 m_errorMonitor->VerifyFound();
Chris Forbes280ba2c2015-06-12 11:16:41 +120013615}
Chris Forbes8f68b562015-05-25 11:13:32 +120013616
Karl Schultz6addd812016-02-02 17:17:23 -070013617TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotWritten) {
Mike Weiblencce7ec72016-10-17 19:33:05 -060013618 TEST_DESCRIPTION("Test that an error is produced for a fragment shader which does not "
Chris Forbes1cc79542016-07-20 11:13:44 +120013619 "provide an output for one of the pipeline's color attachments");
Mike Weiblencce7ec72016-10-17 19:33:05 -060013620 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attachment 0 not written by fragment shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013621
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013622 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013623
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013624 char const *vsSource = "#version 450\n"
13625 "\n"
13626 "out gl_PerVertex {\n"
13627 " vec4 gl_Position;\n"
13628 "};\n"
13629 "void main(){\n"
13630 " gl_Position = vec4(1);\n"
13631 "}\n";
13632 char const *fsSource = "#version 450\n"
13633 "\n"
13634 "void main(){\n"
13635 "}\n";
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013636
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013637 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13638 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013639
13640 VkPipelineObj pipe(m_device);
13641 pipe.AddShader(&vs);
13642 pipe.AddShader(&fs);
13643
Chia-I Wu08accc62015-07-07 11:50:03 +080013644 /* set up CB 0, not written */
13645 pipe.AddColorAttachment();
13646 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013647
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013648 VkDescriptorSetObj descriptorSet(m_device);
13649 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013650 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013651
Tony Barbour5781e8f2015-08-04 16:23:11 -060013652 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013653
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013654 m_errorMonitor->VerifyFound();
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013655}
13656
Karl Schultz6addd812016-02-02 17:17:23 -070013657TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotConsumed) {
Mike Weiblencce7ec72016-10-17 19:33:05 -060013658 TEST_DESCRIPTION("Test that a warning is produced for a fragment shader which provides a spurious "
Chris Forbes1cc79542016-07-20 11:13:44 +120013659 "output with no matching attachment");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013660 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
Mike Weiblencce7ec72016-10-17 19:33:05 -060013661 "fragment shader writes to output location 1 with no matching attachment");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013662
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013663 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013664
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013665 char const *vsSource = "#version 450\n"
13666 "\n"
13667 "out gl_PerVertex {\n"
13668 " vec4 gl_Position;\n"
13669 "};\n"
13670 "void main(){\n"
13671 " gl_Position = vec4(1);\n"
13672 "}\n";
13673 char const *fsSource = "#version 450\n"
13674 "\n"
13675 "layout(location=0) out vec4 x;\n"
13676 "layout(location=1) out vec4 y;\n" /* no matching attachment for this */
13677 "void main(){\n"
13678 " x = vec4(1);\n"
13679 " y = vec4(1);\n"
13680 "}\n";
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013681
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013682 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13683 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013684
13685 VkPipelineObj pipe(m_device);
13686 pipe.AddShader(&vs);
13687 pipe.AddShader(&fs);
13688
Chia-I Wu08accc62015-07-07 11:50:03 +080013689 /* set up CB 0, not written */
13690 pipe.AddColorAttachment();
13691 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013692 /* FS writes CB 1, but we don't configure it */
13693
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013694 VkDescriptorSetObj descriptorSet(m_device);
13695 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013696 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013697
Tony Barbour5781e8f2015-08-04 16:23:11 -060013698 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013699
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013700 m_errorMonitor->VerifyFound();
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013701}
13702
Karl Schultz6addd812016-02-02 17:17:23 -070013703TEST_F(VkLayerTest, CreatePipelineFragmentOutputTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013704 TEST_DESCRIPTION("Test that an error is produced for a mismatch between the fundamental "
Mike Weiblencce7ec72016-10-17 19:33:05 -060013705 "type of an fragment shader output variable, and the format of the corresponding attachment");
13706 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "does not match fragment shader output type");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013707
Chris Forbesa36d69e2015-05-25 11:13:44 +120013708 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesa36d69e2015-05-25 11:13:44 +120013709
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013710 char const *vsSource = "#version 450\n"
13711 "\n"
13712 "out gl_PerVertex {\n"
13713 " vec4 gl_Position;\n"
13714 "};\n"
13715 "void main(){\n"
13716 " gl_Position = vec4(1);\n"
13717 "}\n";
13718 char const *fsSource = "#version 450\n"
13719 "\n"
13720 "layout(location=0) out ivec4 x;\n" /* not UNORM */
13721 "void main(){\n"
13722 " x = ivec4(1);\n"
13723 "}\n";
Chris Forbesa36d69e2015-05-25 11:13:44 +120013724
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013725 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13726 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesa36d69e2015-05-25 11:13:44 +120013727
13728 VkPipelineObj pipe(m_device);
13729 pipe.AddShader(&vs);
13730 pipe.AddShader(&fs);
13731
Chia-I Wu08accc62015-07-07 11:50:03 +080013732 /* set up CB 0; type is UNORM by default */
13733 pipe.AddColorAttachment();
13734 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesa36d69e2015-05-25 11:13:44 +120013735
Chris Forbesa36d69e2015-05-25 11:13:44 +120013736 VkDescriptorSetObj descriptorSet(m_device);
13737 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013738 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesa36d69e2015-05-25 11:13:44 +120013739
Tony Barbour5781e8f2015-08-04 16:23:11 -060013740 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesa36d69e2015-05-25 11:13:44 +120013741
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013742 m_errorMonitor->VerifyFound();
Chris Forbesa36d69e2015-05-25 11:13:44 +120013743}
Chris Forbes7b1b8932015-06-05 14:43:36 +120013744
Karl Schultz6addd812016-02-02 17:17:23 -070013745TEST_F(VkLayerTest, CreatePipelineUniformBlockNotProvided) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013746 TEST_DESCRIPTION("Test that an error is produced for a shader consuming a uniform "
13747 "block which has no corresponding binding in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013748 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not declared in pipeline layout");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013749
Chris Forbes556c76c2015-08-14 12:04:59 +120013750 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes556c76c2015-08-14 12:04:59 +120013751
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013752 char const *vsSource = "#version 450\n"
13753 "\n"
13754 "out gl_PerVertex {\n"
13755 " vec4 gl_Position;\n"
13756 "};\n"
13757 "void main(){\n"
13758 " gl_Position = vec4(1);\n"
13759 "}\n";
13760 char const *fsSource = "#version 450\n"
13761 "\n"
13762 "layout(location=0) out vec4 x;\n"
13763 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
13764 "void main(){\n"
13765 " x = vec4(bar.y);\n"
13766 "}\n";
Chris Forbes556c76c2015-08-14 12:04:59 +120013767
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013768 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13769 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes556c76c2015-08-14 12:04:59 +120013770
Chris Forbes556c76c2015-08-14 12:04:59 +120013771 VkPipelineObj pipe(m_device);
13772 pipe.AddShader(&vs);
13773 pipe.AddShader(&fs);
13774
13775 /* set up CB 0; type is UNORM by default */
13776 pipe.AddColorAttachment();
13777 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13778
13779 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013780 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes556c76c2015-08-14 12:04:59 +120013781
13782 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13783
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013784 m_errorMonitor->VerifyFound();
Chris Forbes556c76c2015-08-14 12:04:59 +120013785}
13786
Chris Forbes5c59e902016-02-26 16:56:09 +130013787TEST_F(VkLayerTest, CreatePipelinePushConstantsNotInLayout) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013788 TEST_DESCRIPTION("Test that an error is produced for a shader consuming push constants "
13789 "which are not provided in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013790 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not declared in layout");
Chris Forbes5c59e902016-02-26 16:56:09 +130013791
13792 ASSERT_NO_FATAL_FAILURE(InitState());
13793
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013794 char const *vsSource = "#version 450\n"
13795 "\n"
13796 "layout(push_constant, std430) uniform foo { float x; } consts;\n"
13797 "out gl_PerVertex {\n"
13798 " vec4 gl_Position;\n"
13799 "};\n"
13800 "void main(){\n"
13801 " gl_Position = vec4(consts.x);\n"
13802 "}\n";
13803 char const *fsSource = "#version 450\n"
13804 "\n"
13805 "layout(location=0) out vec4 x;\n"
13806 "void main(){\n"
13807 " x = vec4(1);\n"
13808 "}\n";
Chris Forbes5c59e902016-02-26 16:56:09 +130013809
13810 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13811 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13812
13813 VkPipelineObj pipe(m_device);
13814 pipe.AddShader(&vs);
13815 pipe.AddShader(&fs);
13816
13817 /* set up CB 0; type is UNORM by default */
13818 pipe.AddColorAttachment();
13819 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13820
13821 VkDescriptorSetObj descriptorSet(m_device);
13822 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13823
13824 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13825
13826 /* should have generated an error -- no push constant ranges provided! */
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013827 m_errorMonitor->VerifyFound();
Chris Forbes5c59e902016-02-26 16:56:09 +130013828}
13829
Chris Forbes3fb17902016-08-22 14:57:55 +120013830TEST_F(VkLayerTest, CreatePipelineInputAttachmentMissing) {
13831 TEST_DESCRIPTION("Test that an error is produced for a shader consuming an input attachment "
13832 "which is not included in the subpass description");
13833 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13834 "consumes input attachment index 0 but not provided in subpass");
13835
13836 ASSERT_NO_FATAL_FAILURE(InitState());
13837
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013838 char const *vsSource = "#version 450\n"
13839 "\n"
13840 "out gl_PerVertex {\n"
13841 " vec4 gl_Position;\n"
13842 "};\n"
13843 "void main(){\n"
13844 " gl_Position = vec4(1);\n"
13845 "}\n";
13846 char const *fsSource = "#version 450\n"
13847 "\n"
13848 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
13849 "layout(location=0) out vec4 color;\n"
13850 "void main() {\n"
13851 " color = subpassLoad(x);\n"
13852 "}\n";
Chris Forbes3fb17902016-08-22 14:57:55 +120013853
13854 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13855 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13856
13857 VkPipelineObj pipe(m_device);
13858 pipe.AddShader(&vs);
13859 pipe.AddShader(&fs);
13860 pipe.AddColorAttachment();
13861 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13862
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013863 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
13864 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes3fb17902016-08-22 14:57:55 +120013865 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013866 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes3fb17902016-08-22 14:57:55 +120013867 ASSERT_VK_SUCCESS(err);
13868
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013869 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes3fb17902016-08-22 14:57:55 +120013870 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013871 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes3fb17902016-08-22 14:57:55 +120013872 ASSERT_VK_SUCCESS(err);
13873
13874 // error here.
13875 pipe.CreateVKPipeline(pl, renderPass());
13876
13877 m_errorMonitor->VerifyFound();
13878
13879 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
13880 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
13881}
13882
Chris Forbes5a9a0472016-08-22 16:02:09 +120013883TEST_F(VkLayerTest, CreatePipelineInputAttachmentTypeMismatch) {
13884 TEST_DESCRIPTION("Test that an error is produced for a shader consuming an input attachment "
13885 "with a format having a different fundamental type");
13886 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13887 "input attachment 0 format of VK_FORMAT_R8G8B8A8_UINT does not match");
13888
13889 ASSERT_NO_FATAL_FAILURE(InitState());
13890
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013891 char const *vsSource = "#version 450\n"
13892 "\n"
13893 "out gl_PerVertex {\n"
13894 " vec4 gl_Position;\n"
13895 "};\n"
13896 "void main(){\n"
13897 " gl_Position = vec4(1);\n"
13898 "}\n";
13899 char const *fsSource = "#version 450\n"
13900 "\n"
13901 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
13902 "layout(location=0) out vec4 color;\n"
13903 "void main() {\n"
13904 " color = subpassLoad(x);\n"
13905 "}\n";
Chris Forbes5a9a0472016-08-22 16:02:09 +120013906
13907 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13908 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13909
13910 VkPipelineObj pipe(m_device);
13911 pipe.AddShader(&vs);
13912 pipe.AddShader(&fs);
13913 pipe.AddColorAttachment();
13914 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13915
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013916 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
13917 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes5a9a0472016-08-22 16:02:09 +120013918 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013919 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes5a9a0472016-08-22 16:02:09 +120013920 ASSERT_VK_SUCCESS(err);
13921
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013922 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120013923 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013924 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes5a9a0472016-08-22 16:02:09 +120013925 ASSERT_VK_SUCCESS(err);
13926
13927 VkAttachmentDescription descs[2] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013928 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
13929 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
13930 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
13931 {0, VK_FORMAT_R8G8B8A8_UINT, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
13932 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 +120013933 };
13934 VkAttachmentReference color = {
13935 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
13936 };
13937 VkAttachmentReference input = {
13938 1, VK_IMAGE_LAYOUT_GENERAL,
13939 };
13940
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013941 VkSubpassDescription sd = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 1, &input, 1, &color, nullptr, nullptr, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120013942
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013943 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, descs, 1, &sd, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120013944 VkRenderPass rp;
13945 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
13946 ASSERT_VK_SUCCESS(err);
13947
13948 // error here.
13949 pipe.CreateVKPipeline(pl, rp);
13950
13951 m_errorMonitor->VerifyFound();
13952
13953 vkDestroyRenderPass(m_device->device(), rp, nullptr);
13954 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
13955 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
13956}
13957
Chris Forbes541f7b02016-08-22 15:30:27 +120013958TEST_F(VkLayerTest, CreatePipelineInputAttachmentMissingArray) {
13959 TEST_DESCRIPTION("Test that an error is produced for a shader consuming an input attachment "
13960 "which is not included in the subpass description -- array case");
13961 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13962 "consumes input attachment index 1 but not provided in subpass");
13963
13964 ASSERT_NO_FATAL_FAILURE(InitState());
13965
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013966 char const *vsSource = "#version 450\n"
13967 "\n"
13968 "out gl_PerVertex {\n"
13969 " vec4 gl_Position;\n"
13970 "};\n"
13971 "void main(){\n"
13972 " gl_Position = vec4(1);\n"
13973 "}\n";
13974 char const *fsSource = "#version 450\n"
13975 "\n"
13976 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput xs[2];\n"
13977 "layout(location=0) out vec4 color;\n"
13978 "void main() {\n"
13979 " color = subpassLoad(xs[1]);\n"
13980 "}\n";
Chris Forbes541f7b02016-08-22 15:30:27 +120013981
13982 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13983 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13984
13985 VkPipelineObj pipe(m_device);
13986 pipe.AddShader(&vs);
13987 pipe.AddShader(&fs);
13988 pipe.AddColorAttachment();
13989 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13990
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013991 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 2, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
13992 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes541f7b02016-08-22 15:30:27 +120013993 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013994 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes541f7b02016-08-22 15:30:27 +120013995 ASSERT_VK_SUCCESS(err);
13996
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013997 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes541f7b02016-08-22 15:30:27 +120013998 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013999 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes541f7b02016-08-22 15:30:27 +120014000 ASSERT_VK_SUCCESS(err);
14001
14002 // error here.
14003 pipe.CreateVKPipeline(pl, renderPass());
14004
14005 m_errorMonitor->VerifyFound();
14006
14007 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
14008 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
14009}
14010
Chris Forbes10eb9ae2016-05-31 16:09:42 +120014011TEST_F(VkLayerTest, CreateComputePipelineMissingDescriptor) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014012 TEST_DESCRIPTION("Test that an error is produced for a compute pipeline consuming a "
14013 "descriptor which is not provided in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014014 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Shader uses descriptor slot 0.0");
Chris Forbes10eb9ae2016-05-31 16:09:42 +120014015
14016 ASSERT_NO_FATAL_FAILURE(InitState());
14017
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014018 char const *csSource = "#version 450\n"
14019 "\n"
14020 "layout(local_size_x=1) in;\n"
14021 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
14022 "void main(){\n"
14023 " x = vec4(1);\n"
14024 "}\n";
Chris Forbes10eb9ae2016-05-31 16:09:42 +120014025
14026 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
14027
14028 VkDescriptorSetObj descriptorSet(m_device);
14029 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14030
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014031 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
14032 nullptr,
14033 0,
14034 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
14035 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
14036 descriptorSet.GetPipelineLayout(),
14037 VK_NULL_HANDLE,
14038 -1};
Chris Forbes10eb9ae2016-05-31 16:09:42 +120014039
14040 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014041 VkResult err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes10eb9ae2016-05-31 16:09:42 +120014042
14043 m_errorMonitor->VerifyFound();
14044
14045 if (err == VK_SUCCESS) {
14046 vkDestroyPipeline(m_device->device(), pipe, nullptr);
14047 }
14048}
14049
Chris Forbes22a9b092016-07-19 14:34:05 +120014050TEST_F(VkLayerTest, CreateComputePipelineDescriptorTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014051 TEST_DESCRIPTION("Test that an error is produced for a pipeline consuming a "
14052 "descriptor-backed resource of a mismatched type");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014053 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14054 "but descriptor of type VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER");
Chris Forbes22a9b092016-07-19 14:34:05 +120014055
14056 ASSERT_NO_FATAL_FAILURE(InitState());
14057
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014058 VkDescriptorSetLayoutBinding binding = {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr};
14059 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &binding};
Chris Forbes22a9b092016-07-19 14:34:05 +120014060 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014061 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes22a9b092016-07-19 14:34:05 +120014062 ASSERT_VK_SUCCESS(err);
14063
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014064 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes22a9b092016-07-19 14:34:05 +120014065 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014066 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes22a9b092016-07-19 14:34:05 +120014067 ASSERT_VK_SUCCESS(err);
14068
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014069 char const *csSource = "#version 450\n"
14070 "\n"
14071 "layout(local_size_x=1) in;\n"
14072 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
14073 "void main() {\n"
14074 " x.x = 1.0f;\n"
14075 "}\n";
Chris Forbes22a9b092016-07-19 14:34:05 +120014076 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
14077
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014078 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
14079 nullptr,
14080 0,
14081 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
14082 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
14083 pl,
14084 VK_NULL_HANDLE,
14085 -1};
Chris Forbes22a9b092016-07-19 14:34:05 +120014086
14087 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014088 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes22a9b092016-07-19 14:34:05 +120014089
14090 m_errorMonitor->VerifyFound();
14091
14092 if (err == VK_SUCCESS) {
14093 vkDestroyPipeline(m_device->device(), pipe, nullptr);
14094 }
14095
14096 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
14097 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
14098}
14099
Chris Forbes50020592016-07-27 13:52:41 +120014100TEST_F(VkLayerTest, DrawTimeImageViewTypeMismatchWithPipeline) {
14101 TEST_DESCRIPTION("Test that an error is produced when an image view type "
14102 "does not match the dimensionality declared in the shader");
14103
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014104 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 +120014105
14106 ASSERT_NO_FATAL_FAILURE(InitState());
14107 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14108
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014109 char const *vsSource = "#version 450\n"
14110 "\n"
14111 "out gl_PerVertex { vec4 gl_Position; };\n"
14112 "void main() { gl_Position = vec4(0); }\n";
14113 char const *fsSource = "#version 450\n"
14114 "\n"
14115 "layout(set=0, binding=0) uniform sampler3D s;\n"
14116 "layout(location=0) out vec4 color;\n"
14117 "void main() {\n"
14118 " color = texture(s, vec3(0));\n"
14119 "}\n";
Chris Forbes50020592016-07-27 13:52:41 +120014120 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14121 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14122
14123 VkPipelineObj pipe(m_device);
14124 pipe.AddShader(&vs);
14125 pipe.AddShader(&fs);
14126 pipe.AddColorAttachment();
14127
14128 VkTextureObj texture(m_device, nullptr);
14129 VkSamplerObj sampler(m_device);
14130
14131 VkDescriptorSetObj descriptorSet(m_device);
14132 descriptorSet.AppendSamplerTexture(&sampler, &texture);
14133 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14134
14135 VkResult err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14136 ASSERT_VK_SUCCESS(err);
14137
14138 BeginCommandBuffer();
14139
14140 m_commandBuffer->BindPipeline(pipe);
14141 m_commandBuffer->BindDescriptorSet(descriptorSet);
14142
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014143 VkViewport viewport = {0, 0, 16, 16, 0, 1};
Chris Forbes50020592016-07-27 13:52:41 +120014144 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014145 VkRect2D scissor = {{0, 0}, {16, 16}};
Chris Forbes50020592016-07-27 13:52:41 +120014146 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
14147
14148 // error produced here.
14149 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
14150
14151 m_errorMonitor->VerifyFound();
14152
14153 EndCommandBuffer();
14154}
14155
Chris Forbes5533bfc2016-07-27 14:12:34 +120014156TEST_F(VkLayerTest, DrawTimeImageMultisampleMismatchWithPipeline) {
14157 TEST_DESCRIPTION("Test that an error is produced when a multisampled images "
14158 "are consumed via singlesample images types in the shader, or vice versa.");
14159
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014160 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "requires bound image to have multiple samples");
Chris Forbes5533bfc2016-07-27 14:12:34 +120014161
14162 ASSERT_NO_FATAL_FAILURE(InitState());
14163 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14164
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014165 char const *vsSource = "#version 450\n"
14166 "\n"
14167 "out gl_PerVertex { vec4 gl_Position; };\n"
14168 "void main() { gl_Position = vec4(0); }\n";
14169 char const *fsSource = "#version 450\n"
14170 "\n"
14171 "layout(set=0, binding=0) uniform sampler2DMS s;\n"
14172 "layout(location=0) out vec4 color;\n"
14173 "void main() {\n"
14174 " color = texelFetch(s, ivec2(0), 0);\n"
14175 "}\n";
Chris Forbes5533bfc2016-07-27 14:12:34 +120014176 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14177 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14178
14179 VkPipelineObj pipe(m_device);
14180 pipe.AddShader(&vs);
14181 pipe.AddShader(&fs);
14182 pipe.AddColorAttachment();
14183
14184 VkTextureObj texture(m_device, nullptr);
14185 VkSamplerObj sampler(m_device);
14186
14187 VkDescriptorSetObj descriptorSet(m_device);
14188 descriptorSet.AppendSamplerTexture(&sampler, &texture);
14189 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14190
14191 VkResult err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14192 ASSERT_VK_SUCCESS(err);
14193
14194 BeginCommandBuffer();
14195
14196 m_commandBuffer->BindPipeline(pipe);
14197 m_commandBuffer->BindDescriptorSet(descriptorSet);
14198
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014199 VkViewport viewport = {0, 0, 16, 16, 0, 1};
Chris Forbes5533bfc2016-07-27 14:12:34 +120014200 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014201 VkRect2D scissor = {{0, 0}, {16, 16}};
Chris Forbes5533bfc2016-07-27 14:12:34 +120014202 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
14203
14204 // error produced here.
14205 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
14206
14207 m_errorMonitor->VerifyFound();
14208
14209 EndCommandBuffer();
14210}
14211
Mark Lobodzinski209b5292015-09-17 09:44:05 -060014212#endif // SHADER_CHECKER_TESTS
14213
14214#if DEVICE_LIMITS_TESTS
Mark Youngc48c4c12016-04-11 14:26:49 -060014215TEST_F(VkLayerTest, CreateImageLimitsViolationMaxWidth) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014216 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "CreateImage extents exceed allowable limits for format");
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060014217
14218 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060014219
14220 // Create an image
14221 VkImage image;
14222
Karl Schultz6addd812016-02-02 17:17:23 -070014223 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
14224 const int32_t tex_width = 32;
14225 const int32_t tex_height = 32;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060014226
14227 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014228 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14229 image_create_info.pNext = NULL;
14230 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14231 image_create_info.format = tex_format;
14232 image_create_info.extent.width = tex_width;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060014233 image_create_info.extent.height = tex_height;
Karl Schultz6addd812016-02-02 17:17:23 -070014234 image_create_info.extent.depth = 1;
14235 image_create_info.mipLevels = 1;
14236 image_create_info.arrayLayers = 1;
14237 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14238 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
14239 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
14240 image_create_info.flags = 0;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060014241
14242 // Introduce error by sending down a bogus width extent
14243 image_create_info.extent.width = 65536;
Chia-I Wuf7458c52015-10-26 21:10:41 +080014244 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060014245
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014246 m_errorMonitor->VerifyFound();
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060014247}
14248
Mark Youngc48c4c12016-04-11 14:26:49 -060014249TEST_F(VkLayerTest, CreateImageLimitsViolationMinWidth) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014250 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14251 "CreateImage extents is 0 for at least one required dimension");
Mark Youngc48c4c12016-04-11 14:26:49 -060014252
14253 ASSERT_NO_FATAL_FAILURE(InitState());
14254
14255 // Create an image
14256 VkImage image;
14257
14258 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
14259 const int32_t tex_width = 32;
14260 const int32_t tex_height = 32;
14261
14262 VkImageCreateInfo image_create_info = {};
14263 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14264 image_create_info.pNext = NULL;
14265 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14266 image_create_info.format = tex_format;
14267 image_create_info.extent.width = tex_width;
14268 image_create_info.extent.height = tex_height;
14269 image_create_info.extent.depth = 1;
14270 image_create_info.mipLevels = 1;
14271 image_create_info.arrayLayers = 1;
14272 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14273 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
14274 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
14275 image_create_info.flags = 0;
14276
14277 // Introduce error by sending down a bogus width extent
14278 image_create_info.extent.width = 0;
14279 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
14280
14281 m_errorMonitor->VerifyFound();
14282}
Mark Lobodzinski209b5292015-09-17 09:44:05 -060014283#endif // DEVICE_LIMITS_TESTS
Chris Forbesa36d69e2015-05-25 11:13:44 +120014284
Tobin Ehliscde08892015-09-22 10:11:37 -060014285#if IMAGE_TESTS
Mark Lobodzinski66e5eab2016-11-15 13:30:38 -070014286
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060014287TEST_F(VkLayerTest, AttachmentDescriptionUndefinedFormat) {
14288 TEST_DESCRIPTION("Create a render pass with an attachment description "
14289 "format set to VK_FORMAT_UNDEFINED");
14290
14291 ASSERT_NO_FATAL_FAILURE(InitState());
14292 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14293
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014294 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "format is VK_FORMAT_UNDEFINED");
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060014295
14296 VkAttachmentReference color_attach = {};
14297 color_attach.layout = VK_IMAGE_LAYOUT_GENERAL;
14298 color_attach.attachment = 0;
14299 VkSubpassDescription subpass = {};
14300 subpass.colorAttachmentCount = 1;
14301 subpass.pColorAttachments = &color_attach;
14302
14303 VkRenderPassCreateInfo rpci = {};
14304 rpci.subpassCount = 1;
14305 rpci.pSubpasses = &subpass;
14306 rpci.attachmentCount = 1;
14307 VkAttachmentDescription attach_desc = {};
14308 attach_desc.format = VK_FORMAT_UNDEFINED;
14309 rpci.pAttachments = &attach_desc;
14310 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
14311 VkRenderPass rp;
14312 VkResult result = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
14313
14314 m_errorMonitor->VerifyFound();
14315
14316 if (result == VK_SUCCESS) {
14317 vkDestroyRenderPass(m_device->device(), rp, NULL);
14318 }
14319}
14320
Karl Schultz6addd812016-02-02 17:17:23 -070014321TEST_F(VkLayerTest, InvalidImageView) {
14322 VkResult err;
Tobin Ehliscde08892015-09-22 10:11:37 -060014323
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014324 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with baseMipLevel 10 ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014325
Tobin Ehliscde08892015-09-22 10:11:37 -060014326 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehliscde08892015-09-22 10:11:37 -060014327
Mike Stroyana3082432015-09-25 13:39:21 -060014328 // Create an image and try to create a view with bad baseMipLevel
Karl Schultz6addd812016-02-02 17:17:23 -070014329 VkImage image;
Tobin Ehliscde08892015-09-22 10:11:37 -060014330
Karl Schultz6addd812016-02-02 17:17:23 -070014331 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
14332 const int32_t tex_width = 32;
14333 const int32_t tex_height = 32;
Tobin Ehliscde08892015-09-22 10:11:37 -060014334
14335 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014336 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14337 image_create_info.pNext = NULL;
14338 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14339 image_create_info.format = tex_format;
14340 image_create_info.extent.width = tex_width;
14341 image_create_info.extent.height = tex_height;
14342 image_create_info.extent.depth = 1;
14343 image_create_info.mipLevels = 1;
14344 image_create_info.arrayLayers = 1;
14345 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14346 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
14347 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
14348 image_create_info.flags = 0;
Tobin Ehliscde08892015-09-22 10:11:37 -060014349
Chia-I Wuf7458c52015-10-26 21:10:41 +080014350 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehliscde08892015-09-22 10:11:37 -060014351 ASSERT_VK_SUCCESS(err);
14352
14353 VkImageViewCreateInfo image_view_create_info = {};
Chris Forbes53bef902016-11-28 17:53:04 +130014354 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070014355 image_view_create_info.image = image;
14356 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
14357 image_view_create_info.format = tex_format;
14358 image_view_create_info.subresourceRange.layerCount = 1;
14359 image_view_create_info.subresourceRange.baseMipLevel = 10; // cause an error
14360 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014361 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehliscde08892015-09-22 10:11:37 -060014362
14363 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014364 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehliscde08892015-09-22 10:11:37 -060014365
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014366 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -060014367 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehliscde08892015-09-22 10:11:37 -060014368}
Mike Stroyana3082432015-09-25 13:39:21 -060014369
Mark Youngd339ba32016-05-30 13:28:35 -060014370TEST_F(VkLayerTest, CreateImageViewNoMemoryBoundToImage) {
14371 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -060014372 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -060014373 " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Mark Youngd339ba32016-05-30 13:28:35 -060014374
14375 ASSERT_NO_FATAL_FAILURE(InitState());
14376
14377 // Create an image and try to create a view with no memory backing the image
14378 VkImage image;
14379
14380 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
14381 const int32_t tex_width = 32;
14382 const int32_t tex_height = 32;
14383
14384 VkImageCreateInfo image_create_info = {};
14385 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14386 image_create_info.pNext = NULL;
14387 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14388 image_create_info.format = tex_format;
14389 image_create_info.extent.width = tex_width;
14390 image_create_info.extent.height = tex_height;
14391 image_create_info.extent.depth = 1;
14392 image_create_info.mipLevels = 1;
14393 image_create_info.arrayLayers = 1;
14394 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14395 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
14396 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
14397 image_create_info.flags = 0;
14398
14399 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
14400 ASSERT_VK_SUCCESS(err);
14401
14402 VkImageViewCreateInfo image_view_create_info = {};
Chris Forbes53bef902016-11-28 17:53:04 +130014403 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Mark Youngd339ba32016-05-30 13:28:35 -060014404 image_view_create_info.image = image;
14405 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
14406 image_view_create_info.format = tex_format;
14407 image_view_create_info.subresourceRange.layerCount = 1;
14408 image_view_create_info.subresourceRange.baseMipLevel = 0;
14409 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014410 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Youngd339ba32016-05-30 13:28:35 -060014411
14412 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014413 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Youngd339ba32016-05-30 13:28:35 -060014414
14415 m_errorMonitor->VerifyFound();
14416 vkDestroyImage(m_device->device(), image, NULL);
14417 // If last error is success, it still created the view, so delete it.
14418 if (err == VK_SUCCESS) {
14419 vkDestroyImageView(m_device->device(), view, NULL);
14420 }
Mark Youngd339ba32016-05-30 13:28:35 -060014421}
14422
Karl Schultz6addd812016-02-02 17:17:23 -070014423TEST_F(VkLayerTest, InvalidImageViewAspect) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014424 TEST_DESCRIPTION("Create an image and try to create a view with an invalid aspectMask");
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060014425 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView(): Color image "
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014426 "formats must have ONLY the "
14427 "VK_IMAGE_ASPECT_COLOR_BIT set");
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060014428 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14429 "Color image formats must have the VK_IMAGE_ASPECT_COLOR_BIT set.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014430
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060014431 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060014432
Karl Schultz6addd812016-02-02 17:17:23 -070014433 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060014434 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014435 image.init(32, 32, tex_format, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_LINEAR, 0);
Tobin Ehlis1f567a22016-05-25 16:15:18 -060014436 ASSERT_TRUE(image.initialized());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060014437
14438 VkImageViewCreateInfo image_view_create_info = {};
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060014439 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060014440 image_view_create_info.image = image.handle();
Karl Schultz6addd812016-02-02 17:17:23 -070014441 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
14442 image_view_create_info.format = tex_format;
14443 image_view_create_info.subresourceRange.baseMipLevel = 0;
14444 image_view_create_info.subresourceRange.levelCount = 1;
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060014445 image_view_create_info.subresourceRange.layerCount = 1;
Karl Schultz6addd812016-02-02 17:17:23 -070014446 // Cause an error by setting an invalid image aspect
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014447 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060014448
14449 VkImageView view;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060014450 vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060014451
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014452 m_errorMonitor->VerifyFound();
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060014453}
14454
Mark Lobodzinskidb117632016-03-31 10:45:56 -060014455TEST_F(VkLayerTest, CopyImageLayerCountMismatch) {
Karl Schultz6addd812016-02-02 17:17:23 -070014456 VkResult err;
14457 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060014458
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014459 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14460 "vkCmdCopyImage: number of layers in source and destination subresources for pRegions");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014461
Mike Stroyana3082432015-09-25 13:39:21 -060014462 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060014463
14464 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070014465 VkImage srcImage;
14466 VkImage dstImage;
14467 VkDeviceMemory srcMem;
14468 VkDeviceMemory destMem;
14469 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060014470
14471 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014472 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14473 image_create_info.pNext = NULL;
14474 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14475 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
14476 image_create_info.extent.width = 32;
14477 image_create_info.extent.height = 32;
14478 image_create_info.extent.depth = 1;
14479 image_create_info.mipLevels = 1;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060014480 image_create_info.arrayLayers = 4;
Karl Schultz6addd812016-02-02 17:17:23 -070014481 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14482 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
14483 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
14484 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014485
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014486 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014487 ASSERT_VK_SUCCESS(err);
14488
Mark Lobodzinski867787a2016-10-14 11:49:55 -060014489 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014490 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014491 ASSERT_VK_SUCCESS(err);
14492
14493 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014494 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014495 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
14496 memAlloc.pNext = NULL;
14497 memAlloc.allocationSize = 0;
14498 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014499
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060014500 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014501 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014502 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014503 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014504 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014505 ASSERT_VK_SUCCESS(err);
14506
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014507 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014508 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014509 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060014510 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014511 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014512 ASSERT_VK_SUCCESS(err);
14513
14514 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
14515 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014516 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060014517 ASSERT_VK_SUCCESS(err);
14518
14519 BeginCommandBuffer();
14520 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014521 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014522 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060014523 copyRegion.srcSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060014524 copyRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060014525 copyRegion.srcOffset.x = 0;
14526 copyRegion.srcOffset.y = 0;
14527 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014528 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014529 copyRegion.dstSubresource.mipLevel = 0;
14530 copyRegion.dstSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060014531 // Introduce failure by forcing the dst layerCount to differ from src
14532 copyRegion.dstSubresource.layerCount = 3;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014533 copyRegion.dstOffset.x = 0;
14534 copyRegion.dstOffset.y = 0;
14535 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014536 copyRegion.extent.width = 1;
14537 copyRegion.extent.height = 1;
14538 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014539 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060014540 EndCommandBuffer();
14541
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014542 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060014543
Chia-I Wuf7458c52015-10-26 21:10:41 +080014544 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014545 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080014546 vkFreeMemory(m_device->device(), srcMem, NULL);
14547 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060014548}
14549
Tony Barbourd6673642016-05-05 14:46:39 -060014550TEST_F(VkLayerTest, ImageLayerUnsupportedFormat) {
14551
14552 TEST_DESCRIPTION("Creating images with unsuported formats ");
14553
14554 ASSERT_NO_FATAL_FAILURE(InitState());
14555 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14556 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014557 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 -060014558 VK_IMAGE_TILING_OPTIMAL, 0);
14559 ASSERT_TRUE(image.initialized());
14560
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014561 // Create image with unsupported format - Expect FORMAT_UNSUPPORTED
Chris Forbesf4d8e332016-11-28 17:51:10 +130014562 VkImageCreateInfo image_create_info = {};
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014563 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014564 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14565 image_create_info.format = VK_FORMAT_UNDEFINED;
14566 image_create_info.extent.width = 32;
14567 image_create_info.extent.height = 32;
14568 image_create_info.extent.depth = 1;
14569 image_create_info.mipLevels = 1;
14570 image_create_info.arrayLayers = 1;
14571 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14572 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
14573 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014574
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014575 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14576 "vkCreateImage: VkFormat for image must not be VK_FORMAT_UNDEFINED");
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014577
14578 VkImage localImage;
14579 vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage);
14580 m_errorMonitor->VerifyFound();
14581
Tony Barbourd6673642016-05-05 14:46:39 -060014582 VkFormat unsupported = VK_FORMAT_UNDEFINED;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014583 // Look for a format that is COMPLETELY unsupported with this hardware
Tony Barbourd6673642016-05-05 14:46:39 -060014584 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
14585 VkFormat format = static_cast<VkFormat>(f);
14586 VkFormatProperties fProps = m_device->format_properties(format);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014587 if (format != VK_FORMAT_UNDEFINED && fProps.linearTilingFeatures == 0 && fProps.optimalTilingFeatures == 0) {
Tony Barbourd6673642016-05-05 14:46:39 -060014588 unsupported = format;
14589 break;
14590 }
14591 }
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014592
Tony Barbourd6673642016-05-05 14:46:39 -060014593 if (unsupported != VK_FORMAT_UNDEFINED) {
Tony Barbourd6673642016-05-05 14:46:39 -060014594 image_create_info.format = unsupported;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014595 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is an unsupported format");
Tony Barbourd6673642016-05-05 14:46:39 -060014596
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014597 vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage);
Tony Barbourd6673642016-05-05 14:46:39 -060014598 m_errorMonitor->VerifyFound();
14599 }
14600}
14601
14602TEST_F(VkLayerTest, ImageLayerViewTests) {
14603 VkResult ret;
14604 TEST_DESCRIPTION("Passing bad parameters to CreateImageView");
14605
14606 ASSERT_NO_FATAL_FAILURE(InitState());
14607
14608 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014609 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 -060014610 VK_IMAGE_TILING_OPTIMAL, 0);
14611 ASSERT_TRUE(image.initialized());
14612
14613 VkImageView imgView;
14614 VkImageViewCreateInfo imgViewInfo = {};
14615 imgViewInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
14616 imgViewInfo.image = image.handle();
14617 imgViewInfo.viewType = VK_IMAGE_VIEW_TYPE_2D;
14618 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
14619 imgViewInfo.subresourceRange.layerCount = 1;
14620 imgViewInfo.subresourceRange.baseMipLevel = 0;
14621 imgViewInfo.subresourceRange.levelCount = 1;
14622 imgViewInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14623
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014624 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with baseMipLevel");
Tony Barbourd6673642016-05-05 14:46:39 -060014625 // View can't have baseMipLevel >= image's mipLevels - Expect
14626 // VIEW_CREATE_ERROR
14627 imgViewInfo.subresourceRange.baseMipLevel = 1;
14628 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14629 m_errorMonitor->VerifyFound();
14630 imgViewInfo.subresourceRange.baseMipLevel = 0;
14631
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014632 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with baseArrayLayer");
Tony Barbourd6673642016-05-05 14:46:39 -060014633 // View can't have baseArrayLayer >= image's arraySize - Expect
14634 // VIEW_CREATE_ERROR
14635 imgViewInfo.subresourceRange.baseArrayLayer = 1;
14636 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14637 m_errorMonitor->VerifyFound();
14638 imgViewInfo.subresourceRange.baseArrayLayer = 0;
14639
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014640 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with 0 in "
14641 "pCreateInfo->subresourceRange."
14642 "levelCount");
Tony Barbourd6673642016-05-05 14:46:39 -060014643 // View's levelCount can't be 0 - Expect VIEW_CREATE_ERROR
14644 imgViewInfo.subresourceRange.levelCount = 0;
14645 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14646 m_errorMonitor->VerifyFound();
14647 imgViewInfo.subresourceRange.levelCount = 1;
14648
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014649 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with 0 in "
14650 "pCreateInfo->subresourceRange."
14651 "layerCount");
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060014652 m_errorMonitor->SetDesiredFailureMsg(
14653 VK_DEBUG_REPORT_ERROR_BIT_EXT,
14654 "if pCreateInfo->viewType is VK_IMAGE_TYPE_2D, pCreateInfo->subresourceRange.layerCount must be 1");
Tony Barbourd6673642016-05-05 14:46:39 -060014655 // View's layerCount can't be 0 - Expect VIEW_CREATE_ERROR
14656 imgViewInfo.subresourceRange.layerCount = 0;
14657 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14658 m_errorMonitor->VerifyFound();
14659 imgViewInfo.subresourceRange.layerCount = 1;
14660
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014661 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "but both must be color formats");
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060014662 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Formats MUST be IDENTICAL unless "
14663 "VK_IMAGE_CREATE_MUTABLE_FORMAT BIT "
14664 "was set on image creation.");
Tony Barbourd6673642016-05-05 14:46:39 -060014665 // Can't use depth format for view into color image - Expect INVALID_FORMAT
14666 imgViewInfo.format = VK_FORMAT_D24_UNORM_S8_UINT;
14667 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14668 m_errorMonitor->VerifyFound();
14669 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
14670
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014671 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Formats MUST be IDENTICAL unless "
14672 "VK_IMAGE_CREATE_MUTABLE_FORMAT BIT "
14673 "was set on image creation.");
Tony Barbourd6673642016-05-05 14:46:39 -060014674 // Same compatibility class but no MUTABLE_FORMAT bit - Expect
14675 // VIEW_CREATE_ERROR
14676 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UINT;
14677 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14678 m_errorMonitor->VerifyFound();
14679 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
14680
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014681 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "can support ImageViews with "
14682 "differing formats but they must be "
14683 "in the same compatibility class.");
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060014684 // TODO: Update framework to easily passing mutable flag into ImageObj init
14685 // For now just allowing image for this one test to not have memory bound
14686 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14687 " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Tony Barbourd6673642016-05-05 14:46:39 -060014688 // Have MUTABLE_FORMAT bit but not in same compatibility class - Expect
14689 // VIEW_CREATE_ERROR
14690 VkImageCreateInfo mutImgInfo = image.create_info();
14691 VkImage mutImage;
14692 mutImgInfo.format = VK_FORMAT_R8_UINT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014693 assert(m_device->format_properties(VK_FORMAT_R8_UINT).optimalTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT);
Tony Barbourd6673642016-05-05 14:46:39 -060014694 mutImgInfo.flags = VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT;
14695 mutImgInfo.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
14696 ret = vkCreateImage(m_device->handle(), &mutImgInfo, NULL, &mutImage);
14697 ASSERT_VK_SUCCESS(ret);
14698 imgViewInfo.image = mutImage;
14699 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14700 m_errorMonitor->VerifyFound();
14701 imgViewInfo.image = image.handle();
14702 vkDestroyImage(m_device->handle(), mutImage, NULL);
14703}
14704
14705TEST_F(VkLayerTest, MiscImageLayerTests) {
14706
14707 TEST_DESCRIPTION("Image layer tests that don't belong elsewhare");
14708
14709 ASSERT_NO_FATAL_FAILURE(InitState());
14710
Rene Lindsay135204f2016-12-22 17:11:09 -070014711 // TODO: Ideally we should check if a format is supported, before using it.
Tony Barbourd6673642016-05-05 14:46:39 -060014712 VkImageObj image(m_device);
Rene Lindsay135204f2016-12-22 17:11:09 -070014713 image.init(128, 128, VK_FORMAT_R16G16B16A16_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
14714 VK_IMAGE_TILING_OPTIMAL, 0); // 64bpp
Tony Barbourd6673642016-05-05 14:46:39 -060014715 ASSERT_TRUE(image.initialized());
Tony Barbourd6673642016-05-05 14:46:39 -060014716 vk_testing::Buffer buffer;
14717 VkMemoryPropertyFlags reqs = 0;
Rene Lindsay135204f2016-12-22 17:11:09 -070014718 buffer.init_as_src(*m_device, 128 * 128 * 8, reqs);
Tony Barbourd6673642016-05-05 14:46:39 -060014719 VkBufferImageCopy region = {};
14720 region.bufferRowLength = 128;
14721 region.bufferImageHeight = 128;
14722 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14723 // layerCount can't be 0 - Expect MISMATCHED_IMAGE_ASPECT
Mark Lobodzinski3702e932016-11-22 11:40:48 -070014724 region.imageSubresource.layerCount = 1;
Tony Barbourd6673642016-05-05 14:46:39 -060014725 region.imageExtent.height = 4;
14726 region.imageExtent.width = 4;
14727 region.imageExtent.depth = 1;
Rene Lindsay135204f2016-12-22 17:11:09 -070014728
14729 VkImageObj image2(m_device);
14730 image2.init(128, 128, VK_FORMAT_R8G8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
14731 VK_IMAGE_TILING_OPTIMAL, 0); // 16bpp
14732 ASSERT_TRUE(image2.initialized());
14733 vk_testing::Buffer buffer2;
14734 VkMemoryPropertyFlags reqs2 = 0;
14735 buffer2.init_as_src(*m_device, 128 * 128 * 2, reqs2);
14736 VkBufferImageCopy region2 = {};
14737 region2.bufferRowLength = 128;
14738 region2.bufferImageHeight = 128;
14739 region2.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14740 // layerCount can't be 0 - Expect MISMATCHED_IMAGE_ASPECT
14741 region2.imageSubresource.layerCount = 1;
14742 region2.imageExtent.height = 4;
14743 region2.imageExtent.width = 4;
14744 region2.imageExtent.depth = 1;
Tony Barbourd6673642016-05-05 14:46:39 -060014745 m_commandBuffer->BeginCommandBuffer();
Tony Barbourd6673642016-05-05 14:46:39 -060014746
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070014747 // Image must have offset.z of 0 and extent.depth of 1
14748 // Introduce failure by setting imageExtent.depth to 0
14749 region.imageExtent.depth = 0;
14750 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01269);
14751 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
14752 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
14753 m_errorMonitor->VerifyFound();
14754
14755 region.imageExtent.depth = 1;
14756
14757 // Image must have offset.z of 0 and extent.depth of 1
14758 // Introduce failure by setting imageOffset.z to 4
14759 region.imageOffset.z = 4;
14760 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01269);
14761 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
14762 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
14763 m_errorMonitor->VerifyFound();
14764
14765 region.imageOffset.z = 0;
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060014766 // BufferOffset must be a multiple of the calling command's VkImage parameter's texel size
14767 // Introduce failure by setting bufferOffset to 1 and 1/2 texels
Rene Lindsay135204f2016-12-22 17:11:09 -070014768 region.bufferOffset = 4;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070014769 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01263);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014770 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
14771 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060014772 m_errorMonitor->VerifyFound();
14773
14774 // BufferOffset must be a multiple of 4
14775 // Introduce failure by setting bufferOffset to a value not divisible by 4
Rene Lindsay135204f2016-12-22 17:11:09 -070014776 region2.bufferOffset = 6;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070014777 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01264);
Rene Lindsay135204f2016-12-22 17:11:09 -070014778 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer2.handle(), image2.handle(),
14779 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region2);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060014780 m_errorMonitor->VerifyFound();
14781
14782 // BufferRowLength must be 0, or greater than or equal to the width member of imageExtent
14783 region.bufferOffset = 0;
14784 region.imageExtent.height = 128;
14785 region.imageExtent.width = 128;
14786 // Introduce failure by setting bufferRowLength > 0 but less than width
14787 region.bufferRowLength = 64;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070014788 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01265);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014789 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
14790 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060014791 m_errorMonitor->VerifyFound();
14792
14793 // BufferImageHeight must be 0, or greater than or equal to the height member of imageExtent
14794 region.bufferRowLength = 128;
14795 // Introduce failure by setting bufferRowHeight > 0 but less than height
14796 region.bufferImageHeight = 64;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070014797 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01266);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014798 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
14799 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060014800 m_errorMonitor->VerifyFound();
14801
14802 region.bufferImageHeight = 128;
Dave Houlton34df4cb2016-12-01 16:43:06 -070014803 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "If the format of srcImage is an "
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014804 "integer-based format then filter must be VK_FILTER_NEAREST");
Tony Barbourd6673642016-05-05 14:46:39 -060014805 // Expect INVALID_FILTER
14806 VkImageObj intImage1(m_device);
Rene Lindsaya35e1cb2016-12-26 10:30:05 -070014807 intImage1.init(128, 128, VK_FORMAT_R8_UINT, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT,
14808 VK_IMAGE_TILING_OPTIMAL, 0);
Tony Barbourd6673642016-05-05 14:46:39 -060014809 VkImageObj intImage2(m_device);
Rene Lindsaya35e1cb2016-12-26 10:30:05 -070014810 intImage2.init(128, 128, VK_FORMAT_R8_UINT, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
14811 VK_IMAGE_TILING_OPTIMAL, 0);
Tony Barbourd6673642016-05-05 14:46:39 -060014812 VkImageBlit blitRegion = {};
14813 blitRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14814 blitRegion.srcSubresource.baseArrayLayer = 0;
14815 blitRegion.srcSubresource.layerCount = 1;
14816 blitRegion.srcSubresource.mipLevel = 0;
14817 blitRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14818 blitRegion.dstSubresource.baseArrayLayer = 0;
14819 blitRegion.dstSubresource.layerCount = 1;
14820 blitRegion.dstSubresource.mipLevel = 0;
14821
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014822 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), intImage1.handle(), intImage1.layout(), intImage2.handle(),
Rene Lindsaya35e1cb2016-12-26 10:30:05 -070014823 intImage2.layout(), 1, &blitRegion, VK_FILTER_LINEAR);
Tony Barbourd6673642016-05-05 14:46:39 -060014824 m_errorMonitor->VerifyFound();
14825
Mark Lobodzinskib02ea642016-08-17 13:03:57 -060014826 // Look for NULL-blit warning
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014827 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "Offsets specify a zero-volume area.");
14828 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), intImage1.handle(), intImage1.layout(), intImage2.handle(),
14829 intImage2.layout(), 1, &blitRegion, VK_FILTER_LINEAR);
Mark Lobodzinskib02ea642016-08-17 13:03:57 -060014830 m_errorMonitor->VerifyFound();
14831
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014832 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with 0 in ppMemoryBarriers");
Tony Barbourd6673642016-05-05 14:46:39 -060014833 VkImageMemoryBarrier img_barrier;
14834 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
14835 img_barrier.pNext = NULL;
14836 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
14837 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
14838 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
14839 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
14840 img_barrier.image = image.handle();
14841 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
14842 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
14843 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14844 img_barrier.subresourceRange.baseArrayLayer = 0;
14845 img_barrier.subresourceRange.baseMipLevel = 0;
14846 // layerCount should not be 0 - Expect INVALID_IMAGE_RESOURCE
14847 img_barrier.subresourceRange.layerCount = 0;
14848 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014849 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
14850 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbourd6673642016-05-05 14:46:39 -060014851 m_errorMonitor->VerifyFound();
14852 img_barrier.subresourceRange.layerCount = 1;
14853}
14854
14855TEST_F(VkLayerTest, ImageFormatLimits) {
14856
14857 TEST_DESCRIPTION("Exceed the limits of image format ");
14858
Cody Northropc31a84f2016-08-22 10:41:47 -060014859 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014860 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "CreateImage extents exceed allowable limits for format");
Tony Barbourd6673642016-05-05 14:46:39 -060014861 VkImageCreateInfo image_create_info = {};
14862 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14863 image_create_info.pNext = NULL;
14864 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14865 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
14866 image_create_info.extent.width = 32;
14867 image_create_info.extent.height = 32;
14868 image_create_info.extent.depth = 1;
14869 image_create_info.mipLevels = 1;
14870 image_create_info.arrayLayers = 1;
14871 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14872 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
14873 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
14874 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
14875 image_create_info.flags = 0;
14876
14877 VkImage nullImg;
14878 VkImageFormatProperties imgFmtProps;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014879 vkGetPhysicalDeviceImageFormatProperties(gpu(), image_create_info.format, image_create_info.imageType, image_create_info.tiling,
14880 image_create_info.usage, image_create_info.flags, &imgFmtProps);
Tony Barbourd6673642016-05-05 14:46:39 -060014881 image_create_info.extent.depth = imgFmtProps.maxExtent.depth + 1;
14882 // Expect INVALID_FORMAT_LIMITS_VIOLATION
14883 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
14884 m_errorMonitor->VerifyFound();
14885 image_create_info.extent.depth = 1;
14886
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014887 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "exceeds allowable maximum supported by format of");
Tony Barbourd6673642016-05-05 14:46:39 -060014888 image_create_info.mipLevels = imgFmtProps.maxMipLevels + 1;
14889 // Expect INVALID_FORMAT_LIMITS_VIOLATION
14890 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
14891 m_errorMonitor->VerifyFound();
14892 image_create_info.mipLevels = 1;
14893
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014894 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "exceeds allowable maximum supported by format of");
Tony Barbourd6673642016-05-05 14:46:39 -060014895 image_create_info.arrayLayers = imgFmtProps.maxArrayLayers + 1;
14896 // Expect INVALID_FORMAT_LIMITS_VIOLATION
14897 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
14898 m_errorMonitor->VerifyFound();
14899 image_create_info.arrayLayers = 1;
14900
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014901 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is not supported by format");
Tony Barbourd6673642016-05-05 14:46:39 -060014902 int samples = imgFmtProps.sampleCounts >> 1;
14903 image_create_info.samples = (VkSampleCountFlagBits)samples;
14904 // Expect INVALID_FORMAT_LIMITS_VIOLATION
14905 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
14906 m_errorMonitor->VerifyFound();
14907 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14908
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014909 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "pCreateInfo->initialLayout, must be "
14910 "VK_IMAGE_LAYOUT_UNDEFINED or "
14911 "VK_IMAGE_LAYOUT_PREINITIALIZED");
Tony Barbourd6673642016-05-05 14:46:39 -060014912 image_create_info.initialLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
14913 // Expect INVALID_LAYOUT
14914 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
14915 m_errorMonitor->VerifyFound();
14916 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
14917}
14918
Mark Lobodzinskicea14992016-10-14 10:59:42 -060014919TEST_F(VkLayerTest, CopyImageSrcSizeExceeded) {
14920
14921 // Image copy with source region specified greater than src image size
Mark Lobodzinski629d47b2016-10-18 13:34:58 -060014922 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01175);
Mark Lobodzinskicea14992016-10-14 10:59:42 -060014923
14924 ASSERT_NO_FATAL_FAILURE(InitState());
14925
14926 VkImageObj src_image(m_device);
14927 src_image.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_LINEAR, 0);
14928 VkImageObj dst_image(m_device);
14929 dst_image.init(64, 64, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
14930
14931 BeginCommandBuffer();
14932 VkImageCopy copy_region;
14933 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14934 copy_region.srcSubresource.mipLevel = 0;
14935 copy_region.srcSubresource.baseArrayLayer = 0;
14936 copy_region.srcSubresource.layerCount = 0;
14937 copy_region.srcOffset.x = 0;
14938 copy_region.srcOffset.y = 0;
14939 copy_region.srcOffset.z = 0;
14940 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14941 copy_region.dstSubresource.mipLevel = 0;
14942 copy_region.dstSubresource.baseArrayLayer = 0;
14943 copy_region.dstSubresource.layerCount = 0;
14944 copy_region.dstOffset.x = 0;
14945 copy_region.dstOffset.y = 0;
14946 copy_region.dstOffset.z = 0;
14947 copy_region.extent.width = 64;
14948 copy_region.extent.height = 64;
14949 copy_region.extent.depth = 1;
14950 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
14951 &copy_region);
14952 EndCommandBuffer();
14953
14954 m_errorMonitor->VerifyFound();
14955}
14956
14957TEST_F(VkLayerTest, CopyImageDstSizeExceeded) {
14958
14959 // Image copy with dest region specified greater than dest image size
Mark Lobodzinski629d47b2016-10-18 13:34:58 -060014960 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01176);
Mark Lobodzinskicea14992016-10-14 10:59:42 -060014961
14962 ASSERT_NO_FATAL_FAILURE(InitState());
14963
14964 VkImageObj src_image(m_device);
14965 src_image.init(64, 64, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_LINEAR, 0);
14966 VkImageObj dst_image(m_device);
14967 dst_image.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
14968
14969 BeginCommandBuffer();
14970 VkImageCopy copy_region;
14971 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14972 copy_region.srcSubresource.mipLevel = 0;
14973 copy_region.srcSubresource.baseArrayLayer = 0;
14974 copy_region.srcSubresource.layerCount = 0;
14975 copy_region.srcOffset.x = 0;
14976 copy_region.srcOffset.y = 0;
14977 copy_region.srcOffset.z = 0;
14978 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14979 copy_region.dstSubresource.mipLevel = 0;
14980 copy_region.dstSubresource.baseArrayLayer = 0;
14981 copy_region.dstSubresource.layerCount = 0;
14982 copy_region.dstOffset.x = 0;
14983 copy_region.dstOffset.y = 0;
14984 copy_region.dstOffset.z = 0;
14985 copy_region.extent.width = 64;
14986 copy_region.extent.height = 64;
14987 copy_region.extent.depth = 1;
14988 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
14989 &copy_region);
14990 EndCommandBuffer();
14991
14992 m_errorMonitor->VerifyFound();
14993}
14994
Karl Schultz6addd812016-02-02 17:17:23 -070014995TEST_F(VkLayerTest, CopyImageFormatSizeMismatch) {
Karl Schultzbdb75952016-04-19 11:36:49 -060014996 VkResult err;
14997 bool pass;
14998
14999 // Create color images with different format sizes and try to copy between them
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015000 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15001 "vkCmdCopyImage called with unmatched source and dest image format sizes");
Karl Schultzbdb75952016-04-19 11:36:49 -060015002
15003 ASSERT_NO_FATAL_FAILURE(InitState());
15004
15005 // Create two images of different types and try to copy between them
15006 VkImage srcImage;
15007 VkImage dstImage;
15008 VkDeviceMemory srcMem;
15009 VkDeviceMemory destMem;
15010 VkMemoryRequirements memReqs;
15011
15012 VkImageCreateInfo image_create_info = {};
15013 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15014 image_create_info.pNext = NULL;
15015 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15016 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
15017 image_create_info.extent.width = 32;
15018 image_create_info.extent.height = 32;
15019 image_create_info.extent.depth = 1;
15020 image_create_info.mipLevels = 1;
15021 image_create_info.arrayLayers = 1;
15022 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15023 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15024 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
15025 image_create_info.flags = 0;
15026
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015027 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Karl Schultzbdb75952016-04-19 11:36:49 -060015028 ASSERT_VK_SUCCESS(err);
15029
15030 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
15031 // Introduce failure by creating second image with a different-sized format.
15032 image_create_info.format = VK_FORMAT_R5G5B5A1_UNORM_PACK16;
15033
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015034 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Karl Schultzbdb75952016-04-19 11:36:49 -060015035 ASSERT_VK_SUCCESS(err);
15036
15037 // Allocate memory
15038 VkMemoryAllocateInfo memAlloc = {};
15039 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15040 memAlloc.pNext = NULL;
15041 memAlloc.allocationSize = 0;
15042 memAlloc.memoryTypeIndex = 0;
15043
15044 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
15045 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015046 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -060015047 ASSERT_TRUE(pass);
15048 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
15049 ASSERT_VK_SUCCESS(err);
15050
15051 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
15052 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015053 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -060015054 ASSERT_TRUE(pass);
15055 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
15056 ASSERT_VK_SUCCESS(err);
15057
15058 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
15059 ASSERT_VK_SUCCESS(err);
15060 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
15061 ASSERT_VK_SUCCESS(err);
15062
15063 BeginCommandBuffer();
15064 VkImageCopy copyRegion;
15065 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15066 copyRegion.srcSubresource.mipLevel = 0;
15067 copyRegion.srcSubresource.baseArrayLayer = 0;
15068 copyRegion.srcSubresource.layerCount = 0;
15069 copyRegion.srcOffset.x = 0;
15070 copyRegion.srcOffset.y = 0;
15071 copyRegion.srcOffset.z = 0;
15072 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15073 copyRegion.dstSubresource.mipLevel = 0;
15074 copyRegion.dstSubresource.baseArrayLayer = 0;
15075 copyRegion.dstSubresource.layerCount = 0;
15076 copyRegion.dstOffset.x = 0;
15077 copyRegion.dstOffset.y = 0;
15078 copyRegion.dstOffset.z = 0;
15079 copyRegion.extent.width = 1;
15080 copyRegion.extent.height = 1;
15081 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015082 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Karl Schultzbdb75952016-04-19 11:36:49 -060015083 EndCommandBuffer();
15084
15085 m_errorMonitor->VerifyFound();
15086
15087 vkDestroyImage(m_device->device(), srcImage, NULL);
15088 vkDestroyImage(m_device->device(), dstImage, NULL);
15089 vkFreeMemory(m_device->device(), srcMem, NULL);
15090 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060015091}
15092
Karl Schultz6addd812016-02-02 17:17:23 -070015093TEST_F(VkLayerTest, CopyImageDepthStencilFormatMismatch) {
15094 VkResult err;
15095 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060015096
Mark Lobodzinskidb117632016-03-31 10:45:56 -060015097 // Create a color image and a depth/stencil image and try to copy between them
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015098 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15099 "vkCmdCopyImage called with unmatched source and dest image depth");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015100
Mike Stroyana3082432015-09-25 13:39:21 -060015101 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060015102
15103 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070015104 VkImage srcImage;
15105 VkImage dstImage;
15106 VkDeviceMemory srcMem;
15107 VkDeviceMemory destMem;
15108 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060015109
15110 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015111 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15112 image_create_info.pNext = NULL;
15113 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15114 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
15115 image_create_info.extent.width = 32;
15116 image_create_info.extent.height = 32;
15117 image_create_info.extent.depth = 1;
15118 image_create_info.mipLevels = 1;
15119 image_create_info.arrayLayers = 1;
15120 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15121 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15122 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
15123 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015124
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015125 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015126 ASSERT_VK_SUCCESS(err);
15127
Karl Schultzbdb75952016-04-19 11:36:49 -060015128 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
15129
Mark Lobodzinskidb117632016-03-31 10:45:56 -060015130 // Introduce failure by creating second image with a depth/stencil format
Karl Schultz6addd812016-02-02 17:17:23 -070015131 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060015132 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
Mark Lobodzinski867787a2016-10-14 11:49:55 -060015133 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015134
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015135 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015136 ASSERT_VK_SUCCESS(err);
15137
15138 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015139 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015140 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15141 memAlloc.pNext = NULL;
15142 memAlloc.allocationSize = 0;
15143 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015144
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060015145 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015146 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015147 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015148 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015149 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015150 ASSERT_VK_SUCCESS(err);
15151
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015152 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015153 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015154 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015155 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015156 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015157 ASSERT_VK_SUCCESS(err);
15158
15159 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
15160 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015161 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060015162 ASSERT_VK_SUCCESS(err);
15163
15164 BeginCommandBuffer();
15165 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015166 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015167 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060015168 copyRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015169 copyRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015170 copyRegion.srcOffset.x = 0;
15171 copyRegion.srcOffset.y = 0;
15172 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015173 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015174 copyRegion.dstSubresource.mipLevel = 0;
15175 copyRegion.dstSubresource.baseArrayLayer = 0;
15176 copyRegion.dstSubresource.layerCount = 0;
15177 copyRegion.dstOffset.x = 0;
15178 copyRegion.dstOffset.y = 0;
15179 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015180 copyRegion.extent.width = 1;
15181 copyRegion.extent.height = 1;
15182 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015183 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060015184 EndCommandBuffer();
15185
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015186 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060015187
Chia-I Wuf7458c52015-10-26 21:10:41 +080015188 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015189 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080015190 vkFreeMemory(m_device->device(), srcMem, NULL);
15191 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060015192}
15193
Karl Schultz6addd812016-02-02 17:17:23 -070015194TEST_F(VkLayerTest, ResolveImageLowSampleCount) {
15195 VkResult err;
15196 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060015197
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015198 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15199 "vkCmdResolveImage called with source sample count less than 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015200
Mike Stroyana3082432015-09-25 13:39:21 -060015201 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060015202
15203 // Create two images of sample count 1 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070015204 VkImage srcImage;
15205 VkImage dstImage;
15206 VkDeviceMemory srcMem;
15207 VkDeviceMemory destMem;
15208 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060015209
15210 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015211 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15212 image_create_info.pNext = NULL;
15213 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15214 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
15215 image_create_info.extent.width = 32;
15216 image_create_info.extent.height = 1;
15217 image_create_info.extent.depth = 1;
15218 image_create_info.mipLevels = 1;
15219 image_create_info.arrayLayers = 1;
15220 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15221 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15222 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
15223 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015224
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015225 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015226 ASSERT_VK_SUCCESS(err);
15227
Karl Schultz6addd812016-02-02 17:17:23 -070015228 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015229
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015230 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015231 ASSERT_VK_SUCCESS(err);
15232
15233 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015234 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015235 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15236 memAlloc.pNext = NULL;
15237 memAlloc.allocationSize = 0;
15238 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015239
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060015240 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015241 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015242 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015243 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015244 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015245 ASSERT_VK_SUCCESS(err);
15246
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015247 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015248 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015249 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015250 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015251 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015252 ASSERT_VK_SUCCESS(err);
15253
15254 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
15255 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015256 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060015257 ASSERT_VK_SUCCESS(err);
15258
15259 BeginCommandBuffer();
15260 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070015261 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
15262 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060015263 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015264 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015265 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060015266 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130015267 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060015268 resolveRegion.srcOffset.x = 0;
15269 resolveRegion.srcOffset.y = 0;
15270 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015271 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015272 resolveRegion.dstSubresource.mipLevel = 0;
15273 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130015274 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015275 resolveRegion.dstOffset.x = 0;
15276 resolveRegion.dstOffset.y = 0;
15277 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015278 resolveRegion.extent.width = 1;
15279 resolveRegion.extent.height = 1;
15280 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015281 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060015282 EndCommandBuffer();
15283
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015284 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060015285
Chia-I Wuf7458c52015-10-26 21:10:41 +080015286 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015287 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080015288 vkFreeMemory(m_device->device(), srcMem, NULL);
15289 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060015290}
15291
Karl Schultz6addd812016-02-02 17:17:23 -070015292TEST_F(VkLayerTest, ResolveImageHighSampleCount) {
15293 VkResult err;
15294 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060015295
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015296 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15297 "vkCmdResolveImage called with dest sample count greater than 1.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015298
Mike Stroyana3082432015-09-25 13:39:21 -060015299 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060015300
Chris Forbesa7530692016-05-08 12:35:39 +120015301 // Create two images of sample count 4 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070015302 VkImage srcImage;
15303 VkImage dstImage;
15304 VkDeviceMemory srcMem;
15305 VkDeviceMemory destMem;
15306 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060015307
15308 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015309 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15310 image_create_info.pNext = NULL;
15311 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15312 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
15313 image_create_info.extent.width = 32;
15314 image_create_info.extent.height = 1;
15315 image_create_info.extent.depth = 1;
15316 image_create_info.mipLevels = 1;
15317 image_create_info.arrayLayers = 1;
Chris Forbesa7530692016-05-08 12:35:39 +120015318 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070015319 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15320 // Note: Some implementations expect color attachment usage for any
15321 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015322 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070015323 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015324
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015325 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015326 ASSERT_VK_SUCCESS(err);
15327
Karl Schultz6addd812016-02-02 17:17:23 -070015328 // Note: Some implementations expect color attachment usage for any
15329 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015330 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015331
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015332 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015333 ASSERT_VK_SUCCESS(err);
15334
15335 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015336 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015337 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15338 memAlloc.pNext = NULL;
15339 memAlloc.allocationSize = 0;
15340 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015341
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060015342 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015343 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015344 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015345 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015346 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015347 ASSERT_VK_SUCCESS(err);
15348
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015349 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015350 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015351 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015352 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015353 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015354 ASSERT_VK_SUCCESS(err);
15355
15356 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
15357 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015358 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060015359 ASSERT_VK_SUCCESS(err);
15360
15361 BeginCommandBuffer();
15362 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070015363 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
15364 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060015365 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015366 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015367 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060015368 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130015369 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060015370 resolveRegion.srcOffset.x = 0;
15371 resolveRegion.srcOffset.y = 0;
15372 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015373 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015374 resolveRegion.dstSubresource.mipLevel = 0;
15375 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130015376 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015377 resolveRegion.dstOffset.x = 0;
15378 resolveRegion.dstOffset.y = 0;
15379 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015380 resolveRegion.extent.width = 1;
15381 resolveRegion.extent.height = 1;
15382 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015383 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060015384 EndCommandBuffer();
15385
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015386 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060015387
Chia-I Wuf7458c52015-10-26 21:10:41 +080015388 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015389 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080015390 vkFreeMemory(m_device->device(), srcMem, NULL);
15391 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060015392}
15393
Karl Schultz6addd812016-02-02 17:17:23 -070015394TEST_F(VkLayerTest, ResolveImageFormatMismatch) {
15395 VkResult err;
15396 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060015397
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015398 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15399 "vkCmdResolveImage called with unmatched source and dest formats.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015400
Mike Stroyana3082432015-09-25 13:39:21 -060015401 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060015402
15403 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070015404 VkImage srcImage;
15405 VkImage dstImage;
15406 VkDeviceMemory srcMem;
15407 VkDeviceMemory destMem;
15408 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060015409
15410 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015411 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15412 image_create_info.pNext = NULL;
15413 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15414 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
15415 image_create_info.extent.width = 32;
15416 image_create_info.extent.height = 1;
15417 image_create_info.extent.depth = 1;
15418 image_create_info.mipLevels = 1;
15419 image_create_info.arrayLayers = 1;
15420 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
15421 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15422 // Note: Some implementations expect color attachment usage for any
15423 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015424 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070015425 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015426
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015427 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015428 ASSERT_VK_SUCCESS(err);
15429
Karl Schultz6addd812016-02-02 17:17:23 -070015430 // Set format to something other than source image
15431 image_create_info.format = VK_FORMAT_R32_SFLOAT;
15432 // Note: Some implementations expect color attachment usage for any
15433 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015434 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070015435 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015436
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015437 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015438 ASSERT_VK_SUCCESS(err);
15439
15440 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015441 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015442 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15443 memAlloc.pNext = NULL;
15444 memAlloc.allocationSize = 0;
15445 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015446
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060015447 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015448 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015449 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015450 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015451 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015452 ASSERT_VK_SUCCESS(err);
15453
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015454 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015455 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015456 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015457 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015458 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015459 ASSERT_VK_SUCCESS(err);
15460
15461 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
15462 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015463 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060015464 ASSERT_VK_SUCCESS(err);
15465
15466 BeginCommandBuffer();
15467 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070015468 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
15469 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060015470 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015471 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015472 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060015473 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130015474 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060015475 resolveRegion.srcOffset.x = 0;
15476 resolveRegion.srcOffset.y = 0;
15477 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015478 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015479 resolveRegion.dstSubresource.mipLevel = 0;
15480 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130015481 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015482 resolveRegion.dstOffset.x = 0;
15483 resolveRegion.dstOffset.y = 0;
15484 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015485 resolveRegion.extent.width = 1;
15486 resolveRegion.extent.height = 1;
15487 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015488 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060015489 EndCommandBuffer();
15490
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015491 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060015492
Chia-I Wuf7458c52015-10-26 21:10:41 +080015493 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015494 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080015495 vkFreeMemory(m_device->device(), srcMem, NULL);
15496 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060015497}
15498
Karl Schultz6addd812016-02-02 17:17:23 -070015499TEST_F(VkLayerTest, ResolveImageTypeMismatch) {
15500 VkResult err;
15501 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060015502
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015503 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15504 "vkCmdResolveImage called with unmatched source and dest image types.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015505
Mike Stroyana3082432015-09-25 13:39:21 -060015506 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060015507
15508 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070015509 VkImage srcImage;
15510 VkImage dstImage;
15511 VkDeviceMemory srcMem;
15512 VkDeviceMemory destMem;
15513 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060015514
15515 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015516 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15517 image_create_info.pNext = NULL;
15518 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15519 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
15520 image_create_info.extent.width = 32;
15521 image_create_info.extent.height = 1;
15522 image_create_info.extent.depth = 1;
15523 image_create_info.mipLevels = 1;
15524 image_create_info.arrayLayers = 1;
15525 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
15526 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15527 // Note: Some implementations expect color attachment usage for any
15528 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015529 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070015530 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015531
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015532 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015533 ASSERT_VK_SUCCESS(err);
15534
Karl Schultz6addd812016-02-02 17:17:23 -070015535 image_create_info.imageType = VK_IMAGE_TYPE_1D;
15536 // Note: Some implementations expect color attachment usage for any
15537 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015538 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070015539 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015540
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015541 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015542 ASSERT_VK_SUCCESS(err);
15543
15544 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015545 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015546 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15547 memAlloc.pNext = NULL;
15548 memAlloc.allocationSize = 0;
15549 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015550
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060015551 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015552 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015553 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015554 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015555 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015556 ASSERT_VK_SUCCESS(err);
15557
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015558 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015559 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015560 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015561 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015562 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015563 ASSERT_VK_SUCCESS(err);
15564
15565 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
15566 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015567 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060015568 ASSERT_VK_SUCCESS(err);
15569
15570 BeginCommandBuffer();
15571 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070015572 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
15573 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060015574 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015575 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015576 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060015577 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130015578 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060015579 resolveRegion.srcOffset.x = 0;
15580 resolveRegion.srcOffset.y = 0;
15581 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015582 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015583 resolveRegion.dstSubresource.mipLevel = 0;
15584 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130015585 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015586 resolveRegion.dstOffset.x = 0;
15587 resolveRegion.dstOffset.y = 0;
15588 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015589 resolveRegion.extent.width = 1;
15590 resolveRegion.extent.height = 1;
15591 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015592 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060015593 EndCommandBuffer();
15594
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015595 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060015596
Chia-I Wuf7458c52015-10-26 21:10:41 +080015597 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015598 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080015599 vkFreeMemory(m_device->device(), srcMem, NULL);
15600 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060015601}
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015602
Karl Schultz6addd812016-02-02 17:17:23 -070015603TEST_F(VkLayerTest, DepthStencilImageViewWithColorAspectBitError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015604 // Create a single Image descriptor and cause it to first hit an error due
Karl Schultz6addd812016-02-02 17:17:23 -070015605 // to using a DS format, then cause it to hit error due to COLOR_BIT not
15606 // set in aspect
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015607 // The image format check comes 2nd in validation so we trigger it first,
15608 // then when we cause aspect fail next, bad format check will be preempted
Karl Schultz6addd812016-02-02 17:17:23 -070015609 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015610
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015611 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15612 "Combination depth/stencil image formats can have only the ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015613
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015614 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015615
Chia-I Wu1b99bb22015-10-27 19:25:11 +080015616 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015617 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
15618 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015619
15620 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015621 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
15622 ds_pool_ci.pNext = NULL;
15623 ds_pool_ci.maxSets = 1;
15624 ds_pool_ci.poolSizeCount = 1;
15625 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015626
15627 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015628 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015629 ASSERT_VK_SUCCESS(err);
15630
15631 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015632 dsl_binding.binding = 0;
15633 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
15634 dsl_binding.descriptorCount = 1;
15635 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
15636 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015637
15638 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015639 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
15640 ds_layout_ci.pNext = NULL;
15641 ds_layout_ci.bindingCount = 1;
15642 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015643 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015644 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015645 ASSERT_VK_SUCCESS(err);
15646
15647 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015648 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080015649 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070015650 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015651 alloc_info.descriptorPool = ds_pool;
15652 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015653 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015654 ASSERT_VK_SUCCESS(err);
15655
Karl Schultz6addd812016-02-02 17:17:23 -070015656 VkImage image_bad;
15657 VkImage image_good;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015658 // One bad format and one good format for Color attachment
Tobin Ehlis269f0322016-05-25 16:24:21 -060015659 const VkFormat tex_format_bad = VK_FORMAT_D24_UNORM_S8_UINT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015660 const VkFormat tex_format_good = VK_FORMAT_B8G8R8A8_UNORM;
Karl Schultz6addd812016-02-02 17:17:23 -070015661 const int32_t tex_width = 32;
15662 const int32_t tex_height = 32;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015663
15664 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015665 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15666 image_create_info.pNext = NULL;
15667 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15668 image_create_info.format = tex_format_bad;
15669 image_create_info.extent.width = tex_width;
15670 image_create_info.extent.height = tex_height;
15671 image_create_info.extent.depth = 1;
15672 image_create_info.mipLevels = 1;
15673 image_create_info.arrayLayers = 1;
15674 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15675 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015676 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070015677 image_create_info.flags = 0;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015678
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015679 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_bad);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015680 ASSERT_VK_SUCCESS(err);
15681 image_create_info.format = tex_format_good;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015682 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
15683 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_good);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015684 ASSERT_VK_SUCCESS(err);
15685
Rene Lindsayf1e89c82016-12-28 13:18:31 -070015686 // ---Bind image memory---
15687 VkMemoryRequirements img_mem_reqs;
15688 vkGetImageMemoryRequirements(m_device->device(), image_bad, &img_mem_reqs);
15689 VkMemoryAllocateInfo image_alloc_info = {};
15690 image_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15691 image_alloc_info.pNext = NULL;
15692 image_alloc_info.memoryTypeIndex = 0;
15693 image_alloc_info.allocationSize = img_mem_reqs.size;
15694 bool pass = m_device->phy().set_memory_type(img_mem_reqs.memoryTypeBits, &image_alloc_info, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
15695 ASSERT_TRUE(pass);
15696 VkDeviceMemory mem;
15697 err = vkAllocateMemory(m_device->device(), &image_alloc_info, NULL, &mem);
15698 ASSERT_VK_SUCCESS(err);
15699 err = vkBindImageMemory(m_device->device(), image_bad, mem, 0);
15700 ASSERT_VK_SUCCESS(err);
15701 // -----------------------
15702
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015703 VkImageViewCreateInfo image_view_create_info = {};
Chris Forbes53bef902016-11-28 17:53:04 +130015704 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070015705 image_view_create_info.image = image_bad;
15706 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
15707 image_view_create_info.format = tex_format_bad;
15708 image_view_create_info.subresourceRange.baseArrayLayer = 0;
15709 image_view_create_info.subresourceRange.baseMipLevel = 0;
15710 image_view_create_info.subresourceRange.layerCount = 1;
15711 image_view_create_info.subresourceRange.levelCount = 1;
Rene Lindsayf1e89c82016-12-28 13:18:31 -070015712 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_DEPTH_BIT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015713
15714 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015715 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015716
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015717 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015718
Chia-I Wuf7458c52015-10-26 21:10:41 +080015719 vkDestroyImage(m_device->device(), image_bad, NULL);
15720 vkDestroyImage(m_device->device(), image_good, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080015721 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
15722 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Rene Lindsayf1e89c82016-12-28 13:18:31 -070015723
15724 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015725}
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015726
15727TEST_F(VkLayerTest, ClearImageErrors) {
15728 TEST_DESCRIPTION("Call ClearColorImage w/ a depth|stencil image and "
15729 "ClearDepthStencilImage with a color image.");
15730
15731 ASSERT_NO_FATAL_FAILURE(InitState());
15732 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15733
15734 // Renderpass is started here so end it as Clear cmds can't be in renderpass
15735 BeginCommandBuffer();
15736 m_commandBuffer->EndRenderPass();
15737
15738 // Color image
15739 VkClearColorValue clear_color;
15740 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
15741 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
15742 const VkFormat color_format = VK_FORMAT_B8G8R8A8_UNORM;
15743 const int32_t img_width = 32;
15744 const int32_t img_height = 32;
15745 VkImageCreateInfo image_create_info = {};
15746 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15747 image_create_info.pNext = NULL;
15748 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15749 image_create_info.format = color_format;
15750 image_create_info.extent.width = img_width;
15751 image_create_info.extent.height = img_height;
15752 image_create_info.extent.depth = 1;
15753 image_create_info.mipLevels = 1;
15754 image_create_info.arrayLayers = 1;
15755 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15756 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15757 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
15758
15759 vk_testing::Image color_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015760 color_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015761
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015762 const VkImageSubresourceRange color_range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015763
15764 // Depth/Stencil image
15765 VkClearDepthStencilValue clear_value = {0};
15766 reqs = 0; // don't need HOST_VISIBLE DS image
15767 VkImageCreateInfo ds_image_create_info = vk_testing::Image::create_info();
15768 ds_image_create_info.imageType = VK_IMAGE_TYPE_2D;
15769 ds_image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
15770 ds_image_create_info.extent.width = 64;
15771 ds_image_create_info.extent.height = 64;
15772 ds_image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Rene Lindsaya1fc64a2016-12-27 15:18:54 -070015773 ds_image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015774
15775 vk_testing::Image ds_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015776 ds_image.init(*m_device, (const VkImageCreateInfo &)ds_image_create_info, reqs);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015777
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015778 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 -060015779
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015780 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdClearColorImage called with depth/stencil image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015781
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015782 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), ds_image.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015783 &color_range);
15784
15785 m_errorMonitor->VerifyFound();
15786
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015787 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdClearColorImage called with "
15788 "image created without "
15789 "VK_IMAGE_USAGE_TRANSFER_DST_BIT");
Tony Barbour26434b92016-06-02 09:43:50 -060015790
Rene Lindsaya1fc64a2016-12-27 15:18:54 -070015791 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), color_image.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
Tony Barbour26434b92016-06-02 09:43:50 -060015792 &color_range);
15793
15794 m_errorMonitor->VerifyFound();
15795
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015796 // Call CmdClearDepthStencilImage with color image
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015797 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15798 "vkCmdClearDepthStencilImage called without a depth/stencil image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015799
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015800 vkCmdClearDepthStencilImage(m_commandBuffer->GetBufferHandle(), color_image.handle(),
Rene Lindsaya1fc64a2016-12-27 15:18:54 -070015801 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, &clear_value, 1, &ds_range);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015802
15803 m_errorMonitor->VerifyFound();
15804}
Tobin Ehliscde08892015-09-22 10:11:37 -060015805#endif // IMAGE_TESTS
15806
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060015807
15808// WSI Enabled Tests
15809//
Chris Forbes09368e42016-10-13 11:59:22 +130015810#if 0
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060015811TEST_F(VkWsiEnabledLayerTest, TestEnabledWsi) {
15812
15813#if defined(VK_USE_PLATFORM_XCB_KHR)
15814 VkSurfaceKHR surface = VK_NULL_HANDLE;
15815
15816 VkResult err;
15817 bool pass;
15818 VkSwapchainKHR swapchain = VK_NULL_HANDLE;
15819 VkSwapchainCreateInfoKHR swapchain_create_info = {};
15820 // uint32_t swapchain_image_count = 0;
15821 // VkImage swapchain_images[1] = {VK_NULL_HANDLE};
15822 // uint32_t image_index = 0;
15823 // VkPresentInfoKHR present_info = {};
15824
15825 ASSERT_NO_FATAL_FAILURE(InitState());
15826
15827 // Use the create function from one of the VK_KHR_*_surface extension in
15828 // order to create a surface, testing all known errors in the process,
15829 // before successfully creating a surface:
15830 // First, try to create a surface without a VkXcbSurfaceCreateInfoKHR:
15831 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pCreateInfo specified as NULL");
15832 err = vkCreateXcbSurfaceKHR(instance(), NULL, NULL, &surface);
15833 pass = (err != VK_SUCCESS);
15834 ASSERT_TRUE(pass);
15835 m_errorMonitor->VerifyFound();
15836
15837 // Next, try to create a surface with the wrong
15838 // VkXcbSurfaceCreateInfoKHR::sType:
15839 VkXcbSurfaceCreateInfoKHR xcb_create_info = {};
15840 xcb_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
15841 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pCreateInfo->sType must be");
15842 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
15843 pass = (err != VK_SUCCESS);
15844 ASSERT_TRUE(pass);
15845 m_errorMonitor->VerifyFound();
15846
15847 // Create a native window, and then correctly create a surface:
15848 xcb_connection_t *connection;
15849 xcb_screen_t *screen;
15850 xcb_window_t xcb_window;
15851 xcb_intern_atom_reply_t *atom_wm_delete_window;
15852
15853 const xcb_setup_t *setup;
15854 xcb_screen_iterator_t iter;
15855 int scr;
15856 uint32_t value_mask, value_list[32];
15857 int width = 1;
15858 int height = 1;
15859
15860 connection = xcb_connect(NULL, &scr);
15861 ASSERT_TRUE(connection != NULL);
15862 setup = xcb_get_setup(connection);
15863 iter = xcb_setup_roots_iterator(setup);
15864 while (scr-- > 0)
15865 xcb_screen_next(&iter);
15866 screen = iter.data;
15867
15868 xcb_window = xcb_generate_id(connection);
15869
15870 value_mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK;
15871 value_list[0] = screen->black_pixel;
15872 value_list[1] = XCB_EVENT_MASK_KEY_RELEASE | XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_STRUCTURE_NOTIFY;
15873
15874 xcb_create_window(connection, XCB_COPY_FROM_PARENT, xcb_window, screen->root, 0, 0, width, height, 0,
15875 XCB_WINDOW_CLASS_INPUT_OUTPUT, screen->root_visual, value_mask, value_list);
15876
15877 /* Magic code that will send notification when window is destroyed */
15878 xcb_intern_atom_cookie_t cookie = xcb_intern_atom(connection, 1, 12, "WM_PROTOCOLS");
15879 xcb_intern_atom_reply_t *reply = xcb_intern_atom_reply(connection, cookie, 0);
15880
15881 xcb_intern_atom_cookie_t cookie2 = xcb_intern_atom(connection, 0, 16, "WM_DELETE_WINDOW");
15882 atom_wm_delete_window = xcb_intern_atom_reply(connection, cookie2, 0);
15883 xcb_change_property(connection, XCB_PROP_MODE_REPLACE, xcb_window, (*reply).atom, 4, 32, 1, &(*atom_wm_delete_window).atom);
15884 free(reply);
15885
15886 xcb_map_window(connection, xcb_window);
15887
15888 // Force the x/y coordinates to 100,100 results are identical in consecutive
15889 // runs
15890 const uint32_t coords[] = { 100, 100 };
15891 xcb_configure_window(connection, xcb_window, XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y, coords);
15892
15893 // Finally, try to correctly create a surface:
15894 xcb_create_info.sType = VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR;
15895 xcb_create_info.pNext = NULL;
15896 xcb_create_info.flags = 0;
15897 xcb_create_info.connection = connection;
15898 xcb_create_info.window = xcb_window;
15899 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
15900 pass = (err == VK_SUCCESS);
15901 ASSERT_TRUE(pass);
15902
15903 // Check if surface supports presentation:
15904
15905 // 1st, do so without having queried the queue families:
15906 VkBool32 supported = false;
15907 // TODO: Get the following error to come out:
15908 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15909 "called before calling the vkGetPhysicalDeviceQueueFamilyProperties "
15910 "function");
15911 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
15912 pass = (err != VK_SUCCESS);
15913 // ASSERT_TRUE(pass);
15914 // m_errorMonitor->VerifyFound();
15915
15916 // Next, query a queue family index that's too large:
15917 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with a queueFamilyIndex that is too large");
15918 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 100000, surface, &supported);
15919 pass = (err != VK_SUCCESS);
15920 ASSERT_TRUE(pass);
15921 m_errorMonitor->VerifyFound();
15922
15923 // Finally, do so correctly:
15924 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
15925 // SUPPORTED
15926 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
15927 pass = (err == VK_SUCCESS);
15928 ASSERT_TRUE(pass);
15929
15930 // Before proceeding, try to create a swapchain without having called
15931 // vkGetPhysicalDeviceSurfaceCapabilitiesKHR():
15932 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
15933 swapchain_create_info.pNext = NULL;
15934 swapchain_create_info.flags = 0;
15935 swapchain_create_info.imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
15936 swapchain_create_info.surface = surface;
15937 swapchain_create_info.imageArrayLayers = 1;
15938 swapchain_create_info.preTransform = VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR;
15939 swapchain_create_info.compositeAlpha = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR;
15940 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15941 "called before calling vkGetPhysicalDeviceSurfaceCapabilitiesKHR().");
15942 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
15943 pass = (err != VK_SUCCESS);
15944 ASSERT_TRUE(pass);
15945 m_errorMonitor->VerifyFound();
15946
15947 // Get the surface capabilities:
15948 VkSurfaceCapabilitiesKHR surface_capabilities;
15949
15950 // Do so correctly (only error logged by this entrypoint is if the
15951 // extension isn't enabled):
15952 err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), surface, &surface_capabilities);
15953 pass = (err == VK_SUCCESS);
15954 ASSERT_TRUE(pass);
15955
15956 // Get the surface formats:
15957 uint32_t surface_format_count;
15958
15959 // First, try without a pointer to surface_format_count:
15960 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pSurfaceFormatCount "
15961 "specified as NULL");
15962 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, NULL, NULL);
15963 pass = (err == VK_SUCCESS);
15964 ASSERT_TRUE(pass);
15965 m_errorMonitor->VerifyFound();
15966
15967 // Next, call with a non-NULL pSurfaceFormats, even though we haven't
15968 // correctly done a 1st try (to get the count):
15969 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "but no prior positive value has been seen for");
15970 surface_format_count = 0;
15971 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, (VkSurfaceFormatKHR *)&surface_format_count);
15972 pass = (err == VK_SUCCESS);
15973 ASSERT_TRUE(pass);
15974 m_errorMonitor->VerifyFound();
15975
15976 // Next, correctly do a 1st try (with a NULL pointer to surface_formats):
15977 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, NULL);
15978 pass = (err == VK_SUCCESS);
15979 ASSERT_TRUE(pass);
15980
15981 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
15982 VkSurfaceFormatKHR *surface_formats = (VkSurfaceFormatKHR *)malloc(surface_format_count * sizeof(VkSurfaceFormatKHR));
15983
15984 // Next, do a 2nd try with surface_format_count being set too high:
15985 surface_format_count += 5;
15986 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is greater than the value");
15987 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, surface_formats);
15988 pass = (err == VK_SUCCESS);
15989 ASSERT_TRUE(pass);
15990 m_errorMonitor->VerifyFound();
15991
15992 // Finally, do a correct 1st and 2nd try:
15993 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, NULL);
15994 pass = (err == VK_SUCCESS);
15995 ASSERT_TRUE(pass);
15996 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, surface_formats);
15997 pass = (err == VK_SUCCESS);
15998 ASSERT_TRUE(pass);
15999
16000 // Get the surface present modes:
16001 uint32_t surface_present_mode_count;
16002
16003 // First, try without a pointer to surface_format_count:
16004 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pPresentModeCount "
16005 "specified as NULL");
16006
16007 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, NULL, NULL);
16008 pass = (err == VK_SUCCESS);
16009 ASSERT_TRUE(pass);
16010 m_errorMonitor->VerifyFound();
16011
16012 // Next, call with a non-NULL VkPresentModeKHR, even though we haven't
16013 // correctly done a 1st try (to get the count):
16014 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "but no prior positive value has been seen for");
16015 surface_present_mode_count = 0;
16016 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count,
16017 (VkPresentModeKHR *)&surface_present_mode_count);
16018 pass = (err == VK_SUCCESS);
16019 ASSERT_TRUE(pass);
16020 m_errorMonitor->VerifyFound();
16021
16022 // Next, correctly do a 1st try (with a NULL pointer to surface_formats):
16023 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, NULL);
16024 pass = (err == VK_SUCCESS);
16025 ASSERT_TRUE(pass);
16026
16027 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
16028 VkPresentModeKHR *surface_present_modes = (VkPresentModeKHR *)malloc(surface_present_mode_count * sizeof(VkPresentModeKHR));
16029
16030 // Next, do a 2nd try with surface_format_count being set too high:
16031 surface_present_mode_count += 5;
16032 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is greater than the value");
16033 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, surface_present_modes);
16034 pass = (err == VK_SUCCESS);
16035 ASSERT_TRUE(pass);
16036 m_errorMonitor->VerifyFound();
16037
16038 // Finally, do a correct 1st and 2nd try:
16039 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, NULL);
16040 pass = (err == VK_SUCCESS);
16041 ASSERT_TRUE(pass);
16042 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, surface_present_modes);
16043 pass = (err == VK_SUCCESS);
16044 ASSERT_TRUE(pass);
16045
16046 // Create a swapchain:
16047
16048 // First, try without a pointer to swapchain_create_info:
16049 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pCreateInfo "
16050 "specified as NULL");
16051
16052 err = vkCreateSwapchainKHR(m_device->device(), NULL, NULL, &swapchain);
16053 pass = (err != VK_SUCCESS);
16054 ASSERT_TRUE(pass);
16055 m_errorMonitor->VerifyFound();
16056
16057 // Next, call with a non-NULL swapchain_create_info, that has the wrong
16058 // sType:
16059 swapchain_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
16060 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pCreateInfo->sType must be");
16061
16062 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
16063 pass = (err != VK_SUCCESS);
16064 ASSERT_TRUE(pass);
16065 m_errorMonitor->VerifyFound();
16066
16067 // Next, call with a NULL swapchain pointer:
16068 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
16069 swapchain_create_info.pNext = NULL;
16070 swapchain_create_info.flags = 0;
16071 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pSwapchain "
16072 "specified as NULL");
16073
16074 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, NULL);
16075 pass = (err != VK_SUCCESS);
16076 ASSERT_TRUE(pass);
16077 m_errorMonitor->VerifyFound();
16078
16079 // TODO: Enhance swapchain layer so that
16080 // swapchain_create_info.queueFamilyIndexCount is checked against something?
16081
16082 // Next, call with a queue family index that's too large:
16083 uint32_t queueFamilyIndex[2] = { 100000, 0 };
16084 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
16085 swapchain_create_info.queueFamilyIndexCount = 2;
16086 swapchain_create_info.pQueueFamilyIndices = queueFamilyIndex;
16087 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with a queueFamilyIndex that is too large");
16088 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
16089 pass = (err != VK_SUCCESS);
16090 ASSERT_TRUE(pass);
16091 m_errorMonitor->VerifyFound();
16092
16093 // Next, call a queueFamilyIndexCount that's too small for CONCURRENT:
16094 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
16095 swapchain_create_info.queueFamilyIndexCount = 1;
16096 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16097 "but with a bad value(s) for pCreateInfo->queueFamilyIndexCount or "
16098 "pCreateInfo->pQueueFamilyIndices).");
16099 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
16100 pass = (err != VK_SUCCESS);
16101 ASSERT_TRUE(pass);
16102 m_errorMonitor->VerifyFound();
16103
16104 // Next, call with an invalid imageSharingMode:
16105 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_MAX_ENUM;
16106 swapchain_create_info.queueFamilyIndexCount = 1;
16107 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16108 "called with a non-supported pCreateInfo->imageSharingMode (i.e.");
16109 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
16110 pass = (err != VK_SUCCESS);
16111 ASSERT_TRUE(pass);
16112 m_errorMonitor->VerifyFound();
16113 // Fix for the future:
16114 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
16115 // SUPPORTED
16116 swapchain_create_info.queueFamilyIndexCount = 0;
16117 queueFamilyIndex[0] = 0;
16118 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE;
16119
16120 // TODO: CONTINUE TESTING VALIDATION OF vkCreateSwapchainKHR() ...
16121 // Get the images from a swapchain:
16122 // Acquire an image from a swapchain:
16123 // Present an image to a swapchain:
16124 // Destroy the swapchain:
16125
16126 // TODOs:
16127 //
16128 // - Try destroying the device without first destroying the swapchain
16129 //
16130 // - Try destroying the device without first destroying the surface
16131 //
16132 // - Try destroying the surface without first destroying the swapchain
16133
16134 // Destroy the surface:
16135 vkDestroySurfaceKHR(instance(), surface, NULL);
16136
16137 // Tear down the window:
16138 xcb_destroy_window(connection, xcb_window);
16139 xcb_disconnect(connection);
16140
16141#else // VK_USE_PLATFORM_XCB_KHR
16142 return;
16143#endif // VK_USE_PLATFORM_XCB_KHR
16144}
Chris Forbes09368e42016-10-13 11:59:22 +130016145#endif
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016146
16147//
16148// POSITIVE VALIDATION TESTS
16149//
16150// These tests do not expect to encounter ANY validation errors pass only if this is true
16151
Tobin Ehlise0006882016-11-03 10:14:28 -060016152TEST_F(VkPositiveLayerTest, SecondaryCommandBufferImageLayoutTransitions) {
16153 TEST_DESCRIPTION("Perform an image layout transition in a secondary command buffer followed "
16154 "by a transition in the primary.");
16155 VkResult err;
16156 m_errorMonitor->ExpectSuccess();
16157 ASSERT_NO_FATAL_FAILURE(InitState());
16158 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
16159 // Allocate a secondary and primary cmd buffer
16160 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
16161 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
16162 command_buffer_allocate_info.commandPool = m_commandPool;
16163 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
16164 command_buffer_allocate_info.commandBufferCount = 1;
16165
16166 VkCommandBuffer secondary_command_buffer;
16167 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer));
16168 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
16169 VkCommandBuffer primary_command_buffer;
16170 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &primary_command_buffer));
16171 VkCommandBufferBeginInfo command_buffer_begin_info = {};
16172 VkCommandBufferInheritanceInfo command_buffer_inheritance_info = {};
16173 command_buffer_inheritance_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
16174 command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
16175 command_buffer_begin_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
16176 command_buffer_begin_info.pInheritanceInfo = &command_buffer_inheritance_info;
16177
16178 err = vkBeginCommandBuffer(secondary_command_buffer, &command_buffer_begin_info);
16179 ASSERT_VK_SUCCESS(err);
16180 VkImageObj image(m_device);
16181 image.init(128, 128, VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
16182 ASSERT_TRUE(image.initialized());
16183 VkImageMemoryBarrier img_barrier = {};
16184 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
16185 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
16186 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
16187 img_barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
16188 img_barrier.newLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
16189 img_barrier.image = image.handle();
16190 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
16191 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
16192 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
16193 img_barrier.subresourceRange.baseArrayLayer = 0;
16194 img_barrier.subresourceRange.baseMipLevel = 0;
16195 img_barrier.subresourceRange.layerCount = 1;
16196 img_barrier.subresourceRange.levelCount = 1;
16197 vkCmdPipelineBarrier(secondary_command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr,
16198 0, nullptr, 1, &img_barrier);
16199 err = vkEndCommandBuffer(secondary_command_buffer);
16200 ASSERT_VK_SUCCESS(err);
16201
16202 // Now update primary cmd buffer to execute secondary and transitions image
16203 command_buffer_begin_info.pInheritanceInfo = nullptr;
16204 err = vkBeginCommandBuffer(primary_command_buffer, &command_buffer_begin_info);
16205 ASSERT_VK_SUCCESS(err);
16206 vkCmdExecuteCommands(primary_command_buffer, 1, &secondary_command_buffer);
16207 VkImageMemoryBarrier img_barrier2 = {};
16208 img_barrier2.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
16209 img_barrier2.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
16210 img_barrier2.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
16211 img_barrier2.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
16212 img_barrier2.newLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
16213 img_barrier2.image = image.handle();
16214 img_barrier2.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
16215 img_barrier2.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
16216 img_barrier2.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
16217 img_barrier2.subresourceRange.baseArrayLayer = 0;
16218 img_barrier2.subresourceRange.baseMipLevel = 0;
16219 img_barrier2.subresourceRange.layerCount = 1;
16220 img_barrier2.subresourceRange.levelCount = 1;
16221 vkCmdPipelineBarrier(primary_command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0,
16222 nullptr, 1, &img_barrier2);
16223 err = vkEndCommandBuffer(primary_command_buffer);
16224 ASSERT_VK_SUCCESS(err);
16225 VkSubmitInfo submit_info = {};
16226 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
16227 submit_info.commandBufferCount = 1;
16228 submit_info.pCommandBuffers = &primary_command_buffer;
16229 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
16230 ASSERT_VK_SUCCESS(err);
16231 m_errorMonitor->VerifyNotFound();
16232 err = vkDeviceWaitIdle(m_device->device());
16233 ASSERT_VK_SUCCESS(err);
16234 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &secondary_command_buffer);
16235 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &primary_command_buffer);
16236}
16237
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016238// This is a positive test. No failures are expected.
16239TEST_F(VkPositiveLayerTest, IgnoreUnrelatedDescriptor) {
16240 TEST_DESCRIPTION("Ensure that the vkUpdateDescriptorSets validation code "
16241 "is ignoring VkWriteDescriptorSet members that are not "
16242 "related to the descriptor type specified by "
16243 "VkWriteDescriptorSet::descriptorType. Correct "
16244 "validation behavior will result in the test running to "
16245 "completion without validation errors.");
16246
16247 const uintptr_t invalid_ptr = 0xcdcdcdcd;
16248
16249 ASSERT_NO_FATAL_FAILURE(InitState());
16250
16251 // Image Case
16252 {
16253 m_errorMonitor->ExpectSuccess();
16254
16255 VkImage image;
16256 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
16257 const int32_t tex_width = 32;
16258 const int32_t tex_height = 32;
16259 VkImageCreateInfo image_create_info = {};
16260 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16261 image_create_info.pNext = NULL;
16262 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16263 image_create_info.format = tex_format;
16264 image_create_info.extent.width = tex_width;
16265 image_create_info.extent.height = tex_height;
16266 image_create_info.extent.depth = 1;
16267 image_create_info.mipLevels = 1;
16268 image_create_info.arrayLayers = 1;
16269 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16270 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
16271 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
16272 image_create_info.flags = 0;
16273 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
16274 ASSERT_VK_SUCCESS(err);
16275
16276 VkMemoryRequirements memory_reqs;
16277 VkDeviceMemory image_memory;
16278 bool pass;
16279 VkMemoryAllocateInfo memory_info = {};
16280 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16281 memory_info.pNext = NULL;
16282 memory_info.allocationSize = 0;
16283 memory_info.memoryTypeIndex = 0;
16284 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
16285 memory_info.allocationSize = memory_reqs.size;
16286 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
16287 ASSERT_TRUE(pass);
16288 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
16289 ASSERT_VK_SUCCESS(err);
16290 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
16291 ASSERT_VK_SUCCESS(err);
16292
16293 VkImageViewCreateInfo image_view_create_info = {};
16294 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
16295 image_view_create_info.image = image;
16296 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
16297 image_view_create_info.format = tex_format;
16298 image_view_create_info.subresourceRange.layerCount = 1;
16299 image_view_create_info.subresourceRange.baseMipLevel = 0;
16300 image_view_create_info.subresourceRange.levelCount = 1;
16301 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16302
16303 VkImageView view;
16304 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
16305 ASSERT_VK_SUCCESS(err);
16306
16307 VkDescriptorPoolSize ds_type_count = {};
16308 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
16309 ds_type_count.descriptorCount = 1;
16310
16311 VkDescriptorPoolCreateInfo ds_pool_ci = {};
16312 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
16313 ds_pool_ci.pNext = NULL;
16314 ds_pool_ci.maxSets = 1;
16315 ds_pool_ci.poolSizeCount = 1;
16316 ds_pool_ci.pPoolSizes = &ds_type_count;
16317
16318 VkDescriptorPool ds_pool;
16319 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
16320 ASSERT_VK_SUCCESS(err);
16321
16322 VkDescriptorSetLayoutBinding dsl_binding = {};
16323 dsl_binding.binding = 0;
16324 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
16325 dsl_binding.descriptorCount = 1;
16326 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
16327 dsl_binding.pImmutableSamplers = NULL;
16328
16329 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
16330 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
16331 ds_layout_ci.pNext = NULL;
16332 ds_layout_ci.bindingCount = 1;
16333 ds_layout_ci.pBindings = &dsl_binding;
16334 VkDescriptorSetLayout ds_layout;
16335 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
16336 ASSERT_VK_SUCCESS(err);
16337
16338 VkDescriptorSet descriptor_set;
16339 VkDescriptorSetAllocateInfo alloc_info = {};
16340 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
16341 alloc_info.descriptorSetCount = 1;
16342 alloc_info.descriptorPool = ds_pool;
16343 alloc_info.pSetLayouts = &ds_layout;
16344 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
16345 ASSERT_VK_SUCCESS(err);
16346
16347 VkDescriptorImageInfo image_info = {};
16348 image_info.imageView = view;
16349 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
16350
16351 VkWriteDescriptorSet descriptor_write;
16352 memset(&descriptor_write, 0, sizeof(descriptor_write));
16353 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
16354 descriptor_write.dstSet = descriptor_set;
16355 descriptor_write.dstBinding = 0;
16356 descriptor_write.descriptorCount = 1;
16357 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
16358 descriptor_write.pImageInfo = &image_info;
16359
16360 // Set pBufferInfo and pTexelBufferView to invalid values, which should
16361 // be
16362 // ignored for descriptorType == VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE.
16363 // This will most likely produce a crash if the parameter_validation
16364 // layer
16365 // does not correctly ignore pBufferInfo.
16366 descriptor_write.pBufferInfo = reinterpret_cast<const VkDescriptorBufferInfo *>(invalid_ptr);
16367 descriptor_write.pTexelBufferView = reinterpret_cast<const VkBufferView *>(invalid_ptr);
16368
16369 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
16370
16371 m_errorMonitor->VerifyNotFound();
16372
16373 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
16374 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
16375 vkDestroyImageView(m_device->device(), view, NULL);
16376 vkDestroyImage(m_device->device(), image, NULL);
16377 vkFreeMemory(m_device->device(), image_memory, NULL);
16378 }
16379
16380 // Buffer Case
16381 {
16382 m_errorMonitor->ExpectSuccess();
16383
16384 VkBuffer buffer;
16385 uint32_t queue_family_index = 0;
16386 VkBufferCreateInfo buffer_create_info = {};
16387 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
16388 buffer_create_info.size = 1024;
16389 buffer_create_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
16390 buffer_create_info.queueFamilyIndexCount = 1;
16391 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
16392
16393 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
16394 ASSERT_VK_SUCCESS(err);
16395
16396 VkMemoryRequirements memory_reqs;
16397 VkDeviceMemory buffer_memory;
16398 bool pass;
16399 VkMemoryAllocateInfo memory_info = {};
16400 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16401 memory_info.pNext = NULL;
16402 memory_info.allocationSize = 0;
16403 memory_info.memoryTypeIndex = 0;
16404
16405 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
16406 memory_info.allocationSize = memory_reqs.size;
16407 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
16408 ASSERT_TRUE(pass);
16409
16410 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
16411 ASSERT_VK_SUCCESS(err);
16412 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
16413 ASSERT_VK_SUCCESS(err);
16414
16415 VkDescriptorPoolSize ds_type_count = {};
16416 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16417 ds_type_count.descriptorCount = 1;
16418
16419 VkDescriptorPoolCreateInfo ds_pool_ci = {};
16420 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
16421 ds_pool_ci.pNext = NULL;
16422 ds_pool_ci.maxSets = 1;
16423 ds_pool_ci.poolSizeCount = 1;
16424 ds_pool_ci.pPoolSizes = &ds_type_count;
16425
16426 VkDescriptorPool ds_pool;
16427 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
16428 ASSERT_VK_SUCCESS(err);
16429
16430 VkDescriptorSetLayoutBinding dsl_binding = {};
16431 dsl_binding.binding = 0;
16432 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16433 dsl_binding.descriptorCount = 1;
16434 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
16435 dsl_binding.pImmutableSamplers = NULL;
16436
16437 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
16438 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
16439 ds_layout_ci.pNext = NULL;
16440 ds_layout_ci.bindingCount = 1;
16441 ds_layout_ci.pBindings = &dsl_binding;
16442 VkDescriptorSetLayout ds_layout;
16443 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
16444 ASSERT_VK_SUCCESS(err);
16445
16446 VkDescriptorSet descriptor_set;
16447 VkDescriptorSetAllocateInfo alloc_info = {};
16448 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
16449 alloc_info.descriptorSetCount = 1;
16450 alloc_info.descriptorPool = ds_pool;
16451 alloc_info.pSetLayouts = &ds_layout;
16452 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
16453 ASSERT_VK_SUCCESS(err);
16454
16455 VkDescriptorBufferInfo buffer_info = {};
16456 buffer_info.buffer = buffer;
16457 buffer_info.offset = 0;
16458 buffer_info.range = 1024;
16459
16460 VkWriteDescriptorSet descriptor_write;
16461 memset(&descriptor_write, 0, sizeof(descriptor_write));
16462 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
16463 descriptor_write.dstSet = descriptor_set;
16464 descriptor_write.dstBinding = 0;
16465 descriptor_write.descriptorCount = 1;
16466 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16467 descriptor_write.pBufferInfo = &buffer_info;
16468
16469 // Set pImageInfo and pTexelBufferView to invalid values, which should
16470 // be
16471 // ignored for descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER.
16472 // This will most likely produce a crash if the parameter_validation
16473 // layer
16474 // does not correctly ignore pImageInfo.
16475 descriptor_write.pImageInfo = reinterpret_cast<const VkDescriptorImageInfo *>(invalid_ptr);
16476 descriptor_write.pTexelBufferView = reinterpret_cast<const VkBufferView *>(invalid_ptr);
16477
16478 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
16479
16480 m_errorMonitor->VerifyNotFound();
16481
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016482 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
16483 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
16484 vkDestroyBuffer(m_device->device(), buffer, NULL);
16485 vkFreeMemory(m_device->device(), buffer_memory, NULL);
16486 }
16487
16488 // Texel Buffer Case
16489 {
16490 m_errorMonitor->ExpectSuccess();
16491
16492 VkBuffer buffer;
16493 uint32_t queue_family_index = 0;
16494 VkBufferCreateInfo buffer_create_info = {};
16495 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
16496 buffer_create_info.size = 1024;
16497 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
16498 buffer_create_info.queueFamilyIndexCount = 1;
16499 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
16500
16501 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
16502 ASSERT_VK_SUCCESS(err);
16503
16504 VkMemoryRequirements memory_reqs;
16505 VkDeviceMemory buffer_memory;
16506 bool pass;
16507 VkMemoryAllocateInfo memory_info = {};
16508 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16509 memory_info.pNext = NULL;
16510 memory_info.allocationSize = 0;
16511 memory_info.memoryTypeIndex = 0;
16512
16513 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
16514 memory_info.allocationSize = memory_reqs.size;
16515 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
16516 ASSERT_TRUE(pass);
16517
16518 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
16519 ASSERT_VK_SUCCESS(err);
16520 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
16521 ASSERT_VK_SUCCESS(err);
16522
16523 VkBufferViewCreateInfo buff_view_ci = {};
16524 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
16525 buff_view_ci.buffer = buffer;
16526 buff_view_ci.format = VK_FORMAT_R8_UNORM;
16527 buff_view_ci.range = VK_WHOLE_SIZE;
16528 VkBufferView buffer_view;
16529 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buffer_view);
16530
16531 VkDescriptorPoolSize ds_type_count = {};
16532 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
16533 ds_type_count.descriptorCount = 1;
16534
16535 VkDescriptorPoolCreateInfo ds_pool_ci = {};
16536 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
16537 ds_pool_ci.pNext = NULL;
16538 ds_pool_ci.maxSets = 1;
16539 ds_pool_ci.poolSizeCount = 1;
16540 ds_pool_ci.pPoolSizes = &ds_type_count;
16541
16542 VkDescriptorPool ds_pool;
16543 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
16544 ASSERT_VK_SUCCESS(err);
16545
16546 VkDescriptorSetLayoutBinding dsl_binding = {};
16547 dsl_binding.binding = 0;
16548 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
16549 dsl_binding.descriptorCount = 1;
16550 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
16551 dsl_binding.pImmutableSamplers = NULL;
16552
16553 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
16554 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
16555 ds_layout_ci.pNext = NULL;
16556 ds_layout_ci.bindingCount = 1;
16557 ds_layout_ci.pBindings = &dsl_binding;
16558 VkDescriptorSetLayout ds_layout;
16559 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
16560 ASSERT_VK_SUCCESS(err);
16561
16562 VkDescriptorSet descriptor_set;
16563 VkDescriptorSetAllocateInfo alloc_info = {};
16564 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
16565 alloc_info.descriptorSetCount = 1;
16566 alloc_info.descriptorPool = ds_pool;
16567 alloc_info.pSetLayouts = &ds_layout;
16568 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
16569 ASSERT_VK_SUCCESS(err);
16570
16571 VkWriteDescriptorSet descriptor_write;
16572 memset(&descriptor_write, 0, sizeof(descriptor_write));
16573 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
16574 descriptor_write.dstSet = descriptor_set;
16575 descriptor_write.dstBinding = 0;
16576 descriptor_write.descriptorCount = 1;
16577 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
16578 descriptor_write.pTexelBufferView = &buffer_view;
16579
16580 // Set pImageInfo and pBufferInfo to invalid values, which should be
16581 // ignored for descriptorType ==
16582 // VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER.
16583 // This will most likely produce a crash if the parameter_validation
16584 // layer
16585 // does not correctly ignore pImageInfo and pBufferInfo.
16586 descriptor_write.pImageInfo = reinterpret_cast<const VkDescriptorImageInfo *>(invalid_ptr);
16587 descriptor_write.pBufferInfo = reinterpret_cast<const VkDescriptorBufferInfo *>(invalid_ptr);
16588
16589 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
16590
16591 m_errorMonitor->VerifyNotFound();
16592
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016593 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
16594 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
16595 vkDestroyBufferView(m_device->device(), buffer_view, NULL);
16596 vkDestroyBuffer(m_device->device(), buffer, NULL);
16597 vkFreeMemory(m_device->device(), buffer_memory, NULL);
16598 }
16599}
16600
Tobin Ehlisf7428442016-10-25 07:58:24 -060016601TEST_F(VkLayerTest, DuplicateDescriptorBinding) {
16602 TEST_DESCRIPTION("Create a descriptor set layout with a duplicate binding number.");
16603
16604 ASSERT_NO_FATAL_FAILURE(InitState());
16605 // Create layout where two binding #s are "1"
16606 static const uint32_t NUM_BINDINGS = 3;
16607 VkDescriptorSetLayoutBinding dsl_binding[NUM_BINDINGS] = {};
16608 dsl_binding[0].binding = 1;
16609 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16610 dsl_binding[0].descriptorCount = 1;
16611 dsl_binding[0].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
16612 dsl_binding[0].pImmutableSamplers = NULL;
16613 dsl_binding[1].binding = 0;
16614 dsl_binding[1].descriptorCount = 1;
16615 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16616 dsl_binding[1].descriptorCount = 1;
16617 dsl_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
16618 dsl_binding[1].pImmutableSamplers = NULL;
16619 dsl_binding[2].binding = 1; // Duplicate binding should cause error
16620 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16621 dsl_binding[2].descriptorCount = 1;
16622 dsl_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
16623 dsl_binding[2].pImmutableSamplers = NULL;
16624
16625 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
16626 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
16627 ds_layout_ci.pNext = NULL;
16628 ds_layout_ci.bindingCount = NUM_BINDINGS;
16629 ds_layout_ci.pBindings = dsl_binding;
16630 VkDescriptorSetLayout ds_layout;
16631 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02345);
16632 vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
16633 m_errorMonitor->VerifyFound();
16634}
16635
Mike Weiblen9a0f55d2016-10-31 22:35:00 -060016636TEST_F(VkLayerTest, ViewportAndScissorBoundsChecking) {
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060016637 TEST_DESCRIPTION("Verify errors are detected on misuse of SetViewport and SetScissor.");
16638
16639 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060016640
16641 BeginCommandBuffer();
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060016642
Mike Weiblen9a0f55d2016-10-31 22:35:00 -060016643 const VkPhysicalDeviceLimits &limits = m_device->props.limits;
16644
16645 {
16646 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01448);
16647 VkViewport viewport = {0, 0, static_cast<float>(limits.maxViewportDimensions[0] + 1), 16, 0, 1};
16648 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
16649 m_errorMonitor->VerifyFound();
16650 }
16651
16652 {
16653 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01449);
16654 VkViewport viewport = {0, 0, 16, static_cast<float>(limits.maxViewportDimensions[1] + 1), 0, 1};
16655 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
16656 m_errorMonitor->VerifyFound();
16657 }
16658
16659 {
16660 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01450);
16661 VkViewport viewport = {limits.viewportBoundsRange[0] - 1, 0, 16, 16, 0, 1};
16662 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
16663 m_errorMonitor->VerifyFound();
16664 }
16665
16666 {
16667 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01450);
16668 VkViewport viewport = {0, limits.viewportBoundsRange[0] - 1, 16, 16, 0, 1};
16669 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
16670 m_errorMonitor->VerifyFound();
16671 }
16672
16673 {
16674 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01451);
16675 VkViewport viewport = {limits.viewportBoundsRange[1], 0, 16, 16, 0, 1};
16676 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
16677 m_errorMonitor->VerifyFound();
16678 }
16679
16680 {
16681 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01452);
16682 VkViewport viewport = {0, limits.viewportBoundsRange[1], 16, 16, 0, 1};
16683 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
16684 m_errorMonitor->VerifyFound();
16685 }
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060016686
16687 {
16688 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01489);
16689 VkRect2D scissor = {{-1, 0}, {16, 16}};
16690 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
16691 m_errorMonitor->VerifyFound();
16692 }
16693
16694 {
16695 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01489);
16696 VkRect2D scissor = {{0, -2}, {16, 16}};
16697 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
16698 m_errorMonitor->VerifyFound();
16699 }
16700
16701 {
16702 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01490);
16703 VkRect2D scissor = {{100, 100}, {INT_MAX, 16}};
16704 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
16705 m_errorMonitor->VerifyFound();
16706 }
16707
16708 {
16709 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01491);
16710 VkRect2D scissor = {{100, 100}, {16, INT_MAX}};
16711 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
16712 m_errorMonitor->VerifyFound();
16713 }
16714
16715 EndCommandBuffer();
16716}
16717
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016718// This is a positive test. No failures are expected.
16719TEST_F(VkPositiveLayerTest, EmptyDescriptorUpdateTest) {
16720 TEST_DESCRIPTION("Update last descriptor in a set that includes an empty binding");
16721 VkResult err;
16722
16723 ASSERT_NO_FATAL_FAILURE(InitState());
16724 m_errorMonitor->ExpectSuccess();
16725 VkDescriptorPoolSize ds_type_count = {};
16726 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16727 ds_type_count.descriptorCount = 2;
16728
16729 VkDescriptorPoolCreateInfo ds_pool_ci = {};
16730 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
16731 ds_pool_ci.pNext = NULL;
16732 ds_pool_ci.maxSets = 1;
16733 ds_pool_ci.poolSizeCount = 1;
16734 ds_pool_ci.pPoolSizes = &ds_type_count;
16735
16736 VkDescriptorPool ds_pool;
16737 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
16738 ASSERT_VK_SUCCESS(err);
16739
16740 // Create layout with two uniform buffer descriptors w/ empty binding between them
16741 static const uint32_t NUM_BINDINGS = 3;
16742 VkDescriptorSetLayoutBinding dsl_binding[NUM_BINDINGS] = {};
16743 dsl_binding[0].binding = 0;
16744 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16745 dsl_binding[0].descriptorCount = 1;
16746 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
16747 dsl_binding[0].pImmutableSamplers = NULL;
16748 dsl_binding[1].binding = 1;
16749 dsl_binding[1].descriptorCount = 0; // empty binding
16750 dsl_binding[2].binding = 2;
16751 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16752 dsl_binding[2].descriptorCount = 1;
16753 dsl_binding[2].stageFlags = VK_SHADER_STAGE_ALL;
16754 dsl_binding[2].pImmutableSamplers = NULL;
16755
16756 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
16757 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
16758 ds_layout_ci.pNext = NULL;
16759 ds_layout_ci.bindingCount = NUM_BINDINGS;
16760 ds_layout_ci.pBindings = dsl_binding;
16761 VkDescriptorSetLayout ds_layout;
16762 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
16763 ASSERT_VK_SUCCESS(err);
16764
16765 VkDescriptorSet descriptor_set = {};
16766 VkDescriptorSetAllocateInfo alloc_info = {};
16767 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
16768 alloc_info.descriptorSetCount = 1;
16769 alloc_info.descriptorPool = ds_pool;
16770 alloc_info.pSetLayouts = &ds_layout;
16771 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
16772 ASSERT_VK_SUCCESS(err);
16773
16774 // Create a buffer to be used for update
16775 VkBufferCreateInfo buff_ci = {};
16776 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
16777 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
16778 buff_ci.size = 256;
16779 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
16780 VkBuffer buffer;
16781 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
16782 ASSERT_VK_SUCCESS(err);
16783 // Have to bind memory to buffer before descriptor update
16784 VkMemoryAllocateInfo mem_alloc = {};
16785 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16786 mem_alloc.pNext = NULL;
16787 mem_alloc.allocationSize = 512; // one allocation for both buffers
16788 mem_alloc.memoryTypeIndex = 0;
16789
16790 VkMemoryRequirements mem_reqs;
16791 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
16792 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
16793 if (!pass) {
16794 vkDestroyBuffer(m_device->device(), buffer, NULL);
16795 return;
16796 }
16797
16798 VkDeviceMemory mem;
16799 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
16800 ASSERT_VK_SUCCESS(err);
16801 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
16802 ASSERT_VK_SUCCESS(err);
16803
16804 // Only update the descriptor at binding 2
16805 VkDescriptorBufferInfo buff_info = {};
16806 buff_info.buffer = buffer;
16807 buff_info.offset = 0;
16808 buff_info.range = VK_WHOLE_SIZE;
16809 VkWriteDescriptorSet descriptor_write = {};
16810 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
16811 descriptor_write.dstBinding = 2;
16812 descriptor_write.descriptorCount = 1;
16813 descriptor_write.pTexelBufferView = nullptr;
16814 descriptor_write.pBufferInfo = &buff_info;
16815 descriptor_write.pImageInfo = nullptr;
16816 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16817 descriptor_write.dstSet = descriptor_set;
16818
16819 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
16820
16821 m_errorMonitor->VerifyNotFound();
16822 // Cleanup
16823 vkFreeMemory(m_device->device(), mem, NULL);
16824 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
16825 vkDestroyBuffer(m_device->device(), buffer, NULL);
16826 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
16827}
16828
16829// This is a positive test. No failures are expected.
16830TEST_F(VkPositiveLayerTest, TestAliasedMemoryTracking) {
16831 VkResult err;
16832 bool pass;
16833
16834 TEST_DESCRIPTION("Create a buffer, allocate memory, bind memory, destroy "
16835 "the buffer, create an image, and bind the same memory to "
16836 "it");
16837
16838 m_errorMonitor->ExpectSuccess();
16839
16840 ASSERT_NO_FATAL_FAILURE(InitState());
16841
16842 VkBuffer buffer;
16843 VkImage image;
16844 VkDeviceMemory mem;
16845 VkMemoryRequirements mem_reqs;
16846
16847 VkBufferCreateInfo buf_info = {};
16848 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
16849 buf_info.pNext = NULL;
16850 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
16851 buf_info.size = 256;
16852 buf_info.queueFamilyIndexCount = 0;
16853 buf_info.pQueueFamilyIndices = NULL;
16854 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
16855 buf_info.flags = 0;
16856 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
16857 ASSERT_VK_SUCCESS(err);
16858
16859 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
16860
16861 VkMemoryAllocateInfo alloc_info = {};
16862 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16863 alloc_info.pNext = NULL;
16864 alloc_info.memoryTypeIndex = 0;
16865
16866 // Ensure memory is big enough for both bindings
16867 alloc_info.allocationSize = 0x10000;
16868
16869 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
16870 if (!pass) {
16871 vkDestroyBuffer(m_device->device(), buffer, NULL);
16872 return;
16873 }
16874
16875 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
16876 ASSERT_VK_SUCCESS(err);
16877
16878 uint8_t *pData;
16879 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
16880 ASSERT_VK_SUCCESS(err);
16881
16882 memset(pData, 0xCADECADE, static_cast<size_t>(mem_reqs.size));
16883
16884 vkUnmapMemory(m_device->device(), mem);
16885
16886 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
16887 ASSERT_VK_SUCCESS(err);
16888
16889 // NOW, destroy the buffer. Obviously, the resource no longer occupies this
16890 // memory. In fact, it was never used by the GPU.
16891 // Just be be sure, wait for idle.
16892 vkDestroyBuffer(m_device->device(), buffer, NULL);
16893 vkDeviceWaitIdle(m_device->device());
16894
Tobin Ehlis6a005702016-12-28 15:25:56 -070016895 // Use optimal as some platforms report linear support but then fail image creation
16896 VkImageTiling image_tiling = VK_IMAGE_TILING_OPTIMAL;
16897 VkImageFormatProperties image_format_properties;
16898 vkGetPhysicalDeviceImageFormatProperties(gpu(), VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_TYPE_2D, image_tiling,
16899 VK_IMAGE_USAGE_TRANSFER_SRC_BIT, 0, &image_format_properties);
16900 if (image_format_properties.maxExtent.width == 0) {
16901 printf("Image format not supported; skipped.\n");
16902 vkFreeMemory(m_device->device(), mem, NULL);
16903 return;
16904 }
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016905 VkImageCreateInfo image_create_info = {};
16906 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16907 image_create_info.pNext = NULL;
16908 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16909 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
16910 image_create_info.extent.width = 64;
16911 image_create_info.extent.height = 64;
16912 image_create_info.extent.depth = 1;
16913 image_create_info.mipLevels = 1;
16914 image_create_info.arrayLayers = 1;
16915 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehlis6a005702016-12-28 15:25:56 -070016916 image_create_info.tiling = image_tiling;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016917 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
16918 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
16919 image_create_info.queueFamilyIndexCount = 0;
16920 image_create_info.pQueueFamilyIndices = NULL;
16921 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
16922 image_create_info.flags = 0;
16923
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016924 /* Create a mappable image. It will be the texture if linear images are ok
16925 * to be textures or it will be the staging image if they are not.
16926 */
16927 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
16928 ASSERT_VK_SUCCESS(err);
16929
16930 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
16931
Tobin Ehlis6a005702016-12-28 15:25:56 -070016932 VkMemoryAllocateInfo mem_alloc = {};
16933 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16934 mem_alloc.pNext = NULL;
16935 mem_alloc.allocationSize = 0;
16936 mem_alloc.memoryTypeIndex = 0;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016937 mem_alloc.allocationSize = mem_reqs.size;
16938
16939 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
16940 if (!pass) {
Tobin Ehlis6a005702016-12-28 15:25:56 -070016941 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016942 vkDestroyImage(m_device->device(), image, NULL);
16943 return;
16944 }
16945
16946 // VALIDATION FAILURE:
16947 err = vkBindImageMemory(m_device->device(), image, mem, 0);
16948 ASSERT_VK_SUCCESS(err);
16949
16950 m_errorMonitor->VerifyNotFound();
16951
16952 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016953 vkDestroyImage(m_device->device(), image, NULL);
16954}
16955
Tobin Ehlis953e8392016-11-17 10:54:13 -070016956TEST_F(VkPositiveLayerTest, DynamicOffsetWithInactiveBinding) {
16957 // Create a descriptorSet w/ dynamic descriptors where 1 binding is inactive
16958 // We previously had a bug where dynamic offset of inactive bindings was still being used
16959 VkResult err;
16960 m_errorMonitor->ExpectSuccess();
16961
16962 ASSERT_NO_FATAL_FAILURE(InitState());
16963 ASSERT_NO_FATAL_FAILURE(InitViewport());
16964 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
16965
16966 VkDescriptorPoolSize ds_type_count = {};
16967 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
16968 ds_type_count.descriptorCount = 3;
16969
16970 VkDescriptorPoolCreateInfo ds_pool_ci = {};
16971 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
16972 ds_pool_ci.pNext = NULL;
16973 ds_pool_ci.maxSets = 1;
16974 ds_pool_ci.poolSizeCount = 1;
16975 ds_pool_ci.pPoolSizes = &ds_type_count;
16976
16977 VkDescriptorPool ds_pool;
16978 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
16979 ASSERT_VK_SUCCESS(err);
16980
16981 const uint32_t BINDING_COUNT = 3;
16982 VkDescriptorSetLayoutBinding dsl_binding[BINDING_COUNT] = {};
Tobin Ehlis0050fba2016-11-30 10:22:02 -070016983 dsl_binding[0].binding = 2;
Tobin Ehlis953e8392016-11-17 10:54:13 -070016984 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
16985 dsl_binding[0].descriptorCount = 1;
16986 dsl_binding[0].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
16987 dsl_binding[0].pImmutableSamplers = NULL;
Tobin Ehlis0050fba2016-11-30 10:22:02 -070016988 dsl_binding[1].binding = 0;
Tobin Ehlis953e8392016-11-17 10:54:13 -070016989 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
16990 dsl_binding[1].descriptorCount = 1;
16991 dsl_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
16992 dsl_binding[1].pImmutableSamplers = NULL;
Tobin Ehlis0050fba2016-11-30 10:22:02 -070016993 dsl_binding[2].binding = 1;
Tobin Ehlis953e8392016-11-17 10:54:13 -070016994 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
16995 dsl_binding[2].descriptorCount = 1;
16996 dsl_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
16997 dsl_binding[2].pImmutableSamplers = NULL;
16998
16999 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
17000 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
17001 ds_layout_ci.pNext = NULL;
17002 ds_layout_ci.bindingCount = BINDING_COUNT;
17003 ds_layout_ci.pBindings = dsl_binding;
17004 VkDescriptorSetLayout ds_layout;
17005 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
17006 ASSERT_VK_SUCCESS(err);
17007
17008 VkDescriptorSet descriptor_set;
17009 VkDescriptorSetAllocateInfo alloc_info = {};
17010 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
17011 alloc_info.descriptorSetCount = 1;
17012 alloc_info.descriptorPool = ds_pool;
17013 alloc_info.pSetLayouts = &ds_layout;
17014 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
17015 ASSERT_VK_SUCCESS(err);
17016
17017 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
17018 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
17019 pipeline_layout_ci.pNext = NULL;
17020 pipeline_layout_ci.setLayoutCount = 1;
17021 pipeline_layout_ci.pSetLayouts = &ds_layout;
17022
17023 VkPipelineLayout pipeline_layout;
17024 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
17025 ASSERT_VK_SUCCESS(err);
17026
17027 // Create two buffers to update the descriptors with
17028 // The first will be 2k and used for bindings 0 & 1, the second is 1k for binding 2
17029 uint32_t qfi = 0;
17030 VkBufferCreateInfo buffCI = {};
17031 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
17032 buffCI.size = 2048;
17033 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
17034 buffCI.queueFamilyIndexCount = 1;
17035 buffCI.pQueueFamilyIndices = &qfi;
17036
17037 VkBuffer dyub1;
17038 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub1);
17039 ASSERT_VK_SUCCESS(err);
17040 // buffer2
17041 buffCI.size = 1024;
17042 VkBuffer dyub2;
17043 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub2);
17044 ASSERT_VK_SUCCESS(err);
17045 // Allocate memory and bind to buffers
17046 VkMemoryAllocateInfo mem_alloc[2] = {};
17047 mem_alloc[0].sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17048 mem_alloc[0].pNext = NULL;
17049 mem_alloc[0].memoryTypeIndex = 0;
17050 mem_alloc[1].sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17051 mem_alloc[1].pNext = NULL;
17052 mem_alloc[1].memoryTypeIndex = 0;
17053
17054 VkMemoryRequirements mem_reqs1;
17055 vkGetBufferMemoryRequirements(m_device->device(), dyub1, &mem_reqs1);
17056 VkMemoryRequirements mem_reqs2;
17057 vkGetBufferMemoryRequirements(m_device->device(), dyub2, &mem_reqs2);
17058 mem_alloc[0].allocationSize = mem_reqs1.size;
17059 bool pass = m_device->phy().set_memory_type(mem_reqs1.memoryTypeBits, &mem_alloc[0], 0);
17060 mem_alloc[1].allocationSize = mem_reqs2.size;
17061 pass &= m_device->phy().set_memory_type(mem_reqs2.memoryTypeBits, &mem_alloc[1], 0);
17062 if (!pass) {
17063 vkDestroyBuffer(m_device->device(), dyub1, NULL);
17064 vkDestroyBuffer(m_device->device(), dyub2, NULL);
17065 return;
17066 }
17067
17068 VkDeviceMemory mem1;
17069 err = vkAllocateMemory(m_device->device(), &mem_alloc[0], NULL, &mem1);
17070 ASSERT_VK_SUCCESS(err);
17071 err = vkBindBufferMemory(m_device->device(), dyub1, mem1, 0);
17072 ASSERT_VK_SUCCESS(err);
17073 VkDeviceMemory mem2;
17074 err = vkAllocateMemory(m_device->device(), &mem_alloc[1], NULL, &mem2);
17075 ASSERT_VK_SUCCESS(err);
17076 err = vkBindBufferMemory(m_device->device(), dyub2, mem2, 0);
17077 ASSERT_VK_SUCCESS(err);
17078 // Update descriptors
17079 VkDescriptorBufferInfo buff_info[BINDING_COUNT] = {};
17080 buff_info[0].buffer = dyub1;
17081 buff_info[0].offset = 0;
17082 buff_info[0].range = 256;
17083 buff_info[1].buffer = dyub1;
17084 buff_info[1].offset = 256;
17085 buff_info[1].range = 512;
17086 buff_info[2].buffer = dyub2;
17087 buff_info[2].offset = 0;
17088 buff_info[2].range = 512;
17089
17090 VkWriteDescriptorSet descriptor_write;
17091 memset(&descriptor_write, 0, sizeof(descriptor_write));
17092 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
17093 descriptor_write.dstSet = descriptor_set;
17094 descriptor_write.dstBinding = 0;
17095 descriptor_write.descriptorCount = BINDING_COUNT;
17096 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
17097 descriptor_write.pBufferInfo = buff_info;
17098
17099 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
17100
17101 BeginCommandBuffer();
17102
17103 // Create PSO to be used for draw-time errors below
17104 char const *vsSource = "#version 450\n"
17105 "\n"
17106 "out gl_PerVertex { \n"
17107 " vec4 gl_Position;\n"
17108 "};\n"
17109 "void main(){\n"
17110 " gl_Position = vec4(1);\n"
17111 "}\n";
17112 char const *fsSource = "#version 450\n"
17113 "\n"
17114 "layout(location=0) out vec4 x;\n"
17115 "layout(set=0) layout(binding=0) uniform foo1 { int x; int y; } bar1;\n"
17116 "layout(set=0) layout(binding=2) uniform foo2 { int x; int y; } bar2;\n"
17117 "void main(){\n"
17118 " x = vec4(bar1.y) + vec4(bar2.y);\n"
17119 "}\n";
17120 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
17121 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
17122 VkPipelineObj pipe(m_device);
17123 pipe.SetViewport(m_viewports);
17124 pipe.SetScissor(m_scissors);
17125 pipe.AddShader(&vs);
17126 pipe.AddShader(&fs);
17127 pipe.AddColorAttachment();
17128 pipe.CreateVKPipeline(pipeline_layout, renderPass());
17129
17130 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
17131 // This update should succeed, but offset of inactive binding 1 oversteps binding 2 buffer size
17132 // we used to have a bug in this case.
17133 uint32_t dyn_off[BINDING_COUNT] = {0, 1024, 256};
17134 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
17135 &descriptor_set, BINDING_COUNT, dyn_off);
17136 Draw(1, 0, 0, 0);
17137 m_errorMonitor->VerifyNotFound();
17138
17139 vkDestroyBuffer(m_device->device(), dyub1, NULL);
17140 vkDestroyBuffer(m_device->device(), dyub2, NULL);
17141 vkFreeMemory(m_device->device(), mem1, NULL);
17142 vkFreeMemory(m_device->device(), mem2, NULL);
17143
17144 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
17145 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
17146 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
17147}
17148
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017149TEST_F(VkPositiveLayerTest, NonCoherentMemoryMapping) {
17150
17151 TEST_DESCRIPTION("Ensure that validations handling of non-coherent memory "
17152 "mapping while using VK_WHOLE_SIZE does not cause access "
17153 "violations");
17154 VkResult err;
17155 uint8_t *pData;
17156 ASSERT_NO_FATAL_FAILURE(InitState());
17157
17158 VkDeviceMemory mem;
17159 VkMemoryRequirements mem_reqs;
17160 mem_reqs.memoryTypeBits = 0xFFFFFFFF;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017161 const VkDeviceSize atom_size = m_device->props.limits.nonCoherentAtomSize;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017162 VkMemoryAllocateInfo alloc_info = {};
17163 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17164 alloc_info.pNext = NULL;
17165 alloc_info.memoryTypeIndex = 0;
17166
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017167 static const VkDeviceSize allocation_size = 32 * atom_size;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017168 alloc_info.allocationSize = allocation_size;
17169
17170 // Find a memory configurations WITHOUT a COHERENT bit, otherwise exit
17171 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT,
17172 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
17173 if (!pass) {
17174 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info,
17175 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT,
17176 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
17177 if (!pass) {
17178 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info,
17179 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT |
17180 VK_MEMORY_PROPERTY_HOST_CACHED_BIT,
17181 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
17182 if (!pass) {
17183 return;
17184 }
17185 }
17186 }
17187
17188 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
17189 ASSERT_VK_SUCCESS(err);
17190
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017191 // Map/Flush/Invalidate using WHOLE_SIZE and zero offsets and entire mapped range
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017192 m_errorMonitor->ExpectSuccess();
17193 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, (void **)&pData);
17194 ASSERT_VK_SUCCESS(err);
17195 VkMappedMemoryRange mmr = {};
17196 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
17197 mmr.memory = mem;
17198 mmr.offset = 0;
17199 mmr.size = VK_WHOLE_SIZE;
17200 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
17201 ASSERT_VK_SUCCESS(err);
17202 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
17203 ASSERT_VK_SUCCESS(err);
17204 m_errorMonitor->VerifyNotFound();
17205 vkUnmapMemory(m_device->device(), mem);
17206
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017207 // Map/Flush/Invalidate using WHOLE_SIZE and an offset and entire mapped range
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017208 m_errorMonitor->ExpectSuccess();
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017209 err = vkMapMemory(m_device->device(), mem, 5 * atom_size, VK_WHOLE_SIZE, 0, (void **)&pData);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017210 ASSERT_VK_SUCCESS(err);
17211 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
17212 mmr.memory = mem;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017213 mmr.offset = 6 * atom_size;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017214 mmr.size = VK_WHOLE_SIZE;
17215 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
17216 ASSERT_VK_SUCCESS(err);
17217 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
17218 ASSERT_VK_SUCCESS(err);
17219 m_errorMonitor->VerifyNotFound();
17220 vkUnmapMemory(m_device->device(), mem);
17221
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017222 // Map with offset and size
17223 // Flush/Invalidate subrange of mapped area with offset and size
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017224 m_errorMonitor->ExpectSuccess();
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017225 err = vkMapMemory(m_device->device(), mem, 3 * atom_size, 9 * atom_size, 0, (void **)&pData);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017226 ASSERT_VK_SUCCESS(err);
17227 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
17228 mmr.memory = mem;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017229 mmr.offset = 4 * atom_size;
17230 mmr.size = 2 * atom_size;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017231 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
17232 ASSERT_VK_SUCCESS(err);
17233 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
17234 ASSERT_VK_SUCCESS(err);
17235 m_errorMonitor->VerifyNotFound();
17236 vkUnmapMemory(m_device->device(), mem);
17237
17238 // Map without offset and flush WHOLE_SIZE with two separate offsets
17239 m_errorMonitor->ExpectSuccess();
17240 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, (void **)&pData);
17241 ASSERT_VK_SUCCESS(err);
17242 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
17243 mmr.memory = mem;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017244 mmr.offset = allocation_size - (4 * atom_size);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017245 mmr.size = VK_WHOLE_SIZE;
17246 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
17247 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017248 mmr.offset = allocation_size - (6 * atom_size);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017249 mmr.size = VK_WHOLE_SIZE;
17250 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
17251 ASSERT_VK_SUCCESS(err);
17252 m_errorMonitor->VerifyNotFound();
17253 vkUnmapMemory(m_device->device(), mem);
17254
17255 vkFreeMemory(m_device->device(), mem, NULL);
17256}
17257
17258// This is a positive test. We used to expect error in this case but spec now allows it
17259TEST_F(VkPositiveLayerTest, ResetUnsignaledFence) {
17260 m_errorMonitor->ExpectSuccess();
17261 vk_testing::Fence testFence;
17262 VkFenceCreateInfo fenceInfo = {};
17263 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
17264 fenceInfo.pNext = NULL;
17265
17266 ASSERT_NO_FATAL_FAILURE(InitState());
17267 testFence.init(*m_device, fenceInfo);
17268 VkFence fences[1] = { testFence.handle() };
17269 VkResult result = vkResetFences(m_device->device(), 1, fences);
17270 ASSERT_VK_SUCCESS(result);
17271
17272 m_errorMonitor->VerifyNotFound();
17273}
17274
17275TEST_F(VkPositiveLayerTest, CommandBufferSimultaneousUseSync) {
17276 m_errorMonitor->ExpectSuccess();
17277
17278 ASSERT_NO_FATAL_FAILURE(InitState());
17279 VkResult err;
17280
17281 // Record (empty!) command buffer that can be submitted multiple times
17282 // simultaneously.
17283 VkCommandBufferBeginInfo cbbi = { VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr,
17284 VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT, nullptr };
17285 m_commandBuffer->BeginCommandBuffer(&cbbi);
17286 m_commandBuffer->EndCommandBuffer();
17287
17288 VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
17289 VkFence fence;
17290 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
17291 ASSERT_VK_SUCCESS(err);
17292
17293 VkSemaphoreCreateInfo sci = { VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0 };
17294 VkSemaphore s1, s2;
17295 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s1);
17296 ASSERT_VK_SUCCESS(err);
17297 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s2);
17298 ASSERT_VK_SUCCESS(err);
17299
17300 // Submit CB once signaling s1, with fence so we can roll forward to its retirement.
17301 VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 1, &m_commandBuffer->handle(), 1, &s1 };
17302 err = vkQueueSubmit(m_device->m_queue, 1, &si, fence);
17303 ASSERT_VK_SUCCESS(err);
17304
17305 // Submit CB again, signaling s2.
17306 si.pSignalSemaphores = &s2;
17307 err = vkQueueSubmit(m_device->m_queue, 1, &si, VK_NULL_HANDLE);
17308 ASSERT_VK_SUCCESS(err);
17309
17310 // Wait for fence.
17311 err = vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
17312 ASSERT_VK_SUCCESS(err);
17313
17314 // CB is still in flight from second submission, but semaphore s1 is no
17315 // longer in flight. delete it.
17316 vkDestroySemaphore(m_device->device(), s1, nullptr);
17317
17318 m_errorMonitor->VerifyNotFound();
17319
17320 // Force device idle and clean up remaining objects
17321 vkDeviceWaitIdle(m_device->device());
17322 vkDestroySemaphore(m_device->device(), s2, nullptr);
17323 vkDestroyFence(m_device->device(), fence, nullptr);
17324}
17325
17326TEST_F(VkPositiveLayerTest, FenceCreateSignaledWaitHandling) {
17327 m_errorMonitor->ExpectSuccess();
17328
17329 ASSERT_NO_FATAL_FAILURE(InitState());
17330 VkResult err;
17331
17332 // A fence created signaled
17333 VkFenceCreateInfo fci1 = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, VK_FENCE_CREATE_SIGNALED_BIT };
17334 VkFence f1;
17335 err = vkCreateFence(m_device->device(), &fci1, nullptr, &f1);
17336 ASSERT_VK_SUCCESS(err);
17337
17338 // A fence created not
17339 VkFenceCreateInfo fci2 = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
17340 VkFence f2;
17341 err = vkCreateFence(m_device->device(), &fci2, nullptr, &f2);
17342 ASSERT_VK_SUCCESS(err);
17343
17344 // Submit the unsignaled fence
17345 VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 0, nullptr, 0, nullptr };
17346 err = vkQueueSubmit(m_device->m_queue, 1, &si, f2);
17347
17348 // Wait on both fences, with signaled first.
17349 VkFence fences[] = { f1, f2 };
17350 vkWaitForFences(m_device->device(), 2, fences, VK_TRUE, UINT64_MAX);
17351
17352 // Should have both retired!
17353 vkDestroyFence(m_device->device(), f1, nullptr);
17354 vkDestroyFence(m_device->device(), f2, nullptr);
17355
17356 m_errorMonitor->VerifyNotFound();
17357}
17358
17359TEST_F(VkPositiveLayerTest, ValidUsage) {
17360 TEST_DESCRIPTION("Verify that creating an image view from an image with valid usage "
17361 "doesn't generate validation errors");
17362
17363 ASSERT_NO_FATAL_FAILURE(InitState());
17364
17365 m_errorMonitor->ExpectSuccess();
17366 // Verify that we can create a view with usage INPUT_ATTACHMENT
17367 VkImageObj image(m_device);
17368 image.init(128, 128, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
17369 ASSERT_TRUE(image.initialized());
17370 VkImageView imageView;
17371 VkImageViewCreateInfo ivci = {};
17372 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
17373 ivci.image = image.handle();
17374 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
17375 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
17376 ivci.subresourceRange.layerCount = 1;
17377 ivci.subresourceRange.baseMipLevel = 0;
17378 ivci.subresourceRange.levelCount = 1;
17379 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
17380
17381 vkCreateImageView(m_device->device(), &ivci, NULL, &imageView);
17382 m_errorMonitor->VerifyNotFound();
17383 vkDestroyImageView(m_device->device(), imageView, NULL);
17384}
17385
17386// This is a positive test. No failures are expected.
17387TEST_F(VkPositiveLayerTest, BindSparse) {
17388 TEST_DESCRIPTION("Bind 2 memory ranges to one image using vkQueueBindSparse, destroy the image"
17389 "and then free the memory");
17390
17391 ASSERT_NO_FATAL_FAILURE(InitState());
17392
17393 auto index = m_device->graphics_queue_node_index_;
17394 if (!(m_device->queue_props[index].queueFlags & VK_QUEUE_SPARSE_BINDING_BIT))
17395 return;
17396
17397 m_errorMonitor->ExpectSuccess();
17398
17399 VkImage image;
17400 VkImageCreateInfo image_create_info = {};
17401 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
17402 image_create_info.pNext = NULL;
17403 image_create_info.imageType = VK_IMAGE_TYPE_2D;
17404 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
17405 image_create_info.extent.width = 64;
17406 image_create_info.extent.height = 64;
17407 image_create_info.extent.depth = 1;
17408 image_create_info.mipLevels = 1;
17409 image_create_info.arrayLayers = 1;
17410 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
17411 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
17412 image_create_info.usage = VK_IMAGE_USAGE_STORAGE_BIT;
17413 image_create_info.flags = VK_IMAGE_CREATE_SPARSE_BINDING_BIT;
17414 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
17415 ASSERT_VK_SUCCESS(err);
17416
17417 VkMemoryRequirements memory_reqs;
17418 VkDeviceMemory memory_one, memory_two;
17419 bool pass;
17420 VkMemoryAllocateInfo memory_info = {};
17421 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17422 memory_info.pNext = NULL;
17423 memory_info.allocationSize = 0;
17424 memory_info.memoryTypeIndex = 0;
17425 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
17426 // Find an image big enough to allow sparse mapping of 2 memory regions
17427 // Increase the image size until it is at least twice the
17428 // size of the required alignment, to ensure we can bind both
17429 // allocated memory blocks to the image on aligned offsets.
17430 while (memory_reqs.size < (memory_reqs.alignment * 2)) {
17431 vkDestroyImage(m_device->device(), image, nullptr);
17432 image_create_info.extent.width *= 2;
17433 image_create_info.extent.height *= 2;
17434 err = vkCreateImage(m_device->device(), &image_create_info, nullptr, &image);
17435 ASSERT_VK_SUCCESS(err);
17436 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
17437 }
17438 // Allocate 2 memory regions of minimum alignment size, bind one at 0, the other
17439 // at the end of the first
17440 memory_info.allocationSize = memory_reqs.alignment;
17441 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
17442 ASSERT_TRUE(pass);
17443 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &memory_one);
17444 ASSERT_VK_SUCCESS(err);
17445 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &memory_two);
17446 ASSERT_VK_SUCCESS(err);
17447 VkSparseMemoryBind binds[2];
17448 binds[0].flags = 0;
17449 binds[0].memory = memory_one;
17450 binds[0].memoryOffset = 0;
17451 binds[0].resourceOffset = 0;
17452 binds[0].size = memory_info.allocationSize;
17453 binds[1].flags = 0;
17454 binds[1].memory = memory_two;
17455 binds[1].memoryOffset = 0;
17456 binds[1].resourceOffset = memory_info.allocationSize;
17457 binds[1].size = memory_info.allocationSize;
17458
17459 VkSparseImageOpaqueMemoryBindInfo opaqueBindInfo;
17460 opaqueBindInfo.image = image;
17461 opaqueBindInfo.bindCount = 2;
17462 opaqueBindInfo.pBinds = binds;
17463
17464 VkFence fence = VK_NULL_HANDLE;
17465 VkBindSparseInfo bindSparseInfo = {};
17466 bindSparseInfo.sType = VK_STRUCTURE_TYPE_BIND_SPARSE_INFO;
17467 bindSparseInfo.imageOpaqueBindCount = 1;
17468 bindSparseInfo.pImageOpaqueBinds = &opaqueBindInfo;
17469
17470 vkQueueBindSparse(m_device->m_queue, 1, &bindSparseInfo, fence);
17471 vkQueueWaitIdle(m_device->m_queue);
17472 vkDestroyImage(m_device->device(), image, NULL);
17473 vkFreeMemory(m_device->device(), memory_one, NULL);
17474 vkFreeMemory(m_device->device(), memory_two, NULL);
17475 m_errorMonitor->VerifyNotFound();
17476}
17477
17478TEST_F(VkPositiveLayerTest, RenderPassInitialLayoutUndefined) {
17479 TEST_DESCRIPTION("Ensure that CmdBeginRenderPass with an attachment's "
17480 "initialLayout of VK_IMAGE_LAYOUT_UNDEFINED works when "
17481 "the command buffer has prior knowledge of that "
17482 "attachment's layout.");
17483
17484 m_errorMonitor->ExpectSuccess();
17485
17486 ASSERT_NO_FATAL_FAILURE(InitState());
17487
17488 // A renderpass with one color attachment.
17489 VkAttachmentDescription attachment = { 0,
17490 VK_FORMAT_R8G8B8A8_UNORM,
17491 VK_SAMPLE_COUNT_1_BIT,
17492 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
17493 VK_ATTACHMENT_STORE_OP_STORE,
17494 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
17495 VK_ATTACHMENT_STORE_OP_DONT_CARE,
17496 VK_IMAGE_LAYOUT_UNDEFINED,
17497 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
17498
17499 VkAttachmentReference att_ref = { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
17500
17501 VkSubpassDescription subpass = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr };
17502
17503 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr };
17504
17505 VkRenderPass rp;
17506 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
17507 ASSERT_VK_SUCCESS(err);
17508
17509 // A compatible framebuffer.
17510 VkImageObj image(m_device);
17511 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
17512 ASSERT_TRUE(image.initialized());
17513
17514 VkImageViewCreateInfo ivci = {
17515 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
17516 nullptr,
17517 0,
17518 image.handle(),
17519 VK_IMAGE_VIEW_TYPE_2D,
17520 VK_FORMAT_R8G8B8A8_UNORM,
17521 { VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
17522 VK_COMPONENT_SWIZZLE_IDENTITY },
17523 { VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 },
17524 };
17525 VkImageView view;
17526 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
17527 ASSERT_VK_SUCCESS(err);
17528
17529 VkFramebufferCreateInfo fci = { VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1 };
17530 VkFramebuffer fb;
17531 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
17532 ASSERT_VK_SUCCESS(err);
17533
17534 // Record a single command buffer which uses this renderpass twice. The
17535 // bug is triggered at the beginning of the second renderpass, when the
17536 // command buffer already has a layout recorded for the attachment.
17537 VkRenderPassBeginInfo rpbi = { VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb,{ { 0, 0 },{ 32, 32 } }, 0, nullptr };
17538 BeginCommandBuffer();
17539 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
17540 vkCmdEndRenderPass(m_commandBuffer->handle());
17541 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
17542
17543 m_errorMonitor->VerifyNotFound();
17544
17545 vkCmdEndRenderPass(m_commandBuffer->handle());
17546 EndCommandBuffer();
17547
17548 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
17549 vkDestroyRenderPass(m_device->device(), rp, nullptr);
17550 vkDestroyImageView(m_device->device(), view, nullptr);
17551}
17552
17553TEST_F(VkPositiveLayerTest, FramebufferBindingDestroyCommandPool) {
17554 TEST_DESCRIPTION("This test should pass. Create a Framebuffer and "
17555 "command buffer, bind them together, then destroy "
17556 "command pool and framebuffer and verify there are no "
17557 "errors.");
17558
17559 m_errorMonitor->ExpectSuccess();
17560
17561 ASSERT_NO_FATAL_FAILURE(InitState());
17562
17563 // A renderpass with one color attachment.
17564 VkAttachmentDescription attachment = { 0,
17565 VK_FORMAT_R8G8B8A8_UNORM,
17566 VK_SAMPLE_COUNT_1_BIT,
17567 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
17568 VK_ATTACHMENT_STORE_OP_STORE,
17569 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
17570 VK_ATTACHMENT_STORE_OP_DONT_CARE,
17571 VK_IMAGE_LAYOUT_UNDEFINED,
17572 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
17573
17574 VkAttachmentReference att_ref = { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
17575
17576 VkSubpassDescription subpass = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr };
17577
17578 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr };
17579
17580 VkRenderPass rp;
17581 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
17582 ASSERT_VK_SUCCESS(err);
17583
17584 // A compatible framebuffer.
17585 VkImageObj image(m_device);
17586 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
17587 ASSERT_TRUE(image.initialized());
17588
17589 VkImageViewCreateInfo ivci = {
17590 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
17591 nullptr,
17592 0,
17593 image.handle(),
17594 VK_IMAGE_VIEW_TYPE_2D,
17595 VK_FORMAT_R8G8B8A8_UNORM,
17596 { VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
17597 VK_COMPONENT_SWIZZLE_IDENTITY },
17598 { VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 },
17599 };
17600 VkImageView view;
17601 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
17602 ASSERT_VK_SUCCESS(err);
17603
17604 VkFramebufferCreateInfo fci = { VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1 };
17605 VkFramebuffer fb;
17606 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
17607 ASSERT_VK_SUCCESS(err);
17608
17609 // Explicitly create a command buffer to bind the FB to so that we can then
17610 // destroy the command pool in order to implicitly free command buffer
17611 VkCommandPool command_pool;
17612 VkCommandPoolCreateInfo pool_create_info{};
17613 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17614 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
17615 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17616 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
17617
17618 VkCommandBuffer command_buffer;
17619 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
17620 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17621 command_buffer_allocate_info.commandPool = command_pool;
17622 command_buffer_allocate_info.commandBufferCount = 1;
17623 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17624 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
17625
17626 // Begin our cmd buffer with renderpass using our framebuffer
17627 VkRenderPassBeginInfo rpbi = { VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb,{ { 0, 0 },{ 32, 32 } }, 0, nullptr };
17628 VkCommandBufferBeginInfo begin_info{};
17629 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17630 vkBeginCommandBuffer(command_buffer, &begin_info);
17631
17632 vkCmdBeginRenderPass(command_buffer, &rpbi, VK_SUBPASS_CONTENTS_INLINE);
17633 vkCmdEndRenderPass(command_buffer);
17634 vkEndCommandBuffer(command_buffer);
17635 vkDestroyImageView(m_device->device(), view, nullptr);
17636 // Destroy command pool to implicitly free command buffer
17637 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
17638 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
17639 vkDestroyRenderPass(m_device->device(), rp, nullptr);
17640 m_errorMonitor->VerifyNotFound();
17641}
17642
17643TEST_F(VkPositiveLayerTest, RenderPassSubpassZeroTransitionsApplied) {
17644 TEST_DESCRIPTION("Ensure that CmdBeginRenderPass applies the layout "
17645 "transitions for the first subpass");
17646
17647 m_errorMonitor->ExpectSuccess();
17648
17649 ASSERT_NO_FATAL_FAILURE(InitState());
17650
17651 // A renderpass with one color attachment.
17652 VkAttachmentDescription attachment = { 0,
17653 VK_FORMAT_R8G8B8A8_UNORM,
17654 VK_SAMPLE_COUNT_1_BIT,
17655 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
17656 VK_ATTACHMENT_STORE_OP_STORE,
17657 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
17658 VK_ATTACHMENT_STORE_OP_DONT_CARE,
17659 VK_IMAGE_LAYOUT_UNDEFINED,
17660 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
17661
17662 VkAttachmentReference att_ref = { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
17663
17664 VkSubpassDescription subpass = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr };
17665
17666 VkSubpassDependency dep = { 0,
17667 0,
17668 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
17669 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
17670 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
17671 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
17672 VK_DEPENDENCY_BY_REGION_BIT };
17673
17674 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 1, &dep };
17675
17676 VkResult err;
17677 VkRenderPass rp;
17678 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
17679 ASSERT_VK_SUCCESS(err);
17680
17681 // A compatible framebuffer.
17682 VkImageObj image(m_device);
17683 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
17684 ASSERT_TRUE(image.initialized());
17685
17686 VkImageViewCreateInfo ivci = {
17687 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
17688 nullptr,
17689 0,
17690 image.handle(),
17691 VK_IMAGE_VIEW_TYPE_2D,
17692 VK_FORMAT_R8G8B8A8_UNORM,
17693 { VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
17694 VK_COMPONENT_SWIZZLE_IDENTITY },
17695 { VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 },
17696 };
17697 VkImageView view;
17698 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
17699 ASSERT_VK_SUCCESS(err);
17700
17701 VkFramebufferCreateInfo fci = { VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1 };
17702 VkFramebuffer fb;
17703 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
17704 ASSERT_VK_SUCCESS(err);
17705
17706 // Record a single command buffer which issues a pipeline barrier w/
17707 // image memory barrier for the attachment. This detects the previously
17708 // missing tracking of the subpass layout by throwing a validation error
17709 // if it doesn't occur.
17710 VkRenderPassBeginInfo rpbi = { VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb,{ { 0, 0 },{ 32, 32 } }, 0, nullptr };
17711 BeginCommandBuffer();
17712 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
17713
17714 VkImageMemoryBarrier imb = { VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,
17715 nullptr,
17716 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
17717 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
17718 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
17719 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
17720 VK_QUEUE_FAMILY_IGNORED,
17721 VK_QUEUE_FAMILY_IGNORED,
17722 image.handle(),
17723 { VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 } };
17724 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
17725 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_DEPENDENCY_BY_REGION_BIT, 0, nullptr, 0, nullptr, 1,
17726 &imb);
17727
17728 vkCmdEndRenderPass(m_commandBuffer->handle());
17729 m_errorMonitor->VerifyNotFound();
17730 EndCommandBuffer();
17731
17732 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
17733 vkDestroyRenderPass(m_device->device(), rp, nullptr);
17734 vkDestroyImageView(m_device->device(), view, nullptr);
17735}
17736
17737TEST_F(VkPositiveLayerTest, DepthStencilLayoutTransitionForDepthOnlyImageview) {
17738 TEST_DESCRIPTION("Validate that when an imageView of a depth/stencil image "
17739 "is used as a depth/stencil framebuffer attachment, the "
17740 "aspectMask is ignored and both depth and stencil image "
17741 "subresources are used.");
17742
17743 VkFormatProperties format_properties;
17744 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_D32_SFLOAT_S8_UINT, &format_properties);
17745 if (!(format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)) {
17746 return;
17747 }
17748
17749 m_errorMonitor->ExpectSuccess();
17750
17751 ASSERT_NO_FATAL_FAILURE(InitState());
17752
17753 VkAttachmentDescription attachment = { 0,
17754 VK_FORMAT_D32_SFLOAT_S8_UINT,
17755 VK_SAMPLE_COUNT_1_BIT,
17756 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
17757 VK_ATTACHMENT_STORE_OP_STORE,
17758 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
17759 VK_ATTACHMENT_STORE_OP_DONT_CARE,
17760 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
17761 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL };
17762
17763 VkAttachmentReference att_ref = { 0, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL };
17764
17765 VkSubpassDescription subpass = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, &att_ref, 0, nullptr };
17766
17767 VkSubpassDependency dep = { 0,
17768 0,
17769 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
17770 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
17771 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
17772 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
17773 VK_DEPENDENCY_BY_REGION_BIT};
17774
17775 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 1, &dep };
17776
17777 VkResult err;
17778 VkRenderPass rp;
17779 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
17780 ASSERT_VK_SUCCESS(err);
17781
17782 VkImageObj image(m_device);
17783 image.init_no_layout(32, 32, VK_FORMAT_D32_SFLOAT_S8_UINT,
17784 0x26, // usage
17785 VK_IMAGE_TILING_OPTIMAL, 0);
17786 ASSERT_TRUE(image.initialized());
17787 image.SetLayout(0x6, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL);
17788
17789 VkImageViewCreateInfo ivci = {
17790 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
17791 nullptr,
17792 0,
17793 image.handle(),
17794 VK_IMAGE_VIEW_TYPE_2D,
17795 VK_FORMAT_D32_SFLOAT_S8_UINT,
17796 { VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A },
17797 { 0x2, 0, 1, 0, 1 },
17798 };
17799 VkImageView view;
17800 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
17801 ASSERT_VK_SUCCESS(err);
17802
17803 VkFramebufferCreateInfo fci = { VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1 };
17804 VkFramebuffer fb;
17805 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
17806 ASSERT_VK_SUCCESS(err);
17807
17808 VkRenderPassBeginInfo rpbi = { VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb,{ { 0, 0 },{ 32, 32 } }, 0, nullptr };
17809 BeginCommandBuffer();
17810 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
17811
17812 VkImageMemoryBarrier imb = {};
17813 imb.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
17814 imb.pNext = nullptr;
17815 imb.srcAccessMask = VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
17816 imb.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
17817 imb.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
17818 imb.newLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
17819 imb.srcQueueFamilyIndex = 0;
17820 imb.dstQueueFamilyIndex = 0;
17821 imb.image = image.handle();
17822 imb.subresourceRange.aspectMask = 0x6;
17823 imb.subresourceRange.baseMipLevel = 0;
17824 imb.subresourceRange.levelCount = 0x1;
17825 imb.subresourceRange.baseArrayLayer = 0;
17826 imb.subresourceRange.layerCount = 0x1;
17827
17828 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
17829 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_DEPENDENCY_BY_REGION_BIT, 0, nullptr, 0, nullptr, 1,
17830 &imb);
17831
17832 vkCmdEndRenderPass(m_commandBuffer->handle());
17833 EndCommandBuffer();
17834 QueueCommandBuffer(false);
17835 m_errorMonitor->VerifyNotFound();
17836
17837 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
17838 vkDestroyRenderPass(m_device->device(), rp, nullptr);
17839 vkDestroyImageView(m_device->device(), view, nullptr);
17840}
17841
17842TEST_F(VkPositiveLayerTest, RenderPassTransitionsAttachmentUnused) {
17843 TEST_DESCRIPTION("Ensure that layout transitions work correctly without "
17844 "errors, when an attachment reference is "
17845 "VK_ATTACHMENT_UNUSED");
17846
17847 m_errorMonitor->ExpectSuccess();
17848
17849 ASSERT_NO_FATAL_FAILURE(InitState());
17850
17851 // A renderpass with no attachments
17852 VkAttachmentReference att_ref = { VK_ATTACHMENT_UNUSED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
17853
17854 VkSubpassDescription subpass = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr };
17855
17856 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 1, &subpass, 0, nullptr };
17857
17858 VkRenderPass rp;
17859 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
17860 ASSERT_VK_SUCCESS(err);
17861
17862 // A compatible framebuffer.
17863 VkFramebufferCreateInfo fci = { VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 0, nullptr, 32, 32, 1 };
17864 VkFramebuffer fb;
17865 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
17866 ASSERT_VK_SUCCESS(err);
17867
17868 // Record a command buffer which just begins and ends the renderpass. The
17869 // bug manifests in BeginRenderPass.
17870 VkRenderPassBeginInfo rpbi = { VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb,{ { 0, 0 },{ 32, 32 } }, 0, nullptr };
17871 BeginCommandBuffer();
17872 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
17873 vkCmdEndRenderPass(m_commandBuffer->handle());
17874 m_errorMonitor->VerifyNotFound();
17875 EndCommandBuffer();
17876
17877 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
17878 vkDestroyRenderPass(m_device->device(), rp, nullptr);
17879}
17880
17881// This is a positive test. No errors are expected.
17882TEST_F(VkPositiveLayerTest, StencilLoadOp) {
17883 TEST_DESCRIPTION("Create a stencil-only attachment with a LOAD_OP set to "
17884 "CLEAR. stencil[Load|Store]Op used to be ignored.");
17885 VkResult result = VK_SUCCESS;
17886 VkImageFormatProperties formatProps;
17887 vkGetPhysicalDeviceImageFormatProperties(gpu(), VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
17888 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT, 0,
17889 &formatProps);
17890 if (formatProps.maxExtent.width < 100 || formatProps.maxExtent.height < 100) {
17891 return;
17892 }
17893
17894 ASSERT_NO_FATAL_FAILURE(InitState());
17895 VkFormat depth_stencil_fmt = VK_FORMAT_D24_UNORM_S8_UINT;
17896 m_depthStencil->Init(m_device, 100, 100, depth_stencil_fmt,
17897 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT);
17898 VkAttachmentDescription att = {};
17899 VkAttachmentReference ref = {};
17900 att.format = depth_stencil_fmt;
17901 att.samples = VK_SAMPLE_COUNT_1_BIT;
17902 att.loadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
17903 att.storeOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
17904 att.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
17905 att.stencilStoreOp = VK_ATTACHMENT_STORE_OP_STORE;
17906 att.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
17907 att.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
17908
17909 VkClearValue clear;
17910 clear.depthStencil.depth = 1.0;
17911 clear.depthStencil.stencil = 0;
17912 ref.attachment = 0;
17913 ref.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
17914
17915 VkSubpassDescription subpass = {};
17916 subpass.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;
17917 subpass.flags = 0;
17918 subpass.inputAttachmentCount = 0;
17919 subpass.pInputAttachments = NULL;
17920 subpass.colorAttachmentCount = 0;
17921 subpass.pColorAttachments = NULL;
17922 subpass.pResolveAttachments = NULL;
17923 subpass.pDepthStencilAttachment = &ref;
17924 subpass.preserveAttachmentCount = 0;
17925 subpass.pPreserveAttachments = NULL;
17926
17927 VkRenderPass rp;
17928 VkRenderPassCreateInfo rp_info = {};
17929 rp_info.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
17930 rp_info.attachmentCount = 1;
17931 rp_info.pAttachments = &att;
17932 rp_info.subpassCount = 1;
17933 rp_info.pSubpasses = &subpass;
17934 result = vkCreateRenderPass(device(), &rp_info, NULL, &rp);
17935 ASSERT_VK_SUCCESS(result);
17936
17937 VkImageView *depthView = m_depthStencil->BindInfo();
17938 VkFramebufferCreateInfo fb_info = {};
17939 fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
17940 fb_info.pNext = NULL;
17941 fb_info.renderPass = rp;
17942 fb_info.attachmentCount = 1;
17943 fb_info.pAttachments = depthView;
17944 fb_info.width = 100;
17945 fb_info.height = 100;
17946 fb_info.layers = 1;
17947 VkFramebuffer fb;
17948 result = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
17949 ASSERT_VK_SUCCESS(result);
17950
17951 VkRenderPassBeginInfo rpbinfo = {};
17952 rpbinfo.clearValueCount = 1;
17953 rpbinfo.pClearValues = &clear;
17954 rpbinfo.pNext = NULL;
17955 rpbinfo.renderPass = rp;
17956 rpbinfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
17957 rpbinfo.renderArea.extent.width = 100;
17958 rpbinfo.renderArea.extent.height = 100;
17959 rpbinfo.renderArea.offset.x = 0;
17960 rpbinfo.renderArea.offset.y = 0;
17961 rpbinfo.framebuffer = fb;
17962
17963 VkFence fence = {};
17964 VkFenceCreateInfo fence_ci = {};
17965 fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
17966 fence_ci.pNext = nullptr;
17967 fence_ci.flags = 0;
17968 result = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fence);
17969 ASSERT_VK_SUCCESS(result);
17970
17971 m_commandBuffer->BeginCommandBuffer();
17972 m_commandBuffer->BeginRenderPass(rpbinfo);
17973 m_commandBuffer->EndRenderPass();
17974 m_commandBuffer->EndCommandBuffer();
17975 m_commandBuffer->QueueCommandBuffer(fence);
17976
17977 VkImageObj destImage(m_device);
17978 destImage.init(100, 100, depth_stencil_fmt, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
17979 VK_IMAGE_TILING_OPTIMAL, 0);
17980 VkImageMemoryBarrier barrier = {};
17981 VkImageSubresourceRange range;
17982 barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
17983 barrier.srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
17984 barrier.dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT;
17985 barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
17986 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
17987 barrier.image = m_depthStencil->handle();
17988 range.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
17989 range.baseMipLevel = 0;
17990 range.levelCount = 1;
17991 range.baseArrayLayer = 0;
17992 range.layerCount = 1;
17993 barrier.subresourceRange = range;
17994 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
17995 VkCommandBufferObj cmdbuf(m_device, m_commandPool);
17996 cmdbuf.BeginCommandBuffer();
17997 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
17998 &barrier);
17999 barrier.srcAccessMask = 0;
18000 barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
18001 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
18002 barrier.image = destImage.handle();
18003 barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
18004 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
18005 &barrier);
18006 VkImageCopy cregion;
18007 cregion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
18008 cregion.srcSubresource.mipLevel = 0;
18009 cregion.srcSubresource.baseArrayLayer = 0;
18010 cregion.srcSubresource.layerCount = 1;
18011 cregion.srcOffset.x = 0;
18012 cregion.srcOffset.y = 0;
18013 cregion.srcOffset.z = 0;
18014 cregion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
18015 cregion.dstSubresource.mipLevel = 0;
18016 cregion.dstSubresource.baseArrayLayer = 0;
18017 cregion.dstSubresource.layerCount = 1;
18018 cregion.dstOffset.x = 0;
18019 cregion.dstOffset.y = 0;
18020 cregion.dstOffset.z = 0;
18021 cregion.extent.width = 100;
18022 cregion.extent.height = 100;
18023 cregion.extent.depth = 1;
18024 cmdbuf.CopyImage(m_depthStencil->handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, destImage.handle(),
18025 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &cregion);
18026 cmdbuf.EndCommandBuffer();
18027
18028 VkSubmitInfo submit_info;
18029 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18030 submit_info.pNext = NULL;
18031 submit_info.waitSemaphoreCount = 0;
18032 submit_info.pWaitSemaphores = NULL;
18033 submit_info.pWaitDstStageMask = NULL;
18034 submit_info.commandBufferCount = 1;
18035 submit_info.pCommandBuffers = &cmdbuf.handle();
18036 submit_info.signalSemaphoreCount = 0;
18037 submit_info.pSignalSemaphores = NULL;
18038
18039 m_errorMonitor->ExpectSuccess();
18040 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
18041 m_errorMonitor->VerifyNotFound();
18042
18043 vkQueueWaitIdle(m_device->m_queue);
18044 vkDestroyFence(m_device->device(), fence, nullptr);
18045 vkDestroyRenderPass(m_device->device(), rp, nullptr);
18046 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
18047}
18048
18049// This is a positive test. No errors should be generated.
18050TEST_F(VkPositiveLayerTest, WaitEventThenSet) {
18051 TEST_DESCRIPTION("Wait on a event then set it after the wait has been submitted.");
18052
18053 m_errorMonitor->ExpectSuccess();
18054 ASSERT_NO_FATAL_FAILURE(InitState());
18055
18056 VkEvent event;
18057 VkEventCreateInfo event_create_info{};
18058 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
18059 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
18060
18061 VkCommandPool command_pool;
18062 VkCommandPoolCreateInfo pool_create_info{};
18063 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18064 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18065 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18066 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18067
18068 VkCommandBuffer command_buffer;
18069 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18070 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18071 command_buffer_allocate_info.commandPool = command_pool;
18072 command_buffer_allocate_info.commandBufferCount = 1;
18073 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18074 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
18075
18076 VkQueue queue = VK_NULL_HANDLE;
18077 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
18078
18079 {
18080 VkCommandBufferBeginInfo begin_info{};
18081 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18082 vkBeginCommandBuffer(command_buffer, &begin_info);
18083
18084 vkCmdWaitEvents(command_buffer, 1, &event, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, nullptr, 0,
18085 nullptr, 0, nullptr);
18086 vkCmdResetEvent(command_buffer, event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
18087 vkEndCommandBuffer(command_buffer);
18088 }
18089 {
18090 VkSubmitInfo submit_info{};
18091 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18092 submit_info.commandBufferCount = 1;
18093 submit_info.pCommandBuffers = &command_buffer;
18094 submit_info.signalSemaphoreCount = 0;
18095 submit_info.pSignalSemaphores = nullptr;
18096 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
18097 }
18098 { vkSetEvent(m_device->device(), event); }
18099
18100 vkQueueWaitIdle(queue);
18101
18102 vkDestroyEvent(m_device->device(), event, nullptr);
18103 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
18104 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18105
18106 m_errorMonitor->VerifyNotFound();
18107}
18108// This is a positive test. No errors should be generated.
18109TEST_F(VkPositiveLayerTest, QueryAndCopySecondaryCommandBuffers) {
18110 TEST_DESCRIPTION("Issue a query on a secondary command buffery and copy it on a primary.");
18111
18112 ASSERT_NO_FATAL_FAILURE(InitState());
18113 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
18114 return;
18115
18116 m_errorMonitor->ExpectSuccess();
18117
18118 VkQueryPool query_pool;
18119 VkQueryPoolCreateInfo query_pool_create_info{};
18120 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
18121 query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP;
18122 query_pool_create_info.queryCount = 1;
18123 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
18124
18125 VkCommandPool command_pool;
18126 VkCommandPoolCreateInfo pool_create_info{};
18127 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18128 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18129 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18130 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18131
18132 VkCommandBuffer command_buffer;
18133 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18134 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18135 command_buffer_allocate_info.commandPool = command_pool;
18136 command_buffer_allocate_info.commandBufferCount = 1;
18137 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18138 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
18139
18140 VkCommandBuffer secondary_command_buffer;
18141 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
18142 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer);
18143
18144 VkQueue queue = VK_NULL_HANDLE;
18145 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
18146
18147 uint32_t qfi = 0;
18148 VkBufferCreateInfo buff_create_info = {};
18149 buff_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
18150 buff_create_info.size = 1024;
18151 buff_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
18152 buff_create_info.queueFamilyIndexCount = 1;
18153 buff_create_info.pQueueFamilyIndices = &qfi;
18154
18155 VkResult err;
18156 VkBuffer buffer;
18157 err = vkCreateBuffer(m_device->device(), &buff_create_info, NULL, &buffer);
18158 ASSERT_VK_SUCCESS(err);
18159 VkMemoryAllocateInfo mem_alloc = {};
18160 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18161 mem_alloc.pNext = NULL;
18162 mem_alloc.allocationSize = 1024;
18163 mem_alloc.memoryTypeIndex = 0;
18164
18165 VkMemoryRequirements memReqs;
18166 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
18167 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
18168 if (!pass) {
18169 vkDestroyBuffer(m_device->device(), buffer, NULL);
18170 return;
18171 }
18172
18173 VkDeviceMemory mem;
18174 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
18175 ASSERT_VK_SUCCESS(err);
18176 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
18177 ASSERT_VK_SUCCESS(err);
18178
18179 VkCommandBufferInheritanceInfo hinfo = {};
18180 hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
18181 hinfo.renderPass = VK_NULL_HANDLE;
18182 hinfo.subpass = 0;
18183 hinfo.framebuffer = VK_NULL_HANDLE;
18184 hinfo.occlusionQueryEnable = VK_FALSE;
18185 hinfo.queryFlags = 0;
18186 hinfo.pipelineStatistics = 0;
18187
18188 {
18189 VkCommandBufferBeginInfo begin_info{};
18190 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18191 begin_info.pInheritanceInfo = &hinfo;
18192 vkBeginCommandBuffer(secondary_command_buffer, &begin_info);
18193
18194 vkCmdResetQueryPool(secondary_command_buffer, query_pool, 0, 1);
18195 vkCmdWriteTimestamp(secondary_command_buffer, VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0);
18196
18197 vkEndCommandBuffer(secondary_command_buffer);
18198
18199 begin_info.pInheritanceInfo = nullptr;
18200 vkBeginCommandBuffer(command_buffer, &begin_info);
18201
18202 vkCmdExecuteCommands(command_buffer, 1, &secondary_command_buffer);
18203 vkCmdCopyQueryPoolResults(command_buffer, query_pool, 0, 1, buffer, 0, 0, 0);
18204
18205 vkEndCommandBuffer(command_buffer);
18206 }
18207 {
18208 VkSubmitInfo submit_info{};
18209 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18210 submit_info.commandBufferCount = 1;
18211 submit_info.pCommandBuffers = &command_buffer;
18212 submit_info.signalSemaphoreCount = 0;
18213 submit_info.pSignalSemaphores = nullptr;
18214 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
18215 }
18216
18217 vkQueueWaitIdle(queue);
18218
18219 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
18220 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
18221 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &secondary_command_buffer);
18222 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18223 vkDestroyBuffer(m_device->device(), buffer, NULL);
18224 vkFreeMemory(m_device->device(), mem, NULL);
18225
18226 m_errorMonitor->VerifyNotFound();
18227}
18228
18229// This is a positive test. No errors should be generated.
18230TEST_F(VkPositiveLayerTest, QueryAndCopyMultipleCommandBuffers) {
18231 TEST_DESCRIPTION("Issue a query and copy from it on a second command buffer.");
18232
18233 ASSERT_NO_FATAL_FAILURE(InitState());
18234 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
18235 return;
18236
18237 m_errorMonitor->ExpectSuccess();
18238
18239 VkQueryPool query_pool;
18240 VkQueryPoolCreateInfo query_pool_create_info{};
18241 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
18242 query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP;
18243 query_pool_create_info.queryCount = 1;
18244 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
18245
18246 VkCommandPool command_pool;
18247 VkCommandPoolCreateInfo pool_create_info{};
18248 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18249 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18250 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18251 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18252
18253 VkCommandBuffer command_buffer[2];
18254 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18255 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18256 command_buffer_allocate_info.commandPool = command_pool;
18257 command_buffer_allocate_info.commandBufferCount = 2;
18258 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18259 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18260
18261 VkQueue queue = VK_NULL_HANDLE;
18262 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
18263
18264 uint32_t qfi = 0;
18265 VkBufferCreateInfo buff_create_info = {};
18266 buff_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
18267 buff_create_info.size = 1024;
18268 buff_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
18269 buff_create_info.queueFamilyIndexCount = 1;
18270 buff_create_info.pQueueFamilyIndices = &qfi;
18271
18272 VkResult err;
18273 VkBuffer buffer;
18274 err = vkCreateBuffer(m_device->device(), &buff_create_info, NULL, &buffer);
18275 ASSERT_VK_SUCCESS(err);
18276 VkMemoryAllocateInfo mem_alloc = {};
18277 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18278 mem_alloc.pNext = NULL;
18279 mem_alloc.allocationSize = 1024;
18280 mem_alloc.memoryTypeIndex = 0;
18281
18282 VkMemoryRequirements memReqs;
18283 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
18284 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
18285 if (!pass) {
18286 vkDestroyBuffer(m_device->device(), buffer, NULL);
18287 return;
18288 }
18289
18290 VkDeviceMemory mem;
18291 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
18292 ASSERT_VK_SUCCESS(err);
18293 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
18294 ASSERT_VK_SUCCESS(err);
18295
18296 {
18297 VkCommandBufferBeginInfo begin_info{};
18298 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18299 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18300
18301 vkCmdResetQueryPool(command_buffer[0], query_pool, 0, 1);
18302 vkCmdWriteTimestamp(command_buffer[0], VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0);
18303
18304 vkEndCommandBuffer(command_buffer[0]);
18305
18306 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18307
18308 vkCmdCopyQueryPoolResults(command_buffer[1], query_pool, 0, 1, buffer, 0, 0, 0);
18309
18310 vkEndCommandBuffer(command_buffer[1]);
18311 }
18312 {
18313 VkSubmitInfo submit_info{};
18314 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18315 submit_info.commandBufferCount = 2;
18316 submit_info.pCommandBuffers = command_buffer;
18317 submit_info.signalSemaphoreCount = 0;
18318 submit_info.pSignalSemaphores = nullptr;
18319 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
18320 }
18321
18322 vkQueueWaitIdle(queue);
18323
18324 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
18325 vkFreeCommandBuffers(m_device->device(), command_pool, 2, command_buffer);
18326 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18327 vkDestroyBuffer(m_device->device(), buffer, NULL);
18328 vkFreeMemory(m_device->device(), mem, NULL);
18329
18330 m_errorMonitor->VerifyNotFound();
18331}
18332
Tony Barbourc46924f2016-11-04 11:49:52 -060018333TEST_F(VkLayerTest, ResetEventThenSet) {
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018334 TEST_DESCRIPTION("Reset an event then set it after the reset has been submitted.");
18335
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018336 ASSERT_NO_FATAL_FAILURE(InitState());
18337 VkEvent event;
18338 VkEventCreateInfo event_create_info{};
18339 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
18340 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
18341
18342 VkCommandPool command_pool;
18343 VkCommandPoolCreateInfo pool_create_info{};
18344 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18345 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18346 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18347 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18348
18349 VkCommandBuffer command_buffer;
18350 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18351 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18352 command_buffer_allocate_info.commandPool = command_pool;
18353 command_buffer_allocate_info.commandBufferCount = 1;
18354 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18355 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
18356
18357 VkQueue queue = VK_NULL_HANDLE;
18358 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
18359
18360 {
18361 VkCommandBufferBeginInfo begin_info{};
18362 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18363 vkBeginCommandBuffer(command_buffer, &begin_info);
18364
18365 vkCmdResetEvent(command_buffer, event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018366 vkEndCommandBuffer(command_buffer);
18367 }
18368 {
18369 VkSubmitInfo submit_info{};
18370 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18371 submit_info.commandBufferCount = 1;
18372 submit_info.pCommandBuffers = &command_buffer;
18373 submit_info.signalSemaphoreCount = 0;
18374 submit_info.pSignalSemaphores = nullptr;
18375 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
18376 }
18377 {
18378 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is already in use by a "
18379 "command buffer.");
18380 vkSetEvent(m_device->device(), event);
18381 m_errorMonitor->VerifyFound();
18382 }
18383
18384 vkQueueWaitIdle(queue);
18385
18386 vkDestroyEvent(m_device->device(), event, nullptr);
18387 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
18388 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18389}
18390
18391// This is a positive test. No errors should be generated.
18392TEST_F(VkPositiveLayerTest, TwoFencesThreeFrames) {
18393 TEST_DESCRIPTION("Two command buffers with two separate fences are each "
18394 "run through a Submit & WaitForFences cycle 3 times. This "
18395 "previously revealed a bug so running this positive test "
18396 "to prevent a regression.");
18397 m_errorMonitor->ExpectSuccess();
18398
18399 ASSERT_NO_FATAL_FAILURE(InitState());
18400 VkQueue queue = VK_NULL_HANDLE;
18401 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
18402
18403 static const uint32_t NUM_OBJECTS = 2;
18404 static const uint32_t NUM_FRAMES = 3;
18405 VkCommandBuffer cmd_buffers[NUM_OBJECTS] = {};
18406 VkFence fences[NUM_OBJECTS] = {};
18407
18408 VkCommandPool cmd_pool;
18409 VkCommandPoolCreateInfo cmd_pool_ci = {};
18410 cmd_pool_ci.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18411 cmd_pool_ci.queueFamilyIndex = m_device->graphics_queue_node_index_;
18412 cmd_pool_ci.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18413 VkResult err = vkCreateCommandPool(m_device->device(), &cmd_pool_ci, nullptr, &cmd_pool);
18414 ASSERT_VK_SUCCESS(err);
18415
18416 VkCommandBufferAllocateInfo cmd_buf_info = {};
18417 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18418 cmd_buf_info.commandPool = cmd_pool;
18419 cmd_buf_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18420 cmd_buf_info.commandBufferCount = 1;
18421
18422 VkFenceCreateInfo fence_ci = {};
18423 fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18424 fence_ci.pNext = nullptr;
18425 fence_ci.flags = 0;
18426
18427 for (uint32_t i = 0; i < NUM_OBJECTS; ++i) {
18428 err = vkAllocateCommandBuffers(m_device->device(), &cmd_buf_info, &cmd_buffers[i]);
18429 ASSERT_VK_SUCCESS(err);
18430 err = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fences[i]);
18431 ASSERT_VK_SUCCESS(err);
18432 }
18433
18434 for (uint32_t frame = 0; frame < NUM_FRAMES; ++frame) {
18435 for (uint32_t obj = 0; obj < NUM_OBJECTS; ++obj) {
18436 // Create empty cmd buffer
18437 VkCommandBufferBeginInfo cmdBufBeginDesc = {};
18438 cmdBufBeginDesc.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18439
18440 err = vkBeginCommandBuffer(cmd_buffers[obj], &cmdBufBeginDesc);
18441 ASSERT_VK_SUCCESS(err);
18442 err = vkEndCommandBuffer(cmd_buffers[obj]);
18443 ASSERT_VK_SUCCESS(err);
18444
18445 VkSubmitInfo submit_info = {};
18446 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18447 submit_info.commandBufferCount = 1;
18448 submit_info.pCommandBuffers = &cmd_buffers[obj];
18449 // Submit cmd buffer and wait for fence
18450 err = vkQueueSubmit(queue, 1, &submit_info, fences[obj]);
18451 ASSERT_VK_SUCCESS(err);
18452 err = vkWaitForFences(m_device->device(), 1, &fences[obj], VK_TRUE, UINT64_MAX);
18453 ASSERT_VK_SUCCESS(err);
18454 err = vkResetFences(m_device->device(), 1, &fences[obj]);
18455 ASSERT_VK_SUCCESS(err);
18456 }
18457 }
18458 m_errorMonitor->VerifyNotFound();
18459 vkDestroyCommandPool(m_device->device(), cmd_pool, NULL);
18460 for (uint32_t i = 0; i < NUM_OBJECTS; ++i) {
18461 vkDestroyFence(m_device->device(), fences[i], nullptr);
18462 }
18463}
18464// This is a positive test. No errors should be generated.
18465TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWI) {
18466
18467 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
18468 "submitted on separate queues followed by a QueueWaitIdle.");
18469
18470 ASSERT_NO_FATAL_FAILURE(InitState());
18471 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
18472 return;
18473
18474 m_errorMonitor->ExpectSuccess();
18475
18476 VkSemaphore semaphore;
18477 VkSemaphoreCreateInfo semaphore_create_info{};
18478 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
18479 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
18480
18481 VkCommandPool command_pool;
18482 VkCommandPoolCreateInfo pool_create_info{};
18483 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18484 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18485 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18486 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18487
18488 VkCommandBuffer command_buffer[2];
18489 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18490 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18491 command_buffer_allocate_info.commandPool = command_pool;
18492 command_buffer_allocate_info.commandBufferCount = 2;
18493 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18494 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18495
18496 VkQueue queue = VK_NULL_HANDLE;
18497 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
18498
18499 {
18500 VkCommandBufferBeginInfo begin_info{};
18501 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18502 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18503
18504 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
18505 nullptr, 0, nullptr, 0, nullptr);
18506
18507 VkViewport viewport{};
18508 viewport.maxDepth = 1.0f;
18509 viewport.minDepth = 0.0f;
18510 viewport.width = 512;
18511 viewport.height = 512;
18512 viewport.x = 0;
18513 viewport.y = 0;
18514 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
18515 vkEndCommandBuffer(command_buffer[0]);
18516 }
18517 {
18518 VkCommandBufferBeginInfo begin_info{};
18519 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18520 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18521
18522 VkViewport viewport{};
18523 viewport.maxDepth = 1.0f;
18524 viewport.minDepth = 0.0f;
18525 viewport.width = 512;
18526 viewport.height = 512;
18527 viewport.x = 0;
18528 viewport.y = 0;
18529 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
18530 vkEndCommandBuffer(command_buffer[1]);
18531 }
18532 {
18533 VkSubmitInfo submit_info{};
18534 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18535 submit_info.commandBufferCount = 1;
18536 submit_info.pCommandBuffers = &command_buffer[0];
18537 submit_info.signalSemaphoreCount = 1;
18538 submit_info.pSignalSemaphores = &semaphore;
18539 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
18540 }
18541 {
18542 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
18543 VkSubmitInfo submit_info{};
18544 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18545 submit_info.commandBufferCount = 1;
18546 submit_info.pCommandBuffers = &command_buffer[1];
18547 submit_info.waitSemaphoreCount = 1;
18548 submit_info.pWaitSemaphores = &semaphore;
18549 submit_info.pWaitDstStageMask = flags;
18550 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
18551 }
18552
18553 vkQueueWaitIdle(m_device->m_queue);
18554
18555 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
18556 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
18557 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18558
18559 m_errorMonitor->VerifyNotFound();
18560}
18561
18562// This is a positive test. No errors should be generated.
18563TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWIFence) {
18564
18565 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
18566 "submitted on separate queues, the second having a fence"
18567 "followed by a QueueWaitIdle.");
18568
18569 ASSERT_NO_FATAL_FAILURE(InitState());
18570 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
18571 return;
18572
18573 m_errorMonitor->ExpectSuccess();
18574
18575 VkFence fence;
18576 VkFenceCreateInfo fence_create_info{};
18577 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18578 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
18579
18580 VkSemaphore semaphore;
18581 VkSemaphoreCreateInfo semaphore_create_info{};
18582 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
18583 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
18584
18585 VkCommandPool command_pool;
18586 VkCommandPoolCreateInfo pool_create_info{};
18587 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18588 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18589 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18590 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18591
18592 VkCommandBuffer command_buffer[2];
18593 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18594 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18595 command_buffer_allocate_info.commandPool = command_pool;
18596 command_buffer_allocate_info.commandBufferCount = 2;
18597 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18598 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18599
18600 VkQueue queue = VK_NULL_HANDLE;
18601 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
18602
18603 {
18604 VkCommandBufferBeginInfo begin_info{};
18605 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18606 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18607
18608 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
18609 nullptr, 0, nullptr, 0, nullptr);
18610
18611 VkViewport viewport{};
18612 viewport.maxDepth = 1.0f;
18613 viewport.minDepth = 0.0f;
18614 viewport.width = 512;
18615 viewport.height = 512;
18616 viewport.x = 0;
18617 viewport.y = 0;
18618 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
18619 vkEndCommandBuffer(command_buffer[0]);
18620 }
18621 {
18622 VkCommandBufferBeginInfo begin_info{};
18623 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18624 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18625
18626 VkViewport viewport{};
18627 viewport.maxDepth = 1.0f;
18628 viewport.minDepth = 0.0f;
18629 viewport.width = 512;
18630 viewport.height = 512;
18631 viewport.x = 0;
18632 viewport.y = 0;
18633 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
18634 vkEndCommandBuffer(command_buffer[1]);
18635 }
18636 {
18637 VkSubmitInfo submit_info{};
18638 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18639 submit_info.commandBufferCount = 1;
18640 submit_info.pCommandBuffers = &command_buffer[0];
18641 submit_info.signalSemaphoreCount = 1;
18642 submit_info.pSignalSemaphores = &semaphore;
18643 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
18644 }
18645 {
18646 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
18647 VkSubmitInfo submit_info{};
18648 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18649 submit_info.commandBufferCount = 1;
18650 submit_info.pCommandBuffers = &command_buffer[1];
18651 submit_info.waitSemaphoreCount = 1;
18652 submit_info.pWaitSemaphores = &semaphore;
18653 submit_info.pWaitDstStageMask = flags;
18654 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
18655 }
18656
18657 vkQueueWaitIdle(m_device->m_queue);
18658
18659 vkDestroyFence(m_device->device(), fence, nullptr);
18660 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
18661 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
18662 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18663
18664 m_errorMonitor->VerifyNotFound();
18665}
18666
18667// This is a positive test. No errors should be generated.
18668TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceTwoWFF) {
18669
18670 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
18671 "submitted on separate queues, the second having a fence"
18672 "followed by two consecutive WaitForFences calls on the same fence.");
18673
18674 ASSERT_NO_FATAL_FAILURE(InitState());
18675 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
18676 return;
18677
18678 m_errorMonitor->ExpectSuccess();
18679
18680 VkFence fence;
18681 VkFenceCreateInfo fence_create_info{};
18682 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18683 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
18684
18685 VkSemaphore semaphore;
18686 VkSemaphoreCreateInfo semaphore_create_info{};
18687 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
18688 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
18689
18690 VkCommandPool command_pool;
18691 VkCommandPoolCreateInfo pool_create_info{};
18692 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18693 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18694 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18695 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18696
18697 VkCommandBuffer command_buffer[2];
18698 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18699 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18700 command_buffer_allocate_info.commandPool = command_pool;
18701 command_buffer_allocate_info.commandBufferCount = 2;
18702 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18703 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18704
18705 VkQueue queue = VK_NULL_HANDLE;
18706 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
18707
18708 {
18709 VkCommandBufferBeginInfo begin_info{};
18710 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18711 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18712
18713 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
18714 nullptr, 0, nullptr, 0, nullptr);
18715
18716 VkViewport viewport{};
18717 viewport.maxDepth = 1.0f;
18718 viewport.minDepth = 0.0f;
18719 viewport.width = 512;
18720 viewport.height = 512;
18721 viewport.x = 0;
18722 viewport.y = 0;
18723 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
18724 vkEndCommandBuffer(command_buffer[0]);
18725 }
18726 {
18727 VkCommandBufferBeginInfo begin_info{};
18728 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18729 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18730
18731 VkViewport viewport{};
18732 viewport.maxDepth = 1.0f;
18733 viewport.minDepth = 0.0f;
18734 viewport.width = 512;
18735 viewport.height = 512;
18736 viewport.x = 0;
18737 viewport.y = 0;
18738 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
18739 vkEndCommandBuffer(command_buffer[1]);
18740 }
18741 {
18742 VkSubmitInfo submit_info{};
18743 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18744 submit_info.commandBufferCount = 1;
18745 submit_info.pCommandBuffers = &command_buffer[0];
18746 submit_info.signalSemaphoreCount = 1;
18747 submit_info.pSignalSemaphores = &semaphore;
18748 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
18749 }
18750 {
18751 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
18752 VkSubmitInfo submit_info{};
18753 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18754 submit_info.commandBufferCount = 1;
18755 submit_info.pCommandBuffers = &command_buffer[1];
18756 submit_info.waitSemaphoreCount = 1;
18757 submit_info.pWaitSemaphores = &semaphore;
18758 submit_info.pWaitDstStageMask = flags;
18759 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
18760 }
18761
18762 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
18763 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
18764
18765 vkDestroyFence(m_device->device(), fence, nullptr);
18766 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
18767 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
18768 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18769
18770 m_errorMonitor->VerifyNotFound();
18771}
18772
18773TEST_F(VkPositiveLayerTest, TwoQueuesEnsureCorrectRetirementWithWorkStolen) {
18774
18775 ASSERT_NO_FATAL_FAILURE(InitState());
18776 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) {
18777 printf("Test requires two queues, skipping\n");
18778 return;
18779 }
18780
18781 VkResult err;
18782
18783 m_errorMonitor->ExpectSuccess();
18784
18785 VkQueue q0 = m_device->m_queue;
18786 VkQueue q1 = nullptr;
18787 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &q1);
18788 ASSERT_NE(q1, nullptr);
18789
18790 // An (empty) command buffer. We must have work in the first submission --
18791 // the layer treats unfenced work differently from fenced work.
18792 VkCommandPoolCreateInfo cpci = { VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, nullptr, 0, 0 };
18793 VkCommandPool pool;
18794 err = vkCreateCommandPool(m_device->device(), &cpci, nullptr, &pool);
18795 ASSERT_VK_SUCCESS(err);
18796 VkCommandBufferAllocateInfo cbai = { VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, nullptr, pool,
18797 VK_COMMAND_BUFFER_LEVEL_PRIMARY, 1 };
18798 VkCommandBuffer cb;
18799 err = vkAllocateCommandBuffers(m_device->device(), &cbai, &cb);
18800 ASSERT_VK_SUCCESS(err);
18801 VkCommandBufferBeginInfo cbbi = { VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr, 0, nullptr };
18802 err = vkBeginCommandBuffer(cb, &cbbi);
18803 ASSERT_VK_SUCCESS(err);
18804 err = vkEndCommandBuffer(cb);
18805 ASSERT_VK_SUCCESS(err);
18806
18807 // A semaphore
18808 VkSemaphoreCreateInfo sci = { VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0 };
18809 VkSemaphore s;
18810 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s);
18811 ASSERT_VK_SUCCESS(err);
18812
18813 // First submission, to q0
18814 VkSubmitInfo s0 = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 1, &cb, 1, &s };
18815
18816 err = vkQueueSubmit(q0, 1, &s0, VK_NULL_HANDLE);
18817 ASSERT_VK_SUCCESS(err);
18818
18819 // Second submission, to q1, waiting on s
18820 VkFlags waitmask = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT; // doesn't really matter what this value is.
18821 VkSubmitInfo s1 = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 1, &s, &waitmask, 0, nullptr, 0, nullptr };
18822
18823 err = vkQueueSubmit(q1, 1, &s1, VK_NULL_HANDLE);
18824 ASSERT_VK_SUCCESS(err);
18825
18826 // Wait for q0 idle
18827 err = vkQueueWaitIdle(q0);
18828 ASSERT_VK_SUCCESS(err);
18829
18830 // Command buffer should have been completed (it was on q0); reset the pool.
18831 vkFreeCommandBuffers(m_device->device(), pool, 1, &cb);
18832
18833 m_errorMonitor->VerifyNotFound();
18834
18835 // Force device completely idle and clean up resources
18836 vkDeviceWaitIdle(m_device->device());
18837 vkDestroyCommandPool(m_device->device(), pool, nullptr);
18838 vkDestroySemaphore(m_device->device(), s, nullptr);
18839}
18840
18841// This is a positive test. No errors should be generated.
18842TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFence) {
18843
18844 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
18845 "submitted on separate queues, the second having a fence, "
18846 "followed by a WaitForFences call.");
18847
18848 ASSERT_NO_FATAL_FAILURE(InitState());
18849 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
18850 return;
18851
18852 m_errorMonitor->ExpectSuccess();
18853
18854 ASSERT_NO_FATAL_FAILURE(InitState());
18855 VkFence fence;
18856 VkFenceCreateInfo fence_create_info{};
18857 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18858 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
18859
18860 VkSemaphore semaphore;
18861 VkSemaphoreCreateInfo semaphore_create_info{};
18862 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
18863 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
18864
18865 VkCommandPool command_pool;
18866 VkCommandPoolCreateInfo pool_create_info{};
18867 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18868 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18869 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18870 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18871
18872 VkCommandBuffer command_buffer[2];
18873 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18874 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18875 command_buffer_allocate_info.commandPool = command_pool;
18876 command_buffer_allocate_info.commandBufferCount = 2;
18877 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18878 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18879
18880 VkQueue queue = VK_NULL_HANDLE;
18881 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
18882
18883 {
18884 VkCommandBufferBeginInfo begin_info{};
18885 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18886 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18887
18888 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
18889 nullptr, 0, nullptr, 0, nullptr);
18890
18891 VkViewport viewport{};
18892 viewport.maxDepth = 1.0f;
18893 viewport.minDepth = 0.0f;
18894 viewport.width = 512;
18895 viewport.height = 512;
18896 viewport.x = 0;
18897 viewport.y = 0;
18898 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
18899 vkEndCommandBuffer(command_buffer[0]);
18900 }
18901 {
18902 VkCommandBufferBeginInfo begin_info{};
18903 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18904 vkBeginCommandBuffer(command_buffer[1], &begin_info);
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[1], 0, 1, &viewport);
18914 vkEndCommandBuffer(command_buffer[1]);
18915 }
18916 {
18917 VkSubmitInfo submit_info{};
18918 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18919 submit_info.commandBufferCount = 1;
18920 submit_info.pCommandBuffers = &command_buffer[0];
18921 submit_info.signalSemaphoreCount = 1;
18922 submit_info.pSignalSemaphores = &semaphore;
18923 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
18924 }
18925 {
18926 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
18927 VkSubmitInfo submit_info{};
18928 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18929 submit_info.commandBufferCount = 1;
18930 submit_info.pCommandBuffers = &command_buffer[1];
18931 submit_info.waitSemaphoreCount = 1;
18932 submit_info.pWaitSemaphores = &semaphore;
18933 submit_info.pWaitDstStageMask = flags;
18934 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
18935 }
18936
18937 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
18938
18939 vkDestroyFence(m_device->device(), fence, nullptr);
18940 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
18941 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
18942 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18943
18944 m_errorMonitor->VerifyNotFound();
18945}
18946
18947// This is a positive test. No errors should be generated.
18948TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueWithSemaphoreAndOneFence) {
18949
18950 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
18951 "on the same queue, sharing a signal/wait semaphore, the "
18952 "second having a fence, "
18953 "followed by a WaitForFences call.");
18954
18955 m_errorMonitor->ExpectSuccess();
18956
18957 ASSERT_NO_FATAL_FAILURE(InitState());
18958 VkFence fence;
18959 VkFenceCreateInfo fence_create_info{};
18960 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18961 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
18962
18963 VkSemaphore semaphore;
18964 VkSemaphoreCreateInfo semaphore_create_info{};
18965 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
18966 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
18967
18968 VkCommandPool command_pool;
18969 VkCommandPoolCreateInfo pool_create_info{};
18970 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18971 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18972 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18973 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18974
18975 VkCommandBuffer command_buffer[2];
18976 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18977 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18978 command_buffer_allocate_info.commandPool = command_pool;
18979 command_buffer_allocate_info.commandBufferCount = 2;
18980 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18981 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18982
18983 {
18984 VkCommandBufferBeginInfo begin_info{};
18985 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18986 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18987
18988 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
18989 nullptr, 0, nullptr, 0, nullptr);
18990
18991 VkViewport viewport{};
18992 viewport.maxDepth = 1.0f;
18993 viewport.minDepth = 0.0f;
18994 viewport.width = 512;
18995 viewport.height = 512;
18996 viewport.x = 0;
18997 viewport.y = 0;
18998 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
18999 vkEndCommandBuffer(command_buffer[0]);
19000 }
19001 {
19002 VkCommandBufferBeginInfo begin_info{};
19003 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19004 vkBeginCommandBuffer(command_buffer[1], &begin_info);
19005
19006 VkViewport viewport{};
19007 viewport.maxDepth = 1.0f;
19008 viewport.minDepth = 0.0f;
19009 viewport.width = 512;
19010 viewport.height = 512;
19011 viewport.x = 0;
19012 viewport.y = 0;
19013 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
19014 vkEndCommandBuffer(command_buffer[1]);
19015 }
19016 {
19017 VkSubmitInfo submit_info{};
19018 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19019 submit_info.commandBufferCount = 1;
19020 submit_info.pCommandBuffers = &command_buffer[0];
19021 submit_info.signalSemaphoreCount = 1;
19022 submit_info.pSignalSemaphores = &semaphore;
19023 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
19024 }
19025 {
19026 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
19027 VkSubmitInfo submit_info{};
19028 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19029 submit_info.commandBufferCount = 1;
19030 submit_info.pCommandBuffers = &command_buffer[1];
19031 submit_info.waitSemaphoreCount = 1;
19032 submit_info.pWaitSemaphores = &semaphore;
19033 submit_info.pWaitDstStageMask = flags;
19034 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
19035 }
19036
19037 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
19038
19039 vkDestroyFence(m_device->device(), fence, nullptr);
19040 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
19041 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
19042 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
19043
19044 m_errorMonitor->VerifyNotFound();
19045}
19046
19047// This is a positive test. No errors should be generated.
19048TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueNullQueueSubmitWithFence) {
19049
19050 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
19051 "on the same queue, no fences, followed by a third QueueSubmit with NO "
19052 "SubmitInfos but with a fence, followed by a WaitForFences call.");
19053
19054 m_errorMonitor->ExpectSuccess();
19055
19056 ASSERT_NO_FATAL_FAILURE(InitState());
19057 VkFence fence;
19058 VkFenceCreateInfo fence_create_info{};
19059 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
19060 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
19061
19062 VkCommandPool command_pool;
19063 VkCommandPoolCreateInfo pool_create_info{};
19064 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
19065 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
19066 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
19067 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
19068
19069 VkCommandBuffer command_buffer[2];
19070 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
19071 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
19072 command_buffer_allocate_info.commandPool = command_pool;
19073 command_buffer_allocate_info.commandBufferCount = 2;
19074 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
19075 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
19076
19077 {
19078 VkCommandBufferBeginInfo begin_info{};
19079 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19080 vkBeginCommandBuffer(command_buffer[0], &begin_info);
19081
19082 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
19083 nullptr, 0, nullptr, 0, nullptr);
19084
19085 VkViewport viewport{};
19086 viewport.maxDepth = 1.0f;
19087 viewport.minDepth = 0.0f;
19088 viewport.width = 512;
19089 viewport.height = 512;
19090 viewport.x = 0;
19091 viewport.y = 0;
19092 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
19093 vkEndCommandBuffer(command_buffer[0]);
19094 }
19095 {
19096 VkCommandBufferBeginInfo begin_info{};
19097 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19098 vkBeginCommandBuffer(command_buffer[1], &begin_info);
19099
19100 VkViewport viewport{};
19101 viewport.maxDepth = 1.0f;
19102 viewport.minDepth = 0.0f;
19103 viewport.width = 512;
19104 viewport.height = 512;
19105 viewport.x = 0;
19106 viewport.y = 0;
19107 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
19108 vkEndCommandBuffer(command_buffer[1]);
19109 }
19110 {
19111 VkSubmitInfo submit_info{};
19112 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19113 submit_info.commandBufferCount = 1;
19114 submit_info.pCommandBuffers = &command_buffer[0];
19115 submit_info.signalSemaphoreCount = 0;
19116 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
19117 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
19118 }
19119 {
19120 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
19121 VkSubmitInfo submit_info{};
19122 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19123 submit_info.commandBufferCount = 1;
19124 submit_info.pCommandBuffers = &command_buffer[1];
19125 submit_info.waitSemaphoreCount = 0;
19126 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
19127 submit_info.pWaitDstStageMask = flags;
19128 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
19129 }
19130
19131 vkQueueSubmit(m_device->m_queue, 0, NULL, fence);
19132
19133 VkResult err = vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
19134 ASSERT_VK_SUCCESS(err);
19135
19136 vkDestroyFence(m_device->device(), fence, nullptr);
19137 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
19138 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
19139
19140 m_errorMonitor->VerifyNotFound();
19141}
19142
19143// This is a positive test. No errors should be generated.
19144TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueOneFence) {
19145
19146 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
19147 "on the same queue, the second having a fence, followed "
19148 "by a WaitForFences call.");
19149
19150 m_errorMonitor->ExpectSuccess();
19151
19152 ASSERT_NO_FATAL_FAILURE(InitState());
19153 VkFence fence;
19154 VkFenceCreateInfo fence_create_info{};
19155 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
19156 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
19157
19158 VkCommandPool command_pool;
19159 VkCommandPoolCreateInfo pool_create_info{};
19160 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
19161 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
19162 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
19163 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
19164
19165 VkCommandBuffer command_buffer[2];
19166 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
19167 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
19168 command_buffer_allocate_info.commandPool = command_pool;
19169 command_buffer_allocate_info.commandBufferCount = 2;
19170 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
19171 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
19172
19173 {
19174 VkCommandBufferBeginInfo begin_info{};
19175 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19176 vkBeginCommandBuffer(command_buffer[0], &begin_info);
19177
19178 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
19179 nullptr, 0, nullptr, 0, nullptr);
19180
19181 VkViewport viewport{};
19182 viewport.maxDepth = 1.0f;
19183 viewport.minDepth = 0.0f;
19184 viewport.width = 512;
19185 viewport.height = 512;
19186 viewport.x = 0;
19187 viewport.y = 0;
19188 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
19189 vkEndCommandBuffer(command_buffer[0]);
19190 }
19191 {
19192 VkCommandBufferBeginInfo begin_info{};
19193 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19194 vkBeginCommandBuffer(command_buffer[1], &begin_info);
19195
19196 VkViewport viewport{};
19197 viewport.maxDepth = 1.0f;
19198 viewport.minDepth = 0.0f;
19199 viewport.width = 512;
19200 viewport.height = 512;
19201 viewport.x = 0;
19202 viewport.y = 0;
19203 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
19204 vkEndCommandBuffer(command_buffer[1]);
19205 }
19206 {
19207 VkSubmitInfo submit_info{};
19208 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19209 submit_info.commandBufferCount = 1;
19210 submit_info.pCommandBuffers = &command_buffer[0];
19211 submit_info.signalSemaphoreCount = 0;
19212 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
19213 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
19214 }
19215 {
19216 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
19217 VkSubmitInfo submit_info{};
19218 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19219 submit_info.commandBufferCount = 1;
19220 submit_info.pCommandBuffers = &command_buffer[1];
19221 submit_info.waitSemaphoreCount = 0;
19222 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
19223 submit_info.pWaitDstStageMask = flags;
19224 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
19225 }
19226
19227 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
19228
19229 vkDestroyFence(m_device->device(), fence, nullptr);
19230 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
19231 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
19232
19233 m_errorMonitor->VerifyNotFound();
19234}
19235
19236// This is a positive test. No errors should be generated.
19237TEST_F(VkPositiveLayerTest, TwoSubmitInfosWithSemaphoreOneQueueSubmitsOneFence) {
19238
19239 TEST_DESCRIPTION("Two command buffers each in a separate SubmitInfo sent in a single "
19240 "QueueSubmit call followed by a WaitForFences call.");
19241 ASSERT_NO_FATAL_FAILURE(InitState());
19242
19243 m_errorMonitor->ExpectSuccess();
19244
19245 VkFence fence;
19246 VkFenceCreateInfo fence_create_info{};
19247 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
19248 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
19249
19250 VkSemaphore semaphore;
19251 VkSemaphoreCreateInfo semaphore_create_info{};
19252 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
19253 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
19254
19255 VkCommandPool command_pool;
19256 VkCommandPoolCreateInfo pool_create_info{};
19257 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
19258 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
19259 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
19260 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
19261
19262 VkCommandBuffer command_buffer[2];
19263 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
19264 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
19265 command_buffer_allocate_info.commandPool = command_pool;
19266 command_buffer_allocate_info.commandBufferCount = 2;
19267 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
19268 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
19269
19270 {
19271 VkCommandBufferBeginInfo begin_info{};
19272 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19273 vkBeginCommandBuffer(command_buffer[0], &begin_info);
19274
19275 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
19276 nullptr, 0, nullptr, 0, nullptr);
19277
19278 VkViewport viewport{};
19279 viewport.maxDepth = 1.0f;
19280 viewport.minDepth = 0.0f;
19281 viewport.width = 512;
19282 viewport.height = 512;
19283 viewport.x = 0;
19284 viewport.y = 0;
19285 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
19286 vkEndCommandBuffer(command_buffer[0]);
19287 }
19288 {
19289 VkCommandBufferBeginInfo begin_info{};
19290 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19291 vkBeginCommandBuffer(command_buffer[1], &begin_info);
19292
19293 VkViewport viewport{};
19294 viewport.maxDepth = 1.0f;
19295 viewport.minDepth = 0.0f;
19296 viewport.width = 512;
19297 viewport.height = 512;
19298 viewport.x = 0;
19299 viewport.y = 0;
19300 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
19301 vkEndCommandBuffer(command_buffer[1]);
19302 }
19303 {
19304 VkSubmitInfo submit_info[2];
19305 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
19306
19307 submit_info[0].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19308 submit_info[0].pNext = NULL;
19309 submit_info[0].commandBufferCount = 1;
19310 submit_info[0].pCommandBuffers = &command_buffer[0];
19311 submit_info[0].signalSemaphoreCount = 1;
19312 submit_info[0].pSignalSemaphores = &semaphore;
19313 submit_info[0].waitSemaphoreCount = 0;
19314 submit_info[0].pWaitSemaphores = NULL;
19315 submit_info[0].pWaitDstStageMask = 0;
19316
19317 submit_info[1].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19318 submit_info[1].pNext = NULL;
19319 submit_info[1].commandBufferCount = 1;
19320 submit_info[1].pCommandBuffers = &command_buffer[1];
19321 submit_info[1].waitSemaphoreCount = 1;
19322 submit_info[1].pWaitSemaphores = &semaphore;
19323 submit_info[1].pWaitDstStageMask = flags;
19324 submit_info[1].signalSemaphoreCount = 0;
19325 submit_info[1].pSignalSemaphores = NULL;
19326 vkQueueSubmit(m_device->m_queue, 2, &submit_info[0], fence);
19327 }
19328
19329 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
19330
19331 vkDestroyFence(m_device->device(), fence, nullptr);
19332 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
19333 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
19334 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
19335
19336 m_errorMonitor->VerifyNotFound();
19337}
19338
19339TEST_F(VkPositiveLayerTest, RenderPassSecondaryCommandBuffersMultipleTimes) {
19340 m_errorMonitor->ExpectSuccess();
19341
19342 ASSERT_NO_FATAL_FAILURE(InitState());
19343 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19344
19345 BeginCommandBuffer(); // Framework implicitly begins the renderpass.
19346 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle()); // End implicit.
19347
19348 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
19349 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
19350 m_errorMonitor->VerifyNotFound();
19351 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
19352 m_errorMonitor->VerifyNotFound();
19353 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
19354 m_errorMonitor->VerifyNotFound();
19355
19356 m_commandBuffer->EndCommandBuffer();
19357 m_errorMonitor->VerifyNotFound();
19358}
19359
19360TEST_F(VkPositiveLayerTest, ValidRenderPassAttachmentLayoutWithLoadOp) {
19361 TEST_DESCRIPTION("Positive test where we create a renderpass with an "
19362 "attachment that uses LOAD_OP_CLEAR, the first subpass "
19363 "has a valid layout, and a second subpass then uses a "
19364 "valid *READ_ONLY* layout.");
19365 m_errorMonitor->ExpectSuccess();
19366 ASSERT_NO_FATAL_FAILURE(InitState());
19367
19368 VkAttachmentReference attach[2] = {};
19369 attach[0].attachment = 0;
19370 attach[0].layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
19371 attach[1].attachment = 0;
19372 attach[1].layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
19373 VkSubpassDescription subpasses[2] = {};
19374 // First subpass clears DS attach on load
19375 subpasses[0].pDepthStencilAttachment = &attach[0];
19376 // 2nd subpass reads in DS as input attachment
19377 subpasses[1].inputAttachmentCount = 1;
19378 subpasses[1].pInputAttachments = &attach[1];
19379 VkAttachmentDescription attach_desc = {};
19380 attach_desc.format = VK_FORMAT_D24_UNORM_S8_UINT;
19381 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
19382 attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
19383 attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
19384 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
19385 attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
19386 attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
19387 attach_desc.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
19388 VkRenderPassCreateInfo rpci = {};
19389 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
19390 rpci.attachmentCount = 1;
19391 rpci.pAttachments = &attach_desc;
19392 rpci.subpassCount = 2;
19393 rpci.pSubpasses = subpasses;
19394
19395 // Now create RenderPass and verify no errors
19396 VkRenderPass rp;
19397 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
19398 m_errorMonitor->VerifyNotFound();
19399
19400 vkDestroyRenderPass(m_device->device(), rp, NULL);
19401}
19402
19403TEST_F(VkPositiveLayerTest, CreatePipelineAttribMatrixType) {
19404 TEST_DESCRIPTION("Test that pipeline validation accepts matrices passed "
19405 "as vertex attributes");
19406 m_errorMonitor->ExpectSuccess();
19407
19408 ASSERT_NO_FATAL_FAILURE(InitState());
19409 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19410
19411 VkVertexInputBindingDescription input_binding;
19412 memset(&input_binding, 0, sizeof(input_binding));
19413
19414 VkVertexInputAttributeDescription input_attribs[2];
19415 memset(input_attribs, 0, sizeof(input_attribs));
19416
19417 for (int i = 0; i < 2; i++) {
19418 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
19419 input_attribs[i].location = i;
19420 }
19421
19422 char const *vsSource = "#version 450\n"
19423 "\n"
19424 "layout(location=0) in mat2x4 x;\n"
19425 "out gl_PerVertex {\n"
19426 " vec4 gl_Position;\n"
19427 "};\n"
19428 "void main(){\n"
19429 " gl_Position = x[0] + x[1];\n"
19430 "}\n";
19431 char const *fsSource = "#version 450\n"
19432 "\n"
19433 "layout(location=0) out vec4 color;\n"
19434 "void main(){\n"
19435 " color = vec4(1);\n"
19436 "}\n";
19437
19438 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19439 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19440
19441 VkPipelineObj pipe(m_device);
19442 pipe.AddColorAttachment();
19443 pipe.AddShader(&vs);
19444 pipe.AddShader(&fs);
19445
19446 pipe.AddVertexInputBindings(&input_binding, 1);
19447 pipe.AddVertexInputAttribs(input_attribs, 2);
19448
19449 VkDescriptorSetObj descriptorSet(m_device);
19450 descriptorSet.AppendDummy();
19451 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19452
19453 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
19454
19455 /* expect success */
19456 m_errorMonitor->VerifyNotFound();
19457}
19458
19459TEST_F(VkPositiveLayerTest, CreatePipelineAttribArrayType) {
19460 m_errorMonitor->ExpectSuccess();
19461
19462 ASSERT_NO_FATAL_FAILURE(InitState());
19463 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19464
19465 VkVertexInputBindingDescription input_binding;
19466 memset(&input_binding, 0, sizeof(input_binding));
19467
19468 VkVertexInputAttributeDescription input_attribs[2];
19469 memset(input_attribs, 0, sizeof(input_attribs));
19470
19471 for (int i = 0; i < 2; i++) {
19472 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
19473 input_attribs[i].location = i;
19474 }
19475
19476 char const *vsSource = "#version 450\n"
19477 "\n"
19478 "layout(location=0) in vec4 x[2];\n"
19479 "out gl_PerVertex {\n"
19480 " vec4 gl_Position;\n"
19481 "};\n"
19482 "void main(){\n"
19483 " gl_Position = x[0] + x[1];\n"
19484 "}\n";
19485 char const *fsSource = "#version 450\n"
19486 "\n"
19487 "layout(location=0) out vec4 color;\n"
19488 "void main(){\n"
19489 " color = vec4(1);\n"
19490 "}\n";
19491
19492 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19493 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19494
19495 VkPipelineObj pipe(m_device);
19496 pipe.AddColorAttachment();
19497 pipe.AddShader(&vs);
19498 pipe.AddShader(&fs);
19499
19500 pipe.AddVertexInputBindings(&input_binding, 1);
19501 pipe.AddVertexInputAttribs(input_attribs, 2);
19502
19503 VkDescriptorSetObj descriptorSet(m_device);
19504 descriptorSet.AppendDummy();
19505 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19506
19507 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
19508
19509 m_errorMonitor->VerifyNotFound();
19510}
19511
19512TEST_F(VkPositiveLayerTest, CreatePipelineAttribComponents) {
19513 TEST_DESCRIPTION("Test that pipeline validation accepts consuming a vertex attribute "
19514 "through multiple vertex shader inputs, each consuming a different "
19515 "subset of the components.");
19516 m_errorMonitor->ExpectSuccess();
19517
19518 ASSERT_NO_FATAL_FAILURE(InitState());
19519 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19520
19521 VkVertexInputBindingDescription input_binding;
19522 memset(&input_binding, 0, sizeof(input_binding));
19523
19524 VkVertexInputAttributeDescription input_attribs[3];
19525 memset(input_attribs, 0, sizeof(input_attribs));
19526
19527 for (int i = 0; i < 3; i++) {
19528 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
19529 input_attribs[i].location = i;
19530 }
19531
19532 char const *vsSource = "#version 450\n"
19533 "\n"
19534 "layout(location=0) in vec4 x;\n"
19535 "layout(location=1) in vec3 y1;\n"
19536 "layout(location=1, component=3) in float y2;\n"
19537 "layout(location=2) in vec4 z;\n"
19538 "out gl_PerVertex {\n"
19539 " vec4 gl_Position;\n"
19540 "};\n"
19541 "void main(){\n"
19542 " gl_Position = x + vec4(y1, y2) + z;\n"
19543 "}\n";
19544 char const *fsSource = "#version 450\n"
19545 "\n"
19546 "layout(location=0) out vec4 color;\n"
19547 "void main(){\n"
19548 " color = vec4(1);\n"
19549 "}\n";
19550
19551 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19552 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19553
19554 VkPipelineObj pipe(m_device);
19555 pipe.AddColorAttachment();
19556 pipe.AddShader(&vs);
19557 pipe.AddShader(&fs);
19558
19559 pipe.AddVertexInputBindings(&input_binding, 1);
19560 pipe.AddVertexInputAttribs(input_attribs, 3);
19561
19562 VkDescriptorSetObj descriptorSet(m_device);
19563 descriptorSet.AppendDummy();
19564 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19565
19566 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
19567
19568 m_errorMonitor->VerifyNotFound();
19569}
19570
19571TEST_F(VkPositiveLayerTest, CreatePipelineSimplePositive) {
19572 m_errorMonitor->ExpectSuccess();
19573
19574 ASSERT_NO_FATAL_FAILURE(InitState());
19575 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19576
19577 char const *vsSource = "#version 450\n"
19578 "out gl_PerVertex {\n"
19579 " vec4 gl_Position;\n"
19580 "};\n"
19581 "void main(){\n"
19582 " gl_Position = vec4(0);\n"
19583 "}\n";
19584 char const *fsSource = "#version 450\n"
19585 "\n"
19586 "layout(location=0) out vec4 color;\n"
19587 "void main(){\n"
19588 " color = vec4(1);\n"
19589 "}\n";
19590
19591 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19592 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19593
19594 VkPipelineObj pipe(m_device);
19595 pipe.AddColorAttachment();
19596 pipe.AddShader(&vs);
19597 pipe.AddShader(&fs);
19598
19599 VkDescriptorSetObj descriptorSet(m_device);
19600 descriptorSet.AppendDummy();
19601 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19602
19603 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
19604
19605 m_errorMonitor->VerifyNotFound();
19606}
19607
19608TEST_F(VkPositiveLayerTest, CreatePipelineRelaxedTypeMatch) {
19609 TEST_DESCRIPTION("Test that pipeline validation accepts the relaxed type matching rules "
19610 "set out in 14.1.3: fundamental type must match, and producer side must "
19611 "have at least as many components");
19612 m_errorMonitor->ExpectSuccess();
19613
19614 // VK 1.0.8 Specification, 14.1.3 "Additionally,..." block
19615
19616 ASSERT_NO_FATAL_FAILURE(InitState());
19617 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19618
19619 char const *vsSource = "#version 450\n"
19620 "out gl_PerVertex {\n"
19621 " vec4 gl_Position;\n"
19622 "};\n"
19623 "layout(location=0) out vec3 x;\n"
19624 "layout(location=1) out ivec3 y;\n"
19625 "layout(location=2) out vec3 z;\n"
19626 "void main(){\n"
19627 " gl_Position = vec4(0);\n"
19628 " x = vec3(0); y = ivec3(0); z = vec3(0);\n"
19629 "}\n";
19630 char const *fsSource = "#version 450\n"
19631 "\n"
19632 "layout(location=0) out vec4 color;\n"
19633 "layout(location=0) in float x;\n"
19634 "layout(location=1) flat in int y;\n"
19635 "layout(location=2) in vec2 z;\n"
19636 "void main(){\n"
19637 " color = vec4(1 + x + y + z.x);\n"
19638 "}\n";
19639
19640 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19641 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19642
19643 VkPipelineObj pipe(m_device);
19644 pipe.AddColorAttachment();
19645 pipe.AddShader(&vs);
19646 pipe.AddShader(&fs);
19647
19648 VkDescriptorSetObj descriptorSet(m_device);
19649 descriptorSet.AppendDummy();
19650 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19651
19652 VkResult err = VK_SUCCESS;
19653 err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
19654 ASSERT_VK_SUCCESS(err);
19655
19656 m_errorMonitor->VerifyNotFound();
19657}
19658
19659TEST_F(VkPositiveLayerTest, CreatePipelineTessPerVertex) {
19660 TEST_DESCRIPTION("Test that pipeline validation accepts per-vertex variables "
19661 "passed between the TCS and TES stages");
19662 m_errorMonitor->ExpectSuccess();
19663
19664 ASSERT_NO_FATAL_FAILURE(InitState());
19665 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19666
19667 if (!m_device->phy().features().tessellationShader) {
19668 printf("Device does not support tessellation shaders; skipped.\n");
19669 return;
19670 }
19671
19672 char const *vsSource = "#version 450\n"
19673 "void main(){}\n";
19674 char const *tcsSource = "#version 450\n"
19675 "layout(location=0) out int x[];\n"
19676 "layout(vertices=3) out;\n"
19677 "void main(){\n"
19678 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
19679 " gl_TessLevelInner[0] = 1;\n"
19680 " x[gl_InvocationID] = gl_InvocationID;\n"
19681 "}\n";
19682 char const *tesSource = "#version 450\n"
19683 "layout(triangles, equal_spacing, cw) in;\n"
19684 "layout(location=0) in int x[];\n"
19685 "out gl_PerVertex { vec4 gl_Position; };\n"
19686 "void main(){\n"
19687 " gl_Position.xyz = gl_TessCoord;\n"
19688 " gl_Position.w = x[0] + x[1] + x[2];\n"
19689 "}\n";
19690 char const *fsSource = "#version 450\n"
19691 "layout(location=0) out vec4 color;\n"
19692 "void main(){\n"
19693 " color = vec4(1);\n"
19694 "}\n";
19695
19696 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19697 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
19698 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
19699 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19700
19701 VkPipelineInputAssemblyStateCreateInfo iasci{ VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, nullptr, 0,
19702 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, VK_FALSE };
19703
19704 VkPipelineTessellationStateCreateInfo tsci{ VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, nullptr, 0, 3 };
19705
19706 VkPipelineObj pipe(m_device);
19707 pipe.SetInputAssembly(&iasci);
19708 pipe.SetTessellation(&tsci);
19709 pipe.AddColorAttachment();
19710 pipe.AddShader(&vs);
19711 pipe.AddShader(&tcs);
19712 pipe.AddShader(&tes);
19713 pipe.AddShader(&fs);
19714
19715 VkDescriptorSetObj descriptorSet(m_device);
19716 descriptorSet.AppendDummy();
19717 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19718
19719 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
19720
19721 m_errorMonitor->VerifyNotFound();
19722}
19723
19724TEST_F(VkPositiveLayerTest, CreatePipelineGeometryInputBlockPositive) {
19725 TEST_DESCRIPTION("Test that pipeline validation accepts a user-defined "
19726 "interface block passed into the geometry shader. This "
19727 "is interesting because the 'extra' array level is not "
19728 "present on the member type, but on the block instance.");
19729 m_errorMonitor->ExpectSuccess();
19730
19731 ASSERT_NO_FATAL_FAILURE(InitState());
19732 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19733
19734 if (!m_device->phy().features().geometryShader) {
19735 printf("Device does not support geometry shaders; skipped.\n");
19736 return;
19737 }
19738
19739 char const *vsSource = "#version 450\n"
19740 "layout(location=0) out VertexData { vec4 x; } vs_out;\n"
19741 "void main(){\n"
19742 " vs_out.x = vec4(1);\n"
19743 "}\n";
19744 char const *gsSource = "#version 450\n"
19745 "layout(triangles) in;\n"
19746 "layout(triangle_strip, max_vertices=3) out;\n"
19747 "layout(location=0) in VertexData { vec4 x; } gs_in[];\n"
19748 "out gl_PerVertex { vec4 gl_Position; };\n"
19749 "void main() {\n"
19750 " gl_Position = gs_in[0].x;\n"
19751 " EmitVertex();\n"
19752 "}\n";
19753 char const *fsSource = "#version 450\n"
19754 "layout(location=0) out vec4 color;\n"
19755 "void main(){\n"
19756 " color = vec4(1);\n"
19757 "}\n";
19758
19759 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19760 VkShaderObj gs(m_device, gsSource, VK_SHADER_STAGE_GEOMETRY_BIT, this);
19761 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19762
19763 VkPipelineObj pipe(m_device);
19764 pipe.AddColorAttachment();
19765 pipe.AddShader(&vs);
19766 pipe.AddShader(&gs);
19767 pipe.AddShader(&fs);
19768
19769 VkDescriptorSetObj descriptorSet(m_device);
19770 descriptorSet.AppendDummy();
19771 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19772
19773 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
19774
19775 m_errorMonitor->VerifyNotFound();
19776}
19777
19778TEST_F(VkPositiveLayerTest, CreatePipeline64BitAttributesPositive) {
19779 TEST_DESCRIPTION("Test that pipeline validation accepts basic use of 64bit vertex "
19780 "attributes. This is interesting because they consume multiple "
19781 "locations.");
19782 m_errorMonitor->ExpectSuccess();
19783
19784 ASSERT_NO_FATAL_FAILURE(InitState());
19785 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19786
19787 if (!m_device->phy().features().shaderFloat64) {
19788 printf("Device does not support 64bit vertex attributes; skipped.\n");
19789 return;
19790 }
19791
19792 VkVertexInputBindingDescription input_bindings[1];
19793 memset(input_bindings, 0, sizeof(input_bindings));
19794
19795 VkVertexInputAttributeDescription input_attribs[4];
19796 memset(input_attribs, 0, sizeof(input_attribs));
19797 input_attribs[0].location = 0;
19798 input_attribs[0].offset = 0;
19799 input_attribs[0].format = VK_FORMAT_R64G64B64A64_SFLOAT;
19800 input_attribs[1].location = 2;
19801 input_attribs[1].offset = 32;
19802 input_attribs[1].format = VK_FORMAT_R64G64B64A64_SFLOAT;
19803 input_attribs[2].location = 4;
19804 input_attribs[2].offset = 64;
19805 input_attribs[2].format = VK_FORMAT_R64G64B64A64_SFLOAT;
19806 input_attribs[3].location = 6;
19807 input_attribs[3].offset = 96;
19808 input_attribs[3].format = VK_FORMAT_R64G64B64A64_SFLOAT;
19809
19810 char const *vsSource = "#version 450\n"
19811 "\n"
19812 "layout(location=0) in dmat4 x;\n"
19813 "out gl_PerVertex {\n"
19814 " vec4 gl_Position;\n"
19815 "};\n"
19816 "void main(){\n"
19817 " gl_Position = vec4(x[0][0]);\n"
19818 "}\n";
19819 char const *fsSource = "#version 450\n"
19820 "\n"
19821 "layout(location=0) out vec4 color;\n"
19822 "void main(){\n"
19823 " color = vec4(1);\n"
19824 "}\n";
19825
19826 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19827 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19828
19829 VkPipelineObj pipe(m_device);
19830 pipe.AddColorAttachment();
19831 pipe.AddShader(&vs);
19832 pipe.AddShader(&fs);
19833
19834 pipe.AddVertexInputBindings(input_bindings, 1);
19835 pipe.AddVertexInputAttribs(input_attribs, 4);
19836
19837 VkDescriptorSetObj descriptorSet(m_device);
19838 descriptorSet.AppendDummy();
19839 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19840
19841 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
19842
19843 m_errorMonitor->VerifyNotFound();
19844}
19845
19846TEST_F(VkPositiveLayerTest, CreatePipelineInputAttachmentPositive) {
19847 TEST_DESCRIPTION("Positive test for a correctly matched input attachment");
19848 m_errorMonitor->ExpectSuccess();
19849
19850 ASSERT_NO_FATAL_FAILURE(InitState());
19851
19852 char const *vsSource = "#version 450\n"
19853 "\n"
19854 "out gl_PerVertex {\n"
19855 " vec4 gl_Position;\n"
19856 "};\n"
19857 "void main(){\n"
19858 " gl_Position = vec4(1);\n"
19859 "}\n";
19860 char const *fsSource = "#version 450\n"
19861 "\n"
19862 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
19863 "layout(location=0) out vec4 color;\n"
19864 "void main() {\n"
19865 " color = subpassLoad(x);\n"
19866 "}\n";
19867
19868 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19869 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19870
19871 VkPipelineObj pipe(m_device);
19872 pipe.AddShader(&vs);
19873 pipe.AddShader(&fs);
19874 pipe.AddColorAttachment();
19875 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19876
19877 VkDescriptorSetLayoutBinding dslb = { 0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr };
19878 VkDescriptorSetLayoutCreateInfo dslci = { VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb };
19879 VkDescriptorSetLayout dsl;
19880 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
19881 ASSERT_VK_SUCCESS(err);
19882
19883 VkPipelineLayoutCreateInfo plci = { VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr };
19884 VkPipelineLayout pl;
19885 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
19886 ASSERT_VK_SUCCESS(err);
19887
19888 VkAttachmentDescription descs[2] = {
19889 { 0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
19890 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
19891 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL },
19892 { 0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
19893 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_GENERAL, VK_IMAGE_LAYOUT_GENERAL },
19894 };
19895 VkAttachmentReference color = {
19896 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
19897 };
19898 VkAttachmentReference input = {
19899 1, VK_IMAGE_LAYOUT_GENERAL,
19900 };
19901
19902 VkSubpassDescription sd = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 1, &input, 1, &color, nullptr, nullptr, 0, nullptr };
19903
19904 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, descs, 1, &sd, 0, nullptr };
19905 VkRenderPass rp;
19906 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
19907 ASSERT_VK_SUCCESS(err);
19908
19909 // should be OK. would go wrong here if it's going to...
19910 pipe.CreateVKPipeline(pl, rp);
19911
19912 m_errorMonitor->VerifyNotFound();
19913
19914 vkDestroyRenderPass(m_device->device(), rp, nullptr);
19915 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
19916 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
19917}
19918
19919TEST_F(VkPositiveLayerTest, CreateComputePipelineMissingDescriptorUnusedPositive) {
19920 TEST_DESCRIPTION("Test that pipeline validation accepts a compute pipeline which declares a "
19921 "descriptor-backed resource which is not provided, but the shader does not "
19922 "statically use it. This is interesting because it requires compute pipelines "
19923 "to have a proper descriptor use walk, which they didn't for some time.");
19924 m_errorMonitor->ExpectSuccess();
19925
19926 ASSERT_NO_FATAL_FAILURE(InitState());
19927
19928 char const *csSource = "#version 450\n"
19929 "\n"
19930 "layout(local_size_x=1) in;\n"
19931 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
19932 "void main(){\n"
19933 " // x is not used.\n"
19934 "}\n";
19935
19936 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
19937
19938 VkDescriptorSetObj descriptorSet(m_device);
19939 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19940
19941 VkComputePipelineCreateInfo cpci = { VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
19942 nullptr,
19943 0,
19944 { VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
19945 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr },
19946 descriptorSet.GetPipelineLayout(),
19947 VK_NULL_HANDLE,
19948 -1 };
19949
19950 VkPipeline pipe;
19951 VkResult err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
19952
19953 m_errorMonitor->VerifyNotFound();
19954
19955 if (err == VK_SUCCESS) {
19956 vkDestroyPipeline(m_device->device(), pipe, nullptr);
19957 }
19958}
19959
19960TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsSampler) {
19961 TEST_DESCRIPTION("Test that pipeline validation accepts a shader consuming only the "
19962 "sampler portion of a combined image + sampler");
19963 m_errorMonitor->ExpectSuccess();
19964
19965 ASSERT_NO_FATAL_FAILURE(InitState());
19966
19967 VkDescriptorSetLayoutBinding bindings[] = {
19968 { 0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
19969 { 1, VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
19970 { 2, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
19971 };
19972 VkDescriptorSetLayoutCreateInfo dslci = { VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 3, bindings };
19973 VkDescriptorSetLayout dsl;
19974 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
19975 ASSERT_VK_SUCCESS(err);
19976
19977 VkPipelineLayoutCreateInfo plci = { VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr };
19978 VkPipelineLayout pl;
19979 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
19980 ASSERT_VK_SUCCESS(err);
19981
19982 char const *csSource = "#version 450\n"
19983 "\n"
19984 "layout(local_size_x=1) in;\n"
19985 "layout(set=0, binding=0) uniform sampler s;\n"
19986 "layout(set=0, binding=1) uniform texture2D t;\n"
19987 "layout(set=0, binding=2) buffer block { vec4 x; };\n"
19988 "void main() {\n"
19989 " x = texture(sampler2D(t, s), vec2(0));\n"
19990 "}\n";
19991 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
19992
19993 VkComputePipelineCreateInfo cpci = { VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
19994 nullptr,
19995 0,
19996 { VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
19997 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr },
19998 pl,
19999 VK_NULL_HANDLE,
20000 -1 };
20001
20002 VkPipeline pipe;
20003 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
20004
20005 m_errorMonitor->VerifyNotFound();
20006
20007 if (err == VK_SUCCESS) {
20008 vkDestroyPipeline(m_device->device(), pipe, nullptr);
20009 }
20010
20011 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
20012 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
20013}
20014
20015TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsImage) {
20016 TEST_DESCRIPTION("Test that pipeline validation accepts a shader consuming only the "
20017 "image portion of a combined image + sampler");
20018 m_errorMonitor->ExpectSuccess();
20019
20020 ASSERT_NO_FATAL_FAILURE(InitState());
20021
20022 VkDescriptorSetLayoutBinding bindings[] = {
20023 { 0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
20024 { 1, VK_DESCRIPTOR_TYPE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
20025 { 2, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
20026 };
20027 VkDescriptorSetLayoutCreateInfo dslci = { VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 3, bindings };
20028 VkDescriptorSetLayout dsl;
20029 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
20030 ASSERT_VK_SUCCESS(err);
20031
20032 VkPipelineLayoutCreateInfo plci = { VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr };
20033 VkPipelineLayout pl;
20034 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
20035 ASSERT_VK_SUCCESS(err);
20036
20037 char const *csSource = "#version 450\n"
20038 "\n"
20039 "layout(local_size_x=1) in;\n"
20040 "layout(set=0, binding=0) uniform texture2D t;\n"
20041 "layout(set=0, binding=1) uniform sampler s;\n"
20042 "layout(set=0, binding=2) buffer block { vec4 x; };\n"
20043 "void main() {\n"
20044 " x = texture(sampler2D(t, s), vec2(0));\n"
20045 "}\n";
20046 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
20047
20048 VkComputePipelineCreateInfo cpci = { VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
20049 nullptr,
20050 0,
20051 { VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
20052 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr },
20053 pl,
20054 VK_NULL_HANDLE,
20055 -1 };
20056
20057 VkPipeline pipe;
20058 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
20059
20060 m_errorMonitor->VerifyNotFound();
20061
20062 if (err == VK_SUCCESS) {
20063 vkDestroyPipeline(m_device->device(), pipe, nullptr);
20064 }
20065
20066 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
20067 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
20068}
20069
20070TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsBoth) {
20071 TEST_DESCRIPTION("Test that pipeline validation accepts a shader consuming "
20072 "both the sampler and the image of a combined image+sampler "
20073 "but via separate variables");
20074 m_errorMonitor->ExpectSuccess();
20075
20076 ASSERT_NO_FATAL_FAILURE(InitState());
20077
20078 VkDescriptorSetLayoutBinding bindings[] = {
20079 { 0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
20080 { 1, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
20081 };
20082 VkDescriptorSetLayoutCreateInfo dslci = { VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 2, bindings };
20083 VkDescriptorSetLayout dsl;
20084 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
20085 ASSERT_VK_SUCCESS(err);
20086
20087 VkPipelineLayoutCreateInfo plci = { VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr };
20088 VkPipelineLayout pl;
20089 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
20090 ASSERT_VK_SUCCESS(err);
20091
20092 char const *csSource = "#version 450\n"
20093 "\n"
20094 "layout(local_size_x=1) in;\n"
20095 "layout(set=0, binding=0) uniform texture2D t;\n"
20096 "layout(set=0, binding=0) uniform sampler s; // both binding 0!\n"
20097 "layout(set=0, binding=1) buffer block { vec4 x; };\n"
20098 "void main() {\n"
20099 " x = texture(sampler2D(t, s), vec2(0));\n"
20100 "}\n";
20101 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
20102
20103 VkComputePipelineCreateInfo cpci = { VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
20104 nullptr,
20105 0,
20106 { VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
20107 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr },
20108 pl,
20109 VK_NULL_HANDLE,
20110 -1 };
20111
20112 VkPipeline pipe;
20113 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
20114
20115 m_errorMonitor->VerifyNotFound();
20116
20117 if (err == VK_SUCCESS) {
20118 vkDestroyPipeline(m_device->device(), pipe, nullptr);
20119 }
20120
20121 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
20122 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
20123}
20124
20125TEST_F(VkPositiveLayerTest, ValidStructPNext) {
20126 TEST_DESCRIPTION("Verify that a valid pNext value is handled correctly");
20127
20128 ASSERT_NO_FATAL_FAILURE(InitState());
20129
20130 // Positive test to check parameter_validation and unique_objects support
20131 // for NV_dedicated_allocation
20132 uint32_t extension_count = 0;
20133 bool supports_nv_dedicated_allocation = false;
20134 VkResult err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, nullptr);
20135 ASSERT_VK_SUCCESS(err);
20136
20137 if (extension_count > 0) {
20138 std::vector<VkExtensionProperties> available_extensions(extension_count);
20139
20140 err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, &available_extensions[0]);
20141 ASSERT_VK_SUCCESS(err);
20142
20143 for (const auto &extension_props : available_extensions) {
20144 if (strcmp(extension_props.extensionName, VK_NV_DEDICATED_ALLOCATION_EXTENSION_NAME) == 0) {
20145 supports_nv_dedicated_allocation = true;
20146 }
20147 }
20148 }
20149
20150 if (supports_nv_dedicated_allocation) {
20151 m_errorMonitor->ExpectSuccess();
20152
20153 VkDedicatedAllocationBufferCreateInfoNV dedicated_buffer_create_info = {};
20154 dedicated_buffer_create_info.sType = VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_BUFFER_CREATE_INFO_NV;
20155 dedicated_buffer_create_info.pNext = nullptr;
20156 dedicated_buffer_create_info.dedicatedAllocation = VK_TRUE;
20157
20158 uint32_t queue_family_index = 0;
20159 VkBufferCreateInfo buffer_create_info = {};
20160 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
20161 buffer_create_info.pNext = &dedicated_buffer_create_info;
20162 buffer_create_info.size = 1024;
20163 buffer_create_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
20164 buffer_create_info.queueFamilyIndexCount = 1;
20165 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
20166
20167 VkBuffer buffer;
20168 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
20169 ASSERT_VK_SUCCESS(err);
20170
20171 VkMemoryRequirements memory_reqs;
20172 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
20173
20174 VkDedicatedAllocationMemoryAllocateInfoNV dedicated_memory_info = {};
20175 dedicated_memory_info.sType = VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_MEMORY_ALLOCATE_INFO_NV;
20176 dedicated_memory_info.pNext = nullptr;
20177 dedicated_memory_info.buffer = buffer;
20178 dedicated_memory_info.image = VK_NULL_HANDLE;
20179
20180 VkMemoryAllocateInfo memory_info = {};
20181 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
20182 memory_info.pNext = &dedicated_memory_info;
20183 memory_info.allocationSize = memory_reqs.size;
20184
20185 bool pass;
20186 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
20187 ASSERT_TRUE(pass);
20188
20189 VkDeviceMemory buffer_memory;
20190 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
20191 ASSERT_VK_SUCCESS(err);
20192
20193 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
20194 ASSERT_VK_SUCCESS(err);
20195
20196 vkDestroyBuffer(m_device->device(), buffer, NULL);
20197 vkFreeMemory(m_device->device(), buffer_memory, NULL);
20198
20199 m_errorMonitor->VerifyNotFound();
20200 }
20201}
20202
20203TEST_F(VkPositiveLayerTest, PSOPolygonModeValid) {
20204 VkResult err;
20205
20206 TEST_DESCRIPTION("Verify that using a solid polygon fill mode works correctly.");
20207
20208 ASSERT_NO_FATAL_FAILURE(InitState());
20209 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
20210
20211 std::vector<const char *> device_extension_names;
20212 auto features = m_device->phy().features();
20213 // Artificially disable support for non-solid fill modes
20214 features.fillModeNonSolid = false;
20215 // The sacrificial device object
20216 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
20217
20218 VkRenderpassObj render_pass(&test_device);
20219
20220 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
20221 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
20222 pipeline_layout_ci.setLayoutCount = 0;
20223 pipeline_layout_ci.pSetLayouts = NULL;
20224
20225 VkPipelineLayout pipeline_layout;
20226 err = vkCreatePipelineLayout(test_device.device(), &pipeline_layout_ci, NULL, &pipeline_layout);
20227 ASSERT_VK_SUCCESS(err);
20228
20229 VkPipelineRasterizationStateCreateInfo rs_ci = {};
20230 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
20231 rs_ci.pNext = nullptr;
20232 rs_ci.lineWidth = 1.0f;
20233 rs_ci.rasterizerDiscardEnable = true;
20234
20235 VkShaderObj vs(&test_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
20236 VkShaderObj fs(&test_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
20237
20238 // Set polygonMode=FILL. No error is expected
20239 m_errorMonitor->ExpectSuccess();
20240 {
20241 VkPipelineObj pipe(&test_device);
20242 pipe.AddShader(&vs);
20243 pipe.AddShader(&fs);
20244 pipe.AddColorAttachment();
20245 // Set polygonMode to a good value
20246 rs_ci.polygonMode = VK_POLYGON_MODE_FILL;
20247 pipe.SetRasterization(&rs_ci);
20248 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
20249 }
20250 m_errorMonitor->VerifyNotFound();
20251
20252 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, NULL);
20253}
20254
20255TEST_F(VkPositiveLayerTest, ValidPushConstants) {
20256 VkResult err;
20257 ASSERT_NO_FATAL_FAILURE(InitState());
20258 ASSERT_NO_FATAL_FAILURE(InitViewport());
20259 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
20260
20261 VkPipelineLayout pipeline_layout;
20262 VkPushConstantRange pc_range = {};
20263 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
20264 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
20265 pipeline_layout_ci.pushConstantRangeCount = 1;
20266 pipeline_layout_ci.pPushConstantRanges = &pc_range;
20267
20268 //
20269 // Check for invalid push constant ranges in pipeline layouts.
20270 //
20271 struct PipelineLayoutTestCase {
20272 VkPushConstantRange const range;
20273 char const *msg;
20274 };
20275
20276 // Check for overlapping ranges
20277 const uint32_t ranges_per_test = 5;
20278 struct OverlappingRangeTestCase {
20279 VkPushConstantRange const ranges[ranges_per_test];
20280 char const *msg;
20281 };
20282
20283 // Run some positive tests to make sure overlap checking in the layer is OK
20284 const std::array<OverlappingRangeTestCase, 2> overlapping_range_tests_pos = { { { { { VK_SHADER_STAGE_VERTEX_BIT, 0, 4 },
20285 { VK_SHADER_STAGE_VERTEX_BIT, 4, 4 },
20286 { VK_SHADER_STAGE_VERTEX_BIT, 8, 4 },
20287 { VK_SHADER_STAGE_VERTEX_BIT, 12, 4 },
20288 { VK_SHADER_STAGE_VERTEX_BIT, 16, 4 } },
20289 "" },
20290 { { { VK_SHADER_STAGE_VERTEX_BIT, 92, 24 },
20291 { VK_SHADER_STAGE_VERTEX_BIT, 80, 4 },
20292 { VK_SHADER_STAGE_VERTEX_BIT, 64, 8 },
20293 { VK_SHADER_STAGE_VERTEX_BIT, 4, 16 },
20294 { VK_SHADER_STAGE_VERTEX_BIT, 0, 4 } },
20295 "" } } };
20296 for (const auto &iter : overlapping_range_tests_pos) {
20297 pipeline_layout_ci.pPushConstantRanges = iter.ranges;
20298 m_errorMonitor->ExpectSuccess();
20299 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
20300 m_errorMonitor->VerifyNotFound();
20301 if (VK_SUCCESS == err) {
20302 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
20303 }
20304 }
20305
20306 //
20307 // CmdPushConstants tests
20308 //
20309 const uint8_t dummy_values[100] = {};
20310
20311 BeginCommandBuffer();
20312
20313 // positive overlapping range tests with cmd
20314 const std::array<PipelineLayoutTestCase, 4> cmd_overlap_tests_pos = { {
20315 { { VK_SHADER_STAGE_VERTEX_BIT, 0, 16 }, "" },
20316 { { VK_SHADER_STAGE_VERTEX_BIT, 0, 4 }, "" },
20317 { { VK_SHADER_STAGE_VERTEX_BIT, 20, 12 }, "" },
20318 { { VK_SHADER_STAGE_VERTEX_BIT, 56, 36 }, "" },
20319 } };
20320
20321 // Setup ranges: [0,16) [20,36) [36,44) [44,52) [56,80) [80,92)
20322 const VkPushConstantRange pc_range4[] = {
20323 { VK_SHADER_STAGE_VERTEX_BIT, 20, 16 },{ VK_SHADER_STAGE_VERTEX_BIT, 0, 16 },{ VK_SHADER_STAGE_VERTEX_BIT, 44, 8 },
20324 { VK_SHADER_STAGE_VERTEX_BIT, 80, 12 },{ VK_SHADER_STAGE_VERTEX_BIT, 36, 8 },{ VK_SHADER_STAGE_VERTEX_BIT, 56, 24 },
20325 };
20326
20327 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range4) / sizeof(VkPushConstantRange);
20328 pipeline_layout_ci.pPushConstantRanges = pc_range4;
20329 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
20330 ASSERT_VK_SUCCESS(err);
20331 for (const auto &iter : cmd_overlap_tests_pos) {
20332 m_errorMonitor->ExpectSuccess();
20333 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.range.stageFlags, iter.range.offset,
20334 iter.range.size, dummy_values);
20335 m_errorMonitor->VerifyNotFound();
20336 }
20337 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
20338
20339 EndCommandBuffer();
20340}
20341
20342
20343
20344
20345
20346
20347
20348#if 0 // A few devices have issues with this test so disabling for now
20349TEST_F(VkPositiveLayerTest, LongFenceChain)
20350{
20351 m_errorMonitor->ExpectSuccess();
20352
20353 ASSERT_NO_FATAL_FAILURE(InitState());
20354 VkResult err;
20355
20356 std::vector<VkFence> fences;
20357
20358 const int chainLength = 32768;
20359
20360 for (int i = 0; i < chainLength; i++) {
20361 VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
20362 VkFence fence;
20363 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
20364 ASSERT_VK_SUCCESS(err);
20365
20366 fences.push_back(fence);
20367
20368 VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr,
20369 0, nullptr, 0, nullptr };
20370 err = vkQueueSubmit(m_device->m_queue, 1, &si, fence);
20371 ASSERT_VK_SUCCESS(err);
20372
20373 }
20374
20375 // BOOM, stack overflow.
20376 vkWaitForFences(m_device->device(), 1, &fences.back(), VK_TRUE, UINT64_MAX);
20377
20378 for (auto fence : fences)
20379 vkDestroyFence(m_device->device(), fence, nullptr);
20380
20381 m_errorMonitor->VerifyNotFound();
20382}
20383#endif
20384
20385
Cody Northrop1242dfd2016-07-13 17:24:59 -060020386#if defined(ANDROID) && defined(VALIDATION_APK)
20387static bool initialized = false;
20388static bool active = false;
20389
20390// Convert Intents to argv
20391// Ported from Hologram sample, only difference is flexible key
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020392std::vector<std::string> get_args(android_app &app, const char *intent_extra_data_key) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060020393 std::vector<std::string> args;
20394 JavaVM &vm = *app.activity->vm;
20395 JNIEnv *p_env;
20396 if (vm.AttachCurrentThread(&p_env, nullptr) != JNI_OK)
20397 return args;
20398
20399 JNIEnv &env = *p_env;
20400 jobject activity = app.activity->clazz;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020401 jmethodID get_intent_method = env.GetMethodID(env.GetObjectClass(activity), "getIntent", "()Landroid/content/Intent;");
Cody Northrop1242dfd2016-07-13 17:24:59 -060020402 jobject intent = env.CallObjectMethod(activity, get_intent_method);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020403 jmethodID get_string_extra_method =
20404 env.GetMethodID(env.GetObjectClass(intent), "getStringExtra", "(Ljava/lang/String;)Ljava/lang/String;");
Cody Northrop1242dfd2016-07-13 17:24:59 -060020405 jvalue get_string_extra_args;
20406 get_string_extra_args.l = env.NewStringUTF(intent_extra_data_key);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020407 jstring extra_str = static_cast<jstring>(env.CallObjectMethodA(intent, get_string_extra_method, &get_string_extra_args));
Cody Northrop1242dfd2016-07-13 17:24:59 -060020408
20409 std::string args_str;
20410 if (extra_str) {
20411 const char *extra_utf = env.GetStringUTFChars(extra_str, nullptr);
20412 args_str = extra_utf;
20413 env.ReleaseStringUTFChars(extra_str, extra_utf);
20414 env.DeleteLocalRef(extra_str);
20415 }
20416
20417 env.DeleteLocalRef(get_string_extra_args.l);
20418 env.DeleteLocalRef(intent);
20419 vm.DetachCurrentThread();
20420
20421 // split args_str
20422 std::stringstream ss(args_str);
20423 std::string arg;
20424 while (std::getline(ss, arg, ' ')) {
20425 if (!arg.empty())
20426 args.push_back(arg);
20427 }
20428
20429 return args;
20430}
20431
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020432static int32_t processInput(struct android_app *app, AInputEvent *event) { return 0; }
Cody Northrop1242dfd2016-07-13 17:24:59 -060020433
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020434static void processCommand(struct android_app *app, int32_t cmd) {
20435 switch (cmd) {
20436 case APP_CMD_INIT_WINDOW: {
20437 if (app->window) {
20438 initialized = true;
Cody Northrop1242dfd2016-07-13 17:24:59 -060020439 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020440 break;
20441 }
20442 case APP_CMD_GAINED_FOCUS: {
20443 active = true;
20444 break;
20445 }
20446 case APP_CMD_LOST_FOCUS: {
20447 active = false;
20448 break;
20449 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060020450 }
20451}
20452
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020453void android_main(struct android_app *app) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060020454 app_dummy();
20455
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020456 const char *appTag = "VulkanLayerValidationTests";
Cody Northrop1242dfd2016-07-13 17:24:59 -060020457
20458 int vulkanSupport = InitVulkan();
20459 if (vulkanSupport == 0) {
20460 __android_log_print(ANDROID_LOG_INFO, appTag, "==== FAILED ==== No Vulkan support found");
20461 return;
20462 }
20463
20464 app->onAppCmd = processCommand;
20465 app->onInputEvent = processInput;
20466
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020467 while (1) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060020468 int events;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020469 struct android_poll_source *source;
20470 while (ALooper_pollAll(active ? 0 : -1, NULL, &events, (void **)&source) >= 0) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060020471 if (source) {
20472 source->process(app, source);
20473 }
20474
20475 if (app->destroyRequested != 0) {
20476 VkTestFramework::Finish();
20477 return;
20478 }
20479 }
20480
20481 if (initialized && active) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020482 // Use the following key to send arguments to gtest, i.e.
20483 // --es args "--gtest_filter=-VkLayerTest.foo"
20484 const char key[] = "args";
20485 std::vector<std::string> args = get_args(*app, key);
Cody Northrop1242dfd2016-07-13 17:24:59 -060020486
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020487 std::string filter = "";
20488 if (args.size() > 0) {
20489 __android_log_print(ANDROID_LOG_INFO, appTag, "Intent args = %s", args[0].c_str());
20490 filter += args[0];
20491 } else {
20492 __android_log_print(ANDROID_LOG_INFO, appTag, "No Intent args detected");
20493 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060020494
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020495 int argc = 2;
20496 char *argv[] = {(char *)"foo", (char *)filter.c_str()};
20497 __android_log_print(ANDROID_LOG_DEBUG, appTag, "filter = %s", argv[1]);
Cody Northrop1242dfd2016-07-13 17:24:59 -060020498
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020499 // Route output to files until we can override the gtest output
20500 freopen("/sdcard/Android/data/com.example.VulkanLayerValidationTests/files/out.txt", "w", stdout);
20501 freopen("/sdcard/Android/data/com.example.VulkanLayerValidationTests/files/err.txt", "w", stderr);
Cody Northrop1242dfd2016-07-13 17:24:59 -060020502
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020503 ::testing::InitGoogleTest(&argc, argv);
20504 VkTestFramework::InitArgs(&argc, argv);
20505 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
Cody Northrop1242dfd2016-07-13 17:24:59 -060020506
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020507 int result = RUN_ALL_TESTS();
Cody Northrop1242dfd2016-07-13 17:24:59 -060020508
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020509 if (result != 0) {
20510 __android_log_print(ANDROID_LOG_INFO, appTag, "==== Tests FAILED ====");
20511 } else {
20512 __android_log_print(ANDROID_LOG_INFO, appTag, "==== Tests PASSED ====");
20513 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060020514
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020515 VkTestFramework::Finish();
Cody Northrop1242dfd2016-07-13 17:24:59 -060020516
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020517 fclose(stdout);
20518 fclose(stderr);
Cody Northrop1242dfd2016-07-13 17:24:59 -060020519
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020520 ANativeActivity_finish(app->activity);
Cody Northrop1242dfd2016-07-13 17:24:59 -060020521
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020522 return;
Cody Northrop1242dfd2016-07-13 17:24:59 -060020523 }
20524 }
20525}
20526#endif
20527
Tony Barbour300a6082015-04-07 13:44:53 -060020528int main(int argc, char **argv) {
20529 int result;
20530
Cody Northrop8e54a402016-03-08 22:25:52 -070020531#ifdef ANDROID
20532 int vulkanSupport = InitVulkan();
20533 if (vulkanSupport == 0)
20534 return 1;
20535#endif
20536
Tony Barbour300a6082015-04-07 13:44:53 -060020537 ::testing::InitGoogleTest(&argc, argv);
Tony Barbour6918cd52015-04-09 12:58:51 -060020538 VkTestFramework::InitArgs(&argc, argv);
Tony Barbour300a6082015-04-07 13:44:53 -060020539
20540 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
20541
20542 result = RUN_ALL_TESTS();
20543
Tony Barbour6918cd52015-04-09 12:58:51 -060020544 VkTestFramework::Finish();
Tony Barbour300a6082015-04-07 13:44:53 -060020545 return result;
20546}