blob: 6e6da7a229e511d357702176e70d451372417e71 [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 // Request fb that exceeds max dimensions
3520 // reset attachment to color attachment
3521 fb_info.pAttachments = ivs;
3522 fb_info.width = m_device->props.limits.maxFramebufferWidth + 1;
3523 fb_info.height = m_device->props.limits.maxFramebufferHeight + 1;
3524 fb_info.layers = m_device->props.limits.maxFramebufferLayers + 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003525 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " Requested VkFramebufferCreateInfo "
3526 "dimensions exceed physical device "
3527 "limits. ");
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06003528 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3529
3530 m_errorMonitor->VerifyFound();
3531 if (err == VK_SUCCESS) {
3532 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3533 }
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06003534
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003535 vkDestroyRenderPass(m_device->device(), rp, NULL);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003536}
3537
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003538TEST_F(VkLayerTest, DynamicDepthBiasNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003539 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Depth Bias dynamic "
3540 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003541
Cody Northropc31a84f2016-08-22 10:41:47 -06003542 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003543 // Dynamic depth bias
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003544 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic depth bias state not set for this command buffer");
3545 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthBias);
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003546 m_errorMonitor->VerifyFound();
3547}
3548
3549TEST_F(VkLayerTest, DynamicLineWidthNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003550 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Line Width dynamic "
3551 "state is required but not correctly bound.");
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003552
Cody Northropc31a84f2016-08-22 10:41:47 -06003553 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003554 // Dynamic line width
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003555 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic line width state not set for this command buffer");
3556 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailLineWidth);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003557 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003558}
3559
3560TEST_F(VkLayerTest, DynamicViewportNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003561 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Viewport dynamic "
3562 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003563
Cody Northropc31a84f2016-08-22 10:41:47 -06003564 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003565 // Dynamic viewport state
Mike Weiblen95dd0f92016-10-19 12:28:27 -06003566 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 -06003567 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailViewport);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003568 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003569}
3570
3571TEST_F(VkLayerTest, DynamicScissorNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003572 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Scissor dynamic "
3573 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003574
Cody Northropc31a84f2016-08-22 10:41:47 -06003575 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003576 // Dynamic scissor state
Mike Weiblen95dd0f92016-10-19 12:28:27 -06003577 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 -06003578 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailScissor);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003579 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003580}
3581
Cortd713fe82016-07-27 09:51:27 -07003582TEST_F(VkLayerTest, DynamicBlendConstantsNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003583 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Blend Constants "
3584 "dynamic state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003585
3586 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis21c88352016-05-26 06:15:45 -06003587 // Dynamic blend constant state
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003588 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3589 "Dynamic blend constants state not set for this command buffer");
3590 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailBlend);
Tobin Ehlis21c88352016-05-26 06:15:45 -06003591 m_errorMonitor->VerifyFound();
3592}
3593
3594TEST_F(VkLayerTest, DynamicDepthBoundsNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003595 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Depth Bounds dynamic "
3596 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003597
3598 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis21c88352016-05-26 06:15:45 -06003599 if (!m_device->phy().features().depthBounds) {
3600 printf("Device does not support depthBounds test; skipped.\n");
3601 return;
3602 }
3603 // Dynamic depth bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003604 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3605 "Dynamic depth bounds state not set for this command buffer");
3606 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthBounds);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003607 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003608}
3609
3610TEST_F(VkLayerTest, DynamicStencilReadNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003611 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Stencil Read dynamic "
3612 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003613
3614 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003615 // Dynamic stencil read mask
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003616 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3617 "Dynamic stencil read mask state not set for this command buffer");
3618 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilReadMask);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003619 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003620}
3621
3622TEST_F(VkLayerTest, DynamicStencilWriteNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003623 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Stencil Write dynamic"
3624 " state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003625
3626 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003627 // Dynamic stencil write mask
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003628 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3629 "Dynamic stencil write mask state not set for this command buffer");
3630 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilWriteMask);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003631 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003632}
3633
3634TEST_F(VkLayerTest, DynamicStencilRefNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003635 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Stencil Ref dynamic "
3636 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003637
3638 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003639 // Dynamic stencil reference
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003640 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3641 "Dynamic stencil reference state not set for this command buffer");
3642 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilReference);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003643 m_errorMonitor->VerifyFound();
Tobin Ehlis963a4042015-09-29 08:18:34 -06003644}
3645
Tobin Ehlis379ba3b2016-07-19 11:22:29 -06003646TEST_F(VkLayerTest, IndexBufferNotBound) {
3647 TEST_DESCRIPTION("Run an indexed draw call without an index buffer bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003648
3649 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003650 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3651 "Index buffer object not bound to this command buffer when Indexed ");
3652 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailIndexBuffer);
Tobin Ehlis379ba3b2016-07-19 11:22:29 -06003653 m_errorMonitor->VerifyFound();
3654}
3655
Karl Schultz6addd812016-02-02 17:17:23 -07003656TEST_F(VkLayerTest, CommandBufferTwoSubmits) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003657 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3658 "was begun w/ VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set, but has "
3659 "been submitted");
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003660
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003661 ASSERT_NO_FATAL_FAILURE(InitState());
3662 ASSERT_NO_FATAL_FAILURE(InitViewport());
3663 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3664
Karl Schultz6addd812016-02-02 17:17:23 -07003665 // We luck out b/c by default the framework creates CB w/ the
3666 // VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003667 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003668 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003669 EndCommandBuffer();
3670
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003671 // Bypass framework since it does the waits automatically
3672 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06003673 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08003674 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3675 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003676 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06003677 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07003678 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003679 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003680 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08003681 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06003682 submit_info.pSignalSemaphores = NULL;
3683
Chris Forbes40028e22016-06-13 09:59:34 +12003684 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Karl Schultz6addd812016-02-02 17:17:23 -07003685 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski89cad1a2016-11-11 15:51:31 -07003686 vkQueueWaitIdle(m_device->m_queue);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003687
Karl Schultz6addd812016-02-02 17:17:23 -07003688 // Cause validation error by re-submitting cmd buffer that should only be
3689 // submitted once
Chris Forbes40028e22016-06-13 09:59:34 +12003690 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Lobodzinski89cad1a2016-11-11 15:51:31 -07003691 vkQueueWaitIdle(m_device->m_queue);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003692
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003693 m_errorMonitor->VerifyFound();
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003694}
3695
Karl Schultz6addd812016-02-02 17:17:23 -07003696TEST_F(VkLayerTest, AllocDescriptorFromEmptyPool) {
Tobin Ehlis14cd5852016-11-23 12:52:48 -07003697 TEST_DESCRIPTION("Attempt to allocate more sets and descriptors than descriptor pool has available.");
Karl Schultz6addd812016-02-02 17:17:23 -07003698 VkResult err;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003699
3700 ASSERT_NO_FATAL_FAILURE(InitState());
3701 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003702
Karl Schultz6addd812016-02-02 17:17:23 -07003703 // Create Pool w/ 1 Sampler descriptor, but try to alloc Uniform Buffer
3704 // descriptor from it
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003705 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003706 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
Tobin Ehlis14cd5852016-11-23 12:52:48 -07003707 ds_type_count.descriptorCount = 2;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003708
3709 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003710 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3711 ds_pool_ci.pNext = NULL;
3712 ds_pool_ci.flags = 0;
3713 ds_pool_ci.maxSets = 1;
3714 ds_pool_ci.poolSizeCount = 1;
3715 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003716
3717 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003718 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003719 ASSERT_VK_SUCCESS(err);
3720
Tobin Ehlis14cd5852016-11-23 12:52:48 -07003721 VkDescriptorSetLayoutBinding dsl_binding_samp = {};
3722 dsl_binding_samp.binding = 0;
3723 dsl_binding_samp.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
3724 dsl_binding_samp.descriptorCount = 1;
3725 dsl_binding_samp.stageFlags = VK_SHADER_STAGE_ALL;
3726 dsl_binding_samp.pImmutableSamplers = NULL;
3727
3728 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3729 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3730 ds_layout_ci.pNext = NULL;
3731 ds_layout_ci.bindingCount = 1;
3732 ds_layout_ci.pBindings = &dsl_binding_samp;
3733
3734 VkDescriptorSetLayout ds_layout_samp;
3735 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout_samp);
3736 ASSERT_VK_SUCCESS(err);
3737
3738 // Try to allocate 2 sets when pool only has 1 set
3739 VkDescriptorSet descriptor_sets[2];
3740 VkDescriptorSetLayout set_layouts[2] = {ds_layout_samp, ds_layout_samp};
3741 VkDescriptorSetAllocateInfo alloc_info = {};
3742 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
3743 alloc_info.descriptorSetCount = 2;
3744 alloc_info.descriptorPool = ds_pool;
3745 alloc_info.pSetLayouts = set_layouts;
3746 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00911);
3747 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptor_sets);
3748 m_errorMonitor->VerifyFound();
3749
3750 alloc_info.descriptorSetCount = 1;
3751 // Create layout w/ descriptor type not available in pool
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003752 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003753 dsl_binding.binding = 0;
3754 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3755 dsl_binding.descriptorCount = 1;
3756 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3757 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003758
Karl Schultz6addd812016-02-02 17:17:23 -07003759 ds_layout_ci.bindingCount = 1;
3760 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003761
Tobin Ehlis14cd5852016-11-23 12:52:48 -07003762 VkDescriptorSetLayout ds_layout_ub;
3763 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout_ub);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003764 ASSERT_VK_SUCCESS(err);
3765
Tobin Ehlis14cd5852016-11-23 12:52:48 -07003766 VkDescriptorSet descriptor_set;
Jon Ashburnf19916e2016-01-11 13:12:43 -07003767 alloc_info.descriptorSetCount = 1;
Tobin Ehlis14cd5852016-11-23 12:52:48 -07003768 alloc_info.pSetLayouts = &ds_layout_ub;
3769 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00912);
3770 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003771
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003772 m_errorMonitor->VerifyFound();
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003773
Karl Schultz2825ab92016-12-02 08:23:14 -07003774 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_samp, NULL);
Tobin Ehlis14cd5852016-11-23 12:52:48 -07003775 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_ub, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +08003776 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003777}
3778
Karl Schultz6addd812016-02-02 17:17:23 -07003779TEST_F(VkLayerTest, FreeDescriptorFromOneShotPool) {
3780 VkResult err;
Tobin Ehlise735c692015-10-08 13:13:50 -06003781
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003782 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3783 "It is invalid to call vkFreeDescriptorSets() with a pool created "
3784 "without setting VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003785
Tobin Ehlise735c692015-10-08 13:13:50 -06003786 ASSERT_NO_FATAL_FAILURE(InitState());
3787 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise735c692015-10-08 13:13:50 -06003788
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003789 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003790 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3791 ds_type_count.descriptorCount = 1;
Tobin Ehlise735c692015-10-08 13:13:50 -06003792
3793 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003794 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3795 ds_pool_ci.pNext = NULL;
3796 ds_pool_ci.maxSets = 1;
3797 ds_pool_ci.poolSizeCount = 1;
3798 ds_pool_ci.flags = 0;
3799 // Not specifying VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT means
3800 // app can only call vkResetDescriptorPool on this pool.;
3801 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise735c692015-10-08 13:13:50 -06003802
3803 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003804 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise735c692015-10-08 13:13:50 -06003805 ASSERT_VK_SUCCESS(err);
3806
3807 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003808 dsl_binding.binding = 0;
3809 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3810 dsl_binding.descriptorCount = 1;
3811 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3812 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlise735c692015-10-08 13:13:50 -06003813
3814 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003815 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3816 ds_layout_ci.pNext = NULL;
3817 ds_layout_ci.bindingCount = 1;
3818 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise735c692015-10-08 13:13:50 -06003819
3820 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003821 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise735c692015-10-08 13:13:50 -06003822 ASSERT_VK_SUCCESS(err);
3823
3824 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003825 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08003826 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07003827 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06003828 alloc_info.descriptorPool = ds_pool;
3829 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003830 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise735c692015-10-08 13:13:50 -06003831 ASSERT_VK_SUCCESS(err);
3832
3833 err = vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003834 m_errorMonitor->VerifyFound();
Tobin Ehlise735c692015-10-08 13:13:50 -06003835
Chia-I Wuf7458c52015-10-26 21:10:41 +08003836 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3837 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise735c692015-10-08 13:13:50 -06003838}
3839
Karl Schultz6addd812016-02-02 17:17:23 -07003840TEST_F(VkLayerTest, InvalidDescriptorPool) {
Karl Schultzbdb75952016-04-19 11:36:49 -06003841 // Attempt to clear Descriptor Pool with bad object.
3842 // ObjectTracker should catch this.
Cody Northropc31a84f2016-08-22 10:41:47 -06003843
3844 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultzf78bcdd2016-11-30 12:36:01 -07003845 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00930);
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06003846 uint64_t fake_pool_handle = 0xbaad6001;
3847 VkDescriptorPool bad_pool = reinterpret_cast<VkDescriptorPool &>(fake_pool_handle);
3848 vkResetDescriptorPool(device(), bad_pool, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -06003849 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003850}
3851
Karl Schultzf78bcdd2016-11-30 12:36:01 -07003852TEST_F(VkLayerTest, InvalidDescriptorSet) {
Karl Schultzbdb75952016-04-19 11:36:49 -06003853 // Attempt to bind an invalid Descriptor Set to a valid Command Buffer
3854 // ObjectTracker should catch this.
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003855 // Create a valid cmd buffer
Karl Schultzbdb75952016-04-19 11:36:49 -06003856 // call vkCmdBindDescriptorSets w/ false Descriptor Set
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06003857
3858 uint64_t fake_set_handle = 0xbaad6001;
3859 VkDescriptorSet bad_set = reinterpret_cast<VkDescriptorSet &>(fake_set_handle);
Karl Schultzbdb75952016-04-19 11:36:49 -06003860 VkResult err;
Karl Schultzf78bcdd2016-11-30 12:36:01 -07003861 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00982);
Karl Schultzbdb75952016-04-19 11:36:49 -06003862
3863 ASSERT_NO_FATAL_FAILURE(InitState());
3864
3865 VkDescriptorSetLayoutBinding layout_bindings[1] = {};
3866 layout_bindings[0].binding = 0;
3867 layout_bindings[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3868 layout_bindings[0].descriptorCount = 1;
3869 layout_bindings[0].stageFlags = VK_SHADER_STAGE_VERTEX_BIT;
3870 layout_bindings[0].pImmutableSamplers = NULL;
3871
3872 VkDescriptorSetLayout descriptor_set_layout;
3873 VkDescriptorSetLayoutCreateInfo dslci = {};
3874 dslci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3875 dslci.pNext = NULL;
3876 dslci.bindingCount = 1;
3877 dslci.pBindings = layout_bindings;
3878 err = vkCreateDescriptorSetLayout(device(), &dslci, NULL, &descriptor_set_layout);
Karl Schultz5cb21112016-04-21 17:17:40 -06003879 ASSERT_VK_SUCCESS(err);
Karl Schultzbdb75952016-04-19 11:36:49 -06003880
3881 VkPipelineLayout pipeline_layout;
3882 VkPipelineLayoutCreateInfo plci = {};
3883 plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
3884 plci.pNext = NULL;
3885 plci.setLayoutCount = 1;
3886 plci.pSetLayouts = &descriptor_set_layout;
3887 err = vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout);
Karl Schultz5cb21112016-04-21 17:17:40 -06003888 ASSERT_VK_SUCCESS(err);
Karl Schultzbdb75952016-04-19 11:36:49 -06003889
3890 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003891 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1, &bad_set, 0,
3892 NULL);
Karl Schultzbdb75952016-04-19 11:36:49 -06003893 m_errorMonitor->VerifyFound();
3894 EndCommandBuffer();
3895 vkDestroyPipelineLayout(device(), pipeline_layout, NULL);
3896 vkDestroyDescriptorSetLayout(device(), descriptor_set_layout, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003897}
3898
Karl Schultz6addd812016-02-02 17:17:23 -07003899TEST_F(VkLayerTest, InvalidDescriptorSetLayout) {
Karl Schultzbdb75952016-04-19 11:36:49 -06003900 // Attempt to create a Pipeline Layout with an invalid Descriptor Set Layout.
3901 // ObjectTracker should catch this.
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06003902 uint64_t fake_layout_handle = 0xbaad6001;
3903 VkDescriptorSetLayout bad_layout = reinterpret_cast<VkDescriptorSetLayout &>(fake_layout_handle);
Karl Schultzf78bcdd2016-11-30 12:36:01 -07003904 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00875);
Cody Northropc31a84f2016-08-22 10:41:47 -06003905 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultzbdb75952016-04-19 11:36:49 -06003906 VkPipelineLayout pipeline_layout;
3907 VkPipelineLayoutCreateInfo plci = {};
3908 plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
3909 plci.pNext = NULL;
3910 plci.setLayoutCount = 1;
3911 plci.pSetLayouts = &bad_layout;
3912 vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout);
3913
3914 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003915}
3916
Mark Muellerd4914412016-06-13 17:52:06 -06003917TEST_F(VkLayerTest, WriteDescriptorSetIntegrityCheck) {
3918 TEST_DESCRIPTION("This test verifies some requirements of chapter 13.2.3 of the Vulkan Spec "
3919 "1) A uniform buffer update must have a valid buffer index."
3920 "2) When using an array of descriptors in a single WriteDescriptor,"
3921 " the descriptor types and stageflags must all be the same."
3922 "3) Immutable Sampler state must match across descriptors");
3923
3924 const char *invalid_BufferInfo_ErrorMessage =
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003925 "vkUpdateDescriptorSets: if pDescriptorWrites[0].descriptorType is VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, "
3926 "VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC or "
3927 "VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC, pDescriptorWrites[0].pBufferInfo must not be NULL";
3928 const char *stateFlag_ErrorMessage = "Attempting write update to descriptor set ";
3929 const char *immutable_ErrorMessage = "Attempting write update to descriptor set ";
Mark Muellerd4914412016-06-13 17:52:06 -06003930
Mark Muellerd4914412016-06-13 17:52:06 -06003931 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_BufferInfo_ErrorMessage);
3932
3933 ASSERT_NO_FATAL_FAILURE(InitState());
3934 VkDescriptorPoolSize ds_type_count[4] = {};
3935 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3936 ds_type_count[0].descriptorCount = 1;
Tony Barboure132c5f2016-12-12 11:50:20 -07003937 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLER;
Mark Muellerd4914412016-06-13 17:52:06 -06003938 ds_type_count[1].descriptorCount = 1;
Tony Barboure132c5f2016-12-12 11:50:20 -07003939 ds_type_count[2].type = VK_DESCRIPTOR_TYPE_SAMPLER;
Mark Muellerd4914412016-06-13 17:52:06 -06003940 ds_type_count[2].descriptorCount = 1;
3941 ds_type_count[3].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
3942 ds_type_count[3].descriptorCount = 1;
3943
3944 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3945 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3946 ds_pool_ci.maxSets = 1;
3947 ds_pool_ci.poolSizeCount = sizeof(ds_type_count) / sizeof(VkDescriptorPoolSize);
3948 ds_pool_ci.pPoolSizes = ds_type_count;
3949
3950 VkDescriptorPool ds_pool;
3951 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
3952 ASSERT_VK_SUCCESS(err);
3953
Mark Muellerb9896722016-06-16 09:54:29 -06003954 VkDescriptorSetLayoutBinding layout_binding[3] = {};
Mark Muellerd4914412016-06-13 17:52:06 -06003955 layout_binding[0].binding = 0;
3956 layout_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3957 layout_binding[0].descriptorCount = 1;
3958 layout_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
3959 layout_binding[0].pImmutableSamplers = NULL;
3960
3961 layout_binding[1].binding = 1;
3962 layout_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
3963 layout_binding[1].descriptorCount = 1;
3964 layout_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
3965 layout_binding[1].pImmutableSamplers = NULL;
3966
3967 VkSamplerCreateInfo sampler_ci = {};
3968 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
3969 sampler_ci.pNext = NULL;
3970 sampler_ci.magFilter = VK_FILTER_NEAREST;
3971 sampler_ci.minFilter = VK_FILTER_NEAREST;
3972 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
3973 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3974 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3975 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3976 sampler_ci.mipLodBias = 1.0;
3977 sampler_ci.anisotropyEnable = VK_FALSE;
3978 sampler_ci.maxAnisotropy = 1;
3979 sampler_ci.compareEnable = VK_FALSE;
3980 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
3981 sampler_ci.minLod = 1.0;
3982 sampler_ci.maxLod = 1.0;
3983 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
3984 sampler_ci.unnormalizedCoordinates = VK_FALSE;
3985 VkSampler sampler;
3986
3987 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
3988 ASSERT_VK_SUCCESS(err);
3989
3990 layout_binding[2].binding = 2;
3991 layout_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
3992 layout_binding[2].descriptorCount = 1;
3993 layout_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
3994 layout_binding[2].pImmutableSamplers = static_cast<VkSampler *>(&sampler);
3995
Mark Muellerd4914412016-06-13 17:52:06 -06003996 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3997 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3998 ds_layout_ci.bindingCount = sizeof(layout_binding) / sizeof(VkDescriptorSetLayoutBinding);
3999 ds_layout_ci.pBindings = layout_binding;
4000 VkDescriptorSetLayout ds_layout;
4001 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
4002 ASSERT_VK_SUCCESS(err);
4003
4004 VkDescriptorSetAllocateInfo alloc_info = {};
4005 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
4006 alloc_info.descriptorSetCount = 1;
4007 alloc_info.descriptorPool = ds_pool;
4008 alloc_info.pSetLayouts = &ds_layout;
4009 VkDescriptorSet descriptorSet;
4010 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
4011 ASSERT_VK_SUCCESS(err);
4012
4013 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4014 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4015 pipeline_layout_ci.pNext = NULL;
4016 pipeline_layout_ci.setLayoutCount = 1;
4017 pipeline_layout_ci.pSetLayouts = &ds_layout;
4018
4019 VkPipelineLayout pipeline_layout;
4020 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
4021 ASSERT_VK_SUCCESS(err);
4022
Mark Mueller5c838ce2016-06-16 09:54:29 -06004023 VkWriteDescriptorSet descriptor_write = {};
Mark Muellerd4914412016-06-13 17:52:06 -06004024 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
4025 descriptor_write.dstSet = descriptorSet;
4026 descriptor_write.dstBinding = 0;
4027 descriptor_write.descriptorCount = 1;
4028 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4029
Mark Mueller5c838ce2016-06-16 09:54:29 -06004030 // 1) The uniform buffer is intentionally invalid here
Mark Muellerd4914412016-06-13 17:52:06 -06004031 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4032 m_errorMonitor->VerifyFound();
4033
4034 // Create a buffer to update the descriptor with
4035 uint32_t qfi = 0;
4036 VkBufferCreateInfo buffCI = {};
4037 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
4038 buffCI.size = 1024;
4039 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
4040 buffCI.queueFamilyIndexCount = 1;
4041 buffCI.pQueueFamilyIndices = &qfi;
4042
4043 VkBuffer dyub;
4044 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
4045 ASSERT_VK_SUCCESS(err);
Mark Muellerd4914412016-06-13 17:52:06 -06004046
Tony Barboure132c5f2016-12-12 11:50:20 -07004047 VkDeviceMemory mem;
4048 VkMemoryRequirements mem_reqs;
4049 vkGetBufferMemoryRequirements(m_device->device(), dyub, &mem_reqs);
4050
4051 VkMemoryAllocateInfo mem_alloc_info = {};
4052 mem_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4053 mem_alloc_info.allocationSize = mem_reqs.size;
4054 m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
4055 err = vkAllocateMemory(m_device->device(), &mem_alloc_info, NULL, &mem);
4056 ASSERT_VK_SUCCESS(err);
4057
4058 err = vkBindBufferMemory(m_device->device(), dyub, mem, 0);
4059 ASSERT_VK_SUCCESS(err);
4060
4061 VkDescriptorBufferInfo buffInfo[2] = {};
4062 buffInfo[0].buffer = dyub;
4063 buffInfo[0].offset = 0;
4064 buffInfo[0].range = 1024;
4065 buffInfo[1].buffer = dyub;
4066 buffInfo[1].offset = 0;
4067 buffInfo[1].range = 1024;
4068 descriptor_write.pBufferInfo = buffInfo;
Mark Muellerd4914412016-06-13 17:52:06 -06004069 descriptor_write.descriptorCount = 2;
4070
Mark Mueller5c838ce2016-06-16 09:54:29 -06004071 // 2) The stateFlags don't match between the first and second descriptor
Mark Muellerd4914412016-06-13 17:52:06 -06004072 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, stateFlag_ErrorMessage);
4073 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4074 m_errorMonitor->VerifyFound();
4075
Mark Mueller5c838ce2016-06-16 09:54:29 -06004076 // 3) The second descriptor has a null_ptr pImmutableSamplers and
4077 // the third descriptor contains an immutable sampler
Mark Muellerd4914412016-06-13 17:52:06 -06004078 descriptor_write.dstBinding = 1;
4079 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Mark Mueller5c838ce2016-06-16 09:54:29 -06004080
Mark Mueller5c838ce2016-06-16 09:54:29 -06004081 // Make pImageInfo index non-null to avoid complaints of it missing
4082 VkDescriptorImageInfo imageInfo = {};
4083 imageInfo.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
4084 descriptor_write.pImageInfo = &imageInfo;
Mark Muellerd4914412016-06-13 17:52:06 -06004085 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, immutable_ErrorMessage);
4086 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4087 m_errorMonitor->VerifyFound();
4088
Mark Muellerd4914412016-06-13 17:52:06 -06004089 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tony Barboure132c5f2016-12-12 11:50:20 -07004090 vkFreeMemory(m_device->device(), mem, NULL);
Mark Muellerd4914412016-06-13 17:52:06 -06004091 vkDestroySampler(m_device->device(), sampler, NULL);
4092 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4093 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4094 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
4095}
4096
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004097TEST_F(VkLayerTest, InvalidCmdBufferBufferDestroyed) {
4098 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4099 "due to a buffer dependency being destroyed.");
4100 ASSERT_NO_FATAL_FAILURE(InitState());
4101
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004102 VkBuffer buffer;
4103 VkDeviceMemory mem;
4104 VkMemoryRequirements mem_reqs;
4105
4106 VkBufferCreateInfo buf_info = {};
4107 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes3d5882f2016-09-16 17:37:17 +12004108 buf_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004109 buf_info.size = 256;
4110 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
4111 VkResult err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
4112 ASSERT_VK_SUCCESS(err);
4113
4114 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
4115
4116 VkMemoryAllocateInfo alloc_info = {};
4117 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4118 alloc_info.allocationSize = 256;
4119 bool pass = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004120 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 -06004121 if (!pass) {
4122 vkDestroyBuffer(m_device->device(), buffer, NULL);
4123 return;
4124 }
4125 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
4126 ASSERT_VK_SUCCESS(err);
4127
4128 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
4129 ASSERT_VK_SUCCESS(err);
4130
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004131 m_commandBuffer->BeginCommandBuffer();
Chris Forbes3d5882f2016-09-16 17:37:17 +12004132 vkCmdFillBuffer(m_commandBuffer->GetBufferHandle(), buffer, 0, VK_WHOLE_SIZE, 0);
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004133 m_commandBuffer->EndCommandBuffer();
4134
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004135 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound buffer ");
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004136 // Destroy buffer dependency prior to submit to cause ERROR
4137 vkDestroyBuffer(m_device->device(), buffer, NULL);
4138
4139 VkSubmitInfo submit_info = {};
4140 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4141 submit_info.commandBufferCount = 1;
4142 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4143 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4144
4145 m_errorMonitor->VerifyFound();
Rene Lindsayab6c5cd2016-12-20 14:05:37 -07004146 vkQueueWaitIdle(m_device->m_queue);
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004147 vkFreeMemory(m_device->handle(), mem, NULL);
4148}
4149
Tobin Ehlisea413442016-09-28 10:23:59 -06004150TEST_F(VkLayerTest, InvalidCmdBufferBufferViewDestroyed) {
4151 TEST_DESCRIPTION("Delete bufferView bound to cmd buffer, then attempt to submit cmd buffer.");
4152
4153 ASSERT_NO_FATAL_FAILURE(InitState());
4154 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4155
4156 VkDescriptorPoolSize ds_type_count;
4157 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
4158 ds_type_count.descriptorCount = 1;
4159
4160 VkDescriptorPoolCreateInfo ds_pool_ci = {};
4161 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4162 ds_pool_ci.maxSets = 1;
4163 ds_pool_ci.poolSizeCount = 1;
4164 ds_pool_ci.pPoolSizes = &ds_type_count;
4165
4166 VkDescriptorPool ds_pool;
4167 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
4168 ASSERT_VK_SUCCESS(err);
4169
4170 VkDescriptorSetLayoutBinding layout_binding;
4171 layout_binding.binding = 0;
4172 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
4173 layout_binding.descriptorCount = 1;
4174 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
4175 layout_binding.pImmutableSamplers = NULL;
4176
4177 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
4178 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4179 ds_layout_ci.bindingCount = 1;
4180 ds_layout_ci.pBindings = &layout_binding;
4181 VkDescriptorSetLayout ds_layout;
4182 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
4183 ASSERT_VK_SUCCESS(err);
4184
4185 VkDescriptorSetAllocateInfo alloc_info = {};
4186 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
4187 alloc_info.descriptorSetCount = 1;
4188 alloc_info.descriptorPool = ds_pool;
4189 alloc_info.pSetLayouts = &ds_layout;
4190 VkDescriptorSet descriptor_set;
4191 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
4192 ASSERT_VK_SUCCESS(err);
4193
4194 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4195 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4196 pipeline_layout_ci.pNext = NULL;
4197 pipeline_layout_ci.setLayoutCount = 1;
4198 pipeline_layout_ci.pSetLayouts = &ds_layout;
4199
4200 VkPipelineLayout pipeline_layout;
4201 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
4202 ASSERT_VK_SUCCESS(err);
4203
4204 VkBuffer buffer;
4205 uint32_t queue_family_index = 0;
4206 VkBufferCreateInfo buffer_create_info = {};
4207 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
4208 buffer_create_info.size = 1024;
4209 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
4210 buffer_create_info.queueFamilyIndexCount = 1;
4211 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
4212
4213 err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
4214 ASSERT_VK_SUCCESS(err);
4215
4216 VkMemoryRequirements memory_reqs;
4217 VkDeviceMemory buffer_memory;
4218
4219 VkMemoryAllocateInfo memory_info = {};
4220 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4221 memory_info.allocationSize = 0;
4222 memory_info.memoryTypeIndex = 0;
4223
4224 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
4225 memory_info.allocationSize = memory_reqs.size;
4226 bool pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
4227 ASSERT_TRUE(pass);
4228
4229 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
4230 ASSERT_VK_SUCCESS(err);
4231 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
4232 ASSERT_VK_SUCCESS(err);
4233
4234 VkBufferView view;
4235 VkBufferViewCreateInfo bvci = {};
4236 bvci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
4237 bvci.buffer = buffer;
4238 bvci.format = VK_FORMAT_R8_UNORM;
4239 bvci.range = VK_WHOLE_SIZE;
4240
4241 err = vkCreateBufferView(m_device->device(), &bvci, NULL, &view);
4242 ASSERT_VK_SUCCESS(err);
4243
4244 VkWriteDescriptorSet descriptor_write = {};
4245 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
4246 descriptor_write.dstSet = descriptor_set;
4247 descriptor_write.dstBinding = 0;
4248 descriptor_write.descriptorCount = 1;
4249 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
4250 descriptor_write.pTexelBufferView = &view;
4251
4252 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4253
4254 char const *vsSource = "#version 450\n"
4255 "\n"
4256 "out gl_PerVertex { \n"
4257 " vec4 gl_Position;\n"
4258 "};\n"
4259 "void main(){\n"
4260 " gl_Position = vec4(1);\n"
4261 "}\n";
4262 char const *fsSource = "#version 450\n"
4263 "\n"
4264 "layout(set=0, binding=0, r8) uniform imageBuffer s;\n"
4265 "layout(location=0) out vec4 x;\n"
4266 "void main(){\n"
4267 " x = imageLoad(s, 0);\n"
4268 "}\n";
4269 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4270 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
4271 VkPipelineObj pipe(m_device);
4272 pipe.AddShader(&vs);
4273 pipe.AddShader(&fs);
4274 pipe.AddColorAttachment();
4275 pipe.CreateVKPipeline(pipeline_layout, renderPass());
4276
4277 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot submit cmd buffer using deleted buffer view ");
4278 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound buffer view ");
4279
4280 BeginCommandBuffer();
4281 VkViewport viewport = {0, 0, 16, 16, 0, 1};
4282 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
4283 VkRect2D scissor = {{0, 0}, {16, 16}};
4284 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
4285 // Bind pipeline to cmd buffer
4286 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
4287 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
4288 &descriptor_set, 0, nullptr);
4289 Draw(1, 0, 0, 0);
4290 EndCommandBuffer();
4291
4292 // Delete BufferView in order to invalidate cmd buffer
4293 vkDestroyBufferView(m_device->device(), view, NULL);
4294 // Now attempt submit of cmd buffer
4295 VkSubmitInfo submit_info = {};
4296 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4297 submit_info.commandBufferCount = 1;
4298 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4299 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4300 m_errorMonitor->VerifyFound();
4301
4302 // Clean-up
4303 vkDestroyBuffer(m_device->device(), buffer, NULL);
4304 vkFreeMemory(m_device->device(), buffer_memory, NULL);
4305 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4306 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4307 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
4308}
4309
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004310TEST_F(VkLayerTest, InvalidCmdBufferImageDestroyed) {
4311 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4312 "due to an image dependency being destroyed.");
4313 ASSERT_NO_FATAL_FAILURE(InitState());
4314
4315 VkImage image;
4316 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
4317 VkImageCreateInfo image_create_info = {};
4318 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4319 image_create_info.pNext = NULL;
4320 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4321 image_create_info.format = tex_format;
4322 image_create_info.extent.width = 32;
4323 image_create_info.extent.height = 32;
4324 image_create_info.extent.depth = 1;
4325 image_create_info.mipLevels = 1;
4326 image_create_info.arrayLayers = 1;
4327 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
4328 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004329 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004330 image_create_info.flags = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004331 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004332 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004333 // Have to bind memory to image before recording cmd in cmd buffer using it
4334 VkMemoryRequirements mem_reqs;
4335 VkDeviceMemory image_mem;
4336 bool pass;
4337 VkMemoryAllocateInfo mem_alloc = {};
4338 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4339 mem_alloc.pNext = NULL;
4340 mem_alloc.memoryTypeIndex = 0;
4341 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
4342 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004343 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004344 ASSERT_TRUE(pass);
4345 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
4346 ASSERT_VK_SUCCESS(err);
4347 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
4348 ASSERT_VK_SUCCESS(err);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004349
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004350 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlis764d7072016-07-01 12:54:29 -06004351 VkClearColorValue ccv;
4352 ccv.float32[0] = 1.0f;
4353 ccv.float32[1] = 1.0f;
4354 ccv.float32[2] = 1.0f;
4355 ccv.float32[3] = 1.0f;
4356 VkImageSubresourceRange isr = {};
4357 isr.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004358 isr.baseArrayLayer = 0;
4359 isr.baseMipLevel = 0;
Tobin Ehlis764d7072016-07-01 12:54:29 -06004360 isr.layerCount = 1;
4361 isr.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004362 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), image, VK_IMAGE_LAYOUT_GENERAL, &ccv, 1, &isr);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004363 m_commandBuffer->EndCommandBuffer();
4364
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004365 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004366 // Destroy image dependency prior to submit to cause ERROR
4367 vkDestroyImage(m_device->device(), image, NULL);
4368
4369 VkSubmitInfo submit_info = {};
4370 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4371 submit_info.commandBufferCount = 1;
4372 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4373 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4374
4375 m_errorMonitor->VerifyFound();
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004376 vkFreeMemory(m_device->device(), image_mem, nullptr);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004377}
4378
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004379TEST_F(VkLayerTest, InvalidCmdBufferFramebufferImageDestroyed) {
4380 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4381 "due to a framebuffer image dependency being destroyed.");
4382 VkFormatProperties format_properties;
4383 VkResult err = VK_SUCCESS;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004384 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
4385 if (!(format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)) {
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004386 return;
4387 }
4388
4389 ASSERT_NO_FATAL_FAILURE(InitState());
4390 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4391
4392 VkImageCreateInfo image_ci = {};
4393 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4394 image_ci.pNext = NULL;
4395 image_ci.imageType = VK_IMAGE_TYPE_2D;
4396 image_ci.format = VK_FORMAT_B8G8R8A8_UNORM;
4397 image_ci.extent.width = 32;
4398 image_ci.extent.height = 32;
4399 image_ci.extent.depth = 1;
4400 image_ci.mipLevels = 1;
4401 image_ci.arrayLayers = 1;
4402 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
4403 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004404 image_ci.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_SAMPLED_BIT;
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004405 image_ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
4406 image_ci.flags = 0;
4407 VkImage image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004408 ASSERT_VK_SUCCESS(vkCreateImage(m_device->handle(), &image_ci, NULL, &image));
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004409
4410 VkMemoryRequirements memory_reqs;
4411 VkDeviceMemory image_memory;
4412 bool pass;
4413 VkMemoryAllocateInfo memory_info = {};
4414 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4415 memory_info.pNext = NULL;
4416 memory_info.allocationSize = 0;
4417 memory_info.memoryTypeIndex = 0;
4418 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
4419 memory_info.allocationSize = memory_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004420 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004421 ASSERT_TRUE(pass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004422 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004423 ASSERT_VK_SUCCESS(err);
4424 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
4425 ASSERT_VK_SUCCESS(err);
4426
4427 VkImageViewCreateInfo ivci = {
4428 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
4429 nullptr,
4430 0,
4431 image,
4432 VK_IMAGE_VIEW_TYPE_2D,
4433 VK_FORMAT_B8G8R8A8_UNORM,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004434 {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A},
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004435 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
4436 };
4437 VkImageView view;
4438 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
4439 ASSERT_VK_SUCCESS(err);
4440
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004441 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 32, 32, 1};
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004442 VkFramebuffer fb;
4443 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
4444 ASSERT_VK_SUCCESS(err);
4445
4446 // Just use default renderpass with our framebuffer
4447 m_renderPassBeginInfo.framebuffer = fb;
4448 // Create Null cmd buffer for submit
4449 BeginCommandBuffer();
4450 EndCommandBuffer();
4451 // Destroy image attached to framebuffer to invalidate cmd buffer
4452 vkDestroyImage(m_device->device(), image, NULL);
4453 // Now attempt to submit cmd buffer and verify error
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004454 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004455 QueueCommandBuffer(false);
4456 m_errorMonitor->VerifyFound();
4457
4458 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
4459 vkDestroyImageView(m_device->device(), view, nullptr);
4460 vkFreeMemory(m_device->device(), image_memory, nullptr);
4461}
4462
Tobin Ehlisb329f992016-10-12 13:20:29 -06004463TEST_F(VkLayerTest, FramebufferInUseDestroyedSignaled) {
4464 TEST_DESCRIPTION("Delete in-use framebuffer.");
4465 VkFormatProperties format_properties;
4466 VkResult err = VK_SUCCESS;
4467 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
4468
4469 ASSERT_NO_FATAL_FAILURE(InitState());
4470 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4471
4472 VkImageObj image(m_device);
4473 image.init(256, 256, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
4474 ASSERT_TRUE(image.initialized());
4475 VkImageView view = image.targetView(VK_FORMAT_B8G8R8A8_UNORM);
4476
4477 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 256, 256, 1};
4478 VkFramebuffer fb;
4479 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
4480 ASSERT_VK_SUCCESS(err);
4481
4482 // Just use default renderpass with our framebuffer
4483 m_renderPassBeginInfo.framebuffer = fb;
4484 // Create Null cmd buffer for submit
4485 BeginCommandBuffer();
4486 EndCommandBuffer();
4487 // Submit cmd buffer to put it in-flight
4488 VkSubmitInfo submit_info = {};
4489 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4490 submit_info.commandBufferCount = 1;
4491 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4492 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4493 // Destroy framebuffer while in-flight
4494 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete framebuffer 0x");
4495 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4496 m_errorMonitor->VerifyFound();
4497 // Wait for queue to complete so we can safely destroy everything
4498 vkQueueWaitIdle(m_device->m_queue);
4499 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
4500}
4501
Tobin Ehlis88becd72016-09-21 14:33:41 -06004502TEST_F(VkLayerTest, FramebufferImageInUseDestroyedSignaled) {
4503 TEST_DESCRIPTION("Delete in-use image that's child of framebuffer.");
4504 VkFormatProperties format_properties;
4505 VkResult err = VK_SUCCESS;
4506 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
Tobin Ehlis88becd72016-09-21 14:33:41 -06004507
4508 ASSERT_NO_FATAL_FAILURE(InitState());
4509 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4510
4511 VkImageCreateInfo image_ci = {};
4512 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4513 image_ci.pNext = NULL;
4514 image_ci.imageType = VK_IMAGE_TYPE_2D;
4515 image_ci.format = VK_FORMAT_B8G8R8A8_UNORM;
4516 image_ci.extent.width = 256;
4517 image_ci.extent.height = 256;
4518 image_ci.extent.depth = 1;
4519 image_ci.mipLevels = 1;
4520 image_ci.arrayLayers = 1;
4521 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
4522 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
Tobin Ehlisc8ca0312016-09-22 07:30:05 -06004523 image_ci.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Tobin Ehlis88becd72016-09-21 14:33:41 -06004524 image_ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
4525 image_ci.flags = 0;
4526 VkImage image;
4527 ASSERT_VK_SUCCESS(vkCreateImage(m_device->handle(), &image_ci, NULL, &image));
4528
4529 VkMemoryRequirements memory_reqs;
4530 VkDeviceMemory image_memory;
4531 bool pass;
4532 VkMemoryAllocateInfo memory_info = {};
4533 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4534 memory_info.pNext = NULL;
4535 memory_info.allocationSize = 0;
4536 memory_info.memoryTypeIndex = 0;
4537 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
4538 memory_info.allocationSize = memory_reqs.size;
4539 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
4540 ASSERT_TRUE(pass);
4541 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
4542 ASSERT_VK_SUCCESS(err);
4543 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
4544 ASSERT_VK_SUCCESS(err);
4545
4546 VkImageViewCreateInfo ivci = {
4547 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
4548 nullptr,
4549 0,
4550 image,
4551 VK_IMAGE_VIEW_TYPE_2D,
4552 VK_FORMAT_B8G8R8A8_UNORM,
4553 {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A},
4554 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
4555 };
4556 VkImageView view;
4557 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
4558 ASSERT_VK_SUCCESS(err);
4559
4560 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 256, 256, 1};
4561 VkFramebuffer fb;
4562 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
4563 ASSERT_VK_SUCCESS(err);
4564
4565 // Just use default renderpass with our framebuffer
4566 m_renderPassBeginInfo.framebuffer = fb;
4567 // Create Null cmd buffer for submit
4568 BeginCommandBuffer();
4569 EndCommandBuffer();
4570 // Submit cmd buffer to put it (and attached imageView) in-flight
4571 VkSubmitInfo submit_info = {};
4572 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4573 submit_info.commandBufferCount = 1;
4574 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4575 // Submit cmd buffer to put framebuffer and children in-flight
4576 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4577 // Destroy image attached to framebuffer while in-flight
4578 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete image 0x");
4579 vkDestroyImage(m_device->device(), image, NULL);
4580 m_errorMonitor->VerifyFound();
4581 // Wait for queue to complete so we can safely destroy image and other objects
4582 vkQueueWaitIdle(m_device->m_queue);
4583 vkDestroyImage(m_device->device(), image, NULL);
4584 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
4585 vkDestroyImageView(m_device->device(), view, nullptr);
4586 vkFreeMemory(m_device->device(), image_memory, nullptr);
4587}
4588
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06004589TEST_F(VkLayerTest, RenderPassInUseDestroyedSignaled) {
4590 TEST_DESCRIPTION("Delete in-use renderPass.");
4591
4592 ASSERT_NO_FATAL_FAILURE(InitState());
4593 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4594
4595 // Create simple renderpass
4596 VkAttachmentReference attach = {};
4597 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
4598 VkSubpassDescription subpass = {};
4599 subpass.pColorAttachments = &attach;
4600 VkRenderPassCreateInfo rpci = {};
4601 rpci.subpassCount = 1;
4602 rpci.pSubpasses = &subpass;
4603 rpci.attachmentCount = 1;
4604 VkAttachmentDescription attach_desc = {};
4605 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
4606 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
4607 rpci.pAttachments = &attach_desc;
4608 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
4609 VkRenderPass rp;
4610 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
4611 ASSERT_VK_SUCCESS(err);
4612
4613 // Create a pipeline that uses the given renderpass
4614 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4615 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4616
4617 VkPipelineLayout pipeline_layout;
4618 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
4619 ASSERT_VK_SUCCESS(err);
4620
4621 VkPipelineViewportStateCreateInfo vp_state_ci = {};
4622 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
4623 vp_state_ci.viewportCount = 1;
4624 VkViewport vp = {}; // Just need dummy vp to point to
4625 vp_state_ci.pViewports = &vp;
4626 vp_state_ci.scissorCount = 1;
4627 VkRect2D scissors = {}; // Dummy scissors to point to
4628 vp_state_ci.pScissors = &scissors;
4629
4630 VkPipelineShaderStageCreateInfo shaderStages[2];
4631 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
4632
4633 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
4634 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
4635 // but add it to be able to run on more devices
4636 shaderStages[0] = vs.GetStageCreateInfo();
4637 shaderStages[1] = fs.GetStageCreateInfo();
4638
4639 VkPipelineVertexInputStateCreateInfo vi_ci = {};
4640 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
4641
4642 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
4643 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
4644 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
4645
4646 VkPipelineRasterizationStateCreateInfo rs_ci = {};
4647 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
4648 rs_ci.rasterizerDiscardEnable = true;
4649 rs_ci.lineWidth = 1.0f;
4650
4651 VkPipelineColorBlendAttachmentState att = {};
4652 att.blendEnable = VK_FALSE;
4653 att.colorWriteMask = 0xf;
4654
4655 VkPipelineColorBlendStateCreateInfo cb_ci = {};
4656 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
4657 cb_ci.attachmentCount = 1;
4658 cb_ci.pAttachments = &att;
4659
4660 VkGraphicsPipelineCreateInfo gp_ci = {};
4661 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
4662 gp_ci.stageCount = 2;
4663 gp_ci.pStages = shaderStages;
4664 gp_ci.pVertexInputState = &vi_ci;
4665 gp_ci.pInputAssemblyState = &ia_ci;
4666 gp_ci.pViewportState = &vp_state_ci;
4667 gp_ci.pRasterizationState = &rs_ci;
4668 gp_ci.pColorBlendState = &cb_ci;
4669 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
4670 gp_ci.layout = pipeline_layout;
4671 gp_ci.renderPass = rp;
4672
4673 VkPipelineCacheCreateInfo pc_ci = {};
4674 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
4675
4676 VkPipeline pipeline;
4677 VkPipelineCache pipe_cache;
4678 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipe_cache);
4679 ASSERT_VK_SUCCESS(err);
4680
4681 err = vkCreateGraphicsPipelines(m_device->device(), pipe_cache, 1, &gp_ci, NULL, &pipeline);
4682 ASSERT_VK_SUCCESS(err);
4683 // Bind pipeline to cmd buffer, will also bind renderpass
4684 m_commandBuffer->BeginCommandBuffer();
4685 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
4686 m_commandBuffer->EndCommandBuffer();
4687
4688 VkSubmitInfo submit_info = {};
4689 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4690 submit_info.commandBufferCount = 1;
4691 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4692 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4693
4694 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00393);
4695 vkDestroyRenderPass(m_device->device(), rp, nullptr);
4696 m_errorMonitor->VerifyFound();
4697
4698 // Wait for queue to complete so we can safely destroy everything
4699 vkQueueWaitIdle(m_device->m_queue);
4700 vkDestroyRenderPass(m_device->device(), rp, nullptr);
4701 vkDestroyPipeline(m_device->device(), pipeline, nullptr);
4702 vkDestroyPipelineCache(m_device->device(), pipe_cache, nullptr);
4703 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
4704}
4705
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004706TEST_F(VkLayerTest, ImageMemoryNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004707 TEST_DESCRIPTION("Attempt to draw with an image which has not had memory bound to it.");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004708 ASSERT_NO_FATAL_FAILURE(InitState());
4709
4710 VkImage image;
4711 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
4712 VkImageCreateInfo image_create_info = {};
4713 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4714 image_create_info.pNext = NULL;
4715 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4716 image_create_info.format = tex_format;
4717 image_create_info.extent.width = 32;
4718 image_create_info.extent.height = 32;
4719 image_create_info.extent.depth = 1;
4720 image_create_info.mipLevels = 1;
4721 image_create_info.arrayLayers = 1;
4722 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
4723 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004724 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004725 image_create_info.flags = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004726 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004727 ASSERT_VK_SUCCESS(err);
4728 // Have to bind memory to image before recording cmd in cmd buffer using it
4729 VkMemoryRequirements mem_reqs;
4730 VkDeviceMemory image_mem;
4731 bool pass;
4732 VkMemoryAllocateInfo mem_alloc = {};
4733 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4734 mem_alloc.pNext = NULL;
4735 mem_alloc.memoryTypeIndex = 0;
4736 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
4737 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004738 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004739 ASSERT_TRUE(pass);
4740 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
4741 ASSERT_VK_SUCCESS(err);
4742
Tobin Ehlisfed999f2016-09-21 15:09:45 -06004743 // Introduce error, do not call vkBindImageMemory(m_device->device(), image, image_mem, 0);
4744 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06004745 " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004746
4747 m_commandBuffer->BeginCommandBuffer();
4748 VkClearColorValue ccv;
4749 ccv.float32[0] = 1.0f;
4750 ccv.float32[1] = 1.0f;
4751 ccv.float32[2] = 1.0f;
4752 ccv.float32[3] = 1.0f;
4753 VkImageSubresourceRange isr = {};
4754 isr.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
4755 isr.baseArrayLayer = 0;
4756 isr.baseMipLevel = 0;
4757 isr.layerCount = 1;
4758 isr.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004759 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), image, VK_IMAGE_LAYOUT_GENERAL, &ccv, 1, &isr);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004760 m_commandBuffer->EndCommandBuffer();
4761
4762 m_errorMonitor->VerifyFound();
4763 vkDestroyImage(m_device->device(), image, NULL);
4764 vkFreeMemory(m_device->device(), image_mem, nullptr);
4765}
4766
4767TEST_F(VkLayerTest, BufferMemoryNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004768 TEST_DESCRIPTION("Attempt to copy from a buffer which has not had memory bound to it.");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004769 ASSERT_NO_FATAL_FAILURE(InitState());
4770
4771 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004772 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 -06004773 VK_IMAGE_TILING_OPTIMAL, 0);
4774 ASSERT_TRUE(image.initialized());
4775
4776 VkBuffer buffer;
4777 VkDeviceMemory mem;
4778 VkMemoryRequirements mem_reqs;
4779
4780 VkBufferCreateInfo buf_info = {};
4781 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes8d260dd2016-09-16 17:42:42 +12004782 buf_info.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004783 buf_info.size = 256;
4784 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
4785 VkResult err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
4786 ASSERT_VK_SUCCESS(err);
4787
4788 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
4789
4790 VkMemoryAllocateInfo alloc_info = {};
4791 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4792 alloc_info.allocationSize = 256;
4793 bool pass = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004794 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 -06004795 if (!pass) {
4796 vkDestroyBuffer(m_device->device(), buffer, NULL);
4797 return;
4798 }
4799 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
4800 ASSERT_VK_SUCCESS(err);
4801
Tobin Ehlisfed999f2016-09-21 15:09:45 -06004802 // Introduce failure by not calling vkBindBufferMemory(m_device->device(), buffer, mem, 0);
4803 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06004804 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004805 VkBufferImageCopy region = {};
4806 region.bufferRowLength = 128;
4807 region.bufferImageHeight = 128;
4808 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
4809
4810 region.imageSubresource.layerCount = 1;
4811 region.imageExtent.height = 4;
4812 region.imageExtent.width = 4;
4813 region.imageExtent.depth = 1;
4814 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004815 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer, image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
4816 &region);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004817 m_commandBuffer->EndCommandBuffer();
4818
4819 m_errorMonitor->VerifyFound();
4820
4821 vkDestroyBuffer(m_device->device(), buffer, NULL);
4822 vkFreeMemory(m_device->handle(), mem, NULL);
4823}
4824
Tobin Ehlis85940f52016-07-07 16:57:21 -06004825TEST_F(VkLayerTest, InvalidCmdBufferEventDestroyed) {
4826 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4827 "due to an event dependency being destroyed.");
4828 ASSERT_NO_FATAL_FAILURE(InitState());
4829
4830 VkEvent event;
4831 VkEventCreateInfo evci = {};
4832 evci.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
4833 VkResult result = vkCreateEvent(m_device->device(), &evci, NULL, &event);
4834 ASSERT_VK_SUCCESS(result);
4835
4836 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004837 vkCmdSetEvent(m_commandBuffer->GetBufferHandle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Tobin Ehlis85940f52016-07-07 16:57:21 -06004838 m_commandBuffer->EndCommandBuffer();
4839
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004840 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound event ");
Tobin Ehlis85940f52016-07-07 16:57:21 -06004841 // Destroy event dependency prior to submit to cause ERROR
4842 vkDestroyEvent(m_device->device(), event, NULL);
4843
4844 VkSubmitInfo submit_info = {};
4845 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4846 submit_info.commandBufferCount = 1;
4847 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4848 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4849
4850 m_errorMonitor->VerifyFound();
4851}
4852
Tobin Ehlisdbea7552016-07-08 14:33:31 -06004853TEST_F(VkLayerTest, InvalidCmdBufferQueryPoolDestroyed) {
4854 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4855 "due to a query pool dependency being destroyed.");
4856 ASSERT_NO_FATAL_FAILURE(InitState());
4857
4858 VkQueryPool query_pool;
4859 VkQueryPoolCreateInfo qpci{};
4860 qpci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
4861 qpci.queryType = VK_QUERY_TYPE_TIMESTAMP;
4862 qpci.queryCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004863 VkResult result = vkCreateQueryPool(m_device->device(), &qpci, nullptr, &query_pool);
Tobin Ehlisdbea7552016-07-08 14:33:31 -06004864 ASSERT_VK_SUCCESS(result);
4865
4866 m_commandBuffer->BeginCommandBuffer();
4867 vkCmdResetQueryPool(m_commandBuffer->GetBufferHandle(), query_pool, 0, 1);
4868 m_commandBuffer->EndCommandBuffer();
4869
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004870 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound query pool ");
Tobin Ehlisdbea7552016-07-08 14:33:31 -06004871 // Destroy query pool dependency prior to submit to cause ERROR
4872 vkDestroyQueryPool(m_device->device(), query_pool, NULL);
4873
4874 VkSubmitInfo submit_info = {};
4875 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4876 submit_info.commandBufferCount = 1;
4877 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4878 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4879
4880 m_errorMonitor->VerifyFound();
4881}
4882
Tobin Ehlis24130d92016-07-08 15:50:53 -06004883TEST_F(VkLayerTest, InvalidCmdBufferPipelineDestroyed) {
4884 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4885 "due to a pipeline dependency being destroyed.");
4886 ASSERT_NO_FATAL_FAILURE(InitState());
4887 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4888
4889 VkResult err;
4890
4891 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4892 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4893
4894 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004895 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis24130d92016-07-08 15:50:53 -06004896 ASSERT_VK_SUCCESS(err);
4897
4898 VkPipelineViewportStateCreateInfo vp_state_ci = {};
4899 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
4900 vp_state_ci.viewportCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004901 VkViewport vp = {}; // Just need dummy vp to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -06004902 vp_state_ci.pViewports = &vp;
Tobin Ehlis24130d92016-07-08 15:50:53 -06004903 vp_state_ci.scissorCount = 1;
4904 VkRect2D scissors = {}; // Dummy scissors to point to
4905 vp_state_ci.pScissors = &scissors;
Tobin Ehlis24130d92016-07-08 15:50:53 -06004906
4907 VkPipelineShaderStageCreateInfo shaderStages[2];
4908 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
4909
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004910 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
4911 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
4912 // but add it to be able to run on more devices
Tobin Ehlis24130d92016-07-08 15:50:53 -06004913 shaderStages[0] = vs.GetStageCreateInfo();
4914 shaderStages[1] = fs.GetStageCreateInfo();
4915
4916 VkPipelineVertexInputStateCreateInfo vi_ci = {};
4917 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
4918
4919 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
4920 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
4921 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
4922
4923 VkPipelineRasterizationStateCreateInfo rs_ci = {};
4924 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Chris Forbese06ba252016-09-16 17:48:53 +12004925 rs_ci.rasterizerDiscardEnable = true;
4926 rs_ci.lineWidth = 1.0f;
Tobin Ehlis24130d92016-07-08 15:50:53 -06004927
4928 VkPipelineColorBlendAttachmentState att = {};
4929 att.blendEnable = VK_FALSE;
4930 att.colorWriteMask = 0xf;
4931
4932 VkPipelineColorBlendStateCreateInfo cb_ci = {};
4933 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
4934 cb_ci.attachmentCount = 1;
4935 cb_ci.pAttachments = &att;
4936
4937 VkGraphicsPipelineCreateInfo gp_ci = {};
4938 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
4939 gp_ci.stageCount = 2;
4940 gp_ci.pStages = shaderStages;
4941 gp_ci.pVertexInputState = &vi_ci;
4942 gp_ci.pInputAssemblyState = &ia_ci;
4943 gp_ci.pViewportState = &vp_state_ci;
4944 gp_ci.pRasterizationState = &rs_ci;
4945 gp_ci.pColorBlendState = &cb_ci;
Tobin Ehlis24130d92016-07-08 15:50:53 -06004946 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
4947 gp_ci.layout = pipeline_layout;
4948 gp_ci.renderPass = renderPass();
4949
4950 VkPipelineCacheCreateInfo pc_ci = {};
4951 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
4952
4953 VkPipeline pipeline;
4954 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004955 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis24130d92016-07-08 15:50:53 -06004956 ASSERT_VK_SUCCESS(err);
4957
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004958 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis24130d92016-07-08 15:50:53 -06004959 ASSERT_VK_SUCCESS(err);
4960
4961 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004962 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Tobin Ehlis24130d92016-07-08 15:50:53 -06004963 m_commandBuffer->EndCommandBuffer();
4964 // Now destroy pipeline in order to cause error when submitting
4965 vkDestroyPipeline(m_device->device(), pipeline, nullptr);
4966
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004967 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound pipeline ");
Tobin Ehlis24130d92016-07-08 15:50:53 -06004968
4969 VkSubmitInfo submit_info = {};
4970 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4971 submit_info.commandBufferCount = 1;
4972 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4973 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4974
4975 m_errorMonitor->VerifyFound();
4976 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
4977 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4978}
4979
Tobin Ehlis31289162016-08-17 14:57:58 -06004980TEST_F(VkLayerTest, InvalidCmdBufferDescriptorSetBufferDestroyed) {
4981 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4982 "due to a bound descriptor set with a buffer dependency "
4983 "being destroyed.");
4984 ASSERT_NO_FATAL_FAILURE(InitState());
4985 ASSERT_NO_FATAL_FAILURE(InitViewport());
4986 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4987
4988 VkDescriptorPoolSize ds_type_count = {};
4989 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4990 ds_type_count.descriptorCount = 1;
4991
4992 VkDescriptorPoolCreateInfo ds_pool_ci = {};
4993 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4994 ds_pool_ci.pNext = NULL;
4995 ds_pool_ci.maxSets = 1;
4996 ds_pool_ci.poolSizeCount = 1;
4997 ds_pool_ci.pPoolSizes = &ds_type_count;
4998
4999 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005000 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis31289162016-08-17 14:57:58 -06005001 ASSERT_VK_SUCCESS(err);
5002
5003 VkDescriptorSetLayoutBinding dsl_binding = {};
5004 dsl_binding.binding = 0;
5005 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5006 dsl_binding.descriptorCount = 1;
5007 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5008 dsl_binding.pImmutableSamplers = NULL;
5009
5010 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5011 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5012 ds_layout_ci.pNext = NULL;
5013 ds_layout_ci.bindingCount = 1;
5014 ds_layout_ci.pBindings = &dsl_binding;
5015 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005016 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis31289162016-08-17 14:57:58 -06005017 ASSERT_VK_SUCCESS(err);
5018
5019 VkDescriptorSet descriptorSet;
5020 VkDescriptorSetAllocateInfo alloc_info = {};
5021 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
5022 alloc_info.descriptorSetCount = 1;
5023 alloc_info.descriptorPool = ds_pool;
5024 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005025 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis31289162016-08-17 14:57:58 -06005026 ASSERT_VK_SUCCESS(err);
5027
5028 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5029 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5030 pipeline_layout_ci.pNext = NULL;
5031 pipeline_layout_ci.setLayoutCount = 1;
5032 pipeline_layout_ci.pSetLayouts = &ds_layout;
5033
5034 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005035 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis31289162016-08-17 14:57:58 -06005036 ASSERT_VK_SUCCESS(err);
5037
5038 // Create a buffer to update the descriptor with
5039 uint32_t qfi = 0;
5040 VkBufferCreateInfo buffCI = {};
5041 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
5042 buffCI.size = 1024;
5043 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
5044 buffCI.queueFamilyIndexCount = 1;
5045 buffCI.pQueueFamilyIndices = &qfi;
5046
5047 VkBuffer buffer;
5048 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &buffer);
5049 ASSERT_VK_SUCCESS(err);
5050 // Allocate memory and bind to buffer so we can make it to the appropriate
5051 // error
5052 VkMemoryAllocateInfo mem_alloc = {};
5053 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5054 mem_alloc.pNext = NULL;
5055 mem_alloc.allocationSize = 1024;
5056 mem_alloc.memoryTypeIndex = 0;
5057
5058 VkMemoryRequirements memReqs;
5059 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005060 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis31289162016-08-17 14:57:58 -06005061 if (!pass) {
5062 vkDestroyBuffer(m_device->device(), buffer, NULL);
5063 return;
5064 }
5065
5066 VkDeviceMemory mem;
5067 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
5068 ASSERT_VK_SUCCESS(err);
5069 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
5070 ASSERT_VK_SUCCESS(err);
5071 // Correctly update descriptor to avoid "NOT_UPDATED" error
5072 VkDescriptorBufferInfo buffInfo = {};
5073 buffInfo.buffer = buffer;
5074 buffInfo.offset = 0;
5075 buffInfo.range = 1024;
5076
5077 VkWriteDescriptorSet descriptor_write;
5078 memset(&descriptor_write, 0, sizeof(descriptor_write));
5079 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5080 descriptor_write.dstSet = descriptorSet;
5081 descriptor_write.dstBinding = 0;
5082 descriptor_write.descriptorCount = 1;
5083 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5084 descriptor_write.pBufferInfo = &buffInfo;
5085
5086 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5087
5088 // Create PSO to be used for draw-time errors below
5089 char const *vsSource = "#version 450\n"
5090 "\n"
5091 "out gl_PerVertex { \n"
5092 " vec4 gl_Position;\n"
5093 "};\n"
5094 "void main(){\n"
5095 " gl_Position = vec4(1);\n"
5096 "}\n";
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005097 char const *fsSource = "#version 450\n"
5098 "\n"
5099 "layout(location=0) out vec4 x;\n"
5100 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
5101 "void main(){\n"
5102 " x = vec4(bar.y);\n"
5103 "}\n";
Tobin Ehlis31289162016-08-17 14:57:58 -06005104 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5105 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5106 VkPipelineObj pipe(m_device);
5107 pipe.AddShader(&vs);
5108 pipe.AddShader(&fs);
5109 pipe.AddColorAttachment();
5110 pipe.CreateVKPipeline(pipeline_layout, renderPass());
5111
5112 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005113 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5114 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5115 &descriptorSet, 0, NULL);
Tobin Ehlis31289162016-08-17 14:57:58 -06005116 Draw(1, 0, 0, 0);
5117 EndCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005118 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound buffer ");
Tobin Ehlis31289162016-08-17 14:57:58 -06005119 // Destroy buffer should invalidate the cmd buffer, causing error on submit
5120 vkDestroyBuffer(m_device->device(), buffer, NULL);
5121 // Attempt to submit cmd buffer
5122 VkSubmitInfo submit_info = {};
5123 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5124 submit_info.commandBufferCount = 1;
5125 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5126 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5127 m_errorMonitor->VerifyFound();
5128 // Cleanup
5129 vkFreeMemory(m_device->device(), mem, NULL);
5130
5131 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5132 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5133 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5134}
5135
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005136TEST_F(VkLayerTest, InvalidCmdBufferDescriptorSetImageSamplerDestroyed) {
5137 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
5138 "due to a bound descriptor sets with a combined image "
5139 "sampler having their image, sampler, and descriptor set "
5140 "each respectively destroyed and then attempting to "
Mark Mueller917f6bc2016-08-30 10:57:19 -06005141 "submit associated cmd buffers. Attempt to destroy a "
5142 "DescriptorSet that is in use.");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005143 ASSERT_NO_FATAL_FAILURE(InitState());
5144 ASSERT_NO_FATAL_FAILURE(InitViewport());
5145 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5146
5147 VkDescriptorPoolSize ds_type_count = {};
5148 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5149 ds_type_count.descriptorCount = 1;
5150
5151 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5152 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5153 ds_pool_ci.pNext = NULL;
5154 ds_pool_ci.maxSets = 1;
5155 ds_pool_ci.poolSizeCount = 1;
5156 ds_pool_ci.pPoolSizes = &ds_type_count;
5157
5158 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005159 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005160 ASSERT_VK_SUCCESS(err);
5161
5162 VkDescriptorSetLayoutBinding dsl_binding = {};
5163 dsl_binding.binding = 0;
5164 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5165 dsl_binding.descriptorCount = 1;
5166 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5167 dsl_binding.pImmutableSamplers = NULL;
5168
5169 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5170 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5171 ds_layout_ci.pNext = NULL;
5172 ds_layout_ci.bindingCount = 1;
5173 ds_layout_ci.pBindings = &dsl_binding;
5174 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005175 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005176 ASSERT_VK_SUCCESS(err);
5177
5178 VkDescriptorSet descriptorSet;
5179 VkDescriptorSetAllocateInfo alloc_info = {};
5180 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
5181 alloc_info.descriptorSetCount = 1;
5182 alloc_info.descriptorPool = ds_pool;
5183 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005184 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005185 ASSERT_VK_SUCCESS(err);
5186
5187 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5188 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5189 pipeline_layout_ci.pNext = NULL;
5190 pipeline_layout_ci.setLayoutCount = 1;
5191 pipeline_layout_ci.pSetLayouts = &ds_layout;
5192
5193 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005194 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005195 ASSERT_VK_SUCCESS(err);
5196
5197 // Create images to update the descriptor with
5198 VkImage image;
5199 VkImage image2;
5200 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
5201 const int32_t tex_width = 32;
5202 const int32_t tex_height = 32;
5203 VkImageCreateInfo image_create_info = {};
5204 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5205 image_create_info.pNext = NULL;
5206 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5207 image_create_info.format = tex_format;
5208 image_create_info.extent.width = tex_width;
5209 image_create_info.extent.height = tex_height;
5210 image_create_info.extent.depth = 1;
5211 image_create_info.mipLevels = 1;
5212 image_create_info.arrayLayers = 1;
5213 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
5214 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
5215 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
5216 image_create_info.flags = 0;
5217 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
5218 ASSERT_VK_SUCCESS(err);
5219 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image2);
5220 ASSERT_VK_SUCCESS(err);
5221
5222 VkMemoryRequirements memory_reqs;
5223 VkDeviceMemory image_memory;
5224 bool pass;
5225 VkMemoryAllocateInfo memory_info = {};
5226 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5227 memory_info.pNext = NULL;
5228 memory_info.allocationSize = 0;
5229 memory_info.memoryTypeIndex = 0;
5230 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
5231 // Allocate enough memory for both images
5232 memory_info.allocationSize = memory_reqs.size * 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005233 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005234 ASSERT_TRUE(pass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005235 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005236 ASSERT_VK_SUCCESS(err);
5237 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
5238 ASSERT_VK_SUCCESS(err);
5239 // Bind second image to memory right after first image
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005240 err = vkBindImageMemory(m_device->device(), image2, image_memory, memory_reqs.size);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005241 ASSERT_VK_SUCCESS(err);
5242
5243 VkImageViewCreateInfo image_view_create_info = {};
5244 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
5245 image_view_create_info.image = image;
5246 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
5247 image_view_create_info.format = tex_format;
5248 image_view_create_info.subresourceRange.layerCount = 1;
5249 image_view_create_info.subresourceRange.baseMipLevel = 0;
5250 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005251 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005252
5253 VkImageView view;
5254 VkImageView view2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005255 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005256 ASSERT_VK_SUCCESS(err);
5257 image_view_create_info.image = image2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005258 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view2);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005259 ASSERT_VK_SUCCESS(err);
5260 // Create Samplers
5261 VkSamplerCreateInfo sampler_ci = {};
5262 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
5263 sampler_ci.pNext = NULL;
5264 sampler_ci.magFilter = VK_FILTER_NEAREST;
5265 sampler_ci.minFilter = VK_FILTER_NEAREST;
5266 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
5267 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5268 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5269 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5270 sampler_ci.mipLodBias = 1.0;
5271 sampler_ci.anisotropyEnable = VK_FALSE;
5272 sampler_ci.maxAnisotropy = 1;
5273 sampler_ci.compareEnable = VK_FALSE;
5274 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
5275 sampler_ci.minLod = 1.0;
5276 sampler_ci.maxLod = 1.0;
5277 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
5278 sampler_ci.unnormalizedCoordinates = VK_FALSE;
5279 VkSampler sampler;
5280 VkSampler sampler2;
5281 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
5282 ASSERT_VK_SUCCESS(err);
5283 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler2);
5284 ASSERT_VK_SUCCESS(err);
5285 // Update descriptor with image and sampler
5286 VkDescriptorImageInfo img_info = {};
5287 img_info.sampler = sampler;
5288 img_info.imageView = view;
5289 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
5290
5291 VkWriteDescriptorSet descriptor_write;
5292 memset(&descriptor_write, 0, sizeof(descriptor_write));
5293 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5294 descriptor_write.dstSet = descriptorSet;
5295 descriptor_write.dstBinding = 0;
5296 descriptor_write.descriptorCount = 1;
5297 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5298 descriptor_write.pImageInfo = &img_info;
5299
5300 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5301
5302 // Create PSO to be used for draw-time errors below
5303 char const *vsSource = "#version 450\n"
5304 "\n"
5305 "out gl_PerVertex { \n"
5306 " vec4 gl_Position;\n"
5307 "};\n"
5308 "void main(){\n"
5309 " gl_Position = vec4(1);\n"
5310 "}\n";
5311 char const *fsSource = "#version 450\n"
5312 "\n"
5313 "layout(set=0, binding=0) uniform sampler2D s;\n"
5314 "layout(location=0) out vec4 x;\n"
5315 "void main(){\n"
5316 " x = texture(s, vec2(1));\n"
5317 "}\n";
5318 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5319 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5320 VkPipelineObj pipe(m_device);
5321 pipe.AddShader(&vs);
5322 pipe.AddShader(&fs);
5323 pipe.AddColorAttachment();
5324 pipe.CreateVKPipeline(pipeline_layout, renderPass());
5325
5326 // First error case is destroying sampler prior to cmd buffer submission
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005327 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot submit cmd buffer using deleted sampler ");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005328 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005329 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5330 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5331 &descriptorSet, 0, NULL);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005332 Draw(1, 0, 0, 0);
5333 EndCommandBuffer();
5334 // Destroy sampler invalidates the cmd buffer, causing error on submit
5335 vkDestroySampler(m_device->device(), sampler, NULL);
5336 // Attempt to submit cmd buffer
5337 VkSubmitInfo submit_info = {};
5338 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5339 submit_info.commandBufferCount = 1;
5340 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5341 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5342 m_errorMonitor->VerifyFound();
5343 // Now re-update descriptor with valid sampler and delete image
5344 img_info.sampler = sampler2;
5345 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005346 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005347 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005348 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5349 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5350 &descriptorSet, 0, NULL);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005351 Draw(1, 0, 0, 0);
5352 EndCommandBuffer();
5353 // Destroy image invalidates the cmd buffer, causing error on submit
5354 vkDestroyImage(m_device->device(), image, NULL);
5355 // Attempt to submit cmd buffer
5356 submit_info = {};
5357 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5358 submit_info.commandBufferCount = 1;
5359 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5360 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5361 m_errorMonitor->VerifyFound();
5362 // Now update descriptor to be valid, but then free descriptor
5363 img_info.imageView = view2;
5364 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005365 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound descriptor set ");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005366 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005367 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5368 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5369 &descriptorSet, 0, NULL);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005370 Draw(1, 0, 0, 0);
5371 EndCommandBuffer();
5372 // Destroy descriptor set invalidates the cb, causing error on submit
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005373 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot call vkFreeDescriptorSets() on descriptor set 0x");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005374 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
Mark Mueller917f6bc2016-08-30 10:57:19 -06005375 m_errorMonitor->VerifyFound();
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005376 // Attempt to submit cmd buffer
5377 submit_info = {};
5378 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5379 submit_info.commandBufferCount = 1;
5380 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5381 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5382 m_errorMonitor->VerifyFound();
5383 // Cleanup
5384 vkFreeMemory(m_device->device(), image_memory, NULL);
5385 vkDestroySampler(m_device->device(), sampler2, NULL);
5386 vkDestroyImage(m_device->device(), image2, NULL);
5387 vkDestroyImageView(m_device->device(), view, NULL);
5388 vkDestroyImageView(m_device->device(), view2, NULL);
5389 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5390 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5391 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5392}
5393
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06005394TEST_F(VkLayerTest, DescriptorPoolInUseDestroyedSignaled) {
5395 TEST_DESCRIPTION("Delete a DescriptorPool with a DescriptorSet that is in use.");
5396 ASSERT_NO_FATAL_FAILURE(InitState());
5397 ASSERT_NO_FATAL_FAILURE(InitViewport());
5398 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5399
5400 VkDescriptorPoolSize ds_type_count = {};
5401 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5402 ds_type_count.descriptorCount = 1;
5403
5404 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5405 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5406 ds_pool_ci.pNext = NULL;
5407 ds_pool_ci.maxSets = 1;
5408 ds_pool_ci.poolSizeCount = 1;
5409 ds_pool_ci.pPoolSizes = &ds_type_count;
5410
5411 VkDescriptorPool ds_pool;
5412 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
5413 ASSERT_VK_SUCCESS(err);
5414
5415 VkDescriptorSetLayoutBinding dsl_binding = {};
5416 dsl_binding.binding = 0;
5417 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5418 dsl_binding.descriptorCount = 1;
5419 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5420 dsl_binding.pImmutableSamplers = NULL;
5421
5422 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5423 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5424 ds_layout_ci.pNext = NULL;
5425 ds_layout_ci.bindingCount = 1;
5426 ds_layout_ci.pBindings = &dsl_binding;
5427 VkDescriptorSetLayout ds_layout;
5428 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
5429 ASSERT_VK_SUCCESS(err);
5430
5431 VkDescriptorSet descriptor_set;
5432 VkDescriptorSetAllocateInfo alloc_info = {};
5433 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
5434 alloc_info.descriptorSetCount = 1;
5435 alloc_info.descriptorPool = ds_pool;
5436 alloc_info.pSetLayouts = &ds_layout;
5437 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
5438 ASSERT_VK_SUCCESS(err);
5439
5440 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5441 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5442 pipeline_layout_ci.pNext = NULL;
5443 pipeline_layout_ci.setLayoutCount = 1;
5444 pipeline_layout_ci.pSetLayouts = &ds_layout;
5445
5446 VkPipelineLayout pipeline_layout;
5447 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
5448 ASSERT_VK_SUCCESS(err);
5449
5450 // Create image to update the descriptor with
5451 VkImageObj image(m_device);
5452 image.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
5453 ASSERT_TRUE(image.initialized());
5454
5455 VkImageView view = image.targetView(VK_FORMAT_B8G8R8A8_UNORM);
5456 // Create Sampler
5457 VkSamplerCreateInfo sampler_ci = {};
5458 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
5459 sampler_ci.pNext = NULL;
5460 sampler_ci.magFilter = VK_FILTER_NEAREST;
5461 sampler_ci.minFilter = VK_FILTER_NEAREST;
5462 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
5463 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5464 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5465 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5466 sampler_ci.mipLodBias = 1.0;
5467 sampler_ci.anisotropyEnable = VK_FALSE;
5468 sampler_ci.maxAnisotropy = 1;
5469 sampler_ci.compareEnable = VK_FALSE;
5470 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
5471 sampler_ci.minLod = 1.0;
5472 sampler_ci.maxLod = 1.0;
5473 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
5474 sampler_ci.unnormalizedCoordinates = VK_FALSE;
5475 VkSampler sampler;
5476 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
5477 ASSERT_VK_SUCCESS(err);
5478 // Update descriptor with image and sampler
5479 VkDescriptorImageInfo img_info = {};
5480 img_info.sampler = sampler;
5481 img_info.imageView = view;
5482 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
5483
5484 VkWriteDescriptorSet descriptor_write;
5485 memset(&descriptor_write, 0, sizeof(descriptor_write));
5486 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5487 descriptor_write.dstSet = descriptor_set;
5488 descriptor_write.dstBinding = 0;
5489 descriptor_write.descriptorCount = 1;
5490 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5491 descriptor_write.pImageInfo = &img_info;
5492
5493 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5494
5495 // Create PSO to be used for draw-time errors below
5496 char const *vsSource = "#version 450\n"
5497 "\n"
5498 "out gl_PerVertex { \n"
5499 " vec4 gl_Position;\n"
5500 "};\n"
5501 "void main(){\n"
5502 " gl_Position = vec4(1);\n"
5503 "}\n";
5504 char const *fsSource = "#version 450\n"
5505 "\n"
5506 "layout(set=0, binding=0) uniform sampler2D s;\n"
5507 "layout(location=0) out vec4 x;\n"
5508 "void main(){\n"
5509 " x = texture(s, vec2(1));\n"
5510 "}\n";
5511 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5512 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5513 VkPipelineObj pipe(m_device);
5514 pipe.AddShader(&vs);
5515 pipe.AddShader(&fs);
5516 pipe.AddColorAttachment();
5517 pipe.CreateVKPipeline(pipeline_layout, renderPass());
5518
5519 BeginCommandBuffer();
5520 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5521 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5522 &descriptor_set, 0, NULL);
5523 Draw(1, 0, 0, 0);
5524 EndCommandBuffer();
5525 // Submit cmd buffer to put pool in-flight
5526 VkSubmitInfo submit_info = {};
5527 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5528 submit_info.commandBufferCount = 1;
5529 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5530 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5531 // Destroy pool while in-flight, causing error
5532 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete descriptor pool ");
5533 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5534 m_errorMonitor->VerifyFound();
5535 vkQueueWaitIdle(m_device->m_queue);
5536 // Cleanup
5537 vkDestroySampler(m_device->device(), sampler, NULL);
5538 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5539 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5540 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5541}
5542
Tobin Ehlis50a095d2016-09-21 17:32:49 -06005543TEST_F(VkLayerTest, DescriptorImageUpdateNoMemoryBound) {
5544 TEST_DESCRIPTION("Attempt an image descriptor set update where image's bound memory has been freed.");
5545 ASSERT_NO_FATAL_FAILURE(InitState());
5546 ASSERT_NO_FATAL_FAILURE(InitViewport());
5547 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5548
5549 VkDescriptorPoolSize ds_type_count = {};
5550 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5551 ds_type_count.descriptorCount = 1;
5552
5553 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5554 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5555 ds_pool_ci.pNext = NULL;
5556 ds_pool_ci.maxSets = 1;
5557 ds_pool_ci.poolSizeCount = 1;
5558 ds_pool_ci.pPoolSizes = &ds_type_count;
5559
5560 VkDescriptorPool ds_pool;
5561 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
5562 ASSERT_VK_SUCCESS(err);
5563
5564 VkDescriptorSetLayoutBinding dsl_binding = {};
5565 dsl_binding.binding = 0;
5566 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5567 dsl_binding.descriptorCount = 1;
5568 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5569 dsl_binding.pImmutableSamplers = NULL;
5570
5571 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5572 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5573 ds_layout_ci.pNext = NULL;
5574 ds_layout_ci.bindingCount = 1;
5575 ds_layout_ci.pBindings = &dsl_binding;
5576 VkDescriptorSetLayout ds_layout;
5577 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
5578 ASSERT_VK_SUCCESS(err);
5579
5580 VkDescriptorSet descriptorSet;
5581 VkDescriptorSetAllocateInfo alloc_info = {};
5582 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
5583 alloc_info.descriptorSetCount = 1;
5584 alloc_info.descriptorPool = ds_pool;
5585 alloc_info.pSetLayouts = &ds_layout;
5586 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
5587 ASSERT_VK_SUCCESS(err);
5588
5589 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5590 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5591 pipeline_layout_ci.pNext = NULL;
5592 pipeline_layout_ci.setLayoutCount = 1;
5593 pipeline_layout_ci.pSetLayouts = &ds_layout;
5594
5595 VkPipelineLayout pipeline_layout;
5596 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
5597 ASSERT_VK_SUCCESS(err);
5598
5599 // Create images to update the descriptor with
5600 VkImage image;
5601 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
5602 const int32_t tex_width = 32;
5603 const int32_t tex_height = 32;
5604 VkImageCreateInfo image_create_info = {};
5605 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5606 image_create_info.pNext = NULL;
5607 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5608 image_create_info.format = tex_format;
5609 image_create_info.extent.width = tex_width;
5610 image_create_info.extent.height = tex_height;
5611 image_create_info.extent.depth = 1;
5612 image_create_info.mipLevels = 1;
5613 image_create_info.arrayLayers = 1;
5614 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
5615 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
5616 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
5617 image_create_info.flags = 0;
5618 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
5619 ASSERT_VK_SUCCESS(err);
5620 // Initially bind memory to avoid error at bind view time. We'll break binding before update.
5621 VkMemoryRequirements memory_reqs;
5622 VkDeviceMemory image_memory;
5623 bool pass;
5624 VkMemoryAllocateInfo memory_info = {};
5625 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5626 memory_info.pNext = NULL;
5627 memory_info.allocationSize = 0;
5628 memory_info.memoryTypeIndex = 0;
5629 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
5630 // Allocate enough memory for image
5631 memory_info.allocationSize = memory_reqs.size;
5632 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
5633 ASSERT_TRUE(pass);
5634 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
5635 ASSERT_VK_SUCCESS(err);
5636 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
5637 ASSERT_VK_SUCCESS(err);
5638
5639 VkImageViewCreateInfo image_view_create_info = {};
5640 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
5641 image_view_create_info.image = image;
5642 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
5643 image_view_create_info.format = tex_format;
5644 image_view_create_info.subresourceRange.layerCount = 1;
5645 image_view_create_info.subresourceRange.baseMipLevel = 0;
5646 image_view_create_info.subresourceRange.levelCount = 1;
5647 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
5648
5649 VkImageView view;
5650 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
5651 ASSERT_VK_SUCCESS(err);
5652 // Create Samplers
5653 VkSamplerCreateInfo sampler_ci = {};
5654 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
5655 sampler_ci.pNext = NULL;
5656 sampler_ci.magFilter = VK_FILTER_NEAREST;
5657 sampler_ci.minFilter = VK_FILTER_NEAREST;
5658 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
5659 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5660 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5661 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5662 sampler_ci.mipLodBias = 1.0;
5663 sampler_ci.anisotropyEnable = VK_FALSE;
5664 sampler_ci.maxAnisotropy = 1;
5665 sampler_ci.compareEnable = VK_FALSE;
5666 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
5667 sampler_ci.minLod = 1.0;
5668 sampler_ci.maxLod = 1.0;
5669 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
5670 sampler_ci.unnormalizedCoordinates = VK_FALSE;
5671 VkSampler sampler;
5672 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
5673 ASSERT_VK_SUCCESS(err);
5674 // Update descriptor with image and sampler
5675 VkDescriptorImageInfo img_info = {};
5676 img_info.sampler = sampler;
5677 img_info.imageView = view;
5678 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
5679
5680 VkWriteDescriptorSet descriptor_write;
5681 memset(&descriptor_write, 0, sizeof(descriptor_write));
5682 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5683 descriptor_write.dstSet = descriptorSet;
5684 descriptor_write.dstBinding = 0;
5685 descriptor_write.descriptorCount = 1;
5686 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5687 descriptor_write.pImageInfo = &img_info;
5688 // Break memory binding and attempt update
5689 vkFreeMemory(m_device->device(), image_memory, nullptr);
5690 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06005691 " previously bound memory was freed. Memory must not be freed prior to this operation.");
Tobin Ehlis50a095d2016-09-21 17:32:49 -06005692 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
5693 "vkUpdateDescriptorsSets() failed write update validation for Descriptor Set 0x");
5694 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5695 m_errorMonitor->VerifyFound();
5696 // Cleanup
5697 vkDestroyImage(m_device->device(), image, NULL);
5698 vkDestroySampler(m_device->device(), sampler, NULL);
5699 vkDestroyImageView(m_device->device(), view, NULL);
5700 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5701 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5702 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5703}
5704
Karl Schultz6addd812016-02-02 17:17:23 -07005705TEST_F(VkLayerTest, InvalidPipeline) {
Karl Schultzbdb75952016-04-19 11:36:49 -06005706 // Attempt to bind an invalid Pipeline to a valid Command Buffer
5707 // ObjectTracker should catch this.
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06005708 // Create a valid cmd buffer
5709 // call vkCmdBindPipeline w/ false Pipeline
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06005710 uint64_t fake_pipeline_handle = 0xbaad6001;
5711 VkPipeline bad_pipeline = reinterpret_cast<VkPipeline &>(fake_pipeline_handle);
Karl Schultzbdb75952016-04-19 11:36:49 -06005712 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes4dbf70f2016-09-16 17:58:00 +12005713 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5714
Karl Schultzf78bcdd2016-11-30 12:36:01 -07005715 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00601);
Karl Schultzbdb75952016-04-19 11:36:49 -06005716 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005717 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, bad_pipeline);
Karl Schultzbdb75952016-04-19 11:36:49 -06005718 m_errorMonitor->VerifyFound();
Chris Forbes4dbf70f2016-09-16 17:58:00 +12005719
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06005720 // Now issue a draw call with no pipeline bound
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005721 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 -06005722 Draw(1, 0, 0, 0);
5723 m_errorMonitor->VerifyFound();
Chris Forbes4dbf70f2016-09-16 17:58:00 +12005724
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06005725 // Finally same check once more but with Dispatch/Compute
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005726 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 +12005727 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle()); // must be outside renderpass
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06005728 vkCmdDispatch(m_commandBuffer->GetBufferHandle(), 0, 0, 0);
5729 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06005730}
5731
Karl Schultz6addd812016-02-02 17:17:23 -07005732TEST_F(VkLayerTest, DescriptorSetNotUpdated) {
Tobin Ehlis5a5f5ef2016-08-17 13:56:55 -06005733 TEST_DESCRIPTION("Bind a descriptor set that hasn't been updated.");
Karl Schultz6addd812016-02-02 17:17:23 -07005734 VkResult err;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005735
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005736 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, " bound but it was never updated. ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005737
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005738 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyan713b2d72015-08-04 10:49:29 -06005739 ASSERT_NO_FATAL_FAILURE(InitViewport());
5740 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08005741 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005742 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5743 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06005744
5745 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005746 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5747 ds_pool_ci.pNext = NULL;
5748 ds_pool_ci.maxSets = 1;
5749 ds_pool_ci.poolSizeCount = 1;
5750 ds_pool_ci.pPoolSizes = &ds_type_count;
Mike Stroyan713b2d72015-08-04 10:49:29 -06005751
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005752 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005753 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005754 ASSERT_VK_SUCCESS(err);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005755
Tony Barboureb254902015-07-15 12:50:33 -06005756 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005757 dsl_binding.binding = 0;
5758 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5759 dsl_binding.descriptorCount = 1;
5760 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5761 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005762
Tony Barboureb254902015-07-15 12:50:33 -06005763 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005764 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5765 ds_layout_ci.pNext = NULL;
5766 ds_layout_ci.bindingCount = 1;
5767 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005768 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005769 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005770 ASSERT_VK_SUCCESS(err);
5771
5772 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005773 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08005774 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07005775 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06005776 alloc_info.descriptorPool = ds_pool;
5777 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005778 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005779 ASSERT_VK_SUCCESS(err);
5780
Tony Barboureb254902015-07-15 12:50:33 -06005781 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005782 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5783 pipeline_layout_ci.pNext = NULL;
5784 pipeline_layout_ci.setLayoutCount = 1;
5785 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005786
5787 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005788 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005789 ASSERT_VK_SUCCESS(err);
5790
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005791 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -06005792 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -07005793 // on more devices
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005794 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005795
Tony Barbourc95e4ac2015-08-04 17:05:26 -06005796 VkPipelineObj pipe(m_device);
5797 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06005798 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -06005799 pipe.AddColorAttachment();
Tony Barbourc95e4ac2015-08-04 17:05:26 -06005800 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06005801
5802 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005803 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5804 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5805 &descriptorSet, 0, NULL);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005806
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005807 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06005808
Chia-I Wuf7458c52015-10-26 21:10:41 +08005809 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5810 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5811 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06005812}
5813
Karl Schultz6addd812016-02-02 17:17:23 -07005814TEST_F(VkLayerTest, InvalidBufferViewObject) {
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005815 // Create a single TEXEL_BUFFER descriptor and send it an invalid bufferView
Karl Schultz6addd812016-02-02 17:17:23 -07005816 VkResult err;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005817
Karl Schultzf78bcdd2016-11-30 12:36:01 -07005818 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00940);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005819
5820 ASSERT_NO_FATAL_FAILURE(InitState());
5821 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005822 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
5823 ds_type_count.descriptorCount = 1;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005824
5825 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005826 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5827 ds_pool_ci.pNext = NULL;
5828 ds_pool_ci.maxSets = 1;
5829 ds_pool_ci.poolSizeCount = 1;
5830 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005831
5832 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005833 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005834 ASSERT_VK_SUCCESS(err);
5835
5836 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005837 dsl_binding.binding = 0;
5838 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
5839 dsl_binding.descriptorCount = 1;
5840 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5841 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005842
5843 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005844 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5845 ds_layout_ci.pNext = NULL;
5846 ds_layout_ci.bindingCount = 1;
5847 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005848 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005849 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005850 ASSERT_VK_SUCCESS(err);
5851
5852 VkDescriptorSet descriptorSet;
5853 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08005854 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07005855 alloc_info.descriptorSetCount = 1;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005856 alloc_info.descriptorPool = ds_pool;
5857 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005858 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005859 ASSERT_VK_SUCCESS(err);
5860
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005861 VkBufferView view = (VkBufferView)((size_t)0xbaadbeef); // invalid bufferView object
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005862 VkWriteDescriptorSet descriptor_write;
5863 memset(&descriptor_write, 0, sizeof(descriptor_write));
5864 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5865 descriptor_write.dstSet = descriptorSet;
5866 descriptor_write.dstBinding = 0;
5867 descriptor_write.descriptorCount = 1;
5868 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
5869 descriptor_write.pTexelBufferView = &view;
5870
5871 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5872
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005873 m_errorMonitor->VerifyFound();
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005874
5875 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5876 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5877}
5878
Mark Youngd339ba32016-05-30 13:28:35 -06005879TEST_F(VkLayerTest, CreateBufferViewNoMemoryBoundToBuffer) {
Tobin Ehlis4ff58172016-09-22 10:52:00 -06005880 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 -06005881
5882 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -06005883 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06005884 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Mark Youngd339ba32016-05-30 13:28:35 -06005885
5886 ASSERT_NO_FATAL_FAILURE(InitState());
5887
5888 // Create a buffer with no bound memory and then attempt to create
5889 // a buffer view.
5890 VkBufferCreateInfo buff_ci = {};
5891 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes4538d242016-09-13 18:13:58 +12005892 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT;
Mark Youngd339ba32016-05-30 13:28:35 -06005893 buff_ci.size = 256;
5894 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
5895 VkBuffer buffer;
5896 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
5897 ASSERT_VK_SUCCESS(err);
5898
5899 VkBufferViewCreateInfo buff_view_ci = {};
5900 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
5901 buff_view_ci.buffer = buffer;
5902 buff_view_ci.format = VK_FORMAT_R8_UNORM;
5903 buff_view_ci.range = VK_WHOLE_SIZE;
5904 VkBufferView buff_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005905 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buff_view);
Mark Youngd339ba32016-05-30 13:28:35 -06005906
5907 m_errorMonitor->VerifyFound();
5908 vkDestroyBuffer(m_device->device(), buffer, NULL);
5909 // If last error is success, it still created the view, so delete it.
5910 if (err == VK_SUCCESS) {
5911 vkDestroyBufferView(m_device->device(), buff_view, NULL);
5912 }
5913}
5914
Karl Schultz6addd812016-02-02 17:17:23 -07005915TEST_F(VkLayerTest, InvalidDynamicOffsetCases) {
5916 // Create a descriptorSet w/ dynamic descriptor and then hit 3 offset error
5917 // cases:
Tobin Ehlisf6585052015-12-17 11:48:42 -07005918 // 1. No dynamicOffset supplied
5919 // 2. Too many dynamicOffsets supplied
5920 // 3. Dynamic offset oversteps buffer being updated
Karl Schultz6addd812016-02-02 17:17:23 -07005921 VkResult err;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005922 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " requires 1 dynamicOffsets, but only "
5923 "0 dynamicOffsets are left in "
5924 "pDynamicOffsets ");
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005925
5926 ASSERT_NO_FATAL_FAILURE(InitState());
5927 ASSERT_NO_FATAL_FAILURE(InitViewport());
5928 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5929
5930 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005931 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
5932 ds_type_count.descriptorCount = 1;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005933
5934 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005935 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5936 ds_pool_ci.pNext = NULL;
5937 ds_pool_ci.maxSets = 1;
5938 ds_pool_ci.poolSizeCount = 1;
5939 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005940
5941 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005942 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005943 ASSERT_VK_SUCCESS(err);
5944
5945 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005946 dsl_binding.binding = 0;
5947 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
5948 dsl_binding.descriptorCount = 1;
5949 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5950 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005951
5952 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005953 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5954 ds_layout_ci.pNext = NULL;
5955 ds_layout_ci.bindingCount = 1;
5956 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005957 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005958 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005959 ASSERT_VK_SUCCESS(err);
5960
5961 VkDescriptorSet descriptorSet;
5962 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08005963 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07005964 alloc_info.descriptorSetCount = 1;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005965 alloc_info.descriptorPool = ds_pool;
5966 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005967 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005968 ASSERT_VK_SUCCESS(err);
5969
5970 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005971 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5972 pipeline_layout_ci.pNext = NULL;
5973 pipeline_layout_ci.setLayoutCount = 1;
5974 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005975
5976 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005977 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005978 ASSERT_VK_SUCCESS(err);
5979
5980 // Create a buffer to update the descriptor with
5981 uint32_t qfi = 0;
5982 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005983 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
5984 buffCI.size = 1024;
5985 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
5986 buffCI.queueFamilyIndexCount = 1;
5987 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005988
5989 VkBuffer dyub;
5990 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
5991 ASSERT_VK_SUCCESS(err);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06005992 // Allocate memory and bind to buffer so we can make it to the appropriate
5993 // error
5994 VkMemoryAllocateInfo mem_alloc = {};
5995 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5996 mem_alloc.pNext = NULL;
5997 mem_alloc.allocationSize = 1024;
Chris Forbesb6116cc2016-05-08 11:39:59 +12005998 mem_alloc.memoryTypeIndex = 0;
5999
6000 VkMemoryRequirements memReqs;
6001 vkGetBufferMemoryRequirements(m_device->device(), dyub, &memReqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006002 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
Chris Forbesb6116cc2016-05-08 11:39:59 +12006003 if (!pass) {
6004 vkDestroyBuffer(m_device->device(), dyub, NULL);
6005 return;
6006 }
6007
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06006008 VkDeviceMemory mem;
6009 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
6010 ASSERT_VK_SUCCESS(err);
6011 err = vkBindBufferMemory(m_device->device(), dyub, mem, 0);
6012 ASSERT_VK_SUCCESS(err);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006013 // Correctly update descriptor to avoid "NOT_UPDATED" error
6014 VkDescriptorBufferInfo buffInfo = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006015 buffInfo.buffer = dyub;
6016 buffInfo.offset = 0;
6017 buffInfo.range = 1024;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006018
6019 VkWriteDescriptorSet descriptor_write;
6020 memset(&descriptor_write, 0, sizeof(descriptor_write));
6021 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6022 descriptor_write.dstSet = descriptorSet;
6023 descriptor_write.dstBinding = 0;
6024 descriptor_write.descriptorCount = 1;
6025 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6026 descriptor_write.pBufferInfo = &buffInfo;
6027
6028 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6029
6030 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006031 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6032 &descriptorSet, 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006033 m_errorMonitor->VerifyFound();
Tobin Ehlisf6585052015-12-17 11:48:42 -07006034 uint32_t pDynOff[2] = {512, 756};
6035 // Now cause error b/c too many dynOffsets in array for # of dyn descriptors
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006036 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6037 "Attempting to bind 1 descriptorSets with 1 dynamic descriptors, but ");
6038 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6039 &descriptorSet, 2, pDynOff);
Chris Forbes7b342802016-04-07 13:20:10 +12006040 m_errorMonitor->VerifyFound();
Tobin Ehlisf6585052015-12-17 11:48:42 -07006041 // Finally cause error due to dynamicOffset being too big
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006042 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " dynamic offset 512 combined with "
6043 "offset 0 and range 1024 that "
6044 "oversteps the buffer size of 1024");
Tobin Ehlisf6585052015-12-17 11:48:42 -07006045 // Create PSO to be used for draw-time errors below
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006046 char const *vsSource = "#version 450\n"
6047 "\n"
6048 "out gl_PerVertex { \n"
6049 " vec4 gl_Position;\n"
6050 "};\n"
6051 "void main(){\n"
6052 " gl_Position = vec4(1);\n"
6053 "}\n";
6054 char const *fsSource = "#version 450\n"
6055 "\n"
6056 "layout(location=0) out vec4 x;\n"
6057 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
6058 "void main(){\n"
6059 " x = vec4(bar.y);\n"
6060 "}\n";
Tobin Ehlisf6585052015-12-17 11:48:42 -07006061 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
6062 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
6063 VkPipelineObj pipe(m_device);
6064 pipe.AddShader(&vs);
6065 pipe.AddShader(&fs);
6066 pipe.AddColorAttachment();
6067 pipe.CreateVKPipeline(pipeline_layout, renderPass());
6068
Rene Lindsayacbf5e62016-12-15 18:47:11 -07006069 VkViewport viewport = {0, 0, 16, 16, 0, 1};
6070 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
6071 VkRect2D scissor = {{0, 0}, {16, 16}};
6072 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
6073
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006074 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07006075 // This update should succeed, but offset size of 512 will overstep buffer
6076 // /w range 1024 & size 1024
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006077 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6078 &descriptorSet, 1, pDynOff);
Tobin Ehlisf6585052015-12-17 11:48:42 -07006079 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006080 m_errorMonitor->VerifyFound();
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006081
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06006082 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tobin Ehlis512098e2016-05-05 09:06:12 -06006083 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06006084
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006085 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06006086 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006087 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6088}
6089
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006090TEST_F(VkLayerTest, DescriptorBufferUpdateNoMemoryBound) {
6091 TEST_DESCRIPTION("Attempt to update a descriptor with a non-sparse buffer "
6092 "that doesn't have memory bound");
6093 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -06006094 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06006095 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Tobin Ehlisfed999f2016-09-21 15:09:45 -06006096 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6097 "vkUpdateDescriptorsSets() failed write update validation for Descriptor Set 0x");
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006098
6099 ASSERT_NO_FATAL_FAILURE(InitState());
6100 ASSERT_NO_FATAL_FAILURE(InitViewport());
6101 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6102
6103 VkDescriptorPoolSize ds_type_count = {};
6104 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6105 ds_type_count.descriptorCount = 1;
6106
6107 VkDescriptorPoolCreateInfo ds_pool_ci = {};
6108 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6109 ds_pool_ci.pNext = NULL;
6110 ds_pool_ci.maxSets = 1;
6111 ds_pool_ci.poolSizeCount = 1;
6112 ds_pool_ci.pPoolSizes = &ds_type_count;
6113
6114 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006115 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006116 ASSERT_VK_SUCCESS(err);
6117
6118 VkDescriptorSetLayoutBinding dsl_binding = {};
6119 dsl_binding.binding = 0;
6120 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6121 dsl_binding.descriptorCount = 1;
6122 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6123 dsl_binding.pImmutableSamplers = NULL;
6124
6125 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
6126 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6127 ds_layout_ci.pNext = NULL;
6128 ds_layout_ci.bindingCount = 1;
6129 ds_layout_ci.pBindings = &dsl_binding;
6130 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006131 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006132 ASSERT_VK_SUCCESS(err);
6133
6134 VkDescriptorSet descriptorSet;
6135 VkDescriptorSetAllocateInfo alloc_info = {};
6136 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
6137 alloc_info.descriptorSetCount = 1;
6138 alloc_info.descriptorPool = ds_pool;
6139 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006140 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006141 ASSERT_VK_SUCCESS(err);
6142
6143 // Create a buffer to update the descriptor with
6144 uint32_t qfi = 0;
6145 VkBufferCreateInfo buffCI = {};
6146 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
6147 buffCI.size = 1024;
6148 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
6149 buffCI.queueFamilyIndexCount = 1;
6150 buffCI.pQueueFamilyIndices = &qfi;
6151
6152 VkBuffer dyub;
6153 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
6154 ASSERT_VK_SUCCESS(err);
6155
6156 // Attempt to update descriptor without binding memory to it
6157 VkDescriptorBufferInfo buffInfo = {};
6158 buffInfo.buffer = dyub;
6159 buffInfo.offset = 0;
6160 buffInfo.range = 1024;
6161
6162 VkWriteDescriptorSet descriptor_write;
6163 memset(&descriptor_write, 0, sizeof(descriptor_write));
6164 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6165 descriptor_write.dstSet = descriptorSet;
6166 descriptor_write.dstBinding = 0;
6167 descriptor_write.descriptorCount = 1;
6168 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6169 descriptor_write.pBufferInfo = &buffInfo;
6170
6171 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6172 m_errorMonitor->VerifyFound();
6173
6174 vkDestroyBuffer(m_device->device(), dyub, NULL);
6175 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6176 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6177}
6178
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006179TEST_F(VkLayerTest, InvalidPushConstants) {
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006180 VkResult err;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006181 ASSERT_NO_FATAL_FAILURE(InitState());
6182 ASSERT_NO_FATAL_FAILURE(InitViewport());
6183 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6184
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006185 VkPipelineLayout pipeline_layout;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006186 VkPushConstantRange pc_range = {};
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006187 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
6188 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6189 pipeline_layout_ci.pushConstantRangeCount = 1;
6190 pipeline_layout_ci.pPushConstantRanges = &pc_range;
6191
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006192 //
6193 // Check for invalid push constant ranges in pipeline layouts.
6194 //
6195 struct PipelineLayoutTestCase {
Karl Schultzc81037d2016-05-12 08:11:23 -06006196 VkPushConstantRange const range;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006197 char const *msg;
6198 };
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006199
Karl Schultzc81037d2016-05-12 08:11:23 -06006200 const uint32_t too_big = m_device->props.limits.maxPushConstantsSize + 0x4;
6201 const std::array<PipelineLayoutTestCase, 10> range_tests = {{
6202 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 0},
6203 "vkCreatePipelineLayout() call has push constants index 0 with "
6204 "size 0."},
6205 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 1},
6206 "vkCreatePipelineLayout() call has push constants index 0 with "
6207 "size 1."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006208 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 1},
Karl Schultzc81037d2016-05-12 08:11:23 -06006209 "vkCreatePipelineLayout() call has push constants index 0 with "
6210 "size 1."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006211 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 0},
Karl Schultzc81037d2016-05-12 08:11:23 -06006212 "vkCreatePipelineLayout() call has push constants index 0 with "
6213 "size 0."},
6214 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
6215 "vkCreatePipelineLayout() call has push constants index 0 with "
6216 "offset 1. Offset must"},
6217 {{VK_SHADER_STAGE_VERTEX_BIT, 0, too_big},
6218 "vkCreatePipelineLayout() call has push constants index 0 "
6219 "with offset "},
6220 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, too_big},
6221 "vkCreatePipelineLayout() call has push constants "
6222 "index 0 with offset "},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006223 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, 4},
Karl Schultzc81037d2016-05-12 08:11:23 -06006224 "vkCreatePipelineLayout() call has push constants index 0 "
6225 "with offset "},
6226 {{VK_SHADER_STAGE_VERTEX_BIT, 0xFFFFFFF0, 0x00000020},
6227 "vkCreatePipelineLayout() call has push "
6228 "constants index 0 with offset "},
6229 {{VK_SHADER_STAGE_VERTEX_BIT, 0x00000020, 0xFFFFFFF0},
6230 "vkCreatePipelineLayout() call has push "
6231 "constants index 0 with offset "},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006232 }};
6233
6234 // Check for invalid offset and size
Karl Schultzc81037d2016-05-12 08:11:23 -06006235 for (const auto &iter : range_tests) {
6236 pc_range = iter.range;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006237 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
6238 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006239 m_errorMonitor->VerifyFound();
6240 if (VK_SUCCESS == err) {
6241 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6242 }
6243 }
6244
6245 // Check for invalid stage flag
6246 pc_range.offset = 0;
6247 pc_range.size = 16;
6248 pc_range.stageFlags = 0;
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006249 m_errorMonitor->SetDesiredFailureMsg(
6250 VK_DEBUG_REPORT_ERROR_BIT_EXT,
6251 "vkCreatePipelineLayout: value of pCreateInfo->pPushConstantRanges[0].stageFlags must not be 0");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006252 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006253 m_errorMonitor->VerifyFound();
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006254 if (VK_SUCCESS == err) {
6255 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6256 }
6257
6258 // Check for overlapping ranges
Karl Schultzc81037d2016-05-12 08:11:23 -06006259 const uint32_t ranges_per_test = 5;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006260 struct OverlappingRangeTestCase {
Karl Schultzc81037d2016-05-12 08:11:23 -06006261 VkPushConstantRange const ranges[ranges_per_test];
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006262 char const *msg;
6263 };
6264
Karl Schultzc81037d2016-05-12 08:11:23 -06006265 const std::array<OverlappingRangeTestCase, 5> overlapping_range_tests = {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006266 {{{{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6267 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6268 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6269 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6270 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006271 "vkCreatePipelineLayout() call has push constants with overlapping ranges:"},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006272 {
6273 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6274 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
6275 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
6276 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
6277 {VK_SHADER_STAGE_VERTEX_BIT, 16, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006278 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 3:[12, 20), 4:[16, 20)",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006279 },
6280 {
6281 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
6282 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
6283 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
6284 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
6285 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006286 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 0:[16, 20), 1:[12, 20)",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006287 },
6288 {
6289 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
6290 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
6291 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
6292 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
6293 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006294 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 0:[16, 20), 3:[12, 20)",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006295 },
6296 {
6297 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
6298 {VK_SHADER_STAGE_VERTEX_BIT, 32, 4},
6299 {VK_SHADER_STAGE_VERTEX_BIT, 4, 96},
6300 {VK_SHADER_STAGE_VERTEX_BIT, 40, 8},
6301 {VK_SHADER_STAGE_VERTEX_BIT, 52, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006302 "vkCreatePipelineLayout() call has push constants with overlapping ranges:",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006303 }}};
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006304
Karl Schultzc81037d2016-05-12 08:11:23 -06006305 for (const auto &iter : overlapping_range_tests) {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006306 pipeline_layout_ci.pPushConstantRanges = iter.ranges;
Karl Schultzc81037d2016-05-12 08:11:23 -06006307 pipeline_layout_ci.pushConstantRangeCount = ranges_per_test;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006308 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, iter.msg);
6309 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006310 m_errorMonitor->VerifyFound();
6311 if (VK_SUCCESS == err) {
6312 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6313 }
6314 }
6315
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006316 //
6317 // CmdPushConstants tests
6318 //
Karl Schultzc81037d2016-05-12 08:11:23 -06006319 const uint8_t dummy_values[100] = {};
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006320
6321 // Check for invalid offset and size and if range is within layout range(s)
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006322 const std::array<PipelineLayoutTestCase, 11> cmd_range_tests = {{
6323 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 0}, "vkCmdPushConstants: parameter size must be greater than 0"},
Karl Schultzc81037d2016-05-12 08:11:23 -06006324 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 1},
6325 "vkCmdPushConstants() call has push constants with size 1. Size "
6326 "must be greater than zero and a multiple of 4."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006327 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 1},
Karl Schultzc81037d2016-05-12 08:11:23 -06006328 "vkCmdPushConstants() call has push constants with size 1. Size "
6329 "must be greater than zero and a multiple of 4."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006330 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
Karl Schultzc81037d2016-05-12 08:11:23 -06006331 "vkCmdPushConstants() call has push constants with offset 1. "
6332 "Offset must be a multiple of 4."},
6333 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
6334 "vkCmdPushConstants() call has push constants with offset 1. "
6335 "Offset must be a multiple of 4."},
6336 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 20},
6337 "vkCmdPushConstants() Push constant range [0, 20) with stageFlags = "
6338 "0x1 not within flag-matching ranges in pipeline layout"},
6339 {{VK_SHADER_STAGE_VERTEX_BIT, 60, 8},
6340 "vkCmdPushConstants() Push constant range [60, 68) with stageFlags = "
6341 "0x1 not within flag-matching ranges in pipeline layout"},
6342 {{VK_SHADER_STAGE_VERTEX_BIT, 76, 8},
6343 "vkCmdPushConstants() Push constant range [76, 84) with stageFlags = "
6344 "0x1 not within flag-matching ranges in pipeline layout"},
6345 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 80},
6346 "vkCmdPushConstants() Push constant range [0, 80) with stageFlags = "
6347 "0x1 not within flag-matching ranges in pipeline layout"},
6348 {{VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, 0, 4},
6349 "vkCmdPushConstants() stageFlags = 0x2 do not match the stageFlags in "
6350 "any of the ranges in pipeline layout"},
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006351 {{VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, 0, 16},
Karl Schultzc81037d2016-05-12 08:11:23 -06006352 "vkCmdPushConstants() stageFlags = 0x3 do not match the stageFlags in "
6353 "any of the ranges in pipeline layout"},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006354 }};
6355
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006356 BeginCommandBuffer();
6357
6358 // Setup ranges: [0,16) [64,80)
Karl Schultzc81037d2016-05-12 08:11:23 -06006359 const VkPushConstantRange pc_range2[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006360 {VK_SHADER_STAGE_VERTEX_BIT, 64, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 0, 16},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006361 };
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006362 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range2) / sizeof(VkPushConstantRange);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006363 pipeline_layout_ci.pPushConstantRanges = pc_range2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006364 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006365 ASSERT_VK_SUCCESS(err);
Karl Schultzc81037d2016-05-12 08:11:23 -06006366 for (const auto &iter : cmd_range_tests) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006367 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
6368 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.range.stageFlags, iter.range.offset,
Karl Schultzc81037d2016-05-12 08:11:23 -06006369 iter.range.size, dummy_values);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006370 m_errorMonitor->VerifyFound();
6371 }
6372
6373 // Check for invalid stage flag
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006374 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdPushConstants: value of stageFlags must not be 0");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006375 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, 0, 0, 16, dummy_values);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006376 m_errorMonitor->VerifyFound();
Karl Schultzc81037d2016-05-12 08:11:23 -06006377 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006378
Karl Schultzc81037d2016-05-12 08:11:23 -06006379 // overlapping range tests with cmd
6380 const std::array<PipelineLayoutTestCase, 3> cmd_overlap_tests = {{
6381 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 20},
6382 "vkCmdPushConstants() Push constant range [0, 20) with stageFlags = "
6383 "0x1 not within flag-matching ranges in pipeline layout"},
6384 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
6385 "vkCmdPushConstants() Push constant range [16, 20) with stageFlags = "
6386 "0x1 not within flag-matching ranges in pipeline layout"},
6387 {{VK_SHADER_STAGE_VERTEX_BIT, 40, 16},
6388 "vkCmdPushConstants() Push constant range [40, 56) with stageFlags = "
6389 "0x1 not within flag-matching ranges in pipeline layout"},
6390 }};
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006391 // Setup ranges: [0,16), [20,36), [36,44), [44,52), [80,92)
Karl Schultzc81037d2016-05-12 08:11:23 -06006392 const VkPushConstantRange pc_range3[] = {
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006393 {VK_SHADER_STAGE_VERTEX_BIT, 20, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 0, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 44, 8},
6394 {VK_SHADER_STAGE_VERTEX_BIT, 80, 12}, {VK_SHADER_STAGE_VERTEX_BIT, 36, 8},
Karl Schultzc81037d2016-05-12 08:11:23 -06006395 };
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006396 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range3) / sizeof(VkPushConstantRange);
Karl Schultzc81037d2016-05-12 08:11:23 -06006397 pipeline_layout_ci.pPushConstantRanges = pc_range3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006398 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzc81037d2016-05-12 08:11:23 -06006399 ASSERT_VK_SUCCESS(err);
Karl Schultzc81037d2016-05-12 08:11:23 -06006400 for (const auto &iter : cmd_overlap_tests) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006401 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
6402 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.range.stageFlags, iter.range.offset,
Karl Schultzc81037d2016-05-12 08:11:23 -06006403 iter.range.size, dummy_values);
6404 m_errorMonitor->VerifyFound();
6405 }
Karl Schultzc81037d2016-05-12 08:11:23 -06006406 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6407
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006408 EndCommandBuffer();
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006409}
6410
Karl Schultz6addd812016-02-02 17:17:23 -07006411TEST_F(VkLayerTest, DescriptorSetCompatibility) {
Tobin Ehlis559c6382015-11-05 09:52:49 -07006412 // Test various desriptorSet errors with bad binding combinations
Karl Schultz6addd812016-02-02 17:17:23 -07006413 VkResult err;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006414
6415 ASSERT_NO_FATAL_FAILURE(InitState());
6416 ASSERT_NO_FATAL_FAILURE(InitViewport());
6417 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6418
Mike Stroyanb8a61002016-06-20 16:00:28 -06006419 const VkFormat tex_format = VK_FORMAT_R8G8B8A8_UNORM;
6420 VkImageTiling tiling;
6421 VkFormatProperties format_properties;
6422 vkGetPhysicalDeviceFormatProperties(gpu(), tex_format, &format_properties);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006423 if (format_properties.linearTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
Mike Stroyanb8a61002016-06-20 16:00:28 -06006424 tiling = VK_IMAGE_TILING_LINEAR;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006425 } else if (format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
Mike Stroyanb8a61002016-06-20 16:00:28 -06006426 tiling = VK_IMAGE_TILING_OPTIMAL;
6427 } else {
6428 printf("Device does not support VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT; "
6429 "skipped.\n");
6430 return;
6431 }
6432
Tobin Ehlis559c6382015-11-05 09:52:49 -07006433 static const uint32_t NUM_DESCRIPTOR_TYPES = 5;
6434 VkDescriptorPoolSize ds_type_count[NUM_DESCRIPTOR_TYPES] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006435 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6436 ds_type_count[0].descriptorCount = 10;
6437 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
6438 ds_type_count[1].descriptorCount = 2;
6439 ds_type_count[2].type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
6440 ds_type_count[2].descriptorCount = 2;
6441 ds_type_count[3].type = VK_DESCRIPTOR_TYPE_SAMPLER;
6442 ds_type_count[3].descriptorCount = 5;
6443 // TODO : LunarG ILO driver currently asserts in desc.c w/ INPUT_ATTACHMENT
6444 // type
6445 // ds_type_count[4].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
6446 ds_type_count[4].type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
6447 ds_type_count[4].descriptorCount = 2;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006448
6449 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006450 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6451 ds_pool_ci.pNext = NULL;
6452 ds_pool_ci.maxSets = 5;
6453 ds_pool_ci.poolSizeCount = NUM_DESCRIPTOR_TYPES;
6454 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006455
6456 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006457 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006458 ASSERT_VK_SUCCESS(err);
6459
6460 static const uint32_t MAX_DS_TYPES_IN_LAYOUT = 2;
6461 VkDescriptorSetLayoutBinding dsl_binding[MAX_DS_TYPES_IN_LAYOUT] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006462 dsl_binding[0].binding = 0;
6463 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6464 dsl_binding[0].descriptorCount = 5;
6465 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
6466 dsl_binding[0].pImmutableSamplers = NULL;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006467
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006468 // Create layout identical to set0 layout but w/ different stageFlags
6469 VkDescriptorSetLayoutBinding dsl_fs_stage_only = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006470 dsl_fs_stage_only.binding = 0;
6471 dsl_fs_stage_only.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6472 dsl_fs_stage_only.descriptorCount = 5;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006473 dsl_fs_stage_only.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT; // Different stageFlags to cause error at
6474 // bind time
Karl Schultz6addd812016-02-02 17:17:23 -07006475 dsl_fs_stage_only.pImmutableSamplers = NULL;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006476 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006477 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6478 ds_layout_ci.pNext = NULL;
6479 ds_layout_ci.bindingCount = 1;
6480 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006481 static const uint32_t NUM_LAYOUTS = 4;
6482 VkDescriptorSetLayout ds_layout[NUM_LAYOUTS] = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006483 VkDescriptorSetLayout ds_layout_fs_only = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006484 // Create 4 unique layouts for full pipelineLayout, and 1 special fs-only
6485 // layout for error case
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006486 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[0]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006487 ASSERT_VK_SUCCESS(err);
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07006488 ds_layout_ci.pBindings = &dsl_fs_stage_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006489 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006490 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006491 dsl_binding[0].binding = 0;
6492 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006493 dsl_binding[0].descriptorCount = 2;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07006494 dsl_binding[1].binding = 1;
6495 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
6496 dsl_binding[1].descriptorCount = 2;
6497 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
6498 dsl_binding[1].pImmutableSamplers = NULL;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07006499 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006500 ds_layout_ci.bindingCount = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006501 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[1]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006502 ASSERT_VK_SUCCESS(err);
6503 dsl_binding[0].binding = 0;
6504 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006505 dsl_binding[0].descriptorCount = 5;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006506 ds_layout_ci.bindingCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006507 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[2]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006508 ASSERT_VK_SUCCESS(err);
6509 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006510 dsl_binding[0].descriptorCount = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006511 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[3]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006512 ASSERT_VK_SUCCESS(err);
6513
6514 static const uint32_t NUM_SETS = 4;
6515 VkDescriptorSet descriptorSet[NUM_SETS] = {};
6516 VkDescriptorSetAllocateInfo alloc_info = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006517 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006518 alloc_info.descriptorSetCount = NUM_LAYOUTS;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006519 alloc_info.descriptorPool = ds_pool;
6520 alloc_info.pSetLayouts = ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006521 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptorSet);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006522 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006523 VkDescriptorSet ds0_fs_only = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07006524 alloc_info.descriptorSetCount = 1;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006525 alloc_info.pSetLayouts = &ds_layout_fs_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006526 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &ds0_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006527 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006528
6529 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006530 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6531 pipeline_layout_ci.pNext = NULL;
6532 pipeline_layout_ci.setLayoutCount = NUM_LAYOUTS;
6533 pipeline_layout_ci.pSetLayouts = ds_layout;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006534
6535 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006536 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006537 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006538 // Create pipelineLayout with only one setLayout
6539 pipeline_layout_ci.setLayoutCount = 1;
6540 VkPipelineLayout single_pipe_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006541 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &single_pipe_layout);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006542 ASSERT_VK_SUCCESS(err);
6543 // Create pipelineLayout with 2 descriptor setLayout at index 0
6544 pipeline_layout_ci.pSetLayouts = &ds_layout[3];
6545 VkPipelineLayout pipe_layout_one_desc;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006546 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_one_desc);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006547 ASSERT_VK_SUCCESS(err);
6548 // Create pipelineLayout with 5 SAMPLER descriptor setLayout at index 0
6549 pipeline_layout_ci.pSetLayouts = &ds_layout[2];
6550 VkPipelineLayout pipe_layout_five_samp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006551 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_five_samp);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006552 ASSERT_VK_SUCCESS(err);
6553 // Create pipelineLayout with UB type, but stageFlags for FS only
6554 pipeline_layout_ci.pSetLayouts = &ds_layout_fs_only;
6555 VkPipelineLayout pipe_layout_fs_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006556 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006557 ASSERT_VK_SUCCESS(err);
6558 // Create pipelineLayout w/ incompatible set0 layout, but set1 is fine
6559 VkDescriptorSetLayout pl_bad_s0[2] = {};
6560 pl_bad_s0[0] = ds_layout_fs_only;
6561 pl_bad_s0[1] = ds_layout[1];
6562 pipeline_layout_ci.setLayoutCount = 2;
6563 pipeline_layout_ci.pSetLayouts = pl_bad_s0;
6564 VkPipelineLayout pipe_layout_bad_set0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006565 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_bad_set0);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006566 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006567
6568 // Create a buffer to update the descriptor with
6569 uint32_t qfi = 0;
6570 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006571 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
6572 buffCI.size = 1024;
6573 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
6574 buffCI.queueFamilyIndexCount = 1;
6575 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006576
6577 VkBuffer dyub;
6578 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
6579 ASSERT_VK_SUCCESS(err);
6580 // Correctly update descriptor to avoid "NOT_UPDATED" error
6581 static const uint32_t NUM_BUFFS = 5;
6582 VkDescriptorBufferInfo buffInfo[NUM_BUFFS] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006583 for (uint32_t i = 0; i < NUM_BUFFS; ++i) {
Tobin Ehlis559c6382015-11-05 09:52:49 -07006584 buffInfo[i].buffer = dyub;
6585 buffInfo[i].offset = 0;
6586 buffInfo[i].range = 1024;
6587 }
Karl Schultz6addd812016-02-02 17:17:23 -07006588 VkImage image;
Karl Schultz6addd812016-02-02 17:17:23 -07006589 const int32_t tex_width = 32;
6590 const int32_t tex_height = 32;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006591 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006592 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
6593 image_create_info.pNext = NULL;
6594 image_create_info.imageType = VK_IMAGE_TYPE_2D;
6595 image_create_info.format = tex_format;
6596 image_create_info.extent.width = tex_width;
6597 image_create_info.extent.height = tex_height;
6598 image_create_info.extent.depth = 1;
6599 image_create_info.mipLevels = 1;
6600 image_create_info.arrayLayers = 1;
6601 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyanb8a61002016-06-20 16:00:28 -06006602 image_create_info.tiling = tiling;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006603 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_STORAGE_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -07006604 image_create_info.flags = 0;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006605 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
6606 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006607
Karl Schultz6addd812016-02-02 17:17:23 -07006608 VkMemoryRequirements memReqs;
6609 VkDeviceMemory imageMem;
6610 bool pass;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07006611 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006612 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
6613 memAlloc.pNext = NULL;
6614 memAlloc.allocationSize = 0;
6615 memAlloc.memoryTypeIndex = 0;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07006616 vkGetImageMemoryRequirements(m_device->device(), image, &memReqs);
6617 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006618 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07006619 ASSERT_TRUE(pass);
6620 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &imageMem);
6621 ASSERT_VK_SUCCESS(err);
6622 err = vkBindImageMemory(m_device->device(), image, imageMem, 0);
6623 ASSERT_VK_SUCCESS(err);
6624
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006625 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006626 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
6627 image_view_create_info.image = image;
6628 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
6629 image_view_create_info.format = tex_format;
6630 image_view_create_info.subresourceRange.layerCount = 1;
6631 image_view_create_info.subresourceRange.baseMipLevel = 0;
6632 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006633 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006634
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006635 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006636 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006637 ASSERT_VK_SUCCESS(err);
Tobin Ehlis991d45a2016-01-06 08:48:41 -07006638 VkDescriptorImageInfo imageInfo[4] = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006639 imageInfo[0].imageView = view;
6640 imageInfo[0].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
6641 imageInfo[1].imageView = view;
6642 imageInfo[1].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
Tobin Ehlis991d45a2016-01-06 08:48:41 -07006643 imageInfo[2].imageView = view;
Tobin Ehlisa1fccbc2016-10-10 14:54:43 -06006644 imageInfo[2].imageLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis991d45a2016-01-06 08:48:41 -07006645 imageInfo[3].imageView = view;
Tobin Ehlisa1fccbc2016-10-10 14:54:43 -06006646 imageInfo[3].imageLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006647
6648 static const uint32_t NUM_SET_UPDATES = 3;
6649 VkWriteDescriptorSet descriptor_write[NUM_SET_UPDATES] = {};
6650 descriptor_write[0].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6651 descriptor_write[0].dstSet = descriptorSet[0];
6652 descriptor_write[0].dstBinding = 0;
6653 descriptor_write[0].descriptorCount = 5;
6654 descriptor_write[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6655 descriptor_write[0].pBufferInfo = buffInfo;
6656 descriptor_write[1].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6657 descriptor_write[1].dstSet = descriptorSet[1];
6658 descriptor_write[1].dstBinding = 0;
6659 descriptor_write[1].descriptorCount = 2;
6660 descriptor_write[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
6661 descriptor_write[1].pImageInfo = imageInfo;
6662 descriptor_write[2].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6663 descriptor_write[2].dstSet = descriptorSet[1];
6664 descriptor_write[2].dstBinding = 1;
6665 descriptor_write[2].descriptorCount = 2;
6666 descriptor_write[2].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
Tobin Ehlis991d45a2016-01-06 08:48:41 -07006667 descriptor_write[2].pImageInfo = &imageInfo[2];
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006668
6669 vkUpdateDescriptorSets(m_device->device(), 3, descriptor_write, 0, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006670
Tobin Ehlis88452832015-12-03 09:40:56 -07006671 // Create PSO to be used for draw-time errors below
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006672 char const *vsSource = "#version 450\n"
6673 "\n"
6674 "out gl_PerVertex {\n"
6675 " vec4 gl_Position;\n"
6676 "};\n"
6677 "void main(){\n"
6678 " gl_Position = vec4(1);\n"
6679 "}\n";
6680 char const *fsSource = "#version 450\n"
6681 "\n"
6682 "layout(location=0) out vec4 x;\n"
6683 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
6684 "void main(){\n"
6685 " x = vec4(bar.y);\n"
6686 "}\n";
Tobin Ehlis88452832015-12-03 09:40:56 -07006687 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
6688 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006689 VkPipelineObj pipe(m_device);
6690 pipe.AddShader(&vs);
6691 pipe.AddShader(&fs);
Tobin Ehlis88452832015-12-03 09:40:56 -07006692 pipe.AddColorAttachment();
6693 pipe.CreateVKPipeline(pipe_layout_fs_only, renderPass());
Tobin Ehlis559c6382015-11-05 09:52:49 -07006694
6695 BeginCommandBuffer();
Tobin Ehlis88452832015-12-03 09:40:56 -07006696
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006697 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07006698 // NOTE : I believe LunarG ilo driver has bug (LX#189) that requires binding
6699 // of PSO
6700 // here before binding DSs. Otherwise we assert in cmd_copy_dset_data() of
6701 // cmd_pipeline.c
6702 // due to the fact that cmd_alloc_dset_data() has not been called in
6703 // cmd_bind_graphics_pipeline()
6704 // TODO : Want to cause various binding incompatibility issues here to test
6705 // DrawState
Tobin Ehlis559c6382015-11-05 09:52:49 -07006706 // First cause various verify_layout_compatibility() fails
6707 // Second disturb early and late sets and verify INFO msgs
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006708 // verify_set_layout_compatibility fail cases:
6709 // 1. invalid VkPipelineLayout (layout) passed into vkCmdBindDescriptorSets
Karl Schultzf78bcdd2016-11-30 12:36:01 -07006710 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00981);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006711 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS,
6712 (VkPipelineLayout)((size_t)0xbaadb1be), 0, 1, &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006713 m_errorMonitor->VerifyFound();
6714
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006715 // 2. layoutIndex exceeds # of layouts in layout
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006716 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " attempting to bind set to index 1");
6717 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, single_pipe_layout, 0, 2,
6718 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006719 m_errorMonitor->VerifyFound();
6720
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006721 vkDestroyPipelineLayout(m_device->device(), single_pipe_layout, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07006722 // 3. Pipeline setLayout[0] has 2 descriptors, but set being bound has 5
6723 // descriptors
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006724 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has 2 descriptors, but DescriptorSetLayout ");
6725 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_one_desc, 0, 1,
6726 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006727 m_errorMonitor->VerifyFound();
6728
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006729 vkDestroyPipelineLayout(m_device->device(), pipe_layout_one_desc, NULL);
6730 // 4. same # of descriptors but mismatch in type
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006731 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is type 'VK_DESCRIPTOR_TYPE_SAMPLER' but binding ");
6732 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_five_samp, 0, 1,
6733 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006734 m_errorMonitor->VerifyFound();
6735
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006736 vkDestroyPipelineLayout(m_device->device(), pipe_layout_five_samp, NULL);
6737 // 5. same # of descriptors but mismatch in stageFlags
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006738 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6739 " has stageFlags 16 but binding 0 for DescriptorSetLayout ");
6740 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_fs_only, 0, 1,
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 // Cause INFO messages due to disturbing previously bound Sets
6745 // First bind sets 0 & 1
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006746 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
6747 &descriptorSet[0], 0, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006748 // 1. Disturb bound set0 by re-binding set1 w/ updated pipelineLayout
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006749 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, " previously bound as set #0 was disturbed ");
6750 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_bad_set0, 1, 1,
6751 &descriptorSet[1], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006752 m_errorMonitor->VerifyFound();
6753
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006754 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
6755 &descriptorSet[0], 0, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006756 // 2. Disturb set after last bound set
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006757 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, " newly bound as set #0 so set #1 and "
6758 "any subsequent sets were disturbed ");
6759 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_fs_only, 0, 1,
6760 &ds0_fs_only, 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006761 m_errorMonitor->VerifyFound();
6762
Tobin Ehlis10fad692016-07-07 12:00:36 -06006763 // Now that we're done actively using the pipelineLayout that gfx pipeline
6764 // was created with, we should be able to delete it. Do that now to verify
6765 // that validation obeys pipelineLayout lifetime
6766 vkDestroyPipelineLayout(m_device->device(), pipe_layout_fs_only, NULL);
6767
Tobin Ehlis88452832015-12-03 09:40:56 -07006768 // Cause draw-time errors due to PSO incompatibilities
Karl Schultz6addd812016-02-02 17:17:23 -07006769 // 1. Error due to not binding required set (we actually use same code as
6770 // above to disturb set0)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006771 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
6772 &descriptorSet[0], 0, NULL);
6773 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_bad_set0, 1, 1,
6774 &descriptorSet[1], 0, NULL);
6775 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 -07006776 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006777 m_errorMonitor->VerifyFound();
6778
Tobin Ehlis991d45a2016-01-06 08:48:41 -07006779 vkDestroyPipelineLayout(m_device->device(), pipe_layout_bad_set0, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07006780 // 2. Error due to bound set not being compatible with PSO's
6781 // VkPipelineLayout (diff stageFlags in this case)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006782 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
6783 &descriptorSet[0], 0, NULL);
6784 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " bound as set #0 is not compatible with ");
Tobin Ehlis88452832015-12-03 09:40:56 -07006785 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006786 m_errorMonitor->VerifyFound();
6787
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006788 // Remaining clean-up
Karl Schultz6addd812016-02-02 17:17:23 -07006789 for (uint32_t i = 0; i < NUM_LAYOUTS; ++i) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006790 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout[i], NULL);
6791 }
6792 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_fs_only, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006793 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006794 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6795 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06006796 vkFreeMemory(m_device->device(), imageMem, NULL);
6797 vkDestroyImage(m_device->device(), image, NULL);
6798 vkDestroyImageView(m_device->device(), view, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006799}
Tobin Ehlis559c6382015-11-05 09:52:49 -07006800
Karl Schultz6addd812016-02-02 17:17:23 -07006801TEST_F(VkLayerTest, NoBeginCommandBuffer) {
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006802
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006803 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6804 "You must call vkBeginCommandBuffer() before this call to ");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006805
6806 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006807 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006808 // Call EndCommandBuffer() w/o calling BeginCommandBuffer()
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006809 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006810
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006811 m_errorMonitor->VerifyFound();
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006812}
6813
Karl Schultz6addd812016-02-02 17:17:23 -07006814TEST_F(VkLayerTest, SecondaryCommandBufferNullRenderpass) {
6815 VkResult err;
6816 VkCommandBuffer draw_cmd;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006817
Karl Schultzf78bcdd2016-11-30 12:36:01 -07006818 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00110);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006819
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006820 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006821
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006822 VkCommandBufferAllocateInfo cmd = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006823 cmd.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06006824 cmd.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006825 cmd.commandPool = m_commandPool;
6826 cmd.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006827 cmd.commandBufferCount = 1;
Cody Northropb4569702015-08-04 17:35:57 -06006828
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006829 err = vkAllocateCommandBuffers(m_device->device(), &cmd, &draw_cmd);
Mike Stroyand1c84a52015-08-18 14:40:24 -06006830 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006831
6832 // Force the failure by not setting the Renderpass and Framebuffer fields
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006833 VkCommandBufferBeginInfo cmd_buf_info = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07006834 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006835 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06006836 cmd_buf_info.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006837 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 -07006838 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006839
6840 // The error should be caught by validation of the BeginCommandBuffer call
6841 vkBeginCommandBuffer(draw_cmd, &cmd_buf_info);
6842
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006843 m_errorMonitor->VerifyFound();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006844 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &draw_cmd);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006845}
6846
Karl Schultz6addd812016-02-02 17:17:23 -07006847TEST_F(VkLayerTest, CommandBufferResetErrors) {
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006848 // Cause error due to Begin while recording CB
6849 // Then cause 2 errors for attempting to reset CB w/o having
6850 // VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT set for the pool from
6851 // which CBs were allocated. Note that this bit is off by default.
Mike Weiblencce7ec72016-10-17 19:33:05 -06006852 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot call Begin on command buffer");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006853
6854 ASSERT_NO_FATAL_FAILURE(InitState());
6855
6856 // Calls AllocateCommandBuffers
6857 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
6858
Karl Schultz6addd812016-02-02 17:17:23 -07006859 // Force the failure by setting the Renderpass and Framebuffer fields with
6860 // (fake) data
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006861 VkCommandBufferBeginInfo cmd_buf_info = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07006862 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006863 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
6864 cmd_buf_info.pNext = NULL;
6865 cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006866 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006867
6868 // Begin CB to transition to recording state
6869 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
6870 // Can't re-begin. This should trigger error
6871 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006872 m_errorMonitor->VerifyFound();
6873
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006874 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to reset command buffer ");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006875 VkCommandBufferResetFlags flags = 0; // Don't care about flags for this test
6876 // Reset attempt will trigger error due to incorrect CommandPool state
6877 vkResetCommandBuffer(commandBuffer.GetBufferHandle(), flags);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006878 m_errorMonitor->VerifyFound();
6879
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006880 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " attempts to implicitly reset cmdBuffer created from ");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006881 // Transition CB to RECORDED state
6882 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
6883 // Now attempting to Begin will implicitly reset, which triggers error
6884 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006885 m_errorMonitor->VerifyFound();
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006886}
6887
Karl Schultz6addd812016-02-02 17:17:23 -07006888TEST_F(VkLayerTest, InvalidPipelineCreateState) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006889 // Attempt to Create Gfx Pipeline w/o a VS
Karl Schultz6addd812016-02-02 17:17:23 -07006890 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006891
Mike Weiblencce7ec72016-10-17 19:33:05 -06006892 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Pipeline CreateInfo State: Vertex Shader required");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006893
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006894 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06006895 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinski209b5292015-09-17 09:44:05 -06006896
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006897 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006898 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6899 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06006900
6901 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006902 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6903 ds_pool_ci.pNext = NULL;
6904 ds_pool_ci.maxSets = 1;
6905 ds_pool_ci.poolSizeCount = 1;
6906 ds_pool_ci.pPoolSizes = &ds_type_count;
Mark Lobodzinski209b5292015-09-17 09:44:05 -06006907
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006908 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006909 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006910 ASSERT_VK_SUCCESS(err);
6911
Tony Barboureb254902015-07-15 12:50:33 -06006912 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006913 dsl_binding.binding = 0;
6914 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6915 dsl_binding.descriptorCount = 1;
6916 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6917 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006918
Tony Barboureb254902015-07-15 12:50:33 -06006919 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006920 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6921 ds_layout_ci.pNext = NULL;
6922 ds_layout_ci.bindingCount = 1;
6923 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06006924
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006925 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006926 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006927 ASSERT_VK_SUCCESS(err);
6928
6929 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006930 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006931 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006932 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06006933 alloc_info.descriptorPool = ds_pool;
6934 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006935 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006936 ASSERT_VK_SUCCESS(err);
6937
Tony Barboureb254902015-07-15 12:50:33 -06006938 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006939 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6940 pipeline_layout_ci.setLayoutCount = 1;
6941 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006942
6943 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006944 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006945 ASSERT_VK_SUCCESS(err);
6946
Tobin Ehlise68360f2015-10-01 11:15:13 -06006947 VkViewport vp = {}; // Just need dummy vp to point to
Karl Schultz6addd812016-02-02 17:17:23 -07006948 VkRect2D sc = {}; // dummy scissor to point to
Tobin Ehlise68360f2015-10-01 11:15:13 -06006949
6950 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006951 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
6952 vp_state_ci.scissorCount = 1;
6953 vp_state_ci.pScissors = &sc;
6954 vp_state_ci.viewportCount = 1;
6955 vp_state_ci.pViewports = &vp;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006956
Karl Schultzdfdb8d42016-03-08 10:30:21 -07006957 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
6958 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
6959 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
6960 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
6961 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
6962 rs_state_ci.depthClampEnable = VK_FALSE;
6963 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
6964 rs_state_ci.depthBiasEnable = VK_FALSE;
6965
Tony Barboureb254902015-07-15 12:50:33 -06006966 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006967 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
6968 gp_ci.pViewportState = &vp_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07006969 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07006970 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
6971 gp_ci.layout = pipeline_layout;
6972 gp_ci.renderPass = renderPass();
Tony Barboureb254902015-07-15 12:50:33 -06006973
6974 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006975 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
6976 pc_ci.initialDataSize = 0;
6977 pc_ci.pInitialData = 0;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006978
6979 VkPipeline pipeline;
Jon Ashburnc669cc62015-07-09 15:02:25 -06006980 VkPipelineCache pipelineCache;
6981
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006982 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Jon Ashburnc669cc62015-07-09 15:02:25 -06006983 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006984 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006985
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006986 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06006987
Chia-I Wuf7458c52015-10-26 21:10:41 +08006988 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
6989 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6990 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6991 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006992}
Tobin Ehlis912df022015-09-17 08:46:18 -06006993/*// TODO : This test should be good, but needs Tess support in compiler to run
6994TEST_F(VkLayerTest, InvalidPatchControlPoints)
6995{
6996 // Attempt to Create Gfx Pipeline w/o a VS
Tobin Ehlis912df022015-09-17 08:46:18 -06006997 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006998
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07006999 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07007000 "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH
7001primitive ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007002
Tobin Ehlis912df022015-09-17 08:46:18 -06007003 ASSERT_NO_FATAL_FAILURE(InitState());
7004 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis912df022015-09-17 08:46:18 -06007005
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007006 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlis912df022015-09-17 08:46:18 -06007007 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007008 ds_type_count.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06007009
7010 VkDescriptorPoolCreateInfo ds_pool_ci = {};
7011 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7012 ds_pool_ci.pNext = NULL;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007013 ds_pool_ci.poolSizeCount = 1;
7014 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis912df022015-09-17 08:46:18 -06007015
7016 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07007017 err = vkCreateDescriptorPool(m_device->device(),
7018VK_DESCRIPTOR_POOL_USAGE_NON_FREE, 1, &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis912df022015-09-17 08:46:18 -06007019 ASSERT_VK_SUCCESS(err);
7020
7021 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08007022 dsl_binding.binding = 0;
Tobin Ehlis912df022015-09-17 08:46:18 -06007023 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08007024 dsl_binding.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06007025 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7026 dsl_binding.pImmutableSamplers = NULL;
7027
7028 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007029 ds_layout_ci.sType =
7030VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06007031 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007032 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07007033 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis912df022015-09-17 08:46:18 -06007034
7035 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007036 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
7037&ds_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06007038 ASSERT_VK_SUCCESS(err);
7039
7040 VkDescriptorSet descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -07007041 err = vkAllocateDescriptorSets(m_device->device(), ds_pool,
7042VK_DESCRIPTOR_SET_USAGE_NON_FREE, 1, &ds_layout, &descriptorSet);
Tobin Ehlis912df022015-09-17 08:46:18 -06007043 ASSERT_VK_SUCCESS(err);
7044
7045 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007046 pipeline_layout_ci.sType =
7047VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06007048 pipeline_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007049 pipeline_layout_ci.setLayoutCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06007050 pipeline_layout_ci.pSetLayouts = &ds_layout;
7051
7052 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007053 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
7054&pipeline_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06007055 ASSERT_VK_SUCCESS(err);
7056
7057 VkPipelineShaderStageCreateInfo shaderStages[3];
7058 memset(&shaderStages, 0, 3 * sizeof(VkPipelineShaderStageCreateInfo));
7059
Karl Schultz6addd812016-02-02 17:17:23 -07007060 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT,
7061this);
Tobin Ehlis912df022015-09-17 08:46:18 -06007062 // Just using VS txt for Tess shaders as we don't care about functionality
Karl Schultz6addd812016-02-02 17:17:23 -07007063 VkShaderObj
7064tc(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT,
7065this);
7066 VkShaderObj
7067te(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT,
7068this);
Tobin Ehlis912df022015-09-17 08:46:18 -06007069
Karl Schultz6addd812016-02-02 17:17:23 -07007070 shaderStages[0].sType =
7071VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06007072 shaderStages[0].stage = VK_SHADER_STAGE_VERTEX_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06007073 shaderStages[0].shader = vs.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07007074 shaderStages[1].sType =
7075VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06007076 shaderStages[1].stage = VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06007077 shaderStages[1].shader = tc.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07007078 shaderStages[2].sType =
7079VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06007080 shaderStages[2].stage = VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06007081 shaderStages[2].shader = te.handle();
7082
7083 VkPipelineInputAssemblyStateCreateInfo iaCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007084 iaCI.sType =
7085VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
Chia-I Wu515eb8f2015-10-31 00:31:16 +08007086 iaCI.topology = VK_PRIMITIVE_TOPOLOGY_PATCH_LIST;
Tobin Ehlis912df022015-09-17 08:46:18 -06007087
7088 VkPipelineTessellationStateCreateInfo tsCI = {};
7089 tsCI.sType = VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO;
7090 tsCI.patchControlPoints = 0; // This will cause an error
7091
7092 VkGraphicsPipelineCreateInfo gp_ci = {};
7093 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7094 gp_ci.pNext = NULL;
7095 gp_ci.stageCount = 3;
7096 gp_ci.pStages = shaderStages;
7097 gp_ci.pVertexInputState = NULL;
7098 gp_ci.pInputAssemblyState = &iaCI;
7099 gp_ci.pTessellationState = &tsCI;
7100 gp_ci.pViewportState = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007101 gp_ci.pRasterizationState = NULL;
Tobin Ehlis912df022015-09-17 08:46:18 -06007102 gp_ci.pMultisampleState = NULL;
7103 gp_ci.pDepthStencilState = NULL;
7104 gp_ci.pColorBlendState = NULL;
7105 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7106 gp_ci.layout = pipeline_layout;
7107 gp_ci.renderPass = renderPass();
7108
7109 VkPipelineCacheCreateInfo pc_ci = {};
7110 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
7111 pc_ci.pNext = NULL;
7112 pc_ci.initialSize = 0;
7113 pc_ci.initialData = 0;
7114 pc_ci.maxSize = 0;
7115
7116 VkPipeline pipeline;
7117 VkPipelineCache pipelineCache;
7118
Karl Schultz6addd812016-02-02 17:17:23 -07007119 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL,
7120&pipelineCache);
Tobin Ehlis912df022015-09-17 08:46:18 -06007121 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07007122 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
7123&gp_ci, NULL, &pipeline);
Tobin Ehlis912df022015-09-17 08:46:18 -06007124
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007125 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06007126
Chia-I Wuf7458c52015-10-26 21:10:41 +08007127 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7128 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7129 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7130 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis912df022015-09-17 08:46:18 -06007131}
7132*/
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007133
Mark Lobodzinski510aa5c2016-12-19 07:59:10 -07007134TEST_F(VkLayerTest, PSOViewportScissorCountTests) {
Karl Schultz6addd812016-02-02 17:17:23 -07007135 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007136
Mark Lobodzinski510aa5c2016-12-19 07:59:10 -07007137 TEST_DESCRIPTION("Test various cases of viewport and scissor count validation");
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007138
Tobin Ehlise68360f2015-10-01 11:15:13 -06007139 ASSERT_NO_FATAL_FAILURE(InitState());
7140 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06007141
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007142 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007143 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7144 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007145
7146 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007147 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7148 ds_pool_ci.maxSets = 1;
7149 ds_pool_ci.poolSizeCount = 1;
7150 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007151
7152 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007153 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007154 ASSERT_VK_SUCCESS(err);
7155
7156 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007157 dsl_binding.binding = 0;
7158 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7159 dsl_binding.descriptorCount = 1;
7160 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007161
7162 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007163 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7164 ds_layout_ci.bindingCount = 1;
7165 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007166
7167 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007168 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007169 ASSERT_VK_SUCCESS(err);
7170
7171 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007172 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007173 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007174 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007175 alloc_info.descriptorPool = ds_pool;
7176 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007177 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007178 ASSERT_VK_SUCCESS(err);
7179
7180 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007181 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7182 pipeline_layout_ci.setLayoutCount = 1;
7183 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007184
7185 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007186 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007187 ASSERT_VK_SUCCESS(err);
7188
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007189 VkViewport vp = {};
Tobin Ehlise68360f2015-10-01 11:15:13 -06007190 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007191 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
Mark Lobodzinski510aa5c2016-12-19 07:59:10 -07007192 vp_state_ci.scissorCount = 1;
Mark Lobodzinskif0eab4a2016-12-19 08:43:21 -07007193 vp_state_ci.viewportCount = 1;
Karl Schultz6addd812016-02-02 17:17:23 -07007194 vp_state_ci.pViewports = &vp;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007195
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007196 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
7197 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7198 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
7199 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
7200 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
7201 rs_state_ci.depthClampEnable = VK_FALSE;
7202 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
7203 rs_state_ci.depthBiasEnable = VK_FALSE;
7204
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007205 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7206 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7207 vi_ci.pNext = nullptr;
7208 vi_ci.vertexBindingDescriptionCount = 0;
7209 vi_ci.pVertexBindingDescriptions = nullptr;
7210 vi_ci.vertexAttributeDescriptionCount = 0;
7211 vi_ci.pVertexAttributeDescriptions = nullptr;
7212
7213 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7214 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7215 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7216
7217 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
7218 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
7219 pipe_ms_state_ci.pNext = NULL;
7220 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
7221 pipe_ms_state_ci.sampleShadingEnable = 0;
7222 pipe_ms_state_ci.minSampleShading = 1.0;
7223 pipe_ms_state_ci.pSampleMask = NULL;
7224
Cody Northropeb3a6c12015-10-05 14:44:45 -06007225 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07007226 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06007227
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007228 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinskid04c7862016-12-16 13:17:49 -07007229 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chia-I Wu28e06912015-10-31 00:31:16 +08007230 shaderStages[0] = vs.GetStageCreateInfo();
7231 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007232
7233 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007234 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7235 gp_ci.stageCount = 2;
7236 gp_ci.pStages = shaderStages;
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007237 gp_ci.pVertexInputState = &vi_ci;
7238 gp_ci.pInputAssemblyState = &ia_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007239 gp_ci.pViewportState = &vp_state_ci;
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007240 gp_ci.pMultisampleState = &pipe_ms_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007241 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007242 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7243 gp_ci.layout = pipeline_layout;
7244 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007245
7246 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007247 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007248
7249 VkPipeline pipeline;
7250 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007251 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007252 ASSERT_VK_SUCCESS(err);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007253
Mark Lobodzinskif0eab4a2016-12-19 08:43:21 -07007254 if (!m_device->phy().features().multiViewport) {
7255 printf("MultiViewport feature is disabled -- skipping enabled-state checks.\n");
7256
7257 // Check case where multiViewport is disabled and viewport count is not 1
7258 // We check scissor/viewport simultaneously since separating them would trigger the mismatch error, 1434.
7259 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01430);
7260 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01431);
7261 vp_state_ci.scissorCount = 0;
7262 vp_state_ci.viewportCount = 0;
7263 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
7264 m_errorMonitor->VerifyFound();
7265 } else {
7266 if (m_device->props.limits.maxViewports == 1) {
7267 printf("Device limit maxViewports is 1, skipping tests that require higher limits.\n");
7268 } else {
7269 printf("MultiViewport feature is enabled -- skipping disabled-state checks.\n");
7270
7271 // Check is that viewportcount and scissorcount match
7272 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01434);
7273 vp_state_ci.scissorCount = 1;
7274 vp_state_ci.viewportCount = m_device->props.limits.maxViewports;
7275 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
7276 m_errorMonitor->VerifyFound();
7277
7278
7279 // Check case where multiViewport is enabled and viewport count is greater than max
7280 // We check scissor/viewport simultaneously since separating them would trigger the mismatch error, 1434.
7281 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01432);
7282 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01433);
7283 vp_state_ci.scissorCount = m_device->props.limits.maxViewports + 1;
7284 vp_state_ci.viewportCount = m_device->props.limits.maxViewports + 1;
7285 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
7286 m_errorMonitor->VerifyFound();
7287 }
7288 }
Tobin Ehlise68360f2015-10-01 11:15:13 -06007289
Chia-I Wuf7458c52015-10-26 21:10:41 +08007290 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7291 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7292 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7293 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007294}
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007295
7296// 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
7297// set dynamically.
Karl Schultz6addd812016-02-02 17:17:23 -07007298TEST_F(VkLayerTest, PSOViewportStateNotSet) {
Karl Schultz6addd812016-02-02 17:17:23 -07007299 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007300
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007301 TEST_DESCRIPTION("Create a graphics pipeline with rasterization enabled but no viewport state.");
7302
Mark Lobodzinskid04c7862016-12-16 13:17:49 -07007303 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02113);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007304
Tobin Ehlise68360f2015-10-01 11:15:13 -06007305 ASSERT_NO_FATAL_FAILURE(InitState());
7306 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06007307
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007308 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007309 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7310 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007311
7312 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007313 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7314 ds_pool_ci.maxSets = 1;
7315 ds_pool_ci.poolSizeCount = 1;
7316 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007317
7318 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007319 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007320 ASSERT_VK_SUCCESS(err);
7321
7322 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007323 dsl_binding.binding = 0;
7324 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7325 dsl_binding.descriptorCount = 1;
7326 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007327
7328 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007329 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7330 ds_layout_ci.bindingCount = 1;
7331 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007332
7333 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007334 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007335 ASSERT_VK_SUCCESS(err);
7336
7337 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007338 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007339 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007340 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007341 alloc_info.descriptorPool = ds_pool;
7342 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007343 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007344 ASSERT_VK_SUCCESS(err);
7345
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007346 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7347 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7348 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7349
7350 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7351 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7352 vi_ci.pNext = nullptr;
7353 vi_ci.vertexBindingDescriptionCount = 0;
7354 vi_ci.pVertexBindingDescriptions = nullptr;
7355 vi_ci.vertexAttributeDescriptionCount = 0;
7356 vi_ci.pVertexAttributeDescriptions = nullptr;
7357
7358 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
7359 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
7360 pipe_ms_state_ci.pNext = NULL;
7361 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
7362 pipe_ms_state_ci.sampleShadingEnable = 0;
7363 pipe_ms_state_ci.minSampleShading = 1.0;
7364 pipe_ms_state_ci.pSampleMask = NULL;
7365
Tobin Ehlise68360f2015-10-01 11:15:13 -06007366 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007367 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7368 pipeline_layout_ci.setLayoutCount = 1;
7369 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007370
7371 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007372 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007373 ASSERT_VK_SUCCESS(err);
7374
7375 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
7376 // Set scissor as dynamic to avoid second error
7377 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007378 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
7379 dyn_state_ci.dynamicStateCount = 1;
7380 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007381
Cody Northropeb3a6c12015-10-05 14:44:45 -06007382 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07007383 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06007384
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007385 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007386 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
7387 // 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 +08007388 shaderStages[0] = vs.GetStageCreateInfo();
7389 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007390
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007391 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
7392 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7393 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
7394 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
7395 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
7396 rs_state_ci.depthClampEnable = VK_FALSE;
7397 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
7398 rs_state_ci.depthBiasEnable = VK_FALSE;
7399
Tobin Ehlise68360f2015-10-01 11:15:13 -06007400 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007401 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7402 gp_ci.stageCount = 2;
7403 gp_ci.pStages = shaderStages;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007404 gp_ci.pRasterizationState = &rs_state_ci;
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007405 // Not setting VP state w/o dynamic vp state should cause validation error
7406 gp_ci.pViewportState = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -07007407 gp_ci.pDynamicState = &dyn_state_ci;
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007408 gp_ci.pVertexInputState = &vi_ci;
7409 gp_ci.pInputAssemblyState = &ia_ci;
7410 gp_ci.pMultisampleState = &pipe_ms_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007411 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7412 gp_ci.layout = pipeline_layout;
7413 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007414
7415 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007416 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007417
7418 VkPipeline pipeline;
7419 VkPipelineCache pipelineCache;
7420
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007421 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007422 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007423 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007424
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007425 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007426
Chia-I Wuf7458c52015-10-26 21:10:41 +08007427 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7428 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7429 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7430 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007431}
Mark Lobodzinski73169e22016-12-16 14:01:17 -07007432
7433// Create PSO w/o non-zero viewportCount but no viewport data, then run second test where dynamic scissor count doesn't match PSO
7434// scissor count
Karl Schultz6addd812016-02-02 17:17:23 -07007435TEST_F(VkLayerTest, PSOViewportCountWithoutDataAndDynScissorMismatch) {
7436 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007437
Mark Lobodzinskid04c7862016-12-16 13:17:49 -07007438 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02110);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007439
Tobin Ehlise68360f2015-10-01 11:15:13 -06007440 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007441
7442 if (!m_device->phy().features().multiViewport) {
7443 printf("Device does not support multiple viewports/scissors; skipped.\n");
7444 return;
7445 }
7446
Tobin Ehlise68360f2015-10-01 11:15:13 -06007447 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06007448
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007449 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007450 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7451 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007452
7453 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007454 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7455 ds_pool_ci.maxSets = 1;
7456 ds_pool_ci.poolSizeCount = 1;
7457 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007458
7459 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007460 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007461 ASSERT_VK_SUCCESS(err);
7462
7463 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007464 dsl_binding.binding = 0;
7465 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7466 dsl_binding.descriptorCount = 1;
7467 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007468
7469 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007470 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7471 ds_layout_ci.bindingCount = 1;
7472 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007473
7474 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007475 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007476 ASSERT_VK_SUCCESS(err);
7477
7478 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007479 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007480 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007481 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007482 alloc_info.descriptorPool = ds_pool;
7483 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007484 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007485 ASSERT_VK_SUCCESS(err);
7486
7487 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007488 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7489 pipeline_layout_ci.setLayoutCount = 1;
7490 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007491
7492 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007493 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007494 ASSERT_VK_SUCCESS(err);
7495
7496 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007497 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
7498 vp_state_ci.viewportCount = 1;
7499 vp_state_ci.pViewports = NULL; // Null vp w/ count of 1 should cause error
7500 vp_state_ci.scissorCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007501 vp_state_ci.pScissors = NULL; // Scissor is dynamic (below) so this won't cause error
Tobin Ehlise68360f2015-10-01 11:15:13 -06007502
7503 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
7504 // Set scissor as dynamic to avoid that error
7505 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007506 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
7507 dyn_state_ci.dynamicStateCount = 1;
7508 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007509
Mark Lobodzinski73169e22016-12-16 14:01:17 -07007510 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
7511 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
7512 pipe_ms_state_ci.pNext = NULL;
7513 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
7514 pipe_ms_state_ci.sampleShadingEnable = 0;
7515 pipe_ms_state_ci.minSampleShading = 1.0;
7516 pipe_ms_state_ci.pSampleMask = NULL;
7517
Cody Northropeb3a6c12015-10-05 14:44:45 -06007518 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07007519 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06007520
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007521 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski73169e22016-12-16 14:01:17 -07007522 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
7523 // 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 +08007524 shaderStages[0] = vs.GetStageCreateInfo();
7525 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007526
Cody Northropf6622dc2015-10-06 10:33:21 -06007527 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7528 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7529 vi_ci.pNext = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007530 vi_ci.vertexBindingDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06007531 vi_ci.pVertexBindingDescriptions = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007532 vi_ci.vertexAttributeDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06007533 vi_ci.pVertexAttributeDescriptions = nullptr;
7534
7535 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7536 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7537 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7538
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007539 VkPipelineRasterizationStateCreateInfo rs_ci = {};
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007540 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Mark Lobodzinski73169e22016-12-16 14:01:17 -07007541 rs_ci.lineWidth = m_device->props.limits.lineWidthRange[0];
Cody Northropf6622dc2015-10-06 10:33:21 -06007542 rs_ci.pNext = nullptr;
7543
Mark Youngc89c6312016-03-31 16:03:20 -06007544 VkPipelineColorBlendAttachmentState att = {};
7545 att.blendEnable = VK_FALSE;
7546 att.colorWriteMask = 0xf;
7547
Cody Northropf6622dc2015-10-06 10:33:21 -06007548 VkPipelineColorBlendStateCreateInfo cb_ci = {};
7549 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
7550 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06007551 cb_ci.attachmentCount = 1;
7552 cb_ci.pAttachments = &att;
Cody Northropf6622dc2015-10-06 10:33:21 -06007553
Tobin Ehlise68360f2015-10-01 11:15:13 -06007554 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007555 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7556 gp_ci.stageCount = 2;
7557 gp_ci.pStages = shaderStages;
7558 gp_ci.pVertexInputState = &vi_ci;
7559 gp_ci.pInputAssemblyState = &ia_ci;
7560 gp_ci.pViewportState = &vp_state_ci;
7561 gp_ci.pRasterizationState = &rs_ci;
7562 gp_ci.pColorBlendState = &cb_ci;
7563 gp_ci.pDynamicState = &dyn_state_ci;
Mark Lobodzinski73169e22016-12-16 14:01:17 -07007564 gp_ci.pMultisampleState = &pipe_ms_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007565 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7566 gp_ci.layout = pipeline_layout;
7567 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007568
7569 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007570 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007571
7572 VkPipeline pipeline;
7573 VkPipelineCache pipelineCache;
7574
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007575 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007576 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007577 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007578
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007579 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007580
Tobin Ehlisd332f282015-10-02 11:00:56 -06007581 // Now hit second fail case where we set scissor w/ different count than PSO
Karl Schultz6addd812016-02-02 17:17:23 -07007582 // First need to successfully create the PSO from above by setting
7583 // pViewports
Mike Weiblen95dd0f92016-10-19 12:28:27 -06007584 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic scissor(s) 0 are used by pipeline state object, ");
Karl Schultz6addd812016-02-02 17:17:23 -07007585
7586 VkViewport vp = {}; // Just need dummy vp to point to
7587 vp_state_ci.pViewports = &vp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007588 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Karl Schultz6addd812016-02-02 17:17:23 -07007589 ASSERT_VK_SUCCESS(err);
7590 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007591 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007592 VkRect2D scissors[1] = {}; // don't care about data
Karl Schultz6addd812016-02-02 17:17:23 -07007593 // Count of 2 doesn't match PSO count of 1
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007594 vkCmdSetScissor(m_commandBuffer->GetBufferHandle(), 1, 1, scissors);
Karl Schultz6addd812016-02-02 17:17:23 -07007595 Draw(1, 0, 0, 0);
7596
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007597 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07007598
7599 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7600 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7601 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7602 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06007603 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07007604}
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07007605
7606// 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 -07007607// viewportCount
7608TEST_F(VkLayerTest, PSOScissorCountWithoutDataAndDynViewportMismatch) {
7609 VkResult err;
7610
Mark Lobodzinskid04c7862016-12-16 13:17:49 -07007611 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02111);
Karl Schultz6addd812016-02-02 17:17:23 -07007612
7613 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007614
7615 if (!m_device->phy().features().multiViewport) {
7616 printf("Device does not support multiple viewports/scissors; skipped.\n");
7617 return;
7618 }
7619
Karl Schultz6addd812016-02-02 17:17:23 -07007620 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7621
7622 VkDescriptorPoolSize ds_type_count = {};
7623 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7624 ds_type_count.descriptorCount = 1;
7625
7626 VkDescriptorPoolCreateInfo ds_pool_ci = {};
7627 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7628 ds_pool_ci.maxSets = 1;
7629 ds_pool_ci.poolSizeCount = 1;
7630 ds_pool_ci.pPoolSizes = &ds_type_count;
7631
7632 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007633 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Karl Schultz6addd812016-02-02 17:17:23 -07007634 ASSERT_VK_SUCCESS(err);
7635
7636 VkDescriptorSetLayoutBinding dsl_binding = {};
7637 dsl_binding.binding = 0;
7638 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7639 dsl_binding.descriptorCount = 1;
7640 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7641
7642 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
7643 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7644 ds_layout_ci.bindingCount = 1;
7645 ds_layout_ci.pBindings = &dsl_binding;
7646
7647 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007648 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Karl Schultz6addd812016-02-02 17:17:23 -07007649 ASSERT_VK_SUCCESS(err);
7650
7651 VkDescriptorSet descriptorSet;
7652 VkDescriptorSetAllocateInfo alloc_info = {};
7653 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
7654 alloc_info.descriptorSetCount = 1;
7655 alloc_info.descriptorPool = ds_pool;
7656 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007657 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Karl Schultz6addd812016-02-02 17:17:23 -07007658 ASSERT_VK_SUCCESS(err);
7659
7660 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
7661 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7662 pipeline_layout_ci.setLayoutCount = 1;
7663 pipeline_layout_ci.pSetLayouts = &ds_layout;
7664
7665 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007666 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultz6addd812016-02-02 17:17:23 -07007667 ASSERT_VK_SUCCESS(err);
7668
7669 VkPipelineViewportStateCreateInfo vp_state_ci = {};
7670 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
7671 vp_state_ci.scissorCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007672 vp_state_ci.pScissors = NULL; // Null scissor w/ count of 1 should cause error
Karl Schultz6addd812016-02-02 17:17:23 -07007673 vp_state_ci.viewportCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007674 vp_state_ci.pViewports = NULL; // vp is dynamic (below) so this won't cause error
Karl Schultz6addd812016-02-02 17:17:23 -07007675
7676 VkDynamicState vp_state = VK_DYNAMIC_STATE_VIEWPORT;
7677 // Set scissor as dynamic to avoid that error
7678 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
7679 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
7680 dyn_state_ci.dynamicStateCount = 1;
7681 dyn_state_ci.pDynamicStates = &vp_state;
7682
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07007683 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
7684 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
7685 pipe_ms_state_ci.pNext = NULL;
7686 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
7687 pipe_ms_state_ci.sampleShadingEnable = 0;
7688 pipe_ms_state_ci.minSampleShading = 1.0;
7689 pipe_ms_state_ci.pSampleMask = NULL;
7690
Karl Schultz6addd812016-02-02 17:17:23 -07007691 VkPipelineShaderStageCreateInfo shaderStages[2];
7692 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
7693
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007694 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07007695 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
7696 // 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 -07007697 shaderStages[0] = vs.GetStageCreateInfo();
7698 shaderStages[1] = fs.GetStageCreateInfo();
7699
7700 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7701 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7702 vi_ci.pNext = nullptr;
7703 vi_ci.vertexBindingDescriptionCount = 0;
7704 vi_ci.pVertexBindingDescriptions = nullptr;
7705 vi_ci.vertexAttributeDescriptionCount = 0;
7706 vi_ci.pVertexAttributeDescriptions = nullptr;
7707
7708 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7709 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7710 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7711
7712 VkPipelineRasterizationStateCreateInfo rs_ci = {};
7713 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07007714 rs_ci.lineWidth = m_device->props.limits.lineWidthRange[0];
Karl Schultz6addd812016-02-02 17:17:23 -07007715 rs_ci.pNext = nullptr;
7716
Mark Youngc89c6312016-03-31 16:03:20 -06007717 VkPipelineColorBlendAttachmentState att = {};
7718 att.blendEnable = VK_FALSE;
7719 att.colorWriteMask = 0xf;
7720
Karl Schultz6addd812016-02-02 17:17:23 -07007721 VkPipelineColorBlendStateCreateInfo cb_ci = {};
7722 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
7723 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06007724 cb_ci.attachmentCount = 1;
7725 cb_ci.pAttachments = &att;
Karl Schultz6addd812016-02-02 17:17:23 -07007726
7727 VkGraphicsPipelineCreateInfo gp_ci = {};
7728 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7729 gp_ci.stageCount = 2;
7730 gp_ci.pStages = shaderStages;
7731 gp_ci.pVertexInputState = &vi_ci;
7732 gp_ci.pInputAssemblyState = &ia_ci;
7733 gp_ci.pViewportState = &vp_state_ci;
7734 gp_ci.pRasterizationState = &rs_ci;
7735 gp_ci.pColorBlendState = &cb_ci;
7736 gp_ci.pDynamicState = &dyn_state_ci;
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07007737 gp_ci.pMultisampleState = &pipe_ms_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007738 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7739 gp_ci.layout = pipeline_layout;
7740 gp_ci.renderPass = renderPass();
7741
7742 VkPipelineCacheCreateInfo pc_ci = {};
7743 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
7744
7745 VkPipeline pipeline;
7746 VkPipelineCache pipelineCache;
7747
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007748 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Karl Schultz6addd812016-02-02 17:17:23 -07007749 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007750 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Karl Schultz6addd812016-02-02 17:17:23 -07007751
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007752 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07007753
7754 // Now hit second fail case where we set scissor w/ different count than PSO
7755 // First need to successfully create the PSO from above by setting
7756 // pViewports
Mike Weiblen95dd0f92016-10-19 12:28:27 -06007757 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 -06007758
Tobin Ehlisd332f282015-10-02 11:00:56 -06007759 VkRect2D sc = {}; // Just need dummy vp to point to
7760 vp_state_ci.pScissors = &sc;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007761 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlisd332f282015-10-02 11:00:56 -06007762 ASSERT_VK_SUCCESS(err);
7763 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007764 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07007765 VkViewport viewports[1] = {};
7766 viewports[0].width = 8;
7767 viewports[0].height = 8;
Tobin Ehlisd332f282015-10-02 11:00:56 -06007768 // Count of 2 doesn't match PSO count of 1
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007769 vkCmdSetViewport(m_commandBuffer->GetBufferHandle(), 1, 1, viewports);
Tobin Ehlisd332f282015-10-02 11:00:56 -06007770 Draw(1, 0, 0, 0);
7771
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007772 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007773
Chia-I Wuf7458c52015-10-26 21:10:41 +08007774 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7775 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7776 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7777 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06007778 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007779}
7780
Mark Young7394fdd2016-03-31 14:56:43 -06007781TEST_F(VkLayerTest, PSOLineWidthInvalid) {
7782 VkResult err;
7783
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007784 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to -1");
Mark Young7394fdd2016-03-31 14:56:43 -06007785
7786 ASSERT_NO_FATAL_FAILURE(InitState());
7787 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7788
7789 VkDescriptorPoolSize ds_type_count = {};
7790 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7791 ds_type_count.descriptorCount = 1;
7792
7793 VkDescriptorPoolCreateInfo ds_pool_ci = {};
7794 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7795 ds_pool_ci.maxSets = 1;
7796 ds_pool_ci.poolSizeCount = 1;
7797 ds_pool_ci.pPoolSizes = &ds_type_count;
7798
7799 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007800 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Mark Young7394fdd2016-03-31 14:56:43 -06007801 ASSERT_VK_SUCCESS(err);
7802
7803 VkDescriptorSetLayoutBinding dsl_binding = {};
7804 dsl_binding.binding = 0;
7805 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7806 dsl_binding.descriptorCount = 1;
7807 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7808
7809 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
7810 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7811 ds_layout_ci.bindingCount = 1;
7812 ds_layout_ci.pBindings = &dsl_binding;
7813
7814 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007815 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Young7394fdd2016-03-31 14:56:43 -06007816 ASSERT_VK_SUCCESS(err);
7817
7818 VkDescriptorSet descriptorSet;
7819 VkDescriptorSetAllocateInfo alloc_info = {};
7820 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
7821 alloc_info.descriptorSetCount = 1;
7822 alloc_info.descriptorPool = ds_pool;
7823 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007824 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Young7394fdd2016-03-31 14:56:43 -06007825 ASSERT_VK_SUCCESS(err);
7826
7827 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
7828 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7829 pipeline_layout_ci.setLayoutCount = 1;
7830 pipeline_layout_ci.pSetLayouts = &ds_layout;
7831
7832 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007833 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Mark Young7394fdd2016-03-31 14:56:43 -06007834 ASSERT_VK_SUCCESS(err);
7835
7836 VkPipelineViewportStateCreateInfo vp_state_ci = {};
7837 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
7838 vp_state_ci.scissorCount = 1;
7839 vp_state_ci.pScissors = NULL;
7840 vp_state_ci.viewportCount = 1;
7841 vp_state_ci.pViewports = NULL;
7842
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007843 VkDynamicState dynamic_states[3] = {VK_DYNAMIC_STATE_VIEWPORT, VK_DYNAMIC_STATE_SCISSOR, VK_DYNAMIC_STATE_LINE_WIDTH};
Mark Young7394fdd2016-03-31 14:56:43 -06007844 // Set scissor as dynamic to avoid that error
7845 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
7846 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
7847 dyn_state_ci.dynamicStateCount = 2;
7848 dyn_state_ci.pDynamicStates = dynamic_states;
7849
7850 VkPipelineShaderStageCreateInfo shaderStages[2];
7851 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
7852
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007853 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
7854 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT,
Mark Young7394fdd2016-03-31 14:56:43 -06007855 this); // TODO - We shouldn't need a fragment shader
7856 // but add it to be able to run on more devices
7857 shaderStages[0] = vs.GetStageCreateInfo();
7858 shaderStages[1] = fs.GetStageCreateInfo();
7859
7860 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7861 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7862 vi_ci.pNext = nullptr;
7863 vi_ci.vertexBindingDescriptionCount = 0;
7864 vi_ci.pVertexBindingDescriptions = nullptr;
7865 vi_ci.vertexAttributeDescriptionCount = 0;
7866 vi_ci.pVertexAttributeDescriptions = nullptr;
7867
7868 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7869 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7870 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7871
7872 VkPipelineRasterizationStateCreateInfo rs_ci = {};
7873 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7874 rs_ci.pNext = nullptr;
7875
Mark Young47107952016-05-02 15:59:55 -06007876 // Check too low (line width of -1.0f).
7877 rs_ci.lineWidth = -1.0f;
Mark Young7394fdd2016-03-31 14:56:43 -06007878
7879 VkPipelineColorBlendAttachmentState att = {};
7880 att.blendEnable = VK_FALSE;
7881 att.colorWriteMask = 0xf;
7882
7883 VkPipelineColorBlendStateCreateInfo cb_ci = {};
7884 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
7885 cb_ci.pNext = nullptr;
7886 cb_ci.attachmentCount = 1;
7887 cb_ci.pAttachments = &att;
7888
7889 VkGraphicsPipelineCreateInfo gp_ci = {};
7890 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7891 gp_ci.stageCount = 2;
7892 gp_ci.pStages = shaderStages;
7893 gp_ci.pVertexInputState = &vi_ci;
7894 gp_ci.pInputAssemblyState = &ia_ci;
7895 gp_ci.pViewportState = &vp_state_ci;
7896 gp_ci.pRasterizationState = &rs_ci;
7897 gp_ci.pColorBlendState = &cb_ci;
7898 gp_ci.pDynamicState = &dyn_state_ci;
7899 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7900 gp_ci.layout = pipeline_layout;
7901 gp_ci.renderPass = renderPass();
7902
7903 VkPipelineCacheCreateInfo pc_ci = {};
7904 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
7905
7906 VkPipeline pipeline;
7907 VkPipelineCache pipelineCache;
7908
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007909 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06007910 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007911 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06007912
7913 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06007914 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06007915
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007916 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to 65536");
Mark Young7394fdd2016-03-31 14:56:43 -06007917
7918 // Check too high (line width of 65536.0f).
7919 rs_ci.lineWidth = 65536.0f;
7920
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007921 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06007922 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007923 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06007924
7925 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06007926 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06007927
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007928 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to -1");
Mark Young7394fdd2016-03-31 14:56:43 -06007929
7930 dyn_state_ci.dynamicStateCount = 3;
7931
7932 rs_ci.lineWidth = 1.0f;
7933
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007934 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06007935 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007936 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06007937 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007938 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06007939
7940 // Check too low with dynamic setting.
Mark Young47107952016-05-02 15:59:55 -06007941 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), -1.0f);
Mark Young7394fdd2016-03-31 14:56:43 -06007942 m_errorMonitor->VerifyFound();
7943
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007944 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to 65536");
Mark Young7394fdd2016-03-31 14:56:43 -06007945
7946 // Check too high with dynamic setting.
7947 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), 65536.0f);
7948 m_errorMonitor->VerifyFound();
7949 EndCommandBuffer();
7950
7951 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7952 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7953 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7954 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06007955 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06007956}
7957
Karl Schultz6addd812016-02-02 17:17:23 -07007958TEST_F(VkLayerTest, NullRenderPass) {
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007959 // Bind a NULL RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007960 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mike Schuchardt0b1f2f82016-12-28 15:11:20 -07007961 "vkCmdBeginRenderPass: required parameter pRenderPassBegin specified as NULL");
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007962
7963 ASSERT_NO_FATAL_FAILURE(InitState());
7964 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007965
Tony Barbourfe3351b2015-07-28 10:17:20 -06007966 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07007967 // Don't care about RenderPass handle b/c error should be flagged before
7968 // that
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007969 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), NULL, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007970
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007971 m_errorMonitor->VerifyFound();
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007972}
7973
Karl Schultz6addd812016-02-02 17:17:23 -07007974TEST_F(VkLayerTest, RenderPassWithinRenderPass) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007975 // Bind a BeginRenderPass within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007976 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7977 "It is invalid to issue this call inside an active render pass");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007978
7979 ASSERT_NO_FATAL_FAILURE(InitState());
7980 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007981
Tony Barbourfe3351b2015-07-28 10:17:20 -06007982 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07007983 // Just create a dummy Renderpass that's non-NULL so we can get to the
7984 // proper error
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007985 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007986
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007987 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06007988}
7989
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06007990TEST_F(VkLayerTest, RenderPassClearOpMismatch) {
7991 TEST_DESCRIPTION("Begin a renderPass where clearValueCount is less than"
7992 "the number of renderPass attachments that use loadOp"
7993 "VK_ATTACHMENT_LOAD_OP_CLEAR.");
7994
7995 ASSERT_NO_FATAL_FAILURE(InitState());
7996 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7997
7998 // Create a renderPass with a single attachment that uses loadOp CLEAR
7999 VkAttachmentReference attach = {};
8000 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
8001 VkSubpassDescription subpass = {};
8002 subpass.inputAttachmentCount = 1;
8003 subpass.pInputAttachments = &attach;
8004 VkRenderPassCreateInfo rpci = {};
8005 rpci.subpassCount = 1;
8006 rpci.pSubpasses = &subpass;
8007 rpci.attachmentCount = 1;
8008 VkAttachmentDescription attach_desc = {};
8009 attach_desc.format = VK_FORMAT_UNDEFINED;
8010 // Set loadOp to CLEAR
8011 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
8012 rpci.pAttachments = &attach_desc;
8013 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
8014 VkRenderPass rp;
8015 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
8016
8017 VkCommandBufferInheritanceInfo hinfo = {};
8018 hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
8019 hinfo.renderPass = VK_NULL_HANDLE;
8020 hinfo.subpass = 0;
8021 hinfo.framebuffer = VK_NULL_HANDLE;
8022 hinfo.occlusionQueryEnable = VK_FALSE;
8023 hinfo.queryFlags = 0;
8024 hinfo.pipelineStatistics = 0;
8025 VkCommandBufferBeginInfo info = {};
8026 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
8027 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
8028 info.pInheritanceInfo = &hinfo;
8029
8030 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
8031 VkRenderPassBeginInfo rp_begin = {};
8032 rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
8033 rp_begin.pNext = NULL;
8034 rp_begin.renderPass = renderPass();
8035 rp_begin.framebuffer = framebuffer();
8036 rp_begin.clearValueCount = 0; // Should be 1
8037
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008038 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has a clearValueCount of 0 but "
8039 "there must be at least 1 entries in "
8040 "pClearValues array to account for ");
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008041
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008042 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rp_begin, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008043
8044 m_errorMonitor->VerifyFound();
Mark Lobodzinski5c70ebd2016-06-09 13:45:00 -06008045
8046 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008047}
8048
Slawomir Cygan0808f392016-11-28 17:53:23 +01008049TEST_F(VkLayerTest, RenderPassClearOpTooManyValues) {
8050 TEST_DESCRIPTION("Begin a renderPass where clearValueCount is greater than"
8051 "the number of renderPass attachments that use loadOp"
8052 "VK_ATTACHMENT_LOAD_OP_CLEAR.");
8053
8054 ASSERT_NO_FATAL_FAILURE(InitState());
8055 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8056
8057 // Create a renderPass with a single attachment that uses loadOp CLEAR
8058 VkAttachmentReference attach = {};
8059 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
8060 VkSubpassDescription subpass = {};
8061 subpass.inputAttachmentCount = 1;
8062 subpass.pInputAttachments = &attach;
8063 VkRenderPassCreateInfo rpci = {};
8064 rpci.subpassCount = 1;
8065 rpci.pSubpasses = &subpass;
8066 rpci.attachmentCount = 1;
8067 VkAttachmentDescription attach_desc = {};
8068 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
8069 // Set loadOp to CLEAR
8070 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
8071 rpci.pAttachments = &attach_desc;
8072 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
8073 VkRenderPass rp;
8074 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
8075
8076 VkCommandBufferBeginInfo info = {};
8077 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
8078 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
8079
8080 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
8081 VkRenderPassBeginInfo rp_begin = {};
8082 rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
8083 rp_begin.pNext = NULL;
8084 rp_begin.renderPass = renderPass();
8085 rp_begin.framebuffer = framebuffer();
8086 rp_begin.clearValueCount = 2; // Should be 1
8087
8088 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, " has a clearValueCount of"
8089 " 2 but only first 1 entries in pClearValues array are used");
8090
8091 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rp_begin, VK_SUBPASS_CONTENTS_INLINE);
8092
8093 m_errorMonitor->VerifyFound();
8094
8095 vkDestroyRenderPass(m_device->device(), rp, NULL);
8096}
8097
8098
Cody Northrop3bb4d962016-05-09 16:15:57 -06008099TEST_F(VkLayerTest, EndCommandBufferWithinRenderPass) {
8100
8101 TEST_DESCRIPTION("End a command buffer with an active render pass");
8102
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008103 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8104 "It is invalid to issue this call inside an active render pass");
Cody Northrop3bb4d962016-05-09 16:15:57 -06008105
8106 ASSERT_NO_FATAL_FAILURE(InitState());
8107 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8108
8109 // The framework's BeginCommandBuffer calls CreateRenderPass
8110 BeginCommandBuffer();
8111
8112 // Call directly into vkEndCommandBuffer instead of the
8113 // the framework's EndCommandBuffer, which inserts a
8114 // vkEndRenderPass
8115 vkEndCommandBuffer(m_commandBuffer->GetBufferHandle());
8116
8117 m_errorMonitor->VerifyFound();
8118
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008119 // TODO: Add test for VK_COMMAND_BUFFER_LEVEL_SECONDARY
8120 // TODO: Add test for VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT
Cody Northrop3bb4d962016-05-09 16:15:57 -06008121}
8122
Karl Schultz6addd812016-02-02 17:17:23 -07008123TEST_F(VkLayerTest, FillBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008124 // Call CmdFillBuffer within an active renderpass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008125 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8126 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008127
8128 ASSERT_NO_FATAL_FAILURE(InitState());
8129 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008130
8131 // Renderpass is started here
8132 BeginCommandBuffer();
8133
8134 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008135 vk_testing::Buffer dstBuffer;
8136 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008137
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008138 m_commandBuffer->FillBuffer(dstBuffer.handle(), 0, 4, 0x11111111);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008139
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008140 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008141}
8142
Karl Schultz6addd812016-02-02 17:17:23 -07008143TEST_F(VkLayerTest, UpdateBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008144 // Call CmdUpdateBuffer within an active renderpass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008145 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8146 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008147
8148 ASSERT_NO_FATAL_FAILURE(InitState());
8149 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008150
8151 // Renderpass is started here
8152 BeginCommandBuffer();
8153
8154 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008155 vk_testing::Buffer dstBuffer;
8156 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008157
Karl Schultz6addd812016-02-02 17:17:23 -07008158 VkDeviceSize dstOffset = 0;
8159 VkDeviceSize dataSize = 1024;
Karl Schultzee344492016-07-11 15:09:57 -06008160 const void *pData = NULL;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008161
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008162 vkCmdUpdateBuffer(m_commandBuffer->GetBufferHandle(), dstBuffer.handle(), dstOffset, dataSize, pData);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008163
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008164 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008165}
8166
Karl Schultz6addd812016-02-02 17:17:23 -07008167TEST_F(VkLayerTest, ClearColorImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008168 // Call CmdClearColorImage within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008169 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8170 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008171
8172 ASSERT_NO_FATAL_FAILURE(InitState());
8173 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008174
8175 // Renderpass is started here
8176 BeginCommandBuffer();
8177
Michael Lentine0a369f62016-02-03 16:51:46 -06008178 VkClearColorValue clear_color;
8179 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
Karl Schultz6addd812016-02-02 17:17:23 -07008180 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
8181 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
8182 const int32_t tex_width = 32;
8183 const int32_t tex_height = 32;
8184 VkImageCreateInfo image_create_info = {};
8185 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
8186 image_create_info.pNext = NULL;
8187 image_create_info.imageType = VK_IMAGE_TYPE_2D;
8188 image_create_info.format = tex_format;
8189 image_create_info.extent.width = tex_width;
8190 image_create_info.extent.height = tex_height;
8191 image_create_info.extent.depth = 1;
8192 image_create_info.mipLevels = 1;
8193 image_create_info.arrayLayers = 1;
8194 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
8195 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
8196 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008197
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008198 vk_testing::Image dstImage;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008199 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008200
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008201 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008202
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008203 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1, &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008204
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008205 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008206}
8207
Karl Schultz6addd812016-02-02 17:17:23 -07008208TEST_F(VkLayerTest, ClearDepthStencilImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008209 // Call CmdClearDepthStencilImage within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008210 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8211 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008212
8213 ASSERT_NO_FATAL_FAILURE(InitState());
8214 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008215
8216 // Renderpass is started here
8217 BeginCommandBuffer();
8218
8219 VkClearDepthStencilValue clear_value = {0};
Dustin Gravesa2e5c942016-02-11 18:28:06 -07008220 VkMemoryPropertyFlags reqs = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07008221 VkImageCreateInfo image_create_info = vk_testing::Image::create_info();
8222 image_create_info.imageType = VK_IMAGE_TYPE_2D;
8223 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
8224 image_create_info.extent.width = 64;
8225 image_create_info.extent.height = 64;
8226 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
8227 image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008228
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008229 vk_testing::Image dstImage;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008230 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008231
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008232 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_DEPTH_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008233
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008234 vkCmdClearDepthStencilImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(),
8235 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, &clear_value, 1, &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008236
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008237 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008238}
8239
Karl Schultz6addd812016-02-02 17:17:23 -07008240TEST_F(VkLayerTest, ClearColorAttachmentsOutsideRenderPass) {
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06008241 // Call CmdClearAttachmentss outside of an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07008242 VkResult err;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008243
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008244 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdClearAttachments(): This call "
8245 "must be issued inside an active "
8246 "render pass");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008247
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008248 ASSERT_NO_FATAL_FAILURE(InitState());
8249 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008250
8251 // Start no RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008252 err = m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008253 ASSERT_VK_SUCCESS(err);
8254
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06008255 VkClearAttachment color_attachment;
8256 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8257 color_attachment.clearValue.color.float32[0] = 0;
8258 color_attachment.clearValue.color.float32[1] = 0;
8259 color_attachment.clearValue.color.float32[2] = 0;
8260 color_attachment.clearValue.color.float32[3] = 0;
8261 color_attachment.colorAttachment = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07008262 VkClearRect clear_rect = {{{0, 0}, {32, 32}}};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008263 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008264
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008265 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008266}
8267
Chris Forbes3b97e932016-09-07 11:29:24 +12008268TEST_F(VkLayerTest, RenderPassExcessiveNextSubpass) {
8269 TEST_DESCRIPTION("Test that an error is produced when CmdNextSubpass is "
8270 "called too many times in a renderpass instance");
8271
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008272 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdNextSubpass(): Attempted to advance "
8273 "beyond final subpass");
Chris Forbes3b97e932016-09-07 11:29:24 +12008274
8275 ASSERT_NO_FATAL_FAILURE(InitState());
8276 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8277
8278 BeginCommandBuffer();
8279
8280 // error here.
8281 vkCmdNextSubpass(m_commandBuffer->GetBufferHandle(), VK_SUBPASS_CONTENTS_INLINE);
8282 m_errorMonitor->VerifyFound();
8283
8284 EndCommandBuffer();
8285}
8286
Chris Forbes6d624702016-09-07 13:57:05 +12008287TEST_F(VkLayerTest, RenderPassEndedBeforeFinalSubpass) {
8288 TEST_DESCRIPTION("Test that an error is produced when CmdEndRenderPass is "
8289 "called before the final subpass has been reached");
8290
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008291 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdEndRenderPass(): Called before reaching "
8292 "final subpass");
Chris Forbes6d624702016-09-07 13:57:05 +12008293
8294 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008295 VkSubpassDescription sd[2] = {{0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr},
8296 {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr}};
Chris Forbes6d624702016-09-07 13:57:05 +12008297
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008298 VkRenderPassCreateInfo rcpi = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 2, sd, 0, nullptr};
Chris Forbes6d624702016-09-07 13:57:05 +12008299
8300 VkRenderPass rp;
8301 VkResult err = vkCreateRenderPass(m_device->device(), &rcpi, nullptr, &rp);
8302 ASSERT_VK_SUCCESS(err);
8303
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008304 VkFramebufferCreateInfo fbci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 0, nullptr, 16, 16, 1};
Chris Forbes6d624702016-09-07 13:57:05 +12008305
8306 VkFramebuffer fb;
8307 err = vkCreateFramebuffer(m_device->device(), &fbci, nullptr, &fb);
8308 ASSERT_VK_SUCCESS(err);
8309
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008310 m_commandBuffer->BeginCommandBuffer(); // no implicit RP begin
Chris Forbes6d624702016-09-07 13:57:05 +12008311
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008312 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 +12008313
8314 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
8315
8316 // Error here.
8317 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
8318 m_errorMonitor->VerifyFound();
8319
8320 // Clean up.
8321 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
8322 vkDestroyRenderPass(m_device->device(), rp, nullptr);
8323}
8324
Karl Schultz9e66a292016-04-21 15:57:51 -06008325TEST_F(VkLayerTest, BufferMemoryBarrierNoBuffer) {
8326 // Try to add a buffer memory barrier with no buffer.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008327 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8328 "required parameter pBufferMemoryBarriers[0].buffer specified as VK_NULL_HANDLE");
Karl Schultz9e66a292016-04-21 15:57:51 -06008329
8330 ASSERT_NO_FATAL_FAILURE(InitState());
8331 BeginCommandBuffer();
8332
8333 VkBufferMemoryBarrier buf_barrier = {};
8334 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
8335 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8336 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
8337 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8338 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8339 buf_barrier.buffer = VK_NULL_HANDLE;
8340 buf_barrier.offset = 0;
8341 buf_barrier.size = VK_WHOLE_SIZE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008342 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8343 nullptr, 1, &buf_barrier, 0, nullptr);
Karl Schultz9e66a292016-04-21 15:57:51 -06008344
8345 m_errorMonitor->VerifyFound();
8346}
8347
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008348TEST_F(VkLayerTest, InvalidBarriers) {
8349 TEST_DESCRIPTION("A variety of ways to get VK_INVALID_BARRIER ");
8350
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008351 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Barriers cannot be set during subpass");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008352
8353 ASSERT_NO_FATAL_FAILURE(InitState());
8354 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8355
8356 VkMemoryBarrier mem_barrier = {};
8357 mem_barrier.sType = VK_STRUCTURE_TYPE_MEMORY_BARRIER;
8358 mem_barrier.pNext = NULL;
8359 mem_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8360 mem_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
8361 BeginCommandBuffer();
8362 // BeginCommandBuffer() starts a render pass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008363 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 1,
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008364 &mem_barrier, 0, nullptr, 0, nullptr);
8365 m_errorMonitor->VerifyFound();
8366
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008367 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Image Layout cannot be transitioned to UNDEFINED");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008368 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008369 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 -06008370 ASSERT_TRUE(image.initialized());
8371 VkImageMemoryBarrier img_barrier = {};
8372 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
8373 img_barrier.pNext = NULL;
8374 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8375 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
8376 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8377 // New layout can't be UNDEFINED
8378 img_barrier.newLayout = VK_IMAGE_LAYOUT_UNDEFINED;
8379 img_barrier.image = image.handle();
8380 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8381 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8382 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8383 img_barrier.subresourceRange.baseArrayLayer = 0;
8384 img_barrier.subresourceRange.baseMipLevel = 0;
8385 img_barrier.subresourceRange.layerCount = 1;
8386 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008387 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8388 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008389 m_errorMonitor->VerifyFound();
8390 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8391
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008392 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Subresource must have the sum of the "
8393 "baseArrayLayer");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008394 // baseArrayLayer + layerCount must be <= image's arrayLayers
8395 img_barrier.subresourceRange.baseArrayLayer = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008396 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8397 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008398 m_errorMonitor->VerifyFound();
8399 img_barrier.subresourceRange.baseArrayLayer = 0;
8400
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008401 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Subresource must have the sum of the baseMipLevel");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008402 // baseMipLevel + levelCount must be <= image's mipLevels
8403 img_barrier.subresourceRange.baseMipLevel = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008404 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8405 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008406 m_errorMonitor->VerifyFound();
8407 img_barrier.subresourceRange.baseMipLevel = 0;
8408
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008409 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 -06008410 vk_testing::Buffer buffer;
Mark Lobodzinskibdf378a2016-12-12 17:11:50 -07008411 VkMemoryPropertyFlags mem_reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
8412 buffer.init_as_src_and_dst(*m_device, 256, mem_reqs);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008413 VkBufferMemoryBarrier buf_barrier = {};
8414 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
8415 buf_barrier.pNext = NULL;
8416 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8417 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
8418 buf_barrier.buffer = buffer.handle();
8419 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8420 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8421 buf_barrier.offset = 0;
8422 buf_barrier.size = VK_WHOLE_SIZE;
8423 // Can't send buffer barrier during a render pass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008424 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8425 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008426 m_errorMonitor->VerifyFound();
8427 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
8428
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008429 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "which is not less than total size");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008430 buf_barrier.offset = 257;
8431 // Offset greater than total size
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008432 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8433 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008434 m_errorMonitor->VerifyFound();
8435 buf_barrier.offset = 0;
8436
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008437 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "whose sum is greater than total size");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008438 buf_barrier.size = 257;
8439 // Size greater than total size
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008440 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8441 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008442 m_errorMonitor->VerifyFound();
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008443
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008444 // Now exercise barrier aspect bit errors, first DS
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06008445 m_errorMonitor->SetDesiredFailureMsg(
8446 VK_DEBUG_REPORT_ERROR_BIT_EXT,
8447 "Combination depth/stencil image formats can have only the VK_IMAGE_ASPECT_DEPTH_BIT and VK_IMAGE_ASPECT_STENCIL_BIT set.");
8448 m_errorMonitor->SetDesiredFailureMsg(
8449 VK_DEBUG_REPORT_ERROR_BIT_EXT,
8450 "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 -06008451 VkDepthStencilObj ds_image(m_device);
8452 ds_image.Init(m_device, 128, 128, VK_FORMAT_D24_UNORM_S8_UINT);
8453 ASSERT_TRUE(ds_image.initialized());
Tobin Ehlis15684a02016-07-21 14:55:26 -06008454 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
8455 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008456 img_barrier.image = ds_image.handle();
Tobin Ehlis15684a02016-07-21 14:55:26 -06008457 // Use of COLOR aspect on DS image is error
8458 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008459 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8460 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008461 m_errorMonitor->VerifyFound();
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008462 // Now test depth-only
8463 VkFormatProperties format_props;
8464
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008465 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_D16_UNORM, &format_props);
8466 if (format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) {
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06008467 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8468 "Depth-only image formats must have the VK_IMAGE_ASPECT_DEPTH_BIT set.");
8469 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8470 "Depth-only image formats can have only the VK_IMAGE_ASPECT_DEPTH_BIT set.");
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008471 VkDepthStencilObj d_image(m_device);
8472 d_image.Init(m_device, 128, 128, VK_FORMAT_D16_UNORM);
8473 ASSERT_TRUE(d_image.initialized());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008474 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
Tobin Ehlis15684a02016-07-21 14:55:26 -06008475 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008476 img_barrier.image = d_image.handle();
Tobin Ehlis15684a02016-07-21 14:55:26 -06008477 // Use of COLOR aspect on depth image is error
8478 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008479 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
8480 0, nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008481 m_errorMonitor->VerifyFound();
8482 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008483 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_S8_UINT, &format_props);
8484 if (format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) {
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008485 // Now test stencil-only
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06008486 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8487 "Stencil-only image formats must have the VK_IMAGE_ASPECT_STENCIL_BIT set.");
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008488 VkDepthStencilObj s_image(m_device);
8489 s_image.Init(m_device, 128, 128, VK_FORMAT_S8_UINT);
8490 ASSERT_TRUE(s_image.initialized());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008491 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
Tobin Ehlis15684a02016-07-21 14:55:26 -06008492 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008493 img_barrier.image = s_image.handle();
Tobin Ehlis15684a02016-07-21 14:55:26 -06008494 // Use of COLOR aspect on depth image is error
8495 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008496 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
8497 0, nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008498 m_errorMonitor->VerifyFound();
8499 }
8500 // Finally test color
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06008501 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8502 "Color image formats must have the VK_IMAGE_ASPECT_COLOR_BIT set.");
8503 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8504 "Color image formats must have ONLY the VK_IMAGE_ASPECT_COLOR_BIT set.");
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008505 VkImageObj c_image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008506 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 -06008507 ASSERT_TRUE(c_image.initialized());
8508 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8509 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
8510 img_barrier.image = c_image.handle();
8511 // Set aspect to depth (non-color)
8512 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008513 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8514 nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008515 m_errorMonitor->VerifyFound();
Mark Lobodzinskibdf378a2016-12-12 17:11:50 -07008516
8517 // Attempt to mismatch barriers/waitEvents calls with incompatible queues
8518
8519 // Create command pool with incompatible queueflags
8520 const std::vector<VkQueueFamilyProperties> queue_props = m_device->queue_props;
8521 uint32_t queue_family_index = UINT32_MAX;
8522 for (uint32_t i = 0; i < queue_props.size(); i++) {
8523 if ((queue_props[i].queueFlags & VK_QUEUE_COMPUTE_BIT) == 0) {
8524 queue_family_index = i;
8525 break;
8526 }
8527 }
8528 if (queue_family_index == UINT32_MAX) {
8529 printf("No non-compute queue found; skipped.\n");
8530 return;
8531 }
8532 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02513);
8533
8534 VkCommandPool command_pool;
8535 VkCommandPoolCreateInfo pool_create_info{};
8536 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
8537 pool_create_info.queueFamilyIndex = queue_family_index;
8538 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
8539 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
8540
8541 // Allocate a command buffer
8542 VkCommandBuffer bad_command_buffer;
8543 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
8544 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
8545 command_buffer_allocate_info.commandPool = command_pool;
8546 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
8547 command_buffer_allocate_info.commandBufferCount = 1;
8548 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &bad_command_buffer));
8549
8550 VkCommandBufferBeginInfo cbbi = {};
8551 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
8552 vkBeginCommandBuffer(bad_command_buffer, &cbbi);
8553 buf_barrier.offset = 0;
8554 buf_barrier.size = VK_WHOLE_SIZE;
8555 vkCmdPipelineBarrier(bad_command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 1,
8556 &buf_barrier, 0, nullptr);
8557 m_errorMonitor->VerifyFound();
8558
8559 if ((queue_props[queue_family_index].queueFlags & VK_QUEUE_GRAPHICS_BIT) == 0) {
8560 vkEndCommandBuffer(bad_command_buffer);
8561 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
8562 printf("The non-compute queue does not support graphics; skipped.\n");
8563 return;
8564 }
8565 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02510);
8566 VkEvent event;
8567 VkEventCreateInfo event_create_info{};
8568 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
8569 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
8570 vkCmdWaitEvents(bad_command_buffer, 1, &event, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, nullptr, 0,
8571 nullptr, 0, nullptr);
8572 m_errorMonitor->VerifyFound();
8573
8574 vkEndCommandBuffer(bad_command_buffer);
8575 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008576}
8577
Tony Barbour18ba25c2016-09-29 13:42:40 -06008578TEST_F(VkLayerTest, LayoutFromPresentWithoutAccessMemoryRead) {
8579 // Transition an image away from PRESENT_SRC_KHR without ACCESS_MEMORY_READ in srcAccessMask
8580
8581 m_errorMonitor->SetDesiredFailureMsg(
8582 VK_DEBUG_REPORT_WARNING_BIT_EXT,
8583 "must have required access bit");
8584 ASSERT_NO_FATAL_FAILURE(InitState());
8585 VkImageObj image(m_device);
Tony Barbour256c80a2016-10-05 13:23:46 -06008586 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 -06008587 ASSERT_TRUE(image.initialized());
8588
8589 VkImageMemoryBarrier barrier = {};
8590 VkImageSubresourceRange range;
8591 barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
8592 barrier.srcAccessMask = 0;
8593 barrier.srcAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
8594 barrier.dstAccessMask = VK_ACCESS_MEMORY_READ_BIT;
8595 barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8596 barrier.newLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
8597 barrier.image = image.handle();
8598 range.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8599 range.baseMipLevel = 0;
8600 range.levelCount = 1;
8601 range.baseArrayLayer = 0;
8602 range.layerCount = 1;
8603 barrier.subresourceRange = range;
8604 VkCommandBufferObj cmdbuf(m_device, m_commandPool);
8605 cmdbuf.BeginCommandBuffer();
8606 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
8607 &barrier);
8608 barrier.oldLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
8609 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
8610 barrier.srcAccessMask = 0;
8611 barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
8612 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
8613 &barrier);
8614
8615 m_errorMonitor->VerifyFound();
8616}
8617
Karl Schultz6addd812016-02-02 17:17:23 -07008618TEST_F(VkLayerTest, IdxBufferAlignmentError) {
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008619 // Bind a BeginRenderPass within an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07008620 VkResult err;
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008621
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008622 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdBindIndexBuffer() offset (0x7) does not fall on ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008623
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008624 ASSERT_NO_FATAL_FAILURE(InitState());
8625 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008626 uint32_t qfi = 0;
8627 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008628 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
8629 buffCI.size = 1024;
8630 buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
8631 buffCI.queueFamilyIndexCount = 1;
8632 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008633
8634 VkBuffer ib;
Chia-I Wuf7458c52015-10-26 21:10:41 +08008635 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008636 ASSERT_VK_SUCCESS(err);
8637
8638 BeginCommandBuffer();
8639 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07008640 // vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
8641 // VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008642 // Should error before calling to driver so don't care about actual data
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008643 vkCmdBindIndexBuffer(m_commandBuffer->GetBufferHandle(), ib, 7, VK_INDEX_TYPE_UINT16);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008644
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008645 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06008646
Chia-I Wuf7458c52015-10-26 21:10:41 +08008647 vkDestroyBuffer(m_device->device(), ib, NULL);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008648}
8649
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07008650TEST_F(VkLayerTest, InvalidQueueFamilyIndex) {
8651 // Create an out-of-range queueFamilyIndex
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008652 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8653 "vkCreateBuffer: pCreateInfo->pQueueFamilyIndices[0] (777) must be one "
8654 "of the indices specified when the device was created, via the "
8655 "VkDeviceQueueCreateInfo structure.");
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07008656
8657 ASSERT_NO_FATAL_FAILURE(InitState());
8658 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8659 VkBufferCreateInfo buffCI = {};
8660 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
8661 buffCI.size = 1024;
8662 buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
8663 buffCI.queueFamilyIndexCount = 1;
8664 // Introduce failure by specifying invalid queue_family_index
8665 uint32_t qfi = 777;
8666 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis24aab042016-03-24 10:54:18 -06008667 buffCI.sharingMode = VK_SHARING_MODE_CONCURRENT; // qfi only matters in CONCURRENT mode
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07008668
8669 VkBuffer ib;
8670 vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
8671
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008672 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06008673 vkDestroyBuffer(m_device->device(), ib, NULL);
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07008674}
8675
Karl Schultz6addd812016-02-02 17:17:23 -07008676TEST_F(VkLayerTest, ExecuteCommandsPrimaryCB) {
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -06008677TEST_DESCRIPTION("Attempt vkCmdExecuteCommands with a primary command buffer"
Tobin Ehlis0c94db02016-07-19 10:49:32 -06008678 " (should only be secondary)");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008679
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06008680 ASSERT_NO_FATAL_FAILURE(InitState());
8681 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06008682
Chris Forbesf29a84f2016-10-06 18:39:28 +13008683 // An empty primary command buffer
8684 VkCommandBufferObj cb(m_device, m_commandPool);
8685 cb.BeginCommandBuffer();
8686 cb.EndCommandBuffer();
Tobin Ehlis0c94db02016-07-19 10:49:32 -06008687
Chris Forbesf29a84f2016-10-06 18:39:28 +13008688 m_commandBuffer->BeginCommandBuffer();
8689 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
8690 VkCommandBuffer handle = cb.handle();
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06008691
Chris Forbesf29a84f2016-10-06 18:39:28 +13008692 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdExecuteCommands() called w/ Primary Cmd Buffer ");
8693 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &handle);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008694 m_errorMonitor->VerifyFound();
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06008695}
8696
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008697TEST_F(VkLayerTest, DSUsageBitsErrors) {
8698 TEST_DESCRIPTION("Attempt to update descriptor sets for images and buffers "
8699 "that do not have correct usage bits sets.");
8700 VkResult err;
8701
8702 ASSERT_NO_FATAL_FAILURE(InitState());
8703 VkDescriptorPoolSize ds_type_count[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
8704 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
8705 ds_type_count[i].type = VkDescriptorType(i);
8706 ds_type_count[i].descriptorCount = 1;
8707 }
8708 VkDescriptorPoolCreateInfo ds_pool_ci = {};
8709 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8710 ds_pool_ci.pNext = NULL;
8711 ds_pool_ci.maxSets = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
8712 ds_pool_ci.poolSizeCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
8713 ds_pool_ci.pPoolSizes = ds_type_count;
8714
8715 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008716 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008717 ASSERT_VK_SUCCESS(err);
8718
8719 // Create 10 layouts where each has a single descriptor of different type
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008720 VkDescriptorSetLayoutBinding dsl_binding[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008721 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
8722 dsl_binding[i].binding = 0;
8723 dsl_binding[i].descriptorType = VkDescriptorType(i);
8724 dsl_binding[i].descriptorCount = 1;
8725 dsl_binding[i].stageFlags = VK_SHADER_STAGE_ALL;
8726 dsl_binding[i].pImmutableSamplers = NULL;
8727 }
8728
8729 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
8730 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8731 ds_layout_ci.pNext = NULL;
8732 ds_layout_ci.bindingCount = 1;
8733 VkDescriptorSetLayout ds_layouts[VK_DESCRIPTOR_TYPE_RANGE_SIZE];
8734 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
8735 ds_layout_ci.pBindings = dsl_binding + i;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008736 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, ds_layouts + i);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008737 ASSERT_VK_SUCCESS(err);
8738 }
8739 VkDescriptorSet descriptor_sets[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
8740 VkDescriptorSetAllocateInfo alloc_info = {};
8741 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
8742 alloc_info.descriptorSetCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
8743 alloc_info.descriptorPool = ds_pool;
8744 alloc_info.pSetLayouts = ds_layouts;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008745 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptor_sets);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008746 ASSERT_VK_SUCCESS(err);
8747
8748 // Create a buffer & bufferView to be used for invalid updates
8749 VkBufferCreateInfo buff_ci = {};
8750 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
8751 // This usage is not valid for any descriptor type
8752 buff_ci.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
8753 buff_ci.size = 256;
8754 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
8755 VkBuffer buffer;
8756 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
8757 ASSERT_VK_SUCCESS(err);
8758
8759 VkBufferViewCreateInfo buff_view_ci = {};
8760 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
8761 buff_view_ci.buffer = buffer;
8762 buff_view_ci.format = VK_FORMAT_R8_UNORM;
8763 buff_view_ci.range = VK_WHOLE_SIZE;
8764 VkBufferView buff_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008765 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buff_view);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008766 ASSERT_VK_SUCCESS(err);
8767
8768 // Create an image to be used for invalid updates
8769 VkImageCreateInfo image_ci = {};
8770 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
8771 image_ci.imageType = VK_IMAGE_TYPE_2D;
8772 image_ci.format = VK_FORMAT_R8G8B8A8_UNORM;
8773 image_ci.extent.width = 64;
8774 image_ci.extent.height = 64;
8775 image_ci.extent.depth = 1;
8776 image_ci.mipLevels = 1;
8777 image_ci.arrayLayers = 1;
8778 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
8779 image_ci.tiling = VK_IMAGE_TILING_LINEAR;
8780 image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
8781 // This usage is not valid for any descriptor type
8782 image_ci.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
8783 image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
8784 VkImage image;
8785 err = vkCreateImage(m_device->device(), &image_ci, NULL, &image);
8786 ASSERT_VK_SUCCESS(err);
8787 // Bind memory to image
8788 VkMemoryRequirements mem_reqs;
8789 VkDeviceMemory image_mem;
8790 bool pass;
8791 VkMemoryAllocateInfo mem_alloc = {};
8792 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
8793 mem_alloc.pNext = NULL;
8794 mem_alloc.allocationSize = 0;
8795 mem_alloc.memoryTypeIndex = 0;
8796 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
8797 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008798 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008799 ASSERT_TRUE(pass);
8800 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
8801 ASSERT_VK_SUCCESS(err);
8802 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
8803 ASSERT_VK_SUCCESS(err);
8804 // Now create view for image
8805 VkImageViewCreateInfo image_view_ci = {};
8806 image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
8807 image_view_ci.image = image;
8808 image_view_ci.format = VK_FORMAT_R8G8B8A8_UNORM;
8809 image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D;
8810 image_view_ci.subresourceRange.layerCount = 1;
8811 image_view_ci.subresourceRange.baseArrayLayer = 0;
8812 image_view_ci.subresourceRange.levelCount = 1;
8813 image_view_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8814 VkImageView image_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008815 err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, &image_view);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008816 ASSERT_VK_SUCCESS(err);
8817
8818 VkDescriptorBufferInfo buff_info = {};
8819 buff_info.buffer = buffer;
8820 VkDescriptorImageInfo img_info = {};
8821 img_info.imageView = image_view;
8822 VkWriteDescriptorSet descriptor_write = {};
8823 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
8824 descriptor_write.dstBinding = 0;
8825 descriptor_write.descriptorCount = 1;
8826 descriptor_write.pTexelBufferView = &buff_view;
8827 descriptor_write.pBufferInfo = &buff_info;
8828 descriptor_write.pImageInfo = &img_info;
8829
8830 // These error messages align with VkDescriptorType struct
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008831 const char *error_msgs[] = {"", // placeholder, no error for SAMPLER descriptor
8832 " does not have VK_IMAGE_USAGE_SAMPLED_BIT set.",
8833 " does not have VK_IMAGE_USAGE_SAMPLED_BIT set.",
8834 " does not have VK_IMAGE_USAGE_STORAGE_BIT set.",
8835 " does not have VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT set.",
8836 " does not have VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT set.",
8837 " does not have VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT set.",
8838 " does not have VK_BUFFER_USAGE_STORAGE_BUFFER_BIT set.",
8839 " does not have VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT set.",
8840 " does not have VK_BUFFER_USAGE_STORAGE_BUFFER_BIT set.",
8841 " does not have VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT set."};
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008842 // Start loop at 1 as SAMPLER desc type has no usage bit error
8843 for (uint32_t i = 1; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
8844 descriptor_write.descriptorType = VkDescriptorType(i);
8845 descriptor_write.dstSet = descriptor_sets[i];
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008846 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, error_msgs[i]);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008847
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008848 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008849
8850 m_errorMonitor->VerifyFound();
8851 vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[i], NULL);
8852 }
8853 vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[0], NULL);
8854 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06008855 vkFreeMemory(m_device->device(), image_mem, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008856 vkDestroyImageView(m_device->device(), image_view, NULL);
8857 vkDestroyBuffer(m_device->device(), buffer, NULL);
8858 vkDestroyBufferView(m_device->device(), buff_view, NULL);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008859 vkFreeDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_TYPE_RANGE_SIZE, descriptor_sets);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008860 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
8861}
8862
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008863TEST_F(VkLayerTest, DSBufferInfoErrors) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008864 TEST_DESCRIPTION("Attempt to update buffer descriptor set that has incorrect "
8865 "parameters in VkDescriptorBufferInfo struct. This includes:\n"
8866 "1. offset value greater than buffer size\n"
8867 "2. range value of 0\n"
8868 "3. range value greater than buffer (size - offset)");
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008869 VkResult err;
8870
8871 ASSERT_NO_FATAL_FAILURE(InitState());
8872 VkDescriptorPoolSize ds_type_count = {};
8873 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8874 ds_type_count.descriptorCount = 1;
8875
8876 VkDescriptorPoolCreateInfo ds_pool_ci = {};
8877 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8878 ds_pool_ci.pNext = NULL;
8879 ds_pool_ci.maxSets = 1;
8880 ds_pool_ci.poolSizeCount = 1;
8881 ds_pool_ci.pPoolSizes = &ds_type_count;
8882
8883 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008884 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008885 ASSERT_VK_SUCCESS(err);
8886
8887 // Create layout with single uniform buffer descriptor
8888 VkDescriptorSetLayoutBinding dsl_binding = {};
8889 dsl_binding.binding = 0;
8890 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8891 dsl_binding.descriptorCount = 1;
8892 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8893 dsl_binding.pImmutableSamplers = NULL;
8894
8895 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
8896 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8897 ds_layout_ci.pNext = NULL;
8898 ds_layout_ci.bindingCount = 1;
8899 ds_layout_ci.pBindings = &dsl_binding;
8900 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008901 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008902 ASSERT_VK_SUCCESS(err);
8903
8904 VkDescriptorSet descriptor_set = {};
8905 VkDescriptorSetAllocateInfo alloc_info = {};
8906 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
8907 alloc_info.descriptorSetCount = 1;
8908 alloc_info.descriptorPool = ds_pool;
8909 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008910 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008911 ASSERT_VK_SUCCESS(err);
8912
8913 // Create a buffer to be used for invalid updates
8914 VkBufferCreateInfo buff_ci = {};
8915 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
8916 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
8917 buff_ci.size = 256;
8918 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
8919 VkBuffer buffer;
8920 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
8921 ASSERT_VK_SUCCESS(err);
8922 // Have to bind memory to buffer before descriptor update
8923 VkMemoryAllocateInfo mem_alloc = {};
8924 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
8925 mem_alloc.pNext = NULL;
8926 mem_alloc.allocationSize = 256;
8927 mem_alloc.memoryTypeIndex = 0;
8928
8929 VkMemoryRequirements mem_reqs;
8930 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008931 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008932 if (!pass) {
8933 vkDestroyBuffer(m_device->device(), buffer, NULL);
8934 return;
8935 }
8936
8937 VkDeviceMemory mem;
8938 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
8939 ASSERT_VK_SUCCESS(err);
8940 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
8941 ASSERT_VK_SUCCESS(err);
8942
8943 VkDescriptorBufferInfo buff_info = {};
8944 buff_info.buffer = buffer;
8945 // First make offset 1 larger than buffer size
8946 buff_info.offset = 257;
8947 buff_info.range = VK_WHOLE_SIZE;
8948 VkWriteDescriptorSet descriptor_write = {};
8949 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
8950 descriptor_write.dstBinding = 0;
8951 descriptor_write.descriptorCount = 1;
8952 descriptor_write.pTexelBufferView = nullptr;
8953 descriptor_write.pBufferInfo = &buff_info;
8954 descriptor_write.pImageInfo = nullptr;
8955
8956 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8957 descriptor_write.dstSet = descriptor_set;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008958 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " offset of 257 is greater than buffer ");
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008959
8960 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8961
8962 m_errorMonitor->VerifyFound();
8963 // Now cause error due to range of 0
8964 buff_info.offset = 0;
8965 buff_info.range = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008966 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8967 " range is not VK_WHOLE_SIZE and is zero, which is not allowed.");
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008968
8969 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8970
8971 m_errorMonitor->VerifyFound();
8972 // Now cause error due to range exceeding buffer size - offset
8973 buff_info.offset = 128;
8974 buff_info.range = 200;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008975 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 -06008976
8977 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8978
8979 m_errorMonitor->VerifyFound();
Mark Lobodzinski4bb54092016-07-06 14:27:19 -06008980 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008981 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8982 vkDestroyBuffer(m_device->device(), buffer, NULL);
8983 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
8984 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
8985}
8986
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008987TEST_F(VkLayerTest, DSAspectBitsErrors) {
8988 // TODO : Initially only catching case where DEPTH & STENCIL aspect bits
8989 // are set, but could expand this test to hit more cases.
8990 TEST_DESCRIPTION("Attempt to update descriptor sets for images "
8991 "that do not have correct aspect bits sets.");
8992 VkResult err;
8993
8994 ASSERT_NO_FATAL_FAILURE(InitState());
8995 VkDescriptorPoolSize ds_type_count = {};
8996 ds_type_count.type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
8997 ds_type_count.descriptorCount = 1;
8998
8999 VkDescriptorPoolCreateInfo ds_pool_ci = {};
9000 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9001 ds_pool_ci.pNext = NULL;
9002 ds_pool_ci.maxSets = 5;
9003 ds_pool_ci.poolSizeCount = 1;
9004 ds_pool_ci.pPoolSizes = &ds_type_count;
9005
9006 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009007 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009008 ASSERT_VK_SUCCESS(err);
9009
9010 VkDescriptorSetLayoutBinding dsl_binding = {};
9011 dsl_binding.binding = 0;
9012 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
9013 dsl_binding.descriptorCount = 1;
9014 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9015 dsl_binding.pImmutableSamplers = NULL;
9016
9017 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9018 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9019 ds_layout_ci.pNext = NULL;
9020 ds_layout_ci.bindingCount = 1;
9021 ds_layout_ci.pBindings = &dsl_binding;
9022 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009023 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009024 ASSERT_VK_SUCCESS(err);
9025
9026 VkDescriptorSet descriptor_set = {};
9027 VkDescriptorSetAllocateInfo alloc_info = {};
9028 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
9029 alloc_info.descriptorSetCount = 1;
9030 alloc_info.descriptorPool = ds_pool;
9031 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009032 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009033 ASSERT_VK_SUCCESS(err);
9034
9035 // Create an image to be used for invalid updates
9036 VkImageCreateInfo image_ci = {};
9037 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
9038 image_ci.imageType = VK_IMAGE_TYPE_2D;
9039 image_ci.format = VK_FORMAT_D24_UNORM_S8_UINT;
9040 image_ci.extent.width = 64;
9041 image_ci.extent.height = 64;
9042 image_ci.extent.depth = 1;
9043 image_ci.mipLevels = 1;
9044 image_ci.arrayLayers = 1;
9045 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
9046 image_ci.tiling = VK_IMAGE_TILING_LINEAR;
9047 image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
9048 image_ci.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
9049 image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
9050 VkImage image;
9051 err = vkCreateImage(m_device->device(), &image_ci, NULL, &image);
9052 ASSERT_VK_SUCCESS(err);
9053 // Bind memory to image
9054 VkMemoryRequirements mem_reqs;
9055 VkDeviceMemory image_mem;
9056 bool pass;
9057 VkMemoryAllocateInfo mem_alloc = {};
9058 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
9059 mem_alloc.pNext = NULL;
9060 mem_alloc.allocationSize = 0;
9061 mem_alloc.memoryTypeIndex = 0;
9062 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
9063 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009064 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009065 ASSERT_TRUE(pass);
9066 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
9067 ASSERT_VK_SUCCESS(err);
9068 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
9069 ASSERT_VK_SUCCESS(err);
9070 // Now create view for image
9071 VkImageViewCreateInfo image_view_ci = {};
9072 image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
9073 image_view_ci.image = image;
9074 image_view_ci.format = VK_FORMAT_D24_UNORM_S8_UINT;
9075 image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D;
9076 image_view_ci.subresourceRange.layerCount = 1;
9077 image_view_ci.subresourceRange.baseArrayLayer = 0;
9078 image_view_ci.subresourceRange.levelCount = 1;
9079 // Setting both depth & stencil aspect bits is illegal for descriptor
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009080 image_view_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009081
9082 VkImageView image_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009083 err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, &image_view);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009084 ASSERT_VK_SUCCESS(err);
9085
9086 VkDescriptorImageInfo img_info = {};
9087 img_info.imageView = image_view;
9088 VkWriteDescriptorSet descriptor_write = {};
9089 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
9090 descriptor_write.dstBinding = 0;
9091 descriptor_write.descriptorCount = 1;
9092 descriptor_write.pTexelBufferView = NULL;
9093 descriptor_write.pBufferInfo = NULL;
9094 descriptor_write.pImageInfo = &img_info;
9095 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
9096 descriptor_write.dstSet = descriptor_set;
9097 const char *error_msg = " please only set either VK_IMAGE_ASPECT_DEPTH_BIT "
9098 "or VK_IMAGE_ASPECT_STENCIL_BIT ";
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009099 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, error_msg);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009100
9101 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9102
9103 m_errorMonitor->VerifyFound();
9104 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9105 vkDestroyImage(m_device->device(), image, NULL);
9106 vkFreeMemory(m_device->device(), image_mem, NULL);
9107 vkDestroyImageView(m_device->device(), image_view, NULL);
9108 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
9109 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9110}
9111
Karl Schultz6addd812016-02-02 17:17:23 -07009112TEST_F(VkLayerTest, DSTypeMismatch) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009113 // Create DS w/ layout of one type and attempt Update w/ mis-matched type
Karl Schultz6addd812016-02-02 17:17:23 -07009114 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009115
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009116 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9117 " binding #0 with type VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER but update "
9118 "type is VK_DESCRIPTOR_TYPE_SAMPLER");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009119
Tobin Ehlis3b780662015-05-28 12:11:26 -06009120 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07009121 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009122 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009123 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9124 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009125
9126 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009127 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9128 ds_pool_ci.pNext = NULL;
9129 ds_pool_ci.maxSets = 1;
9130 ds_pool_ci.poolSizeCount = 1;
9131 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06009132
Tobin Ehlis3b780662015-05-28 12:11:26 -06009133 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009134 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009135 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -06009136 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009137 dsl_binding.binding = 0;
9138 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9139 dsl_binding.descriptorCount = 1;
9140 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9141 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009142
Tony Barboureb254902015-07-15 12:50:33 -06009143 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009144 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9145 ds_layout_ci.pNext = NULL;
9146 ds_layout_ci.bindingCount = 1;
9147 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06009148
Tobin Ehlis3b780662015-05-28 12:11:26 -06009149 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009150 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009151 ASSERT_VK_SUCCESS(err);
9152
9153 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009154 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009155 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009156 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009157 alloc_info.descriptorPool = ds_pool;
9158 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009159 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009160 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009161
Tobin Ehlis30db8f82016-05-05 08:19:48 -06009162 VkSamplerCreateInfo sampler_ci = {};
9163 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9164 sampler_ci.pNext = NULL;
9165 sampler_ci.magFilter = VK_FILTER_NEAREST;
9166 sampler_ci.minFilter = VK_FILTER_NEAREST;
9167 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9168 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9169 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9170 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9171 sampler_ci.mipLodBias = 1.0;
9172 sampler_ci.anisotropyEnable = VK_FALSE;
9173 sampler_ci.maxAnisotropy = 1;
9174 sampler_ci.compareEnable = VK_FALSE;
9175 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9176 sampler_ci.minLod = 1.0;
9177 sampler_ci.maxLod = 1.0;
9178 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9179 sampler_ci.unnormalizedCoordinates = VK_FALSE;
9180 VkSampler sampler;
9181 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
9182 ASSERT_VK_SUCCESS(err);
9183
9184 VkDescriptorImageInfo info = {};
9185 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009186
9187 VkWriteDescriptorSet descriptor_write;
9188 memset(&descriptor_write, 0, sizeof(descriptor_write));
9189 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009190 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009191 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009192 // This is a mismatched type for the layout which expects BUFFER
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009193 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06009194 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009195
9196 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9197
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009198 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009199
Chia-I Wuf7458c52015-10-26 21:10:41 +08009200 vkDestroySampler(m_device->device(), sampler, NULL);
9201 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9202 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009203}
9204
Karl Schultz6addd812016-02-02 17:17:23 -07009205TEST_F(VkLayerTest, DSUpdateOutOfBounds) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009206 // For overlapping Update, have arrayIndex exceed that of layout
Karl Schultz6addd812016-02-02 17:17:23 -07009207 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009208
Tobin Ehlisf922ef82016-11-30 10:19:14 -07009209 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00938);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009210
Tobin Ehlis3b780662015-05-28 12:11:26 -06009211 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07009212 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009213 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009214 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9215 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009216
9217 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009218 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9219 ds_pool_ci.pNext = NULL;
9220 ds_pool_ci.maxSets = 1;
9221 ds_pool_ci.poolSizeCount = 1;
9222 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06009223
Tobin Ehlis3b780662015-05-28 12:11:26 -06009224 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009225 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009226 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009227
Tony Barboureb254902015-07-15 12:50:33 -06009228 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009229 dsl_binding.binding = 0;
9230 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9231 dsl_binding.descriptorCount = 1;
9232 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9233 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -06009234
9235 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009236 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9237 ds_layout_ci.pNext = NULL;
9238 ds_layout_ci.bindingCount = 1;
9239 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06009240
Tobin Ehlis3b780662015-05-28 12:11:26 -06009241 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009242 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009243 ASSERT_VK_SUCCESS(err);
9244
9245 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009246 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009247 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009248 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009249 alloc_info.descriptorPool = ds_pool;
9250 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009251 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009252 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009253
Tobin Ehlis30db8f82016-05-05 08:19:48 -06009254 // Correctly update descriptor to avoid "NOT_UPDATED" error
9255 VkDescriptorBufferInfo buff_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009256 buff_info.buffer = VkBuffer(0); // Don't care about buffer handle for this test
Tobin Ehlis30db8f82016-05-05 08:19:48 -06009257 buff_info.offset = 0;
9258 buff_info.range = 1024;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009259
9260 VkWriteDescriptorSet descriptor_write;
9261 memset(&descriptor_write, 0, sizeof(descriptor_write));
9262 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009263 descriptor_write.dstSet = descriptorSet;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009264 descriptor_write.dstArrayElement = 1; /* This index out of bounds for the update */
Chia-I Wud50a7d72015-10-26 20:48:51 +08009265 descriptor_write.descriptorCount = 1;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06009266 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9267 descriptor_write.pBufferInfo = &buff_info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009268
9269 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9270
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009271 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009272
Chia-I Wuf7458c52015-10-26 21:10:41 +08009273 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9274 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009275}
9276
Karl Schultz6addd812016-02-02 17:17:23 -07009277TEST_F(VkLayerTest, InvalidDSUpdateIndex) {
Tobin Ehlisc8d352d2016-11-21 10:33:40 -07009278 // Create layout w/ count of 1 and attempt update to that layout w/ binding index 2
Karl Schultz6addd812016-02-02 17:17:23 -07009279 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009280
Tobin Ehlisc8d352d2016-11-21 10:33:40 -07009281 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00936);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009282
Tobin Ehlis3b780662015-05-28 12:11:26 -06009283 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07009284 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009285 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009286 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9287 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009288
9289 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009290 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9291 ds_pool_ci.pNext = NULL;
9292 ds_pool_ci.maxSets = 1;
9293 ds_pool_ci.poolSizeCount = 1;
9294 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06009295
Tobin Ehlis3b780662015-05-28 12:11:26 -06009296 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009297 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009298 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009299
Tony Barboureb254902015-07-15 12:50:33 -06009300 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009301 dsl_binding.binding = 0;
9302 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9303 dsl_binding.descriptorCount = 1;
9304 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9305 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -06009306
9307 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009308 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9309 ds_layout_ci.pNext = NULL;
9310 ds_layout_ci.bindingCount = 1;
9311 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009312 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009313 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009314 ASSERT_VK_SUCCESS(err);
9315
9316 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009317 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009318 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009319 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009320 alloc_info.descriptorPool = ds_pool;
9321 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009322 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009323 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009324
Tony Barboureb254902015-07-15 12:50:33 -06009325 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009326 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9327 sampler_ci.pNext = NULL;
9328 sampler_ci.magFilter = VK_FILTER_NEAREST;
9329 sampler_ci.minFilter = VK_FILTER_NEAREST;
9330 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9331 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9332 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9333 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9334 sampler_ci.mipLodBias = 1.0;
9335 sampler_ci.anisotropyEnable = VK_FALSE;
9336 sampler_ci.maxAnisotropy = 1;
9337 sampler_ci.compareEnable = VK_FALSE;
9338 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9339 sampler_ci.minLod = 1.0;
9340 sampler_ci.maxLod = 1.0;
9341 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9342 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tony Barboureb254902015-07-15 12:50:33 -06009343
Tobin Ehlis3b780662015-05-28 12:11:26 -06009344 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009345 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009346 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009347
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06009348 VkDescriptorImageInfo info = {};
9349 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009350
9351 VkWriteDescriptorSet descriptor_write;
9352 memset(&descriptor_write, 0, sizeof(descriptor_write));
9353 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009354 descriptor_write.dstSet = descriptorSet;
9355 descriptor_write.dstBinding = 2;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009356 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009357 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009358 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06009359 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009360
9361 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9362
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009363 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009364
Chia-I Wuf7458c52015-10-26 21:10:41 +08009365 vkDestroySampler(m_device->device(), sampler, NULL);
9366 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9367 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009368}
9369
Tobin Ehlise202b2d2016-11-21 10:36:16 -07009370TEST_F(VkLayerTest, DSUpdateEmptyBinding) {
9371 // Create layout w/ empty binding and attempt to update it
9372 VkResult err;
9373
9374 ASSERT_NO_FATAL_FAILURE(InitState());
9375
9376 VkDescriptorPoolSize ds_type_count = {};
9377 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
9378 ds_type_count.descriptorCount = 1;
9379
9380 VkDescriptorPoolCreateInfo ds_pool_ci = {};
9381 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9382 ds_pool_ci.pNext = NULL;
9383 ds_pool_ci.maxSets = 1;
9384 ds_pool_ci.poolSizeCount = 1;
9385 ds_pool_ci.pPoolSizes = &ds_type_count;
9386
9387 VkDescriptorPool ds_pool;
9388 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
9389 ASSERT_VK_SUCCESS(err);
9390
9391 VkDescriptorSetLayoutBinding dsl_binding = {};
9392 dsl_binding.binding = 0;
9393 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9394 dsl_binding.descriptorCount = 0;
9395 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9396 dsl_binding.pImmutableSamplers = NULL;
9397
9398 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9399 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9400 ds_layout_ci.pNext = NULL;
9401 ds_layout_ci.bindingCount = 1;
9402 ds_layout_ci.pBindings = &dsl_binding;
9403 VkDescriptorSetLayout ds_layout;
9404 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
9405 ASSERT_VK_SUCCESS(err);
9406
9407 VkDescriptorSet descriptor_set;
9408 VkDescriptorSetAllocateInfo alloc_info = {};
9409 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
9410 alloc_info.descriptorSetCount = 1;
9411 alloc_info.descriptorPool = ds_pool;
9412 alloc_info.pSetLayouts = &ds_layout;
9413 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
9414 ASSERT_VK_SUCCESS(err);
9415
9416 VkSamplerCreateInfo sampler_ci = {};
9417 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9418 sampler_ci.magFilter = VK_FILTER_NEAREST;
9419 sampler_ci.minFilter = VK_FILTER_NEAREST;
9420 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9421 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9422 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9423 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9424 sampler_ci.mipLodBias = 1.0;
9425 sampler_ci.maxAnisotropy = 1;
9426 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9427 sampler_ci.minLod = 1.0;
9428 sampler_ci.maxLod = 1.0;
9429 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9430
9431 VkSampler sampler;
9432 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
9433 ASSERT_VK_SUCCESS(err);
9434
9435 VkDescriptorImageInfo info = {};
9436 info.sampler = sampler;
9437
9438 VkWriteDescriptorSet descriptor_write;
9439 memset(&descriptor_write, 0, sizeof(descriptor_write));
9440 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
9441 descriptor_write.dstSet = descriptor_set;
9442 descriptor_write.dstBinding = 0;
9443 descriptor_write.descriptorCount = 1; // Lie here to avoid parameter_validation error
9444 // This is the wrong type, but empty binding error will be flagged first
9445 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9446 descriptor_write.pImageInfo = &info;
9447
9448 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02348);
9449 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9450 m_errorMonitor->VerifyFound();
9451
9452 vkDestroySampler(m_device->device(), sampler, NULL);
9453 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9454 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9455}
9456
Karl Schultz6addd812016-02-02 17:17:23 -07009457TEST_F(VkLayerTest, InvalidDSUpdateStruct) {
9458 // Call UpdateDS w/ struct type other than valid VK_STRUCTUR_TYPE_UPDATE_*
9459 // types
9460 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009461
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009462 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 -06009463
Tobin Ehlis3b780662015-05-28 12:11:26 -06009464 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski209b5292015-09-17 09:44:05 -06009465
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009466 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009467 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9468 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009469
9470 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009471 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9472 ds_pool_ci.pNext = NULL;
9473 ds_pool_ci.maxSets = 1;
9474 ds_pool_ci.poolSizeCount = 1;
9475 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06009476
Tobin Ehlis3b780662015-05-28 12:11:26 -06009477 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009478 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009479 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -06009480 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009481 dsl_binding.binding = 0;
9482 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9483 dsl_binding.descriptorCount = 1;
9484 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9485 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009486
Tony Barboureb254902015-07-15 12:50:33 -06009487 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009488 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9489 ds_layout_ci.pNext = NULL;
9490 ds_layout_ci.bindingCount = 1;
9491 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06009492
Tobin Ehlis3b780662015-05-28 12:11:26 -06009493 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009494 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009495 ASSERT_VK_SUCCESS(err);
9496
9497 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009498 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009499 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009500 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009501 alloc_info.descriptorPool = ds_pool;
9502 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009503 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009504 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009505
Tony Barboureb254902015-07-15 12:50:33 -06009506 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009507 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9508 sampler_ci.pNext = NULL;
9509 sampler_ci.magFilter = VK_FILTER_NEAREST;
9510 sampler_ci.minFilter = VK_FILTER_NEAREST;
9511 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9512 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9513 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9514 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9515 sampler_ci.mipLodBias = 1.0;
9516 sampler_ci.anisotropyEnable = VK_FALSE;
9517 sampler_ci.maxAnisotropy = 1;
9518 sampler_ci.compareEnable = VK_FALSE;
9519 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9520 sampler_ci.minLod = 1.0;
9521 sampler_ci.maxLod = 1.0;
9522 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9523 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009524 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009525 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009526 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009527
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06009528 VkDescriptorImageInfo info = {};
9529 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009530
9531 VkWriteDescriptorSet descriptor_write;
9532 memset(&descriptor_write, 0, sizeof(descriptor_write));
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009533 descriptor_write.sType = (VkStructureType)0x99999999; /* Intentionally broken struct type */
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009534 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009535 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009536 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009537 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06009538 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009539
9540 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9541
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009542 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009543
Chia-I Wuf7458c52015-10-26 21:10:41 +08009544 vkDestroySampler(m_device->device(), sampler, NULL);
9545 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9546 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009547}
9548
Karl Schultz6addd812016-02-02 17:17:23 -07009549TEST_F(VkLayerTest, SampleDescriptorUpdateError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009550 // Create a single Sampler descriptor and send it an invalid Sampler
Karl Schultz6addd812016-02-02 17:17:23 -07009551 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009552
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009553 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9554 "Attempted write update to sampler descriptor with invalid sampler");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009555
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009556 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07009557 // TODO : Farm Descriptor setup code to helper function(s) to reduce copied
9558 // code
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009559 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009560 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
9561 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009562
9563 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009564 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9565 ds_pool_ci.pNext = NULL;
9566 ds_pool_ci.maxSets = 1;
9567 ds_pool_ci.poolSizeCount = 1;
9568 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009569
9570 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009571 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009572 ASSERT_VK_SUCCESS(err);
9573
9574 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009575 dsl_binding.binding = 0;
9576 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9577 dsl_binding.descriptorCount = 1;
9578 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9579 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009580
9581 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009582 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9583 ds_layout_ci.pNext = NULL;
9584 ds_layout_ci.bindingCount = 1;
9585 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009586 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009587 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009588 ASSERT_VK_SUCCESS(err);
9589
9590 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009591 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009592 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009593 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009594 alloc_info.descriptorPool = ds_pool;
9595 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009596 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009597 ASSERT_VK_SUCCESS(err);
9598
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009599 VkSampler sampler = (VkSampler)((size_t)0xbaadbeef); // Sampler with invalid handle
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009600
9601 VkDescriptorImageInfo descriptor_info;
9602 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
9603 descriptor_info.sampler = sampler;
9604
9605 VkWriteDescriptorSet descriptor_write;
9606 memset(&descriptor_write, 0, sizeof(descriptor_write));
9607 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009608 descriptor_write.dstSet = descriptorSet;
9609 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009610 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009611 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9612 descriptor_write.pImageInfo = &descriptor_info;
9613
9614 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9615
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009616 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009617
Chia-I Wuf7458c52015-10-26 21:10:41 +08009618 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9619 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009620}
9621
Karl Schultz6addd812016-02-02 17:17:23 -07009622TEST_F(VkLayerTest, ImageViewDescriptorUpdateError) {
9623 // Create a single combined Image/Sampler descriptor and send it an invalid
9624 // imageView
9625 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009626
Karl Schultzf78bcdd2016-11-30 12:36:01 -07009627 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00943);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009628
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009629 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009630 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009631 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
9632 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009633
9634 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009635 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9636 ds_pool_ci.pNext = NULL;
9637 ds_pool_ci.maxSets = 1;
9638 ds_pool_ci.poolSizeCount = 1;
9639 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009640
9641 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009642 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009643 ASSERT_VK_SUCCESS(err);
9644
9645 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009646 dsl_binding.binding = 0;
9647 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
9648 dsl_binding.descriptorCount = 1;
9649 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9650 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009651
9652 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009653 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9654 ds_layout_ci.pNext = NULL;
9655 ds_layout_ci.bindingCount = 1;
9656 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009657 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009658 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009659 ASSERT_VK_SUCCESS(err);
9660
9661 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009662 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009663 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009664 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009665 alloc_info.descriptorPool = ds_pool;
9666 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009667 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009668 ASSERT_VK_SUCCESS(err);
9669
9670 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009671 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9672 sampler_ci.pNext = NULL;
9673 sampler_ci.magFilter = VK_FILTER_NEAREST;
9674 sampler_ci.minFilter = VK_FILTER_NEAREST;
9675 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9676 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9677 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9678 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9679 sampler_ci.mipLodBias = 1.0;
9680 sampler_ci.anisotropyEnable = VK_FALSE;
9681 sampler_ci.maxAnisotropy = 1;
9682 sampler_ci.compareEnable = VK_FALSE;
9683 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9684 sampler_ci.minLod = 1.0;
9685 sampler_ci.maxLod = 1.0;
9686 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9687 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009688
9689 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009690 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009691 ASSERT_VK_SUCCESS(err);
9692
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009693 VkImageView view = (VkImageView)((size_t)0xbaadbeef); // invalid imageView object
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009694
9695 VkDescriptorImageInfo descriptor_info;
9696 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
9697 descriptor_info.sampler = sampler;
9698 descriptor_info.imageView = view;
9699
9700 VkWriteDescriptorSet descriptor_write;
9701 memset(&descriptor_write, 0, sizeof(descriptor_write));
9702 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009703 descriptor_write.dstSet = descriptorSet;
9704 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009705 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009706 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
9707 descriptor_write.pImageInfo = &descriptor_info;
9708
9709 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9710
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009711 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009712
Chia-I Wuf7458c52015-10-26 21:10:41 +08009713 vkDestroySampler(m_device->device(), sampler, NULL);
9714 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9715 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009716}
9717
Karl Schultz6addd812016-02-02 17:17:23 -07009718TEST_F(VkLayerTest, CopyDescriptorUpdateErrors) {
9719 // Create DS w/ layout of 2 types, write update 1 and attempt to copy-update
9720 // into the other
9721 VkResult err;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009722
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009723 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " binding #1 with type "
9724 "VK_DESCRIPTOR_TYPE_SAMPLER. Types do "
9725 "not match.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009726
Tobin Ehlis04356f92015-10-27 16:35:27 -06009727 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07009728 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009729 VkDescriptorPoolSize ds_type_count[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009730 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9731 ds_type_count[0].descriptorCount = 1;
9732 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLER;
9733 ds_type_count[1].descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009734
9735 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009736 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9737 ds_pool_ci.pNext = NULL;
9738 ds_pool_ci.maxSets = 1;
9739 ds_pool_ci.poolSizeCount = 2;
9740 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009741
9742 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009743 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis04356f92015-10-27 16:35:27 -06009744 ASSERT_VK_SUCCESS(err);
9745 VkDescriptorSetLayoutBinding dsl_binding[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009746 dsl_binding[0].binding = 0;
9747 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9748 dsl_binding[0].descriptorCount = 1;
9749 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
9750 dsl_binding[0].pImmutableSamplers = NULL;
9751 dsl_binding[1].binding = 1;
9752 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9753 dsl_binding[1].descriptorCount = 1;
9754 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
9755 dsl_binding[1].pImmutableSamplers = NULL;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009756
9757 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009758 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9759 ds_layout_ci.pNext = NULL;
9760 ds_layout_ci.bindingCount = 2;
9761 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009762
9763 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009764 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis04356f92015-10-27 16:35:27 -06009765 ASSERT_VK_SUCCESS(err);
9766
9767 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009768 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009769 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009770 alloc_info.descriptorSetCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009771 alloc_info.descriptorPool = ds_pool;
9772 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009773 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis04356f92015-10-27 16:35:27 -06009774 ASSERT_VK_SUCCESS(err);
9775
9776 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009777 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9778 sampler_ci.pNext = NULL;
9779 sampler_ci.magFilter = VK_FILTER_NEAREST;
9780 sampler_ci.minFilter = VK_FILTER_NEAREST;
9781 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9782 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9783 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9784 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9785 sampler_ci.mipLodBias = 1.0;
9786 sampler_ci.anisotropyEnable = VK_FALSE;
9787 sampler_ci.maxAnisotropy = 1;
9788 sampler_ci.compareEnable = VK_FALSE;
9789 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9790 sampler_ci.minLod = 1.0;
9791 sampler_ci.maxLod = 1.0;
9792 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9793 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009794
9795 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009796 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis04356f92015-10-27 16:35:27 -06009797 ASSERT_VK_SUCCESS(err);
9798
9799 VkDescriptorImageInfo info = {};
9800 info.sampler = sampler;
9801
9802 VkWriteDescriptorSet descriptor_write;
9803 memset(&descriptor_write, 0, sizeof(VkWriteDescriptorSet));
9804 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009805 descriptor_write.dstSet = descriptorSet;
9806 descriptor_write.dstBinding = 1; // SAMPLER binding from layout above
Chia-I Wud50a7d72015-10-26 20:48:51 +08009807 descriptor_write.descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009808 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9809 descriptor_write.pImageInfo = &info;
9810 // This write update should succeed
9811 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9812 // Now perform a copy update that fails due to type mismatch
9813 VkCopyDescriptorSet copy_ds_update;
9814 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
9815 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
9816 copy_ds_update.srcSet = descriptorSet;
Mark Young29927482016-05-04 14:38:51 -06009817 copy_ds_update.srcBinding = 1; // Copy from SAMPLER binding
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009818 copy_ds_update.dstSet = descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -07009819 copy_ds_update.dstBinding = 0; // ERROR : copy to UNIFORM binding
Chia-I Wud50a7d72015-10-26 20:48:51 +08009820 copy_ds_update.descriptorCount = 1; // copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -06009821 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
9822
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009823 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -06009824 // Now perform a copy update that fails due to binding out of bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009825 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 -06009826 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
9827 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
9828 copy_ds_update.srcSet = descriptorSet;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009829 copy_ds_update.srcBinding = 3; // ERROR : Invalid binding for matching layout
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009830 copy_ds_update.dstSet = descriptorSet;
9831 copy_ds_update.dstBinding = 0;
Mark Young29927482016-05-04 14:38:51 -06009832 copy_ds_update.descriptorCount = 1; // Copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -06009833 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
9834
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009835 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009836
Tobin Ehlis04356f92015-10-27 16:35:27 -06009837 // Now perform a copy update that fails due to binding out of bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009838 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " binding#1 with offset index of 1 plus "
9839 "update array offset of 0 and update of "
9840 "5 descriptors oversteps total number "
9841 "of descriptors in set: 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009842
Tobin Ehlis04356f92015-10-27 16:35:27 -06009843 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
9844 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
9845 copy_ds_update.srcSet = descriptorSet;
9846 copy_ds_update.srcBinding = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009847 copy_ds_update.dstSet = descriptorSet;
9848 copy_ds_update.dstBinding = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009849 copy_ds_update.descriptorCount = 5; // ERROR copy 5 descriptors (out of bounds for layout)
Tobin Ehlis04356f92015-10-27 16:35:27 -06009850 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
9851
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009852 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -06009853
Chia-I Wuf7458c52015-10-26 21:10:41 +08009854 vkDestroySampler(m_device->device(), sampler, NULL);
9855 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9856 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis04356f92015-10-27 16:35:27 -06009857}
9858
Karl Schultz6addd812016-02-02 17:17:23 -07009859TEST_F(VkLayerTest, NumSamplesMismatch) {
9860 // Create CommandBuffer where MSAA samples doesn't match RenderPass
9861 // sampleCount
9862 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009863
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009864 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Num samples mismatch! ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009865
Tobin Ehlis3b780662015-05-28 12:11:26 -06009866 ASSERT_NO_FATAL_FAILURE(InitState());
9867 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009868 VkDescriptorPoolSize ds_type_count = {};
Tony Barboureb254902015-07-15 12:50:33 -06009869 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009870 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009871
9872 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009873 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9874 ds_pool_ci.pNext = NULL;
9875 ds_pool_ci.maxSets = 1;
9876 ds_pool_ci.poolSizeCount = 1;
9877 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06009878
Tobin Ehlis3b780662015-05-28 12:11:26 -06009879 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009880 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009881 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009882
Tony Barboureb254902015-07-15 12:50:33 -06009883 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08009884 dsl_binding.binding = 0;
Tony Barboureb254902015-07-15 12:50:33 -06009885 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08009886 dsl_binding.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009887 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9888 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009889
Tony Barboureb254902015-07-15 12:50:33 -06009890 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9891 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9892 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009893 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07009894 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06009895
Tobin Ehlis3b780662015-05-28 12:11:26 -06009896 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009897 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009898 ASSERT_VK_SUCCESS(err);
9899
9900 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009901 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009902 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009903 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009904 alloc_info.descriptorPool = ds_pool;
9905 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009906 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009907 ASSERT_VK_SUCCESS(err);
9908
Tony Barboureb254902015-07-15 12:50:33 -06009909 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009910 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07009911 pipe_ms_state_ci.pNext = NULL;
9912 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
9913 pipe_ms_state_ci.sampleShadingEnable = 0;
9914 pipe_ms_state_ci.minSampleShading = 1.0;
9915 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009916
Tony Barboureb254902015-07-15 12:50:33 -06009917 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009918 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9919 pipeline_layout_ci.pNext = NULL;
9920 pipeline_layout_ci.setLayoutCount = 1;
9921 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009922
9923 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009924 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009925 ASSERT_VK_SUCCESS(err);
9926
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009927 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
9928 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
9929 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -06009930 VkPipelineObj pipe(m_device);
9931 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06009932 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -06009933 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -06009934 pipe.SetMSAA(&pipe_ms_state_ci);
9935 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tobin Ehlis3b780662015-05-28 12:11:26 -06009936
Tony Barbourfe3351b2015-07-28 10:17:20 -06009937 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009938 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis3b780662015-05-28 12:11:26 -06009939
Mark Young29927482016-05-04 14:38:51 -06009940 // Render triangle (the error should trigger on the attempt to draw).
9941 Draw(3, 1, 0, 0);
9942
9943 // Finalize recording of the command buffer
9944 EndCommandBuffer();
9945
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009946 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009947
Chia-I Wuf7458c52015-10-26 21:10:41 +08009948 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9949 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9950 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009951}
Mark Young29927482016-05-04 14:38:51 -06009952
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009953TEST_F(VkLayerTest, RenderPassIncompatible) {
9954 TEST_DESCRIPTION("Hit RenderPass incompatible cases. "
9955 "Initial case is drawing with an active renderpass that's "
Mike Weiblencce7ec72016-10-17 19:33:05 -06009956 "not compatible with the bound pipeline state object's creation renderpass");
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009957 VkResult err;
9958
9959 ASSERT_NO_FATAL_FAILURE(InitState());
9960 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9961
9962 VkDescriptorSetLayoutBinding dsl_binding = {};
9963 dsl_binding.binding = 0;
9964 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9965 dsl_binding.descriptorCount = 1;
9966 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9967 dsl_binding.pImmutableSamplers = NULL;
9968
9969 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9970 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9971 ds_layout_ci.pNext = NULL;
9972 ds_layout_ci.bindingCount = 1;
9973 ds_layout_ci.pBindings = &dsl_binding;
9974
9975 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009976 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009977 ASSERT_VK_SUCCESS(err);
9978
9979 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
9980 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9981 pipeline_layout_ci.pNext = NULL;
9982 pipeline_layout_ci.setLayoutCount = 1;
9983 pipeline_layout_ci.pSetLayouts = &ds_layout;
9984
9985 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009986 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009987 ASSERT_VK_SUCCESS(err);
9988
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009989 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
9990 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
9991 // but add it to be able to run on more devices
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009992 // Create a renderpass that will be incompatible with default renderpass
9993 VkAttachmentReference attach = {};
9994 attach.layout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
9995 VkAttachmentReference color_att = {};
9996 color_att.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
9997 VkSubpassDescription subpass = {};
9998 subpass.inputAttachmentCount = 1;
9999 subpass.pInputAttachments = &attach;
10000 subpass.colorAttachmentCount = 1;
10001 subpass.pColorAttachments = &color_att;
10002 VkRenderPassCreateInfo rpci = {};
10003 rpci.subpassCount = 1;
10004 rpci.pSubpasses = &subpass;
10005 rpci.attachmentCount = 1;
10006 VkAttachmentDescription attach_desc = {};
10007 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
Cody Northropbd16af12016-06-21 09:25:48 -060010008 // Format incompatible with PSO RP color attach format B8G8R8A8_UNORM
10009 attach_desc.format = VK_FORMAT_R8G8B8A8_UNORM;
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010010 rpci.pAttachments = &attach_desc;
10011 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
10012 VkRenderPass rp;
10013 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10014 VkPipelineObj pipe(m_device);
10015 pipe.AddShader(&vs);
10016 pipe.AddShader(&fs);
10017 pipe.AddColorAttachment();
10018 VkViewport view_port = {};
10019 m_viewports.push_back(view_port);
10020 pipe.SetViewport(m_viewports);
10021 VkRect2D rect = {};
10022 m_scissors.push_back(rect);
10023 pipe.SetScissor(m_scissors);
10024 pipe.CreateVKPipeline(pipeline_layout, renderPass());
10025
10026 VkCommandBufferInheritanceInfo cbii = {};
10027 cbii.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
10028 cbii.renderPass = rp;
10029 cbii.subpass = 0;
10030 VkCommandBufferBeginInfo cbbi = {};
10031 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
10032 cbbi.pInheritanceInfo = &cbii;
10033 vkBeginCommandBuffer(m_commandBuffer->handle(), &cbbi);
10034 VkRenderPassBeginInfo rpbi = {};
10035 rpbi.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
10036 rpbi.framebuffer = m_framebuffer;
10037 rpbi.renderPass = rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010038 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
10039 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010040
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010041 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is incompatible w/ gfx pipeline ");
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010042 // Render triangle (the error should trigger on the attempt to draw).
10043 Draw(3, 1, 0, 0);
10044
10045 // Finalize recording of the command buffer
10046 EndCommandBuffer();
10047
10048 m_errorMonitor->VerifyFound();
10049
10050 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10051 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10052 vkDestroyRenderPass(m_device->device(), rp, NULL);
10053}
10054
Mark Youngc89c6312016-03-31 16:03:20 -060010055TEST_F(VkLayerTest, NumBlendAttachMismatch) {
10056 // Create Pipeline where the number of blend attachments doesn't match the
10057 // number of color attachments. In this case, we don't add any color
10058 // blend attachments even though we have a color attachment.
10059 VkResult err;
10060
10061 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010062 "Render pass subpass 0 mismatch with blending state defined and blend state attachment");
Mark Youngc89c6312016-03-31 16:03:20 -060010063
10064 ASSERT_NO_FATAL_FAILURE(InitState());
10065 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10066 VkDescriptorPoolSize ds_type_count = {};
10067 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10068 ds_type_count.descriptorCount = 1;
10069
10070 VkDescriptorPoolCreateInfo ds_pool_ci = {};
10071 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10072 ds_pool_ci.pNext = NULL;
10073 ds_pool_ci.maxSets = 1;
10074 ds_pool_ci.poolSizeCount = 1;
10075 ds_pool_ci.pPoolSizes = &ds_type_count;
10076
10077 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010078 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Mark Youngc89c6312016-03-31 16:03:20 -060010079 ASSERT_VK_SUCCESS(err);
10080
10081 VkDescriptorSetLayoutBinding dsl_binding = {};
10082 dsl_binding.binding = 0;
10083 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10084 dsl_binding.descriptorCount = 1;
10085 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10086 dsl_binding.pImmutableSamplers = NULL;
10087
10088 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10089 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10090 ds_layout_ci.pNext = NULL;
10091 ds_layout_ci.bindingCount = 1;
10092 ds_layout_ci.pBindings = &dsl_binding;
10093
10094 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010095 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Youngc89c6312016-03-31 16:03:20 -060010096 ASSERT_VK_SUCCESS(err);
10097
10098 VkDescriptorSet descriptorSet;
10099 VkDescriptorSetAllocateInfo alloc_info = {};
10100 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
10101 alloc_info.descriptorSetCount = 1;
10102 alloc_info.descriptorPool = ds_pool;
10103 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010104 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Youngc89c6312016-03-31 16:03:20 -060010105 ASSERT_VK_SUCCESS(err);
10106
10107 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010108 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Mark Youngc89c6312016-03-31 16:03:20 -060010109 pipe_ms_state_ci.pNext = NULL;
10110 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
10111 pipe_ms_state_ci.sampleShadingEnable = 0;
10112 pipe_ms_state_ci.minSampleShading = 1.0;
10113 pipe_ms_state_ci.pSampleMask = NULL;
10114
10115 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
10116 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10117 pipeline_layout_ci.pNext = NULL;
10118 pipeline_layout_ci.setLayoutCount = 1;
10119 pipeline_layout_ci.pSetLayouts = &ds_layout;
10120
10121 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010122 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Mark Youngc89c6312016-03-31 16:03:20 -060010123 ASSERT_VK_SUCCESS(err);
10124
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010125 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
10126 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
10127 // but add it to be able to run on more devices
Mark Youngc89c6312016-03-31 16:03:20 -060010128 VkPipelineObj pipe(m_device);
10129 pipe.AddShader(&vs);
10130 pipe.AddShader(&fs);
10131 pipe.SetMSAA(&pipe_ms_state_ci);
10132 pipe.CreateVKPipeline(pipeline_layout, renderPass());
10133
10134 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010135 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Mark Youngc89c6312016-03-31 16:03:20 -060010136
Mark Young29927482016-05-04 14:38:51 -060010137 // Render triangle (the error should trigger on the attempt to draw).
10138 Draw(3, 1, 0, 0);
10139
10140 // Finalize recording of the command buffer
10141 EndCommandBuffer();
10142
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010143 m_errorMonitor->VerifyFound();
Mark Youngc89c6312016-03-31 16:03:20 -060010144
10145 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10146 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10147 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
10148}
Mark Young29927482016-05-04 14:38:51 -060010149
Mark Muellerd4914412016-06-13 17:52:06 -060010150TEST_F(VkLayerTest, MissingClearAttachment) {
10151 TEST_DESCRIPTION("Points to a wrong colorAttachment index in a VkClearAttachment "
10152 "structure passed to vkCmdClearAttachments");
Cody Northropc31a84f2016-08-22 10:41:47 -060010153 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesda6ae6f2016-09-09 14:36:33 +120010154 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbesfa79fc72016-11-01 10:18:12 +130010155 "vkCmdClearAttachments() color attachment index 1 out of range for active subpass 0");
Mark Muellerd4914412016-06-13 17:52:06 -060010156
10157 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailCmdClearAttachments);
10158 m_errorMonitor->VerifyFound();
10159}
10160
Karl Schultz6addd812016-02-02 17:17:23 -070010161TEST_F(VkLayerTest, ClearCmdNoDraw) {
10162 // Create CommandBuffer where we add ClearCmd for FB Color attachment prior
10163 // to issuing a Draw
10164 VkResult err;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010165
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010166 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Mike Weiblencce7ec72016-10-17 19:33:05 -060010167 "vkCmdClearAttachments() issued on command buffer object ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010168
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010169 ASSERT_NO_FATAL_FAILURE(InitState());
10170 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -060010171
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010172 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010173 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10174 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010175
10176 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010177 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10178 ds_pool_ci.pNext = NULL;
10179 ds_pool_ci.maxSets = 1;
10180 ds_pool_ci.poolSizeCount = 1;
10181 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060010182
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010183 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010184 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010185 ASSERT_VK_SUCCESS(err);
10186
Tony Barboureb254902015-07-15 12:50:33 -060010187 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010188 dsl_binding.binding = 0;
10189 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10190 dsl_binding.descriptorCount = 1;
10191 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10192 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010193
Tony Barboureb254902015-07-15 12:50:33 -060010194 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010195 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10196 ds_layout_ci.pNext = NULL;
10197 ds_layout_ci.bindingCount = 1;
10198 ds_layout_ci.pBindings = &dsl_binding;
Mark Lobodzinski209b5292015-09-17 09:44:05 -060010199
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010200 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010201 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010202 ASSERT_VK_SUCCESS(err);
10203
10204 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010205 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010206 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010207 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060010208 alloc_info.descriptorPool = ds_pool;
10209 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010210 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010211 ASSERT_VK_SUCCESS(err);
10212
Tony Barboureb254902015-07-15 12:50:33 -060010213 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010214 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070010215 pipe_ms_state_ci.pNext = NULL;
10216 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
10217 pipe_ms_state_ci.sampleShadingEnable = 0;
10218 pipe_ms_state_ci.minSampleShading = 1.0;
10219 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010220
Tony Barboureb254902015-07-15 12:50:33 -060010221 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010222 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10223 pipeline_layout_ci.pNext = NULL;
10224 pipeline_layout_ci.setLayoutCount = 1;
10225 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010226
10227 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010228 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010229 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski209b5292015-09-17 09:44:05 -060010230
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010231 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -060010232 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -070010233 // on more devices
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010234 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010235
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010236 VkPipelineObj pipe(m_device);
10237 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -060010238 pipe.AddShader(&fs);
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010239 pipe.SetMSAA(&pipe_ms_state_ci);
10240 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -060010241
10242 BeginCommandBuffer();
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010243
Karl Schultz6addd812016-02-02 17:17:23 -070010244 // Main thing we care about for this test is that the VkImage obj we're
10245 // clearing matches Color Attachment of FB
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010246 // Also pass down other dummy params to keep driver and paramchecker happy
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -060010247 VkClearAttachment color_attachment;
10248 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10249 color_attachment.clearValue.color.float32[0] = 1.0;
10250 color_attachment.clearValue.color.float32[1] = 1.0;
10251 color_attachment.clearValue.color.float32[2] = 1.0;
10252 color_attachment.clearValue.color.float32[3] = 1.0;
10253 color_attachment.colorAttachment = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010254 VkClearRect clear_rect = {{{0, 0}, {(uint32_t)m_width, (uint32_t)m_height}}};
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010255
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010256 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010257
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010258 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010259
Chia-I Wuf7458c52015-10-26 21:10:41 +080010260 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10261 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10262 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010263}
10264
Karl Schultz6addd812016-02-02 17:17:23 -070010265TEST_F(VkLayerTest, VtxBufferBadIndex) {
10266 VkResult err;
Tobin Ehlis502480b2015-06-24 15:53:07 -060010267
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010268 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10269 "but no vertex buffers are attached to this Pipeline State Object");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010270
Tobin Ehlis502480b2015-06-24 15:53:07 -060010271 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisd332f282015-10-02 11:00:56 -060010272 ASSERT_NO_FATAL_FAILURE(InitViewport());
Tobin Ehlis502480b2015-06-24 15:53:07 -060010273 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -060010274
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010275 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010276 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10277 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010278
10279 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010280 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10281 ds_pool_ci.pNext = NULL;
10282 ds_pool_ci.maxSets = 1;
10283 ds_pool_ci.poolSizeCount = 1;
10284 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060010285
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -060010286 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010287 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis502480b2015-06-24 15:53:07 -060010288 ASSERT_VK_SUCCESS(err);
10289
Tony Barboureb254902015-07-15 12:50:33 -060010290 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010291 dsl_binding.binding = 0;
10292 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10293 dsl_binding.descriptorCount = 1;
10294 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10295 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -060010296
Tony Barboureb254902015-07-15 12:50:33 -060010297 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010298 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10299 ds_layout_ci.pNext = NULL;
10300 ds_layout_ci.bindingCount = 1;
10301 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060010302
Tobin Ehlis502480b2015-06-24 15:53:07 -060010303 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010304 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -060010305 ASSERT_VK_SUCCESS(err);
10306
10307 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010308 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010309 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010310 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060010311 alloc_info.descriptorPool = ds_pool;
10312 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010313 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis502480b2015-06-24 15:53:07 -060010314 ASSERT_VK_SUCCESS(err);
10315
Tony Barboureb254902015-07-15 12:50:33 -060010316 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010317 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070010318 pipe_ms_state_ci.pNext = NULL;
10319 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
10320 pipe_ms_state_ci.sampleShadingEnable = 0;
10321 pipe_ms_state_ci.minSampleShading = 1.0;
10322 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -060010323
Tony Barboureb254902015-07-15 12:50:33 -060010324 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010325 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10326 pipeline_layout_ci.pNext = NULL;
10327 pipeline_layout_ci.setLayoutCount = 1;
10328 pipeline_layout_ci.pSetLayouts = &ds_layout;
10329 VkPipelineLayout pipeline_layout;
Tobin Ehlis502480b2015-06-24 15:53:07 -060010330
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010331 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -060010332 ASSERT_VK_SUCCESS(err);
10333
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010334 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
10335 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
10336 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010337 VkPipelineObj pipe(m_device);
10338 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -060010339 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -060010340 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010341 pipe.SetMSAA(&pipe_ms_state_ci);
Tobin Ehlisd332f282015-10-02 11:00:56 -060010342 pipe.SetViewport(m_viewports);
10343 pipe.SetScissor(m_scissors);
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010344 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -060010345
10346 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010347 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisf7bf4502015-09-09 15:12:35 -060010348 // Don't care about actual data, just need to get to draw to flag error
10349 static const float vbo_data[3] = {1.f, 0.f, 1.f};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010350 VkConstantBufferObj vbo(m_device, sizeof(vbo_data), sizeof(float), (const void *)&vbo_data);
Tobin Ehlisf7bf4502015-09-09 15:12:35 -060010351 BindVertexBuffer(&vbo, (VkDeviceSize)0, 1); // VBO idx 1, but no VBO in PSO
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -060010352 Draw(1, 0, 0, 0);
Tobin Ehlis502480b2015-06-24 15:53:07 -060010353
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010354 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010355
Chia-I Wuf7458c52015-10-26 21:10:41 +080010356 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10357 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10358 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis502480b2015-06-24 15:53:07 -060010359}
Mark Muellerdfe37552016-07-07 14:47:42 -060010360
Mark Mueller2ee294f2016-08-04 12:59:48 -060010361TEST_F(VkLayerTest, MismatchCountQueueCreateRequestedFeature) {
10362 TEST_DESCRIPTION("Use an invalid count in a vkEnumeratePhysicalDevices call."
10363 "Use invalid Queue Family Index in vkCreateDevice");
Cody Northropc31a84f2016-08-22 10:41:47 -060010364 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Mueller2ee294f2016-08-04 12:59:48 -060010365
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010366 const char *mismatch_count_message = "Call to vkEnumeratePhysicalDevices() "
10367 "w/ pPhysicalDeviceCount value ";
Mark Mueller2ee294f2016-08-04 12:59:48 -060010368
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010369 const char *invalid_queueFamilyIndex_message = "Invalid queue create request in vkCreateDevice(). Invalid "
10370 "queueFamilyIndex ";
Mark Mueller2ee294f2016-08-04 12:59:48 -060010371
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010372 const char *unavailable_feature_message = "While calling vkCreateDevice(), requesting feature #";
Mark Mueller2ee294f2016-08-04 12:59:48 -060010373
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010374 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, mismatch_count_message);
Mark Mueller880fce52016-08-17 15:23:23 -060010375 // The following test fails with recent NVidia drivers.
10376 // By the time core_validation is reached, the NVidia
10377 // driver has sanitized the invalid condition and core_validation
10378 // is not introduced to the failure condition. This is not the case
10379 // with AMD and Mesa drivers. Futher investigation is required
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010380 // uint32_t count = static_cast<uint32_t>(~0);
10381 // VkPhysicalDevice physical_device;
10382 // vkEnumeratePhysicalDevices(instance(), &count, &physical_device);
10383 // m_errorMonitor->VerifyFound();
Mark Mueller2ee294f2016-08-04 12:59:48 -060010384
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010385 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_queueFamilyIndex_message);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010386 float queue_priority = 0.0;
10387
10388 VkDeviceQueueCreateInfo queue_create_info = {};
10389 queue_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
10390 queue_create_info.queueCount = 1;
10391 queue_create_info.pQueuePriorities = &queue_priority;
10392 queue_create_info.queueFamilyIndex = static_cast<uint32_t>(~0);
10393
10394 VkPhysicalDeviceFeatures features = m_device->phy().features();
10395 VkDevice testDevice;
10396 VkDeviceCreateInfo device_create_info = {};
10397 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
10398 device_create_info.queueCreateInfoCount = 1;
10399 device_create_info.pQueueCreateInfos = &queue_create_info;
10400 device_create_info.pEnabledFeatures = &features;
10401 vkCreateDevice(gpu(), &device_create_info, nullptr, &testDevice);
10402 m_errorMonitor->VerifyFound();
10403
10404 queue_create_info.queueFamilyIndex = 1;
10405
10406 unsigned feature_count = sizeof(VkPhysicalDeviceFeatures) / sizeof(VkBool32);
10407 VkBool32 *feature_array = reinterpret_cast<VkBool32 *>(&features);
10408 for (unsigned i = 0; i < feature_count; i++) {
10409 if (VK_FALSE == feature_array[i]) {
10410 feature_array[i] = VK_TRUE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010411 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, unavailable_feature_message);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010412 device_create_info.pEnabledFeatures = &features;
10413 vkCreateDevice(gpu(), &device_create_info, nullptr, &testDevice);
10414 m_errorMonitor->VerifyFound();
10415 break;
10416 }
10417 }
10418}
10419
Tobin Ehlis16edf082016-11-21 12:33:49 -070010420TEST_F(VkLayerTest, InvalidQueryPoolCreate) {
10421 TEST_DESCRIPTION("Attempt to create a query pool for PIPELINE_STATISTICS without enabling pipeline stats for the device.");
10422
10423 ASSERT_NO_FATAL_FAILURE(InitState());
10424
10425 const std::vector<VkQueueFamilyProperties> queue_props = m_device->queue_props;
10426 std::vector<VkDeviceQueueCreateInfo> queue_info;
10427 queue_info.reserve(queue_props.size());
10428 std::vector<std::vector<float>> queue_priorities;
10429 for (uint32_t i = 0; i < (uint32_t)queue_props.size(); i++) {
10430 VkDeviceQueueCreateInfo qi{};
10431 qi.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
10432 qi.queueFamilyIndex = i;
10433 qi.queueCount = queue_props[i].queueCount;
10434 queue_priorities.emplace_back(qi.queueCount, 0.0f);
10435 qi.pQueuePriorities = queue_priorities[i].data();
10436 queue_info.push_back(qi);
10437 }
10438
10439 std::vector<const char *> device_extension_names;
10440
10441 VkDevice local_device;
10442 VkDeviceCreateInfo device_create_info = {};
10443 auto features = m_device->phy().features();
10444 // Intentionally disable pipeline stats
10445 features.pipelineStatisticsQuery = VK_FALSE;
10446 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
10447 device_create_info.pNext = NULL;
10448 device_create_info.queueCreateInfoCount = queue_info.size();
10449 device_create_info.pQueueCreateInfos = queue_info.data();
10450 device_create_info.enabledLayerCount = 0;
10451 device_create_info.ppEnabledLayerNames = NULL;
10452 device_create_info.pEnabledFeatures = &features;
10453 VkResult err = vkCreateDevice(gpu(), &device_create_info, nullptr, &local_device);
10454 ASSERT_VK_SUCCESS(err);
10455
10456 VkQueryPoolCreateInfo qpci{};
10457 qpci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
10458 qpci.queryType = VK_QUERY_TYPE_PIPELINE_STATISTICS;
10459 qpci.queryCount = 1;
10460 VkQueryPool query_pool;
10461
10462 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01006);
10463 vkCreateQueryPool(local_device, &qpci, nullptr, &query_pool);
10464 m_errorMonitor->VerifyFound();
10465
10466 vkDestroyDevice(local_device, nullptr);
10467}
10468
Mark Mueller2ee294f2016-08-04 12:59:48 -060010469TEST_F(VkLayerTest, InvalidQueueIndexInvalidQuery) {
10470 TEST_DESCRIPTION("Use an invalid queue index in a vkCmdWaitEvents call."
10471 "End a command buffer with a query still in progress.");
10472
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010473 const char *invalid_queue_index = "was created with sharingMode of VK_SHARING_MODE_EXCLUSIVE. If one "
10474 "of src- or dstQueueFamilyIndex is VK_QUEUE_FAMILY_IGNORED, both "
10475 "must be.";
Mark Mueller2ee294f2016-08-04 12:59:48 -060010476
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010477 const char *invalid_query = "Ending command buffer with in progress query: queryPool 0x";
Mark Mueller2ee294f2016-08-04 12:59:48 -060010478
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010479 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_queue_index);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010480
10481 ASSERT_NO_FATAL_FAILURE(InitState());
10482
10483 VkEvent event;
10484 VkEventCreateInfo event_create_info{};
10485 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
10486 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
10487
Mark Mueller2ee294f2016-08-04 12:59:48 -060010488 VkQueue queue = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010489 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010490
10491 BeginCommandBuffer();
10492
10493 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010494 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 -060010495 ASSERT_TRUE(image.initialized());
10496 VkImageMemoryBarrier img_barrier = {};
10497 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
10498 img_barrier.pNext = NULL;
10499 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
10500 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
10501 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
10502 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
10503 img_barrier.image = image.handle();
10504 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
Mark Lobodzinski2a74c5c2016-08-17 13:26:28 -060010505
10506 // QueueFamilyIndex must be VK_QUEUE_FAMILY_IGNORED, this verifies
10507 // that layer validation catches the case when it is not.
10508 img_barrier.dstQueueFamilyIndex = 0;
Mark Mueller2ee294f2016-08-04 12:59:48 -060010509 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10510 img_barrier.subresourceRange.baseArrayLayer = 0;
10511 img_barrier.subresourceRange.baseMipLevel = 0;
10512 img_barrier.subresourceRange.layerCount = 1;
10513 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010514 vkCmdWaitEvents(m_commandBuffer->handle(), 1, &event, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0,
10515 nullptr, 0, nullptr, 1, &img_barrier);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010516 m_errorMonitor->VerifyFound();
10517
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010518 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_query);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010519
10520 VkQueryPool query_pool;
10521 VkQueryPoolCreateInfo query_pool_create_info = {};
10522 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
10523 query_pool_create_info.queryType = VK_QUERY_TYPE_OCCLUSION;
10524 query_pool_create_info.queryCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010525 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010526
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010527 vkCmdResetQueryPool(m_commandBuffer->handle(), query_pool, 0 /*startQuery*/, 1 /*queryCount*/);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010528 vkCmdBeginQuery(m_commandBuffer->handle(), query_pool, 0, 0);
10529
10530 vkEndCommandBuffer(m_commandBuffer->handle());
10531 m_errorMonitor->VerifyFound();
10532
10533 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
10534 vkDestroyEvent(m_device->device(), event, nullptr);
10535}
10536
Mark Muellerdfe37552016-07-07 14:47:42 -060010537TEST_F(VkLayerTest, VertexBufferInvalid) {
10538 TEST_DESCRIPTION("Submit a command buffer using deleted vertex buffer, "
10539 "delete a buffer twice, use an invalid offset for each "
10540 "buffer type, and attempt to bind a null buffer");
10541
10542 const char *deleted_buffer_in_command_buffer = "Cannot submit cmd buffer "
10543 "using deleted buffer ";
Mark Muellerdfe37552016-07-07 14:47:42 -060010544 const char *invalid_offset_message = "vkBindBufferMemory(): "
10545 "memoryOffset is 0x";
10546 const char *invalid_storage_buffer_offset_message = "vkBindBufferMemory(): "
10547 "storage memoryOffset "
10548 "is 0x";
10549 const char *invalid_texel_buffer_offset_message = "vkBindBufferMemory(): "
10550 "texel memoryOffset "
10551 "is 0x";
10552 const char *invalid_uniform_buffer_offset_message = "vkBindBufferMemory(): "
10553 "uniform memoryOffset "
10554 "is 0x";
Mark Muellerdfe37552016-07-07 14:47:42 -060010555
10556 ASSERT_NO_FATAL_FAILURE(InitState());
10557 ASSERT_NO_FATAL_FAILURE(InitViewport());
10558 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10559
10560 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010561 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Mark Muellerdfe37552016-07-07 14:47:42 -060010562 pipe_ms_state_ci.pNext = NULL;
10563 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
10564 pipe_ms_state_ci.sampleShadingEnable = 0;
10565 pipe_ms_state_ci.minSampleShading = 1.0;
10566 pipe_ms_state_ci.pSampleMask = nullptr;
10567
10568 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
10569 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10570 VkPipelineLayout pipeline_layout;
10571
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010572 VkResult err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, nullptr, &pipeline_layout);
Mark Muellerdfe37552016-07-07 14:47:42 -060010573 ASSERT_VK_SUCCESS(err);
10574
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010575 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
10576 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Muellerdfe37552016-07-07 14:47:42 -060010577 VkPipelineObj pipe(m_device);
10578 pipe.AddShader(&vs);
10579 pipe.AddShader(&fs);
10580 pipe.AddColorAttachment();
10581 pipe.SetMSAA(&pipe_ms_state_ci);
10582 pipe.SetViewport(m_viewports);
10583 pipe.SetScissor(m_scissors);
10584 pipe.CreateVKPipeline(pipeline_layout, renderPass());
10585
10586 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010587 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Mark Muellerdfe37552016-07-07 14:47:42 -060010588
10589 {
10590 // Create and bind a vertex buffer in a reduced scope, which will cause
10591 // it to be deleted upon leaving this scope
10592 const float vbo_data[3] = {1.f, 0.f, 1.f};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010593 VkVerticesObj draw_verticies(m_device, 1, 1, sizeof(vbo_data), 3, vbo_data);
Mark Muellerdfe37552016-07-07 14:47:42 -060010594 draw_verticies.BindVertexBuffers(m_commandBuffer->handle());
10595 draw_verticies.AddVertexInputToPipe(pipe);
10596 }
10597
10598 Draw(1, 0, 0, 0);
10599
10600 EndCommandBuffer();
10601
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010602 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, deleted_buffer_in_command_buffer);
Mark Muellerdfe37552016-07-07 14:47:42 -060010603 QueueCommandBuffer(false);
10604 m_errorMonitor->VerifyFound();
10605
10606 {
10607 // Create and bind a vertex buffer in a reduced scope, and delete it
10608 // twice, the second through the destructor
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010609 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eDoubleDelete);
Karl Schultzf78bcdd2016-11-30 12:36:01 -070010610 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00680);
Mark Muellerdfe37552016-07-07 14:47:42 -060010611 buffer_test.TestDoubleDestroy();
10612 }
10613 m_errorMonitor->VerifyFound();
10614
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010615 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidMemoryOffset)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060010616 // Create and bind a memory buffer with an invalid offset.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010617 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_offset_message);
10618 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT, VkBufferTest::eInvalidMemoryOffset);
10619 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010620 m_errorMonitor->VerifyFound();
10621 }
10622
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010623 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset,
10624 VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060010625 // Create and bind a memory buffer with an invalid offset again,
10626 // but look for a texel buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010627 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_texel_buffer_offset_message);
10628 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
10629 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010630 m_errorMonitor->VerifyFound();
10631 }
10632
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010633 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060010634 // Create and bind a memory buffer with an invalid offset again, but
10635 // look for a uniform buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010636 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_uniform_buffer_offset_message);
10637 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
10638 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010639 m_errorMonitor->VerifyFound();
10640 }
10641
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010642 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060010643 // Create and bind a memory buffer with an invalid offset again, but
10644 // look for a storage buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010645 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_storage_buffer_offset_message);
10646 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
10647 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010648 m_errorMonitor->VerifyFound();
10649 }
10650
10651 {
10652 // Attempt to bind a null buffer.
Karl Schultzf78bcdd2016-11-30 12:36:01 -070010653 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00799);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010654 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eBindNullBuffer);
10655 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010656 m_errorMonitor->VerifyFound();
10657 }
10658
10659 {
10660 // Attempt to use an invalid handle to delete a buffer.
Karl Schultzf78bcdd2016-11-30 12:36:01 -070010661 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00622);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010662 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eFreeInvalidHandle);
10663 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010664 }
10665 m_errorMonitor->VerifyFound();
10666
10667 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10668}
10669
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010670// INVALID_IMAGE_LAYOUT tests (one other case is hit by MapMemWithoutHostVisibleBit and not here)
10671TEST_F(VkLayerTest, InvalidImageLayout) {
10672 TEST_DESCRIPTION("Hit all possible validation checks associated with the "
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010673 "DRAWSTATE_INVALID_IMAGE_LAYOUT enum. Generally these involve having"
10674 "images in the wrong layout when they're copied or transitioned.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010675 // 3 in ValidateCmdBufImageLayouts
10676 // * -1 Attempt to submit cmd buf w/ deleted image
10677 // * -2 Cmd buf submit of image w/ layout not matching first use w/ subresource
10678 // * -3 Cmd buf submit of image w/ layout not matching first use w/o subresource
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010679
10680 ASSERT_NO_FATAL_FAILURE(InitState());
10681 // Create src & dst images to use for copy operations
10682 VkImage src_image;
10683 VkImage dst_image;
Cort3b021012016-12-07 12:00:57 -080010684 VkImage depth_image;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010685
10686 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
10687 const int32_t tex_width = 32;
10688 const int32_t tex_height = 32;
10689
10690 VkImageCreateInfo image_create_info = {};
10691 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
10692 image_create_info.pNext = NULL;
10693 image_create_info.imageType = VK_IMAGE_TYPE_2D;
10694 image_create_info.format = tex_format;
10695 image_create_info.extent.width = tex_width;
10696 image_create_info.extent.height = tex_height;
10697 image_create_info.extent.depth = 1;
10698 image_create_info.mipLevels = 1;
10699 image_create_info.arrayLayers = 4;
10700 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
10701 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
10702 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Cort3b021012016-12-07 12:00:57 -080010703 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010704 image_create_info.flags = 0;
10705
10706 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &src_image);
10707 ASSERT_VK_SUCCESS(err);
Cort3b021012016-12-07 12:00:57 -080010708 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010709 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dst_image);
10710 ASSERT_VK_SUCCESS(err);
Cort3b021012016-12-07 12:00:57 -080010711 image_create_info.format = VK_FORMAT_D32_SFLOAT;
10712 image_create_info.usage |= VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
10713 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &depth_image);
10714 ASSERT_VK_SUCCESS(err);
10715
10716 // Allocate memory
10717 VkMemoryRequirements img_mem_reqs = {};
Cort530cf382016-12-08 09:59:47 -080010718 VkMemoryAllocateInfo mem_alloc = {};
Cort3b021012016-12-07 12:00:57 -080010719 VkDeviceMemory src_image_mem, dst_image_mem, depth_image_mem;
Cort530cf382016-12-08 09:59:47 -080010720 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
10721 mem_alloc.pNext = NULL;
10722 mem_alloc.allocationSize = 0;
10723 mem_alloc.memoryTypeIndex = 0;
Cort3b021012016-12-07 12:00:57 -080010724
10725 vkGetImageMemoryRequirements(m_device->device(), src_image, &img_mem_reqs);
Cort530cf382016-12-08 09:59:47 -080010726 mem_alloc.allocationSize = img_mem_reqs.size;
10727 bool pass = m_device->phy().set_memory_type(img_mem_reqs.memoryTypeBits, &mem_alloc, 0);
Cort3b021012016-12-07 12:00:57 -080010728 ASSERT_TRUE(pass);
Cort530cf382016-12-08 09:59:47 -080010729 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &src_image_mem);
Cort3b021012016-12-07 12:00:57 -080010730 ASSERT_VK_SUCCESS(err);
10731
10732 vkGetImageMemoryRequirements(m_device->device(), dst_image, &img_mem_reqs);
Cort530cf382016-12-08 09:59:47 -080010733 mem_alloc.allocationSize = img_mem_reqs.size;
10734 pass = m_device->phy().set_memory_type(img_mem_reqs.memoryTypeBits, &mem_alloc, 0);
Cort3b021012016-12-07 12:00:57 -080010735 ASSERT_VK_SUCCESS(err);
Cort530cf382016-12-08 09:59:47 -080010736 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &dst_image_mem);
Cort3b021012016-12-07 12:00:57 -080010737 ASSERT_VK_SUCCESS(err);
10738
10739 vkGetImageMemoryRequirements(m_device->device(), depth_image, &img_mem_reqs);
Cort530cf382016-12-08 09:59:47 -080010740 mem_alloc.allocationSize = img_mem_reqs.size;
10741 pass = m_device->phy().set_memory_type(img_mem_reqs.memoryTypeBits, &mem_alloc, 0);
Cort3b021012016-12-07 12:00:57 -080010742 ASSERT_VK_SUCCESS(err);
Cort530cf382016-12-08 09:59:47 -080010743 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &depth_image_mem);
Cort3b021012016-12-07 12:00:57 -080010744 ASSERT_VK_SUCCESS(err);
10745
10746 err = vkBindImageMemory(m_device->device(), src_image, src_image_mem, 0);
10747 ASSERT_VK_SUCCESS(err);
10748 err = vkBindImageMemory(m_device->device(), dst_image, dst_image_mem, 0);
10749 ASSERT_VK_SUCCESS(err);
10750 err = vkBindImageMemory(m_device->device(), depth_image, depth_image_mem, 0);
10751 ASSERT_VK_SUCCESS(err);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010752
10753 BeginCommandBuffer();
Cort530cf382016-12-08 09:59:47 -080010754 VkImageCopy copy_region;
10755 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10756 copy_region.srcSubresource.mipLevel = 0;
10757 copy_region.srcSubresource.baseArrayLayer = 0;
10758 copy_region.srcSubresource.layerCount = 1;
10759 copy_region.srcOffset.x = 0;
10760 copy_region.srcOffset.y = 0;
10761 copy_region.srcOffset.z = 0;
10762 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10763 copy_region.dstSubresource.mipLevel = 0;
10764 copy_region.dstSubresource.baseArrayLayer = 0;
10765 copy_region.dstSubresource.layerCount = 1;
10766 copy_region.dstOffset.x = 0;
10767 copy_region.dstOffset.y = 0;
10768 copy_region.dstOffset.z = 0;
10769 copy_region.extent.width = 1;
10770 copy_region.extent.height = 1;
10771 copy_region.extent.depth = 1;
10772
10773 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10774 "Layout for input image should be TRANSFER_SRC_OPTIMAL instead of GENERAL.");
10775 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 -060010776 m_errorMonitor->VerifyFound();
10777 // Now cause error due to src image layout changing
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010778 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot copy from an image whose source layout is "
10779 "VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current "
10780 "layout VK_IMAGE_LAYOUT_GENERAL.");
Cort530cf382016-12-08 09:59:47 -080010781 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 -060010782 m_errorMonitor->VerifyFound();
10783 // Final src error is due to bad layout type
10784 m_errorMonitor->SetDesiredFailureMsg(
10785 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10786 "Layout for input image is VK_IMAGE_LAYOUT_UNDEFINED but can only be TRANSFER_SRC_OPTIMAL or GENERAL.");
Cort530cf382016-12-08 09:59:47 -080010787 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 -060010788 m_errorMonitor->VerifyFound();
10789 // Now verify same checks for dst
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010790 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10791 "Layout for output image should be TRANSFER_DST_OPTIMAL instead of GENERAL.");
Cort530cf382016-12-08 09:59:47 -080010792 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 -060010793 m_errorMonitor->VerifyFound();
10794 // Now cause error due to src image layout changing
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010795 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot copy from an image whose dest layout is "
10796 "VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current "
10797 "layout VK_IMAGE_LAYOUT_GENERAL.");
Cort530cf382016-12-08 09:59:47 -080010798 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 -060010799 m_errorMonitor->VerifyFound();
10800 m_errorMonitor->SetDesiredFailureMsg(
10801 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10802 "Layout for output image is VK_IMAGE_LAYOUT_UNDEFINED but can only be TRANSFER_DST_OPTIMAL or GENERAL.");
Cort530cf382016-12-08 09:59:47 -080010803 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 -060010804 m_errorMonitor->VerifyFound();
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010010805
Cort3b021012016-12-07 12:00:57 -080010806 // Convert dst and depth images to TRANSFER_DST for subsequent tests
10807 VkImageMemoryBarrier transfer_dst_image_barrier[1] = {};
10808 transfer_dst_image_barrier[0].sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
10809 transfer_dst_image_barrier[0].oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
10810 transfer_dst_image_barrier[0].newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
10811 transfer_dst_image_barrier[0].srcAccessMask = 0;
10812 transfer_dst_image_barrier[0].dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
10813 transfer_dst_image_barrier[0].image = dst_image;
10814 transfer_dst_image_barrier[0].subresourceRange.layerCount = image_create_info.arrayLayers;
10815 transfer_dst_image_barrier[0].subresourceRange.levelCount = image_create_info.mipLevels;
10816 transfer_dst_image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10817 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
10818 NULL, 0, NULL, 1, transfer_dst_image_barrier);
10819 transfer_dst_image_barrier[0].image = depth_image;
10820 transfer_dst_image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
10821 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
10822 NULL, 0, NULL, 1, transfer_dst_image_barrier);
10823
10824 // Cause errors due to clearing with invalid image layouts
Cort530cf382016-12-08 09:59:47 -080010825 VkClearColorValue color_clear_value = {};
10826 VkImageSubresourceRange clear_range;
10827 clear_range.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10828 clear_range.baseMipLevel = 0;
10829 clear_range.baseArrayLayer = 0;
10830 clear_range.layerCount = 1;
10831 clear_range.levelCount = 1;
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010010832
Cort3b021012016-12-07 12:00:57 -080010833 // Fail due to explicitly prohibited layout for color clear (only GENERAL and TRANSFER_DST are permitted).
10834 // Since the image is currently not in UNDEFINED layout, this will emit two errors.
10835 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01086);
10836 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01085);
Cort530cf382016-12-08 09:59:47 -080010837 m_commandBuffer->ClearColorImage(dst_image, VK_IMAGE_LAYOUT_UNDEFINED, &color_clear_value, 1, &clear_range);
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010010838 m_errorMonitor->VerifyFound();
Cort3b021012016-12-07 12:00:57 -080010839 // Fail due to provided layout not matching actual current layout for color clear.
10840 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01085);
Cort530cf382016-12-08 09:59:47 -080010841 m_commandBuffer->ClearColorImage(dst_image, VK_IMAGE_LAYOUT_GENERAL, &color_clear_value, 1, &clear_range);
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010010842 m_errorMonitor->VerifyFound();
Cort3b021012016-12-07 12:00:57 -080010843
Cort530cf382016-12-08 09:59:47 -080010844 VkClearDepthStencilValue depth_clear_value = {};
10845 clear_range.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
Cort3b021012016-12-07 12:00:57 -080010846
10847 // Fail due to explicitly prohibited layout for depth clear (only GENERAL and TRANSFER_DST are permitted).
10848 // Since the image is currently not in UNDEFINED layout, this will emit two errors.
10849 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01101);
10850 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01100);
Cort530cf382016-12-08 09:59:47 -080010851 m_commandBuffer->ClearDepthStencilImage(depth_image, VK_IMAGE_LAYOUT_UNDEFINED, &depth_clear_value, 1, &clear_range);
Cort3b021012016-12-07 12:00:57 -080010852 m_errorMonitor->VerifyFound();
10853 // Fail due to provided layout not matching actual current layout for depth clear.
10854 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01100);
Cort530cf382016-12-08 09:59:47 -080010855 m_commandBuffer->ClearDepthStencilImage(depth_image, VK_IMAGE_LAYOUT_GENERAL, &depth_clear_value, 1, &clear_range);
Cort3b021012016-12-07 12:00:57 -080010856 m_errorMonitor->VerifyFound();
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010010857
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010858 // Now cause error due to bad image layout transition in PipelineBarrier
10859 VkImageMemoryBarrier image_barrier[1] = {};
Cort3b021012016-12-07 12:00:57 -080010860 image_barrier[0].sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010861 image_barrier[0].oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
Cort3b021012016-12-07 12:00:57 -080010862 image_barrier[0].newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010863 image_barrier[0].image = src_image;
Cort3b021012016-12-07 12:00:57 -080010864 image_barrier[0].subresourceRange.layerCount = image_create_info.arrayLayers;
10865 image_barrier[0].subresourceRange.levelCount = image_create_info.mipLevels;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010866 image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010867 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "You cannot transition the layout from "
10868 "VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL when "
10869 "current layout is VK_IMAGE_LAYOUT_GENERAL.");
10870 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
10871 NULL, 0, NULL, 1, image_barrier);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010872 m_errorMonitor->VerifyFound();
10873
10874 // Finally some layout errors at RenderPass create time
10875 // Just hacking in specific state to get to the errors we want so don't copy this unless you know what you're doing.
10876 VkAttachmentReference attach = {};
10877 // perf warning for GENERAL layout w/ non-DS input attachment
10878 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
10879 VkSubpassDescription subpass = {};
10880 subpass.inputAttachmentCount = 1;
10881 subpass.pInputAttachments = &attach;
10882 VkRenderPassCreateInfo rpci = {};
10883 rpci.subpassCount = 1;
10884 rpci.pSubpasses = &subpass;
10885 rpci.attachmentCount = 1;
10886 VkAttachmentDescription attach_desc = {};
10887 attach_desc.format = VK_FORMAT_UNDEFINED;
10888 rpci.pAttachments = &attach_desc;
Tobin Ehlis1efce022016-05-11 10:40:34 -060010889 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010890 VkRenderPass rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010891 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10892 "Layout for input attachment is GENERAL but should be READ_ONLY_OPTIMAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010893 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10894 m_errorMonitor->VerifyFound();
10895 // error w/ non-general layout
10896 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
10897
10898 m_errorMonitor->SetDesiredFailureMsg(
10899 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10900 "Layout for input attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be READ_ONLY_OPTIMAL or GENERAL.");
10901 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10902 m_errorMonitor->VerifyFound();
10903 subpass.inputAttachmentCount = 0;
10904 subpass.colorAttachmentCount = 1;
10905 subpass.pColorAttachments = &attach;
10906 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
10907 // perf warning for GENERAL layout on color attachment
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010908 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10909 "Layout for color attachment is GENERAL but should be COLOR_ATTACHMENT_OPTIMAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010910 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10911 m_errorMonitor->VerifyFound();
10912 // error w/ non-color opt or GENERAL layout for color attachment
10913 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
10914 m_errorMonitor->SetDesiredFailureMsg(
10915 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10916 "Layout for color attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be COLOR_ATTACHMENT_OPTIMAL or GENERAL.");
10917 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10918 m_errorMonitor->VerifyFound();
10919 subpass.colorAttachmentCount = 0;
10920 subpass.pDepthStencilAttachment = &attach;
10921 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
10922 // perf warning for GENERAL layout on DS attachment
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010923 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10924 "GENERAL layout for depth attachment may not give optimal performance.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010925 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10926 m_errorMonitor->VerifyFound();
10927 // error w/ non-ds opt or GENERAL layout for color attachment
10928 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010929 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10930 "Layout for depth attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be "
10931 "DEPTH_STENCIL_ATTACHMENT_OPTIMAL, DEPTH_STENCIL_READ_ONLY_OPTIMAL or GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010932 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10933 m_errorMonitor->VerifyFound();
Tobin Ehlis1efce022016-05-11 10:40:34 -060010934 // For this error we need a valid renderpass so create default one
10935 attach.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
10936 attach.attachment = 0;
10937 attach_desc.format = VK_FORMAT_D24_UNORM_S8_UINT;
10938 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
10939 attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
10940 attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
10941 attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
10942 // Can't do a CLEAR load on READ_ONLY initialLayout
10943 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
10944 attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
10945 attach_desc.finalLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010946 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " with invalid first layout "
10947 "VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_"
10948 "ONLY_OPTIMAL");
Tobin Ehlis1efce022016-05-11 10:40:34 -060010949 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10950 m_errorMonitor->VerifyFound();
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010951
Cort3b021012016-12-07 12:00:57 -080010952 vkFreeMemory(m_device->device(), src_image_mem, NULL);
10953 vkFreeMemory(m_device->device(), dst_image_mem, NULL);
10954 vkFreeMemory(m_device->device(), depth_image_mem, NULL);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010955 vkDestroyImage(m_device->device(), src_image, NULL);
10956 vkDestroyImage(m_device->device(), dst_image, NULL);
Cort3b021012016-12-07 12:00:57 -080010957 vkDestroyImage(m_device->device(), depth_image, NULL);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010958}
Tobin Ehlisd8d89182016-07-18 20:13:11 -060010959
Tobin Ehlise0936662016-10-11 08:10:51 -060010960TEST_F(VkLayerTest, InvalidStorageImageLayout) {
10961 TEST_DESCRIPTION("Attempt to update a STORAGE_IMAGE descriptor w/o GENERAL layout.");
10962 VkResult err;
10963
10964 ASSERT_NO_FATAL_FAILURE(InitState());
10965
10966 const VkFormat tex_format = VK_FORMAT_R8G8B8A8_UNORM;
10967 VkImageTiling tiling;
10968 VkFormatProperties format_properties;
10969 vkGetPhysicalDeviceFormatProperties(gpu(), tex_format, &format_properties);
10970 if (format_properties.linearTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
10971 tiling = VK_IMAGE_TILING_LINEAR;
10972 } else if (format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
10973 tiling = VK_IMAGE_TILING_OPTIMAL;
10974 } else {
10975 printf("Device does not support VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT; "
10976 "skipped.\n");
10977 return;
10978 }
10979
10980 VkDescriptorPoolSize ds_type = {};
10981 ds_type.type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
10982 ds_type.descriptorCount = 1;
10983
10984 VkDescriptorPoolCreateInfo ds_pool_ci = {};
10985 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10986 ds_pool_ci.maxSets = 1;
10987 ds_pool_ci.poolSizeCount = 1;
10988 ds_pool_ci.pPoolSizes = &ds_type;
10989 ds_pool_ci.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
10990
10991 VkDescriptorPool ds_pool;
10992 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
10993 ASSERT_VK_SUCCESS(err);
10994
10995 VkDescriptorSetLayoutBinding dsl_binding = {};
10996 dsl_binding.binding = 0;
10997 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
10998 dsl_binding.descriptorCount = 1;
10999 dsl_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
11000 dsl_binding.pImmutableSamplers = NULL;
11001
11002 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11003 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11004 ds_layout_ci.pNext = NULL;
11005 ds_layout_ci.bindingCount = 1;
11006 ds_layout_ci.pBindings = &dsl_binding;
11007
11008 VkDescriptorSetLayout ds_layout;
11009 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
11010 ASSERT_VK_SUCCESS(err);
11011
11012 VkDescriptorSetAllocateInfo alloc_info = {};
11013 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11014 alloc_info.descriptorSetCount = 1;
11015 alloc_info.descriptorPool = ds_pool;
11016 alloc_info.pSetLayouts = &ds_layout;
11017 VkDescriptorSet descriptor_set;
11018 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
11019 ASSERT_VK_SUCCESS(err);
11020
11021 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11022 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11023 pipeline_layout_ci.pNext = NULL;
11024 pipeline_layout_ci.setLayoutCount = 1;
11025 pipeline_layout_ci.pSetLayouts = &ds_layout;
11026 VkPipelineLayout pipeline_layout;
11027 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
11028 ASSERT_VK_SUCCESS(err);
11029
11030 VkImageObj image(m_device);
11031 image.init(32, 32, tex_format, VK_IMAGE_USAGE_STORAGE_BIT, tiling, 0);
11032 ASSERT_TRUE(image.initialized());
11033 VkImageView view = image.targetView(tex_format);
11034
11035 VkDescriptorImageInfo image_info = {};
11036 image_info.imageView = view;
11037 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
11038
11039 VkWriteDescriptorSet descriptor_write = {};
11040 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
11041 descriptor_write.dstSet = descriptor_set;
11042 descriptor_write.dstBinding = 0;
11043 descriptor_write.descriptorCount = 1;
11044 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
11045 descriptor_write.pImageInfo = &image_info;
11046
11047 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11048 " of VK_DESCRIPTOR_TYPE_STORAGE_IMAGE type is being updated with layout "
11049 "VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL but according to spec ");
11050 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11051 m_errorMonitor->VerifyFound();
11052
11053 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11054 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11055 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
11056 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
11057}
11058
Mark Mueller93b938f2016-08-18 10:27:40 -060011059TEST_F(VkLayerTest, SimultaneousUse) {
11060 TEST_DESCRIPTION("Use vkCmdExecuteCommands with invalid state "
11061 "in primary and secondary command buffers.");
11062
11063 ASSERT_NO_FATAL_FAILURE(InitState());
11064 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11065
Mike Weiblen95dd0f92016-10-19 12:28:27 -060011066 const char *simultaneous_use_message1 = "without VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set!";
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011067 const char *simultaneous_use_message2 = "does not have VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set and "
11068 "will cause primary command buffer";
Mark Mueller93b938f2016-08-18 10:27:40 -060011069
11070 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011071 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Mueller93b938f2016-08-18 10:27:40 -060011072 command_buffer_allocate_info.commandPool = m_commandPool;
11073 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
11074 command_buffer_allocate_info.commandBufferCount = 1;
11075
11076 VkCommandBuffer secondary_command_buffer;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011077 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer));
Mark Mueller93b938f2016-08-18 10:27:40 -060011078 VkCommandBufferBeginInfo command_buffer_begin_info = {};
11079 VkCommandBufferInheritanceInfo command_buffer_inheritance_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011080 command_buffer_inheritance_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
Mark Mueller93b938f2016-08-18 10:27:40 -060011081 command_buffer_inheritance_info.renderPass = m_renderPass;
11082 command_buffer_inheritance_info.framebuffer = m_framebuffer;
11083 command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011084 command_buffer_begin_info.flags =
11085 VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT | VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT;
Mark Mueller93b938f2016-08-18 10:27:40 -060011086 command_buffer_begin_info.pInheritanceInfo = &command_buffer_inheritance_info;
11087
11088 vkBeginCommandBuffer(secondary_command_buffer, &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011089 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
11090 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller4042b652016-09-05 22:52:21 -060011091 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
Mark Mueller93b938f2016-08-18 10:27:40 -060011092 vkEndCommandBuffer(secondary_command_buffer);
11093
Mark Mueller93b938f2016-08-18 10:27:40 -060011094 VkSubmitInfo submit_info = {};
11095 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11096 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011097 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Mueller4042b652016-09-05 22:52:21 -060011098 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Mueller93b938f2016-08-18 10:27:40 -060011099
Mark Mueller4042b652016-09-05 22:52:21 -060011100 vkBeginCommandBuffer(m_commandBuffer->handle(), &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011101 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
11102 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, simultaneous_use_message1);
11103 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller93b938f2016-08-18 10:27:40 -060011104 m_errorMonitor->VerifyFound();
Mark Mueller4042b652016-09-05 22:52:21 -060011105 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
11106 vkEndCommandBuffer(m_commandBuffer->handle());
Mark Mueller93b938f2016-08-18 10:27:40 -060011107
11108 m_errorMonitor->SetDesiredFailureMsg(0, "");
Mark Mueller93b938f2016-08-18 10:27:40 -060011109 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11110
Mark Mueller4042b652016-09-05 22:52:21 -060011111 command_buffer_begin_info.flags = VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT;
Mark Mueller93b938f2016-08-18 10:27:40 -060011112 vkBeginCommandBuffer(m_commandBuffer->handle(), &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011113 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
Mark Mueller4042b652016-09-05 22:52:21 -060011114
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011115 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, simultaneous_use_message2);
11116 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller93b938f2016-08-18 10:27:40 -060011117 m_errorMonitor->VerifyFound();
Mark Mueller4042b652016-09-05 22:52:21 -060011118 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
11119 vkEndCommandBuffer(m_commandBuffer->handle());
Mark Mueller93b938f2016-08-18 10:27:40 -060011120}
11121
Mark Mueller917f6bc2016-08-30 10:57:19 -060011122TEST_F(VkLayerTest, InUseDestroyedSignaled) {
11123 TEST_DESCRIPTION("Use vkCmdExecuteCommands with invalid state "
11124 "in primary and secondary command buffers. "
Mark Muellerc8d441e2016-08-23 17:36:00 -060011125 "Delete objects that are inuse. Call VkQueueSubmit "
11126 "with an event that has been deleted.");
Mark Mueller917f6bc2016-08-30 10:57:19 -060011127
11128 ASSERT_NO_FATAL_FAILURE(InitState());
11129 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11130
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011131 const char *submit_with_deleted_event_message = "Cannot submit cmd buffer using deleted event 0x";
11132 const char *cannot_delete_event_message = "Cannot delete event 0x";
11133 const char *cannot_delete_semaphore_message = "Cannot delete semaphore 0x";
11134 const char *cannot_destroy_fence_message = "Fence 0x";
Mark Mueller917f6bc2016-08-30 10:57:19 -060011135
11136 BeginCommandBuffer();
11137
11138 VkEvent event;
11139 VkEventCreateInfo event_create_info = {};
11140 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
11141 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011142 vkCmdSetEvent(m_commandBuffer->handle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Mark Mueller917f6bc2016-08-30 10:57:19 -060011143
Mark Muellerc8d441e2016-08-23 17:36:00 -060011144 EndCommandBuffer();
11145 vkDestroyEvent(m_device->device(), event, nullptr);
11146
11147 VkSubmitInfo submit_info = {};
11148 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11149 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011150 submit_info.pCommandBuffers = &m_commandBuffer->handle();
11151 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, submit_with_deleted_event_message);
Mark Muellerc8d441e2016-08-23 17:36:00 -060011152 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11153 m_errorMonitor->VerifyFound();
11154
11155 m_errorMonitor->SetDesiredFailureMsg(0, "");
11156 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
11157
11158 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
11159
Mark Mueller917f6bc2016-08-30 10:57:19 -060011160 VkSemaphoreCreateInfo semaphore_create_info = {};
11161 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
11162 VkSemaphore semaphore;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011163 ASSERT_VK_SUCCESS(vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore));
Mark Mueller917f6bc2016-08-30 10:57:19 -060011164 VkFenceCreateInfo fence_create_info = {};
11165 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
11166 VkFence fence;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011167 ASSERT_VK_SUCCESS(vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence));
Mark Mueller917f6bc2016-08-30 10:57:19 -060011168
11169 VkDescriptorPoolSize descriptor_pool_type_count = {};
Mark Mueller4042b652016-09-05 22:52:21 -060011170 descriptor_pool_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Mark Mueller917f6bc2016-08-30 10:57:19 -060011171 descriptor_pool_type_count.descriptorCount = 1;
11172
11173 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
11174 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11175 descriptor_pool_create_info.maxSets = 1;
11176 descriptor_pool_create_info.poolSizeCount = 1;
11177 descriptor_pool_create_info.pPoolSizes = &descriptor_pool_type_count;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011178 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
Mark Mueller917f6bc2016-08-30 10:57:19 -060011179
11180 VkDescriptorPool descriptorset_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011181 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
Mark Mueller917f6bc2016-08-30 10:57:19 -060011182
11183 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
Mark Mueller4042b652016-09-05 22:52:21 -060011184 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Mark Mueller917f6bc2016-08-30 10:57:19 -060011185 descriptorset_layout_binding.descriptorCount = 1;
11186 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_ALL;
11187
11188 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011189 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060011190 descriptorset_layout_create_info.bindingCount = 1;
11191 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
11192
11193 VkDescriptorSetLayout descriptorset_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011194 ASSERT_VK_SUCCESS(
11195 vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
Mark Mueller917f6bc2016-08-30 10:57:19 -060011196
11197 VkDescriptorSet descriptorset;
11198 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011199 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060011200 descriptorset_allocate_info.descriptorSetCount = 1;
11201 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
11202 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011203 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
Mark Mueller917f6bc2016-08-30 10:57:19 -060011204
Mark Mueller4042b652016-09-05 22:52:21 -060011205 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
11206
11207 VkDescriptorBufferInfo buffer_info = {};
11208 buffer_info.buffer = buffer_test.GetBuffer();
11209 buffer_info.offset = 0;
11210 buffer_info.range = 1024;
11211
11212 VkWriteDescriptorSet write_descriptor_set = {};
11213 write_descriptor_set.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
11214 write_descriptor_set.dstSet = descriptorset;
11215 write_descriptor_set.descriptorCount = 1;
11216 write_descriptor_set.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11217 write_descriptor_set.pBufferInfo = &buffer_info;
11218
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011219 vkUpdateDescriptorSets(m_device->device(), 1, &write_descriptor_set, 0, nullptr);
Mark Mueller4042b652016-09-05 22:52:21 -060011220
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011221 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
11222 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Mueller917f6bc2016-08-30 10:57:19 -060011223
11224 VkPipelineObj pipe(m_device);
11225 pipe.AddColorAttachment();
11226 pipe.AddShader(&vs);
11227 pipe.AddShader(&fs);
11228
11229 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011230 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060011231 pipeline_layout_create_info.setLayoutCount = 1;
11232 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
11233
11234 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011235 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
Mark Mueller917f6bc2016-08-30 10:57:19 -060011236
11237 pipe.CreateVKPipeline(pipeline_layout, m_renderPass);
11238
Mark Muellerc8d441e2016-08-23 17:36:00 -060011239 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011240 vkCmdSetEvent(m_commandBuffer->handle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Mark Muellerc8d441e2016-08-23 17:36:00 -060011241
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011242 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
11243 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
11244 &descriptorset, 0, NULL);
Mark Mueller917f6bc2016-08-30 10:57:19 -060011245
Mark Muellerc8d441e2016-08-23 17:36:00 -060011246 EndCommandBuffer();
Mark Mueller917f6bc2016-08-30 10:57:19 -060011247
Mark Mueller917f6bc2016-08-30 10:57:19 -060011248 submit_info.signalSemaphoreCount = 1;
11249 submit_info.pSignalSemaphores = &semaphore;
11250 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
Mark Muellerc8d441e2016-08-23 17:36:00 -060011251
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011252 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, cannot_delete_event_message);
Mark Mueller917f6bc2016-08-30 10:57:19 -060011253 vkDestroyEvent(m_device->device(), event, nullptr);
11254 m_errorMonitor->VerifyFound();
11255
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011256 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, cannot_delete_semaphore_message);
Mark Mueller917f6bc2016-08-30 10:57:19 -060011257 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
11258 m_errorMonitor->VerifyFound();
11259
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011260 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, cannot_destroy_fence_message);
Mark Mueller917f6bc2016-08-30 10:57:19 -060011261 vkDestroyFence(m_device->device(), fence, nullptr);
11262 m_errorMonitor->VerifyFound();
11263
Tobin Ehlis122207b2016-09-01 08:50:06 -070011264 vkQueueWaitIdle(m_device->m_queue);
Mark Mueller917f6bc2016-08-30 10:57:19 -060011265 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
11266 vkDestroyFence(m_device->device(), fence, nullptr);
11267 vkDestroyEvent(m_device->device(), event, nullptr);
11268 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011269 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
Mark Mueller917f6bc2016-08-30 10:57:19 -060011270 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
11271}
11272
Tobin Ehlis2adda372016-09-01 08:51:06 -070011273TEST_F(VkLayerTest, QueryPoolInUseDestroyedSignaled) {
11274 TEST_DESCRIPTION("Delete in-use query pool.");
11275
11276 ASSERT_NO_FATAL_FAILURE(InitState());
11277 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11278
11279 VkQueryPool query_pool;
11280 VkQueryPoolCreateInfo query_pool_ci{};
11281 query_pool_ci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
11282 query_pool_ci.queryType = VK_QUERY_TYPE_TIMESTAMP;
11283 query_pool_ci.queryCount = 1;
11284 vkCreateQueryPool(m_device->device(), &query_pool_ci, nullptr, &query_pool);
11285 BeginCommandBuffer();
11286 // Reset query pool to create binding with cmd buffer
11287 vkCmdResetQueryPool(m_commandBuffer->handle(), query_pool, 0, 1);
11288
11289 EndCommandBuffer();
11290
11291 VkSubmitInfo submit_info = {};
11292 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11293 submit_info.commandBufferCount = 1;
11294 submit_info.pCommandBuffers = &m_commandBuffer->handle();
11295 // Submit cmd buffer and then destroy query pool while in-flight
11296 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11297
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011298 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete query pool 0x");
Tobin Ehlis2adda372016-09-01 08:51:06 -070011299 vkDestroyQueryPool(m_device->handle(), query_pool, NULL);
11300 m_errorMonitor->VerifyFound();
11301
11302 vkQueueWaitIdle(m_device->m_queue);
11303 // Now that cmd buffer done we can safely destroy query_pool
11304 vkDestroyQueryPool(m_device->handle(), query_pool, NULL);
11305}
11306
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060011307TEST_F(VkLayerTest, PipelineInUseDestroyedSignaled) {
11308 TEST_DESCRIPTION("Delete in-use pipeline.");
11309
11310 ASSERT_NO_FATAL_FAILURE(InitState());
11311 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11312
11313 // Empty pipeline layout used for binding PSO
11314 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11315 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11316 pipeline_layout_ci.setLayoutCount = 0;
11317 pipeline_layout_ci.pSetLayouts = NULL;
11318
11319 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011320 VkResult err = vkCreatePipelineLayout(m_device->handle(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060011321 ASSERT_VK_SUCCESS(err);
11322
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011323 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete pipeline 0x");
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060011324 // Create PSO to be used for draw-time errors below
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011325 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
11326 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060011327 // Store pipeline handle so we can actually delete it before test finishes
11328 VkPipeline delete_this_pipeline;
11329 { // Scope pipeline so it will be auto-deleted
11330 VkPipelineObj pipe(m_device);
11331 pipe.AddShader(&vs);
11332 pipe.AddShader(&fs);
11333 pipe.AddColorAttachment();
11334 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11335 delete_this_pipeline = pipe.handle();
11336
11337 BeginCommandBuffer();
11338 // Bind pipeline to cmd buffer
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011339 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060011340
11341 EndCommandBuffer();
11342
11343 VkSubmitInfo submit_info = {};
11344 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11345 submit_info.commandBufferCount = 1;
11346 submit_info.pCommandBuffers = &m_commandBuffer->handle();
11347 // Submit cmd buffer and then pipeline destroyed while in-flight
11348 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11349 } // Pipeline deletion triggered here
11350 m_errorMonitor->VerifyFound();
11351 // Make sure queue finished and then actually delete pipeline
11352 vkQueueWaitIdle(m_device->m_queue);
11353 vkDestroyPipeline(m_device->handle(), delete_this_pipeline, nullptr);
11354 vkDestroyPipelineLayout(m_device->handle(), pipeline_layout, nullptr);
11355}
11356
Tobin Ehlis7d965da2016-09-19 16:15:45 -060011357TEST_F(VkLayerTest, ImageViewInUseDestroyedSignaled) {
11358 TEST_DESCRIPTION("Delete in-use imageView.");
11359
11360 ASSERT_NO_FATAL_FAILURE(InitState());
11361 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11362
11363 VkDescriptorPoolSize ds_type_count;
11364 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11365 ds_type_count.descriptorCount = 1;
11366
11367 VkDescriptorPoolCreateInfo ds_pool_ci = {};
11368 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11369 ds_pool_ci.maxSets = 1;
11370 ds_pool_ci.poolSizeCount = 1;
11371 ds_pool_ci.pPoolSizes = &ds_type_count;
11372
11373 VkDescriptorPool ds_pool;
11374 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
11375 ASSERT_VK_SUCCESS(err);
11376
11377 VkSamplerCreateInfo sampler_ci = {};
11378 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
11379 sampler_ci.pNext = NULL;
11380 sampler_ci.magFilter = VK_FILTER_NEAREST;
11381 sampler_ci.minFilter = VK_FILTER_NEAREST;
11382 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
11383 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11384 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11385 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11386 sampler_ci.mipLodBias = 1.0;
11387 sampler_ci.anisotropyEnable = VK_FALSE;
11388 sampler_ci.maxAnisotropy = 1;
11389 sampler_ci.compareEnable = VK_FALSE;
11390 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
11391 sampler_ci.minLod = 1.0;
11392 sampler_ci.maxLod = 1.0;
11393 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
11394 sampler_ci.unnormalizedCoordinates = VK_FALSE;
11395 VkSampler sampler;
11396
11397 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
11398 ASSERT_VK_SUCCESS(err);
11399
11400 VkDescriptorSetLayoutBinding layout_binding;
11401 layout_binding.binding = 0;
11402 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11403 layout_binding.descriptorCount = 1;
11404 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
11405 layout_binding.pImmutableSamplers = NULL;
11406
11407 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11408 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11409 ds_layout_ci.bindingCount = 1;
11410 ds_layout_ci.pBindings = &layout_binding;
11411 VkDescriptorSetLayout ds_layout;
11412 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
11413 ASSERT_VK_SUCCESS(err);
11414
11415 VkDescriptorSetAllocateInfo alloc_info = {};
11416 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11417 alloc_info.descriptorSetCount = 1;
11418 alloc_info.descriptorPool = ds_pool;
11419 alloc_info.pSetLayouts = &ds_layout;
11420 VkDescriptorSet descriptor_set;
11421 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
11422 ASSERT_VK_SUCCESS(err);
11423
11424 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11425 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11426 pipeline_layout_ci.pNext = NULL;
11427 pipeline_layout_ci.setLayoutCount = 1;
11428 pipeline_layout_ci.pSetLayouts = &ds_layout;
11429
11430 VkPipelineLayout pipeline_layout;
11431 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
11432 ASSERT_VK_SUCCESS(err);
11433
11434 VkImageObj image(m_device);
11435 image.init(128, 128, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
11436 ASSERT_TRUE(image.initialized());
11437
11438 VkImageView view;
11439 VkImageViewCreateInfo ivci = {};
11440 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
11441 ivci.image = image.handle();
11442 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
11443 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
11444 ivci.subresourceRange.layerCount = 1;
11445 ivci.subresourceRange.baseMipLevel = 0;
11446 ivci.subresourceRange.levelCount = 1;
11447 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11448
11449 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
11450 ASSERT_VK_SUCCESS(err);
11451
11452 VkDescriptorImageInfo image_info{};
11453 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
11454 image_info.imageView = view;
11455 image_info.sampler = sampler;
11456
11457 VkWriteDescriptorSet descriptor_write = {};
11458 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
11459 descriptor_write.dstSet = descriptor_set;
11460 descriptor_write.dstBinding = 0;
11461 descriptor_write.descriptorCount = 1;
11462 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11463 descriptor_write.pImageInfo = &image_info;
11464
11465 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11466
11467 // Create PSO to use the sampler
11468 char const *vsSource = "#version 450\n"
11469 "\n"
11470 "out gl_PerVertex { \n"
11471 " vec4 gl_Position;\n"
11472 "};\n"
11473 "void main(){\n"
11474 " gl_Position = vec4(1);\n"
11475 "}\n";
11476 char const *fsSource = "#version 450\n"
11477 "\n"
11478 "layout(set=0, binding=0) uniform sampler2D s;\n"
11479 "layout(location=0) out vec4 x;\n"
11480 "void main(){\n"
11481 " x = texture(s, vec2(1));\n"
11482 "}\n";
11483 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
11484 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
11485 VkPipelineObj pipe(m_device);
11486 pipe.AddShader(&vs);
11487 pipe.AddShader(&fs);
11488 pipe.AddColorAttachment();
11489 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11490
11491 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete image view 0x");
11492
11493 BeginCommandBuffer();
11494 // Bind pipeline to cmd buffer
11495 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
11496 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
11497 &descriptor_set, 0, nullptr);
11498 Draw(1, 0, 0, 0);
11499 EndCommandBuffer();
11500 // Submit cmd buffer then destroy sampler
11501 VkSubmitInfo submit_info = {};
11502 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11503 submit_info.commandBufferCount = 1;
11504 submit_info.pCommandBuffers = &m_commandBuffer->handle();
11505 // Submit cmd buffer and then destroy imageView while in-flight
11506 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11507
11508 vkDestroyImageView(m_device->device(), view, nullptr);
11509 m_errorMonitor->VerifyFound();
11510 vkQueueWaitIdle(m_device->m_queue);
11511 // Now we can actually destroy imageView
11512 vkDestroyImageView(m_device->device(), view, NULL);
11513 vkDestroySampler(m_device->device(), sampler, nullptr);
11514 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11515 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11516 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
11517}
11518
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060011519TEST_F(VkLayerTest, BufferViewInUseDestroyedSignaled) {
11520 TEST_DESCRIPTION("Delete in-use bufferView.");
11521
11522 ASSERT_NO_FATAL_FAILURE(InitState());
11523 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11524
11525 VkDescriptorPoolSize ds_type_count;
11526 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
11527 ds_type_count.descriptorCount = 1;
11528
11529 VkDescriptorPoolCreateInfo ds_pool_ci = {};
11530 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11531 ds_pool_ci.maxSets = 1;
11532 ds_pool_ci.poolSizeCount = 1;
11533 ds_pool_ci.pPoolSizes = &ds_type_count;
11534
11535 VkDescriptorPool ds_pool;
11536 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
11537 ASSERT_VK_SUCCESS(err);
11538
11539 VkDescriptorSetLayoutBinding layout_binding;
11540 layout_binding.binding = 0;
11541 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
11542 layout_binding.descriptorCount = 1;
11543 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
11544 layout_binding.pImmutableSamplers = NULL;
11545
11546 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11547 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11548 ds_layout_ci.bindingCount = 1;
11549 ds_layout_ci.pBindings = &layout_binding;
11550 VkDescriptorSetLayout ds_layout;
11551 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
11552 ASSERT_VK_SUCCESS(err);
11553
11554 VkDescriptorSetAllocateInfo alloc_info = {};
11555 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11556 alloc_info.descriptorSetCount = 1;
11557 alloc_info.descriptorPool = ds_pool;
11558 alloc_info.pSetLayouts = &ds_layout;
11559 VkDescriptorSet descriptor_set;
11560 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
11561 ASSERT_VK_SUCCESS(err);
11562
11563 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11564 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11565 pipeline_layout_ci.pNext = NULL;
11566 pipeline_layout_ci.setLayoutCount = 1;
11567 pipeline_layout_ci.pSetLayouts = &ds_layout;
11568
11569 VkPipelineLayout pipeline_layout;
11570 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
11571 ASSERT_VK_SUCCESS(err);
11572
11573 VkBuffer buffer;
11574 uint32_t queue_family_index = 0;
11575 VkBufferCreateInfo buffer_create_info = {};
11576 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
11577 buffer_create_info.size = 1024;
11578 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
11579 buffer_create_info.queueFamilyIndexCount = 1;
11580 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
11581
11582 err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
11583 ASSERT_VK_SUCCESS(err);
11584
11585 VkMemoryRequirements memory_reqs;
11586 VkDeviceMemory buffer_memory;
11587
11588 VkMemoryAllocateInfo memory_info = {};
11589 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
11590 memory_info.allocationSize = 0;
11591 memory_info.memoryTypeIndex = 0;
11592
11593 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
11594 memory_info.allocationSize = memory_reqs.size;
11595 bool pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
11596 ASSERT_TRUE(pass);
11597
11598 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
11599 ASSERT_VK_SUCCESS(err);
11600 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
11601 ASSERT_VK_SUCCESS(err);
11602
11603 VkBufferView view;
11604 VkBufferViewCreateInfo bvci = {};
11605 bvci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
11606 bvci.buffer = buffer;
11607 bvci.format = VK_FORMAT_R8_UNORM;
11608 bvci.range = VK_WHOLE_SIZE;
11609
11610 err = vkCreateBufferView(m_device->device(), &bvci, NULL, &view);
11611 ASSERT_VK_SUCCESS(err);
11612
11613 VkWriteDescriptorSet descriptor_write = {};
11614 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
11615 descriptor_write.dstSet = descriptor_set;
11616 descriptor_write.dstBinding = 0;
11617 descriptor_write.descriptorCount = 1;
11618 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
11619 descriptor_write.pTexelBufferView = &view;
11620
11621 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11622
11623 char const *vsSource = "#version 450\n"
11624 "\n"
11625 "out gl_PerVertex { \n"
11626 " vec4 gl_Position;\n"
11627 "};\n"
11628 "void main(){\n"
11629 " gl_Position = vec4(1);\n"
11630 "}\n";
11631 char const *fsSource = "#version 450\n"
11632 "\n"
11633 "layout(set=0, binding=0, r8) uniform imageBuffer s;\n"
11634 "layout(location=0) out vec4 x;\n"
11635 "void main(){\n"
11636 " x = imageLoad(s, 0);\n"
11637 "}\n";
11638 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
11639 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
11640 VkPipelineObj pipe(m_device);
11641 pipe.AddShader(&vs);
11642 pipe.AddShader(&fs);
11643 pipe.AddColorAttachment();
11644 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11645
11646 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete buffer view 0x");
11647
11648 BeginCommandBuffer();
11649 VkViewport viewport = {0, 0, 16, 16, 0, 1};
11650 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
11651 VkRect2D scissor = {{0, 0}, {16, 16}};
11652 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
11653 // Bind pipeline to cmd buffer
11654 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
11655 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
11656 &descriptor_set, 0, nullptr);
11657 Draw(1, 0, 0, 0);
11658 EndCommandBuffer();
11659
11660 VkSubmitInfo submit_info = {};
11661 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11662 submit_info.commandBufferCount = 1;
11663 submit_info.pCommandBuffers = &m_commandBuffer->handle();
11664 // Submit cmd buffer and then destroy bufferView while in-flight
11665 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11666
11667 vkDestroyBufferView(m_device->device(), view, nullptr);
11668 m_errorMonitor->VerifyFound();
11669 vkQueueWaitIdle(m_device->m_queue);
11670 // Now we can actually destroy bufferView
11671 vkDestroyBufferView(m_device->device(), view, NULL);
11672 vkDestroyBuffer(m_device->device(), buffer, NULL);
11673 vkFreeMemory(m_device->device(), buffer_memory, NULL);
11674 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11675 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11676 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
11677}
11678
Tobin Ehlis209532e2016-09-07 13:52:18 -060011679TEST_F(VkLayerTest, SamplerInUseDestroyedSignaled) {
11680 TEST_DESCRIPTION("Delete in-use sampler.");
11681
11682 ASSERT_NO_FATAL_FAILURE(InitState());
11683 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11684
11685 VkDescriptorPoolSize ds_type_count;
11686 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11687 ds_type_count.descriptorCount = 1;
11688
11689 VkDescriptorPoolCreateInfo ds_pool_ci = {};
11690 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11691 ds_pool_ci.maxSets = 1;
11692 ds_pool_ci.poolSizeCount = 1;
11693 ds_pool_ci.pPoolSizes = &ds_type_count;
11694
11695 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011696 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis209532e2016-09-07 13:52:18 -060011697 ASSERT_VK_SUCCESS(err);
11698
11699 VkSamplerCreateInfo sampler_ci = {};
11700 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
11701 sampler_ci.pNext = NULL;
11702 sampler_ci.magFilter = VK_FILTER_NEAREST;
11703 sampler_ci.minFilter = VK_FILTER_NEAREST;
11704 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
11705 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11706 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11707 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11708 sampler_ci.mipLodBias = 1.0;
11709 sampler_ci.anisotropyEnable = VK_FALSE;
11710 sampler_ci.maxAnisotropy = 1;
11711 sampler_ci.compareEnable = VK_FALSE;
11712 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
11713 sampler_ci.minLod = 1.0;
11714 sampler_ci.maxLod = 1.0;
11715 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
11716 sampler_ci.unnormalizedCoordinates = VK_FALSE;
11717 VkSampler sampler;
11718
11719 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
11720 ASSERT_VK_SUCCESS(err);
11721
11722 VkDescriptorSetLayoutBinding layout_binding;
11723 layout_binding.binding = 0;
Tobin Ehlis94fc0ad2016-09-19 16:23:01 -060011724 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
Tobin Ehlis209532e2016-09-07 13:52:18 -060011725 layout_binding.descriptorCount = 1;
11726 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
11727 layout_binding.pImmutableSamplers = NULL;
11728
11729 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11730 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11731 ds_layout_ci.bindingCount = 1;
11732 ds_layout_ci.pBindings = &layout_binding;
11733 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011734 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis209532e2016-09-07 13:52:18 -060011735 ASSERT_VK_SUCCESS(err);
11736
11737 VkDescriptorSetAllocateInfo alloc_info = {};
11738 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11739 alloc_info.descriptorSetCount = 1;
11740 alloc_info.descriptorPool = ds_pool;
11741 alloc_info.pSetLayouts = &ds_layout;
11742 VkDescriptorSet descriptor_set;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011743 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis209532e2016-09-07 13:52:18 -060011744 ASSERT_VK_SUCCESS(err);
11745
11746 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11747 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11748 pipeline_layout_ci.pNext = NULL;
11749 pipeline_layout_ci.setLayoutCount = 1;
11750 pipeline_layout_ci.pSetLayouts = &ds_layout;
11751
11752 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011753 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis209532e2016-09-07 13:52:18 -060011754 ASSERT_VK_SUCCESS(err);
11755
11756 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011757 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 -060011758 ASSERT_TRUE(image.initialized());
11759
11760 VkImageView view;
11761 VkImageViewCreateInfo ivci = {};
11762 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
11763 ivci.image = image.handle();
11764 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
11765 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
11766 ivci.subresourceRange.layerCount = 1;
11767 ivci.subresourceRange.baseMipLevel = 0;
11768 ivci.subresourceRange.levelCount = 1;
11769 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11770
11771 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
11772 ASSERT_VK_SUCCESS(err);
11773
11774 VkDescriptorImageInfo image_info{};
11775 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
11776 image_info.imageView = view;
11777 image_info.sampler = sampler;
11778
11779 VkWriteDescriptorSet descriptor_write = {};
11780 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
11781 descriptor_write.dstSet = descriptor_set;
11782 descriptor_write.dstBinding = 0;
11783 descriptor_write.descriptorCount = 1;
11784 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11785 descriptor_write.pImageInfo = &image_info;
11786
11787 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11788
11789 // Create PSO to use the sampler
11790 char const *vsSource = "#version 450\n"
11791 "\n"
11792 "out gl_PerVertex { \n"
11793 " vec4 gl_Position;\n"
11794 "};\n"
11795 "void main(){\n"
11796 " gl_Position = vec4(1);\n"
11797 "}\n";
11798 char const *fsSource = "#version 450\n"
11799 "\n"
11800 "layout(set=0, binding=0) uniform sampler2D s;\n"
11801 "layout(location=0) out vec4 x;\n"
11802 "void main(){\n"
11803 " x = texture(s, vec2(1));\n"
11804 "}\n";
11805 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
11806 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
11807 VkPipelineObj pipe(m_device);
11808 pipe.AddShader(&vs);
11809 pipe.AddShader(&fs);
11810 pipe.AddColorAttachment();
11811 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11812
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011813 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete sampler 0x");
Tobin Ehlis209532e2016-09-07 13:52:18 -060011814
11815 BeginCommandBuffer();
11816 // Bind pipeline to cmd buffer
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011817 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
11818 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
11819 &descriptor_set, 0, nullptr);
Tobin Ehlis209532e2016-09-07 13:52:18 -060011820 Draw(1, 0, 0, 0);
11821 EndCommandBuffer();
11822 // Submit cmd buffer then destroy sampler
11823 VkSubmitInfo submit_info = {};
11824 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11825 submit_info.commandBufferCount = 1;
11826 submit_info.pCommandBuffers = &m_commandBuffer->handle();
11827 // Submit cmd buffer and then destroy sampler while in-flight
11828 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11829
11830 vkDestroySampler(m_device->device(), sampler, nullptr);
11831 m_errorMonitor->VerifyFound();
11832 vkQueueWaitIdle(m_device->m_queue);
11833 // Now we can actually destroy sampler
11834 vkDestroySampler(m_device->device(), sampler, nullptr);
11835 vkDestroyImageView(m_device->device(), view, NULL);
11836 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11837 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11838 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
11839}
11840
Mark Mueller1cd9f412016-08-25 13:23:52 -060011841TEST_F(VkLayerTest, QueueForwardProgressFenceWait) {
Mark Mueller96a56d52016-08-24 10:28:05 -060011842 TEST_DESCRIPTION("Call VkQueueSubmit with a semaphore that is already "
Mark Mueller1cd9f412016-08-25 13:23:52 -060011843 "signaled but not waited on by the queue. Wait on a "
11844 "fence that has not yet been submitted to a queue.");
Mark Mueller96a56d52016-08-24 10:28:05 -060011845
11846 ASSERT_NO_FATAL_FAILURE(InitState());
11847 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11848
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011849 const char *queue_forward_progress_message = " that has already been signaled but not waited on by queue 0x";
11850 const char *invalid_fence_wait_message = " which has not been submitted on a Queue or during "
11851 "acquire next image.";
Mark Mueller96a56d52016-08-24 10:28:05 -060011852
11853 BeginCommandBuffer();
11854 EndCommandBuffer();
11855
11856 VkSemaphoreCreateInfo semaphore_create_info = {};
11857 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
11858 VkSemaphore semaphore;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011859 ASSERT_VK_SUCCESS(vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore));
Mark Mueller96a56d52016-08-24 10:28:05 -060011860 VkSubmitInfo submit_info = {};
11861 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11862 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011863 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Mueller96a56d52016-08-24 10:28:05 -060011864 submit_info.signalSemaphoreCount = 1;
11865 submit_info.pSignalSemaphores = &semaphore;
11866 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11867 m_errorMonitor->SetDesiredFailureMsg(0, "");
11868 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
11869 BeginCommandBuffer();
11870 EndCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011871 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, queue_forward_progress_message);
Mark Mueller96a56d52016-08-24 10:28:05 -060011872 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11873 m_errorMonitor->VerifyFound();
11874
Mark Mueller1cd9f412016-08-25 13:23:52 -060011875 VkFenceCreateInfo fence_create_info = {};
11876 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
11877 VkFence fence;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011878 ASSERT_VK_SUCCESS(vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence));
Mark Mueller1cd9f412016-08-25 13:23:52 -060011879
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011880 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, invalid_fence_wait_message);
Mark Mueller1cd9f412016-08-25 13:23:52 -060011881 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
11882 m_errorMonitor->VerifyFound();
11883
Mark Mueller4042b652016-09-05 22:52:21 -060011884 vkDeviceWaitIdle(m_device->device());
Mark Mueller1cd9f412016-08-25 13:23:52 -060011885 vkDestroyFence(m_device->device(), fence, nullptr);
Mark Mueller96a56d52016-08-24 10:28:05 -060011886 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
11887}
11888
Tobin Ehlis4af23302016-07-19 10:50:30 -060011889TEST_F(VkLayerTest, FramebufferIncompatible) {
11890 TEST_DESCRIPTION("Bind a secondary command buffer with with a framebuffer "
11891 "that does not match the framebuffer for the active "
11892 "renderpass.");
11893 ASSERT_NO_FATAL_FAILURE(InitState());
11894 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11895
11896 // A renderpass with one color attachment.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011897 VkAttachmentDescription attachment = {0,
11898 VK_FORMAT_B8G8R8A8_UNORM,
11899 VK_SAMPLE_COUNT_1_BIT,
11900 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
11901 VK_ATTACHMENT_STORE_OP_STORE,
11902 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
11903 VK_ATTACHMENT_STORE_OP_DONT_CARE,
11904 VK_IMAGE_LAYOUT_UNDEFINED,
11905 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis4af23302016-07-19 10:50:30 -060011906
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011907 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis4af23302016-07-19 10:50:30 -060011908
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011909 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Tobin Ehlis4af23302016-07-19 10:50:30 -060011910
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011911 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
Tobin Ehlis4af23302016-07-19 10:50:30 -060011912
11913 VkRenderPass rp;
11914 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
11915 ASSERT_VK_SUCCESS(err);
11916
11917 // A compatible framebuffer.
11918 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011919 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 -060011920 ASSERT_TRUE(image.initialized());
11921
11922 VkImageViewCreateInfo ivci = {
11923 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
11924 nullptr,
11925 0,
11926 image.handle(),
11927 VK_IMAGE_VIEW_TYPE_2D,
11928 VK_FORMAT_B8G8R8A8_UNORM,
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011929 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
11930 VK_COMPONENT_SWIZZLE_IDENTITY},
Tobin Ehlis4af23302016-07-19 10:50:30 -060011931 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
11932 };
11933 VkImageView view;
11934 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
11935 ASSERT_VK_SUCCESS(err);
11936
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011937 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Tobin Ehlis4af23302016-07-19 10:50:30 -060011938 VkFramebuffer fb;
11939 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
11940 ASSERT_VK_SUCCESS(err);
11941
11942 VkCommandBufferAllocateInfo cbai = {};
11943 cbai.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
11944 cbai.commandPool = m_commandPool;
11945 cbai.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
11946 cbai.commandBufferCount = 1;
11947
11948 VkCommandBuffer sec_cb;
11949 err = vkAllocateCommandBuffers(m_device->device(), &cbai, &sec_cb);
11950 ASSERT_VK_SUCCESS(err);
11951 VkCommandBufferBeginInfo cbbi = {};
11952 VkCommandBufferInheritanceInfo cbii = {};
Chris Forbes98420382016-11-28 17:56:51 +130011953 cbii.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
Tobin Ehlis4af23302016-07-19 10:50:30 -060011954 cbii.renderPass = renderPass();
11955 cbii.framebuffer = fb;
11956 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
11957 cbbi.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011958 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 -060011959 cbbi.pInheritanceInfo = &cbii;
11960 vkBeginCommandBuffer(sec_cb, &cbbi);
11961 vkEndCommandBuffer(sec_cb);
11962
Chris Forbes3400bc52016-09-13 18:10:34 +120011963 VkCommandBufferBeginInfo cbbi2 = {
11964 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr,
11965 0, nullptr
11966 };
11967 vkBeginCommandBuffer(m_commandBuffer->GetBufferHandle(), &cbbi2);
11968 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
Tobin Ehlis4af23302016-07-19 10:50:30 -060011969
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011970 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mike Weiblencce7ec72016-10-17 19:33:05 -060011971 " that is not the same as the primary command buffer's current active framebuffer ");
Tobin Ehlis4af23302016-07-19 10:50:30 -060011972 vkCmdExecuteCommands(m_commandBuffer->GetBufferHandle(), 1, &sec_cb);
11973 m_errorMonitor->VerifyFound();
11974 // Cleanup
11975 vkDestroyImageView(m_device->device(), view, NULL);
11976 vkDestroyRenderPass(m_device->device(), rp, NULL);
11977 vkDestroyFramebuffer(m_device->device(), fb, NULL);
11978}
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011979
11980TEST_F(VkLayerTest, ColorBlendLogicOpTests) {
11981 TEST_DESCRIPTION("If logicOp is available on the device, set it to an "
11982 "invalid value. If logicOp is not available, attempt to "
11983 "use it and verify that we see the correct error.");
11984 ASSERT_NO_FATAL_FAILURE(InitState());
11985 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11986
11987 auto features = m_device->phy().features();
11988 // Set the expected error depending on whether or not logicOp available
11989 if (VK_FALSE == features.logicOp) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011990 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "If logic operations feature not "
11991 "enabled, logicOpEnable must be "
11992 "VK_FALSE");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011993 } else {
Chris Forbes34797bc2016-10-03 15:28:49 +130011994 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "pColorBlendState->logicOp (16)");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011995 }
11996 // Create a pipeline using logicOp
11997 VkResult err;
11998
11999 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
12000 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12001
12002 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012003 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012004 ASSERT_VK_SUCCESS(err);
12005
12006 VkPipelineViewportStateCreateInfo vp_state_ci = {};
12007 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
12008 vp_state_ci.viewportCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012009 VkViewport vp = {}; // Just need dummy vp to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012010 vp_state_ci.pViewports = &vp;
12011 vp_state_ci.scissorCount = 1;
12012 VkRect2D scissors = {}; // Dummy scissors to point to
12013 vp_state_ci.pScissors = &scissors;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012014
12015 VkPipelineShaderStageCreateInfo shaderStages[2];
12016 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
12017
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012018 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
12019 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012020 shaderStages[0] = vs.GetStageCreateInfo();
12021 shaderStages[1] = fs.GetStageCreateInfo();
12022
12023 VkPipelineVertexInputStateCreateInfo vi_ci = {};
12024 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
12025
12026 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
12027 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
12028 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
12029
12030 VkPipelineRasterizationStateCreateInfo rs_ci = {};
12031 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Chris Forbes14088512016-10-03 14:28:00 +130012032 rs_ci.lineWidth = 1.0f;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012033
12034 VkPipelineColorBlendAttachmentState att = {};
12035 att.blendEnable = VK_FALSE;
12036 att.colorWriteMask = 0xf;
12037
12038 VkPipelineColorBlendStateCreateInfo cb_ci = {};
12039 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
12040 // Enable logicOp & set logicOp to value 1 beyond allowed entries
12041 cb_ci.logicOpEnable = VK_TRUE;
12042 cb_ci.logicOp = VK_LOGIC_OP_RANGE_SIZE; // This should cause an error
12043 cb_ci.attachmentCount = 1;
12044 cb_ci.pAttachments = &att;
12045
Chris Forbes8aeacbf2016-10-03 14:25:08 +130012046 VkPipelineMultisampleStateCreateInfo ms_ci = {};
12047 ms_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
12048 ms_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
12049
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012050 VkGraphicsPipelineCreateInfo gp_ci = {};
12051 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
12052 gp_ci.stageCount = 2;
12053 gp_ci.pStages = shaderStages;
12054 gp_ci.pVertexInputState = &vi_ci;
12055 gp_ci.pInputAssemblyState = &ia_ci;
12056 gp_ci.pViewportState = &vp_state_ci;
12057 gp_ci.pRasterizationState = &rs_ci;
12058 gp_ci.pColorBlendState = &cb_ci;
Chris Forbes8aeacbf2016-10-03 14:25:08 +130012059 gp_ci.pMultisampleState = &ms_ci;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012060 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
12061 gp_ci.layout = pipeline_layout;
12062 gp_ci.renderPass = renderPass();
12063
12064 VkPipelineCacheCreateInfo pc_ci = {};
12065 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
12066
12067 VkPipeline pipeline;
12068 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012069 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012070 ASSERT_VK_SUCCESS(err);
12071
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012072 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012073 m_errorMonitor->VerifyFound();
12074 if (VK_SUCCESS == err) {
12075 vkDestroyPipeline(m_device->device(), pipeline, NULL);
12076 }
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012077 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
12078 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
12079}
Mark Lobodzinski209b5292015-09-17 09:44:05 -060012080#endif // DRAW_STATE_TESTS
12081
Tobin Ehlis0788f522015-05-26 16:11:58 -060012082#if THREADING_TESTS
Mike Stroyanaccf7692015-05-12 16:00:45 -060012083#if GTEST_IS_THREADSAFE
12084struct thread_data_struct {
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012085 VkCommandBuffer commandBuffer;
Mike Stroyanaccf7692015-05-12 16:00:45 -060012086 VkEvent event;
12087 bool bailout;
12088};
12089
Karl Schultz6addd812016-02-02 17:17:23 -070012090extern "C" void *AddToCommandBuffer(void *arg) {
12091 struct thread_data_struct *data = (struct thread_data_struct *)arg;
Mike Stroyanaccf7692015-05-12 16:00:45 -060012092
Mike Stroyana6d14942016-07-13 15:10:05 -060012093 for (int i = 0; i < 80000; i++) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012094 vkCmdSetEvent(data->commandBuffer, data->event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Mike Stroyanaccf7692015-05-12 16:00:45 -060012095 if (data->bailout) {
12096 break;
12097 }
12098 }
12099 return NULL;
12100}
12101
Karl Schultz6addd812016-02-02 17:17:23 -070012102TEST_F(VkLayerTest, ThreadCommandBufferCollision) {
Mike Stroyan4268d1f2015-07-13 14:45:35 -060012103 test_platform_thread thread;
Mike Stroyanaccf7692015-05-12 16:00:45 -060012104
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012105 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "THREADING ERROR");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012106
Mike Stroyanaccf7692015-05-12 16:00:45 -060012107 ASSERT_NO_FATAL_FAILURE(InitState());
12108 ASSERT_NO_FATAL_FAILURE(InitViewport());
12109 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12110
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012111 // Calls AllocateCommandBuffers
12112 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Mark Lobodzinski5495d132015-09-30 16:19:16 -060012113
12114 // Avoid creating RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012115 commandBuffer.BeginCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -060012116
12117 VkEventCreateInfo event_info;
12118 VkEvent event;
Mike Stroyanaccf7692015-05-12 16:00:45 -060012119 VkResult err;
12120
12121 memset(&event_info, 0, sizeof(event_info));
12122 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
12123
Chia-I Wuf7458c52015-10-26 21:10:41 +080012124 err = vkCreateEvent(device(), &event_info, NULL, &event);
Mike Stroyanaccf7692015-05-12 16:00:45 -060012125 ASSERT_VK_SUCCESS(err);
12126
Mike Stroyanaccf7692015-05-12 16:00:45 -060012127 err = vkResetEvent(device(), event);
12128 ASSERT_VK_SUCCESS(err);
12129
12130 struct thread_data_struct data;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012131 data.commandBuffer = commandBuffer.GetBufferHandle();
Mike Stroyanaccf7692015-05-12 16:00:45 -060012132 data.event = event;
12133 data.bailout = false;
12134 m_errorMonitor->SetBailout(&data.bailout);
Mike Stroyana6d14942016-07-13 15:10:05 -060012135
12136 // First do some correct operations using multiple threads.
12137 // Add many entries to command buffer from another thread.
12138 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
12139 // Make non-conflicting calls from this thread at the same time.
12140 for (int i = 0; i < 80000; i++) {
Mike Stroyand6343902016-07-14 08:56:16 -060012141 uint32_t count;
12142 vkEnumeratePhysicalDevices(instance(), &count, NULL);
Mike Stroyana6d14942016-07-13 15:10:05 -060012143 }
12144 test_platform_thread_join(thread, NULL);
12145
12146 // Then do some incorrect operations using multiple threads.
Mike Stroyanaccf7692015-05-12 16:00:45 -060012147 // Add many entries to command buffer from another thread.
Mike Stroyan4268d1f2015-07-13 14:45:35 -060012148 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
Mike Stroyanaccf7692015-05-12 16:00:45 -060012149 // Add many entries to command buffer from this thread at the same time.
12150 AddToCommandBuffer(&data);
Mark Lobodzinski5495d132015-09-30 16:19:16 -060012151
Mike Stroyan4268d1f2015-07-13 14:45:35 -060012152 test_platform_thread_join(thread, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012153 commandBuffer.EndCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -060012154
Mike Stroyan10b8cb72016-01-22 15:22:03 -070012155 m_errorMonitor->SetBailout(NULL);
12156
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012157 m_errorMonitor->VerifyFound();
Mike Stroyanaccf7692015-05-12 16:00:45 -060012158
Chia-I Wuf7458c52015-10-26 21:10:41 +080012159 vkDestroyEvent(device(), event, NULL);
Mike Stroyanaccf7692015-05-12 16:00:45 -060012160}
Mark Lobodzinski209b5292015-09-17 09:44:05 -060012161#endif // GTEST_IS_THREADSAFE
12162#endif // THREADING_TESTS
12163
Chris Forbes9f7ff632015-05-25 11:13:08 +120012164#if SHADER_CHECKER_TESTS
Karl Schultz6addd812016-02-02 17:17:23 -070012165TEST_F(VkLayerTest, InvalidSPIRVCodeSize) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012166 TEST_DESCRIPTION("Test that an error is produced for a spirv module "
12167 "with an impossible code size");
12168
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012169 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012170
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012171 ASSERT_NO_FATAL_FAILURE(InitState());
12172 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12173
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012174 VkShaderModule module;
12175 VkShaderModuleCreateInfo moduleCreateInfo;
12176 struct icd_spv_header spv;
12177
12178 spv.magic = ICD_SPV_MAGIC;
12179 spv.version = ICD_SPV_VERSION;
12180 spv.gen_magic = 0;
12181
12182 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
12183 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -070012184 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012185 moduleCreateInfo.codeSize = 4;
12186 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080012187 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012188
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012189 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012190}
12191
Karl Schultz6addd812016-02-02 17:17:23 -070012192TEST_F(VkLayerTest, InvalidSPIRVMagic) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012193 TEST_DESCRIPTION("Test that an error is produced for a spirv module "
12194 "with a bad magic number");
12195
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012196 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid SPIR-V magic number");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012197
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012198 ASSERT_NO_FATAL_FAILURE(InitState());
12199 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12200
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012201 VkShaderModule module;
12202 VkShaderModuleCreateInfo moduleCreateInfo;
12203 struct icd_spv_header spv;
12204
12205 spv.magic = ~ICD_SPV_MAGIC;
12206 spv.version = ICD_SPV_VERSION;
12207 spv.gen_magic = 0;
12208
12209 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
12210 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -070012211 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012212 moduleCreateInfo.codeSize = sizeof(spv) + 10;
12213 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080012214 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012215
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012216 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012217}
12218
Chris Forbesb4afd0f2016-04-04 10:48:35 +120012219#if 0
12220// Not currently covered by SPIRV-Tools validator
Karl Schultz6addd812016-02-02 17:17:23 -070012221TEST_F(VkLayerTest, InvalidSPIRVVersion) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -070012222 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbesb4afd0f2016-04-04 10:48:35 +120012223 "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012224
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012225 ASSERT_NO_FATAL_FAILURE(InitState());
12226 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12227
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012228 VkShaderModule module;
12229 VkShaderModuleCreateInfo moduleCreateInfo;
12230 struct icd_spv_header spv;
12231
12232 spv.magic = ICD_SPV_MAGIC;
12233 spv.version = ~ICD_SPV_VERSION;
12234 spv.gen_magic = 0;
12235
12236 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
12237 moduleCreateInfo.pNext = NULL;
12238
Karl Schultz6addd812016-02-02 17:17:23 -070012239 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012240 moduleCreateInfo.codeSize = sizeof(spv) + 10;
12241 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080012242 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012243
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012244 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012245}
Chris Forbesb4afd0f2016-04-04 10:48:35 +120012246#endif
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012247
Karl Schultz6addd812016-02-02 17:17:23 -070012248TEST_F(VkLayerTest, CreatePipelineVertexOutputNotConsumed) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012249 TEST_DESCRIPTION("Test that a warning is produced for a vertex output that "
12250 "is not consumed by the fragment stage");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012251 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "not consumed by fragment shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012252
Chris Forbes9f7ff632015-05-25 11:13:08 +120012253 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060012254 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes9f7ff632015-05-25 11:13:08 +120012255
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012256 char const *vsSource = "#version 450\n"
12257 "\n"
12258 "layout(location=0) out float x;\n"
12259 "out gl_PerVertex {\n"
12260 " vec4 gl_Position;\n"
12261 "};\n"
12262 "void main(){\n"
12263 " gl_Position = vec4(1);\n"
12264 " x = 0;\n"
12265 "}\n";
12266 char const *fsSource = "#version 450\n"
12267 "\n"
12268 "layout(location=0) out vec4 color;\n"
12269 "void main(){\n"
12270 " color = vec4(1);\n"
12271 "}\n";
Chris Forbes9f7ff632015-05-25 11:13:08 +120012272
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012273 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12274 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes9f7ff632015-05-25 11:13:08 +120012275
12276 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080012277 pipe.AddColorAttachment();
Chris Forbes9f7ff632015-05-25 11:13:08 +120012278 pipe.AddShader(&vs);
12279 pipe.AddShader(&fs);
12280
Chris Forbes9f7ff632015-05-25 11:13:08 +120012281 VkDescriptorSetObj descriptorSet(m_device);
12282 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012283 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes9f7ff632015-05-25 11:13:08 +120012284
Tony Barbour5781e8f2015-08-04 16:23:11 -060012285 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes9f7ff632015-05-25 11:13:08 +120012286
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012287 m_errorMonitor->VerifyFound();
Chris Forbes9f7ff632015-05-25 11:13:08 +120012288}
Chris Forbes9f7ff632015-05-25 11:13:08 +120012289
Mark Mueller098c9cb2016-09-08 09:01:57 -060012290TEST_F(VkLayerTest, CreatePipelineCheckShaderBadSpecialization) {
12291 TEST_DESCRIPTION("Challenge core_validation with shader validation issues related to vkCreateGraphicsPipelines.");
12292
12293 ASSERT_NO_FATAL_FAILURE(InitState());
12294 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12295
12296 const char *bad_specialization_message =
12297 "Specialization entry 0 (for constant id 0) references memory outside provided specialization data ";
12298
12299 char const *vsSource =
12300 "#version 450\n"
12301 "\n"
12302 "out gl_PerVertex {\n"
12303 " vec4 gl_Position;\n"
12304 "};\n"
12305 "void main(){\n"
12306 " gl_Position = vec4(1);\n"
12307 "}\n";
12308
12309 char const *fsSource =
12310 "#version 450\n"
12311 "\n"
12312 "layout (constant_id = 0) const float r = 0.0f;\n"
12313 "layout(location = 0) out vec4 uFragColor;\n"
12314 "void main(){\n"
12315 " uFragColor = vec4(r,1,0,1);\n"
12316 "}\n";
12317
12318 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12319 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12320
12321 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
12322 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12323
12324 VkPipelineLayout pipeline_layout;
12325 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
12326
12327 VkPipelineViewportStateCreateInfo vp_state_create_info = {};
12328 vp_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
12329 vp_state_create_info.viewportCount = 1;
12330 VkViewport viewport = {};
12331 vp_state_create_info.pViewports = &viewport;
12332 vp_state_create_info.scissorCount = 1;
12333 VkRect2D scissors = {};
12334 vp_state_create_info.pScissors = &scissors;
12335
12336 VkDynamicState scissor_state = VK_DYNAMIC_STATE_SCISSOR;
12337
12338 VkPipelineDynamicStateCreateInfo pipeline_dynamic_state_create_info = {};
12339 pipeline_dynamic_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
12340 pipeline_dynamic_state_create_info.dynamicStateCount = 1;
12341 pipeline_dynamic_state_create_info.pDynamicStates = &scissor_state;
12342
12343 VkPipelineShaderStageCreateInfo shader_stage_create_info[2] = {
12344 vs.GetStageCreateInfo(),
12345 fs.GetStageCreateInfo()
12346 };
12347
12348 VkPipelineVertexInputStateCreateInfo vertex_input_create_info = {};
12349 vertex_input_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
12350
12351 VkPipelineInputAssemblyStateCreateInfo input_assembly_create_info = {};
12352 input_assembly_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
12353 input_assembly_create_info.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
12354
12355 VkPipelineRasterizationStateCreateInfo rasterization_state_create_info = {};
12356 rasterization_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
12357 rasterization_state_create_info.pNext = nullptr;
12358 rasterization_state_create_info.lineWidth = 1.0f;
12359 rasterization_state_create_info.rasterizerDiscardEnable = true;
12360
12361 VkPipelineColorBlendAttachmentState color_blend_attachment_state = {};
12362 color_blend_attachment_state.blendEnable = VK_FALSE;
12363 color_blend_attachment_state.colorWriteMask = 0xf;
12364
12365 VkPipelineColorBlendStateCreateInfo color_blend_state_create_info = {};
12366 color_blend_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
12367 color_blend_state_create_info.attachmentCount = 1;
12368 color_blend_state_create_info.pAttachments = &color_blend_attachment_state;
12369
12370 VkGraphicsPipelineCreateInfo graphicspipe_create_info = {};
12371 graphicspipe_create_info.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
12372 graphicspipe_create_info.stageCount = 2;
12373 graphicspipe_create_info.pStages = shader_stage_create_info;
12374 graphicspipe_create_info.pVertexInputState = &vertex_input_create_info;
12375 graphicspipe_create_info.pInputAssemblyState = &input_assembly_create_info;
12376 graphicspipe_create_info.pViewportState = &vp_state_create_info;
12377 graphicspipe_create_info.pRasterizationState = &rasterization_state_create_info;
12378 graphicspipe_create_info.pColorBlendState = &color_blend_state_create_info;
12379 graphicspipe_create_info.pDynamicState = &pipeline_dynamic_state_create_info;
12380 graphicspipe_create_info.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
12381 graphicspipe_create_info.layout = pipeline_layout;
12382 graphicspipe_create_info.renderPass = renderPass();
12383
12384 VkPipelineCacheCreateInfo pipeline_cache_create_info = {};
12385 pipeline_cache_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
12386
12387 VkPipelineCache pipelineCache;
12388 ASSERT_VK_SUCCESS(vkCreatePipelineCache(m_device->device(), &pipeline_cache_create_info, nullptr, &pipelineCache));
12389
12390 // This structure maps constant ids to data locations.
12391 const VkSpecializationMapEntry entry =
12392 // id, offset, size
12393 {0, 4, sizeof(uint32_t)}; // Challenge core validation by using a bogus offset.
12394
12395 uint32_t data = 1;
12396
12397 // Set up the info describing spec map and data
12398 const VkSpecializationInfo specialization_info = {
12399 1,
12400 &entry,
12401 1 * sizeof(float),
12402 &data,
12403 };
12404 shader_stage_create_info[0].pSpecializationInfo = &specialization_info;
12405
12406 VkPipeline pipeline;
12407 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bad_specialization_message);
12408 vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &graphicspipe_create_info, nullptr, &pipeline);
12409 m_errorMonitor->VerifyFound();
12410
12411 vkDestroyPipelineCache(m_device->device(), pipelineCache, nullptr);
12412 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
12413}
12414
12415TEST_F(VkLayerTest, CreatePipelineCheckShaderDescriptorTypeMismatch) {
12416 TEST_DESCRIPTION("Challenge core_validation with shader validation issues related to vkCreateGraphicsPipelines.");
12417
12418 ASSERT_NO_FATAL_FAILURE(InitState());
12419 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12420
12421 const char *descriptor_type_mismatch_message = "Type mismatch on descriptor slot 0.0 (used as type ";
12422
12423 VkDescriptorPoolSize descriptor_pool_type_count[2] = {};
12424 descriptor_pool_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
12425 descriptor_pool_type_count[0].descriptorCount = 1;
12426 descriptor_pool_type_count[1].type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
12427 descriptor_pool_type_count[1].descriptorCount = 1;
12428
12429 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
12430 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12431 descriptor_pool_create_info.maxSets = 1;
12432 descriptor_pool_create_info.poolSizeCount = 2;
12433 descriptor_pool_create_info.pPoolSizes = descriptor_pool_type_count;
12434 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
12435
12436 VkDescriptorPool descriptorset_pool;
12437 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
12438
12439 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
12440 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
12441 descriptorset_layout_binding.descriptorCount = 1;
12442 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_ALL;
12443
12444 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
12445 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
12446 descriptorset_layout_create_info.bindingCount = 1;
12447 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
12448
12449 VkDescriptorSetLayout descriptorset_layout;
12450 ASSERT_VK_SUCCESS(vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
12451
12452 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
12453 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
12454 descriptorset_allocate_info.descriptorSetCount = 1;
12455 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
12456 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
12457 VkDescriptorSet descriptorset;
12458 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
12459
12460 // Challenge core_validation with a non uniform buffer type.
12461 VkBufferTest storage_buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT);
12462
Mark Mueller098c9cb2016-09-08 09:01:57 -060012463 char const *vsSource =
12464 "#version 450\n"
12465 "\n"
12466 "layout (std140, set = 0, binding = 0) uniform buf {\n"
12467 " mat4 mvp;\n"
12468 "} ubuf;\n"
12469 "out gl_PerVertex {\n"
12470 " vec4 gl_Position;\n"
12471 "};\n"
12472 "void main(){\n"
12473 " gl_Position = ubuf.mvp * vec4(1);\n"
12474 "}\n";
12475
12476 char const *fsSource =
12477 "#version 450\n"
12478 "\n"
12479 "layout(location = 0) out vec4 uFragColor;\n"
12480 "void main(){\n"
12481 " uFragColor = vec4(0,1,0,1);\n"
12482 "}\n";
12483
12484 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12485 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12486
12487 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
12488 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12489 pipeline_layout_create_info.setLayoutCount = 1;
12490 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
12491
12492 VkPipelineLayout pipeline_layout;
12493 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
12494
12495 VkPipelineObj pipe(m_device);
12496 pipe.AddColorAttachment();
12497 pipe.AddShader(&vs);
12498 pipe.AddShader(&fs);
12499
12500 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, descriptor_type_mismatch_message);
12501 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12502 m_errorMonitor->VerifyFound();
12503
12504 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
12505 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
12506 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
12507}
12508
12509TEST_F(VkLayerTest, CreatePipelineCheckShaderDescriptorNotAccessible) {
12510 TEST_DESCRIPTION(
12511 "Create a pipeline in which a descriptor used by a shader stage does not include that stage in its stageFlags.");
12512
12513 ASSERT_NO_FATAL_FAILURE(InitState());
12514 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12515
12516 const char *descriptor_not_accessible_message = "Shader uses descriptor slot 0.0 (used as type ";
12517
12518 VkDescriptorPoolSize descriptor_pool_type_count = {};
12519 descriptor_pool_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
12520 descriptor_pool_type_count.descriptorCount = 1;
12521
12522 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
12523 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12524 descriptor_pool_create_info.maxSets = 1;
12525 descriptor_pool_create_info.poolSizeCount = 1;
12526 descriptor_pool_create_info.pPoolSizes = &descriptor_pool_type_count;
12527 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
12528
12529 VkDescriptorPool descriptorset_pool;
12530 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
12531
12532 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
12533 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
12534 descriptorset_layout_binding.descriptorCount = 1;
12535 // Intentionally make the uniform buffer inaccessible to the vertex shader to challenge core_validation
12536 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
12537
12538 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
12539 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
12540 descriptorset_layout_create_info.bindingCount = 1;
12541 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
12542
12543 VkDescriptorSetLayout descriptorset_layout;
12544 ASSERT_VK_SUCCESS(vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info,
12545 nullptr, &descriptorset_layout));
12546
12547 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
12548 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
12549 descriptorset_allocate_info.descriptorSetCount = 1;
12550 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
12551 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
12552 VkDescriptorSet descriptorset;
12553 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
12554
12555 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
12556
Mark Mueller098c9cb2016-09-08 09:01:57 -060012557 char const *vsSource =
12558 "#version 450\n"
12559 "\n"
12560 "layout (std140, set = 0, binding = 0) uniform buf {\n"
12561 " mat4 mvp;\n"
12562 "} ubuf;\n"
12563 "out gl_PerVertex {\n"
12564 " vec4 gl_Position;\n"
12565 "};\n"
12566 "void main(){\n"
12567 " gl_Position = ubuf.mvp * vec4(1);\n"
12568 "}\n";
12569
12570 char const *fsSource =
12571 "#version 450\n"
12572 "\n"
12573 "layout(location = 0) out vec4 uFragColor;\n"
12574 "void main(){\n"
12575 " uFragColor = vec4(0,1,0,1);\n"
12576 "}\n";
12577
12578 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12579 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12580
12581 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
12582 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12583 pipeline_layout_create_info.setLayoutCount = 1;
12584 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
12585
12586 VkPipelineLayout pipeline_layout;
12587 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
12588
12589 VkPipelineObj pipe(m_device);
12590 pipe.AddColorAttachment();
12591 pipe.AddShader(&vs);
12592 pipe.AddShader(&fs);
12593
12594 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, descriptor_not_accessible_message);
12595 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12596 m_errorMonitor->VerifyFound();
12597
12598 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
12599 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
12600 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
12601}
12602
12603TEST_F(VkLayerTest, CreatePipelineCheckShaderPushConstantNotAccessible) {
12604 TEST_DESCRIPTION("Create a graphics pipleine in which a push constant range containing a push constant block member is not "
12605 "accessible from the current shader stage.");
12606
12607 ASSERT_NO_FATAL_FAILURE(InitState());
12608 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12609
12610 const char *push_constant_not_accessible_message =
12611 "Push constant range covering variable starting at offset 0 not accessible from stage VK_SHADER_STAGE_VERTEX_BIT";
12612
12613 char const *vsSource =
12614 "#version 450\n"
12615 "\n"
12616 "layout(push_constant, std430) uniform foo { float x; } consts;\n"
12617 "out gl_PerVertex {\n"
12618 " vec4 gl_Position;\n"
12619 "};\n"
12620 "void main(){\n"
12621 " gl_Position = vec4(consts.x);\n"
12622 "}\n";
12623
12624 char const *fsSource =
12625 "#version 450\n"
12626 "\n"
12627 "layout(location = 0) out vec4 uFragColor;\n"
12628 "void main(){\n"
12629 " uFragColor = vec4(0,1,0,1);\n"
12630 "}\n";
12631
12632 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12633 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12634
12635 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
12636 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12637
12638 // Set up a push constant range
12639 VkPushConstantRange push_constant_ranges = {};
12640 // Set to the wrong stage to challenge core_validation
12641 push_constant_ranges.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
12642 push_constant_ranges.size = 4;
12643
12644 pipeline_layout_create_info.pPushConstantRanges = &push_constant_ranges;
12645 pipeline_layout_create_info.pushConstantRangeCount = 1;
12646
12647 VkPipelineLayout pipeline_layout;
12648 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
12649
12650 VkPipelineObj pipe(m_device);
12651 pipe.AddColorAttachment();
12652 pipe.AddShader(&vs);
12653 pipe.AddShader(&fs);
12654
12655 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, push_constant_not_accessible_message);
12656 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12657 m_errorMonitor->VerifyFound();
12658
12659 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
12660}
12661
12662TEST_F(VkLayerTest, CreatePipelineCheckShaderNotEnabled) {
12663 TEST_DESCRIPTION(
12664 "Create a graphics pipeline in which a capability declared by the shader requires a feature not enabled on the device.");
12665
12666 ASSERT_NO_FATAL_FAILURE(InitState());
12667 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12668
12669 const char *feature_not_enabled_message =
12670 "Shader requires VkPhysicalDeviceFeatures::shaderFloat64 but is not enabled on the device";
12671
12672 // Some awkward steps are required to test with custom device features.
12673 std::vector<const char *> device_extension_names;
12674 auto features = m_device->phy().features();
12675 // Disable support for 64 bit floats
12676 features.shaderFloat64 = false;
12677 // The sacrificial device object
12678 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
12679
12680 char const *vsSource = "#version 450\n"
12681 "\n"
12682 "out gl_PerVertex {\n"
12683 " vec4 gl_Position;\n"
12684 "};\n"
12685 "void main(){\n"
12686 " gl_Position = vec4(1);\n"
12687 "}\n";
12688 char const *fsSource = "#version 450\n"
12689 "\n"
12690 "layout(location=0) out vec4 color;\n"
12691 "void main(){\n"
12692 " dvec4 green = vec4(0.0, 1.0, 0.0, 1.0);\n"
12693 " color = vec4(green);\n"
12694 "}\n";
12695
12696 VkShaderObj vs(&test_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12697 VkShaderObj fs(&test_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12698
12699 VkRenderpassObj render_pass(&test_device);
Mark Mueller098c9cb2016-09-08 09:01:57 -060012700
12701 VkPipelineObj pipe(&test_device);
12702 pipe.AddColorAttachment();
12703 pipe.AddShader(&vs);
12704 pipe.AddShader(&fs);
12705
12706 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
12707 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12708 VkPipelineLayout pipeline_layout;
12709 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(test_device.device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
12710
12711 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, feature_not_enabled_message);
12712 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
12713 m_errorMonitor->VerifyFound();
12714
12715 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, nullptr);
12716}
12717
12718TEST_F(VkLayerTest, CreatePipelineCheckShaderBadCapability) {
12719 TEST_DESCRIPTION("Create a graphics pipeline in which a capability declared by the shader is not supported by Vulkan shaders.");
12720
12721 ASSERT_NO_FATAL_FAILURE(InitState());
12722 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12723
12724 const char *bad_capability_message = "Shader declares capability 53, not supported in Vulkan.";
12725
12726 char const *vsSource = "#version 450\n"
12727 "\n"
12728 "out gl_PerVertex {\n"
12729 " vec4 gl_Position;\n"
12730 "};\n"
12731 "layout(xfb_buffer = 1) out;"
12732 "void main(){\n"
12733 " gl_Position = vec4(1);\n"
12734 "}\n";
12735 char const *fsSource = "#version 450\n"
12736 "\n"
12737 "layout(location=0) out vec4 color;\n"
12738 "void main(){\n"
12739 " dvec4 green = vec4(0.0, 1.0, 0.0, 1.0);\n"
12740 " color = vec4(green);\n"
12741 "}\n";
12742
12743 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12744 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12745
12746 VkPipelineObj pipe(m_device);
12747 pipe.AddColorAttachment();
12748 pipe.AddShader(&vs);
12749 pipe.AddShader(&fs);
12750
12751 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
12752 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12753 VkPipelineLayout pipeline_layout;
12754 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
12755
12756 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bad_capability_message);
12757 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12758 m_errorMonitor->VerifyFound();
12759
12760 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
12761}
12762
Karl Schultz6addd812016-02-02 17:17:23 -070012763TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvided) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012764 TEST_DESCRIPTION("Test that an error is produced for a fragment shader input "
12765 "which is not present in the outputs of the previous stage");
12766
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012767 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not written by vertex shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012768
Chris Forbes59cb88d2015-05-25 11:13:13 +120012769 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060012770 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes59cb88d2015-05-25 11:13:13 +120012771
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012772 char const *vsSource = "#version 450\n"
12773 "\n"
12774 "out gl_PerVertex {\n"
12775 " vec4 gl_Position;\n"
12776 "};\n"
12777 "void main(){\n"
12778 " gl_Position = vec4(1);\n"
12779 "}\n";
12780 char const *fsSource = "#version 450\n"
12781 "\n"
12782 "layout(location=0) in float x;\n"
12783 "layout(location=0) out vec4 color;\n"
12784 "void main(){\n"
12785 " color = vec4(x);\n"
12786 "}\n";
Chris Forbes59cb88d2015-05-25 11:13:13 +120012787
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012788 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12789 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes59cb88d2015-05-25 11:13:13 +120012790
12791 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080012792 pipe.AddColorAttachment();
Chris Forbes59cb88d2015-05-25 11:13:13 +120012793 pipe.AddShader(&vs);
12794 pipe.AddShader(&fs);
12795
Chris Forbes59cb88d2015-05-25 11:13:13 +120012796 VkDescriptorSetObj descriptorSet(m_device);
12797 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012798 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes59cb88d2015-05-25 11:13:13 +120012799
Tony Barbour5781e8f2015-08-04 16:23:11 -060012800 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes59cb88d2015-05-25 11:13:13 +120012801
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012802 m_errorMonitor->VerifyFound();
Chris Forbes59cb88d2015-05-25 11:13:13 +120012803}
12804
Karl Schultz6addd812016-02-02 17:17:23 -070012805TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvidedInBlock) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012806 TEST_DESCRIPTION("Test that an error is produced for a fragment shader input "
12807 "within an interace block, which is not present in the outputs "
12808 "of the previous stage.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012809 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not written by vertex shader");
Chris Forbesa3e85f62016-01-15 14:53:11 +130012810
12811 ASSERT_NO_FATAL_FAILURE(InitState());
12812 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12813
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012814 char const *vsSource = "#version 450\n"
12815 "\n"
12816 "out gl_PerVertex {\n"
12817 " vec4 gl_Position;\n"
12818 "};\n"
12819 "void main(){\n"
12820 " gl_Position = vec4(1);\n"
12821 "}\n";
12822 char const *fsSource = "#version 450\n"
12823 "\n"
12824 "in block { layout(location=0) float x; } ins;\n"
12825 "layout(location=0) out vec4 color;\n"
12826 "void main(){\n"
12827 " color = vec4(ins.x);\n"
12828 "}\n";
Chris Forbesa3e85f62016-01-15 14:53:11 +130012829
12830 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12831 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12832
12833 VkPipelineObj pipe(m_device);
12834 pipe.AddColorAttachment();
12835 pipe.AddShader(&vs);
12836 pipe.AddShader(&fs);
12837
12838 VkDescriptorSetObj descriptorSet(m_device);
12839 descriptorSet.AppendDummy();
12840 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12841
12842 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12843
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012844 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +130012845}
12846
Karl Schultz6addd812016-02-02 17:17:23 -070012847TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchArraySize) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012848 TEST_DESCRIPTION("Test that an error is produced for mismatched array sizes "
Mike Weiblencce7ec72016-10-17 19:33:05 -060012849 "across the vertex->fragment shader interface");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012850 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0.0: 'ptr to "
12851 "output arr[2] of float32' vs 'ptr to "
12852 "input arr[3] of float32'");
Chris Forbes0036fd12016-01-26 14:19:49 +130012853
12854 ASSERT_NO_FATAL_FAILURE(InitState());
12855 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12856
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012857 char const *vsSource = "#version 450\n"
12858 "\n"
12859 "layout(location=0) out float x[2];\n"
12860 "out gl_PerVertex {\n"
12861 " vec4 gl_Position;\n"
12862 "};\n"
12863 "void main(){\n"
12864 " x[0] = 0; x[1] = 0;\n"
12865 " gl_Position = vec4(1);\n"
12866 "}\n";
12867 char const *fsSource = "#version 450\n"
12868 "\n"
12869 "layout(location=0) in float x[3];\n"
12870 "layout(location=0) out vec4 color;\n"
12871 "void main(){\n"
12872 " color = vec4(x[0] + x[1] + x[2]);\n"
12873 "}\n";
Chris Forbes0036fd12016-01-26 14:19:49 +130012874
12875 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12876 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12877
12878 VkPipelineObj pipe(m_device);
12879 pipe.AddColorAttachment();
12880 pipe.AddShader(&vs);
12881 pipe.AddShader(&fs);
12882
12883 VkDescriptorSetObj descriptorSet(m_device);
12884 descriptorSet.AppendDummy();
12885 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12886
12887 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12888
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012889 m_errorMonitor->VerifyFound();
Chris Forbes0036fd12016-01-26 14:19:49 +130012890}
12891
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060012892
Karl Schultz6addd812016-02-02 17:17:23 -070012893TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012894 TEST_DESCRIPTION("Test that an error is produced for mismatched types across "
Mike Weiblencce7ec72016-10-17 19:33:05 -060012895 "the vertex->fragment shader interface");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012896 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012897
Chris Forbesb56af562015-05-25 11:13:17 +120012898 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060012899 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesb56af562015-05-25 11:13:17 +120012900
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012901 char const *vsSource = "#version 450\n"
12902 "\n"
12903 "layout(location=0) out int x;\n"
12904 "out gl_PerVertex {\n"
12905 " vec4 gl_Position;\n"
12906 "};\n"
12907 "void main(){\n"
12908 " x = 0;\n"
12909 " gl_Position = vec4(1);\n"
12910 "}\n";
12911 char const *fsSource = "#version 450\n"
12912 "\n"
12913 "layout(location=0) in float x;\n" /* VS writes int */
12914 "layout(location=0) out vec4 color;\n"
12915 "void main(){\n"
12916 " color = vec4(x);\n"
12917 "}\n";
Chris Forbesb56af562015-05-25 11:13:17 +120012918
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012919 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12920 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesb56af562015-05-25 11:13:17 +120012921
12922 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080012923 pipe.AddColorAttachment();
Chris Forbesb56af562015-05-25 11:13:17 +120012924 pipe.AddShader(&vs);
12925 pipe.AddShader(&fs);
12926
Chris Forbesb56af562015-05-25 11:13:17 +120012927 VkDescriptorSetObj descriptorSet(m_device);
12928 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012929 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesb56af562015-05-25 11:13:17 +120012930
Tony Barbour5781e8f2015-08-04 16:23:11 -060012931 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesb56af562015-05-25 11:13:17 +120012932
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012933 m_errorMonitor->VerifyFound();
Chris Forbesb56af562015-05-25 11:13:17 +120012934}
12935
Karl Schultz6addd812016-02-02 17:17:23 -070012936TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchInBlock) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012937 TEST_DESCRIPTION("Test that an error is produced for mismatched types across "
Mike Weiblencce7ec72016-10-17 19:33:05 -060012938 "the vertex->fragment shader interface, when the variable is contained within "
Chris Forbes1cc79542016-07-20 11:13:44 +120012939 "an interface block");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012940 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0");
Chris Forbesa3e85f62016-01-15 14:53:11 +130012941
12942 ASSERT_NO_FATAL_FAILURE(InitState());
12943 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12944
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012945 char const *vsSource = "#version 450\n"
12946 "\n"
12947 "out block { layout(location=0) int x; } outs;\n"
12948 "out gl_PerVertex {\n"
12949 " vec4 gl_Position;\n"
12950 "};\n"
12951 "void main(){\n"
12952 " outs.x = 0;\n"
12953 " gl_Position = vec4(1);\n"
12954 "}\n";
12955 char const *fsSource = "#version 450\n"
12956 "\n"
12957 "in block { layout(location=0) float x; } ins;\n" /* VS writes int */
12958 "layout(location=0) out vec4 color;\n"
12959 "void main(){\n"
12960 " color = vec4(ins.x);\n"
12961 "}\n";
Chris Forbesa3e85f62016-01-15 14:53:11 +130012962
12963 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12964 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12965
12966 VkPipelineObj pipe(m_device);
12967 pipe.AddColorAttachment();
12968 pipe.AddShader(&vs);
12969 pipe.AddShader(&fs);
12970
12971 VkDescriptorSetObj descriptorSet(m_device);
12972 descriptorSet.AppendDummy();
12973 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12974
12975 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12976
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012977 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +130012978}
12979
12980TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByLocation) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012981 TEST_DESCRIPTION("Test that an error is produced for location mismatches across "
Mike Weiblencce7ec72016-10-17 19:33:05 -060012982 "the vertex->fragment shader interface; This should manifest as a not-written/not-consumed "
Chris Forbes1cc79542016-07-20 11:13:44 +120012983 "pair, but flushes out broken walking of the interfaces");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012984 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 +130012985
12986 ASSERT_NO_FATAL_FAILURE(InitState());
12987 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12988
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012989 char const *vsSource = "#version 450\n"
12990 "\n"
12991 "out block { layout(location=1) float x; } outs;\n"
12992 "out gl_PerVertex {\n"
12993 " vec4 gl_Position;\n"
12994 "};\n"
12995 "void main(){\n"
12996 " outs.x = 0;\n"
12997 " gl_Position = vec4(1);\n"
12998 "}\n";
12999 char const *fsSource = "#version 450\n"
13000 "\n"
13001 "in block { layout(location=0) float x; } ins;\n"
13002 "layout(location=0) out vec4 color;\n"
13003 "void main(){\n"
13004 " color = vec4(ins.x);\n"
13005 "}\n";
Chris Forbese9928822016-02-17 14:44:52 +130013006
13007 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13008 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13009
13010 VkPipelineObj pipe(m_device);
13011 pipe.AddColorAttachment();
13012 pipe.AddShader(&vs);
13013 pipe.AddShader(&fs);
13014
13015 VkDescriptorSetObj descriptorSet(m_device);
13016 descriptorSet.AppendDummy();
13017 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13018
13019 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13020
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013021 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +130013022}
13023
13024TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByComponent) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013025 TEST_DESCRIPTION("Test that an error is produced for component mismatches across the "
Mike Weiblencce7ec72016-10-17 19:33:05 -060013026 "vertex->fragment shader interface. It's not enough to have the same set of locations in "
Chris Forbes1cc79542016-07-20 11:13:44 +120013027 "use; matching is defined in terms of spirv variables.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013028 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 +130013029
13030 ASSERT_NO_FATAL_FAILURE(InitState());
13031 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13032
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013033 char const *vsSource = "#version 450\n"
13034 "\n"
13035 "out block { layout(location=0, component=0) float x; } outs;\n"
13036 "out gl_PerVertex {\n"
13037 " vec4 gl_Position;\n"
13038 "};\n"
13039 "void main(){\n"
13040 " outs.x = 0;\n"
13041 " gl_Position = vec4(1);\n"
13042 "}\n";
13043 char const *fsSource = "#version 450\n"
13044 "\n"
13045 "in block { layout(location=0, component=1) float x; } ins;\n"
13046 "layout(location=0) out vec4 color;\n"
13047 "void main(){\n"
13048 " color = vec4(ins.x);\n"
13049 "}\n";
Chris Forbese9928822016-02-17 14:44:52 +130013050
13051 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13052 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13053
13054 VkPipelineObj pipe(m_device);
13055 pipe.AddColorAttachment();
13056 pipe.AddShader(&vs);
13057 pipe.AddShader(&fs);
13058
13059 VkDescriptorSetObj descriptorSet(m_device);
13060 descriptorSet.AppendDummy();
13061 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13062
13063 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13064
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013065 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +130013066}
13067
Chris Forbes1f3b0152016-11-30 12:48:40 +130013068TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByPrecision) {
13069 TEST_DESCRIPTION("Test that the RelaxedPrecision decoration is validated to match");
13070
13071 ASSERT_NO_FATAL_FAILURE(InitState());
13072 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13073
13074 char const *vsSource = "#version 450\n"
13075 "layout(location=0) out mediump float x;\n"
13076 "void main() { gl_Position = vec4(0); x = 1.0; }\n";
13077 char const *fsSource = "#version 450\n"
13078 "layout(location=0) in highp float x;\n"
13079 "layout(location=0) out vec4 color;\n"
13080 "void main() { color = vec4(x); }\n";
13081
13082 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13083 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13084
13085 VkPipelineObj pipe(m_device);
13086 pipe.AddColorAttachment();
13087 pipe.AddShader(&vs);
13088 pipe.AddShader(&fs);
13089
13090 VkDescriptorSetObj descriptorSet(m_device);
13091 descriptorSet.AppendDummy();
13092 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13093
13094 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "differ in precision");
13095
13096 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13097
13098 m_errorMonitor->VerifyFound();
13099}
13100
Chris Forbes870a39e2016-11-30 12:55:56 +130013101TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByPrecisionBlock) {
13102 TEST_DESCRIPTION("Test that the RelaxedPrecision decoration is validated to match");
13103
13104 ASSERT_NO_FATAL_FAILURE(InitState());
13105 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13106
13107 char const *vsSource = "#version 450\n"
13108 "out block { layout(location=0) mediump float x; };\n"
13109 "void main() { gl_Position = vec4(0); x = 1.0; }\n";
13110 char const *fsSource = "#version 450\n"
13111 "in block { layout(location=0) highp float x; };\n"
13112 "layout(location=0) out vec4 color;\n"
13113 "void main() { color = vec4(x); }\n";
13114
13115 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13116 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13117
13118 VkPipelineObj pipe(m_device);
13119 pipe.AddColorAttachment();
13120 pipe.AddShader(&vs);
13121 pipe.AddShader(&fs);
13122
13123 VkDescriptorSetObj descriptorSet(m_device);
13124 descriptorSet.AppendDummy();
13125 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13126
13127 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "differ in precision");
13128
13129 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13130
13131 m_errorMonitor->VerifyFound();
13132}
13133
Karl Schultz6addd812016-02-02 17:17:23 -070013134TEST_F(VkLayerTest, CreatePipelineAttribNotConsumed) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013135 TEST_DESCRIPTION("Test that a warning is produced for a vertex attribute which is "
13136 "not consumed by the vertex shader");
Mike Weiblencce7ec72016-10-17 19:33:05 -060013137 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "location 0 not consumed by vertex shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013138
Chris Forbesde136e02015-05-25 11:13:28 +120013139 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013140 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesde136e02015-05-25 11:13:28 +120013141
13142 VkVertexInputBindingDescription input_binding;
13143 memset(&input_binding, 0, sizeof(input_binding));
13144
13145 VkVertexInputAttributeDescription input_attrib;
13146 memset(&input_attrib, 0, sizeof(input_attrib));
13147 input_attrib.format = VK_FORMAT_R32_SFLOAT;
13148
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013149 char const *vsSource = "#version 450\n"
13150 "\n"
13151 "out gl_PerVertex {\n"
13152 " vec4 gl_Position;\n"
13153 "};\n"
13154 "void main(){\n"
13155 " gl_Position = vec4(1);\n"
13156 "}\n";
13157 char const *fsSource = "#version 450\n"
13158 "\n"
13159 "layout(location=0) out vec4 color;\n"
13160 "void main(){\n"
13161 " color = vec4(1);\n"
13162 "}\n";
Chris Forbesde136e02015-05-25 11:13:28 +120013163
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013164 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13165 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesde136e02015-05-25 11:13:28 +120013166
13167 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013168 pipe.AddColorAttachment();
Chris Forbesde136e02015-05-25 11:13:28 +120013169 pipe.AddShader(&vs);
13170 pipe.AddShader(&fs);
13171
13172 pipe.AddVertexInputBindings(&input_binding, 1);
13173 pipe.AddVertexInputAttribs(&input_attrib, 1);
13174
Chris Forbesde136e02015-05-25 11:13:28 +120013175 VkDescriptorSetObj descriptorSet(m_device);
13176 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013177 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesde136e02015-05-25 11:13:28 +120013178
Tony Barbour5781e8f2015-08-04 16:23:11 -060013179 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesde136e02015-05-25 11:13:28 +120013180
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013181 m_errorMonitor->VerifyFound();
Chris Forbesde136e02015-05-25 11:13:28 +120013182}
13183
Karl Schultz6addd812016-02-02 17:17:23 -070013184TEST_F(VkLayerTest, CreatePipelineAttribLocationMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013185 TEST_DESCRIPTION("Test that a warning is produced for a location mismatch on "
13186 "vertex attributes. This flushes out bad behavior in the interface walker");
Mike Weiblencce7ec72016-10-17 19:33:05 -060013187 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "location 0 not consumed by vertex shader");
Chris Forbes7d83cd52016-01-15 11:32:03 +130013188
13189 ASSERT_NO_FATAL_FAILURE(InitState());
13190 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13191
13192 VkVertexInputBindingDescription input_binding;
13193 memset(&input_binding, 0, sizeof(input_binding));
13194
13195 VkVertexInputAttributeDescription input_attrib;
13196 memset(&input_attrib, 0, sizeof(input_attrib));
13197 input_attrib.format = VK_FORMAT_R32_SFLOAT;
13198
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013199 char const *vsSource = "#version 450\n"
13200 "\n"
13201 "layout(location=1) in float x;\n"
13202 "out gl_PerVertex {\n"
13203 " vec4 gl_Position;\n"
13204 "};\n"
13205 "void main(){\n"
13206 " gl_Position = vec4(x);\n"
13207 "}\n";
13208 char const *fsSource = "#version 450\n"
13209 "\n"
13210 "layout(location=0) out vec4 color;\n"
13211 "void main(){\n"
13212 " color = vec4(1);\n"
13213 "}\n";
Chris Forbes7d83cd52016-01-15 11:32:03 +130013214
13215 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13216 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13217
13218 VkPipelineObj pipe(m_device);
13219 pipe.AddColorAttachment();
13220 pipe.AddShader(&vs);
13221 pipe.AddShader(&fs);
13222
13223 pipe.AddVertexInputBindings(&input_binding, 1);
13224 pipe.AddVertexInputAttribs(&input_attrib, 1);
13225
13226 VkDescriptorSetObj descriptorSet(m_device);
13227 descriptorSet.AppendDummy();
13228 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13229
13230 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13231
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013232 m_errorMonitor->VerifyFound();
Chris Forbes7d83cd52016-01-15 11:32:03 +130013233}
13234
Karl Schultz6addd812016-02-02 17:17:23 -070013235TEST_F(VkLayerTest, CreatePipelineAttribNotProvided) {
Mike Weiblen15bd38e2016-10-03 19:19:41 -060013236 TEST_DESCRIPTION("Test that an error is produced for a vertex shader input which is not "
Chris Forbes1cc79542016-07-20 11:13:44 +120013237 "provided by a vertex attribute");
Mike Weiblen15bd38e2016-10-03 19:19:41 -060013238 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 -060013239
Chris Forbes62e8e502015-05-25 11:13:29 +120013240 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013241 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes62e8e502015-05-25 11:13:29 +120013242
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013243 char const *vsSource = "#version 450\n"
13244 "\n"
13245 "layout(location=0) in vec4 x;\n" /* not provided */
13246 "out gl_PerVertex {\n"
13247 " vec4 gl_Position;\n"
13248 "};\n"
13249 "void main(){\n"
13250 " gl_Position = x;\n"
13251 "}\n";
13252 char const *fsSource = "#version 450\n"
13253 "\n"
13254 "layout(location=0) out vec4 color;\n"
13255 "void main(){\n"
13256 " color = vec4(1);\n"
13257 "}\n";
Chris Forbes62e8e502015-05-25 11:13:29 +120013258
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013259 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13260 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes62e8e502015-05-25 11:13:29 +120013261
13262 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013263 pipe.AddColorAttachment();
Chris Forbes62e8e502015-05-25 11:13:29 +120013264 pipe.AddShader(&vs);
13265 pipe.AddShader(&fs);
13266
Chris Forbes62e8e502015-05-25 11:13:29 +120013267 VkDescriptorSetObj descriptorSet(m_device);
13268 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013269 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes62e8e502015-05-25 11:13:29 +120013270
Tony Barbour5781e8f2015-08-04 16:23:11 -060013271 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes62e8e502015-05-25 11:13:29 +120013272
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013273 m_errorMonitor->VerifyFound();
Chris Forbes62e8e502015-05-25 11:13:29 +120013274}
13275
Karl Schultz6addd812016-02-02 17:17:23 -070013276TEST_F(VkLayerTest, CreatePipelineAttribTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013277 TEST_DESCRIPTION("Test that an error is produced for a mismatch between the "
13278 "fundamental type (float/int/uint) of an attribute and the "
Mike Weiblen15bd38e2016-10-03 19:19:41 -060013279 "vertex shader input that consumes it");
13280 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 -060013281
Chris Forbesc97d98e2015-05-25 11:13:31 +120013282 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013283 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesc97d98e2015-05-25 11:13:31 +120013284
13285 VkVertexInputBindingDescription input_binding;
13286 memset(&input_binding, 0, sizeof(input_binding));
13287
13288 VkVertexInputAttributeDescription input_attrib;
13289 memset(&input_attrib, 0, sizeof(input_attrib));
13290 input_attrib.format = VK_FORMAT_R32_SFLOAT;
13291
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013292 char const *vsSource = "#version 450\n"
13293 "\n"
13294 "layout(location=0) in int x;\n" /* attrib provided float */
13295 "out gl_PerVertex {\n"
13296 " vec4 gl_Position;\n"
13297 "};\n"
13298 "void main(){\n"
13299 " gl_Position = vec4(x);\n"
13300 "}\n";
13301 char const *fsSource = "#version 450\n"
13302 "\n"
13303 "layout(location=0) out vec4 color;\n"
13304 "void main(){\n"
13305 " color = vec4(1);\n"
13306 "}\n";
Chris Forbesc97d98e2015-05-25 11:13:31 +120013307
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013308 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13309 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesc97d98e2015-05-25 11:13:31 +120013310
13311 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013312 pipe.AddColorAttachment();
Chris Forbesc97d98e2015-05-25 11:13:31 +120013313 pipe.AddShader(&vs);
13314 pipe.AddShader(&fs);
13315
13316 pipe.AddVertexInputBindings(&input_binding, 1);
13317 pipe.AddVertexInputAttribs(&input_attrib, 1);
13318
Chris Forbesc97d98e2015-05-25 11:13:31 +120013319 VkDescriptorSetObj descriptorSet(m_device);
13320 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013321 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesc97d98e2015-05-25 11:13:31 +120013322
Tony Barbour5781e8f2015-08-04 16:23:11 -060013323 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesc97d98e2015-05-25 11:13:31 +120013324
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013325 m_errorMonitor->VerifyFound();
Chris Forbesc97d98e2015-05-25 11:13:31 +120013326}
13327
Chris Forbesc68b43c2016-04-06 11:18:47 +120013328TEST_F(VkLayerTest, CreatePipelineDuplicateStage) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013329 TEST_DESCRIPTION("Test that an error is produced for a pipeline containing multiple "
13330 "shaders for the same stage");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013331 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13332 "Multiple shaders provided for stage VK_SHADER_STAGE_VERTEX_BIT");
Chris Forbesc68b43c2016-04-06 11:18:47 +120013333
13334 ASSERT_NO_FATAL_FAILURE(InitState());
13335 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13336
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013337 char const *vsSource = "#version 450\n"
13338 "\n"
13339 "out gl_PerVertex {\n"
13340 " vec4 gl_Position;\n"
13341 "};\n"
13342 "void main(){\n"
13343 " gl_Position = vec4(1);\n"
13344 "}\n";
13345 char const *fsSource = "#version 450\n"
13346 "\n"
13347 "layout(location=0) out vec4 color;\n"
13348 "void main(){\n"
13349 " color = vec4(1);\n"
13350 "}\n";
Chris Forbesc68b43c2016-04-06 11:18:47 +120013351
13352 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13353 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13354
13355 VkPipelineObj pipe(m_device);
13356 pipe.AddColorAttachment();
13357 pipe.AddShader(&vs);
Mike Weiblencce7ec72016-10-17 19:33:05 -060013358 pipe.AddShader(&vs); // intentionally duplicate vertex shader attachment
Chris Forbesc68b43c2016-04-06 11:18:47 +120013359 pipe.AddShader(&fs);
13360
13361 VkDescriptorSetObj descriptorSet(m_device);
13362 descriptorSet.AppendDummy();
13363 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13364
13365 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13366
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013367 m_errorMonitor->VerifyFound();
Chris Forbesc68b43c2016-04-06 11:18:47 +120013368}
13369
Chris Forbes82ff92a2016-09-09 10:50:24 +120013370TEST_F(VkLayerTest, CreatePipelineMissingEntrypoint) {
13371 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13372 "No entrypoint found named `foo`");
13373
13374 ASSERT_NO_FATAL_FAILURE(InitState());
13375 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13376
13377 char const *vsSource = "#version 450\n"
13378 "out gl_PerVertex {\n"
13379 " vec4 gl_Position;\n"
13380 "};\n"
13381 "void main(){\n"
13382 " gl_Position = vec4(0);\n"
13383 "}\n";
13384 char const *fsSource = "#version 450\n"
13385 "\n"
13386 "layout(location=0) out vec4 color;\n"
13387 "void main(){\n"
13388 " color = vec4(1);\n"
13389 "}\n";
13390
13391 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13392 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this, "foo");
13393
13394 VkPipelineObj pipe(m_device);
13395 pipe.AddColorAttachment();
13396 pipe.AddShader(&vs);
13397 pipe.AddShader(&fs);
13398
13399 VkDescriptorSetObj descriptorSet(m_device);
13400 descriptorSet.AppendDummy();
13401 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13402
13403 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13404
13405 m_errorMonitor->VerifyFound();
13406}
13407
Chris Forbesae9d8cd2016-09-13 16:32:57 +120013408TEST_F(VkLayerTest, CreatePipelineDepthStencilRequired) {
13409 m_errorMonitor->SetDesiredFailureMsg(
13410 VK_DEBUG_REPORT_ERROR_BIT_EXT,
13411 "pDepthStencilState is NULL when rasterization is enabled and subpass "
13412 "uses a depth/stencil attachment");
13413
13414 ASSERT_NO_FATAL_FAILURE(InitState());
13415 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13416
13417 char const *vsSource = "#version 450\n"
13418 "void main(){ gl_Position = vec4(0); }\n";
13419 char const *fsSource = "#version 450\n"
13420 "\n"
13421 "layout(location=0) out vec4 color;\n"
13422 "void main(){\n"
13423 " color = vec4(1);\n"
13424 "}\n";
13425
13426 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13427 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13428
13429 VkPipelineObj pipe(m_device);
13430 pipe.AddColorAttachment();
13431 pipe.AddShader(&vs);
13432 pipe.AddShader(&fs);
13433
13434 VkDescriptorSetObj descriptorSet(m_device);
13435 descriptorSet.AppendDummy();
13436 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13437
13438 VkAttachmentDescription attachments[] = {
13439 { 0, VK_FORMAT_B8G8R8A8_UNORM, VK_SAMPLE_COUNT_1_BIT,
13440 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
13441 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
13442 VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
13443 },
13444 { 0, VK_FORMAT_D16_UNORM, VK_SAMPLE_COUNT_1_BIT,
13445 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
13446 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
13447 VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
13448 },
13449 };
13450 VkAttachmentReference refs[] = {
13451 { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL },
13452 { 1, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL },
13453 };
13454 VkSubpassDescription subpass = {
13455 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr,
13456 1, &refs[0], nullptr, &refs[1],
13457 0, nullptr
13458 };
13459 VkRenderPassCreateInfo rpci = {
13460 VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr,
13461 0, 2, attachments, 1, &subpass, 0, nullptr
13462 };
13463 VkRenderPass rp;
13464 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
13465 ASSERT_VK_SUCCESS(err);
13466
13467 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), rp);
13468
13469 m_errorMonitor->VerifyFound();
13470
13471 vkDestroyRenderPass(m_device->device(), rp, nullptr);
13472}
13473
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013474TEST_F(VkLayerTest, CreatePipelineTessPatchDecorationMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013475 TEST_DESCRIPTION("Test that an error is produced for a variable output from "
13476 "the TCS without the patch decoration, but consumed in the TES "
13477 "with the decoration.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013478 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is per-vertex in tessellation control shader stage "
13479 "but per-patch in tessellation evaluation shader stage");
Chris Forbesa0193bc2016-04-04 19:19:47 +120013480
13481 ASSERT_NO_FATAL_FAILURE(InitState());
13482 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13483
Chris Forbesc1e852d2016-04-04 19:26:42 +120013484 if (!m_device->phy().features().tessellationShader) {
13485 printf("Device does not support tessellation shaders; skipped.\n");
13486 return;
13487 }
13488
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013489 char const *vsSource = "#version 450\n"
13490 "void main(){}\n";
13491 char const *tcsSource = "#version 450\n"
13492 "layout(location=0) out int x[];\n"
13493 "layout(vertices=3) out;\n"
13494 "void main(){\n"
13495 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
13496 " gl_TessLevelInner[0] = 1;\n"
13497 " x[gl_InvocationID] = gl_InvocationID;\n"
13498 "}\n";
13499 char const *tesSource = "#version 450\n"
13500 "layout(triangles, equal_spacing, cw) in;\n"
13501 "layout(location=0) patch in int x;\n"
13502 "out gl_PerVertex { vec4 gl_Position; };\n"
13503 "void main(){\n"
13504 " gl_Position.xyz = gl_TessCoord;\n"
13505 " gl_Position.w = x;\n"
13506 "}\n";
13507 char const *fsSource = "#version 450\n"
13508 "layout(location=0) out vec4 color;\n"
13509 "void main(){\n"
13510 " color = vec4(1);\n"
13511 "}\n";
Chris Forbesa0193bc2016-04-04 19:19:47 +120013512
13513 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13514 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
13515 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
13516 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13517
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013518 VkPipelineInputAssemblyStateCreateInfo iasci{VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, nullptr, 0,
13519 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, VK_FALSE};
Chris Forbesa0193bc2016-04-04 19:19:47 +120013520
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013521 VkPipelineTessellationStateCreateInfo tsci{VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, nullptr, 0, 3};
Chris Forbesa0193bc2016-04-04 19:19:47 +120013522
13523 VkPipelineObj pipe(m_device);
13524 pipe.SetInputAssembly(&iasci);
13525 pipe.SetTessellation(&tsci);
13526 pipe.AddColorAttachment();
13527 pipe.AddShader(&vs);
13528 pipe.AddShader(&tcs);
13529 pipe.AddShader(&tes);
13530 pipe.AddShader(&fs);
13531
13532 VkDescriptorSetObj descriptorSet(m_device);
13533 descriptorSet.AppendDummy();
13534 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13535
13536 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13537
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013538 m_errorMonitor->VerifyFound();
Chris Forbesa0193bc2016-04-04 19:19:47 +120013539}
13540
Karl Schultz6addd812016-02-02 17:17:23 -070013541TEST_F(VkLayerTest, CreatePipelineAttribBindingConflict) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013542 TEST_DESCRIPTION("Test that an error is produced for a vertex attribute setup where multiple "
13543 "bindings provide the same location");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013544 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13545 "Duplicate vertex input binding descriptions for binding 0");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013546
Chris Forbes280ba2c2015-06-12 11:16:41 +120013547 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013548 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes280ba2c2015-06-12 11:16:41 +120013549
13550 /* Two binding descriptions for binding 0 */
13551 VkVertexInputBindingDescription input_bindings[2];
13552 memset(input_bindings, 0, sizeof(input_bindings));
13553
13554 VkVertexInputAttributeDescription input_attrib;
13555 memset(&input_attrib, 0, sizeof(input_attrib));
13556 input_attrib.format = VK_FORMAT_R32_SFLOAT;
13557
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013558 char const *vsSource = "#version 450\n"
13559 "\n"
13560 "layout(location=0) in float x;\n" /* attrib provided float */
13561 "out gl_PerVertex {\n"
13562 " vec4 gl_Position;\n"
13563 "};\n"
13564 "void main(){\n"
13565 " gl_Position = vec4(x);\n"
13566 "}\n";
13567 char const *fsSource = "#version 450\n"
13568 "\n"
13569 "layout(location=0) out vec4 color;\n"
13570 "void main(){\n"
13571 " color = vec4(1);\n"
13572 "}\n";
Chris Forbes280ba2c2015-06-12 11:16:41 +120013573
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013574 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13575 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes280ba2c2015-06-12 11:16:41 +120013576
13577 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013578 pipe.AddColorAttachment();
Chris Forbes280ba2c2015-06-12 11:16:41 +120013579 pipe.AddShader(&vs);
13580 pipe.AddShader(&fs);
13581
13582 pipe.AddVertexInputBindings(input_bindings, 2);
13583 pipe.AddVertexInputAttribs(&input_attrib, 1);
13584
Chris Forbes280ba2c2015-06-12 11:16:41 +120013585 VkDescriptorSetObj descriptorSet(m_device);
13586 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013587 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes280ba2c2015-06-12 11:16:41 +120013588
Tony Barbour5781e8f2015-08-04 16:23:11 -060013589 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes280ba2c2015-06-12 11:16:41 +120013590
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013591 m_errorMonitor->VerifyFound();
Chris Forbes280ba2c2015-06-12 11:16:41 +120013592}
Chris Forbes8f68b562015-05-25 11:13:32 +120013593
Karl Schultz6addd812016-02-02 17:17:23 -070013594TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotWritten) {
Mike Weiblencce7ec72016-10-17 19:33:05 -060013595 TEST_DESCRIPTION("Test that an error is produced for a fragment shader which does not "
Chris Forbes1cc79542016-07-20 11:13:44 +120013596 "provide an output for one of the pipeline's color attachments");
Mike Weiblencce7ec72016-10-17 19:33:05 -060013597 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attachment 0 not written by fragment shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013598
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013599 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013600
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013601 char const *vsSource = "#version 450\n"
13602 "\n"
13603 "out gl_PerVertex {\n"
13604 " vec4 gl_Position;\n"
13605 "};\n"
13606 "void main(){\n"
13607 " gl_Position = vec4(1);\n"
13608 "}\n";
13609 char const *fsSource = "#version 450\n"
13610 "\n"
13611 "void main(){\n"
13612 "}\n";
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013613
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013614 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13615 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013616
13617 VkPipelineObj pipe(m_device);
13618 pipe.AddShader(&vs);
13619 pipe.AddShader(&fs);
13620
Chia-I Wu08accc62015-07-07 11:50:03 +080013621 /* set up CB 0, not written */
13622 pipe.AddColorAttachment();
13623 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013624
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013625 VkDescriptorSetObj descriptorSet(m_device);
13626 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013627 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013628
Tony Barbour5781e8f2015-08-04 16:23:11 -060013629 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013630
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013631 m_errorMonitor->VerifyFound();
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013632}
13633
Karl Schultz6addd812016-02-02 17:17:23 -070013634TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotConsumed) {
Mike Weiblencce7ec72016-10-17 19:33:05 -060013635 TEST_DESCRIPTION("Test that a warning is produced for a fragment shader which provides a spurious "
Chris Forbes1cc79542016-07-20 11:13:44 +120013636 "output with no matching attachment");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013637 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
Mike Weiblencce7ec72016-10-17 19:33:05 -060013638 "fragment shader writes to output location 1 with no matching attachment");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013639
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013640 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013641
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013642 char const *vsSource = "#version 450\n"
13643 "\n"
13644 "out gl_PerVertex {\n"
13645 " vec4 gl_Position;\n"
13646 "};\n"
13647 "void main(){\n"
13648 " gl_Position = vec4(1);\n"
13649 "}\n";
13650 char const *fsSource = "#version 450\n"
13651 "\n"
13652 "layout(location=0) out vec4 x;\n"
13653 "layout(location=1) out vec4 y;\n" /* no matching attachment for this */
13654 "void main(){\n"
13655 " x = vec4(1);\n"
13656 " y = vec4(1);\n"
13657 "}\n";
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013658
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013659 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13660 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013661
13662 VkPipelineObj pipe(m_device);
13663 pipe.AddShader(&vs);
13664 pipe.AddShader(&fs);
13665
Chia-I Wu08accc62015-07-07 11:50:03 +080013666 /* set up CB 0, not written */
13667 pipe.AddColorAttachment();
13668 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013669 /* FS writes CB 1, but we don't configure it */
13670
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013671 VkDescriptorSetObj descriptorSet(m_device);
13672 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013673 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013674
Tony Barbour5781e8f2015-08-04 16:23:11 -060013675 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013676
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013677 m_errorMonitor->VerifyFound();
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013678}
13679
Karl Schultz6addd812016-02-02 17:17:23 -070013680TEST_F(VkLayerTest, CreatePipelineFragmentOutputTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013681 TEST_DESCRIPTION("Test that an error is produced for a mismatch between the fundamental "
Mike Weiblencce7ec72016-10-17 19:33:05 -060013682 "type of an fragment shader output variable, and the format of the corresponding attachment");
13683 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "does not match fragment shader output type");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013684
Chris Forbesa36d69e2015-05-25 11:13:44 +120013685 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesa36d69e2015-05-25 11:13:44 +120013686
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013687 char const *vsSource = "#version 450\n"
13688 "\n"
13689 "out gl_PerVertex {\n"
13690 " vec4 gl_Position;\n"
13691 "};\n"
13692 "void main(){\n"
13693 " gl_Position = vec4(1);\n"
13694 "}\n";
13695 char const *fsSource = "#version 450\n"
13696 "\n"
13697 "layout(location=0) out ivec4 x;\n" /* not UNORM */
13698 "void main(){\n"
13699 " x = ivec4(1);\n"
13700 "}\n";
Chris Forbesa36d69e2015-05-25 11:13:44 +120013701
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013702 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13703 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesa36d69e2015-05-25 11:13:44 +120013704
13705 VkPipelineObj pipe(m_device);
13706 pipe.AddShader(&vs);
13707 pipe.AddShader(&fs);
13708
Chia-I Wu08accc62015-07-07 11:50:03 +080013709 /* set up CB 0; type is UNORM by default */
13710 pipe.AddColorAttachment();
13711 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesa36d69e2015-05-25 11:13:44 +120013712
Chris Forbesa36d69e2015-05-25 11:13:44 +120013713 VkDescriptorSetObj descriptorSet(m_device);
13714 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013715 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesa36d69e2015-05-25 11:13:44 +120013716
Tony Barbour5781e8f2015-08-04 16:23:11 -060013717 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesa36d69e2015-05-25 11:13:44 +120013718
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013719 m_errorMonitor->VerifyFound();
Chris Forbesa36d69e2015-05-25 11:13:44 +120013720}
Chris Forbes7b1b8932015-06-05 14:43:36 +120013721
Karl Schultz6addd812016-02-02 17:17:23 -070013722TEST_F(VkLayerTest, CreatePipelineUniformBlockNotProvided) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013723 TEST_DESCRIPTION("Test that an error is produced for a shader consuming a uniform "
13724 "block which has no corresponding binding in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013725 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not declared in pipeline layout");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013726
Chris Forbes556c76c2015-08-14 12:04:59 +120013727 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes556c76c2015-08-14 12:04:59 +120013728
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013729 char const *vsSource = "#version 450\n"
13730 "\n"
13731 "out gl_PerVertex {\n"
13732 " vec4 gl_Position;\n"
13733 "};\n"
13734 "void main(){\n"
13735 " gl_Position = vec4(1);\n"
13736 "}\n";
13737 char const *fsSource = "#version 450\n"
13738 "\n"
13739 "layout(location=0) out vec4 x;\n"
13740 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
13741 "void main(){\n"
13742 " x = vec4(bar.y);\n"
13743 "}\n";
Chris Forbes556c76c2015-08-14 12:04:59 +120013744
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013745 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13746 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes556c76c2015-08-14 12:04:59 +120013747
Chris Forbes556c76c2015-08-14 12:04:59 +120013748 VkPipelineObj pipe(m_device);
13749 pipe.AddShader(&vs);
13750 pipe.AddShader(&fs);
13751
13752 /* set up CB 0; type is UNORM by default */
13753 pipe.AddColorAttachment();
13754 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13755
13756 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013757 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes556c76c2015-08-14 12:04:59 +120013758
13759 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13760
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013761 m_errorMonitor->VerifyFound();
Chris Forbes556c76c2015-08-14 12:04:59 +120013762}
13763
Chris Forbes5c59e902016-02-26 16:56:09 +130013764TEST_F(VkLayerTest, CreatePipelinePushConstantsNotInLayout) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013765 TEST_DESCRIPTION("Test that an error is produced for a shader consuming push constants "
13766 "which are not provided in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013767 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not declared in layout");
Chris Forbes5c59e902016-02-26 16:56:09 +130013768
13769 ASSERT_NO_FATAL_FAILURE(InitState());
13770
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013771 char const *vsSource = "#version 450\n"
13772 "\n"
13773 "layout(push_constant, std430) uniform foo { float x; } consts;\n"
13774 "out gl_PerVertex {\n"
13775 " vec4 gl_Position;\n"
13776 "};\n"
13777 "void main(){\n"
13778 " gl_Position = vec4(consts.x);\n"
13779 "}\n";
13780 char const *fsSource = "#version 450\n"
13781 "\n"
13782 "layout(location=0) out vec4 x;\n"
13783 "void main(){\n"
13784 " x = vec4(1);\n"
13785 "}\n";
Chris Forbes5c59e902016-02-26 16:56:09 +130013786
13787 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13788 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13789
13790 VkPipelineObj pipe(m_device);
13791 pipe.AddShader(&vs);
13792 pipe.AddShader(&fs);
13793
13794 /* set up CB 0; type is UNORM by default */
13795 pipe.AddColorAttachment();
13796 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13797
13798 VkDescriptorSetObj descriptorSet(m_device);
13799 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13800
13801 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13802
13803 /* should have generated an error -- no push constant ranges provided! */
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013804 m_errorMonitor->VerifyFound();
Chris Forbes5c59e902016-02-26 16:56:09 +130013805}
13806
Chris Forbes3fb17902016-08-22 14:57:55 +120013807TEST_F(VkLayerTest, CreatePipelineInputAttachmentMissing) {
13808 TEST_DESCRIPTION("Test that an error is produced for a shader consuming an input attachment "
13809 "which is not included in the subpass description");
13810 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13811 "consumes input attachment index 0 but not provided in subpass");
13812
13813 ASSERT_NO_FATAL_FAILURE(InitState());
13814
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013815 char const *vsSource = "#version 450\n"
13816 "\n"
13817 "out gl_PerVertex {\n"
13818 " vec4 gl_Position;\n"
13819 "};\n"
13820 "void main(){\n"
13821 " gl_Position = vec4(1);\n"
13822 "}\n";
13823 char const *fsSource = "#version 450\n"
13824 "\n"
13825 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
13826 "layout(location=0) out vec4 color;\n"
13827 "void main() {\n"
13828 " color = subpassLoad(x);\n"
13829 "}\n";
Chris Forbes3fb17902016-08-22 14:57:55 +120013830
13831 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13832 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13833
13834 VkPipelineObj pipe(m_device);
13835 pipe.AddShader(&vs);
13836 pipe.AddShader(&fs);
13837 pipe.AddColorAttachment();
13838 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13839
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013840 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
13841 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes3fb17902016-08-22 14:57:55 +120013842 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013843 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes3fb17902016-08-22 14:57:55 +120013844 ASSERT_VK_SUCCESS(err);
13845
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013846 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes3fb17902016-08-22 14:57:55 +120013847 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013848 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes3fb17902016-08-22 14:57:55 +120013849 ASSERT_VK_SUCCESS(err);
13850
13851 // error here.
13852 pipe.CreateVKPipeline(pl, renderPass());
13853
13854 m_errorMonitor->VerifyFound();
13855
13856 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
13857 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
13858}
13859
Chris Forbes5a9a0472016-08-22 16:02:09 +120013860TEST_F(VkLayerTest, CreatePipelineInputAttachmentTypeMismatch) {
13861 TEST_DESCRIPTION("Test that an error is produced for a shader consuming an input attachment "
13862 "with a format having a different fundamental type");
13863 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13864 "input attachment 0 format of VK_FORMAT_R8G8B8A8_UINT does not match");
13865
13866 ASSERT_NO_FATAL_FAILURE(InitState());
13867
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013868 char const *vsSource = "#version 450\n"
13869 "\n"
13870 "out gl_PerVertex {\n"
13871 " vec4 gl_Position;\n"
13872 "};\n"
13873 "void main(){\n"
13874 " gl_Position = vec4(1);\n"
13875 "}\n";
13876 char const *fsSource = "#version 450\n"
13877 "\n"
13878 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
13879 "layout(location=0) out vec4 color;\n"
13880 "void main() {\n"
13881 " color = subpassLoad(x);\n"
13882 "}\n";
Chris Forbes5a9a0472016-08-22 16:02:09 +120013883
13884 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13885 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13886
13887 VkPipelineObj pipe(m_device);
13888 pipe.AddShader(&vs);
13889 pipe.AddShader(&fs);
13890 pipe.AddColorAttachment();
13891 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13892
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013893 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
13894 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes5a9a0472016-08-22 16:02:09 +120013895 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013896 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes5a9a0472016-08-22 16:02:09 +120013897 ASSERT_VK_SUCCESS(err);
13898
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013899 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120013900 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013901 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes5a9a0472016-08-22 16:02:09 +120013902 ASSERT_VK_SUCCESS(err);
13903
13904 VkAttachmentDescription descs[2] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013905 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
13906 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
13907 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
13908 {0, VK_FORMAT_R8G8B8A8_UINT, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
13909 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 +120013910 };
13911 VkAttachmentReference color = {
13912 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
13913 };
13914 VkAttachmentReference input = {
13915 1, VK_IMAGE_LAYOUT_GENERAL,
13916 };
13917
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013918 VkSubpassDescription sd = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 1, &input, 1, &color, nullptr, nullptr, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120013919
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013920 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, descs, 1, &sd, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120013921 VkRenderPass rp;
13922 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
13923 ASSERT_VK_SUCCESS(err);
13924
13925 // error here.
13926 pipe.CreateVKPipeline(pl, rp);
13927
13928 m_errorMonitor->VerifyFound();
13929
13930 vkDestroyRenderPass(m_device->device(), rp, nullptr);
13931 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
13932 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
13933}
13934
Chris Forbes541f7b02016-08-22 15:30:27 +120013935TEST_F(VkLayerTest, CreatePipelineInputAttachmentMissingArray) {
13936 TEST_DESCRIPTION("Test that an error is produced for a shader consuming an input attachment "
13937 "which is not included in the subpass description -- array case");
13938 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13939 "consumes input attachment index 1 but not provided in subpass");
13940
13941 ASSERT_NO_FATAL_FAILURE(InitState());
13942
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013943 char const *vsSource = "#version 450\n"
13944 "\n"
13945 "out gl_PerVertex {\n"
13946 " vec4 gl_Position;\n"
13947 "};\n"
13948 "void main(){\n"
13949 " gl_Position = vec4(1);\n"
13950 "}\n";
13951 char const *fsSource = "#version 450\n"
13952 "\n"
13953 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput xs[2];\n"
13954 "layout(location=0) out vec4 color;\n"
13955 "void main() {\n"
13956 " color = subpassLoad(xs[1]);\n"
13957 "}\n";
Chris Forbes541f7b02016-08-22 15:30:27 +120013958
13959 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13960 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13961
13962 VkPipelineObj pipe(m_device);
13963 pipe.AddShader(&vs);
13964 pipe.AddShader(&fs);
13965 pipe.AddColorAttachment();
13966 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13967
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013968 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 2, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
13969 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes541f7b02016-08-22 15:30:27 +120013970 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013971 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes541f7b02016-08-22 15:30:27 +120013972 ASSERT_VK_SUCCESS(err);
13973
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013974 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes541f7b02016-08-22 15:30:27 +120013975 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013976 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes541f7b02016-08-22 15:30:27 +120013977 ASSERT_VK_SUCCESS(err);
13978
13979 // error here.
13980 pipe.CreateVKPipeline(pl, renderPass());
13981
13982 m_errorMonitor->VerifyFound();
13983
13984 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
13985 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
13986}
13987
Chris Forbes10eb9ae2016-05-31 16:09:42 +120013988TEST_F(VkLayerTest, CreateComputePipelineMissingDescriptor) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013989 TEST_DESCRIPTION("Test that an error is produced for a compute pipeline consuming a "
13990 "descriptor which is not provided in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013991 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Shader uses descriptor slot 0.0");
Chris Forbes10eb9ae2016-05-31 16:09:42 +120013992
13993 ASSERT_NO_FATAL_FAILURE(InitState());
13994
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013995 char const *csSource = "#version 450\n"
13996 "\n"
13997 "layout(local_size_x=1) in;\n"
13998 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
13999 "void main(){\n"
14000 " x = vec4(1);\n"
14001 "}\n";
Chris Forbes10eb9ae2016-05-31 16:09:42 +120014002
14003 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
14004
14005 VkDescriptorSetObj descriptorSet(m_device);
14006 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14007
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014008 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
14009 nullptr,
14010 0,
14011 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
14012 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
14013 descriptorSet.GetPipelineLayout(),
14014 VK_NULL_HANDLE,
14015 -1};
Chris Forbes10eb9ae2016-05-31 16:09:42 +120014016
14017 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014018 VkResult err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes10eb9ae2016-05-31 16:09:42 +120014019
14020 m_errorMonitor->VerifyFound();
14021
14022 if (err == VK_SUCCESS) {
14023 vkDestroyPipeline(m_device->device(), pipe, nullptr);
14024 }
14025}
14026
Chris Forbes22a9b092016-07-19 14:34:05 +120014027TEST_F(VkLayerTest, CreateComputePipelineDescriptorTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014028 TEST_DESCRIPTION("Test that an error is produced for a pipeline consuming a "
14029 "descriptor-backed resource of a mismatched type");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014030 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14031 "but descriptor of type VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER");
Chris Forbes22a9b092016-07-19 14:34:05 +120014032
14033 ASSERT_NO_FATAL_FAILURE(InitState());
14034
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014035 VkDescriptorSetLayoutBinding binding = {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr};
14036 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &binding};
Chris Forbes22a9b092016-07-19 14:34:05 +120014037 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014038 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes22a9b092016-07-19 14:34:05 +120014039 ASSERT_VK_SUCCESS(err);
14040
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014041 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes22a9b092016-07-19 14:34:05 +120014042 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014043 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes22a9b092016-07-19 14:34:05 +120014044 ASSERT_VK_SUCCESS(err);
14045
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014046 char const *csSource = "#version 450\n"
14047 "\n"
14048 "layout(local_size_x=1) in;\n"
14049 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
14050 "void main() {\n"
14051 " x.x = 1.0f;\n"
14052 "}\n";
Chris Forbes22a9b092016-07-19 14:34:05 +120014053 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
14054
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014055 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
14056 nullptr,
14057 0,
14058 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
14059 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
14060 pl,
14061 VK_NULL_HANDLE,
14062 -1};
Chris Forbes22a9b092016-07-19 14:34:05 +120014063
14064 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014065 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes22a9b092016-07-19 14:34:05 +120014066
14067 m_errorMonitor->VerifyFound();
14068
14069 if (err == VK_SUCCESS) {
14070 vkDestroyPipeline(m_device->device(), pipe, nullptr);
14071 }
14072
14073 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
14074 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
14075}
14076
Chris Forbes50020592016-07-27 13:52:41 +120014077TEST_F(VkLayerTest, DrawTimeImageViewTypeMismatchWithPipeline) {
14078 TEST_DESCRIPTION("Test that an error is produced when an image view type "
14079 "does not match the dimensionality declared in the shader");
14080
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014081 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 +120014082
14083 ASSERT_NO_FATAL_FAILURE(InitState());
14084 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14085
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014086 char const *vsSource = "#version 450\n"
14087 "\n"
14088 "out gl_PerVertex { vec4 gl_Position; };\n"
14089 "void main() { gl_Position = vec4(0); }\n";
14090 char const *fsSource = "#version 450\n"
14091 "\n"
14092 "layout(set=0, binding=0) uniform sampler3D s;\n"
14093 "layout(location=0) out vec4 color;\n"
14094 "void main() {\n"
14095 " color = texture(s, vec3(0));\n"
14096 "}\n";
Chris Forbes50020592016-07-27 13:52:41 +120014097 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14098 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14099
14100 VkPipelineObj pipe(m_device);
14101 pipe.AddShader(&vs);
14102 pipe.AddShader(&fs);
14103 pipe.AddColorAttachment();
14104
14105 VkTextureObj texture(m_device, nullptr);
14106 VkSamplerObj sampler(m_device);
14107
14108 VkDescriptorSetObj descriptorSet(m_device);
14109 descriptorSet.AppendSamplerTexture(&sampler, &texture);
14110 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14111
14112 VkResult err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14113 ASSERT_VK_SUCCESS(err);
14114
14115 BeginCommandBuffer();
14116
14117 m_commandBuffer->BindPipeline(pipe);
14118 m_commandBuffer->BindDescriptorSet(descriptorSet);
14119
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014120 VkViewport viewport = {0, 0, 16, 16, 0, 1};
Chris Forbes50020592016-07-27 13:52:41 +120014121 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014122 VkRect2D scissor = {{0, 0}, {16, 16}};
Chris Forbes50020592016-07-27 13:52:41 +120014123 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
14124
14125 // error produced here.
14126 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
14127
14128 m_errorMonitor->VerifyFound();
14129
14130 EndCommandBuffer();
14131}
14132
Chris Forbes5533bfc2016-07-27 14:12:34 +120014133TEST_F(VkLayerTest, DrawTimeImageMultisampleMismatchWithPipeline) {
14134 TEST_DESCRIPTION("Test that an error is produced when a multisampled images "
14135 "are consumed via singlesample images types in the shader, or vice versa.");
14136
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014137 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "requires bound image to have multiple samples");
Chris Forbes5533bfc2016-07-27 14:12:34 +120014138
14139 ASSERT_NO_FATAL_FAILURE(InitState());
14140 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14141
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014142 char const *vsSource = "#version 450\n"
14143 "\n"
14144 "out gl_PerVertex { vec4 gl_Position; };\n"
14145 "void main() { gl_Position = vec4(0); }\n";
14146 char const *fsSource = "#version 450\n"
14147 "\n"
14148 "layout(set=0, binding=0) uniform sampler2DMS s;\n"
14149 "layout(location=0) out vec4 color;\n"
14150 "void main() {\n"
14151 " color = texelFetch(s, ivec2(0), 0);\n"
14152 "}\n";
Chris Forbes5533bfc2016-07-27 14:12:34 +120014153 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14154 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14155
14156 VkPipelineObj pipe(m_device);
14157 pipe.AddShader(&vs);
14158 pipe.AddShader(&fs);
14159 pipe.AddColorAttachment();
14160
14161 VkTextureObj texture(m_device, nullptr);
14162 VkSamplerObj sampler(m_device);
14163
14164 VkDescriptorSetObj descriptorSet(m_device);
14165 descriptorSet.AppendSamplerTexture(&sampler, &texture);
14166 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14167
14168 VkResult err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14169 ASSERT_VK_SUCCESS(err);
14170
14171 BeginCommandBuffer();
14172
14173 m_commandBuffer->BindPipeline(pipe);
14174 m_commandBuffer->BindDescriptorSet(descriptorSet);
14175
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014176 VkViewport viewport = {0, 0, 16, 16, 0, 1};
Chris Forbes5533bfc2016-07-27 14:12:34 +120014177 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014178 VkRect2D scissor = {{0, 0}, {16, 16}};
Chris Forbes5533bfc2016-07-27 14:12:34 +120014179 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
14180
14181 // error produced here.
14182 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
14183
14184 m_errorMonitor->VerifyFound();
14185
14186 EndCommandBuffer();
14187}
14188
Mark Lobodzinski209b5292015-09-17 09:44:05 -060014189#endif // SHADER_CHECKER_TESTS
14190
14191#if DEVICE_LIMITS_TESTS
Mark Youngc48c4c12016-04-11 14:26:49 -060014192TEST_F(VkLayerTest, CreateImageLimitsViolationMaxWidth) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014193 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "CreateImage extents exceed allowable limits for format");
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060014194
14195 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060014196
14197 // Create an image
14198 VkImage image;
14199
Karl Schultz6addd812016-02-02 17:17:23 -070014200 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
14201 const int32_t tex_width = 32;
14202 const int32_t tex_height = 32;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060014203
14204 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014205 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14206 image_create_info.pNext = NULL;
14207 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14208 image_create_info.format = tex_format;
14209 image_create_info.extent.width = tex_width;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060014210 image_create_info.extent.height = tex_height;
Karl Schultz6addd812016-02-02 17:17:23 -070014211 image_create_info.extent.depth = 1;
14212 image_create_info.mipLevels = 1;
14213 image_create_info.arrayLayers = 1;
14214 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14215 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
14216 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
14217 image_create_info.flags = 0;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060014218
14219 // Introduce error by sending down a bogus width extent
14220 image_create_info.extent.width = 65536;
Chia-I Wuf7458c52015-10-26 21:10:41 +080014221 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060014222
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014223 m_errorMonitor->VerifyFound();
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060014224}
14225
Mark Youngc48c4c12016-04-11 14:26:49 -060014226TEST_F(VkLayerTest, CreateImageLimitsViolationMinWidth) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014227 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14228 "CreateImage extents is 0 for at least one required dimension");
Mark Youngc48c4c12016-04-11 14:26:49 -060014229
14230 ASSERT_NO_FATAL_FAILURE(InitState());
14231
14232 // Create an image
14233 VkImage image;
14234
14235 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
14236 const int32_t tex_width = 32;
14237 const int32_t tex_height = 32;
14238
14239 VkImageCreateInfo image_create_info = {};
14240 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14241 image_create_info.pNext = NULL;
14242 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14243 image_create_info.format = tex_format;
14244 image_create_info.extent.width = tex_width;
14245 image_create_info.extent.height = tex_height;
14246 image_create_info.extent.depth = 1;
14247 image_create_info.mipLevels = 1;
14248 image_create_info.arrayLayers = 1;
14249 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14250 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
14251 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
14252 image_create_info.flags = 0;
14253
14254 // Introduce error by sending down a bogus width extent
14255 image_create_info.extent.width = 0;
14256 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
14257
14258 m_errorMonitor->VerifyFound();
14259}
Mark Lobodzinski209b5292015-09-17 09:44:05 -060014260#endif // DEVICE_LIMITS_TESTS
Chris Forbesa36d69e2015-05-25 11:13:44 +120014261
Tobin Ehliscde08892015-09-22 10:11:37 -060014262#if IMAGE_TESTS
Mark Lobodzinski66e5eab2016-11-15 13:30:38 -070014263
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060014264TEST_F(VkLayerTest, AttachmentDescriptionUndefinedFormat) {
14265 TEST_DESCRIPTION("Create a render pass with an attachment description "
14266 "format set to VK_FORMAT_UNDEFINED");
14267
14268 ASSERT_NO_FATAL_FAILURE(InitState());
14269 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14270
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014271 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "format is VK_FORMAT_UNDEFINED");
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060014272
14273 VkAttachmentReference color_attach = {};
14274 color_attach.layout = VK_IMAGE_LAYOUT_GENERAL;
14275 color_attach.attachment = 0;
14276 VkSubpassDescription subpass = {};
14277 subpass.colorAttachmentCount = 1;
14278 subpass.pColorAttachments = &color_attach;
14279
14280 VkRenderPassCreateInfo rpci = {};
14281 rpci.subpassCount = 1;
14282 rpci.pSubpasses = &subpass;
14283 rpci.attachmentCount = 1;
14284 VkAttachmentDescription attach_desc = {};
14285 attach_desc.format = VK_FORMAT_UNDEFINED;
14286 rpci.pAttachments = &attach_desc;
14287 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
14288 VkRenderPass rp;
14289 VkResult result = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
14290
14291 m_errorMonitor->VerifyFound();
14292
14293 if (result == VK_SUCCESS) {
14294 vkDestroyRenderPass(m_device->device(), rp, NULL);
14295 }
14296}
14297
Karl Schultz6addd812016-02-02 17:17:23 -070014298TEST_F(VkLayerTest, InvalidImageView) {
14299 VkResult err;
Tobin Ehliscde08892015-09-22 10:11:37 -060014300
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014301 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with baseMipLevel 10 ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014302
Tobin Ehliscde08892015-09-22 10:11:37 -060014303 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehliscde08892015-09-22 10:11:37 -060014304
Mike Stroyana3082432015-09-25 13:39:21 -060014305 // Create an image and try to create a view with bad baseMipLevel
Karl Schultz6addd812016-02-02 17:17:23 -070014306 VkImage image;
Tobin Ehliscde08892015-09-22 10:11:37 -060014307
Karl Schultz6addd812016-02-02 17:17:23 -070014308 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
14309 const int32_t tex_width = 32;
14310 const int32_t tex_height = 32;
Tobin Ehliscde08892015-09-22 10:11:37 -060014311
14312 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014313 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14314 image_create_info.pNext = NULL;
14315 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14316 image_create_info.format = tex_format;
14317 image_create_info.extent.width = tex_width;
14318 image_create_info.extent.height = tex_height;
14319 image_create_info.extent.depth = 1;
14320 image_create_info.mipLevels = 1;
14321 image_create_info.arrayLayers = 1;
14322 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14323 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
14324 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
14325 image_create_info.flags = 0;
Tobin Ehliscde08892015-09-22 10:11:37 -060014326
Chia-I Wuf7458c52015-10-26 21:10:41 +080014327 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehliscde08892015-09-22 10:11:37 -060014328 ASSERT_VK_SUCCESS(err);
14329
14330 VkImageViewCreateInfo image_view_create_info = {};
Chris Forbes53bef902016-11-28 17:53:04 +130014331 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070014332 image_view_create_info.image = image;
14333 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
14334 image_view_create_info.format = tex_format;
14335 image_view_create_info.subresourceRange.layerCount = 1;
14336 image_view_create_info.subresourceRange.baseMipLevel = 10; // cause an error
14337 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014338 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehliscde08892015-09-22 10:11:37 -060014339
14340 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014341 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehliscde08892015-09-22 10:11:37 -060014342
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014343 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -060014344 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehliscde08892015-09-22 10:11:37 -060014345}
Mike Stroyana3082432015-09-25 13:39:21 -060014346
Mark Youngd339ba32016-05-30 13:28:35 -060014347TEST_F(VkLayerTest, CreateImageViewNoMemoryBoundToImage) {
14348 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -060014349 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -060014350 " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Mark Youngd339ba32016-05-30 13:28:35 -060014351
14352 ASSERT_NO_FATAL_FAILURE(InitState());
14353
14354 // Create an image and try to create a view with no memory backing the image
14355 VkImage image;
14356
14357 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
14358 const int32_t tex_width = 32;
14359 const int32_t tex_height = 32;
14360
14361 VkImageCreateInfo image_create_info = {};
14362 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14363 image_create_info.pNext = NULL;
14364 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14365 image_create_info.format = tex_format;
14366 image_create_info.extent.width = tex_width;
14367 image_create_info.extent.height = tex_height;
14368 image_create_info.extent.depth = 1;
14369 image_create_info.mipLevels = 1;
14370 image_create_info.arrayLayers = 1;
14371 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14372 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
14373 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
14374 image_create_info.flags = 0;
14375
14376 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
14377 ASSERT_VK_SUCCESS(err);
14378
14379 VkImageViewCreateInfo image_view_create_info = {};
Chris Forbes53bef902016-11-28 17:53:04 +130014380 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Mark Youngd339ba32016-05-30 13:28:35 -060014381 image_view_create_info.image = image;
14382 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
14383 image_view_create_info.format = tex_format;
14384 image_view_create_info.subresourceRange.layerCount = 1;
14385 image_view_create_info.subresourceRange.baseMipLevel = 0;
14386 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014387 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Youngd339ba32016-05-30 13:28:35 -060014388
14389 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014390 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Youngd339ba32016-05-30 13:28:35 -060014391
14392 m_errorMonitor->VerifyFound();
14393 vkDestroyImage(m_device->device(), image, NULL);
14394 // If last error is success, it still created the view, so delete it.
14395 if (err == VK_SUCCESS) {
14396 vkDestroyImageView(m_device->device(), view, NULL);
14397 }
Mark Youngd339ba32016-05-30 13:28:35 -060014398}
14399
Karl Schultz6addd812016-02-02 17:17:23 -070014400TEST_F(VkLayerTest, InvalidImageViewAspect) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014401 TEST_DESCRIPTION("Create an image and try to create a view with an invalid aspectMask");
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060014402 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView(): Color image "
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014403 "formats must have ONLY the "
14404 "VK_IMAGE_ASPECT_COLOR_BIT set");
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060014405 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14406 "Color image formats must have the VK_IMAGE_ASPECT_COLOR_BIT set.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014407
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060014408 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060014409
Karl Schultz6addd812016-02-02 17:17:23 -070014410 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060014411 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014412 image.init(32, 32, tex_format, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_LINEAR, 0);
Tobin Ehlis1f567a22016-05-25 16:15:18 -060014413 ASSERT_TRUE(image.initialized());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060014414
14415 VkImageViewCreateInfo image_view_create_info = {};
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060014416 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060014417 image_view_create_info.image = image.handle();
Karl Schultz6addd812016-02-02 17:17:23 -070014418 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
14419 image_view_create_info.format = tex_format;
14420 image_view_create_info.subresourceRange.baseMipLevel = 0;
14421 image_view_create_info.subresourceRange.levelCount = 1;
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060014422 image_view_create_info.subresourceRange.layerCount = 1;
Karl Schultz6addd812016-02-02 17:17:23 -070014423 // Cause an error by setting an invalid image aspect
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014424 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060014425
14426 VkImageView view;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060014427 vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060014428
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014429 m_errorMonitor->VerifyFound();
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060014430}
14431
Mark Lobodzinskidb117632016-03-31 10:45:56 -060014432TEST_F(VkLayerTest, CopyImageLayerCountMismatch) {
Karl Schultz6addd812016-02-02 17:17:23 -070014433 VkResult err;
14434 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060014435
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014436 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14437 "vkCmdCopyImage: number of layers in source and destination subresources for pRegions");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014438
Mike Stroyana3082432015-09-25 13:39:21 -060014439 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060014440
14441 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070014442 VkImage srcImage;
14443 VkImage dstImage;
14444 VkDeviceMemory srcMem;
14445 VkDeviceMemory destMem;
14446 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060014447
14448 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014449 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14450 image_create_info.pNext = NULL;
14451 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14452 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
14453 image_create_info.extent.width = 32;
14454 image_create_info.extent.height = 32;
14455 image_create_info.extent.depth = 1;
14456 image_create_info.mipLevels = 1;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060014457 image_create_info.arrayLayers = 4;
Karl Schultz6addd812016-02-02 17:17:23 -070014458 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14459 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
14460 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
14461 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014462
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014463 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014464 ASSERT_VK_SUCCESS(err);
14465
Mark Lobodzinski867787a2016-10-14 11:49:55 -060014466 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014467 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014468 ASSERT_VK_SUCCESS(err);
14469
14470 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014471 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014472 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
14473 memAlloc.pNext = NULL;
14474 memAlloc.allocationSize = 0;
14475 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014476
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060014477 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014478 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014479 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014480 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014481 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014482 ASSERT_VK_SUCCESS(err);
14483
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014484 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014485 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014486 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060014487 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014488 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014489 ASSERT_VK_SUCCESS(err);
14490
14491 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
14492 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014493 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060014494 ASSERT_VK_SUCCESS(err);
14495
14496 BeginCommandBuffer();
14497 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014498 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014499 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060014500 copyRegion.srcSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060014501 copyRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060014502 copyRegion.srcOffset.x = 0;
14503 copyRegion.srcOffset.y = 0;
14504 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014505 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014506 copyRegion.dstSubresource.mipLevel = 0;
14507 copyRegion.dstSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060014508 // Introduce failure by forcing the dst layerCount to differ from src
14509 copyRegion.dstSubresource.layerCount = 3;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014510 copyRegion.dstOffset.x = 0;
14511 copyRegion.dstOffset.y = 0;
14512 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014513 copyRegion.extent.width = 1;
14514 copyRegion.extent.height = 1;
14515 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014516 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060014517 EndCommandBuffer();
14518
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014519 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060014520
Chia-I Wuf7458c52015-10-26 21:10:41 +080014521 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014522 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080014523 vkFreeMemory(m_device->device(), srcMem, NULL);
14524 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060014525}
14526
Tony Barbourd6673642016-05-05 14:46:39 -060014527TEST_F(VkLayerTest, ImageLayerUnsupportedFormat) {
14528
14529 TEST_DESCRIPTION("Creating images with unsuported formats ");
14530
14531 ASSERT_NO_FATAL_FAILURE(InitState());
14532 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14533 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014534 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 -060014535 VK_IMAGE_TILING_OPTIMAL, 0);
14536 ASSERT_TRUE(image.initialized());
14537
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014538 // Create image with unsupported format - Expect FORMAT_UNSUPPORTED
Chris Forbesf4d8e332016-11-28 17:51:10 +130014539 VkImageCreateInfo image_create_info = {};
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014540 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014541 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14542 image_create_info.format = VK_FORMAT_UNDEFINED;
14543 image_create_info.extent.width = 32;
14544 image_create_info.extent.height = 32;
14545 image_create_info.extent.depth = 1;
14546 image_create_info.mipLevels = 1;
14547 image_create_info.arrayLayers = 1;
14548 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14549 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
14550 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014551
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014552 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14553 "vkCreateImage: VkFormat for image must not be VK_FORMAT_UNDEFINED");
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014554
14555 VkImage localImage;
14556 vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage);
14557 m_errorMonitor->VerifyFound();
14558
Tony Barbourd6673642016-05-05 14:46:39 -060014559 VkFormat unsupported = VK_FORMAT_UNDEFINED;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014560 // Look for a format that is COMPLETELY unsupported with this hardware
Tony Barbourd6673642016-05-05 14:46:39 -060014561 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
14562 VkFormat format = static_cast<VkFormat>(f);
14563 VkFormatProperties fProps = m_device->format_properties(format);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014564 if (format != VK_FORMAT_UNDEFINED && fProps.linearTilingFeatures == 0 && fProps.optimalTilingFeatures == 0) {
Tony Barbourd6673642016-05-05 14:46:39 -060014565 unsupported = format;
14566 break;
14567 }
14568 }
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014569
Tony Barbourd6673642016-05-05 14:46:39 -060014570 if (unsupported != VK_FORMAT_UNDEFINED) {
Tony Barbourd6673642016-05-05 14:46:39 -060014571 image_create_info.format = unsupported;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014572 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is an unsupported format");
Tony Barbourd6673642016-05-05 14:46:39 -060014573
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014574 vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage);
Tony Barbourd6673642016-05-05 14:46:39 -060014575 m_errorMonitor->VerifyFound();
14576 }
14577}
14578
14579TEST_F(VkLayerTest, ImageLayerViewTests) {
14580 VkResult ret;
14581 TEST_DESCRIPTION("Passing bad parameters to CreateImageView");
14582
14583 ASSERT_NO_FATAL_FAILURE(InitState());
14584
14585 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014586 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 -060014587 VK_IMAGE_TILING_OPTIMAL, 0);
14588 ASSERT_TRUE(image.initialized());
14589
14590 VkImageView imgView;
14591 VkImageViewCreateInfo imgViewInfo = {};
14592 imgViewInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
14593 imgViewInfo.image = image.handle();
14594 imgViewInfo.viewType = VK_IMAGE_VIEW_TYPE_2D;
14595 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
14596 imgViewInfo.subresourceRange.layerCount = 1;
14597 imgViewInfo.subresourceRange.baseMipLevel = 0;
14598 imgViewInfo.subresourceRange.levelCount = 1;
14599 imgViewInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14600
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014601 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with baseMipLevel");
Tony Barbourd6673642016-05-05 14:46:39 -060014602 // View can't have baseMipLevel >= image's mipLevels - Expect
14603 // VIEW_CREATE_ERROR
14604 imgViewInfo.subresourceRange.baseMipLevel = 1;
14605 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14606 m_errorMonitor->VerifyFound();
14607 imgViewInfo.subresourceRange.baseMipLevel = 0;
14608
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014609 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with baseArrayLayer");
Tony Barbourd6673642016-05-05 14:46:39 -060014610 // View can't have baseArrayLayer >= image's arraySize - Expect
14611 // VIEW_CREATE_ERROR
14612 imgViewInfo.subresourceRange.baseArrayLayer = 1;
14613 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14614 m_errorMonitor->VerifyFound();
14615 imgViewInfo.subresourceRange.baseArrayLayer = 0;
14616
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014617 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with 0 in "
14618 "pCreateInfo->subresourceRange."
14619 "levelCount");
Tony Barbourd6673642016-05-05 14:46:39 -060014620 // View's levelCount can't be 0 - Expect VIEW_CREATE_ERROR
14621 imgViewInfo.subresourceRange.levelCount = 0;
14622 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14623 m_errorMonitor->VerifyFound();
14624 imgViewInfo.subresourceRange.levelCount = 1;
14625
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014626 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with 0 in "
14627 "pCreateInfo->subresourceRange."
14628 "layerCount");
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060014629 m_errorMonitor->SetDesiredFailureMsg(
14630 VK_DEBUG_REPORT_ERROR_BIT_EXT,
14631 "if pCreateInfo->viewType is VK_IMAGE_TYPE_2D, pCreateInfo->subresourceRange.layerCount must be 1");
Tony Barbourd6673642016-05-05 14:46:39 -060014632 // View's layerCount can't be 0 - Expect VIEW_CREATE_ERROR
14633 imgViewInfo.subresourceRange.layerCount = 0;
14634 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14635 m_errorMonitor->VerifyFound();
14636 imgViewInfo.subresourceRange.layerCount = 1;
14637
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014638 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "but both must be color formats");
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060014639 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Formats MUST be IDENTICAL unless "
14640 "VK_IMAGE_CREATE_MUTABLE_FORMAT BIT "
14641 "was set on image creation.");
Tony Barbourd6673642016-05-05 14:46:39 -060014642 // Can't use depth format for view into color image - Expect INVALID_FORMAT
14643 imgViewInfo.format = VK_FORMAT_D24_UNORM_S8_UINT;
14644 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14645 m_errorMonitor->VerifyFound();
14646 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
14647
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014648 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Formats MUST be IDENTICAL unless "
14649 "VK_IMAGE_CREATE_MUTABLE_FORMAT BIT "
14650 "was set on image creation.");
Tony Barbourd6673642016-05-05 14:46:39 -060014651 // Same compatibility class but no MUTABLE_FORMAT bit - Expect
14652 // VIEW_CREATE_ERROR
14653 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UINT;
14654 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14655 m_errorMonitor->VerifyFound();
14656 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
14657
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014658 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "can support ImageViews with "
14659 "differing formats but they must be "
14660 "in the same compatibility class.");
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060014661 // TODO: Update framework to easily passing mutable flag into ImageObj init
14662 // For now just allowing image for this one test to not have memory bound
14663 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14664 " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Tony Barbourd6673642016-05-05 14:46:39 -060014665 // Have MUTABLE_FORMAT bit but not in same compatibility class - Expect
14666 // VIEW_CREATE_ERROR
14667 VkImageCreateInfo mutImgInfo = image.create_info();
14668 VkImage mutImage;
14669 mutImgInfo.format = VK_FORMAT_R8_UINT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014670 assert(m_device->format_properties(VK_FORMAT_R8_UINT).optimalTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT);
Tony Barbourd6673642016-05-05 14:46:39 -060014671 mutImgInfo.flags = VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT;
14672 mutImgInfo.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
14673 ret = vkCreateImage(m_device->handle(), &mutImgInfo, NULL, &mutImage);
14674 ASSERT_VK_SUCCESS(ret);
14675 imgViewInfo.image = mutImage;
14676 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14677 m_errorMonitor->VerifyFound();
14678 imgViewInfo.image = image.handle();
14679 vkDestroyImage(m_device->handle(), mutImage, NULL);
14680}
14681
14682TEST_F(VkLayerTest, MiscImageLayerTests) {
14683
14684 TEST_DESCRIPTION("Image layer tests that don't belong elsewhare");
14685
14686 ASSERT_NO_FATAL_FAILURE(InitState());
14687
Rene Lindsay135204f2016-12-22 17:11:09 -070014688 // TODO: Ideally we should check if a format is supported, before using it.
Tony Barbourd6673642016-05-05 14:46:39 -060014689 VkImageObj image(m_device);
Rene Lindsay135204f2016-12-22 17:11:09 -070014690 image.init(128, 128, VK_FORMAT_R16G16B16A16_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
14691 VK_IMAGE_TILING_OPTIMAL, 0); // 64bpp
Tony Barbourd6673642016-05-05 14:46:39 -060014692 ASSERT_TRUE(image.initialized());
Tony Barbourd6673642016-05-05 14:46:39 -060014693 vk_testing::Buffer buffer;
14694 VkMemoryPropertyFlags reqs = 0;
Rene Lindsay135204f2016-12-22 17:11:09 -070014695 buffer.init_as_src(*m_device, 128 * 128 * 8, reqs);
Tony Barbourd6673642016-05-05 14:46:39 -060014696 VkBufferImageCopy region = {};
14697 region.bufferRowLength = 128;
14698 region.bufferImageHeight = 128;
14699 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14700 // layerCount can't be 0 - Expect MISMATCHED_IMAGE_ASPECT
Mark Lobodzinski3702e932016-11-22 11:40:48 -070014701 region.imageSubresource.layerCount = 1;
Tony Barbourd6673642016-05-05 14:46:39 -060014702 region.imageExtent.height = 4;
14703 region.imageExtent.width = 4;
14704 region.imageExtent.depth = 1;
Rene Lindsay135204f2016-12-22 17:11:09 -070014705
14706 VkImageObj image2(m_device);
14707 image2.init(128, 128, VK_FORMAT_R8G8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
14708 VK_IMAGE_TILING_OPTIMAL, 0); // 16bpp
14709 ASSERT_TRUE(image2.initialized());
14710 vk_testing::Buffer buffer2;
14711 VkMemoryPropertyFlags reqs2 = 0;
14712 buffer2.init_as_src(*m_device, 128 * 128 * 2, reqs2);
14713 VkBufferImageCopy region2 = {};
14714 region2.bufferRowLength = 128;
14715 region2.bufferImageHeight = 128;
14716 region2.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14717 // layerCount can't be 0 - Expect MISMATCHED_IMAGE_ASPECT
14718 region2.imageSubresource.layerCount = 1;
14719 region2.imageExtent.height = 4;
14720 region2.imageExtent.width = 4;
14721 region2.imageExtent.depth = 1;
Tony Barbourd6673642016-05-05 14:46:39 -060014722 m_commandBuffer->BeginCommandBuffer();
Tony Barbourd6673642016-05-05 14:46:39 -060014723
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070014724 // Image must have offset.z of 0 and extent.depth of 1
14725 // Introduce failure by setting imageExtent.depth to 0
14726 region.imageExtent.depth = 0;
14727 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01269);
14728 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
14729 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
14730 m_errorMonitor->VerifyFound();
14731
14732 region.imageExtent.depth = 1;
14733
14734 // Image must have offset.z of 0 and extent.depth of 1
14735 // Introduce failure by setting imageOffset.z to 4
14736 region.imageOffset.z = 4;
14737 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01269);
14738 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
14739 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
14740 m_errorMonitor->VerifyFound();
14741
14742 region.imageOffset.z = 0;
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060014743 // BufferOffset must be a multiple of the calling command's VkImage parameter's texel size
14744 // Introduce failure by setting bufferOffset to 1 and 1/2 texels
Rene Lindsay135204f2016-12-22 17:11:09 -070014745 region.bufferOffset = 4;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070014746 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01263);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014747 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
14748 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060014749 m_errorMonitor->VerifyFound();
14750
14751 // BufferOffset must be a multiple of 4
14752 // Introduce failure by setting bufferOffset to a value not divisible by 4
Rene Lindsay135204f2016-12-22 17:11:09 -070014753 region2.bufferOffset = 6;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070014754 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01264);
Rene Lindsay135204f2016-12-22 17:11:09 -070014755 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer2.handle(), image2.handle(),
14756 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region2);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060014757 m_errorMonitor->VerifyFound();
14758
14759 // BufferRowLength must be 0, or greater than or equal to the width member of imageExtent
14760 region.bufferOffset = 0;
14761 region.imageExtent.height = 128;
14762 region.imageExtent.width = 128;
14763 // Introduce failure by setting bufferRowLength > 0 but less than width
14764 region.bufferRowLength = 64;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070014765 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01265);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014766 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
14767 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060014768 m_errorMonitor->VerifyFound();
14769
14770 // BufferImageHeight must be 0, or greater than or equal to the height member of imageExtent
14771 region.bufferRowLength = 128;
14772 // Introduce failure by setting bufferRowHeight > 0 but less than height
14773 region.bufferImageHeight = 64;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070014774 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01266);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014775 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
14776 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060014777 m_errorMonitor->VerifyFound();
14778
14779 region.bufferImageHeight = 128;
Dave Houlton34df4cb2016-12-01 16:43:06 -070014780 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "If the format of srcImage is an "
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014781 "integer-based format then filter must be VK_FILTER_NEAREST");
Tony Barbourd6673642016-05-05 14:46:39 -060014782 // Expect INVALID_FILTER
14783 VkImageObj intImage1(m_device);
Rene Lindsaya35e1cb2016-12-26 10:30:05 -070014784 intImage1.init(128, 128, VK_FORMAT_R8_UINT, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT,
14785 VK_IMAGE_TILING_OPTIMAL, 0);
Tony Barbourd6673642016-05-05 14:46:39 -060014786 VkImageObj intImage2(m_device);
Rene Lindsaya35e1cb2016-12-26 10:30:05 -070014787 intImage2.init(128, 128, VK_FORMAT_R8_UINT, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
14788 VK_IMAGE_TILING_OPTIMAL, 0);
Tony Barbourd6673642016-05-05 14:46:39 -060014789 VkImageBlit blitRegion = {};
14790 blitRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14791 blitRegion.srcSubresource.baseArrayLayer = 0;
14792 blitRegion.srcSubresource.layerCount = 1;
14793 blitRegion.srcSubresource.mipLevel = 0;
14794 blitRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14795 blitRegion.dstSubresource.baseArrayLayer = 0;
14796 blitRegion.dstSubresource.layerCount = 1;
14797 blitRegion.dstSubresource.mipLevel = 0;
14798
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014799 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), intImage1.handle(), intImage1.layout(), intImage2.handle(),
Rene Lindsaya35e1cb2016-12-26 10:30:05 -070014800 intImage2.layout(), 1, &blitRegion, VK_FILTER_LINEAR);
Tony Barbourd6673642016-05-05 14:46:39 -060014801 m_errorMonitor->VerifyFound();
14802
Mark Lobodzinskib02ea642016-08-17 13:03:57 -060014803 // Look for NULL-blit warning
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014804 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "Offsets specify a zero-volume area.");
14805 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), intImage1.handle(), intImage1.layout(), intImage2.handle(),
14806 intImage2.layout(), 1, &blitRegion, VK_FILTER_LINEAR);
Mark Lobodzinskib02ea642016-08-17 13:03:57 -060014807 m_errorMonitor->VerifyFound();
14808
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014809 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with 0 in ppMemoryBarriers");
Tony Barbourd6673642016-05-05 14:46:39 -060014810 VkImageMemoryBarrier img_barrier;
14811 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
14812 img_barrier.pNext = NULL;
14813 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
14814 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
14815 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
14816 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
14817 img_barrier.image = image.handle();
14818 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
14819 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
14820 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14821 img_barrier.subresourceRange.baseArrayLayer = 0;
14822 img_barrier.subresourceRange.baseMipLevel = 0;
14823 // layerCount should not be 0 - Expect INVALID_IMAGE_RESOURCE
14824 img_barrier.subresourceRange.layerCount = 0;
14825 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014826 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
14827 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbourd6673642016-05-05 14:46:39 -060014828 m_errorMonitor->VerifyFound();
14829 img_barrier.subresourceRange.layerCount = 1;
14830}
14831
14832TEST_F(VkLayerTest, ImageFormatLimits) {
14833
14834 TEST_DESCRIPTION("Exceed the limits of image format ");
14835
Cody Northropc31a84f2016-08-22 10:41:47 -060014836 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014837 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "CreateImage extents exceed allowable limits for format");
Tony Barbourd6673642016-05-05 14:46:39 -060014838 VkImageCreateInfo image_create_info = {};
14839 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14840 image_create_info.pNext = NULL;
14841 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14842 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
14843 image_create_info.extent.width = 32;
14844 image_create_info.extent.height = 32;
14845 image_create_info.extent.depth = 1;
14846 image_create_info.mipLevels = 1;
14847 image_create_info.arrayLayers = 1;
14848 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14849 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
14850 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
14851 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
14852 image_create_info.flags = 0;
14853
14854 VkImage nullImg;
14855 VkImageFormatProperties imgFmtProps;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014856 vkGetPhysicalDeviceImageFormatProperties(gpu(), image_create_info.format, image_create_info.imageType, image_create_info.tiling,
14857 image_create_info.usage, image_create_info.flags, &imgFmtProps);
Tony Barbourd6673642016-05-05 14:46:39 -060014858 image_create_info.extent.depth = imgFmtProps.maxExtent.depth + 1;
14859 // Expect INVALID_FORMAT_LIMITS_VIOLATION
14860 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
14861 m_errorMonitor->VerifyFound();
14862 image_create_info.extent.depth = 1;
14863
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014864 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "exceeds allowable maximum supported by format of");
Tony Barbourd6673642016-05-05 14:46:39 -060014865 image_create_info.mipLevels = imgFmtProps.maxMipLevels + 1;
14866 // Expect INVALID_FORMAT_LIMITS_VIOLATION
14867 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
14868 m_errorMonitor->VerifyFound();
14869 image_create_info.mipLevels = 1;
14870
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014871 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "exceeds allowable maximum supported by format of");
Tony Barbourd6673642016-05-05 14:46:39 -060014872 image_create_info.arrayLayers = imgFmtProps.maxArrayLayers + 1;
14873 // Expect INVALID_FORMAT_LIMITS_VIOLATION
14874 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
14875 m_errorMonitor->VerifyFound();
14876 image_create_info.arrayLayers = 1;
14877
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014878 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is not supported by format");
Tony Barbourd6673642016-05-05 14:46:39 -060014879 int samples = imgFmtProps.sampleCounts >> 1;
14880 image_create_info.samples = (VkSampleCountFlagBits)samples;
14881 // Expect INVALID_FORMAT_LIMITS_VIOLATION
14882 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
14883 m_errorMonitor->VerifyFound();
14884 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14885
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014886 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "pCreateInfo->initialLayout, must be "
14887 "VK_IMAGE_LAYOUT_UNDEFINED or "
14888 "VK_IMAGE_LAYOUT_PREINITIALIZED");
Tony Barbourd6673642016-05-05 14:46:39 -060014889 image_create_info.initialLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
14890 // Expect INVALID_LAYOUT
14891 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
14892 m_errorMonitor->VerifyFound();
14893 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
14894}
14895
Mark Lobodzinskicea14992016-10-14 10:59:42 -060014896TEST_F(VkLayerTest, CopyImageSrcSizeExceeded) {
14897
14898 // Image copy with source region specified greater than src image size
Mark Lobodzinski629d47b2016-10-18 13:34:58 -060014899 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01175);
Mark Lobodzinskicea14992016-10-14 10:59:42 -060014900
14901 ASSERT_NO_FATAL_FAILURE(InitState());
14902
14903 VkImageObj src_image(m_device);
14904 src_image.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_LINEAR, 0);
14905 VkImageObj dst_image(m_device);
14906 dst_image.init(64, 64, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
14907
14908 BeginCommandBuffer();
14909 VkImageCopy copy_region;
14910 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14911 copy_region.srcSubresource.mipLevel = 0;
14912 copy_region.srcSubresource.baseArrayLayer = 0;
14913 copy_region.srcSubresource.layerCount = 0;
14914 copy_region.srcOffset.x = 0;
14915 copy_region.srcOffset.y = 0;
14916 copy_region.srcOffset.z = 0;
14917 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14918 copy_region.dstSubresource.mipLevel = 0;
14919 copy_region.dstSubresource.baseArrayLayer = 0;
14920 copy_region.dstSubresource.layerCount = 0;
14921 copy_region.dstOffset.x = 0;
14922 copy_region.dstOffset.y = 0;
14923 copy_region.dstOffset.z = 0;
14924 copy_region.extent.width = 64;
14925 copy_region.extent.height = 64;
14926 copy_region.extent.depth = 1;
14927 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
14928 &copy_region);
14929 EndCommandBuffer();
14930
14931 m_errorMonitor->VerifyFound();
14932}
14933
14934TEST_F(VkLayerTest, CopyImageDstSizeExceeded) {
14935
14936 // Image copy with dest region specified greater than dest image size
Mark Lobodzinski629d47b2016-10-18 13:34:58 -060014937 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01176);
Mark Lobodzinskicea14992016-10-14 10:59:42 -060014938
14939 ASSERT_NO_FATAL_FAILURE(InitState());
14940
14941 VkImageObj src_image(m_device);
14942 src_image.init(64, 64, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_LINEAR, 0);
14943 VkImageObj dst_image(m_device);
14944 dst_image.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
14945
14946 BeginCommandBuffer();
14947 VkImageCopy copy_region;
14948 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14949 copy_region.srcSubresource.mipLevel = 0;
14950 copy_region.srcSubresource.baseArrayLayer = 0;
14951 copy_region.srcSubresource.layerCount = 0;
14952 copy_region.srcOffset.x = 0;
14953 copy_region.srcOffset.y = 0;
14954 copy_region.srcOffset.z = 0;
14955 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14956 copy_region.dstSubresource.mipLevel = 0;
14957 copy_region.dstSubresource.baseArrayLayer = 0;
14958 copy_region.dstSubresource.layerCount = 0;
14959 copy_region.dstOffset.x = 0;
14960 copy_region.dstOffset.y = 0;
14961 copy_region.dstOffset.z = 0;
14962 copy_region.extent.width = 64;
14963 copy_region.extent.height = 64;
14964 copy_region.extent.depth = 1;
14965 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
14966 &copy_region);
14967 EndCommandBuffer();
14968
14969 m_errorMonitor->VerifyFound();
14970}
14971
Karl Schultz6addd812016-02-02 17:17:23 -070014972TEST_F(VkLayerTest, CopyImageFormatSizeMismatch) {
Karl Schultzbdb75952016-04-19 11:36:49 -060014973 VkResult err;
14974 bool pass;
14975
14976 // Create color images with different format sizes and try to copy between them
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014977 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14978 "vkCmdCopyImage called with unmatched source and dest image format sizes");
Karl Schultzbdb75952016-04-19 11:36:49 -060014979
14980 ASSERT_NO_FATAL_FAILURE(InitState());
14981
14982 // Create two images of different types and try to copy between them
14983 VkImage srcImage;
14984 VkImage dstImage;
14985 VkDeviceMemory srcMem;
14986 VkDeviceMemory destMem;
14987 VkMemoryRequirements memReqs;
14988
14989 VkImageCreateInfo image_create_info = {};
14990 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14991 image_create_info.pNext = NULL;
14992 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14993 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
14994 image_create_info.extent.width = 32;
14995 image_create_info.extent.height = 32;
14996 image_create_info.extent.depth = 1;
14997 image_create_info.mipLevels = 1;
14998 image_create_info.arrayLayers = 1;
14999 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15000 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15001 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
15002 image_create_info.flags = 0;
15003
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015004 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Karl Schultzbdb75952016-04-19 11:36:49 -060015005 ASSERT_VK_SUCCESS(err);
15006
15007 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
15008 // Introduce failure by creating second image with a different-sized format.
15009 image_create_info.format = VK_FORMAT_R5G5B5A1_UNORM_PACK16;
15010
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015011 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Karl Schultzbdb75952016-04-19 11:36:49 -060015012 ASSERT_VK_SUCCESS(err);
15013
15014 // Allocate memory
15015 VkMemoryAllocateInfo memAlloc = {};
15016 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15017 memAlloc.pNext = NULL;
15018 memAlloc.allocationSize = 0;
15019 memAlloc.memoryTypeIndex = 0;
15020
15021 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
15022 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015023 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -060015024 ASSERT_TRUE(pass);
15025 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
15026 ASSERT_VK_SUCCESS(err);
15027
15028 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
15029 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015030 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -060015031 ASSERT_TRUE(pass);
15032 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
15033 ASSERT_VK_SUCCESS(err);
15034
15035 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
15036 ASSERT_VK_SUCCESS(err);
15037 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
15038 ASSERT_VK_SUCCESS(err);
15039
15040 BeginCommandBuffer();
15041 VkImageCopy copyRegion;
15042 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15043 copyRegion.srcSubresource.mipLevel = 0;
15044 copyRegion.srcSubresource.baseArrayLayer = 0;
15045 copyRegion.srcSubresource.layerCount = 0;
15046 copyRegion.srcOffset.x = 0;
15047 copyRegion.srcOffset.y = 0;
15048 copyRegion.srcOffset.z = 0;
15049 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15050 copyRegion.dstSubresource.mipLevel = 0;
15051 copyRegion.dstSubresource.baseArrayLayer = 0;
15052 copyRegion.dstSubresource.layerCount = 0;
15053 copyRegion.dstOffset.x = 0;
15054 copyRegion.dstOffset.y = 0;
15055 copyRegion.dstOffset.z = 0;
15056 copyRegion.extent.width = 1;
15057 copyRegion.extent.height = 1;
15058 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015059 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Karl Schultzbdb75952016-04-19 11:36:49 -060015060 EndCommandBuffer();
15061
15062 m_errorMonitor->VerifyFound();
15063
15064 vkDestroyImage(m_device->device(), srcImage, NULL);
15065 vkDestroyImage(m_device->device(), dstImage, NULL);
15066 vkFreeMemory(m_device->device(), srcMem, NULL);
15067 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060015068}
15069
Karl Schultz6addd812016-02-02 17:17:23 -070015070TEST_F(VkLayerTest, CopyImageDepthStencilFormatMismatch) {
15071 VkResult err;
15072 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060015073
Mark Lobodzinskidb117632016-03-31 10:45:56 -060015074 // Create a color image and a depth/stencil image and try to copy between them
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015075 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15076 "vkCmdCopyImage called with unmatched source and dest image depth");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015077
Mike Stroyana3082432015-09-25 13:39:21 -060015078 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060015079
15080 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070015081 VkImage srcImage;
15082 VkImage dstImage;
15083 VkDeviceMemory srcMem;
15084 VkDeviceMemory destMem;
15085 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060015086
15087 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015088 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15089 image_create_info.pNext = NULL;
15090 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15091 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
15092 image_create_info.extent.width = 32;
15093 image_create_info.extent.height = 32;
15094 image_create_info.extent.depth = 1;
15095 image_create_info.mipLevels = 1;
15096 image_create_info.arrayLayers = 1;
15097 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15098 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15099 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
15100 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015101
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015102 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015103 ASSERT_VK_SUCCESS(err);
15104
Karl Schultzbdb75952016-04-19 11:36:49 -060015105 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
15106
Mark Lobodzinskidb117632016-03-31 10:45:56 -060015107 // Introduce failure by creating second image with a depth/stencil format
Karl Schultz6addd812016-02-02 17:17:23 -070015108 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060015109 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
Mark Lobodzinski867787a2016-10-14 11:49:55 -060015110 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015111
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015112 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015113 ASSERT_VK_SUCCESS(err);
15114
15115 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015116 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015117 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15118 memAlloc.pNext = NULL;
15119 memAlloc.allocationSize = 0;
15120 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015121
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060015122 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015123 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015124 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015125 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015126 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015127 ASSERT_VK_SUCCESS(err);
15128
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015129 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015130 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015131 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015132 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015133 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015134 ASSERT_VK_SUCCESS(err);
15135
15136 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
15137 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015138 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060015139 ASSERT_VK_SUCCESS(err);
15140
15141 BeginCommandBuffer();
15142 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015143 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015144 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060015145 copyRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015146 copyRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015147 copyRegion.srcOffset.x = 0;
15148 copyRegion.srcOffset.y = 0;
15149 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015150 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015151 copyRegion.dstSubresource.mipLevel = 0;
15152 copyRegion.dstSubresource.baseArrayLayer = 0;
15153 copyRegion.dstSubresource.layerCount = 0;
15154 copyRegion.dstOffset.x = 0;
15155 copyRegion.dstOffset.y = 0;
15156 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015157 copyRegion.extent.width = 1;
15158 copyRegion.extent.height = 1;
15159 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015160 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060015161 EndCommandBuffer();
15162
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015163 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060015164
Chia-I Wuf7458c52015-10-26 21:10:41 +080015165 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015166 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080015167 vkFreeMemory(m_device->device(), srcMem, NULL);
15168 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060015169}
15170
Karl Schultz6addd812016-02-02 17:17:23 -070015171TEST_F(VkLayerTest, ResolveImageLowSampleCount) {
15172 VkResult err;
15173 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060015174
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015175 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15176 "vkCmdResolveImage called with source sample count less than 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015177
Mike Stroyana3082432015-09-25 13:39:21 -060015178 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060015179
15180 // Create two images of sample count 1 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070015181 VkImage srcImage;
15182 VkImage dstImage;
15183 VkDeviceMemory srcMem;
15184 VkDeviceMemory destMem;
15185 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060015186
15187 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015188 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15189 image_create_info.pNext = NULL;
15190 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15191 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
15192 image_create_info.extent.width = 32;
15193 image_create_info.extent.height = 1;
15194 image_create_info.extent.depth = 1;
15195 image_create_info.mipLevels = 1;
15196 image_create_info.arrayLayers = 1;
15197 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15198 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15199 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
15200 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015201
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015202 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015203 ASSERT_VK_SUCCESS(err);
15204
Karl Schultz6addd812016-02-02 17:17:23 -070015205 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015206
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015207 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015208 ASSERT_VK_SUCCESS(err);
15209
15210 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015211 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015212 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15213 memAlloc.pNext = NULL;
15214 memAlloc.allocationSize = 0;
15215 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015216
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060015217 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015218 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015219 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015220 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015221 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015222 ASSERT_VK_SUCCESS(err);
15223
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015224 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015225 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015226 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015227 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015228 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015229 ASSERT_VK_SUCCESS(err);
15230
15231 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
15232 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015233 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060015234 ASSERT_VK_SUCCESS(err);
15235
15236 BeginCommandBuffer();
15237 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070015238 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
15239 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060015240 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015241 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015242 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060015243 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130015244 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060015245 resolveRegion.srcOffset.x = 0;
15246 resolveRegion.srcOffset.y = 0;
15247 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015248 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015249 resolveRegion.dstSubresource.mipLevel = 0;
15250 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130015251 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015252 resolveRegion.dstOffset.x = 0;
15253 resolveRegion.dstOffset.y = 0;
15254 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015255 resolveRegion.extent.width = 1;
15256 resolveRegion.extent.height = 1;
15257 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015258 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060015259 EndCommandBuffer();
15260
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015261 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060015262
Chia-I Wuf7458c52015-10-26 21:10:41 +080015263 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015264 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080015265 vkFreeMemory(m_device->device(), srcMem, NULL);
15266 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060015267}
15268
Karl Schultz6addd812016-02-02 17:17:23 -070015269TEST_F(VkLayerTest, ResolveImageHighSampleCount) {
15270 VkResult err;
15271 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060015272
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015273 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15274 "vkCmdResolveImage called with dest sample count greater than 1.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015275
Mike Stroyana3082432015-09-25 13:39:21 -060015276 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060015277
Chris Forbesa7530692016-05-08 12:35:39 +120015278 // Create two images of sample count 4 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070015279 VkImage srcImage;
15280 VkImage dstImage;
15281 VkDeviceMemory srcMem;
15282 VkDeviceMemory destMem;
15283 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060015284
15285 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015286 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15287 image_create_info.pNext = NULL;
15288 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15289 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
15290 image_create_info.extent.width = 32;
15291 image_create_info.extent.height = 1;
15292 image_create_info.extent.depth = 1;
15293 image_create_info.mipLevels = 1;
15294 image_create_info.arrayLayers = 1;
Chris Forbesa7530692016-05-08 12:35:39 +120015295 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070015296 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15297 // Note: Some implementations expect color attachment usage for any
15298 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015299 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070015300 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015301
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015302 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015303 ASSERT_VK_SUCCESS(err);
15304
Karl Schultz6addd812016-02-02 17:17:23 -070015305 // Note: Some implementations expect color attachment usage for any
15306 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015307 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015308
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015309 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015310 ASSERT_VK_SUCCESS(err);
15311
15312 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015313 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015314 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15315 memAlloc.pNext = NULL;
15316 memAlloc.allocationSize = 0;
15317 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015318
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060015319 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015320 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015321 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015322 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015323 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015324 ASSERT_VK_SUCCESS(err);
15325
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015326 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015327 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015328 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015329 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015330 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015331 ASSERT_VK_SUCCESS(err);
15332
15333 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
15334 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015335 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060015336 ASSERT_VK_SUCCESS(err);
15337
15338 BeginCommandBuffer();
15339 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070015340 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
15341 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060015342 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015343 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015344 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060015345 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130015346 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060015347 resolveRegion.srcOffset.x = 0;
15348 resolveRegion.srcOffset.y = 0;
15349 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015350 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015351 resolveRegion.dstSubresource.mipLevel = 0;
15352 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130015353 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015354 resolveRegion.dstOffset.x = 0;
15355 resolveRegion.dstOffset.y = 0;
15356 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015357 resolveRegion.extent.width = 1;
15358 resolveRegion.extent.height = 1;
15359 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015360 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060015361 EndCommandBuffer();
15362
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015363 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060015364
Chia-I Wuf7458c52015-10-26 21:10:41 +080015365 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015366 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080015367 vkFreeMemory(m_device->device(), srcMem, NULL);
15368 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060015369}
15370
Karl Schultz6addd812016-02-02 17:17:23 -070015371TEST_F(VkLayerTest, ResolveImageFormatMismatch) {
15372 VkResult err;
15373 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060015374
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015375 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15376 "vkCmdResolveImage called with unmatched source and dest formats.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015377
Mike Stroyana3082432015-09-25 13:39:21 -060015378 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060015379
15380 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070015381 VkImage srcImage;
15382 VkImage dstImage;
15383 VkDeviceMemory srcMem;
15384 VkDeviceMemory destMem;
15385 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060015386
15387 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015388 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15389 image_create_info.pNext = NULL;
15390 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15391 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
15392 image_create_info.extent.width = 32;
15393 image_create_info.extent.height = 1;
15394 image_create_info.extent.depth = 1;
15395 image_create_info.mipLevels = 1;
15396 image_create_info.arrayLayers = 1;
15397 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
15398 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15399 // Note: Some implementations expect color attachment usage for any
15400 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015401 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070015402 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015403
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015404 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015405 ASSERT_VK_SUCCESS(err);
15406
Karl Schultz6addd812016-02-02 17:17:23 -070015407 // Set format to something other than source image
15408 image_create_info.format = VK_FORMAT_R32_SFLOAT;
15409 // Note: Some implementations expect color attachment usage for any
15410 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015411 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070015412 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015413
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015414 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015415 ASSERT_VK_SUCCESS(err);
15416
15417 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015418 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015419 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15420 memAlloc.pNext = NULL;
15421 memAlloc.allocationSize = 0;
15422 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015423
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060015424 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015425 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015426 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015427 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015428 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015429 ASSERT_VK_SUCCESS(err);
15430
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015431 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015432 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015433 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015434 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015435 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015436 ASSERT_VK_SUCCESS(err);
15437
15438 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
15439 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015440 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060015441 ASSERT_VK_SUCCESS(err);
15442
15443 BeginCommandBuffer();
15444 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070015445 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
15446 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060015447 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015448 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015449 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060015450 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130015451 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060015452 resolveRegion.srcOffset.x = 0;
15453 resolveRegion.srcOffset.y = 0;
15454 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015455 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015456 resolveRegion.dstSubresource.mipLevel = 0;
15457 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130015458 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015459 resolveRegion.dstOffset.x = 0;
15460 resolveRegion.dstOffset.y = 0;
15461 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015462 resolveRegion.extent.width = 1;
15463 resolveRegion.extent.height = 1;
15464 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015465 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060015466 EndCommandBuffer();
15467
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015468 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060015469
Chia-I Wuf7458c52015-10-26 21:10:41 +080015470 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015471 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080015472 vkFreeMemory(m_device->device(), srcMem, NULL);
15473 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060015474}
15475
Karl Schultz6addd812016-02-02 17:17:23 -070015476TEST_F(VkLayerTest, ResolveImageTypeMismatch) {
15477 VkResult err;
15478 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060015479
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015480 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15481 "vkCmdResolveImage called with unmatched source and dest image types.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015482
Mike Stroyana3082432015-09-25 13:39:21 -060015483 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060015484
15485 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070015486 VkImage srcImage;
15487 VkImage dstImage;
15488 VkDeviceMemory srcMem;
15489 VkDeviceMemory destMem;
15490 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060015491
15492 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015493 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15494 image_create_info.pNext = NULL;
15495 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15496 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
15497 image_create_info.extent.width = 32;
15498 image_create_info.extent.height = 1;
15499 image_create_info.extent.depth = 1;
15500 image_create_info.mipLevels = 1;
15501 image_create_info.arrayLayers = 1;
15502 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
15503 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15504 // Note: Some implementations expect color attachment usage for any
15505 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015506 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070015507 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015508
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015509 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015510 ASSERT_VK_SUCCESS(err);
15511
Karl Schultz6addd812016-02-02 17:17:23 -070015512 image_create_info.imageType = VK_IMAGE_TYPE_1D;
15513 // Note: Some implementations expect color attachment usage for any
15514 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015515 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070015516 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015517
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015518 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015519 ASSERT_VK_SUCCESS(err);
15520
15521 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015522 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015523 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15524 memAlloc.pNext = NULL;
15525 memAlloc.allocationSize = 0;
15526 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015527
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060015528 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015529 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015530 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015531 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015532 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015533 ASSERT_VK_SUCCESS(err);
15534
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015535 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015536 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015537 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015538 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015539 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015540 ASSERT_VK_SUCCESS(err);
15541
15542 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
15543 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015544 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060015545 ASSERT_VK_SUCCESS(err);
15546
15547 BeginCommandBuffer();
15548 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070015549 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
15550 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060015551 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015552 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015553 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060015554 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130015555 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060015556 resolveRegion.srcOffset.x = 0;
15557 resolveRegion.srcOffset.y = 0;
15558 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015559 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015560 resolveRegion.dstSubresource.mipLevel = 0;
15561 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130015562 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015563 resolveRegion.dstOffset.x = 0;
15564 resolveRegion.dstOffset.y = 0;
15565 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015566 resolveRegion.extent.width = 1;
15567 resolveRegion.extent.height = 1;
15568 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015569 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060015570 EndCommandBuffer();
15571
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015572 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060015573
Chia-I Wuf7458c52015-10-26 21:10:41 +080015574 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015575 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080015576 vkFreeMemory(m_device->device(), srcMem, NULL);
15577 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060015578}
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015579
Karl Schultz6addd812016-02-02 17:17:23 -070015580TEST_F(VkLayerTest, DepthStencilImageViewWithColorAspectBitError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015581 // Create a single Image descriptor and cause it to first hit an error due
Karl Schultz6addd812016-02-02 17:17:23 -070015582 // to using a DS format, then cause it to hit error due to COLOR_BIT not
15583 // set in aspect
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015584 // The image format check comes 2nd in validation so we trigger it first,
15585 // then when we cause aspect fail next, bad format check will be preempted
Karl Schultz6addd812016-02-02 17:17:23 -070015586 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015587
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015588 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15589 "Combination depth/stencil image formats can have only the ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015590
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015591 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015592
Chia-I Wu1b99bb22015-10-27 19:25:11 +080015593 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015594 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
15595 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015596
15597 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015598 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
15599 ds_pool_ci.pNext = NULL;
15600 ds_pool_ci.maxSets = 1;
15601 ds_pool_ci.poolSizeCount = 1;
15602 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015603
15604 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015605 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015606 ASSERT_VK_SUCCESS(err);
15607
15608 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015609 dsl_binding.binding = 0;
15610 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
15611 dsl_binding.descriptorCount = 1;
15612 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
15613 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015614
15615 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015616 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
15617 ds_layout_ci.pNext = NULL;
15618 ds_layout_ci.bindingCount = 1;
15619 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015620 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015621 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015622 ASSERT_VK_SUCCESS(err);
15623
15624 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015625 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080015626 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070015627 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015628 alloc_info.descriptorPool = ds_pool;
15629 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015630 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015631 ASSERT_VK_SUCCESS(err);
15632
Karl Schultz6addd812016-02-02 17:17:23 -070015633 VkImage image_bad;
15634 VkImage image_good;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015635 // One bad format and one good format for Color attachment
Tobin Ehlis269f0322016-05-25 16:24:21 -060015636 const VkFormat tex_format_bad = VK_FORMAT_D24_UNORM_S8_UINT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015637 const VkFormat tex_format_good = VK_FORMAT_B8G8R8A8_UNORM;
Karl Schultz6addd812016-02-02 17:17:23 -070015638 const int32_t tex_width = 32;
15639 const int32_t tex_height = 32;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015640
15641 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015642 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15643 image_create_info.pNext = NULL;
15644 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15645 image_create_info.format = tex_format_bad;
15646 image_create_info.extent.width = tex_width;
15647 image_create_info.extent.height = tex_height;
15648 image_create_info.extent.depth = 1;
15649 image_create_info.mipLevels = 1;
15650 image_create_info.arrayLayers = 1;
15651 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15652 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015653 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070015654 image_create_info.flags = 0;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015655
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015656 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_bad);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015657 ASSERT_VK_SUCCESS(err);
15658 image_create_info.format = tex_format_good;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015659 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
15660 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_good);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015661 ASSERT_VK_SUCCESS(err);
15662
Rene Lindsayf1e89c82016-12-28 13:18:31 -070015663 // ---Bind image memory---
15664 VkMemoryRequirements img_mem_reqs;
15665 vkGetImageMemoryRequirements(m_device->device(), image_bad, &img_mem_reqs);
15666 VkMemoryAllocateInfo image_alloc_info = {};
15667 image_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15668 image_alloc_info.pNext = NULL;
15669 image_alloc_info.memoryTypeIndex = 0;
15670 image_alloc_info.allocationSize = img_mem_reqs.size;
15671 bool pass = m_device->phy().set_memory_type(img_mem_reqs.memoryTypeBits, &image_alloc_info, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
15672 ASSERT_TRUE(pass);
15673 VkDeviceMemory mem;
15674 err = vkAllocateMemory(m_device->device(), &image_alloc_info, NULL, &mem);
15675 ASSERT_VK_SUCCESS(err);
15676 err = vkBindImageMemory(m_device->device(), image_bad, mem, 0);
15677 ASSERT_VK_SUCCESS(err);
15678 // -----------------------
15679
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015680 VkImageViewCreateInfo image_view_create_info = {};
Chris Forbes53bef902016-11-28 17:53:04 +130015681 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070015682 image_view_create_info.image = image_bad;
15683 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
15684 image_view_create_info.format = tex_format_bad;
15685 image_view_create_info.subresourceRange.baseArrayLayer = 0;
15686 image_view_create_info.subresourceRange.baseMipLevel = 0;
15687 image_view_create_info.subresourceRange.layerCount = 1;
15688 image_view_create_info.subresourceRange.levelCount = 1;
Rene Lindsayf1e89c82016-12-28 13:18:31 -070015689 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_DEPTH_BIT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015690
15691 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015692 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015693
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015694 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015695
Chia-I Wuf7458c52015-10-26 21:10:41 +080015696 vkDestroyImage(m_device->device(), image_bad, NULL);
15697 vkDestroyImage(m_device->device(), image_good, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080015698 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
15699 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Rene Lindsayf1e89c82016-12-28 13:18:31 -070015700
15701 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015702}
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015703
15704TEST_F(VkLayerTest, ClearImageErrors) {
15705 TEST_DESCRIPTION("Call ClearColorImage w/ a depth|stencil image and "
15706 "ClearDepthStencilImage with a color image.");
15707
15708 ASSERT_NO_FATAL_FAILURE(InitState());
15709 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15710
15711 // Renderpass is started here so end it as Clear cmds can't be in renderpass
15712 BeginCommandBuffer();
15713 m_commandBuffer->EndRenderPass();
15714
15715 // Color image
15716 VkClearColorValue clear_color;
15717 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
15718 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
15719 const VkFormat color_format = VK_FORMAT_B8G8R8A8_UNORM;
15720 const int32_t img_width = 32;
15721 const int32_t img_height = 32;
15722 VkImageCreateInfo image_create_info = {};
15723 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15724 image_create_info.pNext = NULL;
15725 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15726 image_create_info.format = color_format;
15727 image_create_info.extent.width = img_width;
15728 image_create_info.extent.height = img_height;
15729 image_create_info.extent.depth = 1;
15730 image_create_info.mipLevels = 1;
15731 image_create_info.arrayLayers = 1;
15732 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15733 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15734 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
15735
15736 vk_testing::Image color_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015737 color_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015738
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015739 const VkImageSubresourceRange color_range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015740
15741 // Depth/Stencil image
15742 VkClearDepthStencilValue clear_value = {0};
15743 reqs = 0; // don't need HOST_VISIBLE DS image
15744 VkImageCreateInfo ds_image_create_info = vk_testing::Image::create_info();
15745 ds_image_create_info.imageType = VK_IMAGE_TYPE_2D;
15746 ds_image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
15747 ds_image_create_info.extent.width = 64;
15748 ds_image_create_info.extent.height = 64;
15749 ds_image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Rene Lindsaya1fc64a2016-12-27 15:18:54 -070015750 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 -060015751
15752 vk_testing::Image ds_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015753 ds_image.init(*m_device, (const VkImageCreateInfo &)ds_image_create_info, reqs);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015754
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015755 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 -060015756
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015757 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdClearColorImage called with depth/stencil image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015758
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015759 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), ds_image.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015760 &color_range);
15761
15762 m_errorMonitor->VerifyFound();
15763
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015764 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdClearColorImage called with "
15765 "image created without "
15766 "VK_IMAGE_USAGE_TRANSFER_DST_BIT");
Tony Barbour26434b92016-06-02 09:43:50 -060015767
Rene Lindsaya1fc64a2016-12-27 15:18:54 -070015768 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), color_image.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
Tony Barbour26434b92016-06-02 09:43:50 -060015769 &color_range);
15770
15771 m_errorMonitor->VerifyFound();
15772
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015773 // Call CmdClearDepthStencilImage with color image
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015774 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15775 "vkCmdClearDepthStencilImage called without a depth/stencil image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015776
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015777 vkCmdClearDepthStencilImage(m_commandBuffer->GetBufferHandle(), color_image.handle(),
Rene Lindsaya1fc64a2016-12-27 15:18:54 -070015778 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, &clear_value, 1, &ds_range);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015779
15780 m_errorMonitor->VerifyFound();
15781}
Tobin Ehliscde08892015-09-22 10:11:37 -060015782#endif // IMAGE_TESTS
15783
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060015784
15785// WSI Enabled Tests
15786//
Chris Forbes09368e42016-10-13 11:59:22 +130015787#if 0
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060015788TEST_F(VkWsiEnabledLayerTest, TestEnabledWsi) {
15789
15790#if defined(VK_USE_PLATFORM_XCB_KHR)
15791 VkSurfaceKHR surface = VK_NULL_HANDLE;
15792
15793 VkResult err;
15794 bool pass;
15795 VkSwapchainKHR swapchain = VK_NULL_HANDLE;
15796 VkSwapchainCreateInfoKHR swapchain_create_info = {};
15797 // uint32_t swapchain_image_count = 0;
15798 // VkImage swapchain_images[1] = {VK_NULL_HANDLE};
15799 // uint32_t image_index = 0;
15800 // VkPresentInfoKHR present_info = {};
15801
15802 ASSERT_NO_FATAL_FAILURE(InitState());
15803
15804 // Use the create function from one of the VK_KHR_*_surface extension in
15805 // order to create a surface, testing all known errors in the process,
15806 // before successfully creating a surface:
15807 // First, try to create a surface without a VkXcbSurfaceCreateInfoKHR:
15808 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pCreateInfo specified as NULL");
15809 err = vkCreateXcbSurfaceKHR(instance(), NULL, NULL, &surface);
15810 pass = (err != VK_SUCCESS);
15811 ASSERT_TRUE(pass);
15812 m_errorMonitor->VerifyFound();
15813
15814 // Next, try to create a surface with the wrong
15815 // VkXcbSurfaceCreateInfoKHR::sType:
15816 VkXcbSurfaceCreateInfoKHR xcb_create_info = {};
15817 xcb_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
15818 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pCreateInfo->sType must be");
15819 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
15820 pass = (err != VK_SUCCESS);
15821 ASSERT_TRUE(pass);
15822 m_errorMonitor->VerifyFound();
15823
15824 // Create a native window, and then correctly create a surface:
15825 xcb_connection_t *connection;
15826 xcb_screen_t *screen;
15827 xcb_window_t xcb_window;
15828 xcb_intern_atom_reply_t *atom_wm_delete_window;
15829
15830 const xcb_setup_t *setup;
15831 xcb_screen_iterator_t iter;
15832 int scr;
15833 uint32_t value_mask, value_list[32];
15834 int width = 1;
15835 int height = 1;
15836
15837 connection = xcb_connect(NULL, &scr);
15838 ASSERT_TRUE(connection != NULL);
15839 setup = xcb_get_setup(connection);
15840 iter = xcb_setup_roots_iterator(setup);
15841 while (scr-- > 0)
15842 xcb_screen_next(&iter);
15843 screen = iter.data;
15844
15845 xcb_window = xcb_generate_id(connection);
15846
15847 value_mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK;
15848 value_list[0] = screen->black_pixel;
15849 value_list[1] = XCB_EVENT_MASK_KEY_RELEASE | XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_STRUCTURE_NOTIFY;
15850
15851 xcb_create_window(connection, XCB_COPY_FROM_PARENT, xcb_window, screen->root, 0, 0, width, height, 0,
15852 XCB_WINDOW_CLASS_INPUT_OUTPUT, screen->root_visual, value_mask, value_list);
15853
15854 /* Magic code that will send notification when window is destroyed */
15855 xcb_intern_atom_cookie_t cookie = xcb_intern_atom(connection, 1, 12, "WM_PROTOCOLS");
15856 xcb_intern_atom_reply_t *reply = xcb_intern_atom_reply(connection, cookie, 0);
15857
15858 xcb_intern_atom_cookie_t cookie2 = xcb_intern_atom(connection, 0, 16, "WM_DELETE_WINDOW");
15859 atom_wm_delete_window = xcb_intern_atom_reply(connection, cookie2, 0);
15860 xcb_change_property(connection, XCB_PROP_MODE_REPLACE, xcb_window, (*reply).atom, 4, 32, 1, &(*atom_wm_delete_window).atom);
15861 free(reply);
15862
15863 xcb_map_window(connection, xcb_window);
15864
15865 // Force the x/y coordinates to 100,100 results are identical in consecutive
15866 // runs
15867 const uint32_t coords[] = { 100, 100 };
15868 xcb_configure_window(connection, xcb_window, XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y, coords);
15869
15870 // Finally, try to correctly create a surface:
15871 xcb_create_info.sType = VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR;
15872 xcb_create_info.pNext = NULL;
15873 xcb_create_info.flags = 0;
15874 xcb_create_info.connection = connection;
15875 xcb_create_info.window = xcb_window;
15876 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
15877 pass = (err == VK_SUCCESS);
15878 ASSERT_TRUE(pass);
15879
15880 // Check if surface supports presentation:
15881
15882 // 1st, do so without having queried the queue families:
15883 VkBool32 supported = false;
15884 // TODO: Get the following error to come out:
15885 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15886 "called before calling the vkGetPhysicalDeviceQueueFamilyProperties "
15887 "function");
15888 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
15889 pass = (err != VK_SUCCESS);
15890 // ASSERT_TRUE(pass);
15891 // m_errorMonitor->VerifyFound();
15892
15893 // Next, query a queue family index that's too large:
15894 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with a queueFamilyIndex that is too large");
15895 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 100000, surface, &supported);
15896 pass = (err != VK_SUCCESS);
15897 ASSERT_TRUE(pass);
15898 m_errorMonitor->VerifyFound();
15899
15900 // Finally, do so correctly:
15901 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
15902 // SUPPORTED
15903 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
15904 pass = (err == VK_SUCCESS);
15905 ASSERT_TRUE(pass);
15906
15907 // Before proceeding, try to create a swapchain without having called
15908 // vkGetPhysicalDeviceSurfaceCapabilitiesKHR():
15909 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
15910 swapchain_create_info.pNext = NULL;
15911 swapchain_create_info.flags = 0;
15912 swapchain_create_info.imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
15913 swapchain_create_info.surface = surface;
15914 swapchain_create_info.imageArrayLayers = 1;
15915 swapchain_create_info.preTransform = VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR;
15916 swapchain_create_info.compositeAlpha = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR;
15917 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15918 "called before calling vkGetPhysicalDeviceSurfaceCapabilitiesKHR().");
15919 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
15920 pass = (err != VK_SUCCESS);
15921 ASSERT_TRUE(pass);
15922 m_errorMonitor->VerifyFound();
15923
15924 // Get the surface capabilities:
15925 VkSurfaceCapabilitiesKHR surface_capabilities;
15926
15927 // Do so correctly (only error logged by this entrypoint is if the
15928 // extension isn't enabled):
15929 err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), surface, &surface_capabilities);
15930 pass = (err == VK_SUCCESS);
15931 ASSERT_TRUE(pass);
15932
15933 // Get the surface formats:
15934 uint32_t surface_format_count;
15935
15936 // First, try without a pointer to surface_format_count:
15937 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pSurfaceFormatCount "
15938 "specified as NULL");
15939 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, NULL, NULL);
15940 pass = (err == VK_SUCCESS);
15941 ASSERT_TRUE(pass);
15942 m_errorMonitor->VerifyFound();
15943
15944 // Next, call with a non-NULL pSurfaceFormats, even though we haven't
15945 // correctly done a 1st try (to get the count):
15946 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "but no prior positive value has been seen for");
15947 surface_format_count = 0;
15948 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, (VkSurfaceFormatKHR *)&surface_format_count);
15949 pass = (err == VK_SUCCESS);
15950 ASSERT_TRUE(pass);
15951 m_errorMonitor->VerifyFound();
15952
15953 // Next, correctly do a 1st try (with a NULL pointer to surface_formats):
15954 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, NULL);
15955 pass = (err == VK_SUCCESS);
15956 ASSERT_TRUE(pass);
15957
15958 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
15959 VkSurfaceFormatKHR *surface_formats = (VkSurfaceFormatKHR *)malloc(surface_format_count * sizeof(VkSurfaceFormatKHR));
15960
15961 // Next, do a 2nd try with surface_format_count being set too high:
15962 surface_format_count += 5;
15963 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is greater than the value");
15964 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, surface_formats);
15965 pass = (err == VK_SUCCESS);
15966 ASSERT_TRUE(pass);
15967 m_errorMonitor->VerifyFound();
15968
15969 // Finally, do a correct 1st and 2nd try:
15970 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, NULL);
15971 pass = (err == VK_SUCCESS);
15972 ASSERT_TRUE(pass);
15973 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, surface_formats);
15974 pass = (err == VK_SUCCESS);
15975 ASSERT_TRUE(pass);
15976
15977 // Get the surface present modes:
15978 uint32_t surface_present_mode_count;
15979
15980 // First, try without a pointer to surface_format_count:
15981 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pPresentModeCount "
15982 "specified as NULL");
15983
15984 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, NULL, NULL);
15985 pass = (err == VK_SUCCESS);
15986 ASSERT_TRUE(pass);
15987 m_errorMonitor->VerifyFound();
15988
15989 // Next, call with a non-NULL VkPresentModeKHR, even though we haven't
15990 // correctly done a 1st try (to get the count):
15991 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "but no prior positive value has been seen for");
15992 surface_present_mode_count = 0;
15993 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count,
15994 (VkPresentModeKHR *)&surface_present_mode_count);
15995 pass = (err == VK_SUCCESS);
15996 ASSERT_TRUE(pass);
15997 m_errorMonitor->VerifyFound();
15998
15999 // Next, correctly do a 1st try (with a NULL pointer to surface_formats):
16000 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, NULL);
16001 pass = (err == VK_SUCCESS);
16002 ASSERT_TRUE(pass);
16003
16004 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
16005 VkPresentModeKHR *surface_present_modes = (VkPresentModeKHR *)malloc(surface_present_mode_count * sizeof(VkPresentModeKHR));
16006
16007 // Next, do a 2nd try with surface_format_count being set too high:
16008 surface_present_mode_count += 5;
16009 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is greater than the value");
16010 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, surface_present_modes);
16011 pass = (err == VK_SUCCESS);
16012 ASSERT_TRUE(pass);
16013 m_errorMonitor->VerifyFound();
16014
16015 // Finally, do a correct 1st and 2nd try:
16016 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, NULL);
16017 pass = (err == VK_SUCCESS);
16018 ASSERT_TRUE(pass);
16019 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, surface_present_modes);
16020 pass = (err == VK_SUCCESS);
16021 ASSERT_TRUE(pass);
16022
16023 // Create a swapchain:
16024
16025 // First, try without a pointer to swapchain_create_info:
16026 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pCreateInfo "
16027 "specified as NULL");
16028
16029 err = vkCreateSwapchainKHR(m_device->device(), NULL, NULL, &swapchain);
16030 pass = (err != VK_SUCCESS);
16031 ASSERT_TRUE(pass);
16032 m_errorMonitor->VerifyFound();
16033
16034 // Next, call with a non-NULL swapchain_create_info, that has the wrong
16035 // sType:
16036 swapchain_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
16037 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pCreateInfo->sType must be");
16038
16039 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
16040 pass = (err != VK_SUCCESS);
16041 ASSERT_TRUE(pass);
16042 m_errorMonitor->VerifyFound();
16043
16044 // Next, call with a NULL swapchain pointer:
16045 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
16046 swapchain_create_info.pNext = NULL;
16047 swapchain_create_info.flags = 0;
16048 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pSwapchain "
16049 "specified as NULL");
16050
16051 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, NULL);
16052 pass = (err != VK_SUCCESS);
16053 ASSERT_TRUE(pass);
16054 m_errorMonitor->VerifyFound();
16055
16056 // TODO: Enhance swapchain layer so that
16057 // swapchain_create_info.queueFamilyIndexCount is checked against something?
16058
16059 // Next, call with a queue family index that's too large:
16060 uint32_t queueFamilyIndex[2] = { 100000, 0 };
16061 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
16062 swapchain_create_info.queueFamilyIndexCount = 2;
16063 swapchain_create_info.pQueueFamilyIndices = queueFamilyIndex;
16064 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with a queueFamilyIndex that is too large");
16065 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
16066 pass = (err != VK_SUCCESS);
16067 ASSERT_TRUE(pass);
16068 m_errorMonitor->VerifyFound();
16069
16070 // Next, call a queueFamilyIndexCount that's too small for CONCURRENT:
16071 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
16072 swapchain_create_info.queueFamilyIndexCount = 1;
16073 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16074 "but with a bad value(s) for pCreateInfo->queueFamilyIndexCount or "
16075 "pCreateInfo->pQueueFamilyIndices).");
16076 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
16077 pass = (err != VK_SUCCESS);
16078 ASSERT_TRUE(pass);
16079 m_errorMonitor->VerifyFound();
16080
16081 // Next, call with an invalid imageSharingMode:
16082 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_MAX_ENUM;
16083 swapchain_create_info.queueFamilyIndexCount = 1;
16084 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16085 "called with a non-supported pCreateInfo->imageSharingMode (i.e.");
16086 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
16087 pass = (err != VK_SUCCESS);
16088 ASSERT_TRUE(pass);
16089 m_errorMonitor->VerifyFound();
16090 // Fix for the future:
16091 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
16092 // SUPPORTED
16093 swapchain_create_info.queueFamilyIndexCount = 0;
16094 queueFamilyIndex[0] = 0;
16095 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE;
16096
16097 // TODO: CONTINUE TESTING VALIDATION OF vkCreateSwapchainKHR() ...
16098 // Get the images from a swapchain:
16099 // Acquire an image from a swapchain:
16100 // Present an image to a swapchain:
16101 // Destroy the swapchain:
16102
16103 // TODOs:
16104 //
16105 // - Try destroying the device without first destroying the swapchain
16106 //
16107 // - Try destroying the device without first destroying the surface
16108 //
16109 // - Try destroying the surface without first destroying the swapchain
16110
16111 // Destroy the surface:
16112 vkDestroySurfaceKHR(instance(), surface, NULL);
16113
16114 // Tear down the window:
16115 xcb_destroy_window(connection, xcb_window);
16116 xcb_disconnect(connection);
16117
16118#else // VK_USE_PLATFORM_XCB_KHR
16119 return;
16120#endif // VK_USE_PLATFORM_XCB_KHR
16121}
Chris Forbes09368e42016-10-13 11:59:22 +130016122#endif
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016123
16124//
16125// POSITIVE VALIDATION TESTS
16126//
16127// These tests do not expect to encounter ANY validation errors pass only if this is true
16128
Tobin Ehlise0006882016-11-03 10:14:28 -060016129TEST_F(VkPositiveLayerTest, SecondaryCommandBufferImageLayoutTransitions) {
16130 TEST_DESCRIPTION("Perform an image layout transition in a secondary command buffer followed "
16131 "by a transition in the primary.");
16132 VkResult err;
16133 m_errorMonitor->ExpectSuccess();
16134 ASSERT_NO_FATAL_FAILURE(InitState());
16135 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
16136 // Allocate a secondary and primary cmd buffer
16137 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
16138 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
16139 command_buffer_allocate_info.commandPool = m_commandPool;
16140 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
16141 command_buffer_allocate_info.commandBufferCount = 1;
16142
16143 VkCommandBuffer secondary_command_buffer;
16144 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer));
16145 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
16146 VkCommandBuffer primary_command_buffer;
16147 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &primary_command_buffer));
16148 VkCommandBufferBeginInfo command_buffer_begin_info = {};
16149 VkCommandBufferInheritanceInfo command_buffer_inheritance_info = {};
16150 command_buffer_inheritance_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
16151 command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
16152 command_buffer_begin_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
16153 command_buffer_begin_info.pInheritanceInfo = &command_buffer_inheritance_info;
16154
16155 err = vkBeginCommandBuffer(secondary_command_buffer, &command_buffer_begin_info);
16156 ASSERT_VK_SUCCESS(err);
16157 VkImageObj image(m_device);
16158 image.init(128, 128, VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
16159 ASSERT_TRUE(image.initialized());
16160 VkImageMemoryBarrier img_barrier = {};
16161 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
16162 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
16163 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
16164 img_barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
16165 img_barrier.newLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
16166 img_barrier.image = image.handle();
16167 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
16168 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
16169 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
16170 img_barrier.subresourceRange.baseArrayLayer = 0;
16171 img_barrier.subresourceRange.baseMipLevel = 0;
16172 img_barrier.subresourceRange.layerCount = 1;
16173 img_barrier.subresourceRange.levelCount = 1;
16174 vkCmdPipelineBarrier(secondary_command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr,
16175 0, nullptr, 1, &img_barrier);
16176 err = vkEndCommandBuffer(secondary_command_buffer);
16177 ASSERT_VK_SUCCESS(err);
16178
16179 // Now update primary cmd buffer to execute secondary and transitions image
16180 command_buffer_begin_info.pInheritanceInfo = nullptr;
16181 err = vkBeginCommandBuffer(primary_command_buffer, &command_buffer_begin_info);
16182 ASSERT_VK_SUCCESS(err);
16183 vkCmdExecuteCommands(primary_command_buffer, 1, &secondary_command_buffer);
16184 VkImageMemoryBarrier img_barrier2 = {};
16185 img_barrier2.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
16186 img_barrier2.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
16187 img_barrier2.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
16188 img_barrier2.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
16189 img_barrier2.newLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
16190 img_barrier2.image = image.handle();
16191 img_barrier2.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
16192 img_barrier2.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
16193 img_barrier2.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
16194 img_barrier2.subresourceRange.baseArrayLayer = 0;
16195 img_barrier2.subresourceRange.baseMipLevel = 0;
16196 img_barrier2.subresourceRange.layerCount = 1;
16197 img_barrier2.subresourceRange.levelCount = 1;
16198 vkCmdPipelineBarrier(primary_command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0,
16199 nullptr, 1, &img_barrier2);
16200 err = vkEndCommandBuffer(primary_command_buffer);
16201 ASSERT_VK_SUCCESS(err);
16202 VkSubmitInfo submit_info = {};
16203 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
16204 submit_info.commandBufferCount = 1;
16205 submit_info.pCommandBuffers = &primary_command_buffer;
16206 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
16207 ASSERT_VK_SUCCESS(err);
16208 m_errorMonitor->VerifyNotFound();
16209 err = vkDeviceWaitIdle(m_device->device());
16210 ASSERT_VK_SUCCESS(err);
16211 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &secondary_command_buffer);
16212 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &primary_command_buffer);
16213}
16214
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016215// This is a positive test. No failures are expected.
16216TEST_F(VkPositiveLayerTest, IgnoreUnrelatedDescriptor) {
16217 TEST_DESCRIPTION("Ensure that the vkUpdateDescriptorSets validation code "
16218 "is ignoring VkWriteDescriptorSet members that are not "
16219 "related to the descriptor type specified by "
16220 "VkWriteDescriptorSet::descriptorType. Correct "
16221 "validation behavior will result in the test running to "
16222 "completion without validation errors.");
16223
16224 const uintptr_t invalid_ptr = 0xcdcdcdcd;
16225
16226 ASSERT_NO_FATAL_FAILURE(InitState());
16227
16228 // Image Case
16229 {
16230 m_errorMonitor->ExpectSuccess();
16231
16232 VkImage image;
16233 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
16234 const int32_t tex_width = 32;
16235 const int32_t tex_height = 32;
16236 VkImageCreateInfo image_create_info = {};
16237 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16238 image_create_info.pNext = NULL;
16239 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16240 image_create_info.format = tex_format;
16241 image_create_info.extent.width = tex_width;
16242 image_create_info.extent.height = tex_height;
16243 image_create_info.extent.depth = 1;
16244 image_create_info.mipLevels = 1;
16245 image_create_info.arrayLayers = 1;
16246 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16247 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
16248 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
16249 image_create_info.flags = 0;
16250 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
16251 ASSERT_VK_SUCCESS(err);
16252
16253 VkMemoryRequirements memory_reqs;
16254 VkDeviceMemory image_memory;
16255 bool pass;
16256 VkMemoryAllocateInfo memory_info = {};
16257 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16258 memory_info.pNext = NULL;
16259 memory_info.allocationSize = 0;
16260 memory_info.memoryTypeIndex = 0;
16261 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
16262 memory_info.allocationSize = memory_reqs.size;
16263 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
16264 ASSERT_TRUE(pass);
16265 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
16266 ASSERT_VK_SUCCESS(err);
16267 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
16268 ASSERT_VK_SUCCESS(err);
16269
16270 VkImageViewCreateInfo image_view_create_info = {};
16271 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
16272 image_view_create_info.image = image;
16273 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
16274 image_view_create_info.format = tex_format;
16275 image_view_create_info.subresourceRange.layerCount = 1;
16276 image_view_create_info.subresourceRange.baseMipLevel = 0;
16277 image_view_create_info.subresourceRange.levelCount = 1;
16278 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16279
16280 VkImageView view;
16281 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
16282 ASSERT_VK_SUCCESS(err);
16283
16284 VkDescriptorPoolSize ds_type_count = {};
16285 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
16286 ds_type_count.descriptorCount = 1;
16287
16288 VkDescriptorPoolCreateInfo ds_pool_ci = {};
16289 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
16290 ds_pool_ci.pNext = NULL;
16291 ds_pool_ci.maxSets = 1;
16292 ds_pool_ci.poolSizeCount = 1;
16293 ds_pool_ci.pPoolSizes = &ds_type_count;
16294
16295 VkDescriptorPool ds_pool;
16296 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
16297 ASSERT_VK_SUCCESS(err);
16298
16299 VkDescriptorSetLayoutBinding dsl_binding = {};
16300 dsl_binding.binding = 0;
16301 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
16302 dsl_binding.descriptorCount = 1;
16303 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
16304 dsl_binding.pImmutableSamplers = NULL;
16305
16306 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
16307 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
16308 ds_layout_ci.pNext = NULL;
16309 ds_layout_ci.bindingCount = 1;
16310 ds_layout_ci.pBindings = &dsl_binding;
16311 VkDescriptorSetLayout ds_layout;
16312 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
16313 ASSERT_VK_SUCCESS(err);
16314
16315 VkDescriptorSet descriptor_set;
16316 VkDescriptorSetAllocateInfo alloc_info = {};
16317 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
16318 alloc_info.descriptorSetCount = 1;
16319 alloc_info.descriptorPool = ds_pool;
16320 alloc_info.pSetLayouts = &ds_layout;
16321 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
16322 ASSERT_VK_SUCCESS(err);
16323
16324 VkDescriptorImageInfo image_info = {};
16325 image_info.imageView = view;
16326 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
16327
16328 VkWriteDescriptorSet descriptor_write;
16329 memset(&descriptor_write, 0, sizeof(descriptor_write));
16330 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
16331 descriptor_write.dstSet = descriptor_set;
16332 descriptor_write.dstBinding = 0;
16333 descriptor_write.descriptorCount = 1;
16334 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
16335 descriptor_write.pImageInfo = &image_info;
16336
16337 // Set pBufferInfo and pTexelBufferView to invalid values, which should
16338 // be
16339 // ignored for descriptorType == VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE.
16340 // This will most likely produce a crash if the parameter_validation
16341 // layer
16342 // does not correctly ignore pBufferInfo.
16343 descriptor_write.pBufferInfo = reinterpret_cast<const VkDescriptorBufferInfo *>(invalid_ptr);
16344 descriptor_write.pTexelBufferView = reinterpret_cast<const VkBufferView *>(invalid_ptr);
16345
16346 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
16347
16348 m_errorMonitor->VerifyNotFound();
16349
16350 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
16351 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
16352 vkDestroyImageView(m_device->device(), view, NULL);
16353 vkDestroyImage(m_device->device(), image, NULL);
16354 vkFreeMemory(m_device->device(), image_memory, NULL);
16355 }
16356
16357 // Buffer Case
16358 {
16359 m_errorMonitor->ExpectSuccess();
16360
16361 VkBuffer buffer;
16362 uint32_t queue_family_index = 0;
16363 VkBufferCreateInfo buffer_create_info = {};
16364 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
16365 buffer_create_info.size = 1024;
16366 buffer_create_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
16367 buffer_create_info.queueFamilyIndexCount = 1;
16368 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
16369
16370 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
16371 ASSERT_VK_SUCCESS(err);
16372
16373 VkMemoryRequirements memory_reqs;
16374 VkDeviceMemory buffer_memory;
16375 bool pass;
16376 VkMemoryAllocateInfo memory_info = {};
16377 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16378 memory_info.pNext = NULL;
16379 memory_info.allocationSize = 0;
16380 memory_info.memoryTypeIndex = 0;
16381
16382 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
16383 memory_info.allocationSize = memory_reqs.size;
16384 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
16385 ASSERT_TRUE(pass);
16386
16387 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
16388 ASSERT_VK_SUCCESS(err);
16389 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
16390 ASSERT_VK_SUCCESS(err);
16391
16392 VkDescriptorPoolSize ds_type_count = {};
16393 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16394 ds_type_count.descriptorCount = 1;
16395
16396 VkDescriptorPoolCreateInfo ds_pool_ci = {};
16397 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
16398 ds_pool_ci.pNext = NULL;
16399 ds_pool_ci.maxSets = 1;
16400 ds_pool_ci.poolSizeCount = 1;
16401 ds_pool_ci.pPoolSizes = &ds_type_count;
16402
16403 VkDescriptorPool ds_pool;
16404 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
16405 ASSERT_VK_SUCCESS(err);
16406
16407 VkDescriptorSetLayoutBinding dsl_binding = {};
16408 dsl_binding.binding = 0;
16409 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16410 dsl_binding.descriptorCount = 1;
16411 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
16412 dsl_binding.pImmutableSamplers = NULL;
16413
16414 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
16415 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
16416 ds_layout_ci.pNext = NULL;
16417 ds_layout_ci.bindingCount = 1;
16418 ds_layout_ci.pBindings = &dsl_binding;
16419 VkDescriptorSetLayout ds_layout;
16420 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
16421 ASSERT_VK_SUCCESS(err);
16422
16423 VkDescriptorSet descriptor_set;
16424 VkDescriptorSetAllocateInfo alloc_info = {};
16425 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
16426 alloc_info.descriptorSetCount = 1;
16427 alloc_info.descriptorPool = ds_pool;
16428 alloc_info.pSetLayouts = &ds_layout;
16429 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
16430 ASSERT_VK_SUCCESS(err);
16431
16432 VkDescriptorBufferInfo buffer_info = {};
16433 buffer_info.buffer = buffer;
16434 buffer_info.offset = 0;
16435 buffer_info.range = 1024;
16436
16437 VkWriteDescriptorSet descriptor_write;
16438 memset(&descriptor_write, 0, sizeof(descriptor_write));
16439 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
16440 descriptor_write.dstSet = descriptor_set;
16441 descriptor_write.dstBinding = 0;
16442 descriptor_write.descriptorCount = 1;
16443 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16444 descriptor_write.pBufferInfo = &buffer_info;
16445
16446 // Set pImageInfo and pTexelBufferView to invalid values, which should
16447 // be
16448 // ignored for descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER.
16449 // This will most likely produce a crash if the parameter_validation
16450 // layer
16451 // does not correctly ignore pImageInfo.
16452 descriptor_write.pImageInfo = reinterpret_cast<const VkDescriptorImageInfo *>(invalid_ptr);
16453 descriptor_write.pTexelBufferView = reinterpret_cast<const VkBufferView *>(invalid_ptr);
16454
16455 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
16456
16457 m_errorMonitor->VerifyNotFound();
16458
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016459 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
16460 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
16461 vkDestroyBuffer(m_device->device(), buffer, NULL);
16462 vkFreeMemory(m_device->device(), buffer_memory, NULL);
16463 }
16464
16465 // Texel Buffer Case
16466 {
16467 m_errorMonitor->ExpectSuccess();
16468
16469 VkBuffer buffer;
16470 uint32_t queue_family_index = 0;
16471 VkBufferCreateInfo buffer_create_info = {};
16472 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
16473 buffer_create_info.size = 1024;
16474 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
16475 buffer_create_info.queueFamilyIndexCount = 1;
16476 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
16477
16478 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
16479 ASSERT_VK_SUCCESS(err);
16480
16481 VkMemoryRequirements memory_reqs;
16482 VkDeviceMemory buffer_memory;
16483 bool pass;
16484 VkMemoryAllocateInfo memory_info = {};
16485 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16486 memory_info.pNext = NULL;
16487 memory_info.allocationSize = 0;
16488 memory_info.memoryTypeIndex = 0;
16489
16490 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
16491 memory_info.allocationSize = memory_reqs.size;
16492 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
16493 ASSERT_TRUE(pass);
16494
16495 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
16496 ASSERT_VK_SUCCESS(err);
16497 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
16498 ASSERT_VK_SUCCESS(err);
16499
16500 VkBufferViewCreateInfo buff_view_ci = {};
16501 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
16502 buff_view_ci.buffer = buffer;
16503 buff_view_ci.format = VK_FORMAT_R8_UNORM;
16504 buff_view_ci.range = VK_WHOLE_SIZE;
16505 VkBufferView buffer_view;
16506 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buffer_view);
16507
16508 VkDescriptorPoolSize ds_type_count = {};
16509 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
16510 ds_type_count.descriptorCount = 1;
16511
16512 VkDescriptorPoolCreateInfo ds_pool_ci = {};
16513 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
16514 ds_pool_ci.pNext = NULL;
16515 ds_pool_ci.maxSets = 1;
16516 ds_pool_ci.poolSizeCount = 1;
16517 ds_pool_ci.pPoolSizes = &ds_type_count;
16518
16519 VkDescriptorPool ds_pool;
16520 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
16521 ASSERT_VK_SUCCESS(err);
16522
16523 VkDescriptorSetLayoutBinding dsl_binding = {};
16524 dsl_binding.binding = 0;
16525 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
16526 dsl_binding.descriptorCount = 1;
16527 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
16528 dsl_binding.pImmutableSamplers = NULL;
16529
16530 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
16531 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
16532 ds_layout_ci.pNext = NULL;
16533 ds_layout_ci.bindingCount = 1;
16534 ds_layout_ci.pBindings = &dsl_binding;
16535 VkDescriptorSetLayout ds_layout;
16536 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
16537 ASSERT_VK_SUCCESS(err);
16538
16539 VkDescriptorSet descriptor_set;
16540 VkDescriptorSetAllocateInfo alloc_info = {};
16541 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
16542 alloc_info.descriptorSetCount = 1;
16543 alloc_info.descriptorPool = ds_pool;
16544 alloc_info.pSetLayouts = &ds_layout;
16545 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
16546 ASSERT_VK_SUCCESS(err);
16547
16548 VkWriteDescriptorSet descriptor_write;
16549 memset(&descriptor_write, 0, sizeof(descriptor_write));
16550 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
16551 descriptor_write.dstSet = descriptor_set;
16552 descriptor_write.dstBinding = 0;
16553 descriptor_write.descriptorCount = 1;
16554 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
16555 descriptor_write.pTexelBufferView = &buffer_view;
16556
16557 // Set pImageInfo and pBufferInfo to invalid values, which should be
16558 // ignored for descriptorType ==
16559 // VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER.
16560 // This will most likely produce a crash if the parameter_validation
16561 // layer
16562 // does not correctly ignore pImageInfo and pBufferInfo.
16563 descriptor_write.pImageInfo = reinterpret_cast<const VkDescriptorImageInfo *>(invalid_ptr);
16564 descriptor_write.pBufferInfo = reinterpret_cast<const VkDescriptorBufferInfo *>(invalid_ptr);
16565
16566 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
16567
16568 m_errorMonitor->VerifyNotFound();
16569
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016570 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
16571 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
16572 vkDestroyBufferView(m_device->device(), buffer_view, NULL);
16573 vkDestroyBuffer(m_device->device(), buffer, NULL);
16574 vkFreeMemory(m_device->device(), buffer_memory, NULL);
16575 }
16576}
16577
Tobin Ehlisf7428442016-10-25 07:58:24 -060016578TEST_F(VkLayerTest, DuplicateDescriptorBinding) {
16579 TEST_DESCRIPTION("Create a descriptor set layout with a duplicate binding number.");
16580
16581 ASSERT_NO_FATAL_FAILURE(InitState());
16582 // Create layout where two binding #s are "1"
16583 static const uint32_t NUM_BINDINGS = 3;
16584 VkDescriptorSetLayoutBinding dsl_binding[NUM_BINDINGS] = {};
16585 dsl_binding[0].binding = 1;
16586 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16587 dsl_binding[0].descriptorCount = 1;
16588 dsl_binding[0].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
16589 dsl_binding[0].pImmutableSamplers = NULL;
16590 dsl_binding[1].binding = 0;
16591 dsl_binding[1].descriptorCount = 1;
16592 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16593 dsl_binding[1].descriptorCount = 1;
16594 dsl_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
16595 dsl_binding[1].pImmutableSamplers = NULL;
16596 dsl_binding[2].binding = 1; // Duplicate binding should cause error
16597 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16598 dsl_binding[2].descriptorCount = 1;
16599 dsl_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
16600 dsl_binding[2].pImmutableSamplers = NULL;
16601
16602 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
16603 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
16604 ds_layout_ci.pNext = NULL;
16605 ds_layout_ci.bindingCount = NUM_BINDINGS;
16606 ds_layout_ci.pBindings = dsl_binding;
16607 VkDescriptorSetLayout ds_layout;
16608 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02345);
16609 vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
16610 m_errorMonitor->VerifyFound();
16611}
16612
Mike Weiblen9a0f55d2016-10-31 22:35:00 -060016613TEST_F(VkLayerTest, ViewportAndScissorBoundsChecking) {
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060016614 TEST_DESCRIPTION("Verify errors are detected on misuse of SetViewport and SetScissor.");
16615
16616 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060016617
16618 BeginCommandBuffer();
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060016619
Mike Weiblen9a0f55d2016-10-31 22:35:00 -060016620 const VkPhysicalDeviceLimits &limits = m_device->props.limits;
16621
16622 {
16623 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01448);
16624 VkViewport viewport = {0, 0, static_cast<float>(limits.maxViewportDimensions[0] + 1), 16, 0, 1};
16625 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
16626 m_errorMonitor->VerifyFound();
16627 }
16628
16629 {
16630 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01449);
16631 VkViewport viewport = {0, 0, 16, static_cast<float>(limits.maxViewportDimensions[1] + 1), 0, 1};
16632 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
16633 m_errorMonitor->VerifyFound();
16634 }
16635
16636 {
16637 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01450);
16638 VkViewport viewport = {limits.viewportBoundsRange[0] - 1, 0, 16, 16, 0, 1};
16639 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
16640 m_errorMonitor->VerifyFound();
16641 }
16642
16643 {
16644 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01450);
16645 VkViewport viewport = {0, limits.viewportBoundsRange[0] - 1, 16, 16, 0, 1};
16646 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
16647 m_errorMonitor->VerifyFound();
16648 }
16649
16650 {
16651 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01451);
16652 VkViewport viewport = {limits.viewportBoundsRange[1], 0, 16, 16, 0, 1};
16653 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
16654 m_errorMonitor->VerifyFound();
16655 }
16656
16657 {
16658 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01452);
16659 VkViewport viewport = {0, limits.viewportBoundsRange[1], 16, 16, 0, 1};
16660 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
16661 m_errorMonitor->VerifyFound();
16662 }
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060016663
16664 {
16665 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01489);
16666 VkRect2D scissor = {{-1, 0}, {16, 16}};
16667 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
16668 m_errorMonitor->VerifyFound();
16669 }
16670
16671 {
16672 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01489);
16673 VkRect2D scissor = {{0, -2}, {16, 16}};
16674 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
16675 m_errorMonitor->VerifyFound();
16676 }
16677
16678 {
16679 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01490);
16680 VkRect2D scissor = {{100, 100}, {INT_MAX, 16}};
16681 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
16682 m_errorMonitor->VerifyFound();
16683 }
16684
16685 {
16686 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01491);
16687 VkRect2D scissor = {{100, 100}, {16, INT_MAX}};
16688 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
16689 m_errorMonitor->VerifyFound();
16690 }
16691
16692 EndCommandBuffer();
16693}
16694
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016695// This is a positive test. No failures are expected.
16696TEST_F(VkPositiveLayerTest, EmptyDescriptorUpdateTest) {
16697 TEST_DESCRIPTION("Update last descriptor in a set that includes an empty binding");
16698 VkResult err;
16699
16700 ASSERT_NO_FATAL_FAILURE(InitState());
16701 m_errorMonitor->ExpectSuccess();
16702 VkDescriptorPoolSize ds_type_count = {};
16703 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16704 ds_type_count.descriptorCount = 2;
16705
16706 VkDescriptorPoolCreateInfo ds_pool_ci = {};
16707 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
16708 ds_pool_ci.pNext = NULL;
16709 ds_pool_ci.maxSets = 1;
16710 ds_pool_ci.poolSizeCount = 1;
16711 ds_pool_ci.pPoolSizes = &ds_type_count;
16712
16713 VkDescriptorPool ds_pool;
16714 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
16715 ASSERT_VK_SUCCESS(err);
16716
16717 // Create layout with two uniform buffer descriptors w/ empty binding between them
16718 static const uint32_t NUM_BINDINGS = 3;
16719 VkDescriptorSetLayoutBinding dsl_binding[NUM_BINDINGS] = {};
16720 dsl_binding[0].binding = 0;
16721 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16722 dsl_binding[0].descriptorCount = 1;
16723 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
16724 dsl_binding[0].pImmutableSamplers = NULL;
16725 dsl_binding[1].binding = 1;
16726 dsl_binding[1].descriptorCount = 0; // empty binding
16727 dsl_binding[2].binding = 2;
16728 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16729 dsl_binding[2].descriptorCount = 1;
16730 dsl_binding[2].stageFlags = VK_SHADER_STAGE_ALL;
16731 dsl_binding[2].pImmutableSamplers = NULL;
16732
16733 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
16734 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
16735 ds_layout_ci.pNext = NULL;
16736 ds_layout_ci.bindingCount = NUM_BINDINGS;
16737 ds_layout_ci.pBindings = dsl_binding;
16738 VkDescriptorSetLayout ds_layout;
16739 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
16740 ASSERT_VK_SUCCESS(err);
16741
16742 VkDescriptorSet descriptor_set = {};
16743 VkDescriptorSetAllocateInfo alloc_info = {};
16744 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
16745 alloc_info.descriptorSetCount = 1;
16746 alloc_info.descriptorPool = ds_pool;
16747 alloc_info.pSetLayouts = &ds_layout;
16748 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
16749 ASSERT_VK_SUCCESS(err);
16750
16751 // Create a buffer to be used for update
16752 VkBufferCreateInfo buff_ci = {};
16753 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
16754 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
16755 buff_ci.size = 256;
16756 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
16757 VkBuffer buffer;
16758 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
16759 ASSERT_VK_SUCCESS(err);
16760 // Have to bind memory to buffer before descriptor update
16761 VkMemoryAllocateInfo mem_alloc = {};
16762 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16763 mem_alloc.pNext = NULL;
16764 mem_alloc.allocationSize = 512; // one allocation for both buffers
16765 mem_alloc.memoryTypeIndex = 0;
16766
16767 VkMemoryRequirements mem_reqs;
16768 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
16769 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
16770 if (!pass) {
16771 vkDestroyBuffer(m_device->device(), buffer, NULL);
16772 return;
16773 }
16774
16775 VkDeviceMemory mem;
16776 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
16777 ASSERT_VK_SUCCESS(err);
16778 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
16779 ASSERT_VK_SUCCESS(err);
16780
16781 // Only update the descriptor at binding 2
16782 VkDescriptorBufferInfo buff_info = {};
16783 buff_info.buffer = buffer;
16784 buff_info.offset = 0;
16785 buff_info.range = VK_WHOLE_SIZE;
16786 VkWriteDescriptorSet descriptor_write = {};
16787 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
16788 descriptor_write.dstBinding = 2;
16789 descriptor_write.descriptorCount = 1;
16790 descriptor_write.pTexelBufferView = nullptr;
16791 descriptor_write.pBufferInfo = &buff_info;
16792 descriptor_write.pImageInfo = nullptr;
16793 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16794 descriptor_write.dstSet = descriptor_set;
16795
16796 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
16797
16798 m_errorMonitor->VerifyNotFound();
16799 // Cleanup
16800 vkFreeMemory(m_device->device(), mem, NULL);
16801 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
16802 vkDestroyBuffer(m_device->device(), buffer, NULL);
16803 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
16804}
16805
16806// This is a positive test. No failures are expected.
16807TEST_F(VkPositiveLayerTest, TestAliasedMemoryTracking) {
16808 VkResult err;
16809 bool pass;
16810
16811 TEST_DESCRIPTION("Create a buffer, allocate memory, bind memory, destroy "
16812 "the buffer, create an image, and bind the same memory to "
16813 "it");
16814
16815 m_errorMonitor->ExpectSuccess();
16816
16817 ASSERT_NO_FATAL_FAILURE(InitState());
16818
16819 VkBuffer buffer;
16820 VkImage image;
16821 VkDeviceMemory mem;
16822 VkMemoryRequirements mem_reqs;
16823
16824 VkBufferCreateInfo buf_info = {};
16825 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
16826 buf_info.pNext = NULL;
16827 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
16828 buf_info.size = 256;
16829 buf_info.queueFamilyIndexCount = 0;
16830 buf_info.pQueueFamilyIndices = NULL;
16831 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
16832 buf_info.flags = 0;
16833 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
16834 ASSERT_VK_SUCCESS(err);
16835
16836 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
16837
16838 VkMemoryAllocateInfo alloc_info = {};
16839 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16840 alloc_info.pNext = NULL;
16841 alloc_info.memoryTypeIndex = 0;
16842
16843 // Ensure memory is big enough for both bindings
16844 alloc_info.allocationSize = 0x10000;
16845
16846 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
16847 if (!pass) {
16848 vkDestroyBuffer(m_device->device(), buffer, NULL);
16849 return;
16850 }
16851
16852 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
16853 ASSERT_VK_SUCCESS(err);
16854
16855 uint8_t *pData;
16856 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
16857 ASSERT_VK_SUCCESS(err);
16858
16859 memset(pData, 0xCADECADE, static_cast<size_t>(mem_reqs.size));
16860
16861 vkUnmapMemory(m_device->device(), mem);
16862
16863 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
16864 ASSERT_VK_SUCCESS(err);
16865
16866 // NOW, destroy the buffer. Obviously, the resource no longer occupies this
16867 // memory. In fact, it was never used by the GPU.
16868 // Just be be sure, wait for idle.
16869 vkDestroyBuffer(m_device->device(), buffer, NULL);
16870 vkDeviceWaitIdle(m_device->device());
16871
Tobin Ehlis6a005702016-12-28 15:25:56 -070016872 // Use optimal as some platforms report linear support but then fail image creation
16873 VkImageTiling image_tiling = VK_IMAGE_TILING_OPTIMAL;
16874 VkImageFormatProperties image_format_properties;
16875 vkGetPhysicalDeviceImageFormatProperties(gpu(), VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_TYPE_2D, image_tiling,
16876 VK_IMAGE_USAGE_TRANSFER_SRC_BIT, 0, &image_format_properties);
16877 if (image_format_properties.maxExtent.width == 0) {
16878 printf("Image format not supported; skipped.\n");
16879 vkFreeMemory(m_device->device(), mem, NULL);
16880 return;
16881 }
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016882 VkImageCreateInfo image_create_info = {};
16883 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16884 image_create_info.pNext = NULL;
16885 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16886 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
16887 image_create_info.extent.width = 64;
16888 image_create_info.extent.height = 64;
16889 image_create_info.extent.depth = 1;
16890 image_create_info.mipLevels = 1;
16891 image_create_info.arrayLayers = 1;
16892 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehlis6a005702016-12-28 15:25:56 -070016893 image_create_info.tiling = image_tiling;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016894 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
16895 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
16896 image_create_info.queueFamilyIndexCount = 0;
16897 image_create_info.pQueueFamilyIndices = NULL;
16898 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
16899 image_create_info.flags = 0;
16900
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016901 /* Create a mappable image. It will be the texture if linear images are ok
16902 * to be textures or it will be the staging image if they are not.
16903 */
16904 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
16905 ASSERT_VK_SUCCESS(err);
16906
16907 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
16908
Tobin Ehlis6a005702016-12-28 15:25:56 -070016909 VkMemoryAllocateInfo mem_alloc = {};
16910 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16911 mem_alloc.pNext = NULL;
16912 mem_alloc.allocationSize = 0;
16913 mem_alloc.memoryTypeIndex = 0;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016914 mem_alloc.allocationSize = mem_reqs.size;
16915
16916 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
16917 if (!pass) {
Tobin Ehlis6a005702016-12-28 15:25:56 -070016918 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016919 vkDestroyImage(m_device->device(), image, NULL);
16920 return;
16921 }
16922
16923 // VALIDATION FAILURE:
16924 err = vkBindImageMemory(m_device->device(), image, mem, 0);
16925 ASSERT_VK_SUCCESS(err);
16926
16927 m_errorMonitor->VerifyNotFound();
16928
16929 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016930 vkDestroyImage(m_device->device(), image, NULL);
16931}
16932
Tobin Ehlis953e8392016-11-17 10:54:13 -070016933TEST_F(VkPositiveLayerTest, DynamicOffsetWithInactiveBinding) {
16934 // Create a descriptorSet w/ dynamic descriptors where 1 binding is inactive
16935 // We previously had a bug where dynamic offset of inactive bindings was still being used
16936 VkResult err;
16937 m_errorMonitor->ExpectSuccess();
16938
16939 ASSERT_NO_FATAL_FAILURE(InitState());
16940 ASSERT_NO_FATAL_FAILURE(InitViewport());
16941 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
16942
16943 VkDescriptorPoolSize ds_type_count = {};
16944 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
16945 ds_type_count.descriptorCount = 3;
16946
16947 VkDescriptorPoolCreateInfo ds_pool_ci = {};
16948 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
16949 ds_pool_ci.pNext = NULL;
16950 ds_pool_ci.maxSets = 1;
16951 ds_pool_ci.poolSizeCount = 1;
16952 ds_pool_ci.pPoolSizes = &ds_type_count;
16953
16954 VkDescriptorPool ds_pool;
16955 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
16956 ASSERT_VK_SUCCESS(err);
16957
16958 const uint32_t BINDING_COUNT = 3;
16959 VkDescriptorSetLayoutBinding dsl_binding[BINDING_COUNT] = {};
Tobin Ehlis0050fba2016-11-30 10:22:02 -070016960 dsl_binding[0].binding = 2;
Tobin Ehlis953e8392016-11-17 10:54:13 -070016961 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
16962 dsl_binding[0].descriptorCount = 1;
16963 dsl_binding[0].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
16964 dsl_binding[0].pImmutableSamplers = NULL;
Tobin Ehlis0050fba2016-11-30 10:22:02 -070016965 dsl_binding[1].binding = 0;
Tobin Ehlis953e8392016-11-17 10:54:13 -070016966 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
16967 dsl_binding[1].descriptorCount = 1;
16968 dsl_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
16969 dsl_binding[1].pImmutableSamplers = NULL;
Tobin Ehlis0050fba2016-11-30 10:22:02 -070016970 dsl_binding[2].binding = 1;
Tobin Ehlis953e8392016-11-17 10:54:13 -070016971 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
16972 dsl_binding[2].descriptorCount = 1;
16973 dsl_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
16974 dsl_binding[2].pImmutableSamplers = NULL;
16975
16976 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
16977 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
16978 ds_layout_ci.pNext = NULL;
16979 ds_layout_ci.bindingCount = BINDING_COUNT;
16980 ds_layout_ci.pBindings = dsl_binding;
16981 VkDescriptorSetLayout ds_layout;
16982 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
16983 ASSERT_VK_SUCCESS(err);
16984
16985 VkDescriptorSet descriptor_set;
16986 VkDescriptorSetAllocateInfo alloc_info = {};
16987 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
16988 alloc_info.descriptorSetCount = 1;
16989 alloc_info.descriptorPool = ds_pool;
16990 alloc_info.pSetLayouts = &ds_layout;
16991 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
16992 ASSERT_VK_SUCCESS(err);
16993
16994 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
16995 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
16996 pipeline_layout_ci.pNext = NULL;
16997 pipeline_layout_ci.setLayoutCount = 1;
16998 pipeline_layout_ci.pSetLayouts = &ds_layout;
16999
17000 VkPipelineLayout pipeline_layout;
17001 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
17002 ASSERT_VK_SUCCESS(err);
17003
17004 // Create two buffers to update the descriptors with
17005 // The first will be 2k and used for bindings 0 & 1, the second is 1k for binding 2
17006 uint32_t qfi = 0;
17007 VkBufferCreateInfo buffCI = {};
17008 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
17009 buffCI.size = 2048;
17010 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
17011 buffCI.queueFamilyIndexCount = 1;
17012 buffCI.pQueueFamilyIndices = &qfi;
17013
17014 VkBuffer dyub1;
17015 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub1);
17016 ASSERT_VK_SUCCESS(err);
17017 // buffer2
17018 buffCI.size = 1024;
17019 VkBuffer dyub2;
17020 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub2);
17021 ASSERT_VK_SUCCESS(err);
17022 // Allocate memory and bind to buffers
17023 VkMemoryAllocateInfo mem_alloc[2] = {};
17024 mem_alloc[0].sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17025 mem_alloc[0].pNext = NULL;
17026 mem_alloc[0].memoryTypeIndex = 0;
17027 mem_alloc[1].sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17028 mem_alloc[1].pNext = NULL;
17029 mem_alloc[1].memoryTypeIndex = 0;
17030
17031 VkMemoryRequirements mem_reqs1;
17032 vkGetBufferMemoryRequirements(m_device->device(), dyub1, &mem_reqs1);
17033 VkMemoryRequirements mem_reqs2;
17034 vkGetBufferMemoryRequirements(m_device->device(), dyub2, &mem_reqs2);
17035 mem_alloc[0].allocationSize = mem_reqs1.size;
17036 bool pass = m_device->phy().set_memory_type(mem_reqs1.memoryTypeBits, &mem_alloc[0], 0);
17037 mem_alloc[1].allocationSize = mem_reqs2.size;
17038 pass &= m_device->phy().set_memory_type(mem_reqs2.memoryTypeBits, &mem_alloc[1], 0);
17039 if (!pass) {
17040 vkDestroyBuffer(m_device->device(), dyub1, NULL);
17041 vkDestroyBuffer(m_device->device(), dyub2, NULL);
17042 return;
17043 }
17044
17045 VkDeviceMemory mem1;
17046 err = vkAllocateMemory(m_device->device(), &mem_alloc[0], NULL, &mem1);
17047 ASSERT_VK_SUCCESS(err);
17048 err = vkBindBufferMemory(m_device->device(), dyub1, mem1, 0);
17049 ASSERT_VK_SUCCESS(err);
17050 VkDeviceMemory mem2;
17051 err = vkAllocateMemory(m_device->device(), &mem_alloc[1], NULL, &mem2);
17052 ASSERT_VK_SUCCESS(err);
17053 err = vkBindBufferMemory(m_device->device(), dyub2, mem2, 0);
17054 ASSERT_VK_SUCCESS(err);
17055 // Update descriptors
17056 VkDescriptorBufferInfo buff_info[BINDING_COUNT] = {};
17057 buff_info[0].buffer = dyub1;
17058 buff_info[0].offset = 0;
17059 buff_info[0].range = 256;
17060 buff_info[1].buffer = dyub1;
17061 buff_info[1].offset = 256;
17062 buff_info[1].range = 512;
17063 buff_info[2].buffer = dyub2;
17064 buff_info[2].offset = 0;
17065 buff_info[2].range = 512;
17066
17067 VkWriteDescriptorSet descriptor_write;
17068 memset(&descriptor_write, 0, sizeof(descriptor_write));
17069 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
17070 descriptor_write.dstSet = descriptor_set;
17071 descriptor_write.dstBinding = 0;
17072 descriptor_write.descriptorCount = BINDING_COUNT;
17073 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
17074 descriptor_write.pBufferInfo = buff_info;
17075
17076 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
17077
17078 BeginCommandBuffer();
17079
17080 // Create PSO to be used for draw-time errors below
17081 char const *vsSource = "#version 450\n"
17082 "\n"
17083 "out gl_PerVertex { \n"
17084 " vec4 gl_Position;\n"
17085 "};\n"
17086 "void main(){\n"
17087 " gl_Position = vec4(1);\n"
17088 "}\n";
17089 char const *fsSource = "#version 450\n"
17090 "\n"
17091 "layout(location=0) out vec4 x;\n"
17092 "layout(set=0) layout(binding=0) uniform foo1 { int x; int y; } bar1;\n"
17093 "layout(set=0) layout(binding=2) uniform foo2 { int x; int y; } bar2;\n"
17094 "void main(){\n"
17095 " x = vec4(bar1.y) + vec4(bar2.y);\n"
17096 "}\n";
17097 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
17098 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
17099 VkPipelineObj pipe(m_device);
17100 pipe.SetViewport(m_viewports);
17101 pipe.SetScissor(m_scissors);
17102 pipe.AddShader(&vs);
17103 pipe.AddShader(&fs);
17104 pipe.AddColorAttachment();
17105 pipe.CreateVKPipeline(pipeline_layout, renderPass());
17106
17107 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
17108 // This update should succeed, but offset of inactive binding 1 oversteps binding 2 buffer size
17109 // we used to have a bug in this case.
17110 uint32_t dyn_off[BINDING_COUNT] = {0, 1024, 256};
17111 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
17112 &descriptor_set, BINDING_COUNT, dyn_off);
17113 Draw(1, 0, 0, 0);
17114 m_errorMonitor->VerifyNotFound();
17115
17116 vkDestroyBuffer(m_device->device(), dyub1, NULL);
17117 vkDestroyBuffer(m_device->device(), dyub2, NULL);
17118 vkFreeMemory(m_device->device(), mem1, NULL);
17119 vkFreeMemory(m_device->device(), mem2, NULL);
17120
17121 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
17122 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
17123 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
17124}
17125
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017126TEST_F(VkPositiveLayerTest, NonCoherentMemoryMapping) {
17127
17128 TEST_DESCRIPTION("Ensure that validations handling of non-coherent memory "
17129 "mapping while using VK_WHOLE_SIZE does not cause access "
17130 "violations");
17131 VkResult err;
17132 uint8_t *pData;
17133 ASSERT_NO_FATAL_FAILURE(InitState());
17134
17135 VkDeviceMemory mem;
17136 VkMemoryRequirements mem_reqs;
17137 mem_reqs.memoryTypeBits = 0xFFFFFFFF;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017138 const VkDeviceSize atom_size = m_device->props.limits.nonCoherentAtomSize;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017139 VkMemoryAllocateInfo alloc_info = {};
17140 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17141 alloc_info.pNext = NULL;
17142 alloc_info.memoryTypeIndex = 0;
17143
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017144 static const VkDeviceSize allocation_size = 32 * atom_size;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017145 alloc_info.allocationSize = allocation_size;
17146
17147 // Find a memory configurations WITHOUT a COHERENT bit, otherwise exit
17148 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT,
17149 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
17150 if (!pass) {
17151 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info,
17152 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT,
17153 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
17154 if (!pass) {
17155 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info,
17156 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT |
17157 VK_MEMORY_PROPERTY_HOST_CACHED_BIT,
17158 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
17159 if (!pass) {
17160 return;
17161 }
17162 }
17163 }
17164
17165 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
17166 ASSERT_VK_SUCCESS(err);
17167
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017168 // Map/Flush/Invalidate using WHOLE_SIZE and zero offsets and entire mapped range
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017169 m_errorMonitor->ExpectSuccess();
17170 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, (void **)&pData);
17171 ASSERT_VK_SUCCESS(err);
17172 VkMappedMemoryRange mmr = {};
17173 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
17174 mmr.memory = mem;
17175 mmr.offset = 0;
17176 mmr.size = VK_WHOLE_SIZE;
17177 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
17178 ASSERT_VK_SUCCESS(err);
17179 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
17180 ASSERT_VK_SUCCESS(err);
17181 m_errorMonitor->VerifyNotFound();
17182 vkUnmapMemory(m_device->device(), mem);
17183
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017184 // Map/Flush/Invalidate using WHOLE_SIZE and an offset and entire mapped range
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017185 m_errorMonitor->ExpectSuccess();
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017186 err = vkMapMemory(m_device->device(), mem, 5 * atom_size, VK_WHOLE_SIZE, 0, (void **)&pData);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017187 ASSERT_VK_SUCCESS(err);
17188 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
17189 mmr.memory = mem;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017190 mmr.offset = 6 * atom_size;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017191 mmr.size = VK_WHOLE_SIZE;
17192 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
17193 ASSERT_VK_SUCCESS(err);
17194 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
17195 ASSERT_VK_SUCCESS(err);
17196 m_errorMonitor->VerifyNotFound();
17197 vkUnmapMemory(m_device->device(), mem);
17198
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017199 // Map with offset and size
17200 // Flush/Invalidate subrange of mapped area with offset and size
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017201 m_errorMonitor->ExpectSuccess();
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017202 err = vkMapMemory(m_device->device(), mem, 3 * atom_size, 9 * atom_size, 0, (void **)&pData);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017203 ASSERT_VK_SUCCESS(err);
17204 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
17205 mmr.memory = mem;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017206 mmr.offset = 4 * atom_size;
17207 mmr.size = 2 * atom_size;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017208 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
17209 ASSERT_VK_SUCCESS(err);
17210 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
17211 ASSERT_VK_SUCCESS(err);
17212 m_errorMonitor->VerifyNotFound();
17213 vkUnmapMemory(m_device->device(), mem);
17214
17215 // Map without offset and flush WHOLE_SIZE with two separate offsets
17216 m_errorMonitor->ExpectSuccess();
17217 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, (void **)&pData);
17218 ASSERT_VK_SUCCESS(err);
17219 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
17220 mmr.memory = mem;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017221 mmr.offset = allocation_size - (4 * atom_size);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017222 mmr.size = VK_WHOLE_SIZE;
17223 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
17224 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017225 mmr.offset = allocation_size - (6 * atom_size);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017226 mmr.size = VK_WHOLE_SIZE;
17227 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
17228 ASSERT_VK_SUCCESS(err);
17229 m_errorMonitor->VerifyNotFound();
17230 vkUnmapMemory(m_device->device(), mem);
17231
17232 vkFreeMemory(m_device->device(), mem, NULL);
17233}
17234
17235// This is a positive test. We used to expect error in this case but spec now allows it
17236TEST_F(VkPositiveLayerTest, ResetUnsignaledFence) {
17237 m_errorMonitor->ExpectSuccess();
17238 vk_testing::Fence testFence;
17239 VkFenceCreateInfo fenceInfo = {};
17240 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
17241 fenceInfo.pNext = NULL;
17242
17243 ASSERT_NO_FATAL_FAILURE(InitState());
17244 testFence.init(*m_device, fenceInfo);
17245 VkFence fences[1] = { testFence.handle() };
17246 VkResult result = vkResetFences(m_device->device(), 1, fences);
17247 ASSERT_VK_SUCCESS(result);
17248
17249 m_errorMonitor->VerifyNotFound();
17250}
17251
17252TEST_F(VkPositiveLayerTest, CommandBufferSimultaneousUseSync) {
17253 m_errorMonitor->ExpectSuccess();
17254
17255 ASSERT_NO_FATAL_FAILURE(InitState());
17256 VkResult err;
17257
17258 // Record (empty!) command buffer that can be submitted multiple times
17259 // simultaneously.
17260 VkCommandBufferBeginInfo cbbi = { VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr,
17261 VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT, nullptr };
17262 m_commandBuffer->BeginCommandBuffer(&cbbi);
17263 m_commandBuffer->EndCommandBuffer();
17264
17265 VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
17266 VkFence fence;
17267 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
17268 ASSERT_VK_SUCCESS(err);
17269
17270 VkSemaphoreCreateInfo sci = { VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0 };
17271 VkSemaphore s1, s2;
17272 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s1);
17273 ASSERT_VK_SUCCESS(err);
17274 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s2);
17275 ASSERT_VK_SUCCESS(err);
17276
17277 // Submit CB once signaling s1, with fence so we can roll forward to its retirement.
17278 VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 1, &m_commandBuffer->handle(), 1, &s1 };
17279 err = vkQueueSubmit(m_device->m_queue, 1, &si, fence);
17280 ASSERT_VK_SUCCESS(err);
17281
17282 // Submit CB again, signaling s2.
17283 si.pSignalSemaphores = &s2;
17284 err = vkQueueSubmit(m_device->m_queue, 1, &si, VK_NULL_HANDLE);
17285 ASSERT_VK_SUCCESS(err);
17286
17287 // Wait for fence.
17288 err = vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
17289 ASSERT_VK_SUCCESS(err);
17290
17291 // CB is still in flight from second submission, but semaphore s1 is no
17292 // longer in flight. delete it.
17293 vkDestroySemaphore(m_device->device(), s1, nullptr);
17294
17295 m_errorMonitor->VerifyNotFound();
17296
17297 // Force device idle and clean up remaining objects
17298 vkDeviceWaitIdle(m_device->device());
17299 vkDestroySemaphore(m_device->device(), s2, nullptr);
17300 vkDestroyFence(m_device->device(), fence, nullptr);
17301}
17302
17303TEST_F(VkPositiveLayerTest, FenceCreateSignaledWaitHandling) {
17304 m_errorMonitor->ExpectSuccess();
17305
17306 ASSERT_NO_FATAL_FAILURE(InitState());
17307 VkResult err;
17308
17309 // A fence created signaled
17310 VkFenceCreateInfo fci1 = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, VK_FENCE_CREATE_SIGNALED_BIT };
17311 VkFence f1;
17312 err = vkCreateFence(m_device->device(), &fci1, nullptr, &f1);
17313 ASSERT_VK_SUCCESS(err);
17314
17315 // A fence created not
17316 VkFenceCreateInfo fci2 = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
17317 VkFence f2;
17318 err = vkCreateFence(m_device->device(), &fci2, nullptr, &f2);
17319 ASSERT_VK_SUCCESS(err);
17320
17321 // Submit the unsignaled fence
17322 VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 0, nullptr, 0, nullptr };
17323 err = vkQueueSubmit(m_device->m_queue, 1, &si, f2);
17324
17325 // Wait on both fences, with signaled first.
17326 VkFence fences[] = { f1, f2 };
17327 vkWaitForFences(m_device->device(), 2, fences, VK_TRUE, UINT64_MAX);
17328
17329 // Should have both retired!
17330 vkDestroyFence(m_device->device(), f1, nullptr);
17331 vkDestroyFence(m_device->device(), f2, nullptr);
17332
17333 m_errorMonitor->VerifyNotFound();
17334}
17335
17336TEST_F(VkPositiveLayerTest, ValidUsage) {
17337 TEST_DESCRIPTION("Verify that creating an image view from an image with valid usage "
17338 "doesn't generate validation errors");
17339
17340 ASSERT_NO_FATAL_FAILURE(InitState());
17341
17342 m_errorMonitor->ExpectSuccess();
17343 // Verify that we can create a view with usage INPUT_ATTACHMENT
17344 VkImageObj image(m_device);
17345 image.init(128, 128, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
17346 ASSERT_TRUE(image.initialized());
17347 VkImageView imageView;
17348 VkImageViewCreateInfo ivci = {};
17349 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
17350 ivci.image = image.handle();
17351 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
17352 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
17353 ivci.subresourceRange.layerCount = 1;
17354 ivci.subresourceRange.baseMipLevel = 0;
17355 ivci.subresourceRange.levelCount = 1;
17356 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
17357
17358 vkCreateImageView(m_device->device(), &ivci, NULL, &imageView);
17359 m_errorMonitor->VerifyNotFound();
17360 vkDestroyImageView(m_device->device(), imageView, NULL);
17361}
17362
17363// This is a positive test. No failures are expected.
17364TEST_F(VkPositiveLayerTest, BindSparse) {
17365 TEST_DESCRIPTION("Bind 2 memory ranges to one image using vkQueueBindSparse, destroy the image"
17366 "and then free the memory");
17367
17368 ASSERT_NO_FATAL_FAILURE(InitState());
17369
17370 auto index = m_device->graphics_queue_node_index_;
17371 if (!(m_device->queue_props[index].queueFlags & VK_QUEUE_SPARSE_BINDING_BIT))
17372 return;
17373
17374 m_errorMonitor->ExpectSuccess();
17375
17376 VkImage image;
17377 VkImageCreateInfo image_create_info = {};
17378 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
17379 image_create_info.pNext = NULL;
17380 image_create_info.imageType = VK_IMAGE_TYPE_2D;
17381 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
17382 image_create_info.extent.width = 64;
17383 image_create_info.extent.height = 64;
17384 image_create_info.extent.depth = 1;
17385 image_create_info.mipLevels = 1;
17386 image_create_info.arrayLayers = 1;
17387 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
17388 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
17389 image_create_info.usage = VK_IMAGE_USAGE_STORAGE_BIT;
17390 image_create_info.flags = VK_IMAGE_CREATE_SPARSE_BINDING_BIT;
17391 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
17392 ASSERT_VK_SUCCESS(err);
17393
17394 VkMemoryRequirements memory_reqs;
17395 VkDeviceMemory memory_one, memory_two;
17396 bool pass;
17397 VkMemoryAllocateInfo memory_info = {};
17398 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17399 memory_info.pNext = NULL;
17400 memory_info.allocationSize = 0;
17401 memory_info.memoryTypeIndex = 0;
17402 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
17403 // Find an image big enough to allow sparse mapping of 2 memory regions
17404 // Increase the image size until it is at least twice the
17405 // size of the required alignment, to ensure we can bind both
17406 // allocated memory blocks to the image on aligned offsets.
17407 while (memory_reqs.size < (memory_reqs.alignment * 2)) {
17408 vkDestroyImage(m_device->device(), image, nullptr);
17409 image_create_info.extent.width *= 2;
17410 image_create_info.extent.height *= 2;
17411 err = vkCreateImage(m_device->device(), &image_create_info, nullptr, &image);
17412 ASSERT_VK_SUCCESS(err);
17413 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
17414 }
17415 // Allocate 2 memory regions of minimum alignment size, bind one at 0, the other
17416 // at the end of the first
17417 memory_info.allocationSize = memory_reqs.alignment;
17418 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
17419 ASSERT_TRUE(pass);
17420 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &memory_one);
17421 ASSERT_VK_SUCCESS(err);
17422 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &memory_two);
17423 ASSERT_VK_SUCCESS(err);
17424 VkSparseMemoryBind binds[2];
17425 binds[0].flags = 0;
17426 binds[0].memory = memory_one;
17427 binds[0].memoryOffset = 0;
17428 binds[0].resourceOffset = 0;
17429 binds[0].size = memory_info.allocationSize;
17430 binds[1].flags = 0;
17431 binds[1].memory = memory_two;
17432 binds[1].memoryOffset = 0;
17433 binds[1].resourceOffset = memory_info.allocationSize;
17434 binds[1].size = memory_info.allocationSize;
17435
17436 VkSparseImageOpaqueMemoryBindInfo opaqueBindInfo;
17437 opaqueBindInfo.image = image;
17438 opaqueBindInfo.bindCount = 2;
17439 opaqueBindInfo.pBinds = binds;
17440
17441 VkFence fence = VK_NULL_HANDLE;
17442 VkBindSparseInfo bindSparseInfo = {};
17443 bindSparseInfo.sType = VK_STRUCTURE_TYPE_BIND_SPARSE_INFO;
17444 bindSparseInfo.imageOpaqueBindCount = 1;
17445 bindSparseInfo.pImageOpaqueBinds = &opaqueBindInfo;
17446
17447 vkQueueBindSparse(m_device->m_queue, 1, &bindSparseInfo, fence);
17448 vkQueueWaitIdle(m_device->m_queue);
17449 vkDestroyImage(m_device->device(), image, NULL);
17450 vkFreeMemory(m_device->device(), memory_one, NULL);
17451 vkFreeMemory(m_device->device(), memory_two, NULL);
17452 m_errorMonitor->VerifyNotFound();
17453}
17454
17455TEST_F(VkPositiveLayerTest, RenderPassInitialLayoutUndefined) {
17456 TEST_DESCRIPTION("Ensure that CmdBeginRenderPass with an attachment's "
17457 "initialLayout of VK_IMAGE_LAYOUT_UNDEFINED works when "
17458 "the command buffer has prior knowledge of that "
17459 "attachment's layout.");
17460
17461 m_errorMonitor->ExpectSuccess();
17462
17463 ASSERT_NO_FATAL_FAILURE(InitState());
17464
17465 // A renderpass with one color attachment.
17466 VkAttachmentDescription attachment = { 0,
17467 VK_FORMAT_R8G8B8A8_UNORM,
17468 VK_SAMPLE_COUNT_1_BIT,
17469 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
17470 VK_ATTACHMENT_STORE_OP_STORE,
17471 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
17472 VK_ATTACHMENT_STORE_OP_DONT_CARE,
17473 VK_IMAGE_LAYOUT_UNDEFINED,
17474 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
17475
17476 VkAttachmentReference att_ref = { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
17477
17478 VkSubpassDescription subpass = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr };
17479
17480 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr };
17481
17482 VkRenderPass rp;
17483 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
17484 ASSERT_VK_SUCCESS(err);
17485
17486 // A compatible framebuffer.
17487 VkImageObj image(m_device);
17488 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
17489 ASSERT_TRUE(image.initialized());
17490
17491 VkImageViewCreateInfo ivci = {
17492 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
17493 nullptr,
17494 0,
17495 image.handle(),
17496 VK_IMAGE_VIEW_TYPE_2D,
17497 VK_FORMAT_R8G8B8A8_UNORM,
17498 { VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
17499 VK_COMPONENT_SWIZZLE_IDENTITY },
17500 { VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 },
17501 };
17502 VkImageView view;
17503 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
17504 ASSERT_VK_SUCCESS(err);
17505
17506 VkFramebufferCreateInfo fci = { VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1 };
17507 VkFramebuffer fb;
17508 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
17509 ASSERT_VK_SUCCESS(err);
17510
17511 // Record a single command buffer which uses this renderpass twice. The
17512 // bug is triggered at the beginning of the second renderpass, when the
17513 // command buffer already has a layout recorded for the attachment.
17514 VkRenderPassBeginInfo rpbi = { VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb,{ { 0, 0 },{ 32, 32 } }, 0, nullptr };
17515 BeginCommandBuffer();
17516 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
17517 vkCmdEndRenderPass(m_commandBuffer->handle());
17518 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
17519
17520 m_errorMonitor->VerifyNotFound();
17521
17522 vkCmdEndRenderPass(m_commandBuffer->handle());
17523 EndCommandBuffer();
17524
17525 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
17526 vkDestroyRenderPass(m_device->device(), rp, nullptr);
17527 vkDestroyImageView(m_device->device(), view, nullptr);
17528}
17529
17530TEST_F(VkPositiveLayerTest, FramebufferBindingDestroyCommandPool) {
17531 TEST_DESCRIPTION("This test should pass. Create a Framebuffer and "
17532 "command buffer, bind them together, then destroy "
17533 "command pool and framebuffer and verify there are no "
17534 "errors.");
17535
17536 m_errorMonitor->ExpectSuccess();
17537
17538 ASSERT_NO_FATAL_FAILURE(InitState());
17539
17540 // A renderpass with one color attachment.
17541 VkAttachmentDescription attachment = { 0,
17542 VK_FORMAT_R8G8B8A8_UNORM,
17543 VK_SAMPLE_COUNT_1_BIT,
17544 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
17545 VK_ATTACHMENT_STORE_OP_STORE,
17546 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
17547 VK_ATTACHMENT_STORE_OP_DONT_CARE,
17548 VK_IMAGE_LAYOUT_UNDEFINED,
17549 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
17550
17551 VkAttachmentReference att_ref = { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
17552
17553 VkSubpassDescription subpass = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr };
17554
17555 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr };
17556
17557 VkRenderPass rp;
17558 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
17559 ASSERT_VK_SUCCESS(err);
17560
17561 // A compatible framebuffer.
17562 VkImageObj image(m_device);
17563 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
17564 ASSERT_TRUE(image.initialized());
17565
17566 VkImageViewCreateInfo ivci = {
17567 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
17568 nullptr,
17569 0,
17570 image.handle(),
17571 VK_IMAGE_VIEW_TYPE_2D,
17572 VK_FORMAT_R8G8B8A8_UNORM,
17573 { VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
17574 VK_COMPONENT_SWIZZLE_IDENTITY },
17575 { VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 },
17576 };
17577 VkImageView view;
17578 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
17579 ASSERT_VK_SUCCESS(err);
17580
17581 VkFramebufferCreateInfo fci = { VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1 };
17582 VkFramebuffer fb;
17583 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
17584 ASSERT_VK_SUCCESS(err);
17585
17586 // Explicitly create a command buffer to bind the FB to so that we can then
17587 // destroy the command pool in order to implicitly free command buffer
17588 VkCommandPool command_pool;
17589 VkCommandPoolCreateInfo pool_create_info{};
17590 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17591 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
17592 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17593 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
17594
17595 VkCommandBuffer command_buffer;
17596 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
17597 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17598 command_buffer_allocate_info.commandPool = command_pool;
17599 command_buffer_allocate_info.commandBufferCount = 1;
17600 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17601 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
17602
17603 // Begin our cmd buffer with renderpass using our framebuffer
17604 VkRenderPassBeginInfo rpbi = { VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb,{ { 0, 0 },{ 32, 32 } }, 0, nullptr };
17605 VkCommandBufferBeginInfo begin_info{};
17606 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17607 vkBeginCommandBuffer(command_buffer, &begin_info);
17608
17609 vkCmdBeginRenderPass(command_buffer, &rpbi, VK_SUBPASS_CONTENTS_INLINE);
17610 vkCmdEndRenderPass(command_buffer);
17611 vkEndCommandBuffer(command_buffer);
17612 vkDestroyImageView(m_device->device(), view, nullptr);
17613 // Destroy command pool to implicitly free command buffer
17614 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
17615 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
17616 vkDestroyRenderPass(m_device->device(), rp, nullptr);
17617 m_errorMonitor->VerifyNotFound();
17618}
17619
17620TEST_F(VkPositiveLayerTest, RenderPassSubpassZeroTransitionsApplied) {
17621 TEST_DESCRIPTION("Ensure that CmdBeginRenderPass applies the layout "
17622 "transitions for the first subpass");
17623
17624 m_errorMonitor->ExpectSuccess();
17625
17626 ASSERT_NO_FATAL_FAILURE(InitState());
17627
17628 // A renderpass with one color attachment.
17629 VkAttachmentDescription attachment = { 0,
17630 VK_FORMAT_R8G8B8A8_UNORM,
17631 VK_SAMPLE_COUNT_1_BIT,
17632 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
17633 VK_ATTACHMENT_STORE_OP_STORE,
17634 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
17635 VK_ATTACHMENT_STORE_OP_DONT_CARE,
17636 VK_IMAGE_LAYOUT_UNDEFINED,
17637 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
17638
17639 VkAttachmentReference att_ref = { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
17640
17641 VkSubpassDescription subpass = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr };
17642
17643 VkSubpassDependency dep = { 0,
17644 0,
17645 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
17646 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
17647 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
17648 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
17649 VK_DEPENDENCY_BY_REGION_BIT };
17650
17651 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 1, &dep };
17652
17653 VkResult err;
17654 VkRenderPass rp;
17655 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
17656 ASSERT_VK_SUCCESS(err);
17657
17658 // A compatible framebuffer.
17659 VkImageObj image(m_device);
17660 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
17661 ASSERT_TRUE(image.initialized());
17662
17663 VkImageViewCreateInfo ivci = {
17664 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
17665 nullptr,
17666 0,
17667 image.handle(),
17668 VK_IMAGE_VIEW_TYPE_2D,
17669 VK_FORMAT_R8G8B8A8_UNORM,
17670 { VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
17671 VK_COMPONENT_SWIZZLE_IDENTITY },
17672 { VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 },
17673 };
17674 VkImageView view;
17675 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
17676 ASSERT_VK_SUCCESS(err);
17677
17678 VkFramebufferCreateInfo fci = { VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1 };
17679 VkFramebuffer fb;
17680 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
17681 ASSERT_VK_SUCCESS(err);
17682
17683 // Record a single command buffer which issues a pipeline barrier w/
17684 // image memory barrier for the attachment. This detects the previously
17685 // missing tracking of the subpass layout by throwing a validation error
17686 // if it doesn't occur.
17687 VkRenderPassBeginInfo rpbi = { VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb,{ { 0, 0 },{ 32, 32 } }, 0, nullptr };
17688 BeginCommandBuffer();
17689 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
17690
17691 VkImageMemoryBarrier imb = { VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,
17692 nullptr,
17693 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
17694 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
17695 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
17696 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
17697 VK_QUEUE_FAMILY_IGNORED,
17698 VK_QUEUE_FAMILY_IGNORED,
17699 image.handle(),
17700 { VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 } };
17701 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
17702 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_DEPENDENCY_BY_REGION_BIT, 0, nullptr, 0, nullptr, 1,
17703 &imb);
17704
17705 vkCmdEndRenderPass(m_commandBuffer->handle());
17706 m_errorMonitor->VerifyNotFound();
17707 EndCommandBuffer();
17708
17709 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
17710 vkDestroyRenderPass(m_device->device(), rp, nullptr);
17711 vkDestroyImageView(m_device->device(), view, nullptr);
17712}
17713
17714TEST_F(VkPositiveLayerTest, DepthStencilLayoutTransitionForDepthOnlyImageview) {
17715 TEST_DESCRIPTION("Validate that when an imageView of a depth/stencil image "
17716 "is used as a depth/stencil framebuffer attachment, the "
17717 "aspectMask is ignored and both depth and stencil image "
17718 "subresources are used.");
17719
17720 VkFormatProperties format_properties;
17721 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_D32_SFLOAT_S8_UINT, &format_properties);
17722 if (!(format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)) {
17723 return;
17724 }
17725
17726 m_errorMonitor->ExpectSuccess();
17727
17728 ASSERT_NO_FATAL_FAILURE(InitState());
17729
17730 VkAttachmentDescription attachment = { 0,
17731 VK_FORMAT_D32_SFLOAT_S8_UINT,
17732 VK_SAMPLE_COUNT_1_BIT,
17733 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
17734 VK_ATTACHMENT_STORE_OP_STORE,
17735 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
17736 VK_ATTACHMENT_STORE_OP_DONT_CARE,
17737 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
17738 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL };
17739
17740 VkAttachmentReference att_ref = { 0, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL };
17741
17742 VkSubpassDescription subpass = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, &att_ref, 0, nullptr };
17743
17744 VkSubpassDependency dep = { 0,
17745 0,
17746 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
17747 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
17748 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
17749 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
17750 VK_DEPENDENCY_BY_REGION_BIT};
17751
17752 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 1, &dep };
17753
17754 VkResult err;
17755 VkRenderPass rp;
17756 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
17757 ASSERT_VK_SUCCESS(err);
17758
17759 VkImageObj image(m_device);
17760 image.init_no_layout(32, 32, VK_FORMAT_D32_SFLOAT_S8_UINT,
17761 0x26, // usage
17762 VK_IMAGE_TILING_OPTIMAL, 0);
17763 ASSERT_TRUE(image.initialized());
17764 image.SetLayout(0x6, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL);
17765
17766 VkImageViewCreateInfo ivci = {
17767 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
17768 nullptr,
17769 0,
17770 image.handle(),
17771 VK_IMAGE_VIEW_TYPE_2D,
17772 VK_FORMAT_D32_SFLOAT_S8_UINT,
17773 { VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A },
17774 { 0x2, 0, 1, 0, 1 },
17775 };
17776 VkImageView view;
17777 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
17778 ASSERT_VK_SUCCESS(err);
17779
17780 VkFramebufferCreateInfo fci = { VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1 };
17781 VkFramebuffer fb;
17782 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
17783 ASSERT_VK_SUCCESS(err);
17784
17785 VkRenderPassBeginInfo rpbi = { VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb,{ { 0, 0 },{ 32, 32 } }, 0, nullptr };
17786 BeginCommandBuffer();
17787 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
17788
17789 VkImageMemoryBarrier imb = {};
17790 imb.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
17791 imb.pNext = nullptr;
17792 imb.srcAccessMask = VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
17793 imb.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
17794 imb.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
17795 imb.newLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
17796 imb.srcQueueFamilyIndex = 0;
17797 imb.dstQueueFamilyIndex = 0;
17798 imb.image = image.handle();
17799 imb.subresourceRange.aspectMask = 0x6;
17800 imb.subresourceRange.baseMipLevel = 0;
17801 imb.subresourceRange.levelCount = 0x1;
17802 imb.subresourceRange.baseArrayLayer = 0;
17803 imb.subresourceRange.layerCount = 0x1;
17804
17805 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
17806 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_DEPENDENCY_BY_REGION_BIT, 0, nullptr, 0, nullptr, 1,
17807 &imb);
17808
17809 vkCmdEndRenderPass(m_commandBuffer->handle());
17810 EndCommandBuffer();
17811 QueueCommandBuffer(false);
17812 m_errorMonitor->VerifyNotFound();
17813
17814 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
17815 vkDestroyRenderPass(m_device->device(), rp, nullptr);
17816 vkDestroyImageView(m_device->device(), view, nullptr);
17817}
17818
17819TEST_F(VkPositiveLayerTest, RenderPassTransitionsAttachmentUnused) {
17820 TEST_DESCRIPTION("Ensure that layout transitions work correctly without "
17821 "errors, when an attachment reference is "
17822 "VK_ATTACHMENT_UNUSED");
17823
17824 m_errorMonitor->ExpectSuccess();
17825
17826 ASSERT_NO_FATAL_FAILURE(InitState());
17827
17828 // A renderpass with no attachments
17829 VkAttachmentReference att_ref = { VK_ATTACHMENT_UNUSED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
17830
17831 VkSubpassDescription subpass = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr };
17832
17833 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 1, &subpass, 0, nullptr };
17834
17835 VkRenderPass rp;
17836 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
17837 ASSERT_VK_SUCCESS(err);
17838
17839 // A compatible framebuffer.
17840 VkFramebufferCreateInfo fci = { VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 0, nullptr, 32, 32, 1 };
17841 VkFramebuffer fb;
17842 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
17843 ASSERT_VK_SUCCESS(err);
17844
17845 // Record a command buffer which just begins and ends the renderpass. The
17846 // bug manifests in BeginRenderPass.
17847 VkRenderPassBeginInfo rpbi = { VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb,{ { 0, 0 },{ 32, 32 } }, 0, nullptr };
17848 BeginCommandBuffer();
17849 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
17850 vkCmdEndRenderPass(m_commandBuffer->handle());
17851 m_errorMonitor->VerifyNotFound();
17852 EndCommandBuffer();
17853
17854 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
17855 vkDestroyRenderPass(m_device->device(), rp, nullptr);
17856}
17857
17858// This is a positive test. No errors are expected.
17859TEST_F(VkPositiveLayerTest, StencilLoadOp) {
17860 TEST_DESCRIPTION("Create a stencil-only attachment with a LOAD_OP set to "
17861 "CLEAR. stencil[Load|Store]Op used to be ignored.");
17862 VkResult result = VK_SUCCESS;
17863 VkImageFormatProperties formatProps;
17864 vkGetPhysicalDeviceImageFormatProperties(gpu(), VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
17865 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT, 0,
17866 &formatProps);
17867 if (formatProps.maxExtent.width < 100 || formatProps.maxExtent.height < 100) {
17868 return;
17869 }
17870
17871 ASSERT_NO_FATAL_FAILURE(InitState());
17872 VkFormat depth_stencil_fmt = VK_FORMAT_D24_UNORM_S8_UINT;
17873 m_depthStencil->Init(m_device, 100, 100, depth_stencil_fmt,
17874 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT);
17875 VkAttachmentDescription att = {};
17876 VkAttachmentReference ref = {};
17877 att.format = depth_stencil_fmt;
17878 att.samples = VK_SAMPLE_COUNT_1_BIT;
17879 att.loadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
17880 att.storeOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
17881 att.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
17882 att.stencilStoreOp = VK_ATTACHMENT_STORE_OP_STORE;
17883 att.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
17884 att.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
17885
17886 VkClearValue clear;
17887 clear.depthStencil.depth = 1.0;
17888 clear.depthStencil.stencil = 0;
17889 ref.attachment = 0;
17890 ref.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
17891
17892 VkSubpassDescription subpass = {};
17893 subpass.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;
17894 subpass.flags = 0;
17895 subpass.inputAttachmentCount = 0;
17896 subpass.pInputAttachments = NULL;
17897 subpass.colorAttachmentCount = 0;
17898 subpass.pColorAttachments = NULL;
17899 subpass.pResolveAttachments = NULL;
17900 subpass.pDepthStencilAttachment = &ref;
17901 subpass.preserveAttachmentCount = 0;
17902 subpass.pPreserveAttachments = NULL;
17903
17904 VkRenderPass rp;
17905 VkRenderPassCreateInfo rp_info = {};
17906 rp_info.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
17907 rp_info.attachmentCount = 1;
17908 rp_info.pAttachments = &att;
17909 rp_info.subpassCount = 1;
17910 rp_info.pSubpasses = &subpass;
17911 result = vkCreateRenderPass(device(), &rp_info, NULL, &rp);
17912 ASSERT_VK_SUCCESS(result);
17913
17914 VkImageView *depthView = m_depthStencil->BindInfo();
17915 VkFramebufferCreateInfo fb_info = {};
17916 fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
17917 fb_info.pNext = NULL;
17918 fb_info.renderPass = rp;
17919 fb_info.attachmentCount = 1;
17920 fb_info.pAttachments = depthView;
17921 fb_info.width = 100;
17922 fb_info.height = 100;
17923 fb_info.layers = 1;
17924 VkFramebuffer fb;
17925 result = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
17926 ASSERT_VK_SUCCESS(result);
17927
17928 VkRenderPassBeginInfo rpbinfo = {};
17929 rpbinfo.clearValueCount = 1;
17930 rpbinfo.pClearValues = &clear;
17931 rpbinfo.pNext = NULL;
17932 rpbinfo.renderPass = rp;
17933 rpbinfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
17934 rpbinfo.renderArea.extent.width = 100;
17935 rpbinfo.renderArea.extent.height = 100;
17936 rpbinfo.renderArea.offset.x = 0;
17937 rpbinfo.renderArea.offset.y = 0;
17938 rpbinfo.framebuffer = fb;
17939
17940 VkFence fence = {};
17941 VkFenceCreateInfo fence_ci = {};
17942 fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
17943 fence_ci.pNext = nullptr;
17944 fence_ci.flags = 0;
17945 result = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fence);
17946 ASSERT_VK_SUCCESS(result);
17947
17948 m_commandBuffer->BeginCommandBuffer();
17949 m_commandBuffer->BeginRenderPass(rpbinfo);
17950 m_commandBuffer->EndRenderPass();
17951 m_commandBuffer->EndCommandBuffer();
17952 m_commandBuffer->QueueCommandBuffer(fence);
17953
17954 VkImageObj destImage(m_device);
17955 destImage.init(100, 100, depth_stencil_fmt, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
17956 VK_IMAGE_TILING_OPTIMAL, 0);
17957 VkImageMemoryBarrier barrier = {};
17958 VkImageSubresourceRange range;
17959 barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
17960 barrier.srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
17961 barrier.dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT;
17962 barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
17963 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
17964 barrier.image = m_depthStencil->handle();
17965 range.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
17966 range.baseMipLevel = 0;
17967 range.levelCount = 1;
17968 range.baseArrayLayer = 0;
17969 range.layerCount = 1;
17970 barrier.subresourceRange = range;
17971 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
17972 VkCommandBufferObj cmdbuf(m_device, m_commandPool);
17973 cmdbuf.BeginCommandBuffer();
17974 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
17975 &barrier);
17976 barrier.srcAccessMask = 0;
17977 barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
17978 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
17979 barrier.image = destImage.handle();
17980 barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
17981 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
17982 &barrier);
17983 VkImageCopy cregion;
17984 cregion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
17985 cregion.srcSubresource.mipLevel = 0;
17986 cregion.srcSubresource.baseArrayLayer = 0;
17987 cregion.srcSubresource.layerCount = 1;
17988 cregion.srcOffset.x = 0;
17989 cregion.srcOffset.y = 0;
17990 cregion.srcOffset.z = 0;
17991 cregion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
17992 cregion.dstSubresource.mipLevel = 0;
17993 cregion.dstSubresource.baseArrayLayer = 0;
17994 cregion.dstSubresource.layerCount = 1;
17995 cregion.dstOffset.x = 0;
17996 cregion.dstOffset.y = 0;
17997 cregion.dstOffset.z = 0;
17998 cregion.extent.width = 100;
17999 cregion.extent.height = 100;
18000 cregion.extent.depth = 1;
18001 cmdbuf.CopyImage(m_depthStencil->handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, destImage.handle(),
18002 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &cregion);
18003 cmdbuf.EndCommandBuffer();
18004
18005 VkSubmitInfo submit_info;
18006 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18007 submit_info.pNext = NULL;
18008 submit_info.waitSemaphoreCount = 0;
18009 submit_info.pWaitSemaphores = NULL;
18010 submit_info.pWaitDstStageMask = NULL;
18011 submit_info.commandBufferCount = 1;
18012 submit_info.pCommandBuffers = &cmdbuf.handle();
18013 submit_info.signalSemaphoreCount = 0;
18014 submit_info.pSignalSemaphores = NULL;
18015
18016 m_errorMonitor->ExpectSuccess();
18017 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
18018 m_errorMonitor->VerifyNotFound();
18019
18020 vkQueueWaitIdle(m_device->m_queue);
18021 vkDestroyFence(m_device->device(), fence, nullptr);
18022 vkDestroyRenderPass(m_device->device(), rp, nullptr);
18023 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
18024}
18025
18026// This is a positive test. No errors should be generated.
18027TEST_F(VkPositiveLayerTest, WaitEventThenSet) {
18028 TEST_DESCRIPTION("Wait on a event then set it after the wait has been submitted.");
18029
18030 m_errorMonitor->ExpectSuccess();
18031 ASSERT_NO_FATAL_FAILURE(InitState());
18032
18033 VkEvent event;
18034 VkEventCreateInfo event_create_info{};
18035 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
18036 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
18037
18038 VkCommandPool command_pool;
18039 VkCommandPoolCreateInfo pool_create_info{};
18040 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18041 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18042 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18043 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18044
18045 VkCommandBuffer command_buffer;
18046 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18047 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18048 command_buffer_allocate_info.commandPool = command_pool;
18049 command_buffer_allocate_info.commandBufferCount = 1;
18050 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18051 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
18052
18053 VkQueue queue = VK_NULL_HANDLE;
18054 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
18055
18056 {
18057 VkCommandBufferBeginInfo begin_info{};
18058 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18059 vkBeginCommandBuffer(command_buffer, &begin_info);
18060
18061 vkCmdWaitEvents(command_buffer, 1, &event, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, nullptr, 0,
18062 nullptr, 0, nullptr);
18063 vkCmdResetEvent(command_buffer, event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
18064 vkEndCommandBuffer(command_buffer);
18065 }
18066 {
18067 VkSubmitInfo submit_info{};
18068 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18069 submit_info.commandBufferCount = 1;
18070 submit_info.pCommandBuffers = &command_buffer;
18071 submit_info.signalSemaphoreCount = 0;
18072 submit_info.pSignalSemaphores = nullptr;
18073 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
18074 }
18075 { vkSetEvent(m_device->device(), event); }
18076
18077 vkQueueWaitIdle(queue);
18078
18079 vkDestroyEvent(m_device->device(), event, nullptr);
18080 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
18081 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18082
18083 m_errorMonitor->VerifyNotFound();
18084}
18085// This is a positive test. No errors should be generated.
18086TEST_F(VkPositiveLayerTest, QueryAndCopySecondaryCommandBuffers) {
18087 TEST_DESCRIPTION("Issue a query on a secondary command buffery and copy it on a primary.");
18088
18089 ASSERT_NO_FATAL_FAILURE(InitState());
18090 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
18091 return;
18092
18093 m_errorMonitor->ExpectSuccess();
18094
18095 VkQueryPool query_pool;
18096 VkQueryPoolCreateInfo query_pool_create_info{};
18097 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
18098 query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP;
18099 query_pool_create_info.queryCount = 1;
18100 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
18101
18102 VkCommandPool command_pool;
18103 VkCommandPoolCreateInfo pool_create_info{};
18104 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18105 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18106 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18107 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18108
18109 VkCommandBuffer command_buffer;
18110 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18111 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18112 command_buffer_allocate_info.commandPool = command_pool;
18113 command_buffer_allocate_info.commandBufferCount = 1;
18114 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18115 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
18116
18117 VkCommandBuffer secondary_command_buffer;
18118 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
18119 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer);
18120
18121 VkQueue queue = VK_NULL_HANDLE;
18122 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
18123
18124 uint32_t qfi = 0;
18125 VkBufferCreateInfo buff_create_info = {};
18126 buff_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
18127 buff_create_info.size = 1024;
18128 buff_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
18129 buff_create_info.queueFamilyIndexCount = 1;
18130 buff_create_info.pQueueFamilyIndices = &qfi;
18131
18132 VkResult err;
18133 VkBuffer buffer;
18134 err = vkCreateBuffer(m_device->device(), &buff_create_info, NULL, &buffer);
18135 ASSERT_VK_SUCCESS(err);
18136 VkMemoryAllocateInfo mem_alloc = {};
18137 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18138 mem_alloc.pNext = NULL;
18139 mem_alloc.allocationSize = 1024;
18140 mem_alloc.memoryTypeIndex = 0;
18141
18142 VkMemoryRequirements memReqs;
18143 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
18144 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
18145 if (!pass) {
18146 vkDestroyBuffer(m_device->device(), buffer, NULL);
18147 return;
18148 }
18149
18150 VkDeviceMemory mem;
18151 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
18152 ASSERT_VK_SUCCESS(err);
18153 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
18154 ASSERT_VK_SUCCESS(err);
18155
18156 VkCommandBufferInheritanceInfo hinfo = {};
18157 hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
18158 hinfo.renderPass = VK_NULL_HANDLE;
18159 hinfo.subpass = 0;
18160 hinfo.framebuffer = VK_NULL_HANDLE;
18161 hinfo.occlusionQueryEnable = VK_FALSE;
18162 hinfo.queryFlags = 0;
18163 hinfo.pipelineStatistics = 0;
18164
18165 {
18166 VkCommandBufferBeginInfo begin_info{};
18167 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18168 begin_info.pInheritanceInfo = &hinfo;
18169 vkBeginCommandBuffer(secondary_command_buffer, &begin_info);
18170
18171 vkCmdResetQueryPool(secondary_command_buffer, query_pool, 0, 1);
18172 vkCmdWriteTimestamp(secondary_command_buffer, VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0);
18173
18174 vkEndCommandBuffer(secondary_command_buffer);
18175
18176 begin_info.pInheritanceInfo = nullptr;
18177 vkBeginCommandBuffer(command_buffer, &begin_info);
18178
18179 vkCmdExecuteCommands(command_buffer, 1, &secondary_command_buffer);
18180 vkCmdCopyQueryPoolResults(command_buffer, query_pool, 0, 1, buffer, 0, 0, 0);
18181
18182 vkEndCommandBuffer(command_buffer);
18183 }
18184 {
18185 VkSubmitInfo submit_info{};
18186 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18187 submit_info.commandBufferCount = 1;
18188 submit_info.pCommandBuffers = &command_buffer;
18189 submit_info.signalSemaphoreCount = 0;
18190 submit_info.pSignalSemaphores = nullptr;
18191 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
18192 }
18193
18194 vkQueueWaitIdle(queue);
18195
18196 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
18197 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
18198 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &secondary_command_buffer);
18199 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18200 vkDestroyBuffer(m_device->device(), buffer, NULL);
18201 vkFreeMemory(m_device->device(), mem, NULL);
18202
18203 m_errorMonitor->VerifyNotFound();
18204}
18205
18206// This is a positive test. No errors should be generated.
18207TEST_F(VkPositiveLayerTest, QueryAndCopyMultipleCommandBuffers) {
18208 TEST_DESCRIPTION("Issue a query and copy from it on a second command buffer.");
18209
18210 ASSERT_NO_FATAL_FAILURE(InitState());
18211 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
18212 return;
18213
18214 m_errorMonitor->ExpectSuccess();
18215
18216 VkQueryPool query_pool;
18217 VkQueryPoolCreateInfo query_pool_create_info{};
18218 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
18219 query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP;
18220 query_pool_create_info.queryCount = 1;
18221 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
18222
18223 VkCommandPool command_pool;
18224 VkCommandPoolCreateInfo pool_create_info{};
18225 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18226 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18227 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18228 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18229
18230 VkCommandBuffer command_buffer[2];
18231 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18232 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18233 command_buffer_allocate_info.commandPool = command_pool;
18234 command_buffer_allocate_info.commandBufferCount = 2;
18235 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18236 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18237
18238 VkQueue queue = VK_NULL_HANDLE;
18239 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
18240
18241 uint32_t qfi = 0;
18242 VkBufferCreateInfo buff_create_info = {};
18243 buff_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
18244 buff_create_info.size = 1024;
18245 buff_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
18246 buff_create_info.queueFamilyIndexCount = 1;
18247 buff_create_info.pQueueFamilyIndices = &qfi;
18248
18249 VkResult err;
18250 VkBuffer buffer;
18251 err = vkCreateBuffer(m_device->device(), &buff_create_info, NULL, &buffer);
18252 ASSERT_VK_SUCCESS(err);
18253 VkMemoryAllocateInfo mem_alloc = {};
18254 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18255 mem_alloc.pNext = NULL;
18256 mem_alloc.allocationSize = 1024;
18257 mem_alloc.memoryTypeIndex = 0;
18258
18259 VkMemoryRequirements memReqs;
18260 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
18261 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
18262 if (!pass) {
18263 vkDestroyBuffer(m_device->device(), buffer, NULL);
18264 return;
18265 }
18266
18267 VkDeviceMemory mem;
18268 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
18269 ASSERT_VK_SUCCESS(err);
18270 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
18271 ASSERT_VK_SUCCESS(err);
18272
18273 {
18274 VkCommandBufferBeginInfo begin_info{};
18275 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18276 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18277
18278 vkCmdResetQueryPool(command_buffer[0], query_pool, 0, 1);
18279 vkCmdWriteTimestamp(command_buffer[0], VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0);
18280
18281 vkEndCommandBuffer(command_buffer[0]);
18282
18283 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18284
18285 vkCmdCopyQueryPoolResults(command_buffer[1], query_pool, 0, 1, buffer, 0, 0, 0);
18286
18287 vkEndCommandBuffer(command_buffer[1]);
18288 }
18289 {
18290 VkSubmitInfo submit_info{};
18291 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18292 submit_info.commandBufferCount = 2;
18293 submit_info.pCommandBuffers = command_buffer;
18294 submit_info.signalSemaphoreCount = 0;
18295 submit_info.pSignalSemaphores = nullptr;
18296 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
18297 }
18298
18299 vkQueueWaitIdle(queue);
18300
18301 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
18302 vkFreeCommandBuffers(m_device->device(), command_pool, 2, command_buffer);
18303 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18304 vkDestroyBuffer(m_device->device(), buffer, NULL);
18305 vkFreeMemory(m_device->device(), mem, NULL);
18306
18307 m_errorMonitor->VerifyNotFound();
18308}
18309
Tony Barbourc46924f2016-11-04 11:49:52 -060018310TEST_F(VkLayerTest, ResetEventThenSet) {
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018311 TEST_DESCRIPTION("Reset an event then set it after the reset has been submitted.");
18312
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018313 ASSERT_NO_FATAL_FAILURE(InitState());
18314 VkEvent event;
18315 VkEventCreateInfo event_create_info{};
18316 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
18317 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
18318
18319 VkCommandPool command_pool;
18320 VkCommandPoolCreateInfo pool_create_info{};
18321 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18322 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18323 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18324 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18325
18326 VkCommandBuffer command_buffer;
18327 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18328 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18329 command_buffer_allocate_info.commandPool = command_pool;
18330 command_buffer_allocate_info.commandBufferCount = 1;
18331 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18332 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
18333
18334 VkQueue queue = VK_NULL_HANDLE;
18335 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
18336
18337 {
18338 VkCommandBufferBeginInfo begin_info{};
18339 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18340 vkBeginCommandBuffer(command_buffer, &begin_info);
18341
18342 vkCmdResetEvent(command_buffer, event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018343 vkEndCommandBuffer(command_buffer);
18344 }
18345 {
18346 VkSubmitInfo submit_info{};
18347 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18348 submit_info.commandBufferCount = 1;
18349 submit_info.pCommandBuffers = &command_buffer;
18350 submit_info.signalSemaphoreCount = 0;
18351 submit_info.pSignalSemaphores = nullptr;
18352 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
18353 }
18354 {
18355 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is already in use by a "
18356 "command buffer.");
18357 vkSetEvent(m_device->device(), event);
18358 m_errorMonitor->VerifyFound();
18359 }
18360
18361 vkQueueWaitIdle(queue);
18362
18363 vkDestroyEvent(m_device->device(), event, nullptr);
18364 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
18365 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18366}
18367
18368// This is a positive test. No errors should be generated.
18369TEST_F(VkPositiveLayerTest, TwoFencesThreeFrames) {
18370 TEST_DESCRIPTION("Two command buffers with two separate fences are each "
18371 "run through a Submit & WaitForFences cycle 3 times. This "
18372 "previously revealed a bug so running this positive test "
18373 "to prevent a regression.");
18374 m_errorMonitor->ExpectSuccess();
18375
18376 ASSERT_NO_FATAL_FAILURE(InitState());
18377 VkQueue queue = VK_NULL_HANDLE;
18378 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
18379
18380 static const uint32_t NUM_OBJECTS = 2;
18381 static const uint32_t NUM_FRAMES = 3;
18382 VkCommandBuffer cmd_buffers[NUM_OBJECTS] = {};
18383 VkFence fences[NUM_OBJECTS] = {};
18384
18385 VkCommandPool cmd_pool;
18386 VkCommandPoolCreateInfo cmd_pool_ci = {};
18387 cmd_pool_ci.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18388 cmd_pool_ci.queueFamilyIndex = m_device->graphics_queue_node_index_;
18389 cmd_pool_ci.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18390 VkResult err = vkCreateCommandPool(m_device->device(), &cmd_pool_ci, nullptr, &cmd_pool);
18391 ASSERT_VK_SUCCESS(err);
18392
18393 VkCommandBufferAllocateInfo cmd_buf_info = {};
18394 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18395 cmd_buf_info.commandPool = cmd_pool;
18396 cmd_buf_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18397 cmd_buf_info.commandBufferCount = 1;
18398
18399 VkFenceCreateInfo fence_ci = {};
18400 fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18401 fence_ci.pNext = nullptr;
18402 fence_ci.flags = 0;
18403
18404 for (uint32_t i = 0; i < NUM_OBJECTS; ++i) {
18405 err = vkAllocateCommandBuffers(m_device->device(), &cmd_buf_info, &cmd_buffers[i]);
18406 ASSERT_VK_SUCCESS(err);
18407 err = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fences[i]);
18408 ASSERT_VK_SUCCESS(err);
18409 }
18410
18411 for (uint32_t frame = 0; frame < NUM_FRAMES; ++frame) {
18412 for (uint32_t obj = 0; obj < NUM_OBJECTS; ++obj) {
18413 // Create empty cmd buffer
18414 VkCommandBufferBeginInfo cmdBufBeginDesc = {};
18415 cmdBufBeginDesc.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18416
18417 err = vkBeginCommandBuffer(cmd_buffers[obj], &cmdBufBeginDesc);
18418 ASSERT_VK_SUCCESS(err);
18419 err = vkEndCommandBuffer(cmd_buffers[obj]);
18420 ASSERT_VK_SUCCESS(err);
18421
18422 VkSubmitInfo submit_info = {};
18423 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18424 submit_info.commandBufferCount = 1;
18425 submit_info.pCommandBuffers = &cmd_buffers[obj];
18426 // Submit cmd buffer and wait for fence
18427 err = vkQueueSubmit(queue, 1, &submit_info, fences[obj]);
18428 ASSERT_VK_SUCCESS(err);
18429 err = vkWaitForFences(m_device->device(), 1, &fences[obj], VK_TRUE, UINT64_MAX);
18430 ASSERT_VK_SUCCESS(err);
18431 err = vkResetFences(m_device->device(), 1, &fences[obj]);
18432 ASSERT_VK_SUCCESS(err);
18433 }
18434 }
18435 m_errorMonitor->VerifyNotFound();
18436 vkDestroyCommandPool(m_device->device(), cmd_pool, NULL);
18437 for (uint32_t i = 0; i < NUM_OBJECTS; ++i) {
18438 vkDestroyFence(m_device->device(), fences[i], nullptr);
18439 }
18440}
18441// This is a positive test. No errors should be generated.
18442TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWI) {
18443
18444 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
18445 "submitted on separate queues followed by a QueueWaitIdle.");
18446
18447 ASSERT_NO_FATAL_FAILURE(InitState());
18448 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
18449 return;
18450
18451 m_errorMonitor->ExpectSuccess();
18452
18453 VkSemaphore semaphore;
18454 VkSemaphoreCreateInfo semaphore_create_info{};
18455 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
18456 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
18457
18458 VkCommandPool command_pool;
18459 VkCommandPoolCreateInfo pool_create_info{};
18460 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18461 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18462 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18463 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18464
18465 VkCommandBuffer command_buffer[2];
18466 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18467 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18468 command_buffer_allocate_info.commandPool = command_pool;
18469 command_buffer_allocate_info.commandBufferCount = 2;
18470 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18471 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18472
18473 VkQueue queue = VK_NULL_HANDLE;
18474 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
18475
18476 {
18477 VkCommandBufferBeginInfo begin_info{};
18478 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18479 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18480
18481 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
18482 nullptr, 0, nullptr, 0, nullptr);
18483
18484 VkViewport viewport{};
18485 viewport.maxDepth = 1.0f;
18486 viewport.minDepth = 0.0f;
18487 viewport.width = 512;
18488 viewport.height = 512;
18489 viewport.x = 0;
18490 viewport.y = 0;
18491 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
18492 vkEndCommandBuffer(command_buffer[0]);
18493 }
18494 {
18495 VkCommandBufferBeginInfo begin_info{};
18496 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18497 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18498
18499 VkViewport viewport{};
18500 viewport.maxDepth = 1.0f;
18501 viewport.minDepth = 0.0f;
18502 viewport.width = 512;
18503 viewport.height = 512;
18504 viewport.x = 0;
18505 viewport.y = 0;
18506 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
18507 vkEndCommandBuffer(command_buffer[1]);
18508 }
18509 {
18510 VkSubmitInfo submit_info{};
18511 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18512 submit_info.commandBufferCount = 1;
18513 submit_info.pCommandBuffers = &command_buffer[0];
18514 submit_info.signalSemaphoreCount = 1;
18515 submit_info.pSignalSemaphores = &semaphore;
18516 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
18517 }
18518 {
18519 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
18520 VkSubmitInfo submit_info{};
18521 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18522 submit_info.commandBufferCount = 1;
18523 submit_info.pCommandBuffers = &command_buffer[1];
18524 submit_info.waitSemaphoreCount = 1;
18525 submit_info.pWaitSemaphores = &semaphore;
18526 submit_info.pWaitDstStageMask = flags;
18527 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
18528 }
18529
18530 vkQueueWaitIdle(m_device->m_queue);
18531
18532 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
18533 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
18534 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18535
18536 m_errorMonitor->VerifyNotFound();
18537}
18538
18539// This is a positive test. No errors should be generated.
18540TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWIFence) {
18541
18542 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
18543 "submitted on separate queues, the second having a fence"
18544 "followed by a QueueWaitIdle.");
18545
18546 ASSERT_NO_FATAL_FAILURE(InitState());
18547 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
18548 return;
18549
18550 m_errorMonitor->ExpectSuccess();
18551
18552 VkFence fence;
18553 VkFenceCreateInfo fence_create_info{};
18554 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18555 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
18556
18557 VkSemaphore semaphore;
18558 VkSemaphoreCreateInfo semaphore_create_info{};
18559 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
18560 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
18561
18562 VkCommandPool command_pool;
18563 VkCommandPoolCreateInfo pool_create_info{};
18564 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18565 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18566 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18567 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18568
18569 VkCommandBuffer command_buffer[2];
18570 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18571 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18572 command_buffer_allocate_info.commandPool = command_pool;
18573 command_buffer_allocate_info.commandBufferCount = 2;
18574 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18575 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18576
18577 VkQueue queue = VK_NULL_HANDLE;
18578 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
18579
18580 {
18581 VkCommandBufferBeginInfo begin_info{};
18582 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18583 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18584
18585 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
18586 nullptr, 0, nullptr, 0, nullptr);
18587
18588 VkViewport viewport{};
18589 viewport.maxDepth = 1.0f;
18590 viewport.minDepth = 0.0f;
18591 viewport.width = 512;
18592 viewport.height = 512;
18593 viewport.x = 0;
18594 viewport.y = 0;
18595 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
18596 vkEndCommandBuffer(command_buffer[0]);
18597 }
18598 {
18599 VkCommandBufferBeginInfo begin_info{};
18600 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18601 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18602
18603 VkViewport viewport{};
18604 viewport.maxDepth = 1.0f;
18605 viewport.minDepth = 0.0f;
18606 viewport.width = 512;
18607 viewport.height = 512;
18608 viewport.x = 0;
18609 viewport.y = 0;
18610 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
18611 vkEndCommandBuffer(command_buffer[1]);
18612 }
18613 {
18614 VkSubmitInfo submit_info{};
18615 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18616 submit_info.commandBufferCount = 1;
18617 submit_info.pCommandBuffers = &command_buffer[0];
18618 submit_info.signalSemaphoreCount = 1;
18619 submit_info.pSignalSemaphores = &semaphore;
18620 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
18621 }
18622 {
18623 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
18624 VkSubmitInfo submit_info{};
18625 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18626 submit_info.commandBufferCount = 1;
18627 submit_info.pCommandBuffers = &command_buffer[1];
18628 submit_info.waitSemaphoreCount = 1;
18629 submit_info.pWaitSemaphores = &semaphore;
18630 submit_info.pWaitDstStageMask = flags;
18631 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
18632 }
18633
18634 vkQueueWaitIdle(m_device->m_queue);
18635
18636 vkDestroyFence(m_device->device(), fence, nullptr);
18637 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
18638 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
18639 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18640
18641 m_errorMonitor->VerifyNotFound();
18642}
18643
18644// This is a positive test. No errors should be generated.
18645TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceTwoWFF) {
18646
18647 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
18648 "submitted on separate queues, the second having a fence"
18649 "followed by two consecutive WaitForFences calls on the same fence.");
18650
18651 ASSERT_NO_FATAL_FAILURE(InitState());
18652 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
18653 return;
18654
18655 m_errorMonitor->ExpectSuccess();
18656
18657 VkFence fence;
18658 VkFenceCreateInfo fence_create_info{};
18659 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18660 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
18661
18662 VkSemaphore semaphore;
18663 VkSemaphoreCreateInfo semaphore_create_info{};
18664 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
18665 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
18666
18667 VkCommandPool command_pool;
18668 VkCommandPoolCreateInfo pool_create_info{};
18669 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18670 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18671 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18672 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18673
18674 VkCommandBuffer command_buffer[2];
18675 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18676 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18677 command_buffer_allocate_info.commandPool = command_pool;
18678 command_buffer_allocate_info.commandBufferCount = 2;
18679 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18680 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18681
18682 VkQueue queue = VK_NULL_HANDLE;
18683 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
18684
18685 {
18686 VkCommandBufferBeginInfo begin_info{};
18687 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18688 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18689
18690 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
18691 nullptr, 0, nullptr, 0, nullptr);
18692
18693 VkViewport viewport{};
18694 viewport.maxDepth = 1.0f;
18695 viewport.minDepth = 0.0f;
18696 viewport.width = 512;
18697 viewport.height = 512;
18698 viewport.x = 0;
18699 viewport.y = 0;
18700 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
18701 vkEndCommandBuffer(command_buffer[0]);
18702 }
18703 {
18704 VkCommandBufferBeginInfo begin_info{};
18705 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18706 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18707
18708 VkViewport viewport{};
18709 viewport.maxDepth = 1.0f;
18710 viewport.minDepth = 0.0f;
18711 viewport.width = 512;
18712 viewport.height = 512;
18713 viewport.x = 0;
18714 viewport.y = 0;
18715 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
18716 vkEndCommandBuffer(command_buffer[1]);
18717 }
18718 {
18719 VkSubmitInfo submit_info{};
18720 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18721 submit_info.commandBufferCount = 1;
18722 submit_info.pCommandBuffers = &command_buffer[0];
18723 submit_info.signalSemaphoreCount = 1;
18724 submit_info.pSignalSemaphores = &semaphore;
18725 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
18726 }
18727 {
18728 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
18729 VkSubmitInfo submit_info{};
18730 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18731 submit_info.commandBufferCount = 1;
18732 submit_info.pCommandBuffers = &command_buffer[1];
18733 submit_info.waitSemaphoreCount = 1;
18734 submit_info.pWaitSemaphores = &semaphore;
18735 submit_info.pWaitDstStageMask = flags;
18736 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
18737 }
18738
18739 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
18740 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
18741
18742 vkDestroyFence(m_device->device(), fence, nullptr);
18743 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
18744 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
18745 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18746
18747 m_errorMonitor->VerifyNotFound();
18748}
18749
18750TEST_F(VkPositiveLayerTest, TwoQueuesEnsureCorrectRetirementWithWorkStolen) {
18751
18752 ASSERT_NO_FATAL_FAILURE(InitState());
18753 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) {
18754 printf("Test requires two queues, skipping\n");
18755 return;
18756 }
18757
18758 VkResult err;
18759
18760 m_errorMonitor->ExpectSuccess();
18761
18762 VkQueue q0 = m_device->m_queue;
18763 VkQueue q1 = nullptr;
18764 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &q1);
18765 ASSERT_NE(q1, nullptr);
18766
18767 // An (empty) command buffer. We must have work in the first submission --
18768 // the layer treats unfenced work differently from fenced work.
18769 VkCommandPoolCreateInfo cpci = { VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, nullptr, 0, 0 };
18770 VkCommandPool pool;
18771 err = vkCreateCommandPool(m_device->device(), &cpci, nullptr, &pool);
18772 ASSERT_VK_SUCCESS(err);
18773 VkCommandBufferAllocateInfo cbai = { VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, nullptr, pool,
18774 VK_COMMAND_BUFFER_LEVEL_PRIMARY, 1 };
18775 VkCommandBuffer cb;
18776 err = vkAllocateCommandBuffers(m_device->device(), &cbai, &cb);
18777 ASSERT_VK_SUCCESS(err);
18778 VkCommandBufferBeginInfo cbbi = { VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr, 0, nullptr };
18779 err = vkBeginCommandBuffer(cb, &cbbi);
18780 ASSERT_VK_SUCCESS(err);
18781 err = vkEndCommandBuffer(cb);
18782 ASSERT_VK_SUCCESS(err);
18783
18784 // A semaphore
18785 VkSemaphoreCreateInfo sci = { VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0 };
18786 VkSemaphore s;
18787 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s);
18788 ASSERT_VK_SUCCESS(err);
18789
18790 // First submission, to q0
18791 VkSubmitInfo s0 = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 1, &cb, 1, &s };
18792
18793 err = vkQueueSubmit(q0, 1, &s0, VK_NULL_HANDLE);
18794 ASSERT_VK_SUCCESS(err);
18795
18796 // Second submission, to q1, waiting on s
18797 VkFlags waitmask = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT; // doesn't really matter what this value is.
18798 VkSubmitInfo s1 = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 1, &s, &waitmask, 0, nullptr, 0, nullptr };
18799
18800 err = vkQueueSubmit(q1, 1, &s1, VK_NULL_HANDLE);
18801 ASSERT_VK_SUCCESS(err);
18802
18803 // Wait for q0 idle
18804 err = vkQueueWaitIdle(q0);
18805 ASSERT_VK_SUCCESS(err);
18806
18807 // Command buffer should have been completed (it was on q0); reset the pool.
18808 vkFreeCommandBuffers(m_device->device(), pool, 1, &cb);
18809
18810 m_errorMonitor->VerifyNotFound();
18811
18812 // Force device completely idle and clean up resources
18813 vkDeviceWaitIdle(m_device->device());
18814 vkDestroyCommandPool(m_device->device(), pool, nullptr);
18815 vkDestroySemaphore(m_device->device(), s, nullptr);
18816}
18817
18818// This is a positive test. No errors should be generated.
18819TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFence) {
18820
18821 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
18822 "submitted on separate queues, the second having a fence, "
18823 "followed by a WaitForFences call.");
18824
18825 ASSERT_NO_FATAL_FAILURE(InitState());
18826 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
18827 return;
18828
18829 m_errorMonitor->ExpectSuccess();
18830
18831 ASSERT_NO_FATAL_FAILURE(InitState());
18832 VkFence fence;
18833 VkFenceCreateInfo fence_create_info{};
18834 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18835 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
18836
18837 VkSemaphore semaphore;
18838 VkSemaphoreCreateInfo semaphore_create_info{};
18839 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
18840 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
18841
18842 VkCommandPool command_pool;
18843 VkCommandPoolCreateInfo pool_create_info{};
18844 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18845 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18846 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18847 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18848
18849 VkCommandBuffer command_buffer[2];
18850 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18851 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18852 command_buffer_allocate_info.commandPool = command_pool;
18853 command_buffer_allocate_info.commandBufferCount = 2;
18854 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18855 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18856
18857 VkQueue queue = VK_NULL_HANDLE;
18858 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
18859
18860 {
18861 VkCommandBufferBeginInfo begin_info{};
18862 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18863 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18864
18865 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
18866 nullptr, 0, nullptr, 0, nullptr);
18867
18868 VkViewport viewport{};
18869 viewport.maxDepth = 1.0f;
18870 viewport.minDepth = 0.0f;
18871 viewport.width = 512;
18872 viewport.height = 512;
18873 viewport.x = 0;
18874 viewport.y = 0;
18875 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
18876 vkEndCommandBuffer(command_buffer[0]);
18877 }
18878 {
18879 VkCommandBufferBeginInfo begin_info{};
18880 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18881 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18882
18883 VkViewport viewport{};
18884 viewport.maxDepth = 1.0f;
18885 viewport.minDepth = 0.0f;
18886 viewport.width = 512;
18887 viewport.height = 512;
18888 viewport.x = 0;
18889 viewport.y = 0;
18890 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
18891 vkEndCommandBuffer(command_buffer[1]);
18892 }
18893 {
18894 VkSubmitInfo submit_info{};
18895 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18896 submit_info.commandBufferCount = 1;
18897 submit_info.pCommandBuffers = &command_buffer[0];
18898 submit_info.signalSemaphoreCount = 1;
18899 submit_info.pSignalSemaphores = &semaphore;
18900 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
18901 }
18902 {
18903 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
18904 VkSubmitInfo submit_info{};
18905 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18906 submit_info.commandBufferCount = 1;
18907 submit_info.pCommandBuffers = &command_buffer[1];
18908 submit_info.waitSemaphoreCount = 1;
18909 submit_info.pWaitSemaphores = &semaphore;
18910 submit_info.pWaitDstStageMask = flags;
18911 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
18912 }
18913
18914 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
18915
18916 vkDestroyFence(m_device->device(), fence, nullptr);
18917 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
18918 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
18919 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18920
18921 m_errorMonitor->VerifyNotFound();
18922}
18923
18924// This is a positive test. No errors should be generated.
18925TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueWithSemaphoreAndOneFence) {
18926
18927 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
18928 "on the same queue, sharing a signal/wait semaphore, the "
18929 "second having a fence, "
18930 "followed by a WaitForFences call.");
18931
18932 m_errorMonitor->ExpectSuccess();
18933
18934 ASSERT_NO_FATAL_FAILURE(InitState());
18935 VkFence fence;
18936 VkFenceCreateInfo fence_create_info{};
18937 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18938 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
18939
18940 VkSemaphore semaphore;
18941 VkSemaphoreCreateInfo semaphore_create_info{};
18942 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
18943 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
18944
18945 VkCommandPool command_pool;
18946 VkCommandPoolCreateInfo pool_create_info{};
18947 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18948 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18949 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18950 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18951
18952 VkCommandBuffer command_buffer[2];
18953 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18954 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18955 command_buffer_allocate_info.commandPool = command_pool;
18956 command_buffer_allocate_info.commandBufferCount = 2;
18957 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18958 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18959
18960 {
18961 VkCommandBufferBeginInfo begin_info{};
18962 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18963 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18964
18965 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
18966 nullptr, 0, nullptr, 0, nullptr);
18967
18968 VkViewport viewport{};
18969 viewport.maxDepth = 1.0f;
18970 viewport.minDepth = 0.0f;
18971 viewport.width = 512;
18972 viewport.height = 512;
18973 viewport.x = 0;
18974 viewport.y = 0;
18975 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
18976 vkEndCommandBuffer(command_buffer[0]);
18977 }
18978 {
18979 VkCommandBufferBeginInfo begin_info{};
18980 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18981 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18982
18983 VkViewport viewport{};
18984 viewport.maxDepth = 1.0f;
18985 viewport.minDepth = 0.0f;
18986 viewport.width = 512;
18987 viewport.height = 512;
18988 viewport.x = 0;
18989 viewport.y = 0;
18990 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
18991 vkEndCommandBuffer(command_buffer[1]);
18992 }
18993 {
18994 VkSubmitInfo submit_info{};
18995 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18996 submit_info.commandBufferCount = 1;
18997 submit_info.pCommandBuffers = &command_buffer[0];
18998 submit_info.signalSemaphoreCount = 1;
18999 submit_info.pSignalSemaphores = &semaphore;
19000 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
19001 }
19002 {
19003 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
19004 VkSubmitInfo submit_info{};
19005 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19006 submit_info.commandBufferCount = 1;
19007 submit_info.pCommandBuffers = &command_buffer[1];
19008 submit_info.waitSemaphoreCount = 1;
19009 submit_info.pWaitSemaphores = &semaphore;
19010 submit_info.pWaitDstStageMask = flags;
19011 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
19012 }
19013
19014 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
19015
19016 vkDestroyFence(m_device->device(), fence, nullptr);
19017 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
19018 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
19019 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
19020
19021 m_errorMonitor->VerifyNotFound();
19022}
19023
19024// This is a positive test. No errors should be generated.
19025TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueNullQueueSubmitWithFence) {
19026
19027 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
19028 "on the same queue, no fences, followed by a third QueueSubmit with NO "
19029 "SubmitInfos but with a fence, followed by a WaitForFences call.");
19030
19031 m_errorMonitor->ExpectSuccess();
19032
19033 ASSERT_NO_FATAL_FAILURE(InitState());
19034 VkFence fence;
19035 VkFenceCreateInfo fence_create_info{};
19036 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
19037 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
19038
19039 VkCommandPool command_pool;
19040 VkCommandPoolCreateInfo pool_create_info{};
19041 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
19042 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
19043 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
19044 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
19045
19046 VkCommandBuffer command_buffer[2];
19047 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
19048 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
19049 command_buffer_allocate_info.commandPool = command_pool;
19050 command_buffer_allocate_info.commandBufferCount = 2;
19051 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
19052 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
19053
19054 {
19055 VkCommandBufferBeginInfo begin_info{};
19056 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19057 vkBeginCommandBuffer(command_buffer[0], &begin_info);
19058
19059 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
19060 nullptr, 0, nullptr, 0, nullptr);
19061
19062 VkViewport viewport{};
19063 viewport.maxDepth = 1.0f;
19064 viewport.minDepth = 0.0f;
19065 viewport.width = 512;
19066 viewport.height = 512;
19067 viewport.x = 0;
19068 viewport.y = 0;
19069 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
19070 vkEndCommandBuffer(command_buffer[0]);
19071 }
19072 {
19073 VkCommandBufferBeginInfo begin_info{};
19074 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19075 vkBeginCommandBuffer(command_buffer[1], &begin_info);
19076
19077 VkViewport viewport{};
19078 viewport.maxDepth = 1.0f;
19079 viewport.minDepth = 0.0f;
19080 viewport.width = 512;
19081 viewport.height = 512;
19082 viewport.x = 0;
19083 viewport.y = 0;
19084 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
19085 vkEndCommandBuffer(command_buffer[1]);
19086 }
19087 {
19088 VkSubmitInfo submit_info{};
19089 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19090 submit_info.commandBufferCount = 1;
19091 submit_info.pCommandBuffers = &command_buffer[0];
19092 submit_info.signalSemaphoreCount = 0;
19093 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
19094 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
19095 }
19096 {
19097 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
19098 VkSubmitInfo submit_info{};
19099 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19100 submit_info.commandBufferCount = 1;
19101 submit_info.pCommandBuffers = &command_buffer[1];
19102 submit_info.waitSemaphoreCount = 0;
19103 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
19104 submit_info.pWaitDstStageMask = flags;
19105 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
19106 }
19107
19108 vkQueueSubmit(m_device->m_queue, 0, NULL, fence);
19109
19110 VkResult err = vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
19111 ASSERT_VK_SUCCESS(err);
19112
19113 vkDestroyFence(m_device->device(), fence, nullptr);
19114 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
19115 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
19116
19117 m_errorMonitor->VerifyNotFound();
19118}
19119
19120// This is a positive test. No errors should be generated.
19121TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueOneFence) {
19122
19123 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
19124 "on the same queue, the second having a fence, followed "
19125 "by a WaitForFences call.");
19126
19127 m_errorMonitor->ExpectSuccess();
19128
19129 ASSERT_NO_FATAL_FAILURE(InitState());
19130 VkFence fence;
19131 VkFenceCreateInfo fence_create_info{};
19132 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
19133 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
19134
19135 VkCommandPool command_pool;
19136 VkCommandPoolCreateInfo pool_create_info{};
19137 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
19138 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
19139 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
19140 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
19141
19142 VkCommandBuffer command_buffer[2];
19143 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
19144 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
19145 command_buffer_allocate_info.commandPool = command_pool;
19146 command_buffer_allocate_info.commandBufferCount = 2;
19147 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
19148 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
19149
19150 {
19151 VkCommandBufferBeginInfo begin_info{};
19152 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19153 vkBeginCommandBuffer(command_buffer[0], &begin_info);
19154
19155 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
19156 nullptr, 0, nullptr, 0, nullptr);
19157
19158 VkViewport viewport{};
19159 viewport.maxDepth = 1.0f;
19160 viewport.minDepth = 0.0f;
19161 viewport.width = 512;
19162 viewport.height = 512;
19163 viewport.x = 0;
19164 viewport.y = 0;
19165 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
19166 vkEndCommandBuffer(command_buffer[0]);
19167 }
19168 {
19169 VkCommandBufferBeginInfo begin_info{};
19170 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19171 vkBeginCommandBuffer(command_buffer[1], &begin_info);
19172
19173 VkViewport viewport{};
19174 viewport.maxDepth = 1.0f;
19175 viewport.minDepth = 0.0f;
19176 viewport.width = 512;
19177 viewport.height = 512;
19178 viewport.x = 0;
19179 viewport.y = 0;
19180 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
19181 vkEndCommandBuffer(command_buffer[1]);
19182 }
19183 {
19184 VkSubmitInfo submit_info{};
19185 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19186 submit_info.commandBufferCount = 1;
19187 submit_info.pCommandBuffers = &command_buffer[0];
19188 submit_info.signalSemaphoreCount = 0;
19189 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
19190 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
19191 }
19192 {
19193 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
19194 VkSubmitInfo submit_info{};
19195 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19196 submit_info.commandBufferCount = 1;
19197 submit_info.pCommandBuffers = &command_buffer[1];
19198 submit_info.waitSemaphoreCount = 0;
19199 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
19200 submit_info.pWaitDstStageMask = flags;
19201 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
19202 }
19203
19204 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
19205
19206 vkDestroyFence(m_device->device(), fence, nullptr);
19207 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
19208 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
19209
19210 m_errorMonitor->VerifyNotFound();
19211}
19212
19213// This is a positive test. No errors should be generated.
19214TEST_F(VkPositiveLayerTest, TwoSubmitInfosWithSemaphoreOneQueueSubmitsOneFence) {
19215
19216 TEST_DESCRIPTION("Two command buffers each in a separate SubmitInfo sent in a single "
19217 "QueueSubmit call followed by a WaitForFences call.");
19218 ASSERT_NO_FATAL_FAILURE(InitState());
19219
19220 m_errorMonitor->ExpectSuccess();
19221
19222 VkFence fence;
19223 VkFenceCreateInfo fence_create_info{};
19224 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
19225 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
19226
19227 VkSemaphore semaphore;
19228 VkSemaphoreCreateInfo semaphore_create_info{};
19229 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
19230 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
19231
19232 VkCommandPool command_pool;
19233 VkCommandPoolCreateInfo pool_create_info{};
19234 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
19235 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
19236 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
19237 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
19238
19239 VkCommandBuffer command_buffer[2];
19240 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
19241 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
19242 command_buffer_allocate_info.commandPool = command_pool;
19243 command_buffer_allocate_info.commandBufferCount = 2;
19244 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
19245 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
19246
19247 {
19248 VkCommandBufferBeginInfo begin_info{};
19249 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19250 vkBeginCommandBuffer(command_buffer[0], &begin_info);
19251
19252 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
19253 nullptr, 0, nullptr, 0, nullptr);
19254
19255 VkViewport viewport{};
19256 viewport.maxDepth = 1.0f;
19257 viewport.minDepth = 0.0f;
19258 viewport.width = 512;
19259 viewport.height = 512;
19260 viewport.x = 0;
19261 viewport.y = 0;
19262 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
19263 vkEndCommandBuffer(command_buffer[0]);
19264 }
19265 {
19266 VkCommandBufferBeginInfo begin_info{};
19267 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19268 vkBeginCommandBuffer(command_buffer[1], &begin_info);
19269
19270 VkViewport viewport{};
19271 viewport.maxDepth = 1.0f;
19272 viewport.minDepth = 0.0f;
19273 viewport.width = 512;
19274 viewport.height = 512;
19275 viewport.x = 0;
19276 viewport.y = 0;
19277 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
19278 vkEndCommandBuffer(command_buffer[1]);
19279 }
19280 {
19281 VkSubmitInfo submit_info[2];
19282 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
19283
19284 submit_info[0].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19285 submit_info[0].pNext = NULL;
19286 submit_info[0].commandBufferCount = 1;
19287 submit_info[0].pCommandBuffers = &command_buffer[0];
19288 submit_info[0].signalSemaphoreCount = 1;
19289 submit_info[0].pSignalSemaphores = &semaphore;
19290 submit_info[0].waitSemaphoreCount = 0;
19291 submit_info[0].pWaitSemaphores = NULL;
19292 submit_info[0].pWaitDstStageMask = 0;
19293
19294 submit_info[1].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19295 submit_info[1].pNext = NULL;
19296 submit_info[1].commandBufferCount = 1;
19297 submit_info[1].pCommandBuffers = &command_buffer[1];
19298 submit_info[1].waitSemaphoreCount = 1;
19299 submit_info[1].pWaitSemaphores = &semaphore;
19300 submit_info[1].pWaitDstStageMask = flags;
19301 submit_info[1].signalSemaphoreCount = 0;
19302 submit_info[1].pSignalSemaphores = NULL;
19303 vkQueueSubmit(m_device->m_queue, 2, &submit_info[0], fence);
19304 }
19305
19306 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
19307
19308 vkDestroyFence(m_device->device(), fence, nullptr);
19309 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
19310 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
19311 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
19312
19313 m_errorMonitor->VerifyNotFound();
19314}
19315
19316TEST_F(VkPositiveLayerTest, RenderPassSecondaryCommandBuffersMultipleTimes) {
19317 m_errorMonitor->ExpectSuccess();
19318
19319 ASSERT_NO_FATAL_FAILURE(InitState());
19320 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19321
19322 BeginCommandBuffer(); // Framework implicitly begins the renderpass.
19323 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle()); // End implicit.
19324
19325 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
19326 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
19327 m_errorMonitor->VerifyNotFound();
19328 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
19329 m_errorMonitor->VerifyNotFound();
19330 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
19331 m_errorMonitor->VerifyNotFound();
19332
19333 m_commandBuffer->EndCommandBuffer();
19334 m_errorMonitor->VerifyNotFound();
19335}
19336
19337TEST_F(VkPositiveLayerTest, ValidRenderPassAttachmentLayoutWithLoadOp) {
19338 TEST_DESCRIPTION("Positive test where we create a renderpass with an "
19339 "attachment that uses LOAD_OP_CLEAR, the first subpass "
19340 "has a valid layout, and a second subpass then uses a "
19341 "valid *READ_ONLY* layout.");
19342 m_errorMonitor->ExpectSuccess();
19343 ASSERT_NO_FATAL_FAILURE(InitState());
19344
19345 VkAttachmentReference attach[2] = {};
19346 attach[0].attachment = 0;
19347 attach[0].layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
19348 attach[1].attachment = 0;
19349 attach[1].layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
19350 VkSubpassDescription subpasses[2] = {};
19351 // First subpass clears DS attach on load
19352 subpasses[0].pDepthStencilAttachment = &attach[0];
19353 // 2nd subpass reads in DS as input attachment
19354 subpasses[1].inputAttachmentCount = 1;
19355 subpasses[1].pInputAttachments = &attach[1];
19356 VkAttachmentDescription attach_desc = {};
19357 attach_desc.format = VK_FORMAT_D24_UNORM_S8_UINT;
19358 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
19359 attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
19360 attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
19361 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
19362 attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
19363 attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
19364 attach_desc.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
19365 VkRenderPassCreateInfo rpci = {};
19366 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
19367 rpci.attachmentCount = 1;
19368 rpci.pAttachments = &attach_desc;
19369 rpci.subpassCount = 2;
19370 rpci.pSubpasses = subpasses;
19371
19372 // Now create RenderPass and verify no errors
19373 VkRenderPass rp;
19374 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
19375 m_errorMonitor->VerifyNotFound();
19376
19377 vkDestroyRenderPass(m_device->device(), rp, NULL);
19378}
19379
19380TEST_F(VkPositiveLayerTest, CreatePipelineAttribMatrixType) {
19381 TEST_DESCRIPTION("Test that pipeline validation accepts matrices passed "
19382 "as vertex attributes");
19383 m_errorMonitor->ExpectSuccess();
19384
19385 ASSERT_NO_FATAL_FAILURE(InitState());
19386 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19387
19388 VkVertexInputBindingDescription input_binding;
19389 memset(&input_binding, 0, sizeof(input_binding));
19390
19391 VkVertexInputAttributeDescription input_attribs[2];
19392 memset(input_attribs, 0, sizeof(input_attribs));
19393
19394 for (int i = 0; i < 2; i++) {
19395 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
19396 input_attribs[i].location = i;
19397 }
19398
19399 char const *vsSource = "#version 450\n"
19400 "\n"
19401 "layout(location=0) in mat2x4 x;\n"
19402 "out gl_PerVertex {\n"
19403 " vec4 gl_Position;\n"
19404 "};\n"
19405 "void main(){\n"
19406 " gl_Position = x[0] + x[1];\n"
19407 "}\n";
19408 char const *fsSource = "#version 450\n"
19409 "\n"
19410 "layout(location=0) out vec4 color;\n"
19411 "void main(){\n"
19412 " color = vec4(1);\n"
19413 "}\n";
19414
19415 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19416 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19417
19418 VkPipelineObj pipe(m_device);
19419 pipe.AddColorAttachment();
19420 pipe.AddShader(&vs);
19421 pipe.AddShader(&fs);
19422
19423 pipe.AddVertexInputBindings(&input_binding, 1);
19424 pipe.AddVertexInputAttribs(input_attribs, 2);
19425
19426 VkDescriptorSetObj descriptorSet(m_device);
19427 descriptorSet.AppendDummy();
19428 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19429
19430 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
19431
19432 /* expect success */
19433 m_errorMonitor->VerifyNotFound();
19434}
19435
19436TEST_F(VkPositiveLayerTest, CreatePipelineAttribArrayType) {
19437 m_errorMonitor->ExpectSuccess();
19438
19439 ASSERT_NO_FATAL_FAILURE(InitState());
19440 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19441
19442 VkVertexInputBindingDescription input_binding;
19443 memset(&input_binding, 0, sizeof(input_binding));
19444
19445 VkVertexInputAttributeDescription input_attribs[2];
19446 memset(input_attribs, 0, sizeof(input_attribs));
19447
19448 for (int i = 0; i < 2; i++) {
19449 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
19450 input_attribs[i].location = i;
19451 }
19452
19453 char const *vsSource = "#version 450\n"
19454 "\n"
19455 "layout(location=0) in vec4 x[2];\n"
19456 "out gl_PerVertex {\n"
19457 " vec4 gl_Position;\n"
19458 "};\n"
19459 "void main(){\n"
19460 " gl_Position = x[0] + x[1];\n"
19461 "}\n";
19462 char const *fsSource = "#version 450\n"
19463 "\n"
19464 "layout(location=0) out vec4 color;\n"
19465 "void main(){\n"
19466 " color = vec4(1);\n"
19467 "}\n";
19468
19469 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19470 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19471
19472 VkPipelineObj pipe(m_device);
19473 pipe.AddColorAttachment();
19474 pipe.AddShader(&vs);
19475 pipe.AddShader(&fs);
19476
19477 pipe.AddVertexInputBindings(&input_binding, 1);
19478 pipe.AddVertexInputAttribs(input_attribs, 2);
19479
19480 VkDescriptorSetObj descriptorSet(m_device);
19481 descriptorSet.AppendDummy();
19482 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19483
19484 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
19485
19486 m_errorMonitor->VerifyNotFound();
19487}
19488
19489TEST_F(VkPositiveLayerTest, CreatePipelineAttribComponents) {
19490 TEST_DESCRIPTION("Test that pipeline validation accepts consuming a vertex attribute "
19491 "through multiple vertex shader inputs, each consuming a different "
19492 "subset of the components.");
19493 m_errorMonitor->ExpectSuccess();
19494
19495 ASSERT_NO_FATAL_FAILURE(InitState());
19496 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19497
19498 VkVertexInputBindingDescription input_binding;
19499 memset(&input_binding, 0, sizeof(input_binding));
19500
19501 VkVertexInputAttributeDescription input_attribs[3];
19502 memset(input_attribs, 0, sizeof(input_attribs));
19503
19504 for (int i = 0; i < 3; i++) {
19505 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
19506 input_attribs[i].location = i;
19507 }
19508
19509 char const *vsSource = "#version 450\n"
19510 "\n"
19511 "layout(location=0) in vec4 x;\n"
19512 "layout(location=1) in vec3 y1;\n"
19513 "layout(location=1, component=3) in float y2;\n"
19514 "layout(location=2) in vec4 z;\n"
19515 "out gl_PerVertex {\n"
19516 " vec4 gl_Position;\n"
19517 "};\n"
19518 "void main(){\n"
19519 " gl_Position = x + vec4(y1, y2) + z;\n"
19520 "}\n";
19521 char const *fsSource = "#version 450\n"
19522 "\n"
19523 "layout(location=0) out vec4 color;\n"
19524 "void main(){\n"
19525 " color = vec4(1);\n"
19526 "}\n";
19527
19528 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19529 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19530
19531 VkPipelineObj pipe(m_device);
19532 pipe.AddColorAttachment();
19533 pipe.AddShader(&vs);
19534 pipe.AddShader(&fs);
19535
19536 pipe.AddVertexInputBindings(&input_binding, 1);
19537 pipe.AddVertexInputAttribs(input_attribs, 3);
19538
19539 VkDescriptorSetObj descriptorSet(m_device);
19540 descriptorSet.AppendDummy();
19541 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19542
19543 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
19544
19545 m_errorMonitor->VerifyNotFound();
19546}
19547
19548TEST_F(VkPositiveLayerTest, CreatePipelineSimplePositive) {
19549 m_errorMonitor->ExpectSuccess();
19550
19551 ASSERT_NO_FATAL_FAILURE(InitState());
19552 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19553
19554 char const *vsSource = "#version 450\n"
19555 "out gl_PerVertex {\n"
19556 " vec4 gl_Position;\n"
19557 "};\n"
19558 "void main(){\n"
19559 " gl_Position = vec4(0);\n"
19560 "}\n";
19561 char const *fsSource = "#version 450\n"
19562 "\n"
19563 "layout(location=0) out vec4 color;\n"
19564 "void main(){\n"
19565 " color = vec4(1);\n"
19566 "}\n";
19567
19568 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19569 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19570
19571 VkPipelineObj pipe(m_device);
19572 pipe.AddColorAttachment();
19573 pipe.AddShader(&vs);
19574 pipe.AddShader(&fs);
19575
19576 VkDescriptorSetObj descriptorSet(m_device);
19577 descriptorSet.AppendDummy();
19578 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19579
19580 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
19581
19582 m_errorMonitor->VerifyNotFound();
19583}
19584
19585TEST_F(VkPositiveLayerTest, CreatePipelineRelaxedTypeMatch) {
19586 TEST_DESCRIPTION("Test that pipeline validation accepts the relaxed type matching rules "
19587 "set out in 14.1.3: fundamental type must match, and producer side must "
19588 "have at least as many components");
19589 m_errorMonitor->ExpectSuccess();
19590
19591 // VK 1.0.8 Specification, 14.1.3 "Additionally,..." block
19592
19593 ASSERT_NO_FATAL_FAILURE(InitState());
19594 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19595
19596 char const *vsSource = "#version 450\n"
19597 "out gl_PerVertex {\n"
19598 " vec4 gl_Position;\n"
19599 "};\n"
19600 "layout(location=0) out vec3 x;\n"
19601 "layout(location=1) out ivec3 y;\n"
19602 "layout(location=2) out vec3 z;\n"
19603 "void main(){\n"
19604 " gl_Position = vec4(0);\n"
19605 " x = vec3(0); y = ivec3(0); z = vec3(0);\n"
19606 "}\n";
19607 char const *fsSource = "#version 450\n"
19608 "\n"
19609 "layout(location=0) out vec4 color;\n"
19610 "layout(location=0) in float x;\n"
19611 "layout(location=1) flat in int y;\n"
19612 "layout(location=2) in vec2 z;\n"
19613 "void main(){\n"
19614 " color = vec4(1 + x + y + z.x);\n"
19615 "}\n";
19616
19617 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19618 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19619
19620 VkPipelineObj pipe(m_device);
19621 pipe.AddColorAttachment();
19622 pipe.AddShader(&vs);
19623 pipe.AddShader(&fs);
19624
19625 VkDescriptorSetObj descriptorSet(m_device);
19626 descriptorSet.AppendDummy();
19627 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19628
19629 VkResult err = VK_SUCCESS;
19630 err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
19631 ASSERT_VK_SUCCESS(err);
19632
19633 m_errorMonitor->VerifyNotFound();
19634}
19635
19636TEST_F(VkPositiveLayerTest, CreatePipelineTessPerVertex) {
19637 TEST_DESCRIPTION("Test that pipeline validation accepts per-vertex variables "
19638 "passed between the TCS and TES stages");
19639 m_errorMonitor->ExpectSuccess();
19640
19641 ASSERT_NO_FATAL_FAILURE(InitState());
19642 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19643
19644 if (!m_device->phy().features().tessellationShader) {
19645 printf("Device does not support tessellation shaders; skipped.\n");
19646 return;
19647 }
19648
19649 char const *vsSource = "#version 450\n"
19650 "void main(){}\n";
19651 char const *tcsSource = "#version 450\n"
19652 "layout(location=0) out int x[];\n"
19653 "layout(vertices=3) out;\n"
19654 "void main(){\n"
19655 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
19656 " gl_TessLevelInner[0] = 1;\n"
19657 " x[gl_InvocationID] = gl_InvocationID;\n"
19658 "}\n";
19659 char const *tesSource = "#version 450\n"
19660 "layout(triangles, equal_spacing, cw) in;\n"
19661 "layout(location=0) in int x[];\n"
19662 "out gl_PerVertex { vec4 gl_Position; };\n"
19663 "void main(){\n"
19664 " gl_Position.xyz = gl_TessCoord;\n"
19665 " gl_Position.w = x[0] + x[1] + x[2];\n"
19666 "}\n";
19667 char const *fsSource = "#version 450\n"
19668 "layout(location=0) out vec4 color;\n"
19669 "void main(){\n"
19670 " color = vec4(1);\n"
19671 "}\n";
19672
19673 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19674 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
19675 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
19676 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19677
19678 VkPipelineInputAssemblyStateCreateInfo iasci{ VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, nullptr, 0,
19679 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, VK_FALSE };
19680
19681 VkPipelineTessellationStateCreateInfo tsci{ VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, nullptr, 0, 3 };
19682
19683 VkPipelineObj pipe(m_device);
19684 pipe.SetInputAssembly(&iasci);
19685 pipe.SetTessellation(&tsci);
19686 pipe.AddColorAttachment();
19687 pipe.AddShader(&vs);
19688 pipe.AddShader(&tcs);
19689 pipe.AddShader(&tes);
19690 pipe.AddShader(&fs);
19691
19692 VkDescriptorSetObj descriptorSet(m_device);
19693 descriptorSet.AppendDummy();
19694 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19695
19696 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
19697
19698 m_errorMonitor->VerifyNotFound();
19699}
19700
19701TEST_F(VkPositiveLayerTest, CreatePipelineGeometryInputBlockPositive) {
19702 TEST_DESCRIPTION("Test that pipeline validation accepts a user-defined "
19703 "interface block passed into the geometry shader. This "
19704 "is interesting because the 'extra' array level is not "
19705 "present on the member type, but on the block instance.");
19706 m_errorMonitor->ExpectSuccess();
19707
19708 ASSERT_NO_FATAL_FAILURE(InitState());
19709 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19710
19711 if (!m_device->phy().features().geometryShader) {
19712 printf("Device does not support geometry shaders; skipped.\n");
19713 return;
19714 }
19715
19716 char const *vsSource = "#version 450\n"
19717 "layout(location=0) out VertexData { vec4 x; } vs_out;\n"
19718 "void main(){\n"
19719 " vs_out.x = vec4(1);\n"
19720 "}\n";
19721 char const *gsSource = "#version 450\n"
19722 "layout(triangles) in;\n"
19723 "layout(triangle_strip, max_vertices=3) out;\n"
19724 "layout(location=0) in VertexData { vec4 x; } gs_in[];\n"
19725 "out gl_PerVertex { vec4 gl_Position; };\n"
19726 "void main() {\n"
19727 " gl_Position = gs_in[0].x;\n"
19728 " EmitVertex();\n"
19729 "}\n";
19730 char const *fsSource = "#version 450\n"
19731 "layout(location=0) out vec4 color;\n"
19732 "void main(){\n"
19733 " color = vec4(1);\n"
19734 "}\n";
19735
19736 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19737 VkShaderObj gs(m_device, gsSource, VK_SHADER_STAGE_GEOMETRY_BIT, this);
19738 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19739
19740 VkPipelineObj pipe(m_device);
19741 pipe.AddColorAttachment();
19742 pipe.AddShader(&vs);
19743 pipe.AddShader(&gs);
19744 pipe.AddShader(&fs);
19745
19746 VkDescriptorSetObj descriptorSet(m_device);
19747 descriptorSet.AppendDummy();
19748 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19749
19750 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
19751
19752 m_errorMonitor->VerifyNotFound();
19753}
19754
19755TEST_F(VkPositiveLayerTest, CreatePipeline64BitAttributesPositive) {
19756 TEST_DESCRIPTION("Test that pipeline validation accepts basic use of 64bit vertex "
19757 "attributes. This is interesting because they consume multiple "
19758 "locations.");
19759 m_errorMonitor->ExpectSuccess();
19760
19761 ASSERT_NO_FATAL_FAILURE(InitState());
19762 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19763
19764 if (!m_device->phy().features().shaderFloat64) {
19765 printf("Device does not support 64bit vertex attributes; skipped.\n");
19766 return;
19767 }
19768
19769 VkVertexInputBindingDescription input_bindings[1];
19770 memset(input_bindings, 0, sizeof(input_bindings));
19771
19772 VkVertexInputAttributeDescription input_attribs[4];
19773 memset(input_attribs, 0, sizeof(input_attribs));
19774 input_attribs[0].location = 0;
19775 input_attribs[0].offset = 0;
19776 input_attribs[0].format = VK_FORMAT_R64G64B64A64_SFLOAT;
19777 input_attribs[1].location = 2;
19778 input_attribs[1].offset = 32;
19779 input_attribs[1].format = VK_FORMAT_R64G64B64A64_SFLOAT;
19780 input_attribs[2].location = 4;
19781 input_attribs[2].offset = 64;
19782 input_attribs[2].format = VK_FORMAT_R64G64B64A64_SFLOAT;
19783 input_attribs[3].location = 6;
19784 input_attribs[3].offset = 96;
19785 input_attribs[3].format = VK_FORMAT_R64G64B64A64_SFLOAT;
19786
19787 char const *vsSource = "#version 450\n"
19788 "\n"
19789 "layout(location=0) in dmat4 x;\n"
19790 "out gl_PerVertex {\n"
19791 " vec4 gl_Position;\n"
19792 "};\n"
19793 "void main(){\n"
19794 " gl_Position = vec4(x[0][0]);\n"
19795 "}\n";
19796 char const *fsSource = "#version 450\n"
19797 "\n"
19798 "layout(location=0) out vec4 color;\n"
19799 "void main(){\n"
19800 " color = vec4(1);\n"
19801 "}\n";
19802
19803 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19804 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19805
19806 VkPipelineObj pipe(m_device);
19807 pipe.AddColorAttachment();
19808 pipe.AddShader(&vs);
19809 pipe.AddShader(&fs);
19810
19811 pipe.AddVertexInputBindings(input_bindings, 1);
19812 pipe.AddVertexInputAttribs(input_attribs, 4);
19813
19814 VkDescriptorSetObj descriptorSet(m_device);
19815 descriptorSet.AppendDummy();
19816 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19817
19818 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
19819
19820 m_errorMonitor->VerifyNotFound();
19821}
19822
19823TEST_F(VkPositiveLayerTest, CreatePipelineInputAttachmentPositive) {
19824 TEST_DESCRIPTION("Positive test for a correctly matched input attachment");
19825 m_errorMonitor->ExpectSuccess();
19826
19827 ASSERT_NO_FATAL_FAILURE(InitState());
19828
19829 char const *vsSource = "#version 450\n"
19830 "\n"
19831 "out gl_PerVertex {\n"
19832 " vec4 gl_Position;\n"
19833 "};\n"
19834 "void main(){\n"
19835 " gl_Position = vec4(1);\n"
19836 "}\n";
19837 char const *fsSource = "#version 450\n"
19838 "\n"
19839 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
19840 "layout(location=0) out vec4 color;\n"
19841 "void main() {\n"
19842 " color = subpassLoad(x);\n"
19843 "}\n";
19844
19845 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19846 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19847
19848 VkPipelineObj pipe(m_device);
19849 pipe.AddShader(&vs);
19850 pipe.AddShader(&fs);
19851 pipe.AddColorAttachment();
19852 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19853
19854 VkDescriptorSetLayoutBinding dslb = { 0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr };
19855 VkDescriptorSetLayoutCreateInfo dslci = { VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb };
19856 VkDescriptorSetLayout dsl;
19857 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
19858 ASSERT_VK_SUCCESS(err);
19859
19860 VkPipelineLayoutCreateInfo plci = { VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr };
19861 VkPipelineLayout pl;
19862 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
19863 ASSERT_VK_SUCCESS(err);
19864
19865 VkAttachmentDescription descs[2] = {
19866 { 0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
19867 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
19868 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL },
19869 { 0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
19870 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_GENERAL, VK_IMAGE_LAYOUT_GENERAL },
19871 };
19872 VkAttachmentReference color = {
19873 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
19874 };
19875 VkAttachmentReference input = {
19876 1, VK_IMAGE_LAYOUT_GENERAL,
19877 };
19878
19879 VkSubpassDescription sd = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 1, &input, 1, &color, nullptr, nullptr, 0, nullptr };
19880
19881 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, descs, 1, &sd, 0, nullptr };
19882 VkRenderPass rp;
19883 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
19884 ASSERT_VK_SUCCESS(err);
19885
19886 // should be OK. would go wrong here if it's going to...
19887 pipe.CreateVKPipeline(pl, rp);
19888
19889 m_errorMonitor->VerifyNotFound();
19890
19891 vkDestroyRenderPass(m_device->device(), rp, nullptr);
19892 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
19893 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
19894}
19895
19896TEST_F(VkPositiveLayerTest, CreateComputePipelineMissingDescriptorUnusedPositive) {
19897 TEST_DESCRIPTION("Test that pipeline validation accepts a compute pipeline which declares a "
19898 "descriptor-backed resource which is not provided, but the shader does not "
19899 "statically use it. This is interesting because it requires compute pipelines "
19900 "to have a proper descriptor use walk, which they didn't for some time.");
19901 m_errorMonitor->ExpectSuccess();
19902
19903 ASSERT_NO_FATAL_FAILURE(InitState());
19904
19905 char const *csSource = "#version 450\n"
19906 "\n"
19907 "layout(local_size_x=1) in;\n"
19908 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
19909 "void main(){\n"
19910 " // x is not used.\n"
19911 "}\n";
19912
19913 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
19914
19915 VkDescriptorSetObj descriptorSet(m_device);
19916 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19917
19918 VkComputePipelineCreateInfo cpci = { VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
19919 nullptr,
19920 0,
19921 { VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
19922 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr },
19923 descriptorSet.GetPipelineLayout(),
19924 VK_NULL_HANDLE,
19925 -1 };
19926
19927 VkPipeline pipe;
19928 VkResult err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
19929
19930 m_errorMonitor->VerifyNotFound();
19931
19932 if (err == VK_SUCCESS) {
19933 vkDestroyPipeline(m_device->device(), pipe, nullptr);
19934 }
19935}
19936
19937TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsSampler) {
19938 TEST_DESCRIPTION("Test that pipeline validation accepts a shader consuming only the "
19939 "sampler portion of a combined image + sampler");
19940 m_errorMonitor->ExpectSuccess();
19941
19942 ASSERT_NO_FATAL_FAILURE(InitState());
19943
19944 VkDescriptorSetLayoutBinding bindings[] = {
19945 { 0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
19946 { 1, VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
19947 { 2, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
19948 };
19949 VkDescriptorSetLayoutCreateInfo dslci = { VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 3, bindings };
19950 VkDescriptorSetLayout dsl;
19951 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
19952 ASSERT_VK_SUCCESS(err);
19953
19954 VkPipelineLayoutCreateInfo plci = { VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr };
19955 VkPipelineLayout pl;
19956 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
19957 ASSERT_VK_SUCCESS(err);
19958
19959 char const *csSource = "#version 450\n"
19960 "\n"
19961 "layout(local_size_x=1) in;\n"
19962 "layout(set=0, binding=0) uniform sampler s;\n"
19963 "layout(set=0, binding=1) uniform texture2D t;\n"
19964 "layout(set=0, binding=2) buffer block { vec4 x; };\n"
19965 "void main() {\n"
19966 " x = texture(sampler2D(t, s), vec2(0));\n"
19967 "}\n";
19968 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
19969
19970 VkComputePipelineCreateInfo cpci = { VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
19971 nullptr,
19972 0,
19973 { VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
19974 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr },
19975 pl,
19976 VK_NULL_HANDLE,
19977 -1 };
19978
19979 VkPipeline pipe;
19980 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
19981
19982 m_errorMonitor->VerifyNotFound();
19983
19984 if (err == VK_SUCCESS) {
19985 vkDestroyPipeline(m_device->device(), pipe, nullptr);
19986 }
19987
19988 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
19989 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
19990}
19991
19992TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsImage) {
19993 TEST_DESCRIPTION("Test that pipeline validation accepts a shader consuming only the "
19994 "image portion of a combined image + sampler");
19995 m_errorMonitor->ExpectSuccess();
19996
19997 ASSERT_NO_FATAL_FAILURE(InitState());
19998
19999 VkDescriptorSetLayoutBinding bindings[] = {
20000 { 0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
20001 { 1, VK_DESCRIPTOR_TYPE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
20002 { 2, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
20003 };
20004 VkDescriptorSetLayoutCreateInfo dslci = { VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 3, bindings };
20005 VkDescriptorSetLayout dsl;
20006 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
20007 ASSERT_VK_SUCCESS(err);
20008
20009 VkPipelineLayoutCreateInfo plci = { VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr };
20010 VkPipelineLayout pl;
20011 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
20012 ASSERT_VK_SUCCESS(err);
20013
20014 char const *csSource = "#version 450\n"
20015 "\n"
20016 "layout(local_size_x=1) in;\n"
20017 "layout(set=0, binding=0) uniform texture2D t;\n"
20018 "layout(set=0, binding=1) uniform sampler s;\n"
20019 "layout(set=0, binding=2) buffer block { vec4 x; };\n"
20020 "void main() {\n"
20021 " x = texture(sampler2D(t, s), vec2(0));\n"
20022 "}\n";
20023 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
20024
20025 VkComputePipelineCreateInfo cpci = { VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
20026 nullptr,
20027 0,
20028 { VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
20029 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr },
20030 pl,
20031 VK_NULL_HANDLE,
20032 -1 };
20033
20034 VkPipeline pipe;
20035 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
20036
20037 m_errorMonitor->VerifyNotFound();
20038
20039 if (err == VK_SUCCESS) {
20040 vkDestroyPipeline(m_device->device(), pipe, nullptr);
20041 }
20042
20043 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
20044 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
20045}
20046
20047TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsBoth) {
20048 TEST_DESCRIPTION("Test that pipeline validation accepts a shader consuming "
20049 "both the sampler and the image of a combined image+sampler "
20050 "but via separate variables");
20051 m_errorMonitor->ExpectSuccess();
20052
20053 ASSERT_NO_FATAL_FAILURE(InitState());
20054
20055 VkDescriptorSetLayoutBinding bindings[] = {
20056 { 0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
20057 { 1, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
20058 };
20059 VkDescriptorSetLayoutCreateInfo dslci = { VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 2, bindings };
20060 VkDescriptorSetLayout dsl;
20061 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
20062 ASSERT_VK_SUCCESS(err);
20063
20064 VkPipelineLayoutCreateInfo plci = { VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr };
20065 VkPipelineLayout pl;
20066 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
20067 ASSERT_VK_SUCCESS(err);
20068
20069 char const *csSource = "#version 450\n"
20070 "\n"
20071 "layout(local_size_x=1) in;\n"
20072 "layout(set=0, binding=0) uniform texture2D t;\n"
20073 "layout(set=0, binding=0) uniform sampler s; // both binding 0!\n"
20074 "layout(set=0, binding=1) buffer block { vec4 x; };\n"
20075 "void main() {\n"
20076 " x = texture(sampler2D(t, s), vec2(0));\n"
20077 "}\n";
20078 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
20079
20080 VkComputePipelineCreateInfo cpci = { VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
20081 nullptr,
20082 0,
20083 { VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
20084 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr },
20085 pl,
20086 VK_NULL_HANDLE,
20087 -1 };
20088
20089 VkPipeline pipe;
20090 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
20091
20092 m_errorMonitor->VerifyNotFound();
20093
20094 if (err == VK_SUCCESS) {
20095 vkDestroyPipeline(m_device->device(), pipe, nullptr);
20096 }
20097
20098 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
20099 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
20100}
20101
20102TEST_F(VkPositiveLayerTest, ValidStructPNext) {
20103 TEST_DESCRIPTION("Verify that a valid pNext value is handled correctly");
20104
20105 ASSERT_NO_FATAL_FAILURE(InitState());
20106
20107 // Positive test to check parameter_validation and unique_objects support
20108 // for NV_dedicated_allocation
20109 uint32_t extension_count = 0;
20110 bool supports_nv_dedicated_allocation = false;
20111 VkResult err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, nullptr);
20112 ASSERT_VK_SUCCESS(err);
20113
20114 if (extension_count > 0) {
20115 std::vector<VkExtensionProperties> available_extensions(extension_count);
20116
20117 err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, &available_extensions[0]);
20118 ASSERT_VK_SUCCESS(err);
20119
20120 for (const auto &extension_props : available_extensions) {
20121 if (strcmp(extension_props.extensionName, VK_NV_DEDICATED_ALLOCATION_EXTENSION_NAME) == 0) {
20122 supports_nv_dedicated_allocation = true;
20123 }
20124 }
20125 }
20126
20127 if (supports_nv_dedicated_allocation) {
20128 m_errorMonitor->ExpectSuccess();
20129
20130 VkDedicatedAllocationBufferCreateInfoNV dedicated_buffer_create_info = {};
20131 dedicated_buffer_create_info.sType = VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_BUFFER_CREATE_INFO_NV;
20132 dedicated_buffer_create_info.pNext = nullptr;
20133 dedicated_buffer_create_info.dedicatedAllocation = VK_TRUE;
20134
20135 uint32_t queue_family_index = 0;
20136 VkBufferCreateInfo buffer_create_info = {};
20137 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
20138 buffer_create_info.pNext = &dedicated_buffer_create_info;
20139 buffer_create_info.size = 1024;
20140 buffer_create_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
20141 buffer_create_info.queueFamilyIndexCount = 1;
20142 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
20143
20144 VkBuffer buffer;
20145 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
20146 ASSERT_VK_SUCCESS(err);
20147
20148 VkMemoryRequirements memory_reqs;
20149 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
20150
20151 VkDedicatedAllocationMemoryAllocateInfoNV dedicated_memory_info = {};
20152 dedicated_memory_info.sType = VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_MEMORY_ALLOCATE_INFO_NV;
20153 dedicated_memory_info.pNext = nullptr;
20154 dedicated_memory_info.buffer = buffer;
20155 dedicated_memory_info.image = VK_NULL_HANDLE;
20156
20157 VkMemoryAllocateInfo memory_info = {};
20158 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
20159 memory_info.pNext = &dedicated_memory_info;
20160 memory_info.allocationSize = memory_reqs.size;
20161
20162 bool pass;
20163 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
20164 ASSERT_TRUE(pass);
20165
20166 VkDeviceMemory buffer_memory;
20167 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
20168 ASSERT_VK_SUCCESS(err);
20169
20170 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
20171 ASSERT_VK_SUCCESS(err);
20172
20173 vkDestroyBuffer(m_device->device(), buffer, NULL);
20174 vkFreeMemory(m_device->device(), buffer_memory, NULL);
20175
20176 m_errorMonitor->VerifyNotFound();
20177 }
20178}
20179
20180TEST_F(VkPositiveLayerTest, PSOPolygonModeValid) {
20181 VkResult err;
20182
20183 TEST_DESCRIPTION("Verify that using a solid polygon fill mode works correctly.");
20184
20185 ASSERT_NO_FATAL_FAILURE(InitState());
20186 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
20187
20188 std::vector<const char *> device_extension_names;
20189 auto features = m_device->phy().features();
20190 // Artificially disable support for non-solid fill modes
20191 features.fillModeNonSolid = false;
20192 // The sacrificial device object
20193 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
20194
20195 VkRenderpassObj render_pass(&test_device);
20196
20197 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
20198 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
20199 pipeline_layout_ci.setLayoutCount = 0;
20200 pipeline_layout_ci.pSetLayouts = NULL;
20201
20202 VkPipelineLayout pipeline_layout;
20203 err = vkCreatePipelineLayout(test_device.device(), &pipeline_layout_ci, NULL, &pipeline_layout);
20204 ASSERT_VK_SUCCESS(err);
20205
20206 VkPipelineRasterizationStateCreateInfo rs_ci = {};
20207 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
20208 rs_ci.pNext = nullptr;
20209 rs_ci.lineWidth = 1.0f;
20210 rs_ci.rasterizerDiscardEnable = true;
20211
20212 VkShaderObj vs(&test_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
20213 VkShaderObj fs(&test_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
20214
20215 // Set polygonMode=FILL. No error is expected
20216 m_errorMonitor->ExpectSuccess();
20217 {
20218 VkPipelineObj pipe(&test_device);
20219 pipe.AddShader(&vs);
20220 pipe.AddShader(&fs);
20221 pipe.AddColorAttachment();
20222 // Set polygonMode to a good value
20223 rs_ci.polygonMode = VK_POLYGON_MODE_FILL;
20224 pipe.SetRasterization(&rs_ci);
20225 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
20226 }
20227 m_errorMonitor->VerifyNotFound();
20228
20229 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, NULL);
20230}
20231
20232TEST_F(VkPositiveLayerTest, ValidPushConstants) {
20233 VkResult err;
20234 ASSERT_NO_FATAL_FAILURE(InitState());
20235 ASSERT_NO_FATAL_FAILURE(InitViewport());
20236 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
20237
20238 VkPipelineLayout pipeline_layout;
20239 VkPushConstantRange pc_range = {};
20240 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
20241 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
20242 pipeline_layout_ci.pushConstantRangeCount = 1;
20243 pipeline_layout_ci.pPushConstantRanges = &pc_range;
20244
20245 //
20246 // Check for invalid push constant ranges in pipeline layouts.
20247 //
20248 struct PipelineLayoutTestCase {
20249 VkPushConstantRange const range;
20250 char const *msg;
20251 };
20252
20253 // Check for overlapping ranges
20254 const uint32_t ranges_per_test = 5;
20255 struct OverlappingRangeTestCase {
20256 VkPushConstantRange const ranges[ranges_per_test];
20257 char const *msg;
20258 };
20259
20260 // Run some positive tests to make sure overlap checking in the layer is OK
20261 const std::array<OverlappingRangeTestCase, 2> overlapping_range_tests_pos = { { { { { VK_SHADER_STAGE_VERTEX_BIT, 0, 4 },
20262 { VK_SHADER_STAGE_VERTEX_BIT, 4, 4 },
20263 { VK_SHADER_STAGE_VERTEX_BIT, 8, 4 },
20264 { VK_SHADER_STAGE_VERTEX_BIT, 12, 4 },
20265 { VK_SHADER_STAGE_VERTEX_BIT, 16, 4 } },
20266 "" },
20267 { { { VK_SHADER_STAGE_VERTEX_BIT, 92, 24 },
20268 { VK_SHADER_STAGE_VERTEX_BIT, 80, 4 },
20269 { VK_SHADER_STAGE_VERTEX_BIT, 64, 8 },
20270 { VK_SHADER_STAGE_VERTEX_BIT, 4, 16 },
20271 { VK_SHADER_STAGE_VERTEX_BIT, 0, 4 } },
20272 "" } } };
20273 for (const auto &iter : overlapping_range_tests_pos) {
20274 pipeline_layout_ci.pPushConstantRanges = iter.ranges;
20275 m_errorMonitor->ExpectSuccess();
20276 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
20277 m_errorMonitor->VerifyNotFound();
20278 if (VK_SUCCESS == err) {
20279 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
20280 }
20281 }
20282
20283 //
20284 // CmdPushConstants tests
20285 //
20286 const uint8_t dummy_values[100] = {};
20287
20288 BeginCommandBuffer();
20289
20290 // positive overlapping range tests with cmd
20291 const std::array<PipelineLayoutTestCase, 4> cmd_overlap_tests_pos = { {
20292 { { VK_SHADER_STAGE_VERTEX_BIT, 0, 16 }, "" },
20293 { { VK_SHADER_STAGE_VERTEX_BIT, 0, 4 }, "" },
20294 { { VK_SHADER_STAGE_VERTEX_BIT, 20, 12 }, "" },
20295 { { VK_SHADER_STAGE_VERTEX_BIT, 56, 36 }, "" },
20296 } };
20297
20298 // Setup ranges: [0,16) [20,36) [36,44) [44,52) [56,80) [80,92)
20299 const VkPushConstantRange pc_range4[] = {
20300 { VK_SHADER_STAGE_VERTEX_BIT, 20, 16 },{ VK_SHADER_STAGE_VERTEX_BIT, 0, 16 },{ VK_SHADER_STAGE_VERTEX_BIT, 44, 8 },
20301 { VK_SHADER_STAGE_VERTEX_BIT, 80, 12 },{ VK_SHADER_STAGE_VERTEX_BIT, 36, 8 },{ VK_SHADER_STAGE_VERTEX_BIT, 56, 24 },
20302 };
20303
20304 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range4) / sizeof(VkPushConstantRange);
20305 pipeline_layout_ci.pPushConstantRanges = pc_range4;
20306 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
20307 ASSERT_VK_SUCCESS(err);
20308 for (const auto &iter : cmd_overlap_tests_pos) {
20309 m_errorMonitor->ExpectSuccess();
20310 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.range.stageFlags, iter.range.offset,
20311 iter.range.size, dummy_values);
20312 m_errorMonitor->VerifyNotFound();
20313 }
20314 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
20315
20316 EndCommandBuffer();
20317}
20318
20319
20320
20321
20322
20323
20324
20325#if 0 // A few devices have issues with this test so disabling for now
20326TEST_F(VkPositiveLayerTest, LongFenceChain)
20327{
20328 m_errorMonitor->ExpectSuccess();
20329
20330 ASSERT_NO_FATAL_FAILURE(InitState());
20331 VkResult err;
20332
20333 std::vector<VkFence> fences;
20334
20335 const int chainLength = 32768;
20336
20337 for (int i = 0; i < chainLength; i++) {
20338 VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
20339 VkFence fence;
20340 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
20341 ASSERT_VK_SUCCESS(err);
20342
20343 fences.push_back(fence);
20344
20345 VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr,
20346 0, nullptr, 0, nullptr };
20347 err = vkQueueSubmit(m_device->m_queue, 1, &si, fence);
20348 ASSERT_VK_SUCCESS(err);
20349
20350 }
20351
20352 // BOOM, stack overflow.
20353 vkWaitForFences(m_device->device(), 1, &fences.back(), VK_TRUE, UINT64_MAX);
20354
20355 for (auto fence : fences)
20356 vkDestroyFence(m_device->device(), fence, nullptr);
20357
20358 m_errorMonitor->VerifyNotFound();
20359}
20360#endif
20361
20362
Cody Northrop1242dfd2016-07-13 17:24:59 -060020363#if defined(ANDROID) && defined(VALIDATION_APK)
20364static bool initialized = false;
20365static bool active = false;
20366
20367// Convert Intents to argv
20368// Ported from Hologram sample, only difference is flexible key
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020369std::vector<std::string> get_args(android_app &app, const char *intent_extra_data_key) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060020370 std::vector<std::string> args;
20371 JavaVM &vm = *app.activity->vm;
20372 JNIEnv *p_env;
20373 if (vm.AttachCurrentThread(&p_env, nullptr) != JNI_OK)
20374 return args;
20375
20376 JNIEnv &env = *p_env;
20377 jobject activity = app.activity->clazz;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020378 jmethodID get_intent_method = env.GetMethodID(env.GetObjectClass(activity), "getIntent", "()Landroid/content/Intent;");
Cody Northrop1242dfd2016-07-13 17:24:59 -060020379 jobject intent = env.CallObjectMethod(activity, get_intent_method);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020380 jmethodID get_string_extra_method =
20381 env.GetMethodID(env.GetObjectClass(intent), "getStringExtra", "(Ljava/lang/String;)Ljava/lang/String;");
Cody Northrop1242dfd2016-07-13 17:24:59 -060020382 jvalue get_string_extra_args;
20383 get_string_extra_args.l = env.NewStringUTF(intent_extra_data_key);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020384 jstring extra_str = static_cast<jstring>(env.CallObjectMethodA(intent, get_string_extra_method, &get_string_extra_args));
Cody Northrop1242dfd2016-07-13 17:24:59 -060020385
20386 std::string args_str;
20387 if (extra_str) {
20388 const char *extra_utf = env.GetStringUTFChars(extra_str, nullptr);
20389 args_str = extra_utf;
20390 env.ReleaseStringUTFChars(extra_str, extra_utf);
20391 env.DeleteLocalRef(extra_str);
20392 }
20393
20394 env.DeleteLocalRef(get_string_extra_args.l);
20395 env.DeleteLocalRef(intent);
20396 vm.DetachCurrentThread();
20397
20398 // split args_str
20399 std::stringstream ss(args_str);
20400 std::string arg;
20401 while (std::getline(ss, arg, ' ')) {
20402 if (!arg.empty())
20403 args.push_back(arg);
20404 }
20405
20406 return args;
20407}
20408
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020409static int32_t processInput(struct android_app *app, AInputEvent *event) { return 0; }
Cody Northrop1242dfd2016-07-13 17:24:59 -060020410
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020411static void processCommand(struct android_app *app, int32_t cmd) {
20412 switch (cmd) {
20413 case APP_CMD_INIT_WINDOW: {
20414 if (app->window) {
20415 initialized = true;
Cody Northrop1242dfd2016-07-13 17:24:59 -060020416 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020417 break;
20418 }
20419 case APP_CMD_GAINED_FOCUS: {
20420 active = true;
20421 break;
20422 }
20423 case APP_CMD_LOST_FOCUS: {
20424 active = false;
20425 break;
20426 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060020427 }
20428}
20429
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020430void android_main(struct android_app *app) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060020431 app_dummy();
20432
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020433 const char *appTag = "VulkanLayerValidationTests";
Cody Northrop1242dfd2016-07-13 17:24:59 -060020434
20435 int vulkanSupport = InitVulkan();
20436 if (vulkanSupport == 0) {
20437 __android_log_print(ANDROID_LOG_INFO, appTag, "==== FAILED ==== No Vulkan support found");
20438 return;
20439 }
20440
20441 app->onAppCmd = processCommand;
20442 app->onInputEvent = processInput;
20443
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020444 while (1) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060020445 int events;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020446 struct android_poll_source *source;
20447 while (ALooper_pollAll(active ? 0 : -1, NULL, &events, (void **)&source) >= 0) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060020448 if (source) {
20449 source->process(app, source);
20450 }
20451
20452 if (app->destroyRequested != 0) {
20453 VkTestFramework::Finish();
20454 return;
20455 }
20456 }
20457
20458 if (initialized && active) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020459 // Use the following key to send arguments to gtest, i.e.
20460 // --es args "--gtest_filter=-VkLayerTest.foo"
20461 const char key[] = "args";
20462 std::vector<std::string> args = get_args(*app, key);
Cody Northrop1242dfd2016-07-13 17:24:59 -060020463
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020464 std::string filter = "";
20465 if (args.size() > 0) {
20466 __android_log_print(ANDROID_LOG_INFO, appTag, "Intent args = %s", args[0].c_str());
20467 filter += args[0];
20468 } else {
20469 __android_log_print(ANDROID_LOG_INFO, appTag, "No Intent args detected");
20470 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060020471
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020472 int argc = 2;
20473 char *argv[] = {(char *)"foo", (char *)filter.c_str()};
20474 __android_log_print(ANDROID_LOG_DEBUG, appTag, "filter = %s", argv[1]);
Cody Northrop1242dfd2016-07-13 17:24:59 -060020475
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020476 // Route output to files until we can override the gtest output
20477 freopen("/sdcard/Android/data/com.example.VulkanLayerValidationTests/files/out.txt", "w", stdout);
20478 freopen("/sdcard/Android/data/com.example.VulkanLayerValidationTests/files/err.txt", "w", stderr);
Cody Northrop1242dfd2016-07-13 17:24:59 -060020479
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020480 ::testing::InitGoogleTest(&argc, argv);
20481 VkTestFramework::InitArgs(&argc, argv);
20482 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
Cody Northrop1242dfd2016-07-13 17:24:59 -060020483
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020484 int result = RUN_ALL_TESTS();
Cody Northrop1242dfd2016-07-13 17:24:59 -060020485
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020486 if (result != 0) {
20487 __android_log_print(ANDROID_LOG_INFO, appTag, "==== Tests FAILED ====");
20488 } else {
20489 __android_log_print(ANDROID_LOG_INFO, appTag, "==== Tests PASSED ====");
20490 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060020491
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020492 VkTestFramework::Finish();
Cody Northrop1242dfd2016-07-13 17:24:59 -060020493
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020494 fclose(stdout);
20495 fclose(stderr);
Cody Northrop1242dfd2016-07-13 17:24:59 -060020496
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020497 ANativeActivity_finish(app->activity);
Cody Northrop1242dfd2016-07-13 17:24:59 -060020498
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020499 return;
Cody Northrop1242dfd2016-07-13 17:24:59 -060020500 }
20501 }
20502}
20503#endif
20504
Tony Barbour300a6082015-04-07 13:44:53 -060020505int main(int argc, char **argv) {
20506 int result;
20507
Cody Northrop8e54a402016-03-08 22:25:52 -070020508#ifdef ANDROID
20509 int vulkanSupport = InitVulkan();
20510 if (vulkanSupport == 0)
20511 return 1;
20512#endif
20513
Tony Barbour300a6082015-04-07 13:44:53 -060020514 ::testing::InitGoogleTest(&argc, argv);
Tony Barbour6918cd52015-04-09 12:58:51 -060020515 VkTestFramework::InitArgs(&argc, argv);
Tony Barbour300a6082015-04-07 13:44:53 -060020516
20517 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
20518
20519 result = RUN_ALL_TESTS();
20520
Tony Barbour6918cd52015-04-09 12:58:51 -060020521 VkTestFramework::Finish();
Tony Barbour300a6082015-04-07 13:44:53 -060020522 return result;
20523}