blob: 4794199938c523578c7ddf88562848ba0fa39aae [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:
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600291 void VKTriangleTest(const char *vertShaderText, const char *fragShaderText, BsoFailSelect failMask);
292 void GenericDrawPreparation(VkCommandBufferObj *commandBuffer, VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet,
Karl Schultz6addd812016-02-02 17:17:23 -0700293 BsoFailSelect failMask);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600294 void GenericDrawPreparation(VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet, BsoFailSelect failMask) {
295 GenericDrawPreparation(m_commandBuffer, pipelineobj, descriptorSet, failMask);
Karl Schultz6addd812016-02-02 17:17:23 -0700296 }
Tony Barbour300a6082015-04-07 13:44:53 -0600297
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600298 void Draw(uint32_t vertexCount, uint32_t instanceCount, uint32_t firstVertex, uint32_t firstInstance) {
299 m_commandBuffer->Draw(vertexCount, instanceCount, firstVertex, firstInstance);
Karl Schultz6addd812016-02-02 17:17:23 -0700300 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600301 void DrawIndexed(uint32_t indexCount, uint32_t instanceCount, uint32_t firstIndex, int32_t vertexOffset,
Karl Schultz6addd812016-02-02 17:17:23 -0700302 uint32_t firstInstance) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600303 m_commandBuffer->DrawIndexed(indexCount, instanceCount, firstIndex, vertexOffset, firstInstance);
Karl Schultz6addd812016-02-02 17:17:23 -0700304 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600305 void QueueCommandBuffer(bool checkSuccess = true) { m_commandBuffer->QueueCommandBuffer(checkSuccess); }
306 void QueueCommandBuffer(const VkFence &fence) { m_commandBuffer->QueueCommandBuffer(fence); }
307 void BindVertexBuffer(VkConstantBufferObj *vertexBuffer, VkDeviceSize offset, uint32_t binding) {
Karl Schultz6addd812016-02-02 17:17:23 -0700308 m_commandBuffer->BindVertexBuffer(vertexBuffer, offset, binding);
309 }
310 void BindIndexBuffer(VkIndexBufferObj *indexBuffer, VkDeviceSize offset) {
311 m_commandBuffer->BindIndexBuffer(indexBuffer, offset);
312 }
313
314 protected:
315 ErrorMonitor *m_errorMonitor;
Ian Elliott2c1daf52016-05-12 09:41:46 -0600316 bool m_enableWSI;
Tony Barbour300a6082015-04-07 13:44:53 -0600317
318 virtual void SetUp() {
Courtney Goeltzenleuchtercd69eee2015-07-06 09:10:47 -0600319 std::vector<const char *> instance_layer_names;
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600320 std::vector<const char *> instance_extension_names;
321 std::vector<const char *> device_extension_names;
Tony Barbour3fdff9e2015-04-23 12:55:36 -0600322
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700323 instance_extension_names.push_back(VK_EXT_DEBUG_REPORT_EXTENSION_NAME);
Courtney Goeltzenleuchterc2b06fe2015-06-16 15:59:11 -0600324 /*
325 * Since CreateDbgMsgCallback is an instance level extension call
326 * any extension / layer that utilizes that feature also needs
327 * to be enabled at create instance time.
328 */
Karl Schultz6addd812016-02-02 17:17:23 -0700329 // Use Threading layer first to protect others from
330 // ThreadCommandBufferCollision test
Courtney Goeltzenleuchter76885322016-02-06 17:11:22 -0700331 instance_layer_names.push_back("VK_LAYER_GOOGLE_threading");
Tobin Ehlis24aab042016-03-24 10:54:18 -0600332 instance_layer_names.push_back("VK_LAYER_LUNARG_parameter_validation");
Michael Lentine03107b42015-12-11 10:49:51 -0800333 instance_layer_names.push_back("VK_LAYER_LUNARG_object_tracker");
Tobin Ehlisc96f8062016-03-09 16:12:48 -0700334 instance_layer_names.push_back("VK_LAYER_LUNARG_core_validation");
Michael Lentine03107b42015-12-11 10:49:51 -0800335 instance_layer_names.push_back("VK_LAYER_LUNARG_image");
Ian Elliotte48a1382016-04-28 14:22:58 -0600336 instance_layer_names.push_back("VK_LAYER_LUNARG_swapchain");
Dustin Graveseaa78cd2016-01-26 16:30:22 -0700337 instance_layer_names.push_back("VK_LAYER_GOOGLE_unique_objects");
Courtney Goeltzenleuchterd971b612015-06-17 20:51:59 -0600338
Ian Elliott2c1daf52016-05-12 09:41:46 -0600339 if (m_enableWSI) {
340 instance_extension_names.push_back(VK_KHR_SURFACE_EXTENSION_NAME);
341 device_extension_names.push_back(VK_KHR_SWAPCHAIN_EXTENSION_NAME);
342#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
343#if defined(VK_USE_PLATFORM_ANDROID_KHR)
344 instance_extension_names.push_back(VK_KHR_ANDROID_SURFACE_EXTENSION_NAME);
345#endif // VK_USE_PLATFORM_ANDROID_KHR
346#if defined(VK_USE_PLATFORM_MIR_KHR)
347 instance_extension_names.push_back(VK_KHR_MIR_SURFACE_EXTENSION_NAME);
348#endif // VK_USE_PLATFORM_MIR_KHR
349#if defined(VK_USE_PLATFORM_WAYLAND_KHR)
350 instance_extension_names.push_back(VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME);
351#endif // VK_USE_PLATFORM_WAYLAND_KHR
352#if defined(VK_USE_PLATFORM_WIN32_KHR)
353 instance_extension_names.push_back(VK_KHR_WIN32_SURFACE_EXTENSION_NAME);
354#endif // VK_USE_PLATFORM_WIN32_KHR
355#endif // NEED_TO_TEST_THIS_ON_PLATFORM
356#if defined(VK_USE_PLATFORM_XCB_KHR)
357 instance_extension_names.push_back(VK_KHR_XCB_SURFACE_EXTENSION_NAME);
358#elif defined(VK_USE_PLATFORM_XLIB_KHR)
359 instance_extension_names.push_back(VK_KHR_XLIB_SURFACE_EXTENSION_NAME);
360#endif // VK_USE_PLATFORM_XLIB_KHR
361 }
362
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600363 this->app_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
Tony Barbour300a6082015-04-07 13:44:53 -0600364 this->app_info.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800365 this->app_info.pApplicationName = "layer_tests";
366 this->app_info.applicationVersion = 1;
Tony Barbour300a6082015-04-07 13:44:53 -0600367 this->app_info.pEngineName = "unittest";
368 this->app_info.engineVersion = 1;
Jon Ashburnc5012ff2016-03-22 13:57:46 -0600369 this->app_info.apiVersion = VK_API_VERSION_1_0;
Tony Barbour300a6082015-04-07 13:44:53 -0600370
Tony Barbour15524c32015-04-29 17:34:29 -0600371 m_errorMonitor = new ErrorMonitor;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600372 InitFramework(instance_layer_names, instance_extension_names, device_extension_names, myDbgFunc, m_errorMonitor);
Tony Barbour300a6082015-04-07 13:44:53 -0600373 }
374
375 virtual void TearDown() {
376 // Clean up resources before we reset
Tony Barbour300a6082015-04-07 13:44:53 -0600377 ShutdownFramework();
Tony Barbour0b4d9562015-04-09 10:48:04 -0600378 delete m_errorMonitor;
Tony Barbour300a6082015-04-07 13:44:53 -0600379 }
Ian Elliott2c1daf52016-05-12 09:41:46 -0600380
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600381 VkLayerTest() { m_enableWSI = false; }
Tony Barbour300a6082015-04-07 13:44:53 -0600382};
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500383
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600384void VkLayerTest::VKTriangleTest(const char *vertShaderText, const char *fragShaderText, BsoFailSelect failMask) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500385 // Create identity matrix
386 int i;
387 struct vktriangle_vs_uniform data;
388
389 glm::mat4 Projection = glm::mat4(1.0f);
Karl Schultz6addd812016-02-02 17:17:23 -0700390 glm::mat4 View = glm::mat4(1.0f);
391 glm::mat4 Model = glm::mat4(1.0f);
392 glm::mat4 MVP = Projection * View * Model;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500393 const int matrixSize = sizeof(MVP);
Karl Schultz6addd812016-02-02 17:17:23 -0700394 const int bufSize = sizeof(vktriangle_vs_uniform) / sizeof(float);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500395
396 memcpy(&data.mvp, &MVP[0][0], matrixSize);
397
Karl Schultz6addd812016-02-02 17:17:23 -0700398 static const Vertex tri_data[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600399 {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 -0500400 };
401
Karl Schultz6addd812016-02-02 17:17:23 -0700402 for (i = 0; i < 3; i++) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500403 data.position[i][0] = tri_data[i].posX;
404 data.position[i][1] = tri_data[i].posY;
405 data.position[i][2] = tri_data[i].posZ;
406 data.position[i][3] = tri_data[i].posW;
Karl Schultz6addd812016-02-02 17:17:23 -0700407 data.color[i][0] = tri_data[i].r;
408 data.color[i][1] = tri_data[i].g;
409 data.color[i][2] = tri_data[i].b;
410 data.color[i][3] = tri_data[i].a;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500411 }
412
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500413 ASSERT_NO_FATAL_FAILURE(InitViewport());
414
Chris Forbesbcfaadd2016-09-16 14:13:53 +1200415 VkConstantBufferObj constantBuffer(m_device, bufSize * 2, sizeof(float), (const void *)&data,
416 VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500417
Karl Schultz6addd812016-02-02 17:17:23 -0700418 VkShaderObj vs(m_device, vertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600419 VkShaderObj ps(m_device, fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500420
421 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +0800422 pipelineobj.AddColorAttachment();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500423 pipelineobj.AddShader(&vs);
424 pipelineobj.AddShader(&ps);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600425 if (failMask & BsoFailLineWidth) {
426 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_LINE_WIDTH);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600427 VkPipelineInputAssemblyStateCreateInfo ia_state = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600428 ia_state.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600429 ia_state.topology = VK_PRIMITIVE_TOPOLOGY_LINE_LIST;
430 pipelineobj.SetInputAssembly(&ia_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600431 }
432 if (failMask & BsoFailDepthBias) {
433 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_DEPTH_BIAS);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600434 VkPipelineRasterizationStateCreateInfo rs_state = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600435 rs_state.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600436 rs_state.depthBiasEnable = VK_TRUE;
Mark Young7394fdd2016-03-31 14:56:43 -0600437 rs_state.lineWidth = 1.0f;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600438 pipelineobj.SetRasterization(&rs_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600439 }
Rene Lindsayacbf5e62016-12-15 18:47:11 -0700440 // Viewport and scissors must stay in sync or other errors will occur than
Karl Schultz6addd812016-02-02 17:17:23 -0700441 // the ones we want
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600442 if (failMask & BsoFailViewport) {
443 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_VIEWPORT);
444 }
445 if (failMask & BsoFailScissor) {
446 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_SCISSOR);
447 }
448 if (failMask & BsoFailBlend) {
449 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_BLEND_CONSTANTS);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600450 VkPipelineColorBlendAttachmentState att_state = {};
451 att_state.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
452 att_state.blendEnable = VK_TRUE;
453 pipelineobj.AddColorAttachment(0, &att_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600454 }
455 if (failMask & BsoFailDepthBounds) {
456 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_DEPTH_BOUNDS);
457 }
458 if (failMask & BsoFailStencilReadMask) {
459 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK);
460 }
461 if (failMask & BsoFailStencilWriteMask) {
462 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_WRITE_MASK);
463 }
464 if (failMask & BsoFailStencilReference) {
465 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_REFERENCE);
466 }
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500467
468 VkDescriptorSetObj descriptorSet(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600469 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, constantBuffer);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500470
471 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour552f6c02016-12-21 14:34:07 -0700472 m_commandBuffer->BeginCommandBuffer();
473 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500474
Tony Barbourfe3351b2015-07-28 10:17:20 -0600475 GenericDrawPreparation(pipelineobj, descriptorSet, failMask);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500476
477 // render triangle
Tobin Ehlis379ba3b2016-07-19 11:22:29 -0600478 if (failMask & BsoFailIndexBuffer) {
479 // Use DrawIndexed w/o an index buffer bound
480 DrawIndexed(3, 1, 0, 0, 0);
481 } else {
482 Draw(3, 1, 0, 0);
483 }
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500484
Mark Muellerd4914412016-06-13 17:52:06 -0600485 if (failMask & BsoFailCmdClearAttachments) {
486 VkClearAttachment color_attachment = {};
487 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
488 color_attachment.colorAttachment = 1; // Someone who knew what they were doing would use 0 for the index;
489 VkClearRect clear_rect = {{{0, 0}, {static_cast<uint32_t>(m_width), static_cast<uint32_t>(m_height)}}, 0, 0};
490
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600491 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Muellerd4914412016-06-13 17:52:06 -0600492 }
493
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500494 // finalize recording of the command buffer
Tony Barbour552f6c02016-12-21 14:34:07 -0700495 m_commandBuffer->EndRenderPass();
496 m_commandBuffer->EndCommandBuffer();
Tony Barbourfe3351b2015-07-28 10:17:20 -0600497 QueueCommandBuffer();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500498}
499
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600500void VkLayerTest::GenericDrawPreparation(VkCommandBufferObj *commandBuffer, VkPipelineObj &pipelineobj,
501 VkDescriptorSetObj &descriptorSet, BsoFailSelect failMask) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500502 if (m_depthStencil->Initialized()) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600503 commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, m_depthStencil);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500504 } else {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600505 commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500506 }
507
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800508 commandBuffer->PrepareAttachments();
Karl Schultz6addd812016-02-02 17:17:23 -0700509 // Make sure depthWriteEnable is set so that Depth fail test will work
510 // correctly
511 // Make sure stencilTestEnable is set so that Stencil fail test will work
512 // correctly
Tony Barboureb254902015-07-15 12:50:33 -0600513 VkStencilOpState stencil = {};
Chia-I Wu1b99bb22015-10-27 19:25:11 +0800514 stencil.failOp = VK_STENCIL_OP_KEEP;
515 stencil.passOp = VK_STENCIL_OP_KEEP;
516 stencil.depthFailOp = VK_STENCIL_OP_KEEP;
517 stencil.compareOp = VK_COMPARE_OP_NEVER;
Tony Barboureb254902015-07-15 12:50:33 -0600518
519 VkPipelineDepthStencilStateCreateInfo ds_ci = {};
520 ds_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO;
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600521 ds_ci.pNext = NULL;
522 ds_ci.depthTestEnable = VK_FALSE;
523 ds_ci.depthWriteEnable = VK_TRUE;
524 ds_ci.depthCompareOp = VK_COMPARE_OP_NEVER;
525 ds_ci.depthBoundsTestEnable = VK_FALSE;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600526 if (failMask & BsoFailDepthBounds) {
527 ds_ci.depthBoundsTestEnable = VK_TRUE;
Tobin Ehlis21c88352016-05-26 06:15:45 -0600528 ds_ci.maxDepthBounds = 0.0f;
529 ds_ci.minDepthBounds = 0.0f;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600530 }
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600531 ds_ci.stencilTestEnable = VK_TRUE;
532 ds_ci.front = stencil;
533 ds_ci.back = stencil;
Tony Barboureb254902015-07-15 12:50:33 -0600534
Tobin Ehlis4bf96d12015-06-25 11:58:41 -0600535 pipelineobj.SetDepthStencil(&ds_ci);
Tobin Ehlisd332f282015-10-02 11:00:56 -0600536 pipelineobj.SetViewport(m_viewports);
537 pipelineobj.SetScissor(m_scissors);
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800538 descriptorSet.CreateVKDescriptorSet(commandBuffer);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600539 VkResult err = pipelineobj.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Cody Northrop29a08f22015-08-27 10:20:35 -0600540 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800541 commandBuffer->BindPipeline(pipelineobj);
542 commandBuffer->BindDescriptorSet(descriptorSet);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500543}
544
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600545class VkPositiveLayerTest : public VkLayerTest {
546 public:
547 protected:
548};
549
Ian Elliott2c1daf52016-05-12 09:41:46 -0600550class VkWsiEnabledLayerTest : public VkLayerTest {
551 public:
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600552 protected:
553 VkWsiEnabledLayerTest() { m_enableWSI = true; }
Ian Elliott2c1daf52016-05-12 09:41:46 -0600554};
555
Mark Muellerdfe37552016-07-07 14:47:42 -0600556class VkBufferTest {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600557 public:
Mark Muellerdfe37552016-07-07 14:47:42 -0600558 enum eTestEnFlags {
559 eDoubleDelete,
560 eInvalidDeviceOffset,
561 eInvalidMemoryOffset,
562 eBindNullBuffer,
563 eFreeInvalidHandle,
Mark Mueller4042b652016-09-05 22:52:21 -0600564 eNone,
Mark Muellerdfe37552016-07-07 14:47:42 -0600565 };
566
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600567 enum eTestConditions { eOffsetAlignment = 1 };
Mark Muellerdfe37552016-07-07 14:47:42 -0600568
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600569 static bool GetTestConditionValid(VkDeviceObj *aVulkanDevice, eTestEnFlags aTestFlag, VkBufferUsageFlags aBufferUsage = 0) {
570 if (eInvalidDeviceOffset != aTestFlag && eInvalidMemoryOffset != aTestFlag) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600571 return true;
572 }
573 VkDeviceSize offset_limit = 0;
574 if (eInvalidMemoryOffset == aTestFlag) {
575 VkBuffer vulkanBuffer;
576 VkBufferCreateInfo buffer_create_info = {};
577 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
578 buffer_create_info.size = 32;
579 buffer_create_info.usage = aBufferUsage;
580
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600581 vkCreateBuffer(aVulkanDevice->device(), &buffer_create_info, nullptr, &vulkanBuffer);
Mark Mueller4042b652016-09-05 22:52:21 -0600582 VkMemoryRequirements memory_reqs = {};
Mark Muellerdfe37552016-07-07 14:47:42 -0600583
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600584 vkGetBufferMemoryRequirements(aVulkanDevice->device(), vulkanBuffer, &memory_reqs);
Mark Muellerdfe37552016-07-07 14:47:42 -0600585 vkDestroyBuffer(aVulkanDevice->device(), vulkanBuffer, nullptr);
586 offset_limit = memory_reqs.alignment;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600587 } else if ((VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT | VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT) & aBufferUsage) {
588 offset_limit = aVulkanDevice->props.limits.minTexelBufferOffsetAlignment;
Mark Muellerdfe37552016-07-07 14:47:42 -0600589 } else if (VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT & aBufferUsage) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600590 offset_limit = aVulkanDevice->props.limits.minUniformBufferOffsetAlignment;
Mark Muellerdfe37552016-07-07 14:47:42 -0600591 } else if (VK_BUFFER_USAGE_STORAGE_BUFFER_BIT & aBufferUsage) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600592 offset_limit = aVulkanDevice->props.limits.minStorageBufferOffsetAlignment;
Mark Muellerdfe37552016-07-07 14:47:42 -0600593 }
594 if (eOffsetAlignment < offset_limit) {
595 return true;
596 }
597 return false;
598 }
599
600 // A constructor which performs validation tests within construction.
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600601 VkBufferTest(VkDeviceObj *aVulkanDevice, VkBufferUsageFlags aBufferUsage, eTestEnFlags aTestFlag = eNone)
602 : AllocateCurrent(false), BoundCurrent(false), CreateCurrent(false), VulkanDevice(aVulkanDevice->device()) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600603
604 if (eBindNullBuffer == aTestFlag) {
605 VulkanMemory = 0;
606 vkBindBufferMemory(VulkanDevice, VulkanBuffer, VulkanMemory, 0);
607 } else {
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(VulkanDevice, &buffer_create_info, nullptr, &VulkanBuffer);
Mark Muellerdfe37552016-07-07 14:47:42 -0600614
615 CreateCurrent = true;
616
617 VkMemoryRequirements memory_requirements;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600618 vkGetBufferMemoryRequirements(VulkanDevice, VulkanBuffer, &memory_requirements);
Mark Muellerdfe37552016-07-07 14:47:42 -0600619
620 VkMemoryAllocateInfo memory_allocate_info = {};
621 memory_allocate_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
622 memory_allocate_info.allocationSize = memory_requirements.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600623 bool pass = aVulkanDevice->phy().set_memory_type(memory_requirements.memoryTypeBits, &memory_allocate_info,
624 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
Mark Muellerdfe37552016-07-07 14:47:42 -0600625 if (!pass) {
626 vkDestroyBuffer(VulkanDevice, VulkanBuffer, nullptr);
627 return;
628 }
629
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600630 vkAllocateMemory(VulkanDevice, &memory_allocate_info, NULL, &VulkanMemory);
Mark Muellerdfe37552016-07-07 14:47:42 -0600631 AllocateCurrent = true;
632 // NB: 1 is intentionally an invalid offset value
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600633 const bool offset_en = eInvalidDeviceOffset == aTestFlag || eInvalidMemoryOffset == aTestFlag;
634 vkBindBufferMemory(VulkanDevice, VulkanBuffer, VulkanMemory, offset_en ? eOffsetAlignment : 0);
Mark Muellerdfe37552016-07-07 14:47:42 -0600635 BoundCurrent = true;
636
637 InvalidDeleteEn = (eFreeInvalidHandle == aTestFlag);
638 }
639 }
640
641 ~VkBufferTest() {
642 if (CreateCurrent) {
643 vkDestroyBuffer(VulkanDevice, VulkanBuffer, nullptr);
644 }
645 if (AllocateCurrent) {
646 if (InvalidDeleteEn) {
647 union {
648 VkDeviceMemory device_memory;
649 unsigned long long index_access;
650 } bad_index;
651
652 bad_index.device_memory = VulkanMemory;
653 bad_index.index_access++;
654
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600655 vkFreeMemory(VulkanDevice, bad_index.device_memory, nullptr);
Mark Muellerdfe37552016-07-07 14:47:42 -0600656 }
657 vkFreeMemory(VulkanDevice, VulkanMemory, nullptr);
658 }
659 }
660
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600661 bool GetBufferCurrent() { return AllocateCurrent && BoundCurrent && CreateCurrent; }
Mark Muellerdfe37552016-07-07 14:47:42 -0600662
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600663 const VkBuffer &GetBuffer() { return VulkanBuffer; }
Mark Muellerdfe37552016-07-07 14:47:42 -0600664
665 void TestDoubleDestroy() {
666 // Destroy the buffer but leave the flag set, which will cause
667 // the buffer to be destroyed again in the destructor.
668 vkDestroyBuffer(VulkanDevice, VulkanBuffer, nullptr);
669 }
670
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600671 protected:
Mark Muellerdfe37552016-07-07 14:47:42 -0600672 bool AllocateCurrent;
673 bool BoundCurrent;
674 bool CreateCurrent;
675 bool InvalidDeleteEn;
676
677 VkBuffer VulkanBuffer;
678 VkDevice VulkanDevice;
679 VkDeviceMemory VulkanMemory;
Mark Muellerdfe37552016-07-07 14:47:42 -0600680};
681
682class VkVerticesObj {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600683 public:
684 VkVerticesObj(VkDeviceObj *aVulkanDevice, unsigned aAttributeCount, unsigned aBindingCount, unsigned aByteStride,
Mark Muellerdfe37552016-07-07 14:47:42 -0600685 VkDeviceSize aVertexCount, const float *aVerticies)
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600686 : BoundCurrent(false), AttributeCount(aAttributeCount), BindingCount(aBindingCount), BindId(BindIdGenerator),
Mark Muellerdfe37552016-07-07 14:47:42 -0600687 PipelineVertexInputStateCreateInfo(),
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600688 VulkanMemoryBuffer(aVulkanDevice, 1, static_cast<int>(aByteStride * aVertexCount),
689 reinterpret_cast<const void *>(aVerticies), VK_BUFFER_USAGE_VERTEX_BUFFER_BIT) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600690 BindIdGenerator++; // NB: This can wrap w/misuse
691
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600692 VertexInputAttributeDescription = new VkVertexInputAttributeDescription[AttributeCount];
693 VertexInputBindingDescription = new VkVertexInputBindingDescription[BindingCount];
Mark Muellerdfe37552016-07-07 14:47:42 -0600694
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600695 PipelineVertexInputStateCreateInfo.pVertexAttributeDescriptions = VertexInputAttributeDescription;
696 PipelineVertexInputStateCreateInfo.vertexAttributeDescriptionCount = AttributeCount;
697 PipelineVertexInputStateCreateInfo.pVertexBindingDescriptions = VertexInputBindingDescription;
698 PipelineVertexInputStateCreateInfo.vertexBindingDescriptionCount = BindingCount;
699 PipelineVertexInputStateCreateInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
Mark Muellerdfe37552016-07-07 14:47:42 -0600700
701 unsigned i = 0;
702 do {
703 VertexInputAttributeDescription[i].binding = BindId;
704 VertexInputAttributeDescription[i].location = i;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600705 VertexInputAttributeDescription[i].format = VK_FORMAT_R32G32B32_SFLOAT;
706 VertexInputAttributeDescription[i].offset = sizeof(float) * aByteStride;
Mark Muellerdfe37552016-07-07 14:47:42 -0600707 i++;
708 } while (AttributeCount < i);
709
710 i = 0;
711 do {
712 VertexInputBindingDescription[i].binding = BindId;
713 VertexInputBindingDescription[i].stride = aByteStride;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600714 VertexInputBindingDescription[i].inputRate = VK_VERTEX_INPUT_RATE_VERTEX;
Mark Muellerdfe37552016-07-07 14:47:42 -0600715 i++;
716 } while (BindingCount < i);
717 }
718
719 ~VkVerticesObj() {
720 if (VertexInputAttributeDescription) {
721 delete[] VertexInputAttributeDescription;
722 }
723 if (VertexInputBindingDescription) {
724 delete[] VertexInputBindingDescription;
725 }
726 }
727
728 bool AddVertexInputToPipe(VkPipelineObj &aPipelineObj) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600729 aPipelineObj.AddVertexInputAttribs(VertexInputAttributeDescription, AttributeCount);
730 aPipelineObj.AddVertexInputBindings(VertexInputBindingDescription, BindingCount);
Mark Muellerdfe37552016-07-07 14:47:42 -0600731 return true;
732 }
733
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600734 void BindVertexBuffers(VkCommandBuffer aCommandBuffer, unsigned aOffsetCount = 0, VkDeviceSize *aOffsetList = nullptr) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600735 VkDeviceSize *offsetList;
736 unsigned offsetCount;
737
738 if (aOffsetCount) {
739 offsetList = aOffsetList;
740 offsetCount = aOffsetCount;
741 } else {
742 offsetList = new VkDeviceSize[1]();
743 offsetCount = 1;
744 }
745
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600746 vkCmdBindVertexBuffers(aCommandBuffer, BindId, offsetCount, &VulkanMemoryBuffer.handle(), offsetList);
Mark Muellerdfe37552016-07-07 14:47:42 -0600747 BoundCurrent = true;
748
749 if (!aOffsetCount) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600750 delete[] offsetList;
Mark Muellerdfe37552016-07-07 14:47:42 -0600751 }
752 }
753
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600754 protected:
Mark Muellerdfe37552016-07-07 14:47:42 -0600755 static uint32_t BindIdGenerator;
756
757 bool BoundCurrent;
758 unsigned AttributeCount;
759 unsigned BindingCount;
760 uint32_t BindId;
761
762 VkPipelineVertexInputStateCreateInfo PipelineVertexInputStateCreateInfo;
763 VkVertexInputAttributeDescription *VertexInputAttributeDescription;
764 VkVertexInputBindingDescription *VertexInputBindingDescription;
765 VkConstantBufferObj VulkanMemoryBuffer;
766};
767
768uint32_t VkVerticesObj::BindIdGenerator;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500769// ********************************************************************************************************************
770// ********************************************************************************************************************
771// ********************************************************************************************************************
772// ********************************************************************************************************************
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600773#if PARAMETER_VALIDATION_TESTS
774TEST_F(VkLayerTest, RequiredParameter) {
775 TEST_DESCRIPTION("Specify VK_NULL_HANDLE, NULL, and 0 for required handle, "
776 "pointer, array, and array count parameters");
777
778 ASSERT_NO_FATAL_FAILURE(InitState());
779
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600780 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pFeatures specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600781 // Specify NULL for a pointer to a handle
782 // Expected to trigger an error with
783 // parameter_validation::validate_required_pointer
784 vkGetPhysicalDeviceFeatures(gpu(), NULL);
785 m_errorMonitor->VerifyFound();
786
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600787 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
788 "required parameter pQueueFamilyPropertyCount specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600789 // Specify NULL for pointer to array count
790 // Expected to trigger an error with parameter_validation::validate_array
Dustin Gravesa4bb8c12016-05-16 17:22:51 -0600791 vkGetPhysicalDeviceQueueFamilyProperties(gpu(), NULL, NULL);
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600792 m_errorMonitor->VerifyFound();
793
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600794 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter viewportCount must be greater than 0");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600795 // Specify 0 for a required array count
796 // Expected to trigger an error with parameter_validation::validate_array
797 VkViewport view_port = {};
798 m_commandBuffer->SetViewport(0, 0, &view_port);
799 m_errorMonitor->VerifyFound();
800
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600801 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pViewports specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600802 // Specify NULL for a required array
803 // Expected to trigger an error with parameter_validation::validate_array
804 m_commandBuffer->SetViewport(0, 1, NULL);
805 m_errorMonitor->VerifyFound();
806
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600807 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter memory specified as VK_NULL_HANDLE");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600808 // Specify VK_NULL_HANDLE for a required handle
809 // Expected to trigger an error with
810 // parameter_validation::validate_required_handle
811 vkUnmapMemory(device(), VK_NULL_HANDLE);
812 m_errorMonitor->VerifyFound();
813
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600814 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
815 "required parameter pFences[0] specified as VK_NULL_HANDLE");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600816 // Specify VK_NULL_HANDLE for a required handle array entry
817 // Expected to trigger an error with
818 // parameter_validation::validate_required_handle_array
819 VkFence fence = VK_NULL_HANDLE;
820 vkResetFences(device(), 1, &fence);
821 m_errorMonitor->VerifyFound();
822
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600823 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pAllocateInfo specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600824 // Specify NULL for a required struct pointer
825 // Expected to trigger an error with
826 // parameter_validation::validate_struct_type
827 VkDeviceMemory memory = VK_NULL_HANDLE;
828 vkAllocateMemory(device(), NULL, NULL, &memory);
829 m_errorMonitor->VerifyFound();
830
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600831 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "value of faceMask must not be 0");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600832 // Specify 0 for a required VkFlags parameter
833 // Expected to trigger an error with parameter_validation::validate_flags
834 m_commandBuffer->SetStencilReference(0, 0);
835 m_errorMonitor->VerifyFound();
836
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600837 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 -0600838 // Specify 0 for a required VkFlags array entry
839 // Expected to trigger an error with
840 // parameter_validation::validate_flags_array
841 VkSemaphore semaphore = VK_NULL_HANDLE;
842 VkPipelineStageFlags stageFlags = 0;
843 VkSubmitInfo submitInfo = {};
844 submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
845 submitInfo.waitSemaphoreCount = 1;
846 submitInfo.pWaitSemaphores = &semaphore;
847 submitInfo.pWaitDstStageMask = &stageFlags;
848 vkQueueSubmit(m_device->m_queue, 1, &submitInfo, VK_NULL_HANDLE);
849 m_errorMonitor->VerifyFound();
850}
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600851
Dustin Gravesfce74c02016-05-10 11:42:58 -0600852TEST_F(VkLayerTest, ReservedParameter) {
853 TEST_DESCRIPTION("Specify a non-zero value for a reserved parameter");
854
855 ASSERT_NO_FATAL_FAILURE(InitState());
856
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600857 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " must be 0");
Dustin Gravesfce74c02016-05-10 11:42:58 -0600858 // Specify 0 for a reserved VkFlags parameter
859 // Expected to trigger an error with
860 // parameter_validation::validate_reserved_flags
861 VkEvent event_handle = VK_NULL_HANDLE;
862 VkEventCreateInfo event_info = {};
863 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
864 event_info.flags = 1;
865 vkCreateEvent(device(), &event_info, NULL, &event_handle);
866 m_errorMonitor->VerifyFound();
867}
868
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600869TEST_F(VkLayerTest, InvalidStructSType) {
870 TEST_DESCRIPTION("Specify an invalid VkStructureType for a Vulkan "
871 "structure's sType field");
872
873 ASSERT_NO_FATAL_FAILURE(InitState());
874
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600875 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pAllocateInfo->sType must be");
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600876 // Zero struct memory, effectively setting sType to
877 // VK_STRUCTURE_TYPE_APPLICATION_INFO
878 // Expected to trigger an error with
879 // parameter_validation::validate_struct_type
880 VkMemoryAllocateInfo alloc_info = {};
881 VkDeviceMemory memory = VK_NULL_HANDLE;
882 vkAllocateMemory(device(), &alloc_info, NULL, &memory);
883 m_errorMonitor->VerifyFound();
884
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600885 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pSubmits[0].sType must be");
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600886 // Zero struct memory, effectively setting sType to
887 // VK_STRUCTURE_TYPE_APPLICATION_INFO
888 // Expected to trigger an error with
889 // parameter_validation::validate_struct_type_array
890 VkSubmitInfo submit_info = {};
891 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
892 m_errorMonitor->VerifyFound();
893}
894
895TEST_F(VkLayerTest, InvalidStructPNext) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600896 TEST_DESCRIPTION("Specify an invalid value for a Vulkan structure's pNext field");
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600897
898 ASSERT_NO_FATAL_FAILURE(InitState());
899
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600900 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "value of pCreateInfo->pNext must be NULL");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600901 // Set VkMemoryAllocateInfo::pNext to a non-NULL value, when pNext must be NULL.
Karl Schultz38b50992016-07-11 16:09:09 -0600902 // Need to pick a function that has no allowed pNext structure types.
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600903 // Expected to trigger an error with parameter_validation::validate_struct_pnext
Karl Schultz38b50992016-07-11 16:09:09 -0600904 VkEvent event = VK_NULL_HANDLE;
Karl Schultz70db3902016-07-11 16:22:10 -0600905 VkEventCreateInfo event_alloc_info = {};
Karl Schultz38b50992016-07-11 16:09:09 -0600906 // Zero-initialization will provide the correct sType
907 VkApplicationInfo app_info = {};
908 event_alloc_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
909 event_alloc_info.pNext = &app_info;
910 vkCreateEvent(device(), &event_alloc_info, NULL, &event);
911 m_errorMonitor->VerifyFound();
912
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600913 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
914 " chain includes a structure with unexpected VkStructureType ");
Karl Schultz38b50992016-07-11 16:09:09 -0600915 // Set VkMemoryAllocateInfo::pNext to a non-NULL value, but use
916 // a function that has allowed pNext structure types and specify
917 // a structure type that is not allowed.
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600918 // Expected to trigger an error with parameter_validation::validate_struct_pnext
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600919 VkDeviceMemory memory = VK_NULL_HANDLE;
Dustin Graves47b6cba2016-05-10 17:34:38 -0600920 VkMemoryAllocateInfo memory_alloc_info = {};
921 memory_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
922 memory_alloc_info.pNext = &app_info;
923 vkAllocateMemory(device(), &memory_alloc_info, NULL, &memory);
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600924 m_errorMonitor->VerifyFound();
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600925}
Dustin Graves5d33d532016-05-09 16:21:12 -0600926
927TEST_F(VkLayerTest, UnrecognizedValue) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600928 TEST_DESCRIPTION("Specify unrecognized Vulkan enumeration, flags, and VkBool32 values");
Dustin Graves5d33d532016-05-09 16:21:12 -0600929
930 ASSERT_NO_FATAL_FAILURE(InitState());
931
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600932 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "does not fall within the begin..end "
933 "range of the core VkFormat "
934 "enumeration tokens");
Dustin Graves5d33d532016-05-09 16:21:12 -0600935 // Specify an invalid VkFormat value
936 // Expected to trigger an error with
937 // parameter_validation::validate_ranged_enum
938 VkFormatProperties format_properties;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600939 vkGetPhysicalDeviceFormatProperties(gpu(), static_cast<VkFormat>(8000), &format_properties);
Dustin Graves5d33d532016-05-09 16:21:12 -0600940 m_errorMonitor->VerifyFound();
941
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600942 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 -0600943 // Specify an invalid VkFlags bitmask value
944 // Expected to trigger an error with parameter_validation::validate_flags
945 VkImageFormatProperties image_format_properties;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600946 vkGetPhysicalDeviceImageFormatProperties(gpu(), VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
947 static_cast<VkImageUsageFlags>(1 << 25), 0, &image_format_properties);
Dustin Graves5d33d532016-05-09 16:21:12 -0600948 m_errorMonitor->VerifyFound();
949
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600950 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 -0600951 // Specify an invalid VkFlags array entry
952 // Expected to trigger an error with
953 // parameter_validation::validate_flags_array
954 VkSemaphore semaphore = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600955 VkPipelineStageFlags stage_flags = static_cast<VkPipelineStageFlags>(1 << 25);
Dustin Graves5d33d532016-05-09 16:21:12 -0600956 VkSubmitInfo submit_info = {};
957 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
958 submit_info.waitSemaphoreCount = 1;
959 submit_info.pWaitSemaphores = &semaphore;
960 submit_info.pWaitDstStageMask = &stage_flags;
961 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
962 m_errorMonitor->VerifyFound();
963
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600964 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "is neither VK_TRUE nor VK_FALSE");
Dustin Graves5d33d532016-05-09 16:21:12 -0600965 // Specify an invalid VkBool32 value
966 // Expected to trigger a warning with
967 // parameter_validation::validate_bool32
968 VkSampler sampler = VK_NULL_HANDLE;
969 VkSamplerCreateInfo sampler_info = {};
970 sampler_info.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
971 sampler_info.pNext = NULL;
972 sampler_info.magFilter = VK_FILTER_NEAREST;
973 sampler_info.minFilter = VK_FILTER_NEAREST;
974 sampler_info.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
975 sampler_info.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
976 sampler_info.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
977 sampler_info.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
978 sampler_info.mipLodBias = 1.0;
979 sampler_info.maxAnisotropy = 1;
980 sampler_info.compareEnable = VK_FALSE;
981 sampler_info.compareOp = VK_COMPARE_OP_NEVER;
982 sampler_info.minLod = 1.0;
983 sampler_info.maxLod = 1.0;
984 sampler_info.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
985 sampler_info.unnormalizedCoordinates = VK_FALSE;
986 // Not VK_TRUE or VK_FALSE
987 sampler_info.anisotropyEnable = 3;
988 vkCreateSampler(m_device->device(), &sampler_info, NULL, &sampler);
989 m_errorMonitor->VerifyFound();
990}
Dustin Gravesfce74c02016-05-10 11:42:58 -0600991
992TEST_F(VkLayerTest, FailedReturnValue) {
993 TEST_DESCRIPTION("Check for a message describing a VkResult failure code");
994
995 ASSERT_NO_FATAL_FAILURE(InitState());
996
Dustin Graves13c1e2b2016-05-16 15:31:02 -0600997 // Find an unsupported image format
998 VkFormat unsupported = VK_FORMAT_UNDEFINED;
999 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
1000 VkFormat format = static_cast<VkFormat>(f);
1001 VkFormatProperties fProps = m_device->format_properties(format);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001002 if (format != VK_FORMAT_UNDEFINED && fProps.linearTilingFeatures == 0 && fProps.optimalTilingFeatures == 0) {
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001003 unsupported = format;
1004 break;
1005 }
1006 }
1007
1008 if (unsupported != VK_FORMAT_UNDEFINED) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001009 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
1010 "the requested format is not supported on this device");
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001011 // Specify an unsupported VkFormat value to generate a
1012 // VK_ERROR_FORMAT_NOT_SUPPORTED return code
1013 // Expected to trigger a warning from
1014 // parameter_validation::validate_result
1015 VkImageFormatProperties image_format_properties;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001016 VkResult err = vkGetPhysicalDeviceImageFormatProperties(gpu(), unsupported, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
1017 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, 0, &image_format_properties);
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001018 ASSERT_TRUE(err == VK_ERROR_FORMAT_NOT_SUPPORTED);
1019 m_errorMonitor->VerifyFound();
1020 }
Dustin Gravesfce74c02016-05-10 11:42:58 -06001021}
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001022
1023TEST_F(VkLayerTest, UpdateBufferAlignment) {
1024 TEST_DESCRIPTION("Check alignment parameters for vkCmdUpdateBuffer");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001025 uint32_t updateData[] = {1, 2, 3, 4, 5, 6, 7, 8};
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001026
1027 ASSERT_NO_FATAL_FAILURE(InitState());
1028
1029 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
1030 vk_testing::Buffer buffer;
1031 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
1032
Tony Barbour552f6c02016-12-21 14:34:07 -07001033 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001034 // Introduce failure by using dstOffset that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001035 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001036 m_commandBuffer->UpdateBuffer(buffer.handle(), 1, 4, updateData);
1037 m_errorMonitor->VerifyFound();
1038
1039 // Introduce failure by using dataSize that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001040 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001041 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, 6, updateData);
1042 m_errorMonitor->VerifyFound();
1043
1044 // Introduce failure by using dataSize that is < 0
1045 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001046 "must be greater than zero and less than or equal to 65536");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001047 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, -44, updateData);
1048 m_errorMonitor->VerifyFound();
1049
1050 // Introduce failure by using dataSize that is > 65536
1051 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001052 "must be greater than zero and less than or equal to 65536");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001053 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, 80000, updateData);
1054 m_errorMonitor->VerifyFound();
1055
Tony Barbour552f6c02016-12-21 14:34:07 -07001056 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001057}
1058
1059TEST_F(VkLayerTest, FillBufferAlignment) {
1060 TEST_DESCRIPTION("Check alignment parameters for vkCmdFillBuffer");
1061
1062 ASSERT_NO_FATAL_FAILURE(InitState());
1063
1064 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
1065 vk_testing::Buffer buffer;
1066 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
1067
Tony Barbour552f6c02016-12-21 14:34:07 -07001068 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001069
1070 // Introduce failure by using dstOffset that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001071 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001072 m_commandBuffer->FillBuffer(buffer.handle(), 1, 4, 0x11111111);
1073 m_errorMonitor->VerifyFound();
1074
1075 // Introduce failure by using size that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001076 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001077 m_commandBuffer->FillBuffer(buffer.handle(), 0, 6, 0x11111111);
1078 m_errorMonitor->VerifyFound();
1079
1080 // Introduce failure by using size that is zero
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001081 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "must be greater than zero");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001082 m_commandBuffer->FillBuffer(buffer.handle(), 0, 0, 0x11111111);
1083 m_errorMonitor->VerifyFound();
1084
Tony Barbour552f6c02016-12-21 14:34:07 -07001085 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001086}
Dustin Graves40f35822016-06-23 11:12:53 -06001087
Cortd889ff92016-07-27 09:51:27 -07001088TEST_F(VkLayerTest, PSOPolygonModeInvalid) {
1089 VkResult err;
1090
1091 TEST_DESCRIPTION("Attempt to use a non-solid polygon fill mode in a "
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001092 "pipeline when this feature is not enabled.");
Cortd889ff92016-07-27 09:51:27 -07001093
1094 ASSERT_NO_FATAL_FAILURE(InitState());
1095 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1096
1097 std::vector<const char *> device_extension_names;
1098 auto features = m_device->phy().features();
1099 // Artificially disable support for non-solid fill modes
1100 features.fillModeNonSolid = false;
1101 // The sacrificial device object
1102 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
1103
1104 VkRenderpassObj render_pass(&test_device);
1105
1106 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1107 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1108 pipeline_layout_ci.setLayoutCount = 0;
1109 pipeline_layout_ci.pSetLayouts = NULL;
1110
1111 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001112 err = vkCreatePipelineLayout(test_device.device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Cortd889ff92016-07-27 09:51:27 -07001113 ASSERT_VK_SUCCESS(err);
1114
1115 VkPipelineRasterizationStateCreateInfo rs_ci = {};
1116 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
1117 rs_ci.pNext = nullptr;
1118 rs_ci.lineWidth = 1.0f;
1119 rs_ci.rasterizerDiscardEnable = true;
1120
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001121 VkShaderObj vs(&test_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
1122 VkShaderObj fs(&test_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Cortd889ff92016-07-27 09:51:27 -07001123
Mark Lobodzinski5e644732016-08-15 16:51:19 -06001124 // Set polygonMode to unsupported value POINT, should fail
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001125 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1126 "polygonMode cannot be VK_POLYGON_MODE_POINT or VK_POLYGON_MODE_LINE");
Cortd889ff92016-07-27 09:51:27 -07001127 {
1128 VkPipelineObj pipe(&test_device);
1129 pipe.AddShader(&vs);
1130 pipe.AddShader(&fs);
1131 pipe.AddColorAttachment();
1132 // Introduce failure by setting unsupported polygon mode
1133 rs_ci.polygonMode = VK_POLYGON_MODE_POINT;
1134 pipe.SetRasterization(&rs_ci);
1135 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
1136 }
1137 m_errorMonitor->VerifyFound();
1138
1139 // Try again with polygonMode=LINE, should fail
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001140 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1141 "polygonMode cannot be VK_POLYGON_MODE_POINT or VK_POLYGON_MODE_LINE");
Cortd889ff92016-07-27 09:51:27 -07001142 {
1143 VkPipelineObj pipe(&test_device);
1144 pipe.AddShader(&vs);
1145 pipe.AddShader(&fs);
1146 pipe.AddColorAttachment();
1147 // Introduce failure by setting unsupported polygon mode
1148 rs_ci.polygonMode = VK_POLYGON_MODE_LINE;
1149 pipe.SetRasterization(&rs_ci);
1150 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
1151 }
1152 m_errorMonitor->VerifyFound();
1153
Cortd889ff92016-07-27 09:51:27 -07001154 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, NULL);
1155}
1156
Dustin Gravesffa90fa2016-05-06 11:20:38 -06001157#endif // PARAMETER_VALIDATION_TESTS
1158
Tobin Ehlis0788f522015-05-26 16:11:58 -06001159#if MEM_TRACKER_TESTS
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001160#if 0
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001161TEST_F(VkLayerTest, CallResetCommandBufferBeforeCompletion)
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001162{
1163 vk_testing::Fence testFence;
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001164 VkFenceCreateInfo fenceInfo = {};
1165 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1166 fenceInfo.pNext = NULL;
1167 fenceInfo.flags = 0;
1168
Mike Weiblencce7ec72016-10-17 19:33:05 -06001169 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Resetting command buffer");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001170
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001171 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbourc1eb1a52015-07-20 13:00:10 -06001172
1173 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
1174 vk_testing::Buffer buffer;
1175 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001176
Tony Barbourfe3351b2015-07-28 10:17:20 -06001177 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001178 m_commandBuffer->FillBuffer(buffer.handle(), 0, 4, 0x11111111);
Tony Barbourfe3351b2015-07-28 10:17:20 -06001179 EndCommandBuffer();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001180
1181 testFence.init(*m_device, fenceInfo);
1182
1183 // Bypass framework since it does the waits automatically
1184 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001185 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08001186 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1187 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001188 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001189 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07001190 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001191 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001192 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08001193 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001194 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06001195
1196 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001197 ASSERT_VK_SUCCESS( err );
1198
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001199 // Introduce failure by calling begin again before checking fence
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001200 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001201
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001202 m_errorMonitor->VerifyFound();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001203}
1204
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001205TEST_F(VkLayerTest, CallBeginCommandBufferBeforeCompletion)
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001206{
1207 vk_testing::Fence testFence;
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001208 VkFenceCreateInfo fenceInfo = {};
1209 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1210 fenceInfo.pNext = NULL;
1211 fenceInfo.flags = 0;
1212
Mike Weiblencce7ec72016-10-17 19:33:05 -06001213 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Calling vkBeginCommandBuffer() on active command buffer");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001214
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001215 ASSERT_NO_FATAL_FAILURE(InitState());
1216 ASSERT_NO_FATAL_FAILURE(InitViewport());
1217 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1218
Tony Barbourfe3351b2015-07-28 10:17:20 -06001219 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001220 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbourfe3351b2015-07-28 10:17:20 -06001221 EndCommandBuffer();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001222
1223 testFence.init(*m_device, fenceInfo);
1224
1225 // Bypass framework since it does the waits automatically
1226 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001227 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08001228 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1229 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001230 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001231 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07001232 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001233 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001234 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08001235 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001236 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06001237
1238 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001239 ASSERT_VK_SUCCESS( err );
1240
Jon Ashburnf19916e2016-01-11 13:12:43 -07001241 VkCommandBufferInheritanceInfo hinfo = {};
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001242 VkCommandBufferBeginInfo info = {};
1243 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
1244 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001245 info.renderPass = VK_NULL_HANDLE;
1246 info.subpass = 0;
1247 info.framebuffer = VK_NULL_HANDLE;
Chia-I Wub8d47ae2015-11-11 10:18:12 +08001248 info.occlusionQueryEnable = VK_FALSE;
1249 info.queryFlags = 0;
1250 info.pipelineStatistics = 0;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001251
1252 // Introduce failure by calling BCB again before checking fence
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001253 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001254
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001255 m_errorMonitor->VerifyFound();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001256}
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001257#endif
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001258
Mark Lobodzinski833bb552016-12-15 07:41:13 -07001259TEST_F(VkLayerTest, SparseBindingImageBufferCreate) {
1260 TEST_DESCRIPTION("Create buffer/image with sparse attributes but without the sparse_binding bit set");
1261
1262 ASSERT_NO_FATAL_FAILURE(InitState());
1263
1264 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00669);
1265 VkBuffer buffer;
1266 VkBufferCreateInfo buf_info = {};
1267 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1268 buf_info.pNext = NULL;
1269 buf_info.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
1270 buf_info.size = 2048;
1271 buf_info.queueFamilyIndexCount = 0;
1272 buf_info.pQueueFamilyIndices = NULL;
1273 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1274 buf_info.flags = VK_BUFFER_CREATE_SPARSE_RESIDENCY_BIT;
1275 vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1276 m_errorMonitor->VerifyFound();
1277
1278 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02160);
1279 VkImage image;
1280 VkImageCreateInfo image_create_info = {};
1281 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1282 image_create_info.pNext = NULL;
1283 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1284 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
1285 image_create_info.extent.width = 512;
1286 image_create_info.extent.height = 64;
1287 image_create_info.extent.depth = 1;
1288 image_create_info.mipLevels = 1;
1289 image_create_info.arrayLayers = 1;
1290 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
1291 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
1292 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
1293 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
1294 image_create_info.queueFamilyIndexCount = 0;
1295 image_create_info.pQueueFamilyIndices = NULL;
1296 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1297 image_create_info.flags = VK_BUFFER_CREATE_SPARSE_ALIASED_BIT;
1298 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1299 m_errorMonitor->VerifyFound();
1300}
1301
Tobin Ehlisf11be982016-05-11 13:52:53 -06001302TEST_F(VkLayerTest, InvalidMemoryAliasing) {
1303 TEST_DESCRIPTION("Create a buffer and image, allocate memory, and bind the "
1304 "buffer and image to memory such that they will alias.");
1305 VkResult err;
1306 bool pass;
1307 ASSERT_NO_FATAL_FAILURE(InitState());
1308
Tobin Ehlis077ded32016-05-12 17:39:13 -06001309 VkBuffer buffer, buffer2;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001310 VkImage image;
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001311 VkImage image2;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001312 VkDeviceMemory mem; // buffer will be bound first
1313 VkDeviceMemory mem_img; // image bound first
Tobin Ehlis077ded32016-05-12 17:39:13 -06001314 VkMemoryRequirements buff_mem_reqs, img_mem_reqs;
Rene Lindsayd14f5572016-12-16 14:57:18 -07001315 VkMemoryRequirements buff_mem_reqs2, img_mem_reqs2;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001316
1317 VkBufferCreateInfo buf_info = {};
1318 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1319 buf_info.pNext = NULL;
1320 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
1321 buf_info.size = 256;
1322 buf_info.queueFamilyIndexCount = 0;
1323 buf_info.pQueueFamilyIndices = NULL;
1324 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1325 buf_info.flags = 0;
1326 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1327 ASSERT_VK_SUCCESS(err);
1328
Tobin Ehlis077ded32016-05-12 17:39:13 -06001329 vkGetBufferMemoryRequirements(m_device->device(), buffer, &buff_mem_reqs);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001330
1331 VkImageCreateInfo image_create_info = {};
1332 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1333 image_create_info.pNext = NULL;
1334 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1335 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
1336 image_create_info.extent.width = 64;
1337 image_create_info.extent.height = 64;
1338 image_create_info.extent.depth = 1;
1339 image_create_info.mipLevels = 1;
1340 image_create_info.arrayLayers = 1;
1341 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehlis12a4b5e2016-08-08 12:33:11 -06001342 // Image tiling must be optimal to trigger error when aliasing linear buffer
1343 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001344 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
1345 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
1346 image_create_info.queueFamilyIndexCount = 0;
1347 image_create_info.pQueueFamilyIndices = NULL;
1348 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1349 image_create_info.flags = 0;
1350
Tobin Ehlisf11be982016-05-11 13:52:53 -06001351 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1352 ASSERT_VK_SUCCESS(err);
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001353 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image2);
1354 ASSERT_VK_SUCCESS(err);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001355
Tobin Ehlis077ded32016-05-12 17:39:13 -06001356 vkGetImageMemoryRequirements(m_device->device(), image, &img_mem_reqs);
1357
1358 VkMemoryAllocateInfo alloc_info = {};
1359 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1360 alloc_info.pNext = NULL;
1361 alloc_info.memoryTypeIndex = 0;
1362 // Ensure memory is big enough for both bindings
1363 alloc_info.allocationSize = buff_mem_reqs.size + img_mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001364 pass = m_device->phy().set_memory_type(buff_mem_reqs.memoryTypeBits & img_mem_reqs.memoryTypeBits, &alloc_info,
1365 VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001366 if (!pass) {
Tobin Ehlis077ded32016-05-12 17:39:13 -06001367 vkDestroyBuffer(m_device->device(), buffer, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001368 vkDestroyImage(m_device->device(), image, NULL);
1369 return;
1370 }
Tobin Ehlis077ded32016-05-12 17:39:13 -06001371 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
1372 ASSERT_VK_SUCCESS(err);
1373 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
1374 ASSERT_VK_SUCCESS(err);
1375
Rene Lindsayd14f5572016-12-16 14:57:18 -07001376 vkGetImageMemoryRequirements(m_device->device(), image2, &img_mem_reqs2);
1377
Tobin Ehlis32b2bbc2016-12-13 17:33:41 -07001378 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, " is aliased with linear buffer 0x");
Tobin Ehlis077ded32016-05-12 17:39:13 -06001379 // VALIDATION FAILURE due to image mapping overlapping buffer mapping
Tobin Ehlisf11be982016-05-11 13:52:53 -06001380 err = vkBindImageMemory(m_device->device(), image, mem, 0);
1381 m_errorMonitor->VerifyFound();
1382
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001383 // Now correctly bind image2 to second mem allocation before incorrectly
Tobin Ehlis077ded32016-05-12 17:39:13 -06001384 // aliasing buffer2
1385 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer2);
1386 ASSERT_VK_SUCCESS(err);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001387 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem_img);
1388 ASSERT_VK_SUCCESS(err);
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001389 err = vkBindImageMemory(m_device->device(), image2, mem_img, 0);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001390 ASSERT_VK_SUCCESS(err);
Tobin Ehlis32b2bbc2016-12-13 17:33:41 -07001391 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "is aliased with non-linear image 0x");
Rene Lindsayd14f5572016-12-16 14:57:18 -07001392 vkGetBufferMemoryRequirements(m_device->device(), buffer2, &buff_mem_reqs2);
Tobin Ehlis077ded32016-05-12 17:39:13 -06001393 err = vkBindBufferMemory(m_device->device(), buffer2, mem_img, 0);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001394 m_errorMonitor->VerifyFound();
1395
1396 vkDestroyBuffer(m_device->device(), buffer, NULL);
Tobin Ehlis077ded32016-05-12 17:39:13 -06001397 vkDestroyBuffer(m_device->device(), buffer2, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001398 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001399 vkDestroyImage(m_device->device(), image2, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001400 vkFreeMemory(m_device->device(), mem, NULL);
1401 vkFreeMemory(m_device->device(), mem_img, NULL);
1402}
1403
Tobin Ehlis35372522016-05-12 08:32:31 -06001404TEST_F(VkLayerTest, InvalidMemoryMapping) {
1405 TEST_DESCRIPTION("Attempt to map memory in a number of incorrect ways");
1406 VkResult err;
1407 bool pass;
1408 ASSERT_NO_FATAL_FAILURE(InitState());
1409
1410 VkBuffer buffer;
1411 VkDeviceMemory mem;
1412 VkMemoryRequirements mem_reqs;
1413
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001414 const VkDeviceSize atom_size = m_device->props.limits.nonCoherentAtomSize;
1415
Tobin Ehlis35372522016-05-12 08:32:31 -06001416 VkBufferCreateInfo buf_info = {};
1417 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1418 buf_info.pNext = NULL;
1419 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
1420 buf_info.size = 256;
1421 buf_info.queueFamilyIndexCount = 0;
1422 buf_info.pQueueFamilyIndices = NULL;
1423 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1424 buf_info.flags = 0;
1425 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1426 ASSERT_VK_SUCCESS(err);
1427
1428 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
1429 VkMemoryAllocateInfo alloc_info = {};
1430 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1431 alloc_info.pNext = NULL;
1432 alloc_info.memoryTypeIndex = 0;
1433
1434 // Ensure memory is big enough for both bindings
1435 static const VkDeviceSize allocation_size = 0x10000;
1436 alloc_info.allocationSize = allocation_size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001437 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 -06001438 if (!pass) {
1439 vkDestroyBuffer(m_device->device(), buffer, NULL);
1440 return;
1441 }
1442 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
1443 ASSERT_VK_SUCCESS(err);
1444
1445 uint8_t *pData;
1446 // Attempt to map memory size 0 is invalid
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001447 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 -06001448 err = vkMapMemory(m_device->device(), mem, 0, 0, 0, (void **)&pData);
1449 m_errorMonitor->VerifyFound();
1450 // Map memory twice
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001451 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001452 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001453 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1454 "VkMapMemory: Attempting to map memory on an already-mapped object ");
1455 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001456 m_errorMonitor->VerifyFound();
1457
1458 // Unmap the memory to avoid re-map error
1459 vkUnmapMemory(m_device->device(), mem);
1460 // overstep allocation with VK_WHOLE_SIZE
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001461 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1462 " with size of VK_WHOLE_SIZE oversteps total array size 0x");
1463 err = vkMapMemory(m_device->device(), mem, allocation_size + 1, VK_WHOLE_SIZE, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001464 m_errorMonitor->VerifyFound();
1465 // overstep allocation w/o VK_WHOLE_SIZE
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001466 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " oversteps total array size 0x");
1467 err = vkMapMemory(m_device->device(), mem, 1, allocation_size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001468 m_errorMonitor->VerifyFound();
1469 // Now error due to unmapping memory that's not mapped
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001470 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Unmapping Memory without memory being mapped: ");
Tobin Ehlis35372522016-05-12 08:32:31 -06001471 vkUnmapMemory(m_device->device(), mem);
1472 m_errorMonitor->VerifyFound();
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001473
Tobin Ehlis35372522016-05-12 08:32:31 -06001474 // Now map memory and cause errors due to flushing invalid ranges
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001475 err = vkMapMemory(m_device->device(), mem, 4 * atom_size, VK_WHOLE_SIZE, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001476 ASSERT_VK_SUCCESS(err);
1477 VkMappedMemoryRange mmr = {};
Chris Forbes3aec0892016-06-13 10:29:26 +12001478 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
Tobin Ehlis35372522016-05-12 08:32:31 -06001479 mmr.memory = mem;
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001480 mmr.offset = atom_size; // Error b/c offset less than offset of mapped mem
Mark Lobodzinskib3c675e2016-11-15 08:56:03 -07001481 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00642);
Tobin Ehlis35372522016-05-12 08:32:31 -06001482 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1483 m_errorMonitor->VerifyFound();
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001484
Tobin Ehlis35372522016-05-12 08:32:31 -06001485 // Now flush range that oversteps mapped range
1486 vkUnmapMemory(m_device->device(), mem);
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001487 err = vkMapMemory(m_device->device(), mem, 0, 4 * atom_size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001488 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001489 mmr.offset = atom_size;
1490 mmr.size = 4 * atom_size; // Flushing bounds exceed mapped bounds
Mark Lobodzinskib3c675e2016-11-15 08:56:03 -07001491 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00642);
1492 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1493 m_errorMonitor->VerifyFound();
1494
1495 // Now flush range with VK_WHOLE_SIZE that oversteps offset
1496 vkUnmapMemory(m_device->device(), mem);
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001497 err = vkMapMemory(m_device->device(), mem, 2 * atom_size, 4 * atom_size, 0, (void **)&pData);
Mark Lobodzinskib3c675e2016-11-15 08:56:03 -07001498 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001499 mmr.offset = atom_size;
Mark Lobodzinskib3c675e2016-11-15 08:56:03 -07001500 mmr.size = VK_WHOLE_SIZE;
1501 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00643);
Tobin Ehlis35372522016-05-12 08:32:31 -06001502 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1503 m_errorMonitor->VerifyFound();
1504
Tony Barboure3975eb2016-12-15 14:52:44 -07001505#if 0 // Planning discussion with working group on this validation check.
Mark Lobodzinski3826a4f2016-11-15 09:38:51 -07001506 // Some platforms have an atomsize of 1 which makes the test meaningless
1507 if (atom_size > 3) {
1508 // Now with an offset NOT a multiple of the device limit
1509 vkUnmapMemory(m_device->device(), mem);
1510 err = vkMapMemory(m_device->device(), mem, 0, 4 * atom_size, 0, (void **)&pData);
1511 ASSERT_VK_SUCCESS(err);
1512 mmr.offset = 3; // Not a multiple of atom_size
1513 mmr.size = VK_WHOLE_SIZE;
1514 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00644);
1515 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1516 m_errorMonitor->VerifyFound();
1517
1518 // Now with a size NOT a multiple of the device limit
1519 vkUnmapMemory(m_device->device(), mem);
1520 err = vkMapMemory(m_device->device(), mem, 0, 4 * atom_size, 0, (void **)&pData);
1521 ASSERT_VK_SUCCESS(err);
1522 mmr.offset = atom_size;
1523 mmr.size = 2 * atom_size + 1; // Not a multiple of atom_size
1524 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00645);
1525 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1526 m_errorMonitor->VerifyFound();
1527 }
Tony Barboure3975eb2016-12-15 14:52:44 -07001528#endif
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001529 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT,
1530 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Tobin Ehlis35372522016-05-12 08:32:31 -06001531 if (!pass) {
1532 vkFreeMemory(m_device->device(), mem, NULL);
1533 vkDestroyBuffer(m_device->device(), buffer, NULL);
1534 return;
1535 }
1536 // TODO : If we can get HOST_VISIBLE w/o HOST_COHERENT we can test cases of
1537 // MEMTRACK_INVALID_MAP in validateAndCopyNoncoherentMemoryToDriver()
1538
1539 vkDestroyBuffer(m_device->device(), buffer, NULL);
1540 vkFreeMemory(m_device->device(), mem, NULL);
1541}
1542
Chris Forbes09368e42016-10-13 11:59:22 +13001543#if 0 // disabled until PV gets real extension enable checks
Ian Elliott1c32c772016-04-28 14:47:13 -06001544TEST_F(VkLayerTest, EnableWsiBeforeUse) {
1545 VkResult err;
1546 bool pass;
1547
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001548 // FIXME: After we turn on this code for non-Linux platforms, uncomment the
1549 // following declaration (which is temporarily being moved below):
1550 // VkSurfaceKHR surface = VK_NULL_HANDLE;
Ian Elliott1c32c772016-04-28 14:47:13 -06001551 VkSwapchainKHR swapchain = VK_NULL_HANDLE;
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001552 VkSwapchainCreateInfoKHR swapchain_create_info = {VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR};
Ian Elliott1c32c772016-04-28 14:47:13 -06001553 uint32_t swapchain_image_count = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001554 // VkImage swapchain_images[1] = {VK_NULL_HANDLE};
Ian Elliott1c32c772016-04-28 14:47:13 -06001555 uint32_t image_index = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001556 // VkPresentInfoKHR present_info = {};
Ian Elliott1c32c772016-04-28 14:47:13 -06001557
1558 ASSERT_NO_FATAL_FAILURE(InitState());
1559
Ian Elliott3f06ce52016-04-29 14:46:21 -06001560#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
1561#if defined(VK_USE_PLATFORM_ANDROID_KHR)
1562 // Use the functions from the VK_KHR_android_surface extension without
1563 // enabling that extension:
1564
1565 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001566 VkAndroidSurfaceCreateInfoKHR android_create_info = {VK_STRUCTURE_TYPE_ANDROID_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001567 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1568 err = vkCreateAndroidSurfaceKHR(instance(), &android_create_info, NULL, &surface);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001569 pass = (err != VK_SUCCESS);
1570 ASSERT_TRUE(pass);
1571 m_errorMonitor->VerifyFound();
1572#endif // VK_USE_PLATFORM_ANDROID_KHR
1573
Ian Elliott3f06ce52016-04-29 14:46:21 -06001574#if defined(VK_USE_PLATFORM_MIR_KHR)
1575 // Use the functions from the VK_KHR_mir_surface extension without enabling
1576 // that extension:
1577
1578 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001579 VkMirSurfaceCreateInfoKHR mir_create_info = {VK_STRUCTURE_TYPE_MIR_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001580 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott3f06ce52016-04-29 14:46:21 -06001581 err = vkCreateMirSurfaceKHR(instance(), &mir_create_info, NULL, &surface);
1582 pass = (err != VK_SUCCESS);
1583 ASSERT_TRUE(pass);
1584 m_errorMonitor->VerifyFound();
1585
1586 // Tell whether an mir_connection supports presentation:
1587 MirConnection *mir_connection = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001588 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1589 vkGetPhysicalDeviceMirPresentationSupportKHR(gpu(), 0, mir_connection, visual_id);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001590 m_errorMonitor->VerifyFound();
1591#endif // VK_USE_PLATFORM_MIR_KHR
1592
Ian Elliott3f06ce52016-04-29 14:46:21 -06001593#if defined(VK_USE_PLATFORM_WAYLAND_KHR)
1594 // Use the functions from the VK_KHR_wayland_surface extension without
1595 // enabling that extension:
1596
1597 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001598 VkWaylandSurfaceCreateInfoKHR wayland_create_info = {VK_STRUCTURE_TYPE_WAYLAND_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 = vkCreateWaylandSurfaceKHR(instance(), &wayland_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
1605 // Tell whether an wayland_display supports presentation:
1606 struct wl_display wayland_display = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001607 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1608 vkGetPhysicalDeviceWaylandPresentationSupportKHR(gpu(), 0, &wayland_display);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001609 m_errorMonitor->VerifyFound();
1610#endif // VK_USE_PLATFORM_WAYLAND_KHR
Ian Elliott489eec02016-05-05 14:12:44 -06001611#endif // NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott3f06ce52016-04-29 14:46:21 -06001612
Ian Elliott3f06ce52016-04-29 14:46:21 -06001613#if defined(VK_USE_PLATFORM_WIN32_KHR)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001614 // FIXME: REMOVE THIS HERE, AND UNCOMMENT ABOVE, WHEN THIS TEST HAS BEEN PORTED
1615 // TO NON-LINUX PLATFORMS:
1616 VkSurfaceKHR surface = VK_NULL_HANDLE;
Ian Elliott3f06ce52016-04-29 14:46:21 -06001617 // Use the functions from the VK_KHR_win32_surface extension without
1618 // enabling that extension:
1619
1620 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001621 VkWin32SurfaceCreateInfoKHR win32_create_info = {VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001622 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1623 err = vkCreateWin32SurfaceKHR(instance(), &win32_create_info, NULL, &surface);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001624 pass = (err != VK_SUCCESS);
1625 ASSERT_TRUE(pass);
1626 m_errorMonitor->VerifyFound();
1627
1628 // Tell whether win32 supports presentation:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001629 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott489eec02016-05-05 14:12:44 -06001630 vkGetPhysicalDeviceWin32PresentationSupportKHR(gpu(), 0);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001631 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001632// Set this (for now, until all platforms are supported and tested):
1633#define NEED_TO_TEST_THIS_ON_PLATFORM
1634#endif // VK_USE_PLATFORM_WIN32_KHR
Tony Barbour2e7bd402016-11-14 14:46:33 -07001635#if defined(VK_USE_PLATFORM_XCB_KHR) || defined (VK_USE_PLATFORM_XLIB_KHR)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001636 // FIXME: REMOVE THIS HERE, AND UNCOMMENT ABOVE, WHEN THIS TEST HAS BEEN PORTED
1637 // TO NON-LINUX PLATFORMS:
1638 VkSurfaceKHR surface = VK_NULL_HANDLE;
Tony Barbour2e7bd402016-11-14 14:46:33 -07001639#endif
1640#if defined(VK_USE_PLATFORM_XCB_KHR)
Ian Elliott1c32c772016-04-28 14:47:13 -06001641 // Use the functions from the VK_KHR_xcb_surface extension without enabling
1642 // that extension:
1643
1644 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001645 VkXcbSurfaceCreateInfoKHR xcb_create_info = {VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001646 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001647 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
1648 pass = (err != VK_SUCCESS);
1649 ASSERT_TRUE(pass);
1650 m_errorMonitor->VerifyFound();
1651
1652 // Tell whether an xcb_visualid_t supports presentation:
Ian Elliott3f06ce52016-04-29 14:46:21 -06001653 xcb_connection_t *xcb_connection = NULL;
Ian Elliott1c32c772016-04-28 14:47:13 -06001654 xcb_visualid_t visual_id = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001655 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1656 vkGetPhysicalDeviceXcbPresentationSupportKHR(gpu(), 0, xcb_connection, visual_id);
Ian Elliott1c32c772016-04-28 14:47:13 -06001657 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001658// Set this (for now, until all platforms are supported and tested):
1659#define NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06001660#endif // VK_USE_PLATFORM_XCB_KHR
1661
Ian Elliott12630812016-04-29 14:35:43 -06001662#if defined(VK_USE_PLATFORM_XLIB_KHR)
1663 // Use the functions from the VK_KHR_xlib_surface extension without enabling
1664 // that extension:
1665
1666 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001667 VkXlibSurfaceCreateInfoKHR xlib_create_info = {VK_STRUCTURE_TYPE_XLIB_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001668 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott12630812016-04-29 14:35:43 -06001669 err = vkCreateXlibSurfaceKHR(instance(), &xlib_create_info, NULL, &surface);
1670 pass = (err != VK_SUCCESS);
1671 ASSERT_TRUE(pass);
1672 m_errorMonitor->VerifyFound();
1673
1674 // Tell whether an Xlib VisualID supports presentation:
1675 Display *dpy = NULL;
1676 VisualID visual = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001677 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott12630812016-04-29 14:35:43 -06001678 vkGetPhysicalDeviceXlibPresentationSupportKHR(gpu(), 0, dpy, visual);
1679 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001680// Set this (for now, until all platforms are supported and tested):
1681#define NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott12630812016-04-29 14:35:43 -06001682#endif // VK_USE_PLATFORM_XLIB_KHR
1683
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001684// Use the functions from the VK_KHR_surface extension without enabling
1685// that extension:
Ian Elliott1c32c772016-04-28 14:47:13 -06001686
Ian Elliott489eec02016-05-05 14:12:44 -06001687#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06001688 // Destroy a surface:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001689 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001690 vkDestroySurfaceKHR(instance(), surface, NULL);
1691 m_errorMonitor->VerifyFound();
1692
1693 // Check if surface supports presentation:
1694 VkBool32 supported = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001695 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001696 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
1697 pass = (err != VK_SUCCESS);
1698 ASSERT_TRUE(pass);
1699 m_errorMonitor->VerifyFound();
1700
1701 // Check surface capabilities:
1702 VkSurfaceCapabilitiesKHR capabilities = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001703 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1704 err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), surface, &capabilities);
Ian Elliott1c32c772016-04-28 14:47:13 -06001705 pass = (err != VK_SUCCESS);
1706 ASSERT_TRUE(pass);
1707 m_errorMonitor->VerifyFound();
1708
1709 // Check surface formats:
1710 uint32_t format_count = 0;
1711 VkSurfaceFormatKHR *formats = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001712 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1713 err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &format_count, formats);
Ian Elliott1c32c772016-04-28 14:47:13 -06001714 pass = (err != VK_SUCCESS);
1715 ASSERT_TRUE(pass);
1716 m_errorMonitor->VerifyFound();
1717
1718 // Check surface present modes:
1719 uint32_t present_mode_count = 0;
1720 VkSurfaceFormatKHR *present_modes = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001721 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1722 err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &present_mode_count, present_modes);
Ian Elliott1c32c772016-04-28 14:47:13 -06001723 pass = (err != VK_SUCCESS);
1724 ASSERT_TRUE(pass);
1725 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001726#endif // NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06001727
Ian Elliott1c32c772016-04-28 14:47:13 -06001728 // Use the functions from the VK_KHR_swapchain extension without enabling
1729 // that extension:
1730
1731 // Create a swapchain:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001732 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001733 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
1734 swapchain_create_info.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001735 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
Ian Elliott1c32c772016-04-28 14:47:13 -06001736 pass = (err != VK_SUCCESS);
1737 ASSERT_TRUE(pass);
1738 m_errorMonitor->VerifyFound();
1739
1740 // Get the images from the swapchain:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001741 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1742 err = vkGetSwapchainImagesKHR(m_device->device(), swapchain, &swapchain_image_count, NULL);
Ian Elliott1c32c772016-04-28 14:47:13 -06001743 pass = (err != VK_SUCCESS);
1744 ASSERT_TRUE(pass);
1745 m_errorMonitor->VerifyFound();
1746
Chris Forbeseb7d5502016-09-13 18:19:21 +12001747 // Add a fence to avoid (justifiable) error about not providing fence OR semaphore
1748 VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
1749 VkFence fence;
1750 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
1751
Ian Elliott1c32c772016-04-28 14:47:13 -06001752 // Try to acquire an image:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001753 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Chris Forbeseb7d5502016-09-13 18:19:21 +12001754 err = vkAcquireNextImageKHR(m_device->device(), swapchain, 0, VK_NULL_HANDLE, fence, &image_index);
Ian Elliott1c32c772016-04-28 14:47:13 -06001755 pass = (err != VK_SUCCESS);
1756 ASSERT_TRUE(pass);
1757 m_errorMonitor->VerifyFound();
1758
Chris Forbeseb7d5502016-09-13 18:19:21 +12001759 vkDestroyFence(m_device->device(), fence, nullptr);
1760
Ian Elliott1c32c772016-04-28 14:47:13 -06001761 // Try to present an image:
Ian Elliott2c1daf52016-05-12 09:41:46 -06001762 //
1763 // NOTE: Currently can't test this because a real swapchain is needed (as
1764 // opposed to the fake one we created) in order for the layer to lookup the
1765 // VkDevice used to enable the extension:
Ian Elliott1c32c772016-04-28 14:47:13 -06001766
1767 // Destroy the swapchain:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001768 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001769 vkDestroySwapchainKHR(m_device->device(), swapchain, NULL);
1770 m_errorMonitor->VerifyFound();
1771}
Chris Forbes09368e42016-10-13 11:59:22 +13001772#endif
Ian Elliott1c32c772016-04-28 14:47:13 -06001773
Karl Schultz6addd812016-02-02 17:17:23 -07001774TEST_F(VkLayerTest, MapMemWithoutHostVisibleBit) {
1775 VkResult err;
1776 bool pass;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001777
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001778 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1779 "Mapping Memory without VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001780
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001781 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001782
1783 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07001784 VkImage image;
1785 VkDeviceMemory mem;
1786 VkMemoryRequirements mem_reqs;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001787
Karl Schultz6addd812016-02-02 17:17:23 -07001788 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
1789 const int32_t tex_width = 32;
1790 const int32_t tex_height = 32;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001791
Tony Barboureb254902015-07-15 12:50:33 -06001792 VkImageCreateInfo image_create_info = {};
1793 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07001794 image_create_info.pNext = NULL;
1795 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1796 image_create_info.format = tex_format;
1797 image_create_info.extent.width = tex_width;
1798 image_create_info.extent.height = tex_height;
1799 image_create_info.extent.depth = 1;
1800 image_create_info.mipLevels = 1;
1801 image_create_info.arrayLayers = 1;
1802 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
1803 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
1804 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
1805 image_create_info.flags = 0;
Chris Forbese65e4d02016-09-13 17:39:18 +12001806 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001807
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001808 VkMemoryAllocateInfo mem_alloc = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08001809 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07001810 mem_alloc.pNext = NULL;
1811 mem_alloc.allocationSize = 0;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001812
Chia-I Wuf7458c52015-10-26 21:10:41 +08001813 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001814 ASSERT_VK_SUCCESS(err);
1815
Karl Schultz6addd812016-02-02 17:17:23 -07001816 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001817
Mark Lobodzinski23065352015-05-29 09:32:35 -05001818 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001819
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001820 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 -07001821 if (!pass) { // If we can't find any unmappable memory this test doesn't
1822 // make sense
Chia-I Wuf7458c52015-10-26 21:10:41 +08001823 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbour02fdc7d2015-08-04 16:13:01 -06001824 return;
Mike Stroyand1c84a52015-08-18 14:40:24 -06001825 }
Mike Stroyan713b2d72015-08-04 10:49:29 -06001826
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001827 // allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001828 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001829 ASSERT_VK_SUCCESS(err);
1830
1831 // Try to bind free memory that has been freed
Tony Barbour67e99152015-07-10 14:10:27 -06001832 err = vkBindImageMemory(m_device->device(), image, mem, 0);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001833 ASSERT_VK_SUCCESS(err);
1834
1835 // Map memory as if to initialize the image
1836 void *mappedAddress = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001837 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, &mappedAddress);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001838
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001839 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06001840
Chia-I Wuf7458c52015-10-26 21:10:41 +08001841 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06001842 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001843}
1844
Karl Schultz6addd812016-02-02 17:17:23 -07001845TEST_F(VkLayerTest, RebindMemory) {
1846 VkResult err;
1847 bool pass;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001848
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001849 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "which has already been bound to mem object");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001850
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001851 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001852
1853 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07001854 VkImage image;
1855 VkDeviceMemory mem1;
1856 VkDeviceMemory mem2;
1857 VkMemoryRequirements mem_reqs;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001858
Karl Schultz6addd812016-02-02 17:17:23 -07001859 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
1860 const int32_t tex_width = 32;
1861 const int32_t tex_height = 32;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001862
Tony Barboureb254902015-07-15 12:50:33 -06001863 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07001864 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1865 image_create_info.pNext = NULL;
1866 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1867 image_create_info.format = tex_format;
1868 image_create_info.extent.width = tex_width;
1869 image_create_info.extent.height = tex_height;
1870 image_create_info.extent.depth = 1;
1871 image_create_info.mipLevels = 1;
1872 image_create_info.arrayLayers = 1;
1873 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
1874 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
1875 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
1876 image_create_info.flags = 0;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001877
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001878 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07001879 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1880 mem_alloc.pNext = NULL;
1881 mem_alloc.allocationSize = 0;
1882 mem_alloc.memoryTypeIndex = 0;
Tony Barboureb254902015-07-15 12:50:33 -06001883
Karl Schultz6addd812016-02-02 17:17:23 -07001884 // Introduce failure, do NOT set memProps to
1885 // VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
Tony Barboureb254902015-07-15 12:50:33 -06001886 mem_alloc.memoryTypeIndex = 1;
Chia-I Wuf7458c52015-10-26 21:10:41 +08001887 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001888 ASSERT_VK_SUCCESS(err);
1889
Karl Schultz6addd812016-02-02 17:17:23 -07001890 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001891
1892 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001893 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06001894 ASSERT_TRUE(pass);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001895
1896 // allocate 2 memory objects
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001897 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem1);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001898 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001899 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem2);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001900 ASSERT_VK_SUCCESS(err);
1901
1902 // Bind first memory object to Image object
Tony Barbour67e99152015-07-10 14:10:27 -06001903 err = vkBindImageMemory(m_device->device(), image, mem1, 0);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001904 ASSERT_VK_SUCCESS(err);
1905
Karl Schultz6addd812016-02-02 17:17:23 -07001906 // Introduce validation failure, try to bind a different memory object to
1907 // the same image object
Tony Barbour67e99152015-07-10 14:10:27 -06001908 err = vkBindImageMemory(m_device->device(), image, mem2, 0);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001909
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001910 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06001911
Chia-I Wuf7458c52015-10-26 21:10:41 +08001912 vkDestroyImage(m_device->device(), image, NULL);
1913 vkFreeMemory(m_device->device(), mem1, NULL);
1914 vkFreeMemory(m_device->device(), mem2, NULL);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001915}
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001916
Karl Schultz6addd812016-02-02 17:17:23 -07001917TEST_F(VkLayerTest, SubmitSignaledFence) {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001918 vk_testing::Fence testFence;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001919
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001920 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "submitted in SIGNALED state. Fences "
1921 "must be reset before being submitted");
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001922
1923 VkFenceCreateInfo fenceInfo = {};
Tony Barbour0b4d9562015-04-09 10:48:04 -06001924 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1925 fenceInfo.pNext = NULL;
1926 fenceInfo.flags = VK_FENCE_CREATE_SIGNALED_BIT;
Tony Barbour300a6082015-04-07 13:44:53 -06001927
Tony Barbour300a6082015-04-07 13:44:53 -06001928 ASSERT_NO_FATAL_FAILURE(InitState());
1929 ASSERT_NO_FATAL_FAILURE(InitViewport());
1930 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1931
Tony Barbour552f6c02016-12-21 14:34:07 -07001932 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001933 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbour552f6c02016-12-21 14:34:07 -07001934 m_commandBuffer->EndCommandBuffer();
Tony Barbour300a6082015-04-07 13:44:53 -06001935
1936 testFence.init(*m_device, fenceInfo);
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001937
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001938 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08001939 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1940 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001941 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001942 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07001943 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001944 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001945 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08001946 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001947 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06001948
1949 vkQueueSubmit(m_device->m_queue, 1, &submit_info, testFence.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07001950 vkQueueWaitIdle(m_device->m_queue);
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001951
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001952 m_errorMonitor->VerifyFound();
Tony Barbour0b4d9562015-04-09 10:48:04 -06001953}
Chris Forbes4e44c912016-06-16 10:20:00 +12001954
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001955TEST_F(VkLayerTest, InvalidUsageBits) {
1956 TEST_DESCRIPTION("Specify wrong usage for image then create conflicting view of image "
1957 "Initialize buffer with wrong usage then perform copy expecting errors "
1958 "from both the image and the buffer (2 calls)");
1959 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid usage flag for image ");
Tobin Ehlis41376e12015-07-03 08:45:14 -06001960
1961 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesd2b5fe42016-11-28 18:00:00 +13001962
1963 auto format = VK_FORMAT_D24_UNORM_S8_UINT;
1964
Tony Barbourf92621a2016-05-02 14:28:12 -06001965 VkImageObj image(m_device);
Tony Barbour75d79f02016-08-30 09:39:07 -06001966 // Initialize image with USAGE_TRANSIENT_ATTACHMENT
Chris Forbesd2b5fe42016-11-28 18:00:00 +13001967 image.init(128, 128, format, VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
Karl Schultzb5bc11e2016-05-04 08:36:08 -06001968 ASSERT_TRUE(image.initialized());
Tobin Ehlis41376e12015-07-03 08:45:14 -06001969
Tony Barbourf92621a2016-05-02 14:28:12 -06001970 VkImageView dsv;
1971 VkImageViewCreateInfo dsvci = {};
1972 dsvci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
1973 dsvci.image = image.handle();
1974 dsvci.viewType = VK_IMAGE_VIEW_TYPE_2D;
Chris Forbesd2b5fe42016-11-28 18:00:00 +13001975 dsvci.format = format;
Tony Barbourf92621a2016-05-02 14:28:12 -06001976 dsvci.subresourceRange.layerCount = 1;
1977 dsvci.subresourceRange.baseMipLevel = 0;
1978 dsvci.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001979 dsvci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
Tobin Ehlis41376e12015-07-03 08:45:14 -06001980
Tony Barbourf92621a2016-05-02 14:28:12 -06001981 // Create a view with depth / stencil aspect for image with different usage
1982 vkCreateImageView(m_device->device(), &dsvci, NULL, &dsv);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001983
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001984 m_errorMonitor->VerifyFound();
Tony Barbourf92621a2016-05-02 14:28:12 -06001985
1986 // Initialize buffer with TRANSFER_DST usage
1987 vk_testing::Buffer buffer;
1988 VkMemoryPropertyFlags reqs = 0;
1989 buffer.init_as_dst(*m_device, 128 * 128, reqs);
1990 VkBufferImageCopy region = {};
1991 region.bufferRowLength = 128;
1992 region.bufferImageHeight = 128;
1993 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
1994 region.imageSubresource.layerCount = 1;
1995 region.imageExtent.height = 16;
1996 region.imageExtent.width = 16;
1997 region.imageExtent.depth = 1;
1998
Tony Barbourf92621a2016-05-02 14:28:12 -06001999 // Buffer usage not set to TRANSFER_SRC and image usage not set to
2000 // TRANSFER_DST
Tony Barbour552f6c02016-12-21 14:34:07 -07002001 m_commandBuffer->BeginCommandBuffer();
Tony Barbourf92621a2016-05-02 14:28:12 -06002002
Chris Forbesda581202016-10-06 18:25:26 +13002003 // two separate errors from this call:
2004 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "image should have VK_IMAGE_USAGE_TRANSFER_DST_BIT");
2005 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "buffer should have VK_BUFFER_USAGE_TRANSFER_SRC_BIT");
2006
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002007 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
2008 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Tony Barbourf92621a2016-05-02 14:28:12 -06002009 m_errorMonitor->VerifyFound();
Tobin Ehlis41376e12015-07-03 08:45:14 -06002010}
Tony Barbour75d79f02016-08-30 09:39:07 -06002011
Tony Barbour75d79f02016-08-30 09:39:07 -06002012
Mark Lobodzinski209b5292015-09-17 09:44:05 -06002013#endif // MEM_TRACKER_TESTS
2014
Tobin Ehlis4bf96d12015-06-25 11:58:41 -06002015#if OBJ_TRACKER_TESTS
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002016
2017TEST_F(VkLayerTest, LeakAnObject) {
2018 VkResult err;
2019
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002020 TEST_DESCRIPTION("Create a fence and destroy its device without first destroying the fence.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002021
2022 // Note that we have to create a new device since destroying the
2023 // framework's device causes Teardown() to fail and just calling Teardown
2024 // will destroy the errorMonitor.
2025
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002026 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "has not been destroyed.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002027
2028 ASSERT_NO_FATAL_FAILURE(InitState());
2029
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002030 const std::vector<VkQueueFamilyProperties> queue_props = m_device->queue_props;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002031 std::vector<VkDeviceQueueCreateInfo> queue_info;
2032 queue_info.reserve(queue_props.size());
2033 std::vector<std::vector<float>> queue_priorities;
2034 for (uint32_t i = 0; i < (uint32_t)queue_props.size(); i++) {
2035 VkDeviceQueueCreateInfo qi = {};
2036 qi.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
2037 qi.pNext = NULL;
2038 qi.queueFamilyIndex = i;
2039 qi.queueCount = queue_props[i].queueCount;
2040 queue_priorities.emplace_back(qi.queueCount, 0.0f);
2041 qi.pQueuePriorities = queue_priorities[i].data();
2042 queue_info.push_back(qi);
2043 }
2044
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002045 std::vector<const char *> device_extension_names;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002046
2047 // The sacrificial device object
2048 VkDevice testDevice;
2049 VkDeviceCreateInfo device_create_info = {};
2050 auto features = m_device->phy().features();
2051 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
2052 device_create_info.pNext = NULL;
2053 device_create_info.queueCreateInfoCount = queue_info.size();
2054 device_create_info.pQueueCreateInfos = queue_info.data();
Tony Barbour4c70d102016-08-08 16:06:56 -06002055 device_create_info.enabledLayerCount = 0;
2056 device_create_info.ppEnabledLayerNames = NULL;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002057 device_create_info.pEnabledFeatures = &features;
2058 err = vkCreateDevice(gpu(), &device_create_info, NULL, &testDevice);
2059 ASSERT_VK_SUCCESS(err);
2060
2061 VkFence fence;
2062 VkFenceCreateInfo fence_create_info = {};
2063 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
2064 fence_create_info.pNext = NULL;
2065 fence_create_info.flags = 0;
2066 err = vkCreateFence(testDevice, &fence_create_info, NULL, &fence);
2067 ASSERT_VK_SUCCESS(err);
2068
2069 // Induce failure by not calling vkDestroyFence
2070 vkDestroyDevice(testDevice, NULL);
2071 m_errorMonitor->VerifyFound();
2072}
2073
2074TEST_F(VkLayerTest, InvalidCommandPoolConsistency) {
2075
2076 TEST_DESCRIPTION("Allocate command buffers from one command pool and "
2077 "attempt to delete them from another.");
2078
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002079 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "FreeCommandBuffers is attempting to free Command Buffer");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002080
Cody Northropc31a84f2016-08-22 10:41:47 -06002081 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002082 VkCommandPool command_pool_one;
2083 VkCommandPool command_pool_two;
2084
2085 VkCommandPoolCreateInfo pool_create_info{};
2086 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
2087 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
2088 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
2089
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002090 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool_one);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002091
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002092 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool_two);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002093
Chris Forbes5ab04ec2016-11-28 18:03:11 +13002094 VkCommandBuffer cb;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002095 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002096 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002097 command_buffer_allocate_info.commandPool = command_pool_one;
Chris Forbes5ab04ec2016-11-28 18:03:11 +13002098 command_buffer_allocate_info.commandBufferCount = 1;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002099 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Chris Forbes5ab04ec2016-11-28 18:03:11 +13002100 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &cb);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002101
Chris Forbes5ab04ec2016-11-28 18:03:11 +13002102 vkFreeCommandBuffers(m_device->device(), command_pool_two, 1, &cb);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002103
2104 m_errorMonitor->VerifyFound();
2105
2106 vkDestroyCommandPool(m_device->device(), command_pool_one, NULL);
2107 vkDestroyCommandPool(m_device->device(), command_pool_two, NULL);
2108}
2109
2110TEST_F(VkLayerTest, InvalidDescriptorPoolConsistency) {
2111 VkResult err;
2112
2113 TEST_DESCRIPTION("Allocate descriptor sets from one DS pool and "
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002114 "attempt to delete them from another.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002115
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002116 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "FreeDescriptorSets is attempting to free descriptorSet");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002117
2118 ASSERT_NO_FATAL_FAILURE(InitState());
2119 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2120
2121 VkDescriptorPoolSize ds_type_count = {};
2122 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
2123 ds_type_count.descriptorCount = 1;
2124
2125 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2126 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2127 ds_pool_ci.pNext = NULL;
2128 ds_pool_ci.flags = 0;
2129 ds_pool_ci.maxSets = 1;
2130 ds_pool_ci.poolSizeCount = 1;
2131 ds_pool_ci.pPoolSizes = &ds_type_count;
2132
2133 VkDescriptorPool ds_pool_one;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002134 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool_one);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002135 ASSERT_VK_SUCCESS(err);
2136
2137 // Create a second descriptor pool
2138 VkDescriptorPool ds_pool_two;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002139 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool_two);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002140 ASSERT_VK_SUCCESS(err);
2141
2142 VkDescriptorSetLayoutBinding dsl_binding = {};
2143 dsl_binding.binding = 0;
2144 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
2145 dsl_binding.descriptorCount = 1;
2146 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2147 dsl_binding.pImmutableSamplers = NULL;
2148
2149 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2150 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2151 ds_layout_ci.pNext = NULL;
2152 ds_layout_ci.bindingCount = 1;
2153 ds_layout_ci.pBindings = &dsl_binding;
2154
2155 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002156 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002157 ASSERT_VK_SUCCESS(err);
2158
2159 VkDescriptorSet descriptorSet;
2160 VkDescriptorSetAllocateInfo alloc_info = {};
2161 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
2162 alloc_info.descriptorSetCount = 1;
2163 alloc_info.descriptorPool = ds_pool_one;
2164 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002165 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002166 ASSERT_VK_SUCCESS(err);
2167
2168 err = vkFreeDescriptorSets(m_device->device(), ds_pool_two, 1, &descriptorSet);
2169
2170 m_errorMonitor->VerifyFound();
2171
2172 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2173 vkDestroyDescriptorPool(m_device->device(), ds_pool_one, NULL);
2174 vkDestroyDescriptorPool(m_device->device(), ds_pool_two, NULL);
2175}
2176
2177TEST_F(VkLayerTest, CreateUnknownObject) {
Karl Schultzf78bcdd2016-11-30 12:36:01 -07002178 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00788);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002179
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002180 TEST_DESCRIPTION("Pass an invalid image object handle into a Vulkan API call.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002181
2182 ASSERT_NO_FATAL_FAILURE(InitState());
2183
2184 // Pass bogus handle into GetImageMemoryRequirements
2185 VkMemoryRequirements mem_reqs;
2186 uint64_t fakeImageHandle = 0xCADECADE;
2187 VkImage fauxImage = reinterpret_cast<VkImage &>(fakeImageHandle);
2188
2189 vkGetImageMemoryRequirements(m_device->device(), fauxImage, &mem_reqs);
2190
2191 m_errorMonitor->VerifyFound();
2192}
2193
Karl Schultz6addd812016-02-02 17:17:23 -07002194TEST_F(VkLayerTest, PipelineNotBound) {
2195 VkResult err;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002196
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002197 TEST_DESCRIPTION("Pass in an invalid pipeline object handle into a Vulkan API call.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002198
Karl Schultzf78bcdd2016-11-30 12:36:01 -07002199 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00601);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002200
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002201 ASSERT_NO_FATAL_FAILURE(InitState());
2202 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002203
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002204 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002205 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2206 ds_type_count.descriptorCount = 1;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002207
2208 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002209 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2210 ds_pool_ci.pNext = NULL;
2211 ds_pool_ci.maxSets = 1;
2212 ds_pool_ci.poolSizeCount = 1;
2213 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002214
2215 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002216 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002217 ASSERT_VK_SUCCESS(err);
2218
2219 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002220 dsl_binding.binding = 0;
2221 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2222 dsl_binding.descriptorCount = 1;
2223 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2224 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002225
2226 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002227 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2228 ds_layout_ci.pNext = NULL;
2229 ds_layout_ci.bindingCount = 1;
2230 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002231
2232 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002233 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002234 ASSERT_VK_SUCCESS(err);
2235
2236 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002237 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08002238 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07002239 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06002240 alloc_info.descriptorPool = ds_pool;
2241 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002242 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002243 ASSERT_VK_SUCCESS(err);
2244
2245 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002246 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
2247 pipeline_layout_ci.pNext = NULL;
2248 pipeline_layout_ci.setLayoutCount = 1;
2249 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002250
2251 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002252 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002253 ASSERT_VK_SUCCESS(err);
2254
Mark Youngad779052016-01-06 14:26:04 -07002255 VkPipeline badPipeline = (VkPipeline)((size_t)0xbaadb1be);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002256
Tony Barbour552f6c02016-12-21 14:34:07 -07002257 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002258 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, badPipeline);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002259
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002260 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002261
Chia-I Wuf7458c52015-10-26 21:10:41 +08002262 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
2263 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2264 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002265}
Mike Stroyan80fc6c32016-06-20 15:42:29 -06002266
Mark Lobodzinskibc185762016-06-15 16:28:53 -06002267TEST_F(VkLayerTest, BindImageInvalidMemoryType) {
2268 VkResult err;
2269
2270 TEST_DESCRIPTION("Test validation check for an invalid memory type index "
2271 "during bind[Buffer|Image]Memory time");
2272
Mark Lobodzinskibc185762016-06-15 16:28:53 -06002273 ASSERT_NO_FATAL_FAILURE(InitState());
2274
2275 // Create an image, allocate memory, set a bad typeIndex and then try to
2276 // bind it
2277 VkImage image;
2278 VkDeviceMemory mem;
2279 VkMemoryRequirements mem_reqs;
2280 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2281 const int32_t tex_width = 32;
2282 const int32_t tex_height = 32;
2283
2284 VkImageCreateInfo image_create_info = {};
2285 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2286 image_create_info.pNext = NULL;
2287 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2288 image_create_info.format = tex_format;
2289 image_create_info.extent.width = tex_width;
2290 image_create_info.extent.height = tex_height;
2291 image_create_info.extent.depth = 1;
2292 image_create_info.mipLevels = 1;
2293 image_create_info.arrayLayers = 1;
2294 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2295 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
2296 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2297 image_create_info.flags = 0;
2298
2299 VkMemoryAllocateInfo mem_alloc = {};
2300 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2301 mem_alloc.pNext = NULL;
2302 mem_alloc.allocationSize = 0;
2303 mem_alloc.memoryTypeIndex = 0;
2304
2305 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
2306 ASSERT_VK_SUCCESS(err);
2307
2308 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
2309 mem_alloc.allocationSize = mem_reqs.size;
Mike Stroyan80fc6c32016-06-20 15:42:29 -06002310
2311 // Introduce Failure, select invalid TypeIndex
2312 VkPhysicalDeviceMemoryProperties memory_info;
2313
2314 vkGetPhysicalDeviceMemoryProperties(gpu(), &memory_info);
2315 unsigned int i;
2316 for (i = 0; i < memory_info.memoryTypeCount; i++) {
2317 if ((mem_reqs.memoryTypeBits & (1 << i)) == 0) {
2318 mem_alloc.memoryTypeIndex = i;
2319 break;
2320 }
2321 }
2322 if (i >= memory_info.memoryTypeCount) {
2323 printf("No invalid memory type index could be found; skipped.\n");
2324 vkDestroyImage(m_device->device(), image, NULL);
2325 return;
2326 }
2327
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002328 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 -06002329
2330 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
2331 ASSERT_VK_SUCCESS(err);
2332
2333 err = vkBindImageMemory(m_device->device(), image, mem, 0);
2334 (void)err;
2335
2336 m_errorMonitor->VerifyFound();
2337
2338 vkDestroyImage(m_device->device(), image, NULL);
2339 vkFreeMemory(m_device->device(), mem, NULL);
2340}
Mike Stroyan80fc6c32016-06-20 15:42:29 -06002341
Karl Schultz6addd812016-02-02 17:17:23 -07002342TEST_F(VkLayerTest, BindInvalidMemory) {
2343 VkResult err;
2344 bool pass;
Tobin Ehlisec598302015-09-15 15:02:17 -06002345
Karl Schultzf78bcdd2016-11-30 12:36:01 -07002346 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00809);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002347
Tobin Ehlisec598302015-09-15 15:02:17 -06002348 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisec598302015-09-15 15:02:17 -06002349
2350 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07002351 VkImage image;
2352 VkDeviceMemory mem;
2353 VkMemoryRequirements mem_reqs;
Tobin Ehlisec598302015-09-15 15:02:17 -06002354
Karl Schultz6addd812016-02-02 17:17:23 -07002355 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2356 const int32_t tex_width = 32;
2357 const int32_t tex_height = 32;
Tobin Ehlisec598302015-09-15 15:02:17 -06002358
2359 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002360 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2361 image_create_info.pNext = NULL;
2362 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2363 image_create_info.format = tex_format;
2364 image_create_info.extent.width = tex_width;
2365 image_create_info.extent.height = tex_height;
2366 image_create_info.extent.depth = 1;
2367 image_create_info.mipLevels = 1;
2368 image_create_info.arrayLayers = 1;
2369 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2370 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2371 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2372 image_create_info.flags = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002373
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002374 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002375 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2376 mem_alloc.pNext = NULL;
2377 mem_alloc.allocationSize = 0;
2378 mem_alloc.memoryTypeIndex = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002379
Chia-I Wuf7458c52015-10-26 21:10:41 +08002380 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlisec598302015-09-15 15:02:17 -06002381 ASSERT_VK_SUCCESS(err);
2382
Karl Schultz6addd812016-02-02 17:17:23 -07002383 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Tobin Ehlisec598302015-09-15 15:02:17 -06002384
2385 mem_alloc.allocationSize = mem_reqs.size;
2386
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002387 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06002388 ASSERT_TRUE(pass);
Tobin Ehlisec598302015-09-15 15:02:17 -06002389
2390 // allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002391 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlisec598302015-09-15 15:02:17 -06002392 ASSERT_VK_SUCCESS(err);
2393
2394 // Introduce validation failure, free memory before binding
Chia-I Wuf7458c52015-10-26 21:10:41 +08002395 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002396
2397 // Try to bind free memory that has been freed
2398 err = vkBindImageMemory(m_device->device(), image, mem, 0);
2399 // This may very well return an error.
2400 (void)err;
2401
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002402 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002403
Chia-I Wuf7458c52015-10-26 21:10:41 +08002404 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002405}
2406
Karl Schultz6addd812016-02-02 17:17:23 -07002407TEST_F(VkLayerTest, BindMemoryToDestroyedObject) {
2408 VkResult err;
2409 bool pass;
Tobin Ehlisec598302015-09-15 15:02:17 -06002410
Karl Schultzf78bcdd2016-11-30 12:36:01 -07002411 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00808);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002412
Tobin Ehlisec598302015-09-15 15:02:17 -06002413 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisec598302015-09-15 15:02:17 -06002414
Karl Schultz6addd812016-02-02 17:17:23 -07002415 // Create an image object, allocate memory, destroy the object and then try
2416 // to bind it
2417 VkImage image;
2418 VkDeviceMemory mem;
2419 VkMemoryRequirements mem_reqs;
Tobin Ehlisec598302015-09-15 15:02:17 -06002420
Karl Schultz6addd812016-02-02 17:17:23 -07002421 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2422 const int32_t tex_width = 32;
2423 const int32_t tex_height = 32;
Tobin Ehlisec598302015-09-15 15:02:17 -06002424
2425 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002426 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2427 image_create_info.pNext = NULL;
2428 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2429 image_create_info.format = tex_format;
2430 image_create_info.extent.width = tex_width;
2431 image_create_info.extent.height = tex_height;
2432 image_create_info.extent.depth = 1;
2433 image_create_info.mipLevels = 1;
2434 image_create_info.arrayLayers = 1;
2435 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2436 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2437 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2438 image_create_info.flags = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002439
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002440 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002441 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2442 mem_alloc.pNext = NULL;
2443 mem_alloc.allocationSize = 0;
2444 mem_alloc.memoryTypeIndex = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002445
Chia-I Wuf7458c52015-10-26 21:10:41 +08002446 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlisec598302015-09-15 15:02:17 -06002447 ASSERT_VK_SUCCESS(err);
2448
Karl Schultz6addd812016-02-02 17:17:23 -07002449 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Tobin Ehlisec598302015-09-15 15:02:17 -06002450
2451 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002452 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06002453 ASSERT_TRUE(pass);
Tobin Ehlisec598302015-09-15 15:02:17 -06002454
2455 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002456 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlisec598302015-09-15 15:02:17 -06002457 ASSERT_VK_SUCCESS(err);
2458
2459 // Introduce validation failure, destroy Image object before binding
Chia-I Wuf7458c52015-10-26 21:10:41 +08002460 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002461 ASSERT_VK_SUCCESS(err);
2462
2463 // Now Try to bind memory to this destroyed object
2464 err = vkBindImageMemory(m_device->device(), image, mem, 0);
2465 // This may very well return an error.
Karl Schultz6addd812016-02-02 17:17:23 -07002466 (void)err;
Tobin Ehlisec598302015-09-15 15:02:17 -06002467
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002468 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002469
Chia-I Wuf7458c52015-10-26 21:10:41 +08002470 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002471}
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002472
Mark Lobodzinski209b5292015-09-17 09:44:05 -06002473#endif // OBJ_TRACKER_TESTS
2474
Tobin Ehlis0788f522015-05-26 16:11:58 -06002475#if DRAW_STATE_TESTS
Mark Lobodzinskic808d442016-04-14 10:57:23 -06002476
Mark Lobodzinski66e5eab2016-11-15 13:30:38 -07002477TEST_F(VkLayerTest, CreatePipelineBadVertexAttributeFormat) {
2478 TEST_DESCRIPTION("Test that pipeline validation catches invalid vertex attribute formats");
2479
2480 ASSERT_NO_FATAL_FAILURE(InitState());
2481 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2482
2483 VkVertexInputBindingDescription input_binding;
2484 memset(&input_binding, 0, sizeof(input_binding));
2485
2486 VkVertexInputAttributeDescription input_attribs;
2487 memset(&input_attribs, 0, sizeof(input_attribs));
2488
2489 // Pick a really bad format for this purpose and make sure it should fail
2490 input_attribs.format = VK_FORMAT_BC2_UNORM_BLOCK;
2491 VkFormatProperties format_props = m_device->format_properties(input_attribs.format);
2492 if ((format_props.bufferFeatures & VK_FORMAT_FEATURE_VERTEX_BUFFER_BIT) != 0) {
2493 printf("Format unsuitable for test; skipped.\n");
2494 return;
2495 }
2496
2497 input_attribs.location = 0;
2498 char const *vsSource = "#version 450\n"
2499 "\n"
2500 "out gl_PerVertex {\n"
2501 " vec4 gl_Position;\n"
2502 "};\n"
2503 "void main(){\n"
2504 " gl_Position = vec4(1);\n"
2505 "}\n";
2506 char const *fsSource = "#version 450\n"
2507 "\n"
2508 "layout(location=0) out vec4 color;\n"
2509 "void main(){\n"
2510 " color = vec4(1);\n"
2511 "}\n";
2512
2513 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01413);
2514 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
2515 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
2516
2517 VkPipelineObj pipe(m_device);
2518 pipe.AddColorAttachment();
2519 pipe.AddShader(&vs);
2520 pipe.AddShader(&fs);
2521
2522 pipe.AddVertexInputBindings(&input_binding, 1);
2523 pipe.AddVertexInputAttribs(&input_attribs, 1);
2524
2525 VkDescriptorSetObj descriptorSet(m_device);
2526 descriptorSet.AppendDummy();
2527 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
2528
2529 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
2530
2531 m_errorMonitor->VerifyFound();
2532}
2533
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002534TEST_F(VkLayerTest, ImageSampleCounts) {
2535
2536 TEST_DESCRIPTION("Use bad sample counts in image transfer calls to trigger "
2537 "validation errors.");
2538 ASSERT_NO_FATAL_FAILURE(InitState());
2539
2540 VkMemoryPropertyFlags reqs = 0;
2541 VkImageCreateInfo image_create_info = {};
2542 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2543 image_create_info.pNext = NULL;
2544 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2545 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
2546 image_create_info.extent.width = 256;
2547 image_create_info.extent.height = 256;
2548 image_create_info.extent.depth = 1;
2549 image_create_info.mipLevels = 1;
2550 image_create_info.arrayLayers = 1;
2551 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
2552 image_create_info.flags = 0;
2553
2554 VkImageBlit blit_region = {};
2555 blit_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2556 blit_region.srcSubresource.baseArrayLayer = 0;
2557 blit_region.srcSubresource.layerCount = 1;
2558 blit_region.srcSubresource.mipLevel = 0;
2559 blit_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2560 blit_region.dstSubresource.baseArrayLayer = 0;
2561 blit_region.dstSubresource.layerCount = 1;
2562 blit_region.dstSubresource.mipLevel = 0;
2563
2564 // Create two images, the source with sampleCount = 2, and attempt to blit
2565 // between them
2566 {
2567 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002568 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002569 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002570 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002571 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002572 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002573 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002574 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002575 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002576 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "was created with a sample count "
2577 "of VK_SAMPLE_COUNT_2_BIT but "
2578 "must be VK_SAMPLE_COUNT_1_BIT");
2579 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
2580 dst_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, 1, &blit_region, VK_FILTER_NEAREST);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002581 m_errorMonitor->VerifyFound();
2582 m_commandBuffer->EndCommandBuffer();
2583 }
2584
2585 // Create two images, the dest with sampleCount = 4, and attempt to blit
2586 // between them
2587 {
2588 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002589 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002590 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002591 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002592 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002593 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002594 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002595 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002596 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002597 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "was created with a sample count "
2598 "of VK_SAMPLE_COUNT_4_BIT but "
2599 "must be VK_SAMPLE_COUNT_1_BIT");
2600 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
2601 dst_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, 1, &blit_region, VK_FILTER_NEAREST);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002602 m_errorMonitor->VerifyFound();
2603 m_commandBuffer->EndCommandBuffer();
2604 }
2605
2606 VkBufferImageCopy copy_region = {};
2607 copy_region.bufferRowLength = 128;
2608 copy_region.bufferImageHeight = 128;
2609 copy_region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2610 copy_region.imageSubresource.layerCount = 1;
2611 copy_region.imageExtent.height = 64;
2612 copy_region.imageExtent.width = 64;
2613 copy_region.imageExtent.depth = 1;
2614
2615 // Create src buffer and dst image with sampleCount = 4 and attempt to copy
2616 // buffer to image
2617 {
2618 vk_testing::Buffer src_buffer;
2619 VkMemoryPropertyFlags reqs = 0;
2620 src_buffer.init_as_src(*m_device, 128 * 128 * 4, reqs);
2621 image_create_info.samples = VK_SAMPLE_COUNT_8_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002622 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002623 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002624 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002625 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002626 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "was created with a sample count "
2627 "of VK_SAMPLE_COUNT_8_BIT but "
2628 "must be VK_SAMPLE_COUNT_1_BIT");
2629 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), src_buffer.handle(), dst_image.handle(),
2630 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &copy_region);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002631 m_errorMonitor->VerifyFound();
2632 m_commandBuffer->EndCommandBuffer();
2633 }
2634
2635 // Create dst buffer and src image with sampleCount = 2 and attempt to copy
2636 // image to buffer
2637 {
2638 vk_testing::Buffer dst_buffer;
2639 dst_buffer.init_as_dst(*m_device, 128 * 128 * 4, reqs);
2640 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002641 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002642 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002643 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002644 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002645 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "was created with a sample count "
2646 "of VK_SAMPLE_COUNT_2_BIT but "
2647 "must be VK_SAMPLE_COUNT_1_BIT");
2648 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002649 dst_buffer.handle(), 1, &copy_region);
2650 m_errorMonitor->VerifyFound();
2651 m_commandBuffer->EndCommandBuffer();
2652 }
2653}
2654
Mike Stroyanac5afeb2016-10-17 13:58:10 -06002655TEST_F(VkLayerTest, BlitImageFormats) {
Mike Stroyanac5afeb2016-10-17 13:58:10 -06002656 ASSERT_NO_FATAL_FAILURE(InitState());
2657
2658 VkImageObj src_image(m_device);
2659 src_image.init(64, 64, VK_FORMAT_A2B10G10R10_UINT_PACK32, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_LINEAR, 0);
2660 VkImageObj dst_image(m_device);
2661 dst_image.init(64, 64, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
2662 VkImageObj dst_image2(m_device);
Mike Stroyan131f3e72016-10-18 11:10:23 -06002663 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 -06002664
2665 VkImageBlit blitRegion = {};
2666 blitRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2667 blitRegion.srcSubresource.baseArrayLayer = 0;
2668 blitRegion.srcSubresource.layerCount = 1;
2669 blitRegion.srcSubresource.mipLevel = 0;
2670 blitRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2671 blitRegion.dstSubresource.baseArrayLayer = 0;
2672 blitRegion.dstSubresource.layerCount = 1;
2673 blitRegion.dstSubresource.mipLevel = 0;
2674
Dave Houlton34df4cb2016-12-01 16:43:06 -07002675 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02191);
2676
2677 // TODO: there are 9 permutations of signed, unsigned, & other for source and dest
2678 // this test is only checking 2 of them at the moment
Mike Stroyanac5afeb2016-10-17 13:58:10 -06002679
2680 // Unsigned int vs not an int
Tony Barbour552f6c02016-12-21 14:34:07 -07002681 m_commandBuffer->BeginCommandBuffer();
Mike Stroyanac5afeb2016-10-17 13:58:10 -06002682 vkCmdBlitImage(m_commandBuffer->handle(), src_image.image(), src_image.layout(), dst_image.image(),
2683 dst_image.layout(), 1, &blitRegion, VK_FILTER_NEAREST);
2684
2685 m_errorMonitor->VerifyFound();
2686
Dave Houlton34df4cb2016-12-01 16:43:06 -07002687 // Test should generate 2 VU failures
2688 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02190);
2689 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02191);
Mike Stroyanac5afeb2016-10-17 13:58:10 -06002690
2691 // Unsigned int vs signed int
2692 vkCmdBlitImage(m_commandBuffer->handle(), src_image.image(), src_image.layout(), dst_image2.image(),
2693 dst_image2.layout(), 1, &blitRegion, VK_FILTER_NEAREST);
2694
Dave Houlton34df4cb2016-12-01 16:43:06 -07002695 // TODO: Note that this only verifies that at least one of the VU enums was found
2696 // 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 -06002697 m_errorMonitor->VerifyFound();
2698
Tony Barbour552f6c02016-12-21 14:34:07 -07002699 m_commandBuffer->EndCommandBuffer();
Mike Stroyanac5afeb2016-10-17 13:58:10 -06002700}
2701
2702
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002703TEST_F(VkLayerTest, DSImageTransferGranularityTests) {
2704 VkResult err;
2705 bool pass;
2706
2707 TEST_DESCRIPTION("Tests for validaiton of Queue Family property minImageTransferGranularity.");
2708 ASSERT_NO_FATAL_FAILURE(InitState());
2709
2710 // If w/d/h granularity is 1, test is not meaningful
2711 // TODO: When virtual device limits are available, create a set of limits for this test that
2712 // will always have a granularity of > 1 for w, h, and d
2713 auto index = m_device->graphics_queue_node_index_;
2714 auto queue_family_properties = m_device->phy().queue_properties();
2715
2716 if ((queue_family_properties[index].minImageTransferGranularity.depth < 4) ||
2717 (queue_family_properties[index].minImageTransferGranularity.width < 4) ||
2718 (queue_family_properties[index].minImageTransferGranularity.height < 4)) {
2719 return;
2720 }
2721
2722 // Create two images of different types and try to copy between them
2723 VkImage srcImage;
2724 VkImage dstImage;
2725 VkDeviceMemory srcMem;
2726 VkDeviceMemory destMem;
2727 VkMemoryRequirements memReqs;
2728
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002729 VkImageCreateInfo image_create_info = {};
2730 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2731 image_create_info.pNext = NULL;
2732 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2733 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
2734 image_create_info.extent.width = 32;
2735 image_create_info.extent.height = 32;
2736 image_create_info.extent.depth = 1;
2737 image_create_info.mipLevels = 1;
2738 image_create_info.arrayLayers = 4;
2739 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2740 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
2741 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
2742 image_create_info.flags = 0;
2743
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002744 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002745 ASSERT_VK_SUCCESS(err);
2746
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002747 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002748 ASSERT_VK_SUCCESS(err);
2749
2750 // Allocate memory
2751 VkMemoryAllocateInfo memAlloc = {};
2752 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2753 memAlloc.pNext = NULL;
2754 memAlloc.allocationSize = 0;
2755 memAlloc.memoryTypeIndex = 0;
2756
2757 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
2758 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002759 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002760 ASSERT_TRUE(pass);
2761 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
2762 ASSERT_VK_SUCCESS(err);
2763
2764 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
2765 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002766 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002767 ASSERT_VK_SUCCESS(err);
2768 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
2769 ASSERT_VK_SUCCESS(err);
2770
2771 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
2772 ASSERT_VK_SUCCESS(err);
2773 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
2774 ASSERT_VK_SUCCESS(err);
2775
Tony Barbour552f6c02016-12-21 14:34:07 -07002776 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002777 VkImageCopy copyRegion;
2778 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2779 copyRegion.srcSubresource.mipLevel = 0;
2780 copyRegion.srcSubresource.baseArrayLayer = 0;
2781 copyRegion.srcSubresource.layerCount = 1;
2782 copyRegion.srcOffset.x = 0;
2783 copyRegion.srcOffset.y = 0;
2784 copyRegion.srcOffset.z = 0;
2785 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2786 copyRegion.dstSubresource.mipLevel = 0;
2787 copyRegion.dstSubresource.baseArrayLayer = 0;
2788 copyRegion.dstSubresource.layerCount = 1;
2789 copyRegion.dstOffset.x = 0;
2790 copyRegion.dstOffset.y = 0;
2791 copyRegion.dstOffset.z = 0;
2792 copyRegion.extent.width = 1;
2793 copyRegion.extent.height = 1;
2794 copyRegion.extent.depth = 1;
2795
2796 // Introduce failure by setting srcOffset to a bad granularity value
2797 copyRegion.srcOffset.y = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002798 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2799 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002800 m_errorMonitor->VerifyFound();
2801
2802 // Introduce failure by setting extent to a bad granularity value
2803 copyRegion.srcOffset.y = 0;
2804 copyRegion.extent.width = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002805 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2806 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002807 m_errorMonitor->VerifyFound();
2808
2809 // Now do some buffer/image copies
2810 vk_testing::Buffer buffer;
2811 VkMemoryPropertyFlags reqs = 0;
2812 buffer.init_as_dst(*m_device, 128 * 128, reqs);
2813 VkBufferImageCopy region = {};
2814 region.bufferOffset = 0;
2815 region.bufferRowLength = 3;
2816 region.bufferImageHeight = 128;
2817 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2818 region.imageSubresource.layerCount = 1;
2819 region.imageExtent.height = 16;
2820 region.imageExtent.width = 16;
2821 region.imageExtent.depth = 1;
2822 region.imageOffset.x = 0;
2823 region.imageOffset.y = 0;
2824 region.imageOffset.z = 0;
2825
2826 // Introduce failure by setting bufferRowLength to a bad granularity value
2827 region.bufferRowLength = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002828 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2829 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
2830 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002831 m_errorMonitor->VerifyFound();
2832 region.bufferRowLength = 128;
2833
2834 // Introduce failure by setting bufferOffset to a bad granularity value
2835 region.bufferOffset = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002836 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2837 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
2838 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002839 m_errorMonitor->VerifyFound();
2840 region.bufferOffset = 0;
2841
2842 // Introduce failure by setting bufferImageHeight to a bad granularity value
2843 region.bufferImageHeight = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002844 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2845 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
2846 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002847 m_errorMonitor->VerifyFound();
2848 region.bufferImageHeight = 128;
2849
2850 // Introduce failure by setting imageExtent to a bad granularity value
2851 region.imageExtent.width = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002852 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2853 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
2854 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002855 m_errorMonitor->VerifyFound();
2856 region.imageExtent.width = 16;
2857
2858 // Introduce failure by setting imageOffset to a bad granularity value
2859 region.imageOffset.z = 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
Tony Barbour552f6c02016-12-21 14:34:07 -07002865 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002866
2867 vkDestroyImage(m_device->device(), srcImage, NULL);
2868 vkDestroyImage(m_device->device(), dstImage, NULL);
2869 vkFreeMemory(m_device->device(), srcMem, NULL);
2870 vkFreeMemory(m_device->device(), destMem, NULL);
2871}
2872
Mark Lobodzinski570efc62016-08-09 16:43:19 -06002873TEST_F(VkLayerTest, MismatchedQueueFamiliesOnSubmit) {
Mark Lobodzinski570efc62016-08-09 16:43:19 -06002874 TEST_DESCRIPTION("Submit command buffer created using one queue family and "
2875 "attempt to submit them on a queue created in a different "
2876 "queue family.");
2877
Cody Northropc31a84f2016-08-22 10:41:47 -06002878 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski570efc62016-08-09 16:43:19 -06002879 // This test is meaningless unless we have multiple queue families
2880 auto queue_family_properties = m_device->phy().queue_properties();
2881 if (queue_family_properties.size() < 2) {
2882 return;
2883 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002884 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is being submitted on queue ");
Mark Lobodzinski570efc62016-08-09 16:43:19 -06002885 // Get safe index of another queue family
2886 uint32_t other_queue_family = (m_device->graphics_queue_node_index_ == 0) ? 1 : 0;
2887 ASSERT_NO_FATAL_FAILURE(InitState());
2888 // Create a second queue using a different queue family
2889 VkQueue other_queue;
2890 vkGetDeviceQueue(m_device->device(), other_queue_family, 0, &other_queue);
2891
2892 // Record an empty cmd buffer
2893 VkCommandBufferBeginInfo cmdBufBeginDesc = {};
2894 cmdBufBeginDesc.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
2895 vkBeginCommandBuffer(m_commandBuffer->handle(), &cmdBufBeginDesc);
2896 vkEndCommandBuffer(m_commandBuffer->handle());
2897
2898 // And submit on the wrong queue
2899 VkSubmitInfo submit_info = {};
2900 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
2901 submit_info.commandBufferCount = 1;
2902 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Tobin Ehlisfd213ea2016-08-10 17:10:46 -06002903 vkQueueSubmit(other_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Lobodzinski570efc62016-08-09 16:43:19 -06002904
2905 m_errorMonitor->VerifyFound();
Mark Lobodzinski570efc62016-08-09 16:43:19 -06002906}
2907
Chris Forbes4c24a922016-11-16 08:59:10 +13002908TEST_F(VkLayerTest, RenderPassAttachmentIndexOutOfRange) {
2909 ASSERT_NO_FATAL_FAILURE(InitState());
2910
Chris Forbes2d9b2a82016-11-21 10:45:39 +13002911 // There are no attachments, but refer to attachment 0.
2912 VkAttachmentReference ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Chris Forbes4c24a922016-11-16 08:59:10 +13002913 VkSubpassDescription subpasses[] = {
Chris Forbes2d9b2a82016-11-21 10:45:39 +13002914 {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &ref, nullptr,
2915 nullptr, 0, nullptr},
Chris Forbes4c24a922016-11-16 08:59:10 +13002916 };
2917
Chris Forbes2d9b2a82016-11-21 10:45:39 +13002918 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO,
2919 nullptr,
2920 0,
2921 0,
2922 nullptr,
2923 1,
2924 subpasses,
2925 0,
2926 nullptr};
Chris Forbes4c24a922016-11-16 08:59:10 +13002927 VkRenderPass rp;
2928
Chris Forbes2d9b2a82016-11-21 10:45:39 +13002929 // "... must be less than the total number of attachments ..."
Chris Forbes4c24a922016-11-16 08:59:10 +13002930 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbes2d9b2a82016-11-21 10:45:39 +13002931 VALIDATION_ERROR_00325);
Chris Forbes4c24a922016-11-16 08:59:10 +13002932 vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
2933 m_errorMonitor->VerifyFound();
2934}
2935
Chris Forbesa58c4522016-09-28 15:19:39 +13002936TEST_F(VkLayerTest, RenderPassPipelineSubpassMismatch) {
2937 TEST_DESCRIPTION("Use a pipeline for the wrong subpass in a render pass instance");
2938 ASSERT_NO_FATAL_FAILURE(InitState());
2939
2940 // A renderpass with two subpasses, both writing the same attachment.
2941 VkAttachmentDescription attach[] = {
2942 { 0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT,
2943 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
2944 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
2945 VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL
2946 },
2947 };
2948 VkAttachmentReference ref = { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
2949 VkSubpassDescription subpasses[] = {
2950 { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr,
2951 1, &ref, nullptr, nullptr, 0, nullptr },
2952 { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr,
2953 1, &ref, nullptr, nullptr, 0, nullptr },
2954 };
2955 VkSubpassDependency dep = {
2956 0, 1,
2957 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
2958 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
2959 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
2960 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
2961 VK_DEPENDENCY_BY_REGION_BIT
2962 };
2963 VkRenderPassCreateInfo rpci = {
2964 VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr,
2965 0, 1, attach, 2, subpasses, 1, &dep
2966 };
2967 VkRenderPass rp;
2968 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
2969 ASSERT_VK_SUCCESS(err);
2970
2971 VkImageObj image(m_device);
2972 image.init_no_layout(32, 32, VK_FORMAT_R8G8B8A8_UNORM,
2973 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT,
2974 VK_IMAGE_TILING_OPTIMAL, 0);
2975 VkImageView imageView = image.targetView(VK_FORMAT_R8G8B8A8_UNORM);
2976
2977 VkFramebufferCreateInfo fbci = {
2978 VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr,
2979 0, rp, 1, &imageView, 32, 32, 1
2980 };
2981 VkFramebuffer fb;
2982 err = vkCreateFramebuffer(m_device->device(), &fbci, nullptr, &fb);
2983 ASSERT_VK_SUCCESS(err);
2984
2985 char const *vsSource =
2986 "#version 450\n"
2987 "void main() { gl_Position = vec4(1); }\n";
2988 char const *fsSource =
2989 "#version 450\n"
2990 "layout(location=0) out vec4 color;\n"
2991 "void main() { color = vec4(1); }\n";
2992
2993 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
2994 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
2995 VkPipelineObj pipe(m_device);
2996 pipe.AddColorAttachment();
2997 pipe.AddShader(&vs);
2998 pipe.AddShader(&fs);
2999 VkViewport view_port = {};
3000 m_viewports.push_back(view_port);
3001 pipe.SetViewport(m_viewports);
3002 VkRect2D rect = {};
3003 m_scissors.push_back(rect);
3004 pipe.SetScissor(m_scissors);
3005
3006 VkPipelineLayoutCreateInfo plci = {
3007 VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr,
3008 0, 0, nullptr, 0, nullptr
3009 };
3010 VkPipelineLayout pl;
3011 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
3012 ASSERT_VK_SUCCESS(err);
3013 pipe.CreateVKPipeline(pl, rp);
3014
Tony Barbour552f6c02016-12-21 14:34:07 -07003015 m_commandBuffer->BeginCommandBuffer();
Chris Forbesa58c4522016-09-28 15:19:39 +13003016
3017 VkRenderPassBeginInfo rpbi = {
3018 VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr,
3019 rp, fb, { { 0, 0, }, { 32, 32 } }, 0, nullptr
3020 };
3021
3022 // subtest 1: bind in the wrong subpass
3023 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
3024 vkCmdNextSubpass(m_commandBuffer->handle(), VK_SUBPASS_CONTENTS_INLINE);
3025 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3026 "built for subpass 0 but used in subpass 1");
3027 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
3028 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
3029 m_errorMonitor->VerifyFound();
3030
3031 vkCmdEndRenderPass(m_commandBuffer->handle());
3032
3033 // subtest 2: bind in correct subpass, then transition to next subpass
3034 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
3035 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
3036 vkCmdNextSubpass(m_commandBuffer->handle(), VK_SUBPASS_CONTENTS_INLINE);
3037 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3038 "built for subpass 0 but used in subpass 1");
3039 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
3040 m_errorMonitor->VerifyFound();
3041
3042 vkCmdEndRenderPass(m_commandBuffer->handle());
3043
Tony Barbour552f6c02016-12-21 14:34:07 -07003044 m_commandBuffer->EndCommandBuffer();
Chris Forbesa58c4522016-09-28 15:19:39 +13003045
3046 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
3047 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
3048 vkDestroyRenderPass(m_device->device(), rp, nullptr);
3049}
3050
Tony Barbour4e919972016-08-09 13:27:40 -06003051TEST_F(VkLayerTest, RenderPassInvalidRenderArea) {
3052 TEST_DESCRIPTION("Generate INVALID_RENDER_AREA error by beginning renderpass"
3053 "with extent outside of framebuffer");
3054 ASSERT_NO_FATAL_FAILURE(InitState());
3055 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3056
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003057 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot execute a render pass with renderArea "
3058 "not within the bound of the framebuffer.");
Tony Barbour4e919972016-08-09 13:27:40 -06003059
3060 // Framebuffer for render target is 256x256, exceed that for INVALID_RENDER_AREA
3061 m_renderPassBeginInfo.renderArea.extent.width = 257;
3062 m_renderPassBeginInfo.renderArea.extent.height = 257;
Tony Barbour552f6c02016-12-21 14:34:07 -07003063 m_commandBuffer->BeginCommandBuffer();
3064 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tony Barbour4e919972016-08-09 13:27:40 -06003065 m_errorMonitor->VerifyFound();
3066}
3067
3068TEST_F(VkLayerTest, DisabledIndependentBlend) {
3069 TEST_DESCRIPTION("Generate INDEPENDENT_BLEND by disabling independent "
3070 "blend and then specifying different blend states for two "
3071 "attachements");
Cody Northrop5703cc72016-08-19 09:57:10 -06003072 VkPhysicalDeviceFeatures features = {};
3073 features.independentBlend = VK_FALSE;
Cody Northropc31a84f2016-08-22 10:41:47 -06003074 ASSERT_NO_FATAL_FAILURE(InitState(&features));
Tony Barbour4e919972016-08-09 13:27:40 -06003075
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003076 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3077 "Invalid Pipeline CreateInfo: If independent blend feature not "
3078 "enabled, all elements of pAttachments must be identical");
Tony Barbour4e919972016-08-09 13:27:40 -06003079
Cody Northropc31a84f2016-08-22 10:41:47 -06003080 VkDescriptorSetObj descriptorSet(m_device);
3081 descriptorSet.AppendDummy();
3082 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Tony Barbour4e919972016-08-09 13:27:40 -06003083
Cody Northropc31a84f2016-08-22 10:41:47 -06003084 VkPipelineObj pipeline(m_device);
3085 VkRenderpassObj renderpass(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003086 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Cody Northropc31a84f2016-08-22 10:41:47 -06003087 pipeline.AddShader(&vs);
Cody Northrop5703cc72016-08-19 09:57:10 -06003088
Cody Northropc31a84f2016-08-22 10:41:47 -06003089 VkPipelineColorBlendAttachmentState att_state1 = {}, att_state2 = {};
3090 att_state1.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
3091 att_state1.blendEnable = VK_TRUE;
3092 att_state2.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
3093 att_state2.blendEnable = VK_FALSE;
3094 pipeline.AddColorAttachment(0, &att_state1);
3095 pipeline.AddColorAttachment(1, &att_state2);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003096 pipeline.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderpass.handle());
Cody Northropc31a84f2016-08-22 10:41:47 -06003097 m_errorMonitor->VerifyFound();
Tony Barbour4e919972016-08-09 13:27:40 -06003098}
3099
Chris Forbes26ec2122016-11-29 08:58:33 +13003100#if 0
Tony Barbour4e919972016-08-09 13:27:40 -06003101TEST_F(VkLayerTest, RenderPassDepthStencilAttachmentUnused) {
3102 TEST_DESCRIPTION("Specify no depth attachement in renderpass then specify "
3103 "depth attachments in subpass");
Cody Northropc31a84f2016-08-22 10:41:47 -06003104 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbour4e919972016-08-09 13:27:40 -06003105
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003106 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3107 "vkCreateRenderPass has no depth/stencil attachment, yet subpass");
Tony Barbour4e919972016-08-09 13:27:40 -06003108
3109 // Create a renderPass with a single color attachment
3110 VkAttachmentReference attach = {};
3111 attach.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
3112 VkSubpassDescription subpass = {};
3113 VkRenderPassCreateInfo rpci = {};
3114 rpci.subpassCount = 1;
3115 rpci.pSubpasses = &subpass;
3116 rpci.attachmentCount = 1;
3117 VkAttachmentDescription attach_desc = {};
3118 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
3119 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
3120 rpci.pAttachments = &attach_desc;
3121 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3122 VkRenderPass rp;
3123 subpass.pDepthStencilAttachment = &attach;
3124 subpass.pColorAttachments = NULL;
3125 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3126 m_errorMonitor->VerifyFound();
3127}
Chris Forbes26ec2122016-11-29 08:58:33 +13003128#endif
Tony Barbour4e919972016-08-09 13:27:40 -06003129
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003130TEST_F(VkLayerTest, UnusedPreserveAttachment) {
3131 TEST_DESCRIPTION("Create a framebuffer where a subpass has a preserve "
3132 "attachment reference of VK_ATTACHMENT_UNUSED");
3133
3134 ASSERT_NO_FATAL_FAILURE(InitState());
3135 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3136
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003137 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "must not be VK_ATTACHMENT_UNUSED");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003138
3139 VkAttachmentReference color_attach = {};
3140 color_attach.layout = VK_IMAGE_LAYOUT_GENERAL;
3141 color_attach.attachment = 0;
3142 uint32_t preserve_attachment = VK_ATTACHMENT_UNUSED;
3143 VkSubpassDescription subpass = {};
3144 subpass.colorAttachmentCount = 1;
3145 subpass.pColorAttachments = &color_attach;
3146 subpass.preserveAttachmentCount = 1;
3147 subpass.pPreserveAttachments = &preserve_attachment;
3148
3149 VkRenderPassCreateInfo rpci = {};
3150 rpci.subpassCount = 1;
3151 rpci.pSubpasses = &subpass;
3152 rpci.attachmentCount = 1;
3153 VkAttachmentDescription attach_desc = {};
3154 attach_desc.format = VK_FORMAT_UNDEFINED;
3155 rpci.pAttachments = &attach_desc;
3156 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3157 VkRenderPass rp;
Mark Lobodzinskia4feeeb2016-06-17 12:00:46 -06003158 VkResult result = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003159
3160 m_errorMonitor->VerifyFound();
3161
Mark Lobodzinskia4feeeb2016-06-17 12:00:46 -06003162 if (result == VK_SUCCESS) {
3163 vkDestroyRenderPass(m_device->device(), rp, NULL);
3164 }
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003165}
3166
Chris Forbesc5389742016-06-29 11:49:23 +12003167TEST_F(VkLayerTest, CreateRenderPassResolveRequiresColorMsaa) {
Chris Forbes6655bb32016-07-01 18:27:30 +12003168 TEST_DESCRIPTION("Ensure that CreateRenderPass produces a validation error "
3169 "when the source of a subpass multisample resolve "
3170 "does not have multiple samples.");
3171
Chris Forbesc5389742016-06-29 11:49:23 +12003172 ASSERT_NO_FATAL_FAILURE(InitState());
3173
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003174 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3175 "Subpass 0 requests multisample resolve from attachment 0 which has "
3176 "VK_SAMPLE_COUNT_1_BIT");
Chris Forbesc5389742016-06-29 11:49:23 +12003177
3178 VkAttachmentDescription attachments[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003179 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3180 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3181 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3182 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3183 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3184 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbesc5389742016-06-29 11:49:23 +12003185 };
3186
3187 VkAttachmentReference color = {
3188 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3189 };
3190
3191 VkAttachmentReference resolve = {
3192 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3193 };
3194
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003195 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &color, &resolve, nullptr, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003196
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003197 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003198
3199 VkRenderPass rp;
3200 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3201
3202 m_errorMonitor->VerifyFound();
3203
3204 if (err == VK_SUCCESS)
3205 vkDestroyRenderPass(m_device->device(), rp, nullptr);
3206}
3207
3208TEST_F(VkLayerTest, CreateRenderPassResolveRequiresSingleSampleDest) {
Chris Forbes6655bb32016-07-01 18:27:30 +12003209 TEST_DESCRIPTION("Ensure CreateRenderPass produces a validation error "
3210 "when a subpass multisample resolve operation is "
3211 "requested, and the destination of that resolve has "
3212 "multiple samples.");
3213
Chris Forbesc5389742016-06-29 11:49:23 +12003214 ASSERT_NO_FATAL_FAILURE(InitState());
3215
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003216 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3217 "Subpass 0 requests multisample resolve into attachment 1, which "
3218 "must have VK_SAMPLE_COUNT_1_BIT but has VK_SAMPLE_COUNT_4_BIT");
Chris Forbesc5389742016-06-29 11:49:23 +12003219
3220 VkAttachmentDescription attachments[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003221 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3222 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3223 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3224 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3225 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3226 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbesc5389742016-06-29 11:49:23 +12003227 };
3228
3229 VkAttachmentReference color = {
3230 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3231 };
3232
3233 VkAttachmentReference resolve = {
3234 1, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3235 };
3236
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003237 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &color, &resolve, nullptr, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003238
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003239 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003240
3241 VkRenderPass rp;
3242 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3243
3244 m_errorMonitor->VerifyFound();
3245
3246 if (err == VK_SUCCESS)
3247 vkDestroyRenderPass(m_device->device(), rp, nullptr);
3248}
3249
Chris Forbes3f128ef2016-06-29 14:58:53 +12003250TEST_F(VkLayerTest, CreateRenderPassSubpassSampleCountConsistency) {
Chris Forbes6655bb32016-07-01 18:27:30 +12003251 TEST_DESCRIPTION("Ensure CreateRenderPass produces a validation error "
3252 "when the color and depth attachments used by a subpass "
3253 "have inconsistent sample counts");
3254
Chris Forbes3f128ef2016-06-29 14:58:53 +12003255 ASSERT_NO_FATAL_FAILURE(InitState());
3256
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003257 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3258 "Subpass 0 attempts to render to attachments with inconsistent sample counts");
Chris Forbes3f128ef2016-06-29 14:58:53 +12003259
3260 VkAttachmentDescription attachments[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003261 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3262 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3263 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3264 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3265 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3266 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbes3f128ef2016-06-29 14:58:53 +12003267 };
3268
3269 VkAttachmentReference color[] = {
3270 {
3271 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3272 },
3273 {
3274 1, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3275 },
3276 };
3277
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003278 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 2, color, nullptr, nullptr, 0, nullptr};
Chris Forbes3f128ef2016-06-29 14:58:53 +12003279
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003280 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbes3f128ef2016-06-29 14:58:53 +12003281
3282 VkRenderPass rp;
3283 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3284
3285 m_errorMonitor->VerifyFound();
3286
3287 if (err == VK_SUCCESS)
3288 vkDestroyRenderPass(m_device->device(), rp, nullptr);
3289}
3290
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003291TEST_F(VkLayerTest, FramebufferCreateErrors) {
3292 TEST_DESCRIPTION("Hit errors when attempting to create a framebuffer :\n"
Mike Weiblencce7ec72016-10-17 19:33:05 -06003293 " 1. Mismatch between framebuffer & renderPass attachmentCount\n"
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003294 " 2. Use a color image as depthStencil attachment\n"
Mike Weiblencce7ec72016-10-17 19:33:05 -06003295 " 3. Mismatch framebuffer & renderPass attachment formats\n"
3296 " 4. Mismatch framebuffer & renderPass attachment #samples\n"
3297 " 5. Framebuffer attachment w/ non-1 mip-levels\n"
3298 " 6. Framebuffer attachment where dimensions don't match\n"
3299 " 7. Framebuffer attachment w/o identity swizzle\n"
3300 " 8. framebuffer dimensions exceed physical device limits\n");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003301
3302 ASSERT_NO_FATAL_FAILURE(InitState());
3303 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3304
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003305 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3306 "vkCreateFramebuffer(): VkFramebufferCreateInfo attachmentCount of 2 "
3307 "does not match attachmentCount of 1 of ");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003308
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003309 // Create a renderPass with a single color attachment
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003310 VkAttachmentReference attach = {};
3311 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
3312 VkSubpassDescription subpass = {};
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003313 subpass.pColorAttachments = &attach;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003314 VkRenderPassCreateInfo rpci = {};
3315 rpci.subpassCount = 1;
3316 rpci.pSubpasses = &subpass;
3317 rpci.attachmentCount = 1;
3318 VkAttachmentDescription attach_desc = {};
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003319 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis77d717c2016-06-22 14:19:19 -06003320 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003321 rpci.pAttachments = &attach_desc;
3322 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3323 VkRenderPass rp;
3324 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3325 ASSERT_VK_SUCCESS(err);
3326
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003327 VkImageView ivs[2];
3328 ivs[0] = m_renderTargets[0]->targetView(VK_FORMAT_B8G8R8A8_UNORM);
3329 ivs[1] = m_renderTargets[0]->targetView(VK_FORMAT_B8G8R8A8_UNORM);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003330 VkFramebufferCreateInfo fb_info = {};
3331 fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
3332 fb_info.pNext = NULL;
3333 fb_info.renderPass = rp;
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003334 // Set mis-matching attachmentCount
3335 fb_info.attachmentCount = 2;
3336 fb_info.pAttachments = ivs;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003337 fb_info.width = 100;
3338 fb_info.height = 100;
3339 fb_info.layers = 1;
3340
3341 VkFramebuffer fb;
3342 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3343
3344 m_errorMonitor->VerifyFound();
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003345 if (err == VK_SUCCESS) {
3346 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3347 }
3348 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003349
3350 // Create a renderPass with a depth-stencil attachment created with
3351 // IMAGE_USAGE_COLOR_ATTACHMENT
3352 // Add our color attachment to pDepthStencilAttachment
3353 subpass.pDepthStencilAttachment = &attach;
3354 subpass.pColorAttachments = NULL;
3355 VkRenderPass rp_ds;
3356 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp_ds);
3357 ASSERT_VK_SUCCESS(err);
3358 // Set correct attachment count, but attachment has COLOR usage bit set
3359 fb_info.attachmentCount = 1;
3360 fb_info.renderPass = rp_ds;
3361
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003362 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " conflicts with the image's IMAGE_USAGE flags ");
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003363 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3364
3365 m_errorMonitor->VerifyFound();
3366 if (err == VK_SUCCESS) {
3367 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3368 }
3369 vkDestroyRenderPass(m_device->device(), rp_ds, NULL);
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003370
3371 // Create new renderpass with alternate attachment format from fb
3372 attach_desc.format = VK_FORMAT_R8G8B8A8_UNORM;
3373 subpass.pDepthStencilAttachment = NULL;
3374 subpass.pColorAttachments = &attach;
3375 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3376 ASSERT_VK_SUCCESS(err);
3377
3378 // Cause error due to mis-matched formats between rp & fb
3379 // rp attachment 0 now has RGBA8 but corresponding fb attach is BGRA8
3380 fb_info.renderPass = rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003381 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3382 " has format of VK_FORMAT_B8G8R8A8_UNORM that does not match ");
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003383 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3384
3385 m_errorMonitor->VerifyFound();
3386 if (err == VK_SUCCESS) {
3387 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3388 }
Tobin Ehlis77d717c2016-06-22 14:19:19 -06003389 vkDestroyRenderPass(m_device->device(), rp, NULL);
3390
3391 // Create new renderpass with alternate sample count from fb
3392 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
3393 attach_desc.samples = VK_SAMPLE_COUNT_4_BIT;
3394 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3395 ASSERT_VK_SUCCESS(err);
3396
3397 // Cause error due to mis-matched sample count between rp & fb
3398 fb_info.renderPass = rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003399 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has VK_SAMPLE_COUNT_1_BIT samples "
3400 "that do not match the "
3401 "VK_SAMPLE_COUNT_4_BIT ");
Tobin Ehlis77d717c2016-06-22 14:19:19 -06003402 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3403
3404 m_errorMonitor->VerifyFound();
3405 if (err == VK_SUCCESS) {
3406 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3407 }
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003408
3409 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003410
3411 // Create a custom imageView with non-1 mip levels
3412 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003413 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 -06003414 ASSERT_TRUE(image.initialized());
3415
3416 VkImageView view;
3417 VkImageViewCreateInfo ivci = {};
3418 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
3419 ivci.image = image.handle();
3420 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
3421 ivci.format = VK_FORMAT_B8G8R8A8_UNORM;
3422 ivci.subresourceRange.layerCount = 1;
3423 ivci.subresourceRange.baseMipLevel = 0;
3424 // Set level count 2 (only 1 is allowed for FB attachment)
3425 ivci.subresourceRange.levelCount = 2;
3426 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3427 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
3428 ASSERT_VK_SUCCESS(err);
3429 // Re-create renderpass to have matching sample count
3430 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
3431 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3432 ASSERT_VK_SUCCESS(err);
3433
3434 fb_info.renderPass = rp;
3435 fb_info.pAttachments = &view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003436 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has mip levelCount of 2 but only ");
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003437 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3438
3439 m_errorMonitor->VerifyFound();
3440 if (err == VK_SUCCESS) {
3441 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3442 }
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003443 vkDestroyImageView(m_device->device(), view, NULL);
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06003444 // Update view to original color buffer and grow FB dimensions too big
3445 fb_info.pAttachments = ivs;
3446 fb_info.height = 1024;
3447 fb_info.width = 1024;
3448 fb_info.layers = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003449 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " Attachment dimensions must be at "
3450 "least as large. ");
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06003451 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3452
3453 m_errorMonitor->VerifyFound();
3454 if (err == VK_SUCCESS) {
3455 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3456 }
Tobin Ehlisb1f303b2016-06-23 08:19:55 -06003457 // Create view attachment with non-identity swizzle
3458 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
3459 ivci.image = image.handle();
3460 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
3461 ivci.format = VK_FORMAT_B8G8R8A8_UNORM;
3462 ivci.subresourceRange.layerCount = 1;
3463 ivci.subresourceRange.baseMipLevel = 0;
3464 ivci.subresourceRange.levelCount = 1;
3465 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3466 ivci.components.r = VK_COMPONENT_SWIZZLE_G;
3467 ivci.components.g = VK_COMPONENT_SWIZZLE_R;
3468 ivci.components.b = VK_COMPONENT_SWIZZLE_A;
3469 ivci.components.a = VK_COMPONENT_SWIZZLE_B;
3470 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
3471 ASSERT_VK_SUCCESS(err);
3472
3473 fb_info.pAttachments = &view;
3474 fb_info.height = 100;
3475 fb_info.width = 100;
3476 fb_info.layers = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003477 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has non-identy swizzle. All "
3478 "framebuffer attachments must have "
3479 "been created with the identity "
3480 "swizzle. ");
Tobin Ehlisb1f303b2016-06-23 08:19:55 -06003481 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3482
3483 m_errorMonitor->VerifyFound();
3484 if (err == VK_SUCCESS) {
3485 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3486 }
3487 vkDestroyImageView(m_device->device(), view, NULL);
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06003488 // reset attachment to color attachment
3489 fb_info.pAttachments = ivs;
Mike Schuchardt8fb38062016-12-08 15:36:24 -07003490
3491 // Request fb that exceeds max width
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06003492 fb_info.width = m_device->props.limits.maxFramebufferWidth + 1;
Mike Schuchardt8fb38062016-12-08 15:36:24 -07003493 fb_info.height = 100;
3494 fb_info.layers = 1;
3495 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00413);
3496 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3497
3498 m_errorMonitor->VerifyFound();
3499 if (err == VK_SUCCESS) {
3500 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3501 }
3502
3503 // Request fb that exceeds max height
3504 fb_info.width = 100;
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06003505 fb_info.height = m_device->props.limits.maxFramebufferHeight + 1;
Mike Schuchardt8fb38062016-12-08 15:36:24 -07003506 fb_info.layers = 1;
3507 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00414);
3508 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3509
3510 m_errorMonitor->VerifyFound();
3511 if (err == VK_SUCCESS) {
3512 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3513 }
3514
3515 // Request fb that exceeds max layers
3516 fb_info.width = 100;
3517 fb_info.height = 100;
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06003518 fb_info.layers = m_device->props.limits.maxFramebufferLayers + 1;
Mike Schuchardt8fb38062016-12-08 15:36:24 -07003519 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00415);
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06003520 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3521
3522 m_errorMonitor->VerifyFound();
3523 if (err == VK_SUCCESS) {
3524 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3525 }
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06003526
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003527 vkDestroyRenderPass(m_device->device(), rp, NULL);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003528}
3529
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003530TEST_F(VkLayerTest, DynamicDepthBiasNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003531 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Depth Bias dynamic "
3532 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003533
Cody Northropc31a84f2016-08-22 10:41:47 -06003534 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003535 // Dynamic depth bias
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003536 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic depth bias state not set for this command buffer");
3537 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthBias);
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003538 m_errorMonitor->VerifyFound();
3539}
3540
3541TEST_F(VkLayerTest, DynamicLineWidthNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003542 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Line Width dynamic "
3543 "state is required but not correctly bound.");
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003544
Cody Northropc31a84f2016-08-22 10:41:47 -06003545 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003546 // Dynamic line width
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003547 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic line width state not set for this command buffer");
3548 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailLineWidth);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003549 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003550}
3551
3552TEST_F(VkLayerTest, DynamicViewportNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003553 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Viewport dynamic "
3554 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003555
Cody Northropc31a84f2016-08-22 10:41:47 -06003556 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003557 // Dynamic viewport state
Mike Weiblen95dd0f92016-10-19 12:28:27 -06003558 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 -06003559 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailViewport);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003560 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003561}
3562
3563TEST_F(VkLayerTest, DynamicScissorNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003564 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Scissor dynamic "
3565 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003566
Cody Northropc31a84f2016-08-22 10:41:47 -06003567 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003568 // Dynamic scissor state
Mike Weiblen95dd0f92016-10-19 12:28:27 -06003569 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 -06003570 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailScissor);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003571 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003572}
3573
Cortd713fe82016-07-27 09:51:27 -07003574TEST_F(VkLayerTest, DynamicBlendConstantsNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003575 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Blend Constants "
3576 "dynamic state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003577
3578 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis21c88352016-05-26 06:15:45 -06003579 // Dynamic blend constant state
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003580 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3581 "Dynamic blend constants state not set for this command buffer");
3582 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailBlend);
Tobin Ehlis21c88352016-05-26 06:15:45 -06003583 m_errorMonitor->VerifyFound();
3584}
3585
3586TEST_F(VkLayerTest, DynamicDepthBoundsNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003587 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Depth Bounds dynamic "
3588 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003589
3590 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis21c88352016-05-26 06:15:45 -06003591 if (!m_device->phy().features().depthBounds) {
3592 printf("Device does not support depthBounds test; skipped.\n");
3593 return;
3594 }
3595 // Dynamic depth bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003596 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3597 "Dynamic depth bounds state not set for this command buffer");
3598 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthBounds);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003599 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003600}
3601
3602TEST_F(VkLayerTest, DynamicStencilReadNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003603 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Stencil Read dynamic "
3604 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003605
3606 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003607 // Dynamic stencil read mask
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003608 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3609 "Dynamic stencil read mask state not set for this command buffer");
3610 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilReadMask);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003611 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003612}
3613
3614TEST_F(VkLayerTest, DynamicStencilWriteNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003615 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Stencil Write dynamic"
3616 " state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003617
3618 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003619 // Dynamic stencil write mask
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003620 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3621 "Dynamic stencil write mask state not set for this command buffer");
3622 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilWriteMask);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003623 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003624}
3625
3626TEST_F(VkLayerTest, DynamicStencilRefNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003627 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Stencil Ref dynamic "
3628 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003629
3630 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003631 // Dynamic stencil reference
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003632 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3633 "Dynamic stencil reference state not set for this command buffer");
3634 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilReference);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003635 m_errorMonitor->VerifyFound();
Tobin Ehlis963a4042015-09-29 08:18:34 -06003636}
3637
Tobin Ehlis379ba3b2016-07-19 11:22:29 -06003638TEST_F(VkLayerTest, IndexBufferNotBound) {
3639 TEST_DESCRIPTION("Run an indexed draw call without an index buffer bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003640
3641 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003642 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3643 "Index buffer object not bound to this command buffer when Indexed ");
3644 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailIndexBuffer);
Tobin Ehlis379ba3b2016-07-19 11:22:29 -06003645 m_errorMonitor->VerifyFound();
3646}
3647
Karl Schultz6addd812016-02-02 17:17:23 -07003648TEST_F(VkLayerTest, CommandBufferTwoSubmits) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003649 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3650 "was begun w/ VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set, but has "
3651 "been submitted");
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003652
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003653 ASSERT_NO_FATAL_FAILURE(InitState());
3654 ASSERT_NO_FATAL_FAILURE(InitViewport());
3655 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3656
Karl Schultz6addd812016-02-02 17:17:23 -07003657 // We luck out b/c by default the framework creates CB w/ the
3658 // VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set
Tony Barbour552f6c02016-12-21 14:34:07 -07003659 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003660 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbour552f6c02016-12-21 14:34:07 -07003661 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003662
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003663 // Bypass framework since it does the waits automatically
3664 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06003665 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08003666 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3667 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003668 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06003669 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07003670 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003671 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003672 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08003673 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06003674 submit_info.pSignalSemaphores = NULL;
3675
Chris Forbes40028e22016-06-13 09:59:34 +12003676 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Karl Schultz6addd812016-02-02 17:17:23 -07003677 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski89cad1a2016-11-11 15:51:31 -07003678 vkQueueWaitIdle(m_device->m_queue);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003679
Karl Schultz6addd812016-02-02 17:17:23 -07003680 // Cause validation error by re-submitting cmd buffer that should only be
3681 // submitted once
Chris Forbes40028e22016-06-13 09:59:34 +12003682 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Lobodzinski89cad1a2016-11-11 15:51:31 -07003683 vkQueueWaitIdle(m_device->m_queue);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003684
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003685 m_errorMonitor->VerifyFound();
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003686}
3687
Karl Schultz6addd812016-02-02 17:17:23 -07003688TEST_F(VkLayerTest, AllocDescriptorFromEmptyPool) {
Tobin Ehlis14cd5852016-11-23 12:52:48 -07003689 TEST_DESCRIPTION("Attempt to allocate more sets and descriptors than descriptor pool has available.");
Karl Schultz6addd812016-02-02 17:17:23 -07003690 VkResult err;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003691
3692 ASSERT_NO_FATAL_FAILURE(InitState());
3693 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003694
Karl Schultz6addd812016-02-02 17:17:23 -07003695 // Create Pool w/ 1 Sampler descriptor, but try to alloc Uniform Buffer
3696 // descriptor from it
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003697 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003698 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
Tobin Ehlis14cd5852016-11-23 12:52:48 -07003699 ds_type_count.descriptorCount = 2;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003700
3701 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003702 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3703 ds_pool_ci.pNext = NULL;
3704 ds_pool_ci.flags = 0;
3705 ds_pool_ci.maxSets = 1;
3706 ds_pool_ci.poolSizeCount = 1;
3707 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003708
3709 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003710 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003711 ASSERT_VK_SUCCESS(err);
3712
Tobin Ehlis14cd5852016-11-23 12:52:48 -07003713 VkDescriptorSetLayoutBinding dsl_binding_samp = {};
3714 dsl_binding_samp.binding = 0;
3715 dsl_binding_samp.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
3716 dsl_binding_samp.descriptorCount = 1;
3717 dsl_binding_samp.stageFlags = VK_SHADER_STAGE_ALL;
3718 dsl_binding_samp.pImmutableSamplers = NULL;
3719
3720 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3721 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3722 ds_layout_ci.pNext = NULL;
3723 ds_layout_ci.bindingCount = 1;
3724 ds_layout_ci.pBindings = &dsl_binding_samp;
3725
3726 VkDescriptorSetLayout ds_layout_samp;
3727 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout_samp);
3728 ASSERT_VK_SUCCESS(err);
3729
3730 // Try to allocate 2 sets when pool only has 1 set
3731 VkDescriptorSet descriptor_sets[2];
3732 VkDescriptorSetLayout set_layouts[2] = {ds_layout_samp, ds_layout_samp};
3733 VkDescriptorSetAllocateInfo alloc_info = {};
3734 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
3735 alloc_info.descriptorSetCount = 2;
3736 alloc_info.descriptorPool = ds_pool;
3737 alloc_info.pSetLayouts = set_layouts;
3738 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00911);
3739 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptor_sets);
3740 m_errorMonitor->VerifyFound();
3741
3742 alloc_info.descriptorSetCount = 1;
3743 // Create layout w/ descriptor type not available in pool
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003744 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003745 dsl_binding.binding = 0;
3746 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3747 dsl_binding.descriptorCount = 1;
3748 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3749 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003750
Karl Schultz6addd812016-02-02 17:17:23 -07003751 ds_layout_ci.bindingCount = 1;
3752 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003753
Tobin Ehlis14cd5852016-11-23 12:52:48 -07003754 VkDescriptorSetLayout ds_layout_ub;
3755 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout_ub);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003756 ASSERT_VK_SUCCESS(err);
3757
Tobin Ehlis14cd5852016-11-23 12:52:48 -07003758 VkDescriptorSet descriptor_set;
Jon Ashburnf19916e2016-01-11 13:12:43 -07003759 alloc_info.descriptorSetCount = 1;
Tobin Ehlis14cd5852016-11-23 12:52:48 -07003760 alloc_info.pSetLayouts = &ds_layout_ub;
3761 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00912);
3762 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003763
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003764 m_errorMonitor->VerifyFound();
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003765
Karl Schultz2825ab92016-12-02 08:23:14 -07003766 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_samp, NULL);
Tobin Ehlis14cd5852016-11-23 12:52:48 -07003767 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_ub, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +08003768 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003769}
3770
Karl Schultz6addd812016-02-02 17:17:23 -07003771TEST_F(VkLayerTest, FreeDescriptorFromOneShotPool) {
3772 VkResult err;
Tobin Ehlise735c692015-10-08 13:13:50 -06003773
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07003774 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00922);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003775
Tobin Ehlise735c692015-10-08 13:13:50 -06003776 ASSERT_NO_FATAL_FAILURE(InitState());
3777 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise735c692015-10-08 13:13:50 -06003778
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003779 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003780 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3781 ds_type_count.descriptorCount = 1;
Tobin Ehlise735c692015-10-08 13:13:50 -06003782
3783 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003784 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3785 ds_pool_ci.pNext = NULL;
3786 ds_pool_ci.maxSets = 1;
3787 ds_pool_ci.poolSizeCount = 1;
3788 ds_pool_ci.flags = 0;
3789 // Not specifying VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT means
3790 // app can only call vkResetDescriptorPool on this pool.;
3791 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise735c692015-10-08 13:13:50 -06003792
3793 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003794 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise735c692015-10-08 13:13:50 -06003795 ASSERT_VK_SUCCESS(err);
3796
3797 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003798 dsl_binding.binding = 0;
3799 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3800 dsl_binding.descriptorCount = 1;
3801 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3802 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlise735c692015-10-08 13:13:50 -06003803
3804 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003805 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3806 ds_layout_ci.pNext = NULL;
3807 ds_layout_ci.bindingCount = 1;
3808 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise735c692015-10-08 13:13:50 -06003809
3810 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003811 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise735c692015-10-08 13:13:50 -06003812 ASSERT_VK_SUCCESS(err);
3813
3814 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003815 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08003816 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07003817 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06003818 alloc_info.descriptorPool = ds_pool;
3819 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003820 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise735c692015-10-08 13:13:50 -06003821 ASSERT_VK_SUCCESS(err);
3822
3823 err = vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003824 m_errorMonitor->VerifyFound();
Tobin Ehlise735c692015-10-08 13:13:50 -06003825
Chia-I Wuf7458c52015-10-26 21:10:41 +08003826 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3827 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise735c692015-10-08 13:13:50 -06003828}
3829
Karl Schultz6addd812016-02-02 17:17:23 -07003830TEST_F(VkLayerTest, InvalidDescriptorPool) {
Karl Schultzbdb75952016-04-19 11:36:49 -06003831 // Attempt to clear Descriptor Pool with bad object.
3832 // ObjectTracker should catch this.
Cody Northropc31a84f2016-08-22 10:41:47 -06003833
3834 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultzf78bcdd2016-11-30 12:36:01 -07003835 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00930);
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06003836 uint64_t fake_pool_handle = 0xbaad6001;
3837 VkDescriptorPool bad_pool = reinterpret_cast<VkDescriptorPool &>(fake_pool_handle);
3838 vkResetDescriptorPool(device(), bad_pool, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -06003839 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003840}
3841
Karl Schultzf78bcdd2016-11-30 12:36:01 -07003842TEST_F(VkLayerTest, InvalidDescriptorSet) {
Karl Schultzbdb75952016-04-19 11:36:49 -06003843 // Attempt to bind an invalid Descriptor Set to a valid Command Buffer
3844 // ObjectTracker should catch this.
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003845 // Create a valid cmd buffer
Karl Schultzbdb75952016-04-19 11:36:49 -06003846 // call vkCmdBindDescriptorSets w/ false Descriptor Set
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06003847
3848 uint64_t fake_set_handle = 0xbaad6001;
3849 VkDescriptorSet bad_set = reinterpret_cast<VkDescriptorSet &>(fake_set_handle);
Karl Schultzbdb75952016-04-19 11:36:49 -06003850 VkResult err;
Karl Schultzf78bcdd2016-11-30 12:36:01 -07003851 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00982);
Karl Schultzbdb75952016-04-19 11:36:49 -06003852
3853 ASSERT_NO_FATAL_FAILURE(InitState());
3854
3855 VkDescriptorSetLayoutBinding layout_bindings[1] = {};
3856 layout_bindings[0].binding = 0;
3857 layout_bindings[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3858 layout_bindings[0].descriptorCount = 1;
3859 layout_bindings[0].stageFlags = VK_SHADER_STAGE_VERTEX_BIT;
3860 layout_bindings[0].pImmutableSamplers = NULL;
3861
3862 VkDescriptorSetLayout descriptor_set_layout;
3863 VkDescriptorSetLayoutCreateInfo dslci = {};
3864 dslci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3865 dslci.pNext = NULL;
3866 dslci.bindingCount = 1;
3867 dslci.pBindings = layout_bindings;
3868 err = vkCreateDescriptorSetLayout(device(), &dslci, NULL, &descriptor_set_layout);
Karl Schultz5cb21112016-04-21 17:17:40 -06003869 ASSERT_VK_SUCCESS(err);
Karl Schultzbdb75952016-04-19 11:36:49 -06003870
3871 VkPipelineLayout pipeline_layout;
3872 VkPipelineLayoutCreateInfo plci = {};
3873 plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
3874 plci.pNext = NULL;
3875 plci.setLayoutCount = 1;
3876 plci.pSetLayouts = &descriptor_set_layout;
3877 err = vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout);
Karl Schultz5cb21112016-04-21 17:17:40 -06003878 ASSERT_VK_SUCCESS(err);
Karl Schultzbdb75952016-04-19 11:36:49 -06003879
Tony Barbour552f6c02016-12-21 14:34:07 -07003880 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003881 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1, &bad_set, 0,
3882 NULL);
Karl Schultzbdb75952016-04-19 11:36:49 -06003883 m_errorMonitor->VerifyFound();
Tony Barbour552f6c02016-12-21 14:34:07 -07003884 m_commandBuffer->EndCommandBuffer();
Karl Schultzbdb75952016-04-19 11:36:49 -06003885 vkDestroyPipelineLayout(device(), pipeline_layout, NULL);
3886 vkDestroyDescriptorSetLayout(device(), descriptor_set_layout, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003887}
3888
Karl Schultz6addd812016-02-02 17:17:23 -07003889TEST_F(VkLayerTest, InvalidDescriptorSetLayout) {
Karl Schultzbdb75952016-04-19 11:36:49 -06003890 // Attempt to create a Pipeline Layout with an invalid Descriptor Set Layout.
3891 // ObjectTracker should catch this.
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06003892 uint64_t fake_layout_handle = 0xbaad6001;
3893 VkDescriptorSetLayout bad_layout = reinterpret_cast<VkDescriptorSetLayout &>(fake_layout_handle);
Karl Schultzf78bcdd2016-11-30 12:36:01 -07003894 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00875);
Cody Northropc31a84f2016-08-22 10:41:47 -06003895 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultzbdb75952016-04-19 11:36:49 -06003896 VkPipelineLayout pipeline_layout;
3897 VkPipelineLayoutCreateInfo plci = {};
3898 plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
3899 plci.pNext = NULL;
3900 plci.setLayoutCount = 1;
3901 plci.pSetLayouts = &bad_layout;
3902 vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout);
3903
3904 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003905}
3906
Mark Muellerd4914412016-06-13 17:52:06 -06003907TEST_F(VkLayerTest, WriteDescriptorSetIntegrityCheck) {
3908 TEST_DESCRIPTION("This test verifies some requirements of chapter 13.2.3 of the Vulkan Spec "
3909 "1) A uniform buffer update must have a valid buffer index."
3910 "2) When using an array of descriptors in a single WriteDescriptor,"
3911 " the descriptor types and stageflags must all be the same."
3912 "3) Immutable Sampler state must match across descriptors");
3913
3914 const char *invalid_BufferInfo_ErrorMessage =
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003915 "vkUpdateDescriptorSets: if pDescriptorWrites[0].descriptorType is VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, "
3916 "VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC or "
3917 "VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC, pDescriptorWrites[0].pBufferInfo must not be NULL";
Mark Muellerd4914412016-06-13 17:52:06 -06003918
Mark Muellerd4914412016-06-13 17:52:06 -06003919 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_BufferInfo_ErrorMessage);
3920
3921 ASSERT_NO_FATAL_FAILURE(InitState());
3922 VkDescriptorPoolSize ds_type_count[4] = {};
3923 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3924 ds_type_count[0].descriptorCount = 1;
Tony Barboure132c5f2016-12-12 11:50:20 -07003925 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLER;
Mark Muellerd4914412016-06-13 17:52:06 -06003926 ds_type_count[1].descriptorCount = 1;
Tony Barboure132c5f2016-12-12 11:50:20 -07003927 ds_type_count[2].type = VK_DESCRIPTOR_TYPE_SAMPLER;
Mark Muellerd4914412016-06-13 17:52:06 -06003928 ds_type_count[2].descriptorCount = 1;
3929 ds_type_count[3].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
3930 ds_type_count[3].descriptorCount = 1;
3931
3932 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3933 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3934 ds_pool_ci.maxSets = 1;
3935 ds_pool_ci.poolSizeCount = sizeof(ds_type_count) / sizeof(VkDescriptorPoolSize);
3936 ds_pool_ci.pPoolSizes = ds_type_count;
3937
3938 VkDescriptorPool ds_pool;
3939 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
3940 ASSERT_VK_SUCCESS(err);
3941
Mark Muellerb9896722016-06-16 09:54:29 -06003942 VkDescriptorSetLayoutBinding layout_binding[3] = {};
Mark Muellerd4914412016-06-13 17:52:06 -06003943 layout_binding[0].binding = 0;
3944 layout_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3945 layout_binding[0].descriptorCount = 1;
3946 layout_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
3947 layout_binding[0].pImmutableSamplers = NULL;
3948
3949 layout_binding[1].binding = 1;
3950 layout_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
3951 layout_binding[1].descriptorCount = 1;
3952 layout_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
3953 layout_binding[1].pImmutableSamplers = NULL;
3954
3955 VkSamplerCreateInfo sampler_ci = {};
3956 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
3957 sampler_ci.pNext = NULL;
3958 sampler_ci.magFilter = VK_FILTER_NEAREST;
3959 sampler_ci.minFilter = VK_FILTER_NEAREST;
3960 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
3961 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3962 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3963 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3964 sampler_ci.mipLodBias = 1.0;
3965 sampler_ci.anisotropyEnable = VK_FALSE;
3966 sampler_ci.maxAnisotropy = 1;
3967 sampler_ci.compareEnable = VK_FALSE;
3968 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
3969 sampler_ci.minLod = 1.0;
3970 sampler_ci.maxLod = 1.0;
3971 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
3972 sampler_ci.unnormalizedCoordinates = VK_FALSE;
3973 VkSampler sampler;
3974
3975 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
3976 ASSERT_VK_SUCCESS(err);
3977
3978 layout_binding[2].binding = 2;
3979 layout_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
3980 layout_binding[2].descriptorCount = 1;
3981 layout_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
3982 layout_binding[2].pImmutableSamplers = static_cast<VkSampler *>(&sampler);
3983
Mark Muellerd4914412016-06-13 17:52:06 -06003984 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3985 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3986 ds_layout_ci.bindingCount = sizeof(layout_binding) / sizeof(VkDescriptorSetLayoutBinding);
3987 ds_layout_ci.pBindings = layout_binding;
3988 VkDescriptorSetLayout ds_layout;
3989 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
3990 ASSERT_VK_SUCCESS(err);
3991
3992 VkDescriptorSetAllocateInfo alloc_info = {};
3993 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
3994 alloc_info.descriptorSetCount = 1;
3995 alloc_info.descriptorPool = ds_pool;
3996 alloc_info.pSetLayouts = &ds_layout;
3997 VkDescriptorSet descriptorSet;
3998 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
3999 ASSERT_VK_SUCCESS(err);
4000
4001 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4002 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4003 pipeline_layout_ci.pNext = NULL;
4004 pipeline_layout_ci.setLayoutCount = 1;
4005 pipeline_layout_ci.pSetLayouts = &ds_layout;
4006
4007 VkPipelineLayout pipeline_layout;
4008 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
4009 ASSERT_VK_SUCCESS(err);
4010
Mark Mueller5c838ce2016-06-16 09:54:29 -06004011 VkWriteDescriptorSet descriptor_write = {};
Mark Muellerd4914412016-06-13 17:52:06 -06004012 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
4013 descriptor_write.dstSet = descriptorSet;
4014 descriptor_write.dstBinding = 0;
4015 descriptor_write.descriptorCount = 1;
4016 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4017
Mark Mueller5c838ce2016-06-16 09:54:29 -06004018 // 1) The uniform buffer is intentionally invalid here
Mark Muellerd4914412016-06-13 17:52:06 -06004019 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4020 m_errorMonitor->VerifyFound();
4021
4022 // Create a buffer to update the descriptor with
4023 uint32_t qfi = 0;
4024 VkBufferCreateInfo buffCI = {};
4025 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
4026 buffCI.size = 1024;
4027 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
4028 buffCI.queueFamilyIndexCount = 1;
4029 buffCI.pQueueFamilyIndices = &qfi;
4030
4031 VkBuffer dyub;
4032 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
4033 ASSERT_VK_SUCCESS(err);
Mark Muellerd4914412016-06-13 17:52:06 -06004034
Tony Barboure132c5f2016-12-12 11:50:20 -07004035 VkDeviceMemory mem;
4036 VkMemoryRequirements mem_reqs;
4037 vkGetBufferMemoryRequirements(m_device->device(), dyub, &mem_reqs);
4038
4039 VkMemoryAllocateInfo mem_alloc_info = {};
4040 mem_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4041 mem_alloc_info.allocationSize = mem_reqs.size;
4042 m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
4043 err = vkAllocateMemory(m_device->device(), &mem_alloc_info, NULL, &mem);
4044 ASSERT_VK_SUCCESS(err);
4045
4046 err = vkBindBufferMemory(m_device->device(), dyub, mem, 0);
4047 ASSERT_VK_SUCCESS(err);
4048
4049 VkDescriptorBufferInfo buffInfo[2] = {};
4050 buffInfo[0].buffer = dyub;
4051 buffInfo[0].offset = 0;
4052 buffInfo[0].range = 1024;
4053 buffInfo[1].buffer = dyub;
4054 buffInfo[1].offset = 0;
4055 buffInfo[1].range = 1024;
4056 descriptor_write.pBufferInfo = buffInfo;
Mark Muellerd4914412016-06-13 17:52:06 -06004057 descriptor_write.descriptorCount = 2;
4058
Mark Mueller5c838ce2016-06-16 09:54:29 -06004059 // 2) The stateFlags don't match between the first and second descriptor
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07004060 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00938);
Mark Muellerd4914412016-06-13 17:52:06 -06004061 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4062 m_errorMonitor->VerifyFound();
4063
Mark Mueller5c838ce2016-06-16 09:54:29 -06004064 // 3) The second descriptor has a null_ptr pImmutableSamplers and
4065 // the third descriptor contains an immutable sampler
Mark Muellerd4914412016-06-13 17:52:06 -06004066 descriptor_write.dstBinding = 1;
4067 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Mark Mueller5c838ce2016-06-16 09:54:29 -06004068
Mark Mueller5c838ce2016-06-16 09:54:29 -06004069 // Make pImageInfo index non-null to avoid complaints of it missing
4070 VkDescriptorImageInfo imageInfo = {};
4071 imageInfo.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
4072 descriptor_write.pImageInfo = &imageInfo;
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07004073 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00938);
Mark Muellerd4914412016-06-13 17:52:06 -06004074 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4075 m_errorMonitor->VerifyFound();
4076
Mark Muellerd4914412016-06-13 17:52:06 -06004077 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tony Barboure132c5f2016-12-12 11:50:20 -07004078 vkFreeMemory(m_device->device(), mem, NULL);
Mark Muellerd4914412016-06-13 17:52:06 -06004079 vkDestroySampler(m_device->device(), sampler, NULL);
4080 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4081 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4082 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
4083}
4084
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004085TEST_F(VkLayerTest, InvalidCmdBufferBufferDestroyed) {
4086 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4087 "due to a buffer dependency being destroyed.");
4088 ASSERT_NO_FATAL_FAILURE(InitState());
4089
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004090 VkBuffer buffer;
4091 VkDeviceMemory mem;
4092 VkMemoryRequirements mem_reqs;
4093
4094 VkBufferCreateInfo buf_info = {};
4095 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes3d5882f2016-09-16 17:37:17 +12004096 buf_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004097 buf_info.size = 256;
4098 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
4099 VkResult err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
4100 ASSERT_VK_SUCCESS(err);
4101
4102 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
4103
4104 VkMemoryAllocateInfo alloc_info = {};
4105 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4106 alloc_info.allocationSize = 256;
4107 bool pass = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004108 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 -06004109 if (!pass) {
4110 vkDestroyBuffer(m_device->device(), buffer, NULL);
4111 return;
4112 }
4113 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
4114 ASSERT_VK_SUCCESS(err);
4115
4116 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
4117 ASSERT_VK_SUCCESS(err);
4118
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004119 m_commandBuffer->BeginCommandBuffer();
Chris Forbes3d5882f2016-09-16 17:37:17 +12004120 vkCmdFillBuffer(m_commandBuffer->GetBufferHandle(), buffer, 0, VK_WHOLE_SIZE, 0);
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004121 m_commandBuffer->EndCommandBuffer();
4122
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004123 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound buffer ");
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004124 // Destroy buffer dependency prior to submit to cause ERROR
4125 vkDestroyBuffer(m_device->device(), buffer, NULL);
4126
4127 VkSubmitInfo submit_info = {};
4128 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4129 submit_info.commandBufferCount = 1;
4130 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4131 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4132
4133 m_errorMonitor->VerifyFound();
Rene Lindsayab6c5cd2016-12-20 14:05:37 -07004134 vkQueueWaitIdle(m_device->m_queue);
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004135 vkFreeMemory(m_device->handle(), mem, NULL);
4136}
4137
Tobin Ehlisea413442016-09-28 10:23:59 -06004138TEST_F(VkLayerTest, InvalidCmdBufferBufferViewDestroyed) {
4139 TEST_DESCRIPTION("Delete bufferView bound to cmd buffer, then attempt to submit cmd buffer.");
4140
4141 ASSERT_NO_FATAL_FAILURE(InitState());
4142 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4143
4144 VkDescriptorPoolSize ds_type_count;
4145 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
4146 ds_type_count.descriptorCount = 1;
4147
4148 VkDescriptorPoolCreateInfo ds_pool_ci = {};
4149 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4150 ds_pool_ci.maxSets = 1;
4151 ds_pool_ci.poolSizeCount = 1;
4152 ds_pool_ci.pPoolSizes = &ds_type_count;
4153
4154 VkDescriptorPool ds_pool;
4155 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
4156 ASSERT_VK_SUCCESS(err);
4157
4158 VkDescriptorSetLayoutBinding layout_binding;
4159 layout_binding.binding = 0;
4160 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
4161 layout_binding.descriptorCount = 1;
4162 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
4163 layout_binding.pImmutableSamplers = NULL;
4164
4165 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
4166 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4167 ds_layout_ci.bindingCount = 1;
4168 ds_layout_ci.pBindings = &layout_binding;
4169 VkDescriptorSetLayout ds_layout;
4170 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
4171 ASSERT_VK_SUCCESS(err);
4172
4173 VkDescriptorSetAllocateInfo alloc_info = {};
4174 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
4175 alloc_info.descriptorSetCount = 1;
4176 alloc_info.descriptorPool = ds_pool;
4177 alloc_info.pSetLayouts = &ds_layout;
4178 VkDescriptorSet descriptor_set;
4179 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
4180 ASSERT_VK_SUCCESS(err);
4181
4182 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4183 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4184 pipeline_layout_ci.pNext = NULL;
4185 pipeline_layout_ci.setLayoutCount = 1;
4186 pipeline_layout_ci.pSetLayouts = &ds_layout;
4187
4188 VkPipelineLayout pipeline_layout;
4189 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
4190 ASSERT_VK_SUCCESS(err);
4191
4192 VkBuffer buffer;
4193 uint32_t queue_family_index = 0;
4194 VkBufferCreateInfo buffer_create_info = {};
4195 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
4196 buffer_create_info.size = 1024;
4197 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
4198 buffer_create_info.queueFamilyIndexCount = 1;
4199 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
4200
4201 err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
4202 ASSERT_VK_SUCCESS(err);
4203
4204 VkMemoryRequirements memory_reqs;
4205 VkDeviceMemory buffer_memory;
4206
4207 VkMemoryAllocateInfo memory_info = {};
4208 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4209 memory_info.allocationSize = 0;
4210 memory_info.memoryTypeIndex = 0;
4211
4212 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
4213 memory_info.allocationSize = memory_reqs.size;
4214 bool pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
4215 ASSERT_TRUE(pass);
4216
4217 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
4218 ASSERT_VK_SUCCESS(err);
4219 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
4220 ASSERT_VK_SUCCESS(err);
4221
4222 VkBufferView view;
4223 VkBufferViewCreateInfo bvci = {};
4224 bvci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
4225 bvci.buffer = buffer;
4226 bvci.format = VK_FORMAT_R8_UNORM;
4227 bvci.range = VK_WHOLE_SIZE;
4228
4229 err = vkCreateBufferView(m_device->device(), &bvci, NULL, &view);
4230 ASSERT_VK_SUCCESS(err);
4231
4232 VkWriteDescriptorSet descriptor_write = {};
4233 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
4234 descriptor_write.dstSet = descriptor_set;
4235 descriptor_write.dstBinding = 0;
4236 descriptor_write.descriptorCount = 1;
4237 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
4238 descriptor_write.pTexelBufferView = &view;
4239
4240 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4241
4242 char const *vsSource = "#version 450\n"
4243 "\n"
4244 "out gl_PerVertex { \n"
4245 " vec4 gl_Position;\n"
4246 "};\n"
4247 "void main(){\n"
4248 " gl_Position = vec4(1);\n"
4249 "}\n";
4250 char const *fsSource = "#version 450\n"
4251 "\n"
4252 "layout(set=0, binding=0, r8) uniform imageBuffer s;\n"
4253 "layout(location=0) out vec4 x;\n"
4254 "void main(){\n"
4255 " x = imageLoad(s, 0);\n"
4256 "}\n";
4257 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4258 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
4259 VkPipelineObj pipe(m_device);
4260 pipe.AddShader(&vs);
4261 pipe.AddShader(&fs);
4262 pipe.AddColorAttachment();
4263 pipe.CreateVKPipeline(pipeline_layout, renderPass());
4264
4265 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot submit cmd buffer using deleted buffer view ");
4266 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound buffer view ");
4267
Tony Barbour552f6c02016-12-21 14:34:07 -07004268 m_commandBuffer->BeginCommandBuffer();
4269 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
4270
Tobin Ehlisea413442016-09-28 10:23:59 -06004271 VkViewport viewport = {0, 0, 16, 16, 0, 1};
4272 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
4273 VkRect2D scissor = {{0, 0}, {16, 16}};
4274 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
4275 // Bind pipeline to cmd buffer
4276 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
4277 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
4278 &descriptor_set, 0, nullptr);
4279 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07004280 m_commandBuffer->EndRenderPass();
4281 m_commandBuffer->EndCommandBuffer();
Tobin Ehlisea413442016-09-28 10:23:59 -06004282
4283 // Delete BufferView in order to invalidate cmd buffer
4284 vkDestroyBufferView(m_device->device(), view, NULL);
4285 // Now attempt submit of cmd buffer
4286 VkSubmitInfo submit_info = {};
4287 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4288 submit_info.commandBufferCount = 1;
4289 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4290 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4291 m_errorMonitor->VerifyFound();
4292
4293 // Clean-up
4294 vkDestroyBuffer(m_device->device(), buffer, NULL);
4295 vkFreeMemory(m_device->device(), buffer_memory, NULL);
4296 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4297 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4298 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
4299}
4300
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004301TEST_F(VkLayerTest, InvalidCmdBufferImageDestroyed) {
4302 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4303 "due to an image dependency being destroyed.");
4304 ASSERT_NO_FATAL_FAILURE(InitState());
4305
4306 VkImage image;
4307 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
4308 VkImageCreateInfo image_create_info = {};
4309 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4310 image_create_info.pNext = NULL;
4311 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4312 image_create_info.format = tex_format;
4313 image_create_info.extent.width = 32;
4314 image_create_info.extent.height = 32;
4315 image_create_info.extent.depth = 1;
4316 image_create_info.mipLevels = 1;
4317 image_create_info.arrayLayers = 1;
4318 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
4319 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004320 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004321 image_create_info.flags = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004322 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004323 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004324 // Have to bind memory to image before recording cmd in cmd buffer using it
4325 VkMemoryRequirements mem_reqs;
4326 VkDeviceMemory image_mem;
4327 bool pass;
4328 VkMemoryAllocateInfo mem_alloc = {};
4329 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4330 mem_alloc.pNext = NULL;
4331 mem_alloc.memoryTypeIndex = 0;
4332 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
4333 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004334 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004335 ASSERT_TRUE(pass);
4336 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
4337 ASSERT_VK_SUCCESS(err);
4338 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
4339 ASSERT_VK_SUCCESS(err);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004340
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004341 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlis764d7072016-07-01 12:54:29 -06004342 VkClearColorValue ccv;
4343 ccv.float32[0] = 1.0f;
4344 ccv.float32[1] = 1.0f;
4345 ccv.float32[2] = 1.0f;
4346 ccv.float32[3] = 1.0f;
4347 VkImageSubresourceRange isr = {};
4348 isr.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004349 isr.baseArrayLayer = 0;
4350 isr.baseMipLevel = 0;
Tobin Ehlis764d7072016-07-01 12:54:29 -06004351 isr.layerCount = 1;
4352 isr.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004353 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), image, VK_IMAGE_LAYOUT_GENERAL, &ccv, 1, &isr);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004354 m_commandBuffer->EndCommandBuffer();
4355
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004356 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004357 // Destroy image dependency prior to submit to cause ERROR
4358 vkDestroyImage(m_device->device(), image, NULL);
4359
4360 VkSubmitInfo submit_info = {};
4361 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4362 submit_info.commandBufferCount = 1;
4363 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4364 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4365
4366 m_errorMonitor->VerifyFound();
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004367 vkFreeMemory(m_device->device(), image_mem, nullptr);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004368}
4369
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004370TEST_F(VkLayerTest, InvalidCmdBufferFramebufferImageDestroyed) {
4371 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4372 "due to a framebuffer image dependency being destroyed.");
4373 VkFormatProperties format_properties;
4374 VkResult err = VK_SUCCESS;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004375 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
4376 if (!(format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)) {
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004377 return;
4378 }
4379
4380 ASSERT_NO_FATAL_FAILURE(InitState());
4381 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4382
4383 VkImageCreateInfo image_ci = {};
4384 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4385 image_ci.pNext = NULL;
4386 image_ci.imageType = VK_IMAGE_TYPE_2D;
4387 image_ci.format = VK_FORMAT_B8G8R8A8_UNORM;
4388 image_ci.extent.width = 32;
4389 image_ci.extent.height = 32;
4390 image_ci.extent.depth = 1;
4391 image_ci.mipLevels = 1;
4392 image_ci.arrayLayers = 1;
4393 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
4394 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004395 image_ci.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_SAMPLED_BIT;
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004396 image_ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
4397 image_ci.flags = 0;
4398 VkImage image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004399 ASSERT_VK_SUCCESS(vkCreateImage(m_device->handle(), &image_ci, NULL, &image));
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004400
4401 VkMemoryRequirements memory_reqs;
4402 VkDeviceMemory image_memory;
4403 bool pass;
4404 VkMemoryAllocateInfo memory_info = {};
4405 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4406 memory_info.pNext = NULL;
4407 memory_info.allocationSize = 0;
4408 memory_info.memoryTypeIndex = 0;
4409 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
4410 memory_info.allocationSize = memory_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004411 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004412 ASSERT_TRUE(pass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004413 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004414 ASSERT_VK_SUCCESS(err);
4415 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
4416 ASSERT_VK_SUCCESS(err);
4417
4418 VkImageViewCreateInfo ivci = {
4419 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
4420 nullptr,
4421 0,
4422 image,
4423 VK_IMAGE_VIEW_TYPE_2D,
4424 VK_FORMAT_B8G8R8A8_UNORM,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004425 {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A},
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004426 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
4427 };
4428 VkImageView view;
4429 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
4430 ASSERT_VK_SUCCESS(err);
4431
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004432 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 32, 32, 1};
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004433 VkFramebuffer fb;
4434 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
4435 ASSERT_VK_SUCCESS(err);
4436
4437 // Just use default renderpass with our framebuffer
4438 m_renderPassBeginInfo.framebuffer = fb;
4439 // Create Null cmd buffer for submit
Tony Barbour552f6c02016-12-21 14:34:07 -07004440 m_commandBuffer->BeginCommandBuffer();
4441 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
4442 m_commandBuffer->EndRenderPass();
4443 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004444 // Destroy image attached to framebuffer to invalidate cmd buffer
4445 vkDestroyImage(m_device->device(), image, NULL);
4446 // Now attempt to submit cmd buffer and verify error
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004447 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004448 QueueCommandBuffer(false);
4449 m_errorMonitor->VerifyFound();
4450
4451 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
4452 vkDestroyImageView(m_device->device(), view, nullptr);
4453 vkFreeMemory(m_device->device(), image_memory, nullptr);
4454}
4455
Tobin Ehlisb329f992016-10-12 13:20:29 -06004456TEST_F(VkLayerTest, FramebufferInUseDestroyedSignaled) {
4457 TEST_DESCRIPTION("Delete in-use framebuffer.");
4458 VkFormatProperties format_properties;
4459 VkResult err = VK_SUCCESS;
4460 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
4461
4462 ASSERT_NO_FATAL_FAILURE(InitState());
4463 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4464
4465 VkImageObj image(m_device);
4466 image.init(256, 256, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
4467 ASSERT_TRUE(image.initialized());
4468 VkImageView view = image.targetView(VK_FORMAT_B8G8R8A8_UNORM);
4469
4470 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 256, 256, 1};
4471 VkFramebuffer fb;
4472 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
4473 ASSERT_VK_SUCCESS(err);
4474
4475 // Just use default renderpass with our framebuffer
4476 m_renderPassBeginInfo.framebuffer = fb;
4477 // Create Null cmd buffer for submit
Tony Barbour552f6c02016-12-21 14:34:07 -07004478 m_commandBuffer->BeginCommandBuffer();
4479 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
4480 m_commandBuffer->EndRenderPass();
4481 m_commandBuffer->EndCommandBuffer();
Tobin Ehlisb329f992016-10-12 13:20:29 -06004482 // Submit cmd buffer to put it in-flight
4483 VkSubmitInfo submit_info = {};
4484 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4485 submit_info.commandBufferCount = 1;
4486 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4487 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4488 // Destroy framebuffer while in-flight
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07004489 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00422);
Tobin Ehlisb329f992016-10-12 13:20:29 -06004490 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4491 m_errorMonitor->VerifyFound();
4492 // Wait for queue to complete so we can safely destroy everything
4493 vkQueueWaitIdle(m_device->m_queue);
4494 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
4495}
4496
Tobin Ehlis88becd72016-09-21 14:33:41 -06004497TEST_F(VkLayerTest, FramebufferImageInUseDestroyedSignaled) {
4498 TEST_DESCRIPTION("Delete in-use image that's child of framebuffer.");
4499 VkFormatProperties format_properties;
4500 VkResult err = VK_SUCCESS;
4501 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
Tobin Ehlis88becd72016-09-21 14:33:41 -06004502
4503 ASSERT_NO_FATAL_FAILURE(InitState());
4504 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4505
4506 VkImageCreateInfo image_ci = {};
4507 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4508 image_ci.pNext = NULL;
4509 image_ci.imageType = VK_IMAGE_TYPE_2D;
4510 image_ci.format = VK_FORMAT_B8G8R8A8_UNORM;
4511 image_ci.extent.width = 256;
4512 image_ci.extent.height = 256;
4513 image_ci.extent.depth = 1;
4514 image_ci.mipLevels = 1;
4515 image_ci.arrayLayers = 1;
4516 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
4517 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
Tobin Ehlisc8ca0312016-09-22 07:30:05 -06004518 image_ci.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Tobin Ehlis88becd72016-09-21 14:33:41 -06004519 image_ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
4520 image_ci.flags = 0;
4521 VkImage image;
4522 ASSERT_VK_SUCCESS(vkCreateImage(m_device->handle(), &image_ci, NULL, &image));
4523
4524 VkMemoryRequirements memory_reqs;
4525 VkDeviceMemory image_memory;
4526 bool pass;
4527 VkMemoryAllocateInfo memory_info = {};
4528 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4529 memory_info.pNext = NULL;
4530 memory_info.allocationSize = 0;
4531 memory_info.memoryTypeIndex = 0;
4532 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
4533 memory_info.allocationSize = memory_reqs.size;
4534 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
4535 ASSERT_TRUE(pass);
4536 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
4537 ASSERT_VK_SUCCESS(err);
4538 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
4539 ASSERT_VK_SUCCESS(err);
4540
4541 VkImageViewCreateInfo ivci = {
4542 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
4543 nullptr,
4544 0,
4545 image,
4546 VK_IMAGE_VIEW_TYPE_2D,
4547 VK_FORMAT_B8G8R8A8_UNORM,
4548 {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A},
4549 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
4550 };
4551 VkImageView view;
4552 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
4553 ASSERT_VK_SUCCESS(err);
4554
4555 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 256, 256, 1};
4556 VkFramebuffer fb;
4557 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
4558 ASSERT_VK_SUCCESS(err);
4559
4560 // Just use default renderpass with our framebuffer
4561 m_renderPassBeginInfo.framebuffer = fb;
4562 // Create Null cmd buffer for submit
Tony Barbour552f6c02016-12-21 14:34:07 -07004563 m_commandBuffer->BeginCommandBuffer();
4564 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
4565 m_commandBuffer->EndRenderPass();
4566 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis88becd72016-09-21 14:33:41 -06004567 // Submit cmd buffer to put it (and attached imageView) in-flight
4568 VkSubmitInfo submit_info = {};
4569 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4570 submit_info.commandBufferCount = 1;
4571 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4572 // Submit cmd buffer to put framebuffer and children in-flight
4573 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4574 // Destroy image attached to framebuffer while in-flight
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07004575 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00743);
Tobin Ehlis88becd72016-09-21 14:33:41 -06004576 vkDestroyImage(m_device->device(), image, NULL);
4577 m_errorMonitor->VerifyFound();
4578 // Wait for queue to complete so we can safely destroy image and other objects
4579 vkQueueWaitIdle(m_device->m_queue);
4580 vkDestroyImage(m_device->device(), image, NULL);
4581 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
4582 vkDestroyImageView(m_device->device(), view, nullptr);
4583 vkFreeMemory(m_device->device(), image_memory, nullptr);
4584}
4585
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06004586TEST_F(VkLayerTest, RenderPassInUseDestroyedSignaled) {
4587 TEST_DESCRIPTION("Delete in-use renderPass.");
4588
4589 ASSERT_NO_FATAL_FAILURE(InitState());
4590 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4591
4592 // Create simple renderpass
4593 VkAttachmentReference attach = {};
4594 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
4595 VkSubpassDescription subpass = {};
4596 subpass.pColorAttachments = &attach;
4597 VkRenderPassCreateInfo rpci = {};
4598 rpci.subpassCount = 1;
4599 rpci.pSubpasses = &subpass;
4600 rpci.attachmentCount = 1;
4601 VkAttachmentDescription attach_desc = {};
4602 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
4603 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
4604 rpci.pAttachments = &attach_desc;
4605 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
4606 VkRenderPass rp;
4607 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
4608 ASSERT_VK_SUCCESS(err);
4609
4610 // Create a pipeline that uses the given renderpass
4611 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4612 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4613
4614 VkPipelineLayout pipeline_layout;
4615 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
4616 ASSERT_VK_SUCCESS(err);
4617
4618 VkPipelineViewportStateCreateInfo vp_state_ci = {};
4619 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
4620 vp_state_ci.viewportCount = 1;
4621 VkViewport vp = {}; // Just need dummy vp to point to
4622 vp_state_ci.pViewports = &vp;
4623 vp_state_ci.scissorCount = 1;
4624 VkRect2D scissors = {}; // Dummy scissors to point to
4625 vp_state_ci.pScissors = &scissors;
4626
4627 VkPipelineShaderStageCreateInfo shaderStages[2];
4628 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
4629
4630 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
4631 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
4632 // but add it to be able to run on more devices
4633 shaderStages[0] = vs.GetStageCreateInfo();
4634 shaderStages[1] = fs.GetStageCreateInfo();
4635
4636 VkPipelineVertexInputStateCreateInfo vi_ci = {};
4637 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
4638
4639 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
4640 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
4641 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
4642
4643 VkPipelineRasterizationStateCreateInfo rs_ci = {};
4644 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
4645 rs_ci.rasterizerDiscardEnable = true;
4646 rs_ci.lineWidth = 1.0f;
4647
4648 VkPipelineColorBlendAttachmentState att = {};
4649 att.blendEnable = VK_FALSE;
4650 att.colorWriteMask = 0xf;
4651
4652 VkPipelineColorBlendStateCreateInfo cb_ci = {};
4653 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
4654 cb_ci.attachmentCount = 1;
4655 cb_ci.pAttachments = &att;
4656
4657 VkGraphicsPipelineCreateInfo gp_ci = {};
4658 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
4659 gp_ci.stageCount = 2;
4660 gp_ci.pStages = shaderStages;
4661 gp_ci.pVertexInputState = &vi_ci;
4662 gp_ci.pInputAssemblyState = &ia_ci;
4663 gp_ci.pViewportState = &vp_state_ci;
4664 gp_ci.pRasterizationState = &rs_ci;
4665 gp_ci.pColorBlendState = &cb_ci;
4666 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
4667 gp_ci.layout = pipeline_layout;
4668 gp_ci.renderPass = rp;
4669
4670 VkPipelineCacheCreateInfo pc_ci = {};
4671 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
4672
4673 VkPipeline pipeline;
4674 VkPipelineCache pipe_cache;
4675 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipe_cache);
4676 ASSERT_VK_SUCCESS(err);
4677
4678 err = vkCreateGraphicsPipelines(m_device->device(), pipe_cache, 1, &gp_ci, NULL, &pipeline);
4679 ASSERT_VK_SUCCESS(err);
4680 // Bind pipeline to cmd buffer, will also bind renderpass
4681 m_commandBuffer->BeginCommandBuffer();
4682 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
4683 m_commandBuffer->EndCommandBuffer();
4684
4685 VkSubmitInfo submit_info = {};
4686 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4687 submit_info.commandBufferCount = 1;
4688 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4689 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4690
4691 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00393);
4692 vkDestroyRenderPass(m_device->device(), rp, nullptr);
4693 m_errorMonitor->VerifyFound();
4694
4695 // Wait for queue to complete so we can safely destroy everything
4696 vkQueueWaitIdle(m_device->m_queue);
4697 vkDestroyRenderPass(m_device->device(), rp, nullptr);
4698 vkDestroyPipeline(m_device->device(), pipeline, nullptr);
4699 vkDestroyPipelineCache(m_device->device(), pipe_cache, nullptr);
4700 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
4701}
4702
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004703TEST_F(VkLayerTest, ImageMemoryNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004704 TEST_DESCRIPTION("Attempt to draw with an image which has not had memory bound to it.");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004705 ASSERT_NO_FATAL_FAILURE(InitState());
4706
4707 VkImage image;
4708 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
4709 VkImageCreateInfo image_create_info = {};
4710 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4711 image_create_info.pNext = NULL;
4712 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4713 image_create_info.format = tex_format;
4714 image_create_info.extent.width = 32;
4715 image_create_info.extent.height = 32;
4716 image_create_info.extent.depth = 1;
4717 image_create_info.mipLevels = 1;
4718 image_create_info.arrayLayers = 1;
4719 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
4720 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004721 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004722 image_create_info.flags = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004723 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004724 ASSERT_VK_SUCCESS(err);
4725 // Have to bind memory to image before recording cmd in cmd buffer using it
4726 VkMemoryRequirements mem_reqs;
4727 VkDeviceMemory image_mem;
4728 bool pass;
4729 VkMemoryAllocateInfo mem_alloc = {};
4730 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4731 mem_alloc.pNext = NULL;
4732 mem_alloc.memoryTypeIndex = 0;
4733 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
4734 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004735 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004736 ASSERT_TRUE(pass);
4737 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
4738 ASSERT_VK_SUCCESS(err);
4739
Tobin Ehlisfed999f2016-09-21 15:09:45 -06004740 // Introduce error, do not call vkBindImageMemory(m_device->device(), image, image_mem, 0);
4741 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06004742 " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004743
4744 m_commandBuffer->BeginCommandBuffer();
4745 VkClearColorValue ccv;
4746 ccv.float32[0] = 1.0f;
4747 ccv.float32[1] = 1.0f;
4748 ccv.float32[2] = 1.0f;
4749 ccv.float32[3] = 1.0f;
4750 VkImageSubresourceRange isr = {};
4751 isr.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
4752 isr.baseArrayLayer = 0;
4753 isr.baseMipLevel = 0;
4754 isr.layerCount = 1;
4755 isr.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004756 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), image, VK_IMAGE_LAYOUT_GENERAL, &ccv, 1, &isr);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004757 m_commandBuffer->EndCommandBuffer();
4758
4759 m_errorMonitor->VerifyFound();
4760 vkDestroyImage(m_device->device(), image, NULL);
4761 vkFreeMemory(m_device->device(), image_mem, nullptr);
4762}
4763
4764TEST_F(VkLayerTest, BufferMemoryNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004765 TEST_DESCRIPTION("Attempt to copy from a buffer which has not had memory bound to it.");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004766 ASSERT_NO_FATAL_FAILURE(InitState());
4767
4768 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004769 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 -06004770 VK_IMAGE_TILING_OPTIMAL, 0);
4771 ASSERT_TRUE(image.initialized());
4772
4773 VkBuffer buffer;
4774 VkDeviceMemory mem;
4775 VkMemoryRequirements mem_reqs;
4776
4777 VkBufferCreateInfo buf_info = {};
4778 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes8d260dd2016-09-16 17:42:42 +12004779 buf_info.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004780 buf_info.size = 256;
4781 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
4782 VkResult err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
4783 ASSERT_VK_SUCCESS(err);
4784
4785 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
4786
4787 VkMemoryAllocateInfo alloc_info = {};
4788 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4789 alloc_info.allocationSize = 256;
4790 bool pass = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004791 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 -06004792 if (!pass) {
4793 vkDestroyBuffer(m_device->device(), buffer, NULL);
4794 return;
4795 }
4796 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
4797 ASSERT_VK_SUCCESS(err);
4798
Tobin Ehlisfed999f2016-09-21 15:09:45 -06004799 // Introduce failure by not calling vkBindBufferMemory(m_device->device(), buffer, mem, 0);
4800 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06004801 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004802 VkBufferImageCopy region = {};
4803 region.bufferRowLength = 128;
4804 region.bufferImageHeight = 128;
4805 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
4806
4807 region.imageSubresource.layerCount = 1;
4808 region.imageExtent.height = 4;
4809 region.imageExtent.width = 4;
4810 region.imageExtent.depth = 1;
4811 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004812 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer, image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
4813 &region);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004814 m_commandBuffer->EndCommandBuffer();
4815
4816 m_errorMonitor->VerifyFound();
4817
4818 vkDestroyBuffer(m_device->device(), buffer, NULL);
4819 vkFreeMemory(m_device->handle(), mem, NULL);
4820}
4821
Tobin Ehlis85940f52016-07-07 16:57:21 -06004822TEST_F(VkLayerTest, InvalidCmdBufferEventDestroyed) {
4823 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4824 "due to an event dependency being destroyed.");
4825 ASSERT_NO_FATAL_FAILURE(InitState());
4826
4827 VkEvent event;
4828 VkEventCreateInfo evci = {};
4829 evci.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
4830 VkResult result = vkCreateEvent(m_device->device(), &evci, NULL, &event);
4831 ASSERT_VK_SUCCESS(result);
4832
4833 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004834 vkCmdSetEvent(m_commandBuffer->GetBufferHandle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Tobin Ehlis85940f52016-07-07 16:57:21 -06004835 m_commandBuffer->EndCommandBuffer();
4836
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004837 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound event ");
Tobin Ehlis85940f52016-07-07 16:57:21 -06004838 // Destroy event dependency prior to submit to cause ERROR
4839 vkDestroyEvent(m_device->device(), event, NULL);
4840
4841 VkSubmitInfo submit_info = {};
4842 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4843 submit_info.commandBufferCount = 1;
4844 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4845 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4846
4847 m_errorMonitor->VerifyFound();
4848}
4849
Tobin Ehlisdbea7552016-07-08 14:33:31 -06004850TEST_F(VkLayerTest, InvalidCmdBufferQueryPoolDestroyed) {
4851 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4852 "due to a query pool dependency being destroyed.");
4853 ASSERT_NO_FATAL_FAILURE(InitState());
4854
4855 VkQueryPool query_pool;
4856 VkQueryPoolCreateInfo qpci{};
4857 qpci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
4858 qpci.queryType = VK_QUERY_TYPE_TIMESTAMP;
4859 qpci.queryCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004860 VkResult result = vkCreateQueryPool(m_device->device(), &qpci, nullptr, &query_pool);
Tobin Ehlisdbea7552016-07-08 14:33:31 -06004861 ASSERT_VK_SUCCESS(result);
4862
4863 m_commandBuffer->BeginCommandBuffer();
4864 vkCmdResetQueryPool(m_commandBuffer->GetBufferHandle(), query_pool, 0, 1);
4865 m_commandBuffer->EndCommandBuffer();
4866
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004867 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound query pool ");
Tobin Ehlisdbea7552016-07-08 14:33:31 -06004868 // Destroy query pool dependency prior to submit to cause ERROR
4869 vkDestroyQueryPool(m_device->device(), query_pool, NULL);
4870
4871 VkSubmitInfo submit_info = {};
4872 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4873 submit_info.commandBufferCount = 1;
4874 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4875 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4876
4877 m_errorMonitor->VerifyFound();
4878}
4879
Tobin Ehlis24130d92016-07-08 15:50:53 -06004880TEST_F(VkLayerTest, InvalidCmdBufferPipelineDestroyed) {
4881 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4882 "due to a pipeline dependency being destroyed.");
4883 ASSERT_NO_FATAL_FAILURE(InitState());
4884 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4885
4886 VkResult err;
4887
4888 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4889 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4890
4891 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004892 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis24130d92016-07-08 15:50:53 -06004893 ASSERT_VK_SUCCESS(err);
4894
4895 VkPipelineViewportStateCreateInfo vp_state_ci = {};
4896 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
4897 vp_state_ci.viewportCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004898 VkViewport vp = {}; // Just need dummy vp to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -06004899 vp_state_ci.pViewports = &vp;
Tobin Ehlis24130d92016-07-08 15:50:53 -06004900 vp_state_ci.scissorCount = 1;
4901 VkRect2D scissors = {}; // Dummy scissors to point to
4902 vp_state_ci.pScissors = &scissors;
Tobin Ehlis24130d92016-07-08 15:50:53 -06004903
4904 VkPipelineShaderStageCreateInfo shaderStages[2];
4905 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
4906
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004907 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
4908 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
4909 // but add it to be able to run on more devices
Tobin Ehlis24130d92016-07-08 15:50:53 -06004910 shaderStages[0] = vs.GetStageCreateInfo();
4911 shaderStages[1] = fs.GetStageCreateInfo();
4912
4913 VkPipelineVertexInputStateCreateInfo vi_ci = {};
4914 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
4915
4916 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
4917 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
4918 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
4919
4920 VkPipelineRasterizationStateCreateInfo rs_ci = {};
4921 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Chris Forbese06ba252016-09-16 17:48:53 +12004922 rs_ci.rasterizerDiscardEnable = true;
4923 rs_ci.lineWidth = 1.0f;
Tobin Ehlis24130d92016-07-08 15:50:53 -06004924
4925 VkPipelineColorBlendAttachmentState att = {};
4926 att.blendEnable = VK_FALSE;
4927 att.colorWriteMask = 0xf;
4928
4929 VkPipelineColorBlendStateCreateInfo cb_ci = {};
4930 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
4931 cb_ci.attachmentCount = 1;
4932 cb_ci.pAttachments = &att;
4933
4934 VkGraphicsPipelineCreateInfo gp_ci = {};
4935 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
4936 gp_ci.stageCount = 2;
4937 gp_ci.pStages = shaderStages;
4938 gp_ci.pVertexInputState = &vi_ci;
4939 gp_ci.pInputAssemblyState = &ia_ci;
4940 gp_ci.pViewportState = &vp_state_ci;
4941 gp_ci.pRasterizationState = &rs_ci;
4942 gp_ci.pColorBlendState = &cb_ci;
Tobin Ehlis24130d92016-07-08 15:50:53 -06004943 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
4944 gp_ci.layout = pipeline_layout;
4945 gp_ci.renderPass = renderPass();
4946
4947 VkPipelineCacheCreateInfo pc_ci = {};
4948 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
4949
4950 VkPipeline pipeline;
4951 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004952 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis24130d92016-07-08 15:50:53 -06004953 ASSERT_VK_SUCCESS(err);
4954
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004955 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis24130d92016-07-08 15:50:53 -06004956 ASSERT_VK_SUCCESS(err);
4957
4958 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004959 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Tobin Ehlis24130d92016-07-08 15:50:53 -06004960 m_commandBuffer->EndCommandBuffer();
4961 // Now destroy pipeline in order to cause error when submitting
4962 vkDestroyPipeline(m_device->device(), pipeline, nullptr);
4963
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004964 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound pipeline ");
Tobin Ehlis24130d92016-07-08 15:50:53 -06004965
4966 VkSubmitInfo submit_info = {};
4967 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4968 submit_info.commandBufferCount = 1;
4969 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4970 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4971
4972 m_errorMonitor->VerifyFound();
4973 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
4974 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4975}
4976
Tobin Ehlis31289162016-08-17 14:57:58 -06004977TEST_F(VkLayerTest, InvalidCmdBufferDescriptorSetBufferDestroyed) {
4978 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4979 "due to a bound descriptor set with a buffer dependency "
4980 "being destroyed.");
4981 ASSERT_NO_FATAL_FAILURE(InitState());
4982 ASSERT_NO_FATAL_FAILURE(InitViewport());
4983 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4984
4985 VkDescriptorPoolSize ds_type_count = {};
4986 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4987 ds_type_count.descriptorCount = 1;
4988
4989 VkDescriptorPoolCreateInfo ds_pool_ci = {};
4990 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4991 ds_pool_ci.pNext = NULL;
4992 ds_pool_ci.maxSets = 1;
4993 ds_pool_ci.poolSizeCount = 1;
4994 ds_pool_ci.pPoolSizes = &ds_type_count;
4995
4996 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004997 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis31289162016-08-17 14:57:58 -06004998 ASSERT_VK_SUCCESS(err);
4999
5000 VkDescriptorSetLayoutBinding dsl_binding = {};
5001 dsl_binding.binding = 0;
5002 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5003 dsl_binding.descriptorCount = 1;
5004 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5005 dsl_binding.pImmutableSamplers = NULL;
5006
5007 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5008 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5009 ds_layout_ci.pNext = NULL;
5010 ds_layout_ci.bindingCount = 1;
5011 ds_layout_ci.pBindings = &dsl_binding;
5012 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005013 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis31289162016-08-17 14:57:58 -06005014 ASSERT_VK_SUCCESS(err);
5015
5016 VkDescriptorSet descriptorSet;
5017 VkDescriptorSetAllocateInfo alloc_info = {};
5018 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
5019 alloc_info.descriptorSetCount = 1;
5020 alloc_info.descriptorPool = ds_pool;
5021 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005022 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis31289162016-08-17 14:57:58 -06005023 ASSERT_VK_SUCCESS(err);
5024
5025 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5026 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5027 pipeline_layout_ci.pNext = NULL;
5028 pipeline_layout_ci.setLayoutCount = 1;
5029 pipeline_layout_ci.pSetLayouts = &ds_layout;
5030
5031 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005032 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis31289162016-08-17 14:57:58 -06005033 ASSERT_VK_SUCCESS(err);
5034
5035 // Create a buffer to update the descriptor with
5036 uint32_t qfi = 0;
5037 VkBufferCreateInfo buffCI = {};
5038 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
5039 buffCI.size = 1024;
5040 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
5041 buffCI.queueFamilyIndexCount = 1;
5042 buffCI.pQueueFamilyIndices = &qfi;
5043
5044 VkBuffer buffer;
5045 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &buffer);
5046 ASSERT_VK_SUCCESS(err);
5047 // Allocate memory and bind to buffer so we can make it to the appropriate
5048 // error
5049 VkMemoryAllocateInfo mem_alloc = {};
5050 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5051 mem_alloc.pNext = NULL;
5052 mem_alloc.allocationSize = 1024;
5053 mem_alloc.memoryTypeIndex = 0;
5054
5055 VkMemoryRequirements memReqs;
5056 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005057 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis31289162016-08-17 14:57:58 -06005058 if (!pass) {
5059 vkDestroyBuffer(m_device->device(), buffer, NULL);
5060 return;
5061 }
5062
5063 VkDeviceMemory mem;
5064 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
5065 ASSERT_VK_SUCCESS(err);
5066 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
5067 ASSERT_VK_SUCCESS(err);
5068 // Correctly update descriptor to avoid "NOT_UPDATED" error
5069 VkDescriptorBufferInfo buffInfo = {};
5070 buffInfo.buffer = buffer;
5071 buffInfo.offset = 0;
5072 buffInfo.range = 1024;
5073
5074 VkWriteDescriptorSet descriptor_write;
5075 memset(&descriptor_write, 0, sizeof(descriptor_write));
5076 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5077 descriptor_write.dstSet = descriptorSet;
5078 descriptor_write.dstBinding = 0;
5079 descriptor_write.descriptorCount = 1;
5080 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5081 descriptor_write.pBufferInfo = &buffInfo;
5082
5083 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5084
5085 // Create PSO to be used for draw-time errors below
5086 char const *vsSource = "#version 450\n"
5087 "\n"
5088 "out gl_PerVertex { \n"
5089 " vec4 gl_Position;\n"
5090 "};\n"
5091 "void main(){\n"
5092 " gl_Position = vec4(1);\n"
5093 "}\n";
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005094 char const *fsSource = "#version 450\n"
5095 "\n"
5096 "layout(location=0) out vec4 x;\n"
5097 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
5098 "void main(){\n"
5099 " x = vec4(bar.y);\n"
5100 "}\n";
Tobin Ehlis31289162016-08-17 14:57:58 -06005101 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5102 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5103 VkPipelineObj pipe(m_device);
5104 pipe.AddShader(&vs);
5105 pipe.AddShader(&fs);
5106 pipe.AddColorAttachment();
5107 pipe.CreateVKPipeline(pipeline_layout, renderPass());
5108
Tony Barbour552f6c02016-12-21 14:34:07 -07005109 m_commandBuffer->BeginCommandBuffer();
5110 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005111 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5112 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5113 &descriptorSet, 0, NULL);
Tobin Ehlis31289162016-08-17 14:57:58 -06005114 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07005115 m_commandBuffer->EndRenderPass();
5116 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005117 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound buffer ");
Tobin Ehlis31289162016-08-17 14:57:58 -06005118 // Destroy buffer should invalidate the cmd buffer, causing error on submit
5119 vkDestroyBuffer(m_device->device(), buffer, NULL);
5120 // Attempt to submit cmd buffer
5121 VkSubmitInfo submit_info = {};
5122 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5123 submit_info.commandBufferCount = 1;
5124 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5125 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5126 m_errorMonitor->VerifyFound();
5127 // Cleanup
5128 vkFreeMemory(m_device->device(), mem, NULL);
5129
5130 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5131 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5132 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5133}
5134
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005135TEST_F(VkLayerTest, InvalidCmdBufferDescriptorSetImageSamplerDestroyed) {
5136 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
5137 "due to a bound descriptor sets with a combined image "
5138 "sampler having their image, sampler, and descriptor set "
5139 "each respectively destroyed and then attempting to "
Mark Mueller917f6bc2016-08-30 10:57:19 -06005140 "submit associated cmd buffers. Attempt to destroy a "
5141 "DescriptorSet that is in use.");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005142 ASSERT_NO_FATAL_FAILURE(InitState());
5143 ASSERT_NO_FATAL_FAILURE(InitViewport());
5144 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5145
5146 VkDescriptorPoolSize ds_type_count = {};
5147 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5148 ds_type_count.descriptorCount = 1;
5149
5150 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5151 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5152 ds_pool_ci.pNext = NULL;
5153 ds_pool_ci.maxSets = 1;
5154 ds_pool_ci.poolSizeCount = 1;
5155 ds_pool_ci.pPoolSizes = &ds_type_count;
5156
5157 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005158 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005159 ASSERT_VK_SUCCESS(err);
5160
5161 VkDescriptorSetLayoutBinding dsl_binding = {};
5162 dsl_binding.binding = 0;
5163 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5164 dsl_binding.descriptorCount = 1;
5165 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5166 dsl_binding.pImmutableSamplers = NULL;
5167
5168 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5169 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5170 ds_layout_ci.pNext = NULL;
5171 ds_layout_ci.bindingCount = 1;
5172 ds_layout_ci.pBindings = &dsl_binding;
5173 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005174 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005175 ASSERT_VK_SUCCESS(err);
5176
5177 VkDescriptorSet descriptorSet;
5178 VkDescriptorSetAllocateInfo alloc_info = {};
5179 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
5180 alloc_info.descriptorSetCount = 1;
5181 alloc_info.descriptorPool = ds_pool;
5182 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005183 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005184 ASSERT_VK_SUCCESS(err);
5185
5186 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5187 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5188 pipeline_layout_ci.pNext = NULL;
5189 pipeline_layout_ci.setLayoutCount = 1;
5190 pipeline_layout_ci.pSetLayouts = &ds_layout;
5191
5192 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005193 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005194 ASSERT_VK_SUCCESS(err);
5195
5196 // Create images to update the descriptor with
5197 VkImage image;
5198 VkImage image2;
5199 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
5200 const int32_t tex_width = 32;
5201 const int32_t tex_height = 32;
5202 VkImageCreateInfo image_create_info = {};
5203 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5204 image_create_info.pNext = NULL;
5205 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5206 image_create_info.format = tex_format;
5207 image_create_info.extent.width = tex_width;
5208 image_create_info.extent.height = tex_height;
5209 image_create_info.extent.depth = 1;
5210 image_create_info.mipLevels = 1;
5211 image_create_info.arrayLayers = 1;
5212 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
5213 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
5214 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
5215 image_create_info.flags = 0;
5216 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
5217 ASSERT_VK_SUCCESS(err);
5218 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image2);
5219 ASSERT_VK_SUCCESS(err);
5220
5221 VkMemoryRequirements memory_reqs;
5222 VkDeviceMemory image_memory;
5223 bool pass;
5224 VkMemoryAllocateInfo memory_info = {};
5225 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5226 memory_info.pNext = NULL;
5227 memory_info.allocationSize = 0;
5228 memory_info.memoryTypeIndex = 0;
5229 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
5230 // Allocate enough memory for both images
5231 memory_info.allocationSize = memory_reqs.size * 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005232 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005233 ASSERT_TRUE(pass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005234 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005235 ASSERT_VK_SUCCESS(err);
5236 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
5237 ASSERT_VK_SUCCESS(err);
5238 // Bind second image to memory right after first image
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005239 err = vkBindImageMemory(m_device->device(), image2, image_memory, memory_reqs.size);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005240 ASSERT_VK_SUCCESS(err);
5241
5242 VkImageViewCreateInfo image_view_create_info = {};
5243 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
5244 image_view_create_info.image = image;
5245 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
5246 image_view_create_info.format = tex_format;
5247 image_view_create_info.subresourceRange.layerCount = 1;
5248 image_view_create_info.subresourceRange.baseMipLevel = 0;
5249 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005250 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005251
5252 VkImageView view;
5253 VkImageView view2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005254 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005255 ASSERT_VK_SUCCESS(err);
5256 image_view_create_info.image = image2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005257 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view2);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005258 ASSERT_VK_SUCCESS(err);
5259 // Create Samplers
5260 VkSamplerCreateInfo sampler_ci = {};
5261 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
5262 sampler_ci.pNext = NULL;
5263 sampler_ci.magFilter = VK_FILTER_NEAREST;
5264 sampler_ci.minFilter = VK_FILTER_NEAREST;
5265 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
5266 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5267 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5268 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5269 sampler_ci.mipLodBias = 1.0;
5270 sampler_ci.anisotropyEnable = VK_FALSE;
5271 sampler_ci.maxAnisotropy = 1;
5272 sampler_ci.compareEnable = VK_FALSE;
5273 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
5274 sampler_ci.minLod = 1.0;
5275 sampler_ci.maxLod = 1.0;
5276 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
5277 sampler_ci.unnormalizedCoordinates = VK_FALSE;
5278 VkSampler sampler;
5279 VkSampler sampler2;
5280 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
5281 ASSERT_VK_SUCCESS(err);
5282 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler2);
5283 ASSERT_VK_SUCCESS(err);
5284 // Update descriptor with image and sampler
5285 VkDescriptorImageInfo img_info = {};
5286 img_info.sampler = sampler;
5287 img_info.imageView = view;
5288 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
5289
5290 VkWriteDescriptorSet descriptor_write;
5291 memset(&descriptor_write, 0, sizeof(descriptor_write));
5292 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5293 descriptor_write.dstSet = descriptorSet;
5294 descriptor_write.dstBinding = 0;
5295 descriptor_write.descriptorCount = 1;
5296 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5297 descriptor_write.pImageInfo = &img_info;
5298
5299 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5300
5301 // Create PSO to be used for draw-time errors below
5302 char const *vsSource = "#version 450\n"
5303 "\n"
5304 "out gl_PerVertex { \n"
5305 " vec4 gl_Position;\n"
5306 "};\n"
5307 "void main(){\n"
5308 " gl_Position = vec4(1);\n"
5309 "}\n";
5310 char const *fsSource = "#version 450\n"
5311 "\n"
5312 "layout(set=0, binding=0) uniform sampler2D s;\n"
5313 "layout(location=0) out vec4 x;\n"
5314 "void main(){\n"
5315 " x = texture(s, vec2(1));\n"
5316 "}\n";
5317 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5318 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5319 VkPipelineObj pipe(m_device);
5320 pipe.AddShader(&vs);
5321 pipe.AddShader(&fs);
5322 pipe.AddColorAttachment();
5323 pipe.CreateVKPipeline(pipeline_layout, renderPass());
5324
5325 // First error case is destroying sampler prior to cmd buffer submission
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005326 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot submit cmd buffer using deleted sampler ");
Tony Barbour552f6c02016-12-21 14:34:07 -07005327 m_commandBuffer->BeginCommandBuffer();
5328 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
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);
Tony Barbour552f6c02016-12-21 14:34:07 -07005333 m_commandBuffer->EndRenderPass();
5334 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005335 // Destroy sampler invalidates the cmd buffer, causing error on submit
5336 vkDestroySampler(m_device->device(), sampler, NULL);
5337 // Attempt to submit cmd buffer
5338 VkSubmitInfo submit_info = {};
5339 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5340 submit_info.commandBufferCount = 1;
5341 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5342 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5343 m_errorMonitor->VerifyFound();
5344 // Now re-update descriptor with valid sampler and delete image
5345 img_info.sampler = sampler2;
5346 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005347 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Tony Barbour552f6c02016-12-21 14:34:07 -07005348 m_commandBuffer->BeginCommandBuffer();
5349 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005350 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5351 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5352 &descriptorSet, 0, NULL);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005353 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07005354 m_commandBuffer->EndRenderPass();
5355 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005356 // Destroy image invalidates the cmd buffer, causing error on submit
5357 vkDestroyImage(m_device->device(), image, NULL);
5358 // Attempt to submit cmd buffer
5359 submit_info = {};
5360 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5361 submit_info.commandBufferCount = 1;
5362 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5363 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5364 m_errorMonitor->VerifyFound();
5365 // Now update descriptor to be valid, but then free descriptor
5366 img_info.imageView = view2;
5367 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005368 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound descriptor set ");
Tony Barbour552f6c02016-12-21 14:34:07 -07005369 m_commandBuffer->BeginCommandBuffer();
5370 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005371 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5372 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5373 &descriptorSet, 0, NULL);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005374 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07005375 m_commandBuffer->EndRenderPass();
5376 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005377 // Destroy descriptor set invalidates the cb, causing error on submit
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005378 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot call vkFreeDescriptorSets() on descriptor set 0x");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005379 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
Mark Mueller917f6bc2016-08-30 10:57:19 -06005380 m_errorMonitor->VerifyFound();
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005381 // Attempt to submit cmd buffer
5382 submit_info = {};
5383 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5384 submit_info.commandBufferCount = 1;
5385 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5386 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5387 m_errorMonitor->VerifyFound();
5388 // Cleanup
5389 vkFreeMemory(m_device->device(), image_memory, NULL);
5390 vkDestroySampler(m_device->device(), sampler2, NULL);
5391 vkDestroyImage(m_device->device(), image2, NULL);
5392 vkDestroyImageView(m_device->device(), view, NULL);
5393 vkDestroyImageView(m_device->device(), view2, NULL);
5394 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5395 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5396 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5397}
5398
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06005399TEST_F(VkLayerTest, DescriptorPoolInUseDestroyedSignaled) {
5400 TEST_DESCRIPTION("Delete a DescriptorPool with a DescriptorSet that is in use.");
5401 ASSERT_NO_FATAL_FAILURE(InitState());
5402 ASSERT_NO_FATAL_FAILURE(InitViewport());
5403 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5404
5405 VkDescriptorPoolSize ds_type_count = {};
5406 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5407 ds_type_count.descriptorCount = 1;
5408
5409 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5410 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5411 ds_pool_ci.pNext = NULL;
5412 ds_pool_ci.maxSets = 1;
5413 ds_pool_ci.poolSizeCount = 1;
5414 ds_pool_ci.pPoolSizes = &ds_type_count;
5415
5416 VkDescriptorPool ds_pool;
5417 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
5418 ASSERT_VK_SUCCESS(err);
5419
5420 VkDescriptorSetLayoutBinding dsl_binding = {};
5421 dsl_binding.binding = 0;
5422 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5423 dsl_binding.descriptorCount = 1;
5424 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5425 dsl_binding.pImmutableSamplers = NULL;
5426
5427 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5428 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5429 ds_layout_ci.pNext = NULL;
5430 ds_layout_ci.bindingCount = 1;
5431 ds_layout_ci.pBindings = &dsl_binding;
5432 VkDescriptorSetLayout ds_layout;
5433 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
5434 ASSERT_VK_SUCCESS(err);
5435
5436 VkDescriptorSet descriptor_set;
5437 VkDescriptorSetAllocateInfo alloc_info = {};
5438 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
5439 alloc_info.descriptorSetCount = 1;
5440 alloc_info.descriptorPool = ds_pool;
5441 alloc_info.pSetLayouts = &ds_layout;
5442 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
5443 ASSERT_VK_SUCCESS(err);
5444
5445 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5446 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5447 pipeline_layout_ci.pNext = NULL;
5448 pipeline_layout_ci.setLayoutCount = 1;
5449 pipeline_layout_ci.pSetLayouts = &ds_layout;
5450
5451 VkPipelineLayout pipeline_layout;
5452 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
5453 ASSERT_VK_SUCCESS(err);
5454
5455 // Create image to update the descriptor with
5456 VkImageObj image(m_device);
5457 image.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
5458 ASSERT_TRUE(image.initialized());
5459
5460 VkImageView view = image.targetView(VK_FORMAT_B8G8R8A8_UNORM);
5461 // Create Sampler
5462 VkSamplerCreateInfo sampler_ci = {};
5463 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
5464 sampler_ci.pNext = NULL;
5465 sampler_ci.magFilter = VK_FILTER_NEAREST;
5466 sampler_ci.minFilter = VK_FILTER_NEAREST;
5467 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
5468 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5469 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5470 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5471 sampler_ci.mipLodBias = 1.0;
5472 sampler_ci.anisotropyEnable = VK_FALSE;
5473 sampler_ci.maxAnisotropy = 1;
5474 sampler_ci.compareEnable = VK_FALSE;
5475 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
5476 sampler_ci.minLod = 1.0;
5477 sampler_ci.maxLod = 1.0;
5478 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
5479 sampler_ci.unnormalizedCoordinates = VK_FALSE;
5480 VkSampler sampler;
5481 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
5482 ASSERT_VK_SUCCESS(err);
5483 // Update descriptor with image and sampler
5484 VkDescriptorImageInfo img_info = {};
5485 img_info.sampler = sampler;
5486 img_info.imageView = view;
5487 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
5488
5489 VkWriteDescriptorSet descriptor_write;
5490 memset(&descriptor_write, 0, sizeof(descriptor_write));
5491 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5492 descriptor_write.dstSet = descriptor_set;
5493 descriptor_write.dstBinding = 0;
5494 descriptor_write.descriptorCount = 1;
5495 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5496 descriptor_write.pImageInfo = &img_info;
5497
5498 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5499
5500 // Create PSO to be used for draw-time errors below
5501 char const *vsSource = "#version 450\n"
5502 "\n"
5503 "out gl_PerVertex { \n"
5504 " vec4 gl_Position;\n"
5505 "};\n"
5506 "void main(){\n"
5507 " gl_Position = vec4(1);\n"
5508 "}\n";
5509 char const *fsSource = "#version 450\n"
5510 "\n"
5511 "layout(set=0, binding=0) uniform sampler2D s;\n"
5512 "layout(location=0) out vec4 x;\n"
5513 "void main(){\n"
5514 " x = texture(s, vec2(1));\n"
5515 "}\n";
5516 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5517 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5518 VkPipelineObj pipe(m_device);
5519 pipe.AddShader(&vs);
5520 pipe.AddShader(&fs);
5521 pipe.AddColorAttachment();
5522 pipe.CreateVKPipeline(pipeline_layout, renderPass());
5523
Tony Barbour552f6c02016-12-21 14:34:07 -07005524 m_commandBuffer->BeginCommandBuffer();
5525 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06005526 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5527 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5528 &descriptor_set, 0, NULL);
5529 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07005530 m_commandBuffer->EndRenderPass();
5531 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06005532 // Submit cmd buffer to put pool in-flight
5533 VkSubmitInfo submit_info = {};
5534 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5535 submit_info.commandBufferCount = 1;
5536 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5537 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5538 // Destroy pool while in-flight, causing error
5539 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete descriptor pool ");
5540 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5541 m_errorMonitor->VerifyFound();
5542 vkQueueWaitIdle(m_device->m_queue);
5543 // Cleanup
5544 vkDestroySampler(m_device->device(), sampler, NULL);
5545 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5546 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5547 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5548}
5549
Tobin Ehlis50a095d2016-09-21 17:32:49 -06005550TEST_F(VkLayerTest, DescriptorImageUpdateNoMemoryBound) {
5551 TEST_DESCRIPTION("Attempt an image descriptor set update where image's bound memory has been freed.");
5552 ASSERT_NO_FATAL_FAILURE(InitState());
5553 ASSERT_NO_FATAL_FAILURE(InitViewport());
5554 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5555
5556 VkDescriptorPoolSize ds_type_count = {};
5557 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5558 ds_type_count.descriptorCount = 1;
5559
5560 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5561 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5562 ds_pool_ci.pNext = NULL;
5563 ds_pool_ci.maxSets = 1;
5564 ds_pool_ci.poolSizeCount = 1;
5565 ds_pool_ci.pPoolSizes = &ds_type_count;
5566
5567 VkDescriptorPool ds_pool;
5568 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
5569 ASSERT_VK_SUCCESS(err);
5570
5571 VkDescriptorSetLayoutBinding dsl_binding = {};
5572 dsl_binding.binding = 0;
5573 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5574 dsl_binding.descriptorCount = 1;
5575 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5576 dsl_binding.pImmutableSamplers = NULL;
5577
5578 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5579 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5580 ds_layout_ci.pNext = NULL;
5581 ds_layout_ci.bindingCount = 1;
5582 ds_layout_ci.pBindings = &dsl_binding;
5583 VkDescriptorSetLayout ds_layout;
5584 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
5585 ASSERT_VK_SUCCESS(err);
5586
5587 VkDescriptorSet descriptorSet;
5588 VkDescriptorSetAllocateInfo alloc_info = {};
5589 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
5590 alloc_info.descriptorSetCount = 1;
5591 alloc_info.descriptorPool = ds_pool;
5592 alloc_info.pSetLayouts = &ds_layout;
5593 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
5594 ASSERT_VK_SUCCESS(err);
5595
5596 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5597 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5598 pipeline_layout_ci.pNext = NULL;
5599 pipeline_layout_ci.setLayoutCount = 1;
5600 pipeline_layout_ci.pSetLayouts = &ds_layout;
5601
5602 VkPipelineLayout pipeline_layout;
5603 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
5604 ASSERT_VK_SUCCESS(err);
5605
5606 // Create images to update the descriptor with
5607 VkImage image;
5608 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
5609 const int32_t tex_width = 32;
5610 const int32_t tex_height = 32;
5611 VkImageCreateInfo image_create_info = {};
5612 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5613 image_create_info.pNext = NULL;
5614 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5615 image_create_info.format = tex_format;
5616 image_create_info.extent.width = tex_width;
5617 image_create_info.extent.height = tex_height;
5618 image_create_info.extent.depth = 1;
5619 image_create_info.mipLevels = 1;
5620 image_create_info.arrayLayers = 1;
5621 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
5622 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
5623 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
5624 image_create_info.flags = 0;
5625 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
5626 ASSERT_VK_SUCCESS(err);
5627 // Initially bind memory to avoid error at bind view time. We'll break binding before update.
5628 VkMemoryRequirements memory_reqs;
5629 VkDeviceMemory image_memory;
5630 bool pass;
5631 VkMemoryAllocateInfo memory_info = {};
5632 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5633 memory_info.pNext = NULL;
5634 memory_info.allocationSize = 0;
5635 memory_info.memoryTypeIndex = 0;
5636 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
5637 // Allocate enough memory for image
5638 memory_info.allocationSize = memory_reqs.size;
5639 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
5640 ASSERT_TRUE(pass);
5641 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
5642 ASSERT_VK_SUCCESS(err);
5643 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
5644 ASSERT_VK_SUCCESS(err);
5645
5646 VkImageViewCreateInfo image_view_create_info = {};
5647 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
5648 image_view_create_info.image = image;
5649 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
5650 image_view_create_info.format = tex_format;
5651 image_view_create_info.subresourceRange.layerCount = 1;
5652 image_view_create_info.subresourceRange.baseMipLevel = 0;
5653 image_view_create_info.subresourceRange.levelCount = 1;
5654 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
5655
5656 VkImageView view;
5657 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
5658 ASSERT_VK_SUCCESS(err);
5659 // Create Samplers
5660 VkSamplerCreateInfo sampler_ci = {};
5661 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
5662 sampler_ci.pNext = NULL;
5663 sampler_ci.magFilter = VK_FILTER_NEAREST;
5664 sampler_ci.minFilter = VK_FILTER_NEAREST;
5665 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
5666 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5667 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5668 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5669 sampler_ci.mipLodBias = 1.0;
5670 sampler_ci.anisotropyEnable = VK_FALSE;
5671 sampler_ci.maxAnisotropy = 1;
5672 sampler_ci.compareEnable = VK_FALSE;
5673 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
5674 sampler_ci.minLod = 1.0;
5675 sampler_ci.maxLod = 1.0;
5676 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
5677 sampler_ci.unnormalizedCoordinates = VK_FALSE;
5678 VkSampler sampler;
5679 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
5680 ASSERT_VK_SUCCESS(err);
5681 // Update descriptor with image and sampler
5682 VkDescriptorImageInfo img_info = {};
5683 img_info.sampler = sampler;
5684 img_info.imageView = view;
5685 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
5686
5687 VkWriteDescriptorSet descriptor_write;
5688 memset(&descriptor_write, 0, sizeof(descriptor_write));
5689 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5690 descriptor_write.dstSet = descriptorSet;
5691 descriptor_write.dstBinding = 0;
5692 descriptor_write.descriptorCount = 1;
5693 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5694 descriptor_write.pImageInfo = &img_info;
5695 // Break memory binding and attempt update
5696 vkFreeMemory(m_device->device(), image_memory, nullptr);
5697 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06005698 " previously bound memory was freed. Memory must not be freed prior to this operation.");
Tobin Ehlis50a095d2016-09-21 17:32:49 -06005699 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
5700 "vkUpdateDescriptorsSets() failed write update validation for Descriptor Set 0x");
5701 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5702 m_errorMonitor->VerifyFound();
5703 // Cleanup
5704 vkDestroyImage(m_device->device(), image, NULL);
5705 vkDestroySampler(m_device->device(), sampler, NULL);
5706 vkDestroyImageView(m_device->device(), view, NULL);
5707 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5708 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5709 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5710}
5711
Karl Schultz6addd812016-02-02 17:17:23 -07005712TEST_F(VkLayerTest, InvalidPipeline) {
Karl Schultzbdb75952016-04-19 11:36:49 -06005713 // Attempt to bind an invalid Pipeline to a valid Command Buffer
5714 // ObjectTracker should catch this.
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06005715 // Create a valid cmd buffer
5716 // call vkCmdBindPipeline w/ false Pipeline
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06005717 uint64_t fake_pipeline_handle = 0xbaad6001;
5718 VkPipeline bad_pipeline = reinterpret_cast<VkPipeline &>(fake_pipeline_handle);
Karl Schultzbdb75952016-04-19 11:36:49 -06005719 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes4dbf70f2016-09-16 17:58:00 +12005720 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5721
Karl Schultzf78bcdd2016-11-30 12:36:01 -07005722 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00601);
Tony Barbour552f6c02016-12-21 14:34:07 -07005723 m_commandBuffer->BeginCommandBuffer();
5724 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005725 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, bad_pipeline);
Karl Schultzbdb75952016-04-19 11:36:49 -06005726 m_errorMonitor->VerifyFound();
Chris Forbes4dbf70f2016-09-16 17:58:00 +12005727
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06005728 // Now issue a draw call with no pipeline bound
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005729 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 -06005730 Draw(1, 0, 0, 0);
5731 m_errorMonitor->VerifyFound();
Chris Forbes4dbf70f2016-09-16 17:58:00 +12005732
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06005733 // Finally same check once more but with Dispatch/Compute
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005734 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 +12005735 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle()); // must be outside renderpass
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06005736 vkCmdDispatch(m_commandBuffer->GetBufferHandle(), 0, 0, 0);
5737 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06005738}
5739
Karl Schultz6addd812016-02-02 17:17:23 -07005740TEST_F(VkLayerTest, DescriptorSetNotUpdated) {
Tobin Ehlis5a5f5ef2016-08-17 13:56:55 -06005741 TEST_DESCRIPTION("Bind a descriptor set that hasn't been updated.");
Karl Schultz6addd812016-02-02 17:17:23 -07005742 VkResult err;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005743
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005744 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, " bound but it was never updated. ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005745
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005746 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyan713b2d72015-08-04 10:49:29 -06005747 ASSERT_NO_FATAL_FAILURE(InitViewport());
5748 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08005749 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005750 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5751 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06005752
5753 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005754 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5755 ds_pool_ci.pNext = NULL;
5756 ds_pool_ci.maxSets = 1;
5757 ds_pool_ci.poolSizeCount = 1;
5758 ds_pool_ci.pPoolSizes = &ds_type_count;
Mike Stroyan713b2d72015-08-04 10:49:29 -06005759
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005760 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005761 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005762 ASSERT_VK_SUCCESS(err);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005763
Tony Barboureb254902015-07-15 12:50:33 -06005764 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005765 dsl_binding.binding = 0;
5766 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5767 dsl_binding.descriptorCount = 1;
5768 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5769 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005770
Tony Barboureb254902015-07-15 12:50:33 -06005771 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005772 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5773 ds_layout_ci.pNext = NULL;
5774 ds_layout_ci.bindingCount = 1;
5775 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005776 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005777 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005778 ASSERT_VK_SUCCESS(err);
5779
5780 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005781 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08005782 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07005783 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06005784 alloc_info.descriptorPool = ds_pool;
5785 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005786 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005787 ASSERT_VK_SUCCESS(err);
5788
Tony Barboureb254902015-07-15 12:50:33 -06005789 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005790 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5791 pipeline_layout_ci.pNext = NULL;
5792 pipeline_layout_ci.setLayoutCount = 1;
5793 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005794
5795 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005796 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005797 ASSERT_VK_SUCCESS(err);
5798
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005799 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -06005800 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -07005801 // on more devices
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005802 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005803
Tony Barbourc95e4ac2015-08-04 17:05:26 -06005804 VkPipelineObj pipe(m_device);
5805 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06005806 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -06005807 pipe.AddColorAttachment();
Tony Barbourc95e4ac2015-08-04 17:05:26 -06005808 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06005809
Tony Barbour552f6c02016-12-21 14:34:07 -07005810 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005811 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5812 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5813 &descriptorSet, 0, NULL);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005814
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005815 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06005816
Chia-I Wuf7458c52015-10-26 21:10:41 +08005817 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5818 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5819 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06005820}
5821
Karl Schultz6addd812016-02-02 17:17:23 -07005822TEST_F(VkLayerTest, InvalidBufferViewObject) {
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005823 // Create a single TEXEL_BUFFER descriptor and send it an invalid bufferView
Karl Schultz6addd812016-02-02 17:17:23 -07005824 VkResult err;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005825
Karl Schultzf78bcdd2016-11-30 12:36:01 -07005826 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00940);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005827
5828 ASSERT_NO_FATAL_FAILURE(InitState());
5829 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005830 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
5831 ds_type_count.descriptorCount = 1;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005832
5833 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005834 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5835 ds_pool_ci.pNext = NULL;
5836 ds_pool_ci.maxSets = 1;
5837 ds_pool_ci.poolSizeCount = 1;
5838 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005839
5840 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005841 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005842 ASSERT_VK_SUCCESS(err);
5843
5844 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005845 dsl_binding.binding = 0;
5846 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
5847 dsl_binding.descriptorCount = 1;
5848 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5849 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005850
5851 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005852 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5853 ds_layout_ci.pNext = NULL;
5854 ds_layout_ci.bindingCount = 1;
5855 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005856 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005857 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005858 ASSERT_VK_SUCCESS(err);
5859
5860 VkDescriptorSet descriptorSet;
5861 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08005862 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07005863 alloc_info.descriptorSetCount = 1;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005864 alloc_info.descriptorPool = ds_pool;
5865 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005866 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005867 ASSERT_VK_SUCCESS(err);
5868
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005869 VkBufferView view = (VkBufferView)((size_t)0xbaadbeef); // invalid bufferView object
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005870 VkWriteDescriptorSet descriptor_write;
5871 memset(&descriptor_write, 0, sizeof(descriptor_write));
5872 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5873 descriptor_write.dstSet = descriptorSet;
5874 descriptor_write.dstBinding = 0;
5875 descriptor_write.descriptorCount = 1;
5876 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
5877 descriptor_write.pTexelBufferView = &view;
5878
5879 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5880
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005881 m_errorMonitor->VerifyFound();
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005882
5883 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5884 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5885}
5886
Mark Youngd339ba32016-05-30 13:28:35 -06005887TEST_F(VkLayerTest, CreateBufferViewNoMemoryBoundToBuffer) {
Tobin Ehlis4ff58172016-09-22 10:52:00 -06005888 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 -06005889
5890 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -06005891 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06005892 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Mark Youngd339ba32016-05-30 13:28:35 -06005893
5894 ASSERT_NO_FATAL_FAILURE(InitState());
5895
5896 // Create a buffer with no bound memory and then attempt to create
5897 // a buffer view.
5898 VkBufferCreateInfo buff_ci = {};
5899 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes4538d242016-09-13 18:13:58 +12005900 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT;
Mark Youngd339ba32016-05-30 13:28:35 -06005901 buff_ci.size = 256;
5902 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
5903 VkBuffer buffer;
5904 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
5905 ASSERT_VK_SUCCESS(err);
5906
5907 VkBufferViewCreateInfo buff_view_ci = {};
5908 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
5909 buff_view_ci.buffer = buffer;
5910 buff_view_ci.format = VK_FORMAT_R8_UNORM;
5911 buff_view_ci.range = VK_WHOLE_SIZE;
5912 VkBufferView buff_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005913 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buff_view);
Mark Youngd339ba32016-05-30 13:28:35 -06005914
5915 m_errorMonitor->VerifyFound();
5916 vkDestroyBuffer(m_device->device(), buffer, NULL);
5917 // If last error is success, it still created the view, so delete it.
5918 if (err == VK_SUCCESS) {
5919 vkDestroyBufferView(m_device->device(), buff_view, NULL);
5920 }
5921}
5922
Karl Schultz6addd812016-02-02 17:17:23 -07005923TEST_F(VkLayerTest, InvalidDynamicOffsetCases) {
5924 // Create a descriptorSet w/ dynamic descriptor and then hit 3 offset error
5925 // cases:
Tobin Ehlisf6585052015-12-17 11:48:42 -07005926 // 1. No dynamicOffset supplied
5927 // 2. Too many dynamicOffsets supplied
5928 // 3. Dynamic offset oversteps buffer being updated
Karl Schultz6addd812016-02-02 17:17:23 -07005929 VkResult err;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005930 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " requires 1 dynamicOffsets, but only "
5931 "0 dynamicOffsets are left in "
5932 "pDynamicOffsets ");
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005933
5934 ASSERT_NO_FATAL_FAILURE(InitState());
5935 ASSERT_NO_FATAL_FAILURE(InitViewport());
5936 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5937
5938 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005939 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
5940 ds_type_count.descriptorCount = 1;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005941
5942 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005943 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5944 ds_pool_ci.pNext = NULL;
5945 ds_pool_ci.maxSets = 1;
5946 ds_pool_ci.poolSizeCount = 1;
5947 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005948
5949 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005950 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005951 ASSERT_VK_SUCCESS(err);
5952
5953 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005954 dsl_binding.binding = 0;
5955 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
5956 dsl_binding.descriptorCount = 1;
5957 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5958 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005959
5960 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005961 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5962 ds_layout_ci.pNext = NULL;
5963 ds_layout_ci.bindingCount = 1;
5964 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005965 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005966 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005967 ASSERT_VK_SUCCESS(err);
5968
5969 VkDescriptorSet descriptorSet;
5970 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08005971 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07005972 alloc_info.descriptorSetCount = 1;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005973 alloc_info.descriptorPool = ds_pool;
5974 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005975 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005976 ASSERT_VK_SUCCESS(err);
5977
5978 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005979 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5980 pipeline_layout_ci.pNext = NULL;
5981 pipeline_layout_ci.setLayoutCount = 1;
5982 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005983
5984 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005985 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005986 ASSERT_VK_SUCCESS(err);
5987
5988 // Create a buffer to update the descriptor with
5989 uint32_t qfi = 0;
5990 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005991 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
5992 buffCI.size = 1024;
5993 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
5994 buffCI.queueFamilyIndexCount = 1;
5995 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005996
5997 VkBuffer dyub;
5998 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
5999 ASSERT_VK_SUCCESS(err);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06006000 // Allocate memory and bind to buffer so we can make it to the appropriate
6001 // error
6002 VkMemoryAllocateInfo mem_alloc = {};
6003 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
6004 mem_alloc.pNext = NULL;
6005 mem_alloc.allocationSize = 1024;
Chris Forbesb6116cc2016-05-08 11:39:59 +12006006 mem_alloc.memoryTypeIndex = 0;
6007
6008 VkMemoryRequirements memReqs;
6009 vkGetBufferMemoryRequirements(m_device->device(), dyub, &memReqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006010 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
Chris Forbesb6116cc2016-05-08 11:39:59 +12006011 if (!pass) {
6012 vkDestroyBuffer(m_device->device(), dyub, NULL);
6013 return;
6014 }
6015
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06006016 VkDeviceMemory mem;
6017 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
6018 ASSERT_VK_SUCCESS(err);
6019 err = vkBindBufferMemory(m_device->device(), dyub, mem, 0);
6020 ASSERT_VK_SUCCESS(err);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006021 // Correctly update descriptor to avoid "NOT_UPDATED" error
6022 VkDescriptorBufferInfo buffInfo = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006023 buffInfo.buffer = dyub;
6024 buffInfo.offset = 0;
6025 buffInfo.range = 1024;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006026
6027 VkWriteDescriptorSet descriptor_write;
6028 memset(&descriptor_write, 0, sizeof(descriptor_write));
6029 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6030 descriptor_write.dstSet = descriptorSet;
6031 descriptor_write.dstBinding = 0;
6032 descriptor_write.descriptorCount = 1;
6033 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6034 descriptor_write.pBufferInfo = &buffInfo;
6035
6036 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6037
Tony Barbour552f6c02016-12-21 14:34:07 -07006038 m_commandBuffer->BeginCommandBuffer();
6039 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006040 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6041 &descriptorSet, 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006042 m_errorMonitor->VerifyFound();
Tobin Ehlisf6585052015-12-17 11:48:42 -07006043 uint32_t pDynOff[2] = {512, 756};
6044 // Now cause error b/c too many dynOffsets in array for # of dyn descriptors
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006045 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6046 "Attempting to bind 1 descriptorSets with 1 dynamic descriptors, but ");
6047 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6048 &descriptorSet, 2, pDynOff);
Chris Forbes7b342802016-04-07 13:20:10 +12006049 m_errorMonitor->VerifyFound();
Tobin Ehlisf6585052015-12-17 11:48:42 -07006050 // Finally cause error due to dynamicOffset being too big
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006051 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " dynamic offset 512 combined with "
6052 "offset 0 and range 1024 that "
6053 "oversteps the buffer size of 1024");
Tobin Ehlisf6585052015-12-17 11:48:42 -07006054 // Create PSO to be used for draw-time errors below
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006055 char const *vsSource = "#version 450\n"
6056 "\n"
6057 "out gl_PerVertex { \n"
6058 " vec4 gl_Position;\n"
6059 "};\n"
6060 "void main(){\n"
6061 " gl_Position = vec4(1);\n"
6062 "}\n";
6063 char const *fsSource = "#version 450\n"
6064 "\n"
6065 "layout(location=0) out vec4 x;\n"
6066 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
6067 "void main(){\n"
6068 " x = vec4(bar.y);\n"
6069 "}\n";
Tobin Ehlisf6585052015-12-17 11:48:42 -07006070 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
6071 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
6072 VkPipelineObj pipe(m_device);
6073 pipe.AddShader(&vs);
6074 pipe.AddShader(&fs);
6075 pipe.AddColorAttachment();
6076 pipe.CreateVKPipeline(pipeline_layout, renderPass());
6077
Rene Lindsayacbf5e62016-12-15 18:47:11 -07006078 VkViewport viewport = {0, 0, 16, 16, 0, 1};
6079 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
6080 VkRect2D scissor = {{0, 0}, {16, 16}};
6081 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
6082
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006083 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07006084 // This update should succeed, but offset size of 512 will overstep buffer
6085 // /w range 1024 & size 1024
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006086 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6087 &descriptorSet, 1, pDynOff);
Tobin Ehlisf6585052015-12-17 11:48:42 -07006088 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006089 m_errorMonitor->VerifyFound();
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006090
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06006091 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tobin Ehlis512098e2016-05-05 09:06:12 -06006092 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06006093
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006094 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06006095 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006096 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6097}
6098
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006099TEST_F(VkLayerTest, DescriptorBufferUpdateNoMemoryBound) {
6100 TEST_DESCRIPTION("Attempt to update a descriptor with a non-sparse buffer "
6101 "that doesn't have memory bound");
6102 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -06006103 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06006104 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Tobin Ehlisfed999f2016-09-21 15:09:45 -06006105 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6106 "vkUpdateDescriptorsSets() failed write update validation for Descriptor Set 0x");
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006107
6108 ASSERT_NO_FATAL_FAILURE(InitState());
6109 ASSERT_NO_FATAL_FAILURE(InitViewport());
6110 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6111
6112 VkDescriptorPoolSize ds_type_count = {};
6113 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6114 ds_type_count.descriptorCount = 1;
6115
6116 VkDescriptorPoolCreateInfo ds_pool_ci = {};
6117 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6118 ds_pool_ci.pNext = NULL;
6119 ds_pool_ci.maxSets = 1;
6120 ds_pool_ci.poolSizeCount = 1;
6121 ds_pool_ci.pPoolSizes = &ds_type_count;
6122
6123 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006124 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006125 ASSERT_VK_SUCCESS(err);
6126
6127 VkDescriptorSetLayoutBinding dsl_binding = {};
6128 dsl_binding.binding = 0;
6129 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6130 dsl_binding.descriptorCount = 1;
6131 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6132 dsl_binding.pImmutableSamplers = NULL;
6133
6134 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
6135 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6136 ds_layout_ci.pNext = NULL;
6137 ds_layout_ci.bindingCount = 1;
6138 ds_layout_ci.pBindings = &dsl_binding;
6139 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006140 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006141 ASSERT_VK_SUCCESS(err);
6142
6143 VkDescriptorSet descriptorSet;
6144 VkDescriptorSetAllocateInfo alloc_info = {};
6145 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
6146 alloc_info.descriptorSetCount = 1;
6147 alloc_info.descriptorPool = ds_pool;
6148 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006149 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006150 ASSERT_VK_SUCCESS(err);
6151
6152 // Create a buffer to update the descriptor with
6153 uint32_t qfi = 0;
6154 VkBufferCreateInfo buffCI = {};
6155 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
6156 buffCI.size = 1024;
6157 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
6158 buffCI.queueFamilyIndexCount = 1;
6159 buffCI.pQueueFamilyIndices = &qfi;
6160
6161 VkBuffer dyub;
6162 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
6163 ASSERT_VK_SUCCESS(err);
6164
6165 // Attempt to update descriptor without binding memory to it
6166 VkDescriptorBufferInfo buffInfo = {};
6167 buffInfo.buffer = dyub;
6168 buffInfo.offset = 0;
6169 buffInfo.range = 1024;
6170
6171 VkWriteDescriptorSet descriptor_write;
6172 memset(&descriptor_write, 0, sizeof(descriptor_write));
6173 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6174 descriptor_write.dstSet = descriptorSet;
6175 descriptor_write.dstBinding = 0;
6176 descriptor_write.descriptorCount = 1;
6177 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6178 descriptor_write.pBufferInfo = &buffInfo;
6179
6180 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6181 m_errorMonitor->VerifyFound();
6182
6183 vkDestroyBuffer(m_device->device(), dyub, NULL);
6184 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6185 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6186}
6187
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006188TEST_F(VkLayerTest, InvalidPushConstants) {
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006189 VkResult err;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006190 ASSERT_NO_FATAL_FAILURE(InitState());
6191 ASSERT_NO_FATAL_FAILURE(InitViewport());
6192 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6193
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006194 VkPipelineLayout pipeline_layout;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006195 VkPushConstantRange pc_range = {};
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006196 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
6197 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6198 pipeline_layout_ci.pushConstantRangeCount = 1;
6199 pipeline_layout_ci.pPushConstantRanges = &pc_range;
6200
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006201 //
6202 // Check for invalid push constant ranges in pipeline layouts.
6203 //
6204 struct PipelineLayoutTestCase {
Karl Schultzc81037d2016-05-12 08:11:23 -06006205 VkPushConstantRange const range;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006206 char const *msg;
6207 };
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006208
Karl Schultzc81037d2016-05-12 08:11:23 -06006209 const uint32_t too_big = m_device->props.limits.maxPushConstantsSize + 0x4;
6210 const std::array<PipelineLayoutTestCase, 10> range_tests = {{
6211 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 0},
6212 "vkCreatePipelineLayout() call has push constants index 0 with "
6213 "size 0."},
6214 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 1},
6215 "vkCreatePipelineLayout() call has push constants index 0 with "
6216 "size 1."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006217 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 1},
Karl Schultzc81037d2016-05-12 08:11:23 -06006218 "vkCreatePipelineLayout() call has push constants index 0 with "
6219 "size 1."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006220 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 0},
Karl Schultzc81037d2016-05-12 08:11:23 -06006221 "vkCreatePipelineLayout() call has push constants index 0 with "
6222 "size 0."},
6223 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
6224 "vkCreatePipelineLayout() call has push constants index 0 with "
6225 "offset 1. Offset must"},
6226 {{VK_SHADER_STAGE_VERTEX_BIT, 0, too_big},
6227 "vkCreatePipelineLayout() call has push constants index 0 "
6228 "with offset "},
6229 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, too_big},
6230 "vkCreatePipelineLayout() call has push constants "
6231 "index 0 with offset "},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006232 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, 4},
Karl Schultzc81037d2016-05-12 08:11:23 -06006233 "vkCreatePipelineLayout() call has push constants index 0 "
6234 "with offset "},
6235 {{VK_SHADER_STAGE_VERTEX_BIT, 0xFFFFFFF0, 0x00000020},
6236 "vkCreatePipelineLayout() call has push "
6237 "constants index 0 with offset "},
6238 {{VK_SHADER_STAGE_VERTEX_BIT, 0x00000020, 0xFFFFFFF0},
6239 "vkCreatePipelineLayout() call has push "
6240 "constants index 0 with offset "},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006241 }};
6242
6243 // Check for invalid offset and size
Karl Schultzc81037d2016-05-12 08:11:23 -06006244 for (const auto &iter : range_tests) {
6245 pc_range = iter.range;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006246 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
6247 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006248 m_errorMonitor->VerifyFound();
6249 if (VK_SUCCESS == err) {
6250 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6251 }
6252 }
6253
6254 // Check for invalid stage flag
6255 pc_range.offset = 0;
6256 pc_range.size = 16;
6257 pc_range.stageFlags = 0;
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006258 m_errorMonitor->SetDesiredFailureMsg(
6259 VK_DEBUG_REPORT_ERROR_BIT_EXT,
6260 "vkCreatePipelineLayout: value of pCreateInfo->pPushConstantRanges[0].stageFlags must not be 0");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006261 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006262 m_errorMonitor->VerifyFound();
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006263 if (VK_SUCCESS == err) {
6264 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6265 }
6266
6267 // Check for overlapping ranges
Karl Schultzc81037d2016-05-12 08:11:23 -06006268 const uint32_t ranges_per_test = 5;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006269 struct OverlappingRangeTestCase {
Karl Schultzc81037d2016-05-12 08:11:23 -06006270 VkPushConstantRange const ranges[ranges_per_test];
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006271 char const *msg;
6272 };
6273
Karl Schultzc81037d2016-05-12 08:11:23 -06006274 const std::array<OverlappingRangeTestCase, 5> overlapping_range_tests = {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006275 {{{{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6276 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6277 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6278 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6279 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006280 "vkCreatePipelineLayout() call has push constants with overlapping ranges:"},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006281 {
6282 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6283 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
6284 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
6285 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
6286 {VK_SHADER_STAGE_VERTEX_BIT, 16, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006287 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 3:[12, 20), 4:[16, 20)",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006288 },
6289 {
6290 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
6291 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
6292 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
6293 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
6294 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006295 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 0:[16, 20), 1:[12, 20)",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006296 },
6297 {
6298 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
6299 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
6300 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
6301 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
6302 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006303 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 0:[16, 20), 3:[12, 20)",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006304 },
6305 {
6306 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
6307 {VK_SHADER_STAGE_VERTEX_BIT, 32, 4},
6308 {VK_SHADER_STAGE_VERTEX_BIT, 4, 96},
6309 {VK_SHADER_STAGE_VERTEX_BIT, 40, 8},
6310 {VK_SHADER_STAGE_VERTEX_BIT, 52, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006311 "vkCreatePipelineLayout() call has push constants with overlapping ranges:",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006312 }}};
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006313
Karl Schultzc81037d2016-05-12 08:11:23 -06006314 for (const auto &iter : overlapping_range_tests) {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006315 pipeline_layout_ci.pPushConstantRanges = iter.ranges;
Karl Schultzc81037d2016-05-12 08:11:23 -06006316 pipeline_layout_ci.pushConstantRangeCount = ranges_per_test;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006317 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, iter.msg);
6318 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006319 m_errorMonitor->VerifyFound();
6320 if (VK_SUCCESS == err) {
6321 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6322 }
6323 }
6324
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006325 //
6326 // CmdPushConstants tests
6327 //
Karl Schultzc81037d2016-05-12 08:11:23 -06006328 const uint8_t dummy_values[100] = {};
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006329
6330 // Check for invalid offset and size and if range is within layout range(s)
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006331 const std::array<PipelineLayoutTestCase, 11> cmd_range_tests = {{
6332 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 0}, "vkCmdPushConstants: parameter size must be greater than 0"},
Karl Schultzc81037d2016-05-12 08:11:23 -06006333 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 1},
Dave Houlton197211a2016-12-23 15:26:29 -07006334 "vkCmdPushConstants() call has push constants index 0 with size 1. "
6335 "Size must be a multiple of 4."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006336 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 1},
Dave Houlton197211a2016-12-23 15:26:29 -07006337 "vkCmdPushConstants() call has push constants index 0 with size 1. "
6338 "Size must be a multiple of 4."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006339 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
Karl Schultzc81037d2016-05-12 08:11:23 -06006340 "vkCmdPushConstants() call has push constants with offset 1. "
6341 "Offset must be a multiple of 4."},
6342 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
6343 "vkCmdPushConstants() call has push constants with offset 1. "
6344 "Offset must be a multiple of 4."},
6345 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 20},
6346 "vkCmdPushConstants() Push constant range [0, 20) with stageFlags = "
6347 "0x1 not within flag-matching ranges in pipeline layout"},
6348 {{VK_SHADER_STAGE_VERTEX_BIT, 60, 8},
6349 "vkCmdPushConstants() Push constant range [60, 68) with stageFlags = "
6350 "0x1 not within flag-matching ranges in pipeline layout"},
6351 {{VK_SHADER_STAGE_VERTEX_BIT, 76, 8},
6352 "vkCmdPushConstants() Push constant range [76, 84) with stageFlags = "
6353 "0x1 not within flag-matching ranges in pipeline layout"},
6354 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 80},
6355 "vkCmdPushConstants() Push constant range [0, 80) with stageFlags = "
6356 "0x1 not within flag-matching ranges in pipeline layout"},
6357 {{VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, 0, 4},
6358 "vkCmdPushConstants() stageFlags = 0x2 do not match the stageFlags in "
6359 "any of the ranges in pipeline layout"},
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006360 {{VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, 0, 16},
Karl Schultzc81037d2016-05-12 08:11:23 -06006361 "vkCmdPushConstants() stageFlags = 0x3 do not match the stageFlags in "
6362 "any of the ranges in pipeline layout"},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006363 }};
6364
Tony Barbour552f6c02016-12-21 14:34:07 -07006365 m_commandBuffer->BeginCommandBuffer();
6366 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006367
6368 // Setup ranges: [0,16) [64,80)
Karl Schultzc81037d2016-05-12 08:11:23 -06006369 const VkPushConstantRange pc_range2[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006370 {VK_SHADER_STAGE_VERTEX_BIT, 64, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 0, 16},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006371 };
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006372 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range2) / sizeof(VkPushConstantRange);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006373 pipeline_layout_ci.pPushConstantRanges = pc_range2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006374 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006375 ASSERT_VK_SUCCESS(err);
Karl Schultzc81037d2016-05-12 08:11:23 -06006376 for (const auto &iter : cmd_range_tests) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006377 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
6378 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.range.stageFlags, iter.range.offset,
Karl Schultzc81037d2016-05-12 08:11:23 -06006379 iter.range.size, dummy_values);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006380 m_errorMonitor->VerifyFound();
6381 }
6382
6383 // Check for invalid stage flag
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006384 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdPushConstants: value of stageFlags must not be 0");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006385 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, 0, 0, 16, dummy_values);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006386 m_errorMonitor->VerifyFound();
Karl Schultzc81037d2016-05-12 08:11:23 -06006387 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006388
Karl Schultzc81037d2016-05-12 08:11:23 -06006389 // overlapping range tests with cmd
6390 const std::array<PipelineLayoutTestCase, 3> cmd_overlap_tests = {{
6391 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 20},
6392 "vkCmdPushConstants() Push constant range [0, 20) with stageFlags = "
6393 "0x1 not within flag-matching ranges in pipeline layout"},
6394 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
6395 "vkCmdPushConstants() Push constant range [16, 20) with stageFlags = "
6396 "0x1 not within flag-matching ranges in pipeline layout"},
6397 {{VK_SHADER_STAGE_VERTEX_BIT, 40, 16},
6398 "vkCmdPushConstants() Push constant range [40, 56) with stageFlags = "
6399 "0x1 not within flag-matching ranges in pipeline layout"},
6400 }};
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006401 // Setup ranges: [0,16), [20,36), [36,44), [44,52), [80,92)
Karl Schultzc81037d2016-05-12 08:11:23 -06006402 const VkPushConstantRange pc_range3[] = {
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006403 {VK_SHADER_STAGE_VERTEX_BIT, 20, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 0, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 44, 8},
6404 {VK_SHADER_STAGE_VERTEX_BIT, 80, 12}, {VK_SHADER_STAGE_VERTEX_BIT, 36, 8},
Karl Schultzc81037d2016-05-12 08:11:23 -06006405 };
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006406 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range3) / sizeof(VkPushConstantRange);
Karl Schultzc81037d2016-05-12 08:11:23 -06006407 pipeline_layout_ci.pPushConstantRanges = pc_range3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006408 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzc81037d2016-05-12 08:11:23 -06006409 ASSERT_VK_SUCCESS(err);
Karl Schultzc81037d2016-05-12 08:11:23 -06006410 for (const auto &iter : cmd_overlap_tests) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006411 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
6412 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.range.stageFlags, iter.range.offset,
Karl Schultzc81037d2016-05-12 08:11:23 -06006413 iter.range.size, dummy_values);
6414 m_errorMonitor->VerifyFound();
6415 }
Karl Schultzc81037d2016-05-12 08:11:23 -06006416 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6417
Tony Barbour552f6c02016-12-21 14:34:07 -07006418 m_commandBuffer->EndRenderPass();
6419 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006420}
6421
Karl Schultz6addd812016-02-02 17:17:23 -07006422TEST_F(VkLayerTest, DescriptorSetCompatibility) {
Tobin Ehlis559c6382015-11-05 09:52:49 -07006423 // Test various desriptorSet errors with bad binding combinations
Karl Schultz6addd812016-02-02 17:17:23 -07006424 VkResult err;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006425
6426 ASSERT_NO_FATAL_FAILURE(InitState());
6427 ASSERT_NO_FATAL_FAILURE(InitViewport());
6428 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6429
Mike Stroyanb8a61002016-06-20 16:00:28 -06006430 const VkFormat tex_format = VK_FORMAT_R8G8B8A8_UNORM;
6431 VkImageTiling tiling;
6432 VkFormatProperties format_properties;
6433 vkGetPhysicalDeviceFormatProperties(gpu(), tex_format, &format_properties);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006434 if (format_properties.linearTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
Mike Stroyanb8a61002016-06-20 16:00:28 -06006435 tiling = VK_IMAGE_TILING_LINEAR;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006436 } else if (format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
Mike Stroyanb8a61002016-06-20 16:00:28 -06006437 tiling = VK_IMAGE_TILING_OPTIMAL;
6438 } else {
6439 printf("Device does not support VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT; "
6440 "skipped.\n");
6441 return;
6442 }
6443
Tobin Ehlis559c6382015-11-05 09:52:49 -07006444 static const uint32_t NUM_DESCRIPTOR_TYPES = 5;
6445 VkDescriptorPoolSize ds_type_count[NUM_DESCRIPTOR_TYPES] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006446 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6447 ds_type_count[0].descriptorCount = 10;
6448 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
6449 ds_type_count[1].descriptorCount = 2;
6450 ds_type_count[2].type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
6451 ds_type_count[2].descriptorCount = 2;
6452 ds_type_count[3].type = VK_DESCRIPTOR_TYPE_SAMPLER;
6453 ds_type_count[3].descriptorCount = 5;
6454 // TODO : LunarG ILO driver currently asserts in desc.c w/ INPUT_ATTACHMENT
6455 // type
6456 // ds_type_count[4].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
6457 ds_type_count[4].type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
6458 ds_type_count[4].descriptorCount = 2;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006459
6460 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006461 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6462 ds_pool_ci.pNext = NULL;
6463 ds_pool_ci.maxSets = 5;
6464 ds_pool_ci.poolSizeCount = NUM_DESCRIPTOR_TYPES;
6465 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006466
6467 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006468 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006469 ASSERT_VK_SUCCESS(err);
6470
6471 static const uint32_t MAX_DS_TYPES_IN_LAYOUT = 2;
6472 VkDescriptorSetLayoutBinding dsl_binding[MAX_DS_TYPES_IN_LAYOUT] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006473 dsl_binding[0].binding = 0;
6474 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6475 dsl_binding[0].descriptorCount = 5;
6476 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
6477 dsl_binding[0].pImmutableSamplers = NULL;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006478
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006479 // Create layout identical to set0 layout but w/ different stageFlags
6480 VkDescriptorSetLayoutBinding dsl_fs_stage_only = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006481 dsl_fs_stage_only.binding = 0;
6482 dsl_fs_stage_only.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6483 dsl_fs_stage_only.descriptorCount = 5;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006484 dsl_fs_stage_only.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT; // Different stageFlags to cause error at
6485 // bind time
Karl Schultz6addd812016-02-02 17:17:23 -07006486 dsl_fs_stage_only.pImmutableSamplers = NULL;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006487 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006488 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6489 ds_layout_ci.pNext = NULL;
6490 ds_layout_ci.bindingCount = 1;
6491 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006492 static const uint32_t NUM_LAYOUTS = 4;
6493 VkDescriptorSetLayout ds_layout[NUM_LAYOUTS] = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006494 VkDescriptorSetLayout ds_layout_fs_only = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006495 // Create 4 unique layouts for full pipelineLayout, and 1 special fs-only
6496 // layout for error case
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006497 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[0]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006498 ASSERT_VK_SUCCESS(err);
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07006499 ds_layout_ci.pBindings = &dsl_fs_stage_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006500 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006501 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006502 dsl_binding[0].binding = 0;
6503 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006504 dsl_binding[0].descriptorCount = 2;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07006505 dsl_binding[1].binding = 1;
6506 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
6507 dsl_binding[1].descriptorCount = 2;
6508 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
6509 dsl_binding[1].pImmutableSamplers = NULL;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07006510 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006511 ds_layout_ci.bindingCount = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006512 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[1]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006513 ASSERT_VK_SUCCESS(err);
6514 dsl_binding[0].binding = 0;
6515 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006516 dsl_binding[0].descriptorCount = 5;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006517 ds_layout_ci.bindingCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006518 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[2]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006519 ASSERT_VK_SUCCESS(err);
6520 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006521 dsl_binding[0].descriptorCount = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006522 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[3]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006523 ASSERT_VK_SUCCESS(err);
6524
6525 static const uint32_t NUM_SETS = 4;
6526 VkDescriptorSet descriptorSet[NUM_SETS] = {};
6527 VkDescriptorSetAllocateInfo alloc_info = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006528 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006529 alloc_info.descriptorSetCount = NUM_LAYOUTS;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006530 alloc_info.descriptorPool = ds_pool;
6531 alloc_info.pSetLayouts = ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006532 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptorSet);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006533 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006534 VkDescriptorSet ds0_fs_only = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07006535 alloc_info.descriptorSetCount = 1;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006536 alloc_info.pSetLayouts = &ds_layout_fs_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006537 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &ds0_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006538 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006539
6540 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006541 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6542 pipeline_layout_ci.pNext = NULL;
6543 pipeline_layout_ci.setLayoutCount = NUM_LAYOUTS;
6544 pipeline_layout_ci.pSetLayouts = ds_layout;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006545
6546 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006547 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006548 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006549 // Create pipelineLayout with only one setLayout
6550 pipeline_layout_ci.setLayoutCount = 1;
6551 VkPipelineLayout single_pipe_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006552 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &single_pipe_layout);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006553 ASSERT_VK_SUCCESS(err);
6554 // Create pipelineLayout with 2 descriptor setLayout at index 0
6555 pipeline_layout_ci.pSetLayouts = &ds_layout[3];
6556 VkPipelineLayout pipe_layout_one_desc;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006557 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_one_desc);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006558 ASSERT_VK_SUCCESS(err);
6559 // Create pipelineLayout with 5 SAMPLER descriptor setLayout at index 0
6560 pipeline_layout_ci.pSetLayouts = &ds_layout[2];
6561 VkPipelineLayout pipe_layout_five_samp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006562 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_five_samp);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006563 ASSERT_VK_SUCCESS(err);
6564 // Create pipelineLayout with UB type, but stageFlags for FS only
6565 pipeline_layout_ci.pSetLayouts = &ds_layout_fs_only;
6566 VkPipelineLayout pipe_layout_fs_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006567 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006568 ASSERT_VK_SUCCESS(err);
6569 // Create pipelineLayout w/ incompatible set0 layout, but set1 is fine
6570 VkDescriptorSetLayout pl_bad_s0[2] = {};
6571 pl_bad_s0[0] = ds_layout_fs_only;
6572 pl_bad_s0[1] = ds_layout[1];
6573 pipeline_layout_ci.setLayoutCount = 2;
6574 pipeline_layout_ci.pSetLayouts = pl_bad_s0;
6575 VkPipelineLayout pipe_layout_bad_set0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006576 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_bad_set0);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006577 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006578
6579 // Create a buffer to update the descriptor with
6580 uint32_t qfi = 0;
6581 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006582 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
6583 buffCI.size = 1024;
6584 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
6585 buffCI.queueFamilyIndexCount = 1;
6586 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006587
6588 VkBuffer dyub;
6589 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
6590 ASSERT_VK_SUCCESS(err);
6591 // Correctly update descriptor to avoid "NOT_UPDATED" error
6592 static const uint32_t NUM_BUFFS = 5;
6593 VkDescriptorBufferInfo buffInfo[NUM_BUFFS] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006594 for (uint32_t i = 0; i < NUM_BUFFS; ++i) {
Tobin Ehlis559c6382015-11-05 09:52:49 -07006595 buffInfo[i].buffer = dyub;
6596 buffInfo[i].offset = 0;
6597 buffInfo[i].range = 1024;
6598 }
Karl Schultz6addd812016-02-02 17:17:23 -07006599 VkImage image;
Karl Schultz6addd812016-02-02 17:17:23 -07006600 const int32_t tex_width = 32;
6601 const int32_t tex_height = 32;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006602 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006603 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
6604 image_create_info.pNext = NULL;
6605 image_create_info.imageType = VK_IMAGE_TYPE_2D;
6606 image_create_info.format = tex_format;
6607 image_create_info.extent.width = tex_width;
6608 image_create_info.extent.height = tex_height;
6609 image_create_info.extent.depth = 1;
6610 image_create_info.mipLevels = 1;
6611 image_create_info.arrayLayers = 1;
6612 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyanb8a61002016-06-20 16:00:28 -06006613 image_create_info.tiling = tiling;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006614 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_STORAGE_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -07006615 image_create_info.flags = 0;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006616 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
6617 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006618
Karl Schultz6addd812016-02-02 17:17:23 -07006619 VkMemoryRequirements memReqs;
6620 VkDeviceMemory imageMem;
6621 bool pass;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07006622 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006623 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
6624 memAlloc.pNext = NULL;
6625 memAlloc.allocationSize = 0;
6626 memAlloc.memoryTypeIndex = 0;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07006627 vkGetImageMemoryRequirements(m_device->device(), image, &memReqs);
6628 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006629 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07006630 ASSERT_TRUE(pass);
6631 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &imageMem);
6632 ASSERT_VK_SUCCESS(err);
6633 err = vkBindImageMemory(m_device->device(), image, imageMem, 0);
6634 ASSERT_VK_SUCCESS(err);
6635
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006636 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006637 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
6638 image_view_create_info.image = image;
6639 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
6640 image_view_create_info.format = tex_format;
6641 image_view_create_info.subresourceRange.layerCount = 1;
6642 image_view_create_info.subresourceRange.baseMipLevel = 0;
6643 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006644 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006645
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006646 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006647 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006648 ASSERT_VK_SUCCESS(err);
Tobin Ehlis991d45a2016-01-06 08:48:41 -07006649 VkDescriptorImageInfo imageInfo[4] = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006650 imageInfo[0].imageView = view;
6651 imageInfo[0].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
6652 imageInfo[1].imageView = view;
6653 imageInfo[1].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
Tobin Ehlis991d45a2016-01-06 08:48:41 -07006654 imageInfo[2].imageView = view;
Tobin Ehlisa1fccbc2016-10-10 14:54:43 -06006655 imageInfo[2].imageLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis991d45a2016-01-06 08:48:41 -07006656 imageInfo[3].imageView = view;
Tobin Ehlisa1fccbc2016-10-10 14:54:43 -06006657 imageInfo[3].imageLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006658
6659 static const uint32_t NUM_SET_UPDATES = 3;
6660 VkWriteDescriptorSet descriptor_write[NUM_SET_UPDATES] = {};
6661 descriptor_write[0].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6662 descriptor_write[0].dstSet = descriptorSet[0];
6663 descriptor_write[0].dstBinding = 0;
6664 descriptor_write[0].descriptorCount = 5;
6665 descriptor_write[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6666 descriptor_write[0].pBufferInfo = buffInfo;
6667 descriptor_write[1].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6668 descriptor_write[1].dstSet = descriptorSet[1];
6669 descriptor_write[1].dstBinding = 0;
6670 descriptor_write[1].descriptorCount = 2;
6671 descriptor_write[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
6672 descriptor_write[1].pImageInfo = imageInfo;
6673 descriptor_write[2].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6674 descriptor_write[2].dstSet = descriptorSet[1];
6675 descriptor_write[2].dstBinding = 1;
6676 descriptor_write[2].descriptorCount = 2;
6677 descriptor_write[2].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
Tobin Ehlis991d45a2016-01-06 08:48:41 -07006678 descriptor_write[2].pImageInfo = &imageInfo[2];
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006679
6680 vkUpdateDescriptorSets(m_device->device(), 3, descriptor_write, 0, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006681
Tobin Ehlis88452832015-12-03 09:40:56 -07006682 // Create PSO to be used for draw-time errors below
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006683 char const *vsSource = "#version 450\n"
6684 "\n"
6685 "out gl_PerVertex {\n"
6686 " vec4 gl_Position;\n"
6687 "};\n"
6688 "void main(){\n"
6689 " gl_Position = vec4(1);\n"
6690 "}\n";
6691 char const *fsSource = "#version 450\n"
6692 "\n"
6693 "layout(location=0) out vec4 x;\n"
6694 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
6695 "void main(){\n"
6696 " x = vec4(bar.y);\n"
6697 "}\n";
Tobin Ehlis88452832015-12-03 09:40:56 -07006698 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
6699 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006700 VkPipelineObj pipe(m_device);
6701 pipe.AddShader(&vs);
6702 pipe.AddShader(&fs);
Tobin Ehlis88452832015-12-03 09:40:56 -07006703 pipe.AddColorAttachment();
6704 pipe.CreateVKPipeline(pipe_layout_fs_only, renderPass());
Tobin Ehlis559c6382015-11-05 09:52:49 -07006705
Tony Barbour552f6c02016-12-21 14:34:07 -07006706 m_commandBuffer->BeginCommandBuffer();
6707 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis88452832015-12-03 09:40:56 -07006708
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006709 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07006710 // NOTE : I believe LunarG ilo driver has bug (LX#189) that requires binding
6711 // of PSO
6712 // here before binding DSs. Otherwise we assert in cmd_copy_dset_data() of
6713 // cmd_pipeline.c
6714 // due to the fact that cmd_alloc_dset_data() has not been called in
6715 // cmd_bind_graphics_pipeline()
6716 // TODO : Want to cause various binding incompatibility issues here to test
6717 // DrawState
Tobin Ehlis559c6382015-11-05 09:52:49 -07006718 // First cause various verify_layout_compatibility() fails
6719 // Second disturb early and late sets and verify INFO msgs
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006720 // verify_set_layout_compatibility fail cases:
6721 // 1. invalid VkPipelineLayout (layout) passed into vkCmdBindDescriptorSets
Karl Schultzf78bcdd2016-11-30 12:36:01 -07006722 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00981);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006723 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS,
6724 (VkPipelineLayout)((size_t)0xbaadb1be), 0, 1, &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006725 m_errorMonitor->VerifyFound();
6726
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006727 // 2. layoutIndex exceeds # of layouts in layout
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006728 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " attempting to bind set to index 1");
6729 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, single_pipe_layout, 0, 2,
6730 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006731 m_errorMonitor->VerifyFound();
6732
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006733 vkDestroyPipelineLayout(m_device->device(), single_pipe_layout, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07006734 // 3. Pipeline setLayout[0] has 2 descriptors, but set being bound has 5
6735 // descriptors
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006736 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has 2 descriptors, but DescriptorSetLayout ");
6737 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_one_desc, 0, 1,
6738 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006739 m_errorMonitor->VerifyFound();
6740
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006741 vkDestroyPipelineLayout(m_device->device(), pipe_layout_one_desc, NULL);
6742 // 4. same # of descriptors but mismatch in type
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006743 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is type 'VK_DESCRIPTOR_TYPE_SAMPLER' but binding ");
6744 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_five_samp, 0, 1,
6745 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006746 m_errorMonitor->VerifyFound();
6747
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006748 vkDestroyPipelineLayout(m_device->device(), pipe_layout_five_samp, NULL);
6749 // 5. same # of descriptors but mismatch in stageFlags
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006750 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6751 " has stageFlags 16 but binding 0 for DescriptorSetLayout ");
6752 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_fs_only, 0, 1,
6753 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006754 m_errorMonitor->VerifyFound();
6755
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006756 // Cause INFO messages due to disturbing previously bound Sets
6757 // First bind sets 0 & 1
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006758 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
6759 &descriptorSet[0], 0, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006760 // 1. Disturb bound set0 by re-binding set1 w/ updated pipelineLayout
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006761 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, " previously bound as set #0 was disturbed ");
6762 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_bad_set0, 1, 1,
6763 &descriptorSet[1], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006764 m_errorMonitor->VerifyFound();
6765
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006766 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
6767 &descriptorSet[0], 0, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006768 // 2. Disturb set after last bound set
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006769 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, " newly bound as set #0 so set #1 and "
6770 "any subsequent sets were disturbed ");
6771 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_fs_only, 0, 1,
6772 &ds0_fs_only, 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006773 m_errorMonitor->VerifyFound();
6774
Tobin Ehlis10fad692016-07-07 12:00:36 -06006775 // Now that we're done actively using the pipelineLayout that gfx pipeline
6776 // was created with, we should be able to delete it. Do that now to verify
6777 // that validation obeys pipelineLayout lifetime
6778 vkDestroyPipelineLayout(m_device->device(), pipe_layout_fs_only, NULL);
6779
Tobin Ehlis88452832015-12-03 09:40:56 -07006780 // Cause draw-time errors due to PSO incompatibilities
Karl Schultz6addd812016-02-02 17:17:23 -07006781 // 1. Error due to not binding required set (we actually use same code as
6782 // above to disturb set0)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006783 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
6784 &descriptorSet[0], 0, NULL);
6785 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_bad_set0, 1, 1,
6786 &descriptorSet[1], 0, NULL);
6787 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 -07006788 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006789 m_errorMonitor->VerifyFound();
6790
Tobin Ehlis991d45a2016-01-06 08:48:41 -07006791 vkDestroyPipelineLayout(m_device->device(), pipe_layout_bad_set0, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07006792 // 2. Error due to bound set not being compatible with PSO's
6793 // VkPipelineLayout (diff stageFlags in this case)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006794 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
6795 &descriptorSet[0], 0, NULL);
6796 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " bound as set #0 is not compatible with ");
Tobin Ehlis88452832015-12-03 09:40:56 -07006797 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006798 m_errorMonitor->VerifyFound();
6799
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006800 // Remaining clean-up
Karl Schultz6addd812016-02-02 17:17:23 -07006801 for (uint32_t i = 0; i < NUM_LAYOUTS; ++i) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006802 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout[i], NULL);
6803 }
6804 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_fs_only, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006805 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006806 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6807 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06006808 vkFreeMemory(m_device->device(), imageMem, NULL);
6809 vkDestroyImage(m_device->device(), image, NULL);
6810 vkDestroyImageView(m_device->device(), view, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006811}
Tobin Ehlis559c6382015-11-05 09:52:49 -07006812
Karl Schultz6addd812016-02-02 17:17:23 -07006813TEST_F(VkLayerTest, NoBeginCommandBuffer) {
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006814
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006815 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6816 "You must call vkBeginCommandBuffer() before this call to ");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006817
6818 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006819 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006820 // Call EndCommandBuffer() w/o calling BeginCommandBuffer()
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006821 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006822
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006823 m_errorMonitor->VerifyFound();
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006824}
6825
Karl Schultz6addd812016-02-02 17:17:23 -07006826TEST_F(VkLayerTest, SecondaryCommandBufferNullRenderpass) {
6827 VkResult err;
6828 VkCommandBuffer draw_cmd;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006829
Karl Schultzf78bcdd2016-11-30 12:36:01 -07006830 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00110);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006831
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006832 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006833
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006834 VkCommandBufferAllocateInfo cmd = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006835 cmd.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06006836 cmd.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006837 cmd.commandPool = m_commandPool;
6838 cmd.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006839 cmd.commandBufferCount = 1;
Cody Northropb4569702015-08-04 17:35:57 -06006840
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006841 err = vkAllocateCommandBuffers(m_device->device(), &cmd, &draw_cmd);
Mike Stroyand1c84a52015-08-18 14:40:24 -06006842 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006843
6844 // Force the failure by not setting the Renderpass and Framebuffer fields
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006845 VkCommandBufferBeginInfo cmd_buf_info = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07006846 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006847 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06006848 cmd_buf_info.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006849 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 -07006850 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006851
6852 // The error should be caught by validation of the BeginCommandBuffer call
6853 vkBeginCommandBuffer(draw_cmd, &cmd_buf_info);
6854
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006855 m_errorMonitor->VerifyFound();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006856 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &draw_cmd);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006857}
6858
Karl Schultz6addd812016-02-02 17:17:23 -07006859TEST_F(VkLayerTest, CommandBufferResetErrors) {
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006860 // Cause error due to Begin while recording CB
6861 // Then cause 2 errors for attempting to reset CB w/o having
6862 // VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT set for the pool from
6863 // which CBs were allocated. Note that this bit is off by default.
Mike Weiblencce7ec72016-10-17 19:33:05 -06006864 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot call Begin on command buffer");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006865
6866 ASSERT_NO_FATAL_FAILURE(InitState());
6867
6868 // Calls AllocateCommandBuffers
6869 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
6870
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07006871 // Force the failure by setting the Renderpass and Framebuffer fields with (fake) data
Jon Ashburnf19916e2016-01-11 13:12:43 -07006872 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07006873 cmd_buf_hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
6874 VkCommandBufferBeginInfo cmd_buf_info = {};
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006875 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
6876 cmd_buf_info.pNext = NULL;
6877 cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006878 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006879
6880 // Begin CB to transition to recording state
6881 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
6882 // Can't re-begin. This should trigger error
6883 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006884 m_errorMonitor->VerifyFound();
6885
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07006886 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00093);
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006887 VkCommandBufferResetFlags flags = 0; // Don't care about flags for this test
6888 // Reset attempt will trigger error due to incorrect CommandPool state
6889 vkResetCommandBuffer(commandBuffer.GetBufferHandle(), flags);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006890 m_errorMonitor->VerifyFound();
6891
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07006892 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00105);
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006893 // Transition CB to RECORDED state
6894 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
6895 // Now attempting to Begin will implicitly reset, which triggers error
6896 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006897 m_errorMonitor->VerifyFound();
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006898}
6899
Karl Schultz6addd812016-02-02 17:17:23 -07006900TEST_F(VkLayerTest, InvalidPipelineCreateState) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006901 // Attempt to Create Gfx Pipeline w/o a VS
Karl Schultz6addd812016-02-02 17:17:23 -07006902 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006903
Mike Weiblencce7ec72016-10-17 19:33:05 -06006904 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Pipeline CreateInfo State: Vertex Shader required");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006905
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006906 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06006907 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinski209b5292015-09-17 09:44:05 -06006908
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006909 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006910 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6911 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06006912
6913 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006914 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6915 ds_pool_ci.pNext = NULL;
6916 ds_pool_ci.maxSets = 1;
6917 ds_pool_ci.poolSizeCount = 1;
6918 ds_pool_ci.pPoolSizes = &ds_type_count;
Mark Lobodzinski209b5292015-09-17 09:44:05 -06006919
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006920 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006921 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006922 ASSERT_VK_SUCCESS(err);
6923
Tony Barboureb254902015-07-15 12:50:33 -06006924 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006925 dsl_binding.binding = 0;
6926 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6927 dsl_binding.descriptorCount = 1;
6928 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6929 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006930
Tony Barboureb254902015-07-15 12:50:33 -06006931 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006932 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6933 ds_layout_ci.pNext = NULL;
6934 ds_layout_ci.bindingCount = 1;
6935 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06006936
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006937 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006938 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006939 ASSERT_VK_SUCCESS(err);
6940
6941 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006942 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006943 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006944 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06006945 alloc_info.descriptorPool = ds_pool;
6946 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006947 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006948 ASSERT_VK_SUCCESS(err);
6949
Tony Barboureb254902015-07-15 12:50:33 -06006950 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006951 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6952 pipeline_layout_ci.setLayoutCount = 1;
6953 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006954
6955 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006956 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006957 ASSERT_VK_SUCCESS(err);
6958
Tobin Ehlise68360f2015-10-01 11:15:13 -06006959 VkViewport vp = {}; // Just need dummy vp to point to
Karl Schultz6addd812016-02-02 17:17:23 -07006960 VkRect2D sc = {}; // dummy scissor to point to
Tobin Ehlise68360f2015-10-01 11:15:13 -06006961
6962 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006963 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
6964 vp_state_ci.scissorCount = 1;
6965 vp_state_ci.pScissors = &sc;
6966 vp_state_ci.viewportCount = 1;
6967 vp_state_ci.pViewports = &vp;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006968
Karl Schultzdfdb8d42016-03-08 10:30:21 -07006969 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
6970 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
6971 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
6972 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
6973 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
6974 rs_state_ci.depthClampEnable = VK_FALSE;
6975 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
6976 rs_state_ci.depthBiasEnable = VK_FALSE;
6977
Tony Barboureb254902015-07-15 12:50:33 -06006978 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006979 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
6980 gp_ci.pViewportState = &vp_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07006981 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07006982 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
6983 gp_ci.layout = pipeline_layout;
6984 gp_ci.renderPass = renderPass();
Tony Barboureb254902015-07-15 12:50:33 -06006985
6986 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006987 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
6988 pc_ci.initialDataSize = 0;
6989 pc_ci.pInitialData = 0;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006990
6991 VkPipeline pipeline;
Jon Ashburnc669cc62015-07-09 15:02:25 -06006992 VkPipelineCache pipelineCache;
6993
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006994 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Jon Ashburnc669cc62015-07-09 15:02:25 -06006995 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006996 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006997
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006998 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06006999
Chia-I Wuf7458c52015-10-26 21:10:41 +08007000 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7001 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7002 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7003 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007004}
Tobin Ehlis912df022015-09-17 08:46:18 -06007005/*// TODO : This test should be good, but needs Tess support in compiler to run
7006TEST_F(VkLayerTest, InvalidPatchControlPoints)
7007{
7008 // Attempt to Create Gfx Pipeline w/o a VS
Tobin Ehlis912df022015-09-17 08:46:18 -06007009 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007010
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07007011 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07007012 "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH
7013primitive ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007014
Tobin Ehlis912df022015-09-17 08:46:18 -06007015 ASSERT_NO_FATAL_FAILURE(InitState());
7016 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis912df022015-09-17 08:46:18 -06007017
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007018 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlis912df022015-09-17 08:46:18 -06007019 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007020 ds_type_count.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06007021
7022 VkDescriptorPoolCreateInfo ds_pool_ci = {};
7023 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7024 ds_pool_ci.pNext = NULL;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007025 ds_pool_ci.poolSizeCount = 1;
7026 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis912df022015-09-17 08:46:18 -06007027
7028 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07007029 err = vkCreateDescriptorPool(m_device->device(),
7030VK_DESCRIPTOR_POOL_USAGE_NON_FREE, 1, &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis912df022015-09-17 08:46:18 -06007031 ASSERT_VK_SUCCESS(err);
7032
7033 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08007034 dsl_binding.binding = 0;
Tobin Ehlis912df022015-09-17 08:46:18 -06007035 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08007036 dsl_binding.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06007037 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7038 dsl_binding.pImmutableSamplers = NULL;
7039
7040 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007041 ds_layout_ci.sType =
7042VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06007043 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007044 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07007045 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis912df022015-09-17 08:46:18 -06007046
7047 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007048 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
7049&ds_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06007050 ASSERT_VK_SUCCESS(err);
7051
7052 VkDescriptorSet descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -07007053 err = vkAllocateDescriptorSets(m_device->device(), ds_pool,
7054VK_DESCRIPTOR_SET_USAGE_NON_FREE, 1, &ds_layout, &descriptorSet);
Tobin Ehlis912df022015-09-17 08:46:18 -06007055 ASSERT_VK_SUCCESS(err);
7056
7057 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007058 pipeline_layout_ci.sType =
7059VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06007060 pipeline_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007061 pipeline_layout_ci.setLayoutCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06007062 pipeline_layout_ci.pSetLayouts = &ds_layout;
7063
7064 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007065 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
7066&pipeline_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06007067 ASSERT_VK_SUCCESS(err);
7068
7069 VkPipelineShaderStageCreateInfo shaderStages[3];
7070 memset(&shaderStages, 0, 3 * sizeof(VkPipelineShaderStageCreateInfo));
7071
Karl Schultz6addd812016-02-02 17:17:23 -07007072 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT,
7073this);
Tobin Ehlis912df022015-09-17 08:46:18 -06007074 // Just using VS txt for Tess shaders as we don't care about functionality
Karl Schultz6addd812016-02-02 17:17:23 -07007075 VkShaderObj
7076tc(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT,
7077this);
7078 VkShaderObj
7079te(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT,
7080this);
Tobin Ehlis912df022015-09-17 08:46:18 -06007081
Karl Schultz6addd812016-02-02 17:17:23 -07007082 shaderStages[0].sType =
7083VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06007084 shaderStages[0].stage = VK_SHADER_STAGE_VERTEX_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06007085 shaderStages[0].shader = vs.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07007086 shaderStages[1].sType =
7087VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06007088 shaderStages[1].stage = VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06007089 shaderStages[1].shader = tc.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07007090 shaderStages[2].sType =
7091VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06007092 shaderStages[2].stage = VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06007093 shaderStages[2].shader = te.handle();
7094
7095 VkPipelineInputAssemblyStateCreateInfo iaCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007096 iaCI.sType =
7097VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
Chia-I Wu515eb8f2015-10-31 00:31:16 +08007098 iaCI.topology = VK_PRIMITIVE_TOPOLOGY_PATCH_LIST;
Tobin Ehlis912df022015-09-17 08:46:18 -06007099
7100 VkPipelineTessellationStateCreateInfo tsCI = {};
7101 tsCI.sType = VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO;
7102 tsCI.patchControlPoints = 0; // This will cause an error
7103
7104 VkGraphicsPipelineCreateInfo gp_ci = {};
7105 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7106 gp_ci.pNext = NULL;
7107 gp_ci.stageCount = 3;
7108 gp_ci.pStages = shaderStages;
7109 gp_ci.pVertexInputState = NULL;
7110 gp_ci.pInputAssemblyState = &iaCI;
7111 gp_ci.pTessellationState = &tsCI;
7112 gp_ci.pViewportState = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007113 gp_ci.pRasterizationState = NULL;
Tobin Ehlis912df022015-09-17 08:46:18 -06007114 gp_ci.pMultisampleState = NULL;
7115 gp_ci.pDepthStencilState = NULL;
7116 gp_ci.pColorBlendState = NULL;
7117 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7118 gp_ci.layout = pipeline_layout;
7119 gp_ci.renderPass = renderPass();
7120
7121 VkPipelineCacheCreateInfo pc_ci = {};
7122 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
7123 pc_ci.pNext = NULL;
7124 pc_ci.initialSize = 0;
7125 pc_ci.initialData = 0;
7126 pc_ci.maxSize = 0;
7127
7128 VkPipeline pipeline;
7129 VkPipelineCache pipelineCache;
7130
Karl Schultz6addd812016-02-02 17:17:23 -07007131 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL,
7132&pipelineCache);
Tobin Ehlis912df022015-09-17 08:46:18 -06007133 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07007134 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
7135&gp_ci, NULL, &pipeline);
Tobin Ehlis912df022015-09-17 08:46:18 -06007136
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007137 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06007138
Chia-I Wuf7458c52015-10-26 21:10:41 +08007139 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7140 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7141 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7142 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis912df022015-09-17 08:46:18 -06007143}
7144*/
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007145
Mark Lobodzinski510aa5c2016-12-19 07:59:10 -07007146TEST_F(VkLayerTest, PSOViewportScissorCountTests) {
Karl Schultz6addd812016-02-02 17:17:23 -07007147 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007148
Mark Lobodzinski510aa5c2016-12-19 07:59:10 -07007149 TEST_DESCRIPTION("Test various cases of viewport and scissor count validation");
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007150
Tobin Ehlise68360f2015-10-01 11:15:13 -06007151 ASSERT_NO_FATAL_FAILURE(InitState());
7152 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06007153
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007154 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007155 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7156 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007157
7158 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007159 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7160 ds_pool_ci.maxSets = 1;
7161 ds_pool_ci.poolSizeCount = 1;
7162 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007163
7164 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007165 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007166 ASSERT_VK_SUCCESS(err);
7167
7168 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007169 dsl_binding.binding = 0;
7170 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7171 dsl_binding.descriptorCount = 1;
7172 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007173
7174 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007175 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7176 ds_layout_ci.bindingCount = 1;
7177 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007178
7179 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007180 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007181 ASSERT_VK_SUCCESS(err);
7182
7183 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007184 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007185 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007186 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007187 alloc_info.descriptorPool = ds_pool;
7188 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007189 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007190 ASSERT_VK_SUCCESS(err);
7191
7192 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007193 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7194 pipeline_layout_ci.setLayoutCount = 1;
7195 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007196
7197 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007198 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007199 ASSERT_VK_SUCCESS(err);
7200
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007201 VkViewport vp = {};
Tobin Ehlise68360f2015-10-01 11:15:13 -06007202 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007203 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
Mark Lobodzinski510aa5c2016-12-19 07:59:10 -07007204 vp_state_ci.scissorCount = 1;
Mark Lobodzinskif0eab4a2016-12-19 08:43:21 -07007205 vp_state_ci.viewportCount = 1;
Karl Schultz6addd812016-02-02 17:17:23 -07007206 vp_state_ci.pViewports = &vp;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007207
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007208 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
7209 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7210 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
7211 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
7212 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
7213 rs_state_ci.depthClampEnable = VK_FALSE;
7214 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
7215 rs_state_ci.depthBiasEnable = VK_FALSE;
7216
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007217 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7218 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7219 vi_ci.pNext = nullptr;
7220 vi_ci.vertexBindingDescriptionCount = 0;
7221 vi_ci.pVertexBindingDescriptions = nullptr;
7222 vi_ci.vertexAttributeDescriptionCount = 0;
7223 vi_ci.pVertexAttributeDescriptions = nullptr;
7224
7225 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7226 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7227 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7228
7229 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
7230 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
7231 pipe_ms_state_ci.pNext = NULL;
7232 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
7233 pipe_ms_state_ci.sampleShadingEnable = 0;
7234 pipe_ms_state_ci.minSampleShading = 1.0;
7235 pipe_ms_state_ci.pSampleMask = NULL;
7236
Cody Northropeb3a6c12015-10-05 14:44:45 -06007237 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07007238 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06007239
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007240 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinskid04c7862016-12-16 13:17:49 -07007241 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chia-I Wu28e06912015-10-31 00:31:16 +08007242 shaderStages[0] = vs.GetStageCreateInfo();
7243 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007244
7245 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007246 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7247 gp_ci.stageCount = 2;
7248 gp_ci.pStages = shaderStages;
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007249 gp_ci.pVertexInputState = &vi_ci;
7250 gp_ci.pInputAssemblyState = &ia_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007251 gp_ci.pViewportState = &vp_state_ci;
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007252 gp_ci.pMultisampleState = &pipe_ms_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007253 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007254 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7255 gp_ci.layout = pipeline_layout;
7256 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007257
7258 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007259 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007260
7261 VkPipeline pipeline;
7262 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007263 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007264 ASSERT_VK_SUCCESS(err);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007265
Mark Lobodzinskif0eab4a2016-12-19 08:43:21 -07007266 if (!m_device->phy().features().multiViewport) {
7267 printf("MultiViewport feature is disabled -- skipping enabled-state checks.\n");
7268
7269 // Check case where multiViewport is disabled and viewport count is not 1
7270 // We check scissor/viewport simultaneously since separating them would trigger the mismatch error, 1434.
7271 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01430);
7272 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01431);
7273 vp_state_ci.scissorCount = 0;
7274 vp_state_ci.viewportCount = 0;
7275 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
7276 m_errorMonitor->VerifyFound();
7277 } else {
7278 if (m_device->props.limits.maxViewports == 1) {
7279 printf("Device limit maxViewports is 1, skipping tests that require higher limits.\n");
7280 } else {
7281 printf("MultiViewport feature is enabled -- skipping disabled-state checks.\n");
7282
7283 // Check is that viewportcount and scissorcount match
7284 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01434);
7285 vp_state_ci.scissorCount = 1;
7286 vp_state_ci.viewportCount = m_device->props.limits.maxViewports;
7287 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
7288 m_errorMonitor->VerifyFound();
7289
7290
7291 // Check case where multiViewport is enabled and viewport count is greater than max
7292 // We check scissor/viewport simultaneously since separating them would trigger the mismatch error, 1434.
7293 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01432);
7294 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01433);
7295 vp_state_ci.scissorCount = m_device->props.limits.maxViewports + 1;
7296 vp_state_ci.viewportCount = m_device->props.limits.maxViewports + 1;
7297 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
7298 m_errorMonitor->VerifyFound();
7299 }
7300 }
Tobin Ehlise68360f2015-10-01 11:15:13 -06007301
Chia-I Wuf7458c52015-10-26 21:10:41 +08007302 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7303 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7304 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7305 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007306}
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007307
7308// 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
7309// set dynamically.
Karl Schultz6addd812016-02-02 17:17:23 -07007310TEST_F(VkLayerTest, PSOViewportStateNotSet) {
Karl Schultz6addd812016-02-02 17:17:23 -07007311 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007312
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007313 TEST_DESCRIPTION("Create a graphics pipeline with rasterization enabled but no viewport state.");
7314
Mark Lobodzinskid04c7862016-12-16 13:17:49 -07007315 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02113);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007316
Tobin Ehlise68360f2015-10-01 11:15:13 -06007317 ASSERT_NO_FATAL_FAILURE(InitState());
7318 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06007319
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007320 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007321 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7322 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007323
7324 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007325 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7326 ds_pool_ci.maxSets = 1;
7327 ds_pool_ci.poolSizeCount = 1;
7328 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007329
7330 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007331 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007332 ASSERT_VK_SUCCESS(err);
7333
7334 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007335 dsl_binding.binding = 0;
7336 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7337 dsl_binding.descriptorCount = 1;
7338 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007339
7340 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007341 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7342 ds_layout_ci.bindingCount = 1;
7343 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007344
7345 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007346 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007347 ASSERT_VK_SUCCESS(err);
7348
7349 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007350 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007351 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007352 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007353 alloc_info.descriptorPool = ds_pool;
7354 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007355 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007356 ASSERT_VK_SUCCESS(err);
7357
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007358 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7359 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7360 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7361
7362 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7363 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7364 vi_ci.pNext = nullptr;
7365 vi_ci.vertexBindingDescriptionCount = 0;
7366 vi_ci.pVertexBindingDescriptions = nullptr;
7367 vi_ci.vertexAttributeDescriptionCount = 0;
7368 vi_ci.pVertexAttributeDescriptions = nullptr;
7369
7370 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
7371 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
7372 pipe_ms_state_ci.pNext = NULL;
7373 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
7374 pipe_ms_state_ci.sampleShadingEnable = 0;
7375 pipe_ms_state_ci.minSampleShading = 1.0;
7376 pipe_ms_state_ci.pSampleMask = NULL;
7377
Tobin Ehlise68360f2015-10-01 11:15:13 -06007378 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007379 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7380 pipeline_layout_ci.setLayoutCount = 1;
7381 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007382
7383 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007384 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007385 ASSERT_VK_SUCCESS(err);
7386
7387 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
7388 // Set scissor as dynamic to avoid second error
7389 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007390 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
7391 dyn_state_ci.dynamicStateCount = 1;
7392 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007393
Cody Northropeb3a6c12015-10-05 14:44:45 -06007394 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07007395 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06007396
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007397 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007398 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
7399 // 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 +08007400 shaderStages[0] = vs.GetStageCreateInfo();
7401 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007402
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007403 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
7404 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7405 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
7406 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
7407 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
7408 rs_state_ci.depthClampEnable = VK_FALSE;
7409 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
7410 rs_state_ci.depthBiasEnable = VK_FALSE;
7411
Tobin Ehlise68360f2015-10-01 11:15:13 -06007412 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007413 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7414 gp_ci.stageCount = 2;
7415 gp_ci.pStages = shaderStages;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007416 gp_ci.pRasterizationState = &rs_state_ci;
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007417 // Not setting VP state w/o dynamic vp state should cause validation error
7418 gp_ci.pViewportState = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -07007419 gp_ci.pDynamicState = &dyn_state_ci;
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007420 gp_ci.pVertexInputState = &vi_ci;
7421 gp_ci.pInputAssemblyState = &ia_ci;
7422 gp_ci.pMultisampleState = &pipe_ms_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007423 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7424 gp_ci.layout = pipeline_layout;
7425 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007426
7427 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007428 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007429
7430 VkPipeline pipeline;
7431 VkPipelineCache pipelineCache;
7432
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007433 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007434 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007435 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007436
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007437 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007438
Chia-I Wuf7458c52015-10-26 21:10:41 +08007439 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7440 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7441 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7442 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007443}
Mark Lobodzinski73169e22016-12-16 14:01:17 -07007444
7445// Create PSO w/o non-zero viewportCount but no viewport data, then run second test where dynamic scissor count doesn't match PSO
7446// scissor count
Karl Schultz6addd812016-02-02 17:17:23 -07007447TEST_F(VkLayerTest, PSOViewportCountWithoutDataAndDynScissorMismatch) {
7448 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007449
Mark Lobodzinskid04c7862016-12-16 13:17:49 -07007450 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02110);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007451
Tobin Ehlise68360f2015-10-01 11:15:13 -06007452 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007453
7454 if (!m_device->phy().features().multiViewport) {
7455 printf("Device does not support multiple viewports/scissors; skipped.\n");
7456 return;
7457 }
7458
Tobin Ehlise68360f2015-10-01 11:15:13 -06007459 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06007460
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007461 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007462 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7463 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007464
7465 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007466 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7467 ds_pool_ci.maxSets = 1;
7468 ds_pool_ci.poolSizeCount = 1;
7469 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007470
7471 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007472 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007473 ASSERT_VK_SUCCESS(err);
7474
7475 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007476 dsl_binding.binding = 0;
7477 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7478 dsl_binding.descriptorCount = 1;
7479 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007480
7481 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007482 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7483 ds_layout_ci.bindingCount = 1;
7484 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007485
7486 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007487 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007488 ASSERT_VK_SUCCESS(err);
7489
7490 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007491 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007492 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007493 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007494 alloc_info.descriptorPool = ds_pool;
7495 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007496 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007497 ASSERT_VK_SUCCESS(err);
7498
7499 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007500 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7501 pipeline_layout_ci.setLayoutCount = 1;
7502 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007503
7504 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007505 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007506 ASSERT_VK_SUCCESS(err);
7507
7508 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007509 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
7510 vp_state_ci.viewportCount = 1;
7511 vp_state_ci.pViewports = NULL; // Null vp w/ count of 1 should cause error
7512 vp_state_ci.scissorCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007513 vp_state_ci.pScissors = NULL; // Scissor is dynamic (below) so this won't cause error
Tobin Ehlise68360f2015-10-01 11:15:13 -06007514
7515 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
7516 // Set scissor as dynamic to avoid that error
7517 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007518 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
7519 dyn_state_ci.dynamicStateCount = 1;
7520 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007521
Mark Lobodzinski73169e22016-12-16 14:01:17 -07007522 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
7523 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
7524 pipe_ms_state_ci.pNext = NULL;
7525 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
7526 pipe_ms_state_ci.sampleShadingEnable = 0;
7527 pipe_ms_state_ci.minSampleShading = 1.0;
7528 pipe_ms_state_ci.pSampleMask = NULL;
7529
Cody Northropeb3a6c12015-10-05 14:44:45 -06007530 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07007531 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06007532
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007533 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski73169e22016-12-16 14:01:17 -07007534 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
7535 // 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 +08007536 shaderStages[0] = vs.GetStageCreateInfo();
7537 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007538
Cody Northropf6622dc2015-10-06 10:33:21 -06007539 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7540 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7541 vi_ci.pNext = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007542 vi_ci.vertexBindingDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06007543 vi_ci.pVertexBindingDescriptions = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007544 vi_ci.vertexAttributeDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06007545 vi_ci.pVertexAttributeDescriptions = nullptr;
7546
7547 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7548 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7549 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7550
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007551 VkPipelineRasterizationStateCreateInfo rs_ci = {};
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007552 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Mark Lobodzinski73169e22016-12-16 14:01:17 -07007553 rs_ci.lineWidth = m_device->props.limits.lineWidthRange[0];
Cody Northropf6622dc2015-10-06 10:33:21 -06007554 rs_ci.pNext = nullptr;
7555
Mark Youngc89c6312016-03-31 16:03:20 -06007556 VkPipelineColorBlendAttachmentState att = {};
7557 att.blendEnable = VK_FALSE;
7558 att.colorWriteMask = 0xf;
7559
Cody Northropf6622dc2015-10-06 10:33:21 -06007560 VkPipelineColorBlendStateCreateInfo cb_ci = {};
7561 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
7562 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06007563 cb_ci.attachmentCount = 1;
7564 cb_ci.pAttachments = &att;
Cody Northropf6622dc2015-10-06 10:33:21 -06007565
Tobin Ehlise68360f2015-10-01 11:15:13 -06007566 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007567 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7568 gp_ci.stageCount = 2;
7569 gp_ci.pStages = shaderStages;
7570 gp_ci.pVertexInputState = &vi_ci;
7571 gp_ci.pInputAssemblyState = &ia_ci;
7572 gp_ci.pViewportState = &vp_state_ci;
7573 gp_ci.pRasterizationState = &rs_ci;
7574 gp_ci.pColorBlendState = &cb_ci;
7575 gp_ci.pDynamicState = &dyn_state_ci;
Mark Lobodzinski73169e22016-12-16 14:01:17 -07007576 gp_ci.pMultisampleState = &pipe_ms_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007577 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7578 gp_ci.layout = pipeline_layout;
7579 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007580
7581 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007582 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007583
7584 VkPipeline pipeline;
7585 VkPipelineCache pipelineCache;
7586
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007587 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007588 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007589 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007590
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007591 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007592
Tobin Ehlisd332f282015-10-02 11:00:56 -06007593 // Now hit second fail case where we set scissor w/ different count than PSO
Karl Schultz6addd812016-02-02 17:17:23 -07007594 // First need to successfully create the PSO from above by setting
7595 // pViewports
Mike Weiblen95dd0f92016-10-19 12:28:27 -06007596 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 -07007597
7598 VkViewport vp = {}; // Just need dummy vp to point to
7599 vp_state_ci.pViewports = &vp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007600 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Karl Schultz6addd812016-02-02 17:17:23 -07007601 ASSERT_VK_SUCCESS(err);
Tony Barbour552f6c02016-12-21 14:34:07 -07007602 m_commandBuffer->BeginCommandBuffer();
7603 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007604 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007605 VkRect2D scissors[1] = {}; // don't care about data
Karl Schultz6addd812016-02-02 17:17:23 -07007606 // Count of 2 doesn't match PSO count of 1
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007607 vkCmdSetScissor(m_commandBuffer->GetBufferHandle(), 1, 1, scissors);
Karl Schultz6addd812016-02-02 17:17:23 -07007608 Draw(1, 0, 0, 0);
7609
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007610 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07007611
7612 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7613 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7614 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7615 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06007616 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07007617}
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07007618
7619// 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 -07007620// viewportCount
7621TEST_F(VkLayerTest, PSOScissorCountWithoutDataAndDynViewportMismatch) {
7622 VkResult err;
7623
Mark Lobodzinskid04c7862016-12-16 13:17:49 -07007624 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02111);
Karl Schultz6addd812016-02-02 17:17:23 -07007625
7626 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007627
7628 if (!m_device->phy().features().multiViewport) {
7629 printf("Device does not support multiple viewports/scissors; skipped.\n");
7630 return;
7631 }
7632
Karl Schultz6addd812016-02-02 17:17:23 -07007633 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7634
7635 VkDescriptorPoolSize ds_type_count = {};
7636 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7637 ds_type_count.descriptorCount = 1;
7638
7639 VkDescriptorPoolCreateInfo ds_pool_ci = {};
7640 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7641 ds_pool_ci.maxSets = 1;
7642 ds_pool_ci.poolSizeCount = 1;
7643 ds_pool_ci.pPoolSizes = &ds_type_count;
7644
7645 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007646 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Karl Schultz6addd812016-02-02 17:17:23 -07007647 ASSERT_VK_SUCCESS(err);
7648
7649 VkDescriptorSetLayoutBinding dsl_binding = {};
7650 dsl_binding.binding = 0;
7651 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7652 dsl_binding.descriptorCount = 1;
7653 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7654
7655 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
7656 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7657 ds_layout_ci.bindingCount = 1;
7658 ds_layout_ci.pBindings = &dsl_binding;
7659
7660 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007661 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Karl Schultz6addd812016-02-02 17:17:23 -07007662 ASSERT_VK_SUCCESS(err);
7663
7664 VkDescriptorSet descriptorSet;
7665 VkDescriptorSetAllocateInfo alloc_info = {};
7666 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
7667 alloc_info.descriptorSetCount = 1;
7668 alloc_info.descriptorPool = ds_pool;
7669 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007670 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Karl Schultz6addd812016-02-02 17:17:23 -07007671 ASSERT_VK_SUCCESS(err);
7672
7673 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
7674 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7675 pipeline_layout_ci.setLayoutCount = 1;
7676 pipeline_layout_ci.pSetLayouts = &ds_layout;
7677
7678 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007679 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultz6addd812016-02-02 17:17:23 -07007680 ASSERT_VK_SUCCESS(err);
7681
7682 VkPipelineViewportStateCreateInfo vp_state_ci = {};
7683 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
7684 vp_state_ci.scissorCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007685 vp_state_ci.pScissors = NULL; // Null scissor w/ count of 1 should cause error
Karl Schultz6addd812016-02-02 17:17:23 -07007686 vp_state_ci.viewportCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007687 vp_state_ci.pViewports = NULL; // vp is dynamic (below) so this won't cause error
Karl Schultz6addd812016-02-02 17:17:23 -07007688
7689 VkDynamicState vp_state = VK_DYNAMIC_STATE_VIEWPORT;
7690 // Set scissor as dynamic to avoid that error
7691 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
7692 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
7693 dyn_state_ci.dynamicStateCount = 1;
7694 dyn_state_ci.pDynamicStates = &vp_state;
7695
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07007696 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
7697 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
7698 pipe_ms_state_ci.pNext = NULL;
7699 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
7700 pipe_ms_state_ci.sampleShadingEnable = 0;
7701 pipe_ms_state_ci.minSampleShading = 1.0;
7702 pipe_ms_state_ci.pSampleMask = NULL;
7703
Karl Schultz6addd812016-02-02 17:17:23 -07007704 VkPipelineShaderStageCreateInfo shaderStages[2];
7705 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
7706
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007707 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07007708 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
7709 // 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 -07007710 shaderStages[0] = vs.GetStageCreateInfo();
7711 shaderStages[1] = fs.GetStageCreateInfo();
7712
7713 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7714 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7715 vi_ci.pNext = nullptr;
7716 vi_ci.vertexBindingDescriptionCount = 0;
7717 vi_ci.pVertexBindingDescriptions = nullptr;
7718 vi_ci.vertexAttributeDescriptionCount = 0;
7719 vi_ci.pVertexAttributeDescriptions = nullptr;
7720
7721 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7722 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7723 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7724
7725 VkPipelineRasterizationStateCreateInfo rs_ci = {};
7726 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07007727 rs_ci.lineWidth = m_device->props.limits.lineWidthRange[0];
Karl Schultz6addd812016-02-02 17:17:23 -07007728 rs_ci.pNext = nullptr;
7729
Mark Youngc89c6312016-03-31 16:03:20 -06007730 VkPipelineColorBlendAttachmentState att = {};
7731 att.blendEnable = VK_FALSE;
7732 att.colorWriteMask = 0xf;
7733
Karl Schultz6addd812016-02-02 17:17:23 -07007734 VkPipelineColorBlendStateCreateInfo cb_ci = {};
7735 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
7736 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06007737 cb_ci.attachmentCount = 1;
7738 cb_ci.pAttachments = &att;
Karl Schultz6addd812016-02-02 17:17:23 -07007739
7740 VkGraphicsPipelineCreateInfo gp_ci = {};
7741 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7742 gp_ci.stageCount = 2;
7743 gp_ci.pStages = shaderStages;
7744 gp_ci.pVertexInputState = &vi_ci;
7745 gp_ci.pInputAssemblyState = &ia_ci;
7746 gp_ci.pViewportState = &vp_state_ci;
7747 gp_ci.pRasterizationState = &rs_ci;
7748 gp_ci.pColorBlendState = &cb_ci;
7749 gp_ci.pDynamicState = &dyn_state_ci;
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07007750 gp_ci.pMultisampleState = &pipe_ms_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007751 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7752 gp_ci.layout = pipeline_layout;
7753 gp_ci.renderPass = renderPass();
7754
7755 VkPipelineCacheCreateInfo pc_ci = {};
7756 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
7757
7758 VkPipeline pipeline;
7759 VkPipelineCache pipelineCache;
7760
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007761 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Karl Schultz6addd812016-02-02 17:17:23 -07007762 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007763 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Karl Schultz6addd812016-02-02 17:17:23 -07007764
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007765 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07007766
7767 // Now hit second fail case where we set scissor w/ different count than PSO
7768 // First need to successfully create the PSO from above by setting
7769 // pViewports
Mike Weiblen95dd0f92016-10-19 12:28:27 -06007770 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 -06007771
Tobin Ehlisd332f282015-10-02 11:00:56 -06007772 VkRect2D sc = {}; // Just need dummy vp to point to
7773 vp_state_ci.pScissors = &sc;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007774 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlisd332f282015-10-02 11:00:56 -06007775 ASSERT_VK_SUCCESS(err);
Tony Barbour552f6c02016-12-21 14:34:07 -07007776 m_commandBuffer->BeginCommandBuffer();
7777 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007778 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07007779 VkViewport viewports[1] = {};
7780 viewports[0].width = 8;
7781 viewports[0].height = 8;
Tobin Ehlisd332f282015-10-02 11:00:56 -06007782 // Count of 2 doesn't match PSO count of 1
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007783 vkCmdSetViewport(m_commandBuffer->GetBufferHandle(), 1, 1, viewports);
Tobin Ehlisd332f282015-10-02 11:00:56 -06007784 Draw(1, 0, 0, 0);
7785
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007786 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007787
Chia-I Wuf7458c52015-10-26 21:10:41 +08007788 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7789 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7790 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7791 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06007792 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007793}
7794
Mark Young7394fdd2016-03-31 14:56:43 -06007795TEST_F(VkLayerTest, PSOLineWidthInvalid) {
7796 VkResult err;
7797
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007798 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to -1");
Mark Young7394fdd2016-03-31 14:56:43 -06007799
7800 ASSERT_NO_FATAL_FAILURE(InitState());
7801 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7802
7803 VkDescriptorPoolSize ds_type_count = {};
7804 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7805 ds_type_count.descriptorCount = 1;
7806
7807 VkDescriptorPoolCreateInfo ds_pool_ci = {};
7808 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7809 ds_pool_ci.maxSets = 1;
7810 ds_pool_ci.poolSizeCount = 1;
7811 ds_pool_ci.pPoolSizes = &ds_type_count;
7812
7813 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007814 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Mark Young7394fdd2016-03-31 14:56:43 -06007815 ASSERT_VK_SUCCESS(err);
7816
7817 VkDescriptorSetLayoutBinding dsl_binding = {};
7818 dsl_binding.binding = 0;
7819 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7820 dsl_binding.descriptorCount = 1;
7821 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7822
7823 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
7824 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7825 ds_layout_ci.bindingCount = 1;
7826 ds_layout_ci.pBindings = &dsl_binding;
7827
7828 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007829 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Young7394fdd2016-03-31 14:56:43 -06007830 ASSERT_VK_SUCCESS(err);
7831
7832 VkDescriptorSet descriptorSet;
7833 VkDescriptorSetAllocateInfo alloc_info = {};
7834 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
7835 alloc_info.descriptorSetCount = 1;
7836 alloc_info.descriptorPool = ds_pool;
7837 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007838 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Young7394fdd2016-03-31 14:56:43 -06007839 ASSERT_VK_SUCCESS(err);
7840
7841 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
7842 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7843 pipeline_layout_ci.setLayoutCount = 1;
7844 pipeline_layout_ci.pSetLayouts = &ds_layout;
7845
7846 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007847 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Mark Young7394fdd2016-03-31 14:56:43 -06007848 ASSERT_VK_SUCCESS(err);
7849
7850 VkPipelineViewportStateCreateInfo vp_state_ci = {};
7851 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
7852 vp_state_ci.scissorCount = 1;
7853 vp_state_ci.pScissors = NULL;
7854 vp_state_ci.viewportCount = 1;
7855 vp_state_ci.pViewports = NULL;
7856
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007857 VkDynamicState dynamic_states[3] = {VK_DYNAMIC_STATE_VIEWPORT, VK_DYNAMIC_STATE_SCISSOR, VK_DYNAMIC_STATE_LINE_WIDTH};
Mark Young7394fdd2016-03-31 14:56:43 -06007858 // Set scissor as dynamic to avoid that error
7859 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
7860 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
7861 dyn_state_ci.dynamicStateCount = 2;
7862 dyn_state_ci.pDynamicStates = dynamic_states;
7863
7864 VkPipelineShaderStageCreateInfo shaderStages[2];
7865 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
7866
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007867 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
7868 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT,
Mark Young7394fdd2016-03-31 14:56:43 -06007869 this); // TODO - We shouldn't need a fragment shader
7870 // but add it to be able to run on more devices
7871 shaderStages[0] = vs.GetStageCreateInfo();
7872 shaderStages[1] = fs.GetStageCreateInfo();
7873
7874 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7875 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7876 vi_ci.pNext = nullptr;
7877 vi_ci.vertexBindingDescriptionCount = 0;
7878 vi_ci.pVertexBindingDescriptions = nullptr;
7879 vi_ci.vertexAttributeDescriptionCount = 0;
7880 vi_ci.pVertexAttributeDescriptions = nullptr;
7881
7882 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7883 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7884 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7885
7886 VkPipelineRasterizationStateCreateInfo rs_ci = {};
7887 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7888 rs_ci.pNext = nullptr;
7889
Mark Young47107952016-05-02 15:59:55 -06007890 // Check too low (line width of -1.0f).
7891 rs_ci.lineWidth = -1.0f;
Mark Young7394fdd2016-03-31 14:56:43 -06007892
7893 VkPipelineColorBlendAttachmentState att = {};
7894 att.blendEnable = VK_FALSE;
7895 att.colorWriteMask = 0xf;
7896
7897 VkPipelineColorBlendStateCreateInfo cb_ci = {};
7898 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
7899 cb_ci.pNext = nullptr;
7900 cb_ci.attachmentCount = 1;
7901 cb_ci.pAttachments = &att;
7902
7903 VkGraphicsPipelineCreateInfo gp_ci = {};
7904 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7905 gp_ci.stageCount = 2;
7906 gp_ci.pStages = shaderStages;
7907 gp_ci.pVertexInputState = &vi_ci;
7908 gp_ci.pInputAssemblyState = &ia_ci;
7909 gp_ci.pViewportState = &vp_state_ci;
7910 gp_ci.pRasterizationState = &rs_ci;
7911 gp_ci.pColorBlendState = &cb_ci;
7912 gp_ci.pDynamicState = &dyn_state_ci;
7913 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7914 gp_ci.layout = pipeline_layout;
7915 gp_ci.renderPass = renderPass();
7916
7917 VkPipelineCacheCreateInfo pc_ci = {};
7918 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
7919
7920 VkPipeline pipeline;
7921 VkPipelineCache pipelineCache;
7922
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007923 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06007924 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007925 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06007926
7927 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06007928 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06007929
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007930 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to 65536");
Mark Young7394fdd2016-03-31 14:56:43 -06007931
7932 // Check too high (line width of 65536.0f).
7933 rs_ci.lineWidth = 65536.0f;
7934
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007935 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06007936 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007937 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06007938
7939 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06007940 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06007941
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007942 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to -1");
Mark Young7394fdd2016-03-31 14:56:43 -06007943
7944 dyn_state_ci.dynamicStateCount = 3;
7945
7946 rs_ci.lineWidth = 1.0f;
7947
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007948 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06007949 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007950 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tony Barbour552f6c02016-12-21 14:34:07 -07007951 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007952 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06007953
7954 // Check too low with dynamic setting.
Mark Young47107952016-05-02 15:59:55 -06007955 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), -1.0f);
Mark Young7394fdd2016-03-31 14:56:43 -06007956 m_errorMonitor->VerifyFound();
7957
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007958 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to 65536");
Mark Young7394fdd2016-03-31 14:56:43 -06007959
7960 // Check too high with dynamic setting.
7961 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), 65536.0f);
7962 m_errorMonitor->VerifyFound();
Tony Barbour552f6c02016-12-21 14:34:07 -07007963 m_commandBuffer->EndCommandBuffer();
Mark Young7394fdd2016-03-31 14:56:43 -06007964
7965 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7966 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7967 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7968 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06007969 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06007970}
7971
Karl Schultz6addd812016-02-02 17:17:23 -07007972TEST_F(VkLayerTest, NullRenderPass) {
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007973 // Bind a NULL RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007974 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mike Schuchardt0b1f2f82016-12-28 15:11:20 -07007975 "vkCmdBeginRenderPass: required parameter pRenderPassBegin specified as NULL");
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007976
7977 ASSERT_NO_FATAL_FAILURE(InitState());
7978 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007979
Tony Barbour552f6c02016-12-21 14:34:07 -07007980 m_commandBuffer->BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07007981 // Don't care about RenderPass handle b/c error should be flagged before
7982 // that
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007983 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), NULL, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007984
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007985 m_errorMonitor->VerifyFound();
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007986}
7987
Karl Schultz6addd812016-02-02 17:17:23 -07007988TEST_F(VkLayerTest, RenderPassWithinRenderPass) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007989 // Bind a BeginRenderPass within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007990 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7991 "It is invalid to issue this call inside an active render pass");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007992
7993 ASSERT_NO_FATAL_FAILURE(InitState());
7994 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007995
Tony Barbour552f6c02016-12-21 14:34:07 -07007996 m_commandBuffer->BeginCommandBuffer();
7997 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Karl Schultz6addd812016-02-02 17:17:23 -07007998 // Just create a dummy Renderpass that's non-NULL so we can get to the
7999 // proper error
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008000 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008001
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008002 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06008003}
8004
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008005TEST_F(VkLayerTest, RenderPassClearOpMismatch) {
8006 TEST_DESCRIPTION("Begin a renderPass where clearValueCount is less than"
8007 "the number of renderPass attachments that use loadOp"
8008 "VK_ATTACHMENT_LOAD_OP_CLEAR.");
8009
8010 ASSERT_NO_FATAL_FAILURE(InitState());
8011 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8012
8013 // Create a renderPass with a single attachment that uses loadOp CLEAR
8014 VkAttachmentReference attach = {};
8015 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
8016 VkSubpassDescription subpass = {};
8017 subpass.inputAttachmentCount = 1;
8018 subpass.pInputAttachments = &attach;
8019 VkRenderPassCreateInfo rpci = {};
8020 rpci.subpassCount = 1;
8021 rpci.pSubpasses = &subpass;
8022 rpci.attachmentCount = 1;
8023 VkAttachmentDescription attach_desc = {};
8024 attach_desc.format = VK_FORMAT_UNDEFINED;
8025 // Set loadOp to CLEAR
8026 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
8027 rpci.pAttachments = &attach_desc;
8028 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
8029 VkRenderPass rp;
8030 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
8031
8032 VkCommandBufferInheritanceInfo hinfo = {};
8033 hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
8034 hinfo.renderPass = VK_NULL_HANDLE;
8035 hinfo.subpass = 0;
8036 hinfo.framebuffer = VK_NULL_HANDLE;
8037 hinfo.occlusionQueryEnable = VK_FALSE;
8038 hinfo.queryFlags = 0;
8039 hinfo.pipelineStatistics = 0;
8040 VkCommandBufferBeginInfo info = {};
8041 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
8042 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
8043 info.pInheritanceInfo = &hinfo;
8044
8045 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
8046 VkRenderPassBeginInfo rp_begin = {};
8047 rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
8048 rp_begin.pNext = NULL;
8049 rp_begin.renderPass = renderPass();
8050 rp_begin.framebuffer = framebuffer();
8051 rp_begin.clearValueCount = 0; // Should be 1
8052
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07008053 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00442);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008054
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008055 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rp_begin, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008056
8057 m_errorMonitor->VerifyFound();
Mark Lobodzinski5c70ebd2016-06-09 13:45:00 -06008058
8059 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008060}
8061
Slawomir Cygan0808f392016-11-28 17:53:23 +01008062TEST_F(VkLayerTest, RenderPassClearOpTooManyValues) {
8063 TEST_DESCRIPTION("Begin a renderPass where clearValueCount is greater than"
8064 "the number of renderPass attachments that use loadOp"
8065 "VK_ATTACHMENT_LOAD_OP_CLEAR.");
8066
8067 ASSERT_NO_FATAL_FAILURE(InitState());
8068 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8069
8070 // Create a renderPass with a single attachment that uses loadOp CLEAR
8071 VkAttachmentReference attach = {};
8072 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
8073 VkSubpassDescription subpass = {};
8074 subpass.inputAttachmentCount = 1;
8075 subpass.pInputAttachments = &attach;
8076 VkRenderPassCreateInfo rpci = {};
8077 rpci.subpassCount = 1;
8078 rpci.pSubpasses = &subpass;
8079 rpci.attachmentCount = 1;
8080 VkAttachmentDescription attach_desc = {};
8081 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
8082 // Set loadOp to CLEAR
8083 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
8084 rpci.pAttachments = &attach_desc;
8085 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
8086 VkRenderPass rp;
8087 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
8088
8089 VkCommandBufferBeginInfo info = {};
8090 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
8091 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
8092
8093 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
8094 VkRenderPassBeginInfo rp_begin = {};
8095 rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
8096 rp_begin.pNext = NULL;
8097 rp_begin.renderPass = renderPass();
8098 rp_begin.framebuffer = framebuffer();
8099 rp_begin.clearValueCount = 2; // Should be 1
8100
8101 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, " has a clearValueCount of"
8102 " 2 but only first 1 entries in pClearValues array are used");
8103
8104 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rp_begin, VK_SUBPASS_CONTENTS_INLINE);
8105
8106 m_errorMonitor->VerifyFound();
8107
8108 vkDestroyRenderPass(m_device->device(), rp, NULL);
8109}
8110
8111
Cody Northrop3bb4d962016-05-09 16:15:57 -06008112TEST_F(VkLayerTest, EndCommandBufferWithinRenderPass) {
8113
8114 TEST_DESCRIPTION("End a command buffer with an active render pass");
8115
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008116 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8117 "It is invalid to issue this call inside an active render pass");
Cody Northrop3bb4d962016-05-09 16:15:57 -06008118
8119 ASSERT_NO_FATAL_FAILURE(InitState());
8120 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8121
Tony Barbour552f6c02016-12-21 14:34:07 -07008122 m_commandBuffer->BeginCommandBuffer();
8123 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
8124 vkEndCommandBuffer(m_commandBuffer->handle());
Cody Northrop3bb4d962016-05-09 16:15:57 -06008125
8126 m_errorMonitor->VerifyFound();
8127
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008128 // TODO: Add test for VK_COMMAND_BUFFER_LEVEL_SECONDARY
8129 // TODO: Add test for VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT
Cody Northrop3bb4d962016-05-09 16:15:57 -06008130}
8131
Karl Schultz6addd812016-02-02 17:17:23 -07008132TEST_F(VkLayerTest, FillBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008133 // Call CmdFillBuffer within an active renderpass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008134 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8135 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008136
8137 ASSERT_NO_FATAL_FAILURE(InitState());
8138 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008139
Tony Barbour552f6c02016-12-21 14:34:07 -07008140 m_commandBuffer->BeginCommandBuffer();
8141 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008142
8143 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008144 vk_testing::Buffer dstBuffer;
8145 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008146
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008147 m_commandBuffer->FillBuffer(dstBuffer.handle(), 0, 4, 0x11111111);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008148
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008149 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008150}
8151
Karl Schultz6addd812016-02-02 17:17:23 -07008152TEST_F(VkLayerTest, UpdateBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008153 // Call CmdUpdateBuffer within an active renderpass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008154 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8155 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008156
8157 ASSERT_NO_FATAL_FAILURE(InitState());
8158 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008159
Tony Barbour552f6c02016-12-21 14:34:07 -07008160 m_commandBuffer->BeginCommandBuffer();
8161 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008162
8163 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008164 vk_testing::Buffer dstBuffer;
8165 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008166
Karl Schultz6addd812016-02-02 17:17:23 -07008167 VkDeviceSize dstOffset = 0;
8168 VkDeviceSize dataSize = 1024;
Karl Schultzee344492016-07-11 15:09:57 -06008169 const void *pData = NULL;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008170
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008171 vkCmdUpdateBuffer(m_commandBuffer->GetBufferHandle(), dstBuffer.handle(), dstOffset, dataSize, pData);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008172
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008173 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008174}
8175
Karl Schultz6addd812016-02-02 17:17:23 -07008176TEST_F(VkLayerTest, ClearColorImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008177 // Call CmdClearColorImage within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008178 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8179 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008180
8181 ASSERT_NO_FATAL_FAILURE(InitState());
8182 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008183
Tony Barbour552f6c02016-12-21 14:34:07 -07008184 m_commandBuffer->BeginCommandBuffer();
8185 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008186
Michael Lentine0a369f62016-02-03 16:51:46 -06008187 VkClearColorValue clear_color;
8188 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
Karl Schultz6addd812016-02-02 17:17:23 -07008189 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
8190 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
8191 const int32_t tex_width = 32;
8192 const int32_t tex_height = 32;
8193 VkImageCreateInfo image_create_info = {};
8194 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
8195 image_create_info.pNext = NULL;
8196 image_create_info.imageType = VK_IMAGE_TYPE_2D;
8197 image_create_info.format = tex_format;
8198 image_create_info.extent.width = tex_width;
8199 image_create_info.extent.height = tex_height;
8200 image_create_info.extent.depth = 1;
8201 image_create_info.mipLevels = 1;
8202 image_create_info.arrayLayers = 1;
8203 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
8204 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
8205 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008206
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008207 vk_testing::Image dstImage;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008208 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008209
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008210 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008211
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008212 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1, &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008213
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008214 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008215}
8216
Karl Schultz6addd812016-02-02 17:17:23 -07008217TEST_F(VkLayerTest, ClearDepthStencilImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008218 // Call CmdClearDepthStencilImage within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008219 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8220 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008221
8222 ASSERT_NO_FATAL_FAILURE(InitState());
8223 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008224
Tony Barbour552f6c02016-12-21 14:34:07 -07008225 m_commandBuffer->BeginCommandBuffer();
8226 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008227
8228 VkClearDepthStencilValue clear_value = {0};
Dustin Gravesa2e5c942016-02-11 18:28:06 -07008229 VkMemoryPropertyFlags reqs = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07008230 VkImageCreateInfo image_create_info = vk_testing::Image::create_info();
8231 image_create_info.imageType = VK_IMAGE_TYPE_2D;
8232 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
8233 image_create_info.extent.width = 64;
8234 image_create_info.extent.height = 64;
8235 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
8236 image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008237
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008238 vk_testing::Image dstImage;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008239 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008240
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008241 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_DEPTH_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008242
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008243 vkCmdClearDepthStencilImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(),
8244 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, &clear_value, 1, &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008245
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008246 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008247}
8248
Karl Schultz6addd812016-02-02 17:17:23 -07008249TEST_F(VkLayerTest, ClearColorAttachmentsOutsideRenderPass) {
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06008250 // Call CmdClearAttachmentss outside of an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07008251 VkResult err;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008252
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008253 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdClearAttachments(): This call "
8254 "must be issued inside an active "
8255 "render pass");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008256
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008257 ASSERT_NO_FATAL_FAILURE(InitState());
8258 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008259
8260 // Start no RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008261 err = m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008262 ASSERT_VK_SUCCESS(err);
8263
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06008264 VkClearAttachment color_attachment;
8265 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8266 color_attachment.clearValue.color.float32[0] = 0;
8267 color_attachment.clearValue.color.float32[1] = 0;
8268 color_attachment.clearValue.color.float32[2] = 0;
8269 color_attachment.clearValue.color.float32[3] = 0;
8270 color_attachment.colorAttachment = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07008271 VkClearRect clear_rect = {{{0, 0}, {32, 32}}};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008272 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008273
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008274 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008275}
8276
Chris Forbes3b97e932016-09-07 11:29:24 +12008277TEST_F(VkLayerTest, RenderPassExcessiveNextSubpass) {
8278 TEST_DESCRIPTION("Test that an error is produced when CmdNextSubpass is "
8279 "called too many times in a renderpass instance");
8280
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008281 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdNextSubpass(): Attempted to advance "
8282 "beyond final subpass");
Chris Forbes3b97e932016-09-07 11:29:24 +12008283
8284 ASSERT_NO_FATAL_FAILURE(InitState());
8285 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8286
Tony Barbour552f6c02016-12-21 14:34:07 -07008287 m_commandBuffer->BeginCommandBuffer();
8288 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Chris Forbes3b97e932016-09-07 11:29:24 +12008289
8290 // error here.
8291 vkCmdNextSubpass(m_commandBuffer->GetBufferHandle(), VK_SUBPASS_CONTENTS_INLINE);
8292 m_errorMonitor->VerifyFound();
8293
Tony Barbour552f6c02016-12-21 14:34:07 -07008294 m_commandBuffer->EndRenderPass();
8295 m_commandBuffer->EndCommandBuffer();
Chris Forbes3b97e932016-09-07 11:29:24 +12008296}
8297
Chris Forbes6d624702016-09-07 13:57:05 +12008298TEST_F(VkLayerTest, RenderPassEndedBeforeFinalSubpass) {
8299 TEST_DESCRIPTION("Test that an error is produced when CmdEndRenderPass is "
8300 "called before the final subpass has been reached");
8301
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008302 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdEndRenderPass(): Called before reaching "
8303 "final subpass");
Chris Forbes6d624702016-09-07 13:57:05 +12008304
8305 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008306 VkSubpassDescription sd[2] = {{0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr},
8307 {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr}};
Chris Forbes6d624702016-09-07 13:57:05 +12008308
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008309 VkRenderPassCreateInfo rcpi = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 2, sd, 0, nullptr};
Chris Forbes6d624702016-09-07 13:57:05 +12008310
8311 VkRenderPass rp;
8312 VkResult err = vkCreateRenderPass(m_device->device(), &rcpi, nullptr, &rp);
8313 ASSERT_VK_SUCCESS(err);
8314
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008315 VkFramebufferCreateInfo fbci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 0, nullptr, 16, 16, 1};
Chris Forbes6d624702016-09-07 13:57:05 +12008316
8317 VkFramebuffer fb;
8318 err = vkCreateFramebuffer(m_device->device(), &fbci, nullptr, &fb);
8319 ASSERT_VK_SUCCESS(err);
8320
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008321 m_commandBuffer->BeginCommandBuffer(); // no implicit RP begin
Chris Forbes6d624702016-09-07 13:57:05 +12008322
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008323 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 +12008324
8325 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
8326
8327 // Error here.
8328 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
8329 m_errorMonitor->VerifyFound();
8330
8331 // Clean up.
8332 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
8333 vkDestroyRenderPass(m_device->device(), rp, nullptr);
8334}
8335
Karl Schultz9e66a292016-04-21 15:57:51 -06008336TEST_F(VkLayerTest, BufferMemoryBarrierNoBuffer) {
8337 // Try to add a buffer memory barrier with no buffer.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008338 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8339 "required parameter pBufferMemoryBarriers[0].buffer specified as VK_NULL_HANDLE");
Karl Schultz9e66a292016-04-21 15:57:51 -06008340
8341 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbour552f6c02016-12-21 14:34:07 -07008342 m_commandBuffer->BeginCommandBuffer();
Karl Schultz9e66a292016-04-21 15:57:51 -06008343
8344 VkBufferMemoryBarrier buf_barrier = {};
8345 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
8346 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8347 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
8348 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8349 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8350 buf_barrier.buffer = VK_NULL_HANDLE;
8351 buf_barrier.offset = 0;
8352 buf_barrier.size = VK_WHOLE_SIZE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008353 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8354 nullptr, 1, &buf_barrier, 0, nullptr);
Karl Schultz9e66a292016-04-21 15:57:51 -06008355
8356 m_errorMonitor->VerifyFound();
8357}
8358
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008359TEST_F(VkLayerTest, InvalidBarriers) {
8360 TEST_DESCRIPTION("A variety of ways to get VK_INVALID_BARRIER ");
8361
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008362 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Barriers cannot be set during subpass");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008363
8364 ASSERT_NO_FATAL_FAILURE(InitState());
8365 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8366
8367 VkMemoryBarrier mem_barrier = {};
8368 mem_barrier.sType = VK_STRUCTURE_TYPE_MEMORY_BARRIER;
8369 mem_barrier.pNext = NULL;
8370 mem_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8371 mem_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
Tony Barbour552f6c02016-12-21 14:34:07 -07008372 m_commandBuffer->BeginCommandBuffer();
8373 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008374 // BeginCommandBuffer() starts a render pass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008375 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 1,
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008376 &mem_barrier, 0, nullptr, 0, nullptr);
8377 m_errorMonitor->VerifyFound();
8378
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008379 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Image Layout cannot be transitioned to UNDEFINED");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008380 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008381 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 -06008382 ASSERT_TRUE(image.initialized());
8383 VkImageMemoryBarrier img_barrier = {};
8384 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
8385 img_barrier.pNext = NULL;
8386 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8387 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
8388 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8389 // New layout can't be UNDEFINED
8390 img_barrier.newLayout = VK_IMAGE_LAYOUT_UNDEFINED;
8391 img_barrier.image = image.handle();
8392 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8393 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8394 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8395 img_barrier.subresourceRange.baseArrayLayer = 0;
8396 img_barrier.subresourceRange.baseMipLevel = 0;
8397 img_barrier.subresourceRange.layerCount = 1;
8398 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008399 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8400 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008401 m_errorMonitor->VerifyFound();
8402 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8403
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008404 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Subresource must have the sum of the "
8405 "baseArrayLayer");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008406 // baseArrayLayer + layerCount must be <= image's arrayLayers
8407 img_barrier.subresourceRange.baseArrayLayer = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008408 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8409 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008410 m_errorMonitor->VerifyFound();
8411 img_barrier.subresourceRange.baseArrayLayer = 0;
8412
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008413 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Subresource must have the sum of the baseMipLevel");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008414 // baseMipLevel + levelCount must be <= image's mipLevels
8415 img_barrier.subresourceRange.baseMipLevel = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008416 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8417 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008418 m_errorMonitor->VerifyFound();
8419 img_barrier.subresourceRange.baseMipLevel = 0;
8420
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008421 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 -06008422 vk_testing::Buffer buffer;
Mark Lobodzinskibdf378a2016-12-12 17:11:50 -07008423 VkMemoryPropertyFlags mem_reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
8424 buffer.init_as_src_and_dst(*m_device, 256, mem_reqs);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008425 VkBufferMemoryBarrier buf_barrier = {};
8426 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
8427 buf_barrier.pNext = NULL;
8428 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8429 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
8430 buf_barrier.buffer = buffer.handle();
8431 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8432 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8433 buf_barrier.offset = 0;
8434 buf_barrier.size = VK_WHOLE_SIZE;
8435 // Can't send buffer barrier during a render pass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008436 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8437 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008438 m_errorMonitor->VerifyFound();
8439 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
8440
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008441 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "which is not less than total size");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008442 buf_barrier.offset = 257;
8443 // Offset greater than total size
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008444 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8445 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008446 m_errorMonitor->VerifyFound();
8447 buf_barrier.offset = 0;
8448
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008449 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "whose sum is greater than total size");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008450 buf_barrier.size = 257;
8451 // Size greater than total size
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008452 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8453 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008454 m_errorMonitor->VerifyFound();
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008455
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008456 // Now exercise barrier aspect bit errors, first DS
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06008457 m_errorMonitor->SetDesiredFailureMsg(
8458 VK_DEBUG_REPORT_ERROR_BIT_EXT,
8459 "Combination depth/stencil image formats can have only the VK_IMAGE_ASPECT_DEPTH_BIT and VK_IMAGE_ASPECT_STENCIL_BIT set.");
8460 m_errorMonitor->SetDesiredFailureMsg(
8461 VK_DEBUG_REPORT_ERROR_BIT_EXT,
8462 "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 -06008463 VkDepthStencilObj ds_image(m_device);
8464 ds_image.Init(m_device, 128, 128, VK_FORMAT_D24_UNORM_S8_UINT);
8465 ASSERT_TRUE(ds_image.initialized());
Tobin Ehlis15684a02016-07-21 14:55:26 -06008466 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
8467 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008468 img_barrier.image = ds_image.handle();
Tobin Ehlis15684a02016-07-21 14:55:26 -06008469 // Use of COLOR aspect on DS image is error
8470 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008471 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8472 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008473 m_errorMonitor->VerifyFound();
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008474 // Now test depth-only
8475 VkFormatProperties format_props;
8476
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008477 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_D16_UNORM, &format_props);
8478 if (format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) {
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06008479 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8480 "Depth-only image formats must have the VK_IMAGE_ASPECT_DEPTH_BIT set.");
8481 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8482 "Depth-only image formats can have only the VK_IMAGE_ASPECT_DEPTH_BIT set.");
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008483 VkDepthStencilObj d_image(m_device);
8484 d_image.Init(m_device, 128, 128, VK_FORMAT_D16_UNORM);
8485 ASSERT_TRUE(d_image.initialized());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008486 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
Tobin Ehlis15684a02016-07-21 14:55:26 -06008487 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008488 img_barrier.image = d_image.handle();
Tobin Ehlis15684a02016-07-21 14:55:26 -06008489 // Use of COLOR aspect on depth image is error
8490 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008491 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
8492 0, nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008493 m_errorMonitor->VerifyFound();
8494 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008495 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_S8_UINT, &format_props);
8496 if (format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) {
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008497 // Now test stencil-only
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06008498 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8499 "Stencil-only image formats must have the VK_IMAGE_ASPECT_STENCIL_BIT set.");
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008500 VkDepthStencilObj s_image(m_device);
8501 s_image.Init(m_device, 128, 128, VK_FORMAT_S8_UINT);
8502 ASSERT_TRUE(s_image.initialized());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008503 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
Tobin Ehlis15684a02016-07-21 14:55:26 -06008504 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008505 img_barrier.image = s_image.handle();
Tobin Ehlis15684a02016-07-21 14:55:26 -06008506 // Use of COLOR aspect on depth image is error
8507 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008508 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
8509 0, nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008510 m_errorMonitor->VerifyFound();
8511 }
8512 // Finally test color
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06008513 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8514 "Color image formats must have the VK_IMAGE_ASPECT_COLOR_BIT set.");
8515 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8516 "Color image formats must have ONLY the VK_IMAGE_ASPECT_COLOR_BIT set.");
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008517 VkImageObj c_image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008518 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 -06008519 ASSERT_TRUE(c_image.initialized());
8520 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8521 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
8522 img_barrier.image = c_image.handle();
8523 // Set aspect to depth (non-color)
8524 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008525 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8526 nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008527 m_errorMonitor->VerifyFound();
Mark Lobodzinskibdf378a2016-12-12 17:11:50 -07008528
8529 // Attempt to mismatch barriers/waitEvents calls with incompatible queues
8530
8531 // Create command pool with incompatible queueflags
8532 const std::vector<VkQueueFamilyProperties> queue_props = m_device->queue_props;
8533 uint32_t queue_family_index = UINT32_MAX;
8534 for (uint32_t i = 0; i < queue_props.size(); i++) {
8535 if ((queue_props[i].queueFlags & VK_QUEUE_COMPUTE_BIT) == 0) {
8536 queue_family_index = i;
8537 break;
8538 }
8539 }
8540 if (queue_family_index == UINT32_MAX) {
8541 printf("No non-compute queue found; skipped.\n");
8542 return;
8543 }
8544 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02513);
8545
8546 VkCommandPool command_pool;
8547 VkCommandPoolCreateInfo pool_create_info{};
8548 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
8549 pool_create_info.queueFamilyIndex = queue_family_index;
8550 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
8551 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
8552
8553 // Allocate a command buffer
8554 VkCommandBuffer bad_command_buffer;
8555 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
8556 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
8557 command_buffer_allocate_info.commandPool = command_pool;
8558 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
8559 command_buffer_allocate_info.commandBufferCount = 1;
8560 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &bad_command_buffer));
8561
8562 VkCommandBufferBeginInfo cbbi = {};
8563 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
8564 vkBeginCommandBuffer(bad_command_buffer, &cbbi);
8565 buf_barrier.offset = 0;
8566 buf_barrier.size = VK_WHOLE_SIZE;
8567 vkCmdPipelineBarrier(bad_command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 1,
8568 &buf_barrier, 0, nullptr);
8569 m_errorMonitor->VerifyFound();
8570
8571 if ((queue_props[queue_family_index].queueFlags & VK_QUEUE_GRAPHICS_BIT) == 0) {
8572 vkEndCommandBuffer(bad_command_buffer);
8573 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
8574 printf("The non-compute queue does not support graphics; skipped.\n");
8575 return;
8576 }
8577 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02510);
8578 VkEvent event;
8579 VkEventCreateInfo event_create_info{};
8580 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
8581 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
8582 vkCmdWaitEvents(bad_command_buffer, 1, &event, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, nullptr, 0,
8583 nullptr, 0, nullptr);
8584 m_errorMonitor->VerifyFound();
8585
8586 vkEndCommandBuffer(bad_command_buffer);
8587 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008588}
8589
Tony Barbour18ba25c2016-09-29 13:42:40 -06008590TEST_F(VkLayerTest, LayoutFromPresentWithoutAccessMemoryRead) {
8591 // Transition an image away from PRESENT_SRC_KHR without ACCESS_MEMORY_READ in srcAccessMask
8592
8593 m_errorMonitor->SetDesiredFailureMsg(
8594 VK_DEBUG_REPORT_WARNING_BIT_EXT,
8595 "must have required access bit");
8596 ASSERT_NO_FATAL_FAILURE(InitState());
8597 VkImageObj image(m_device);
Tony Barbour256c80a2016-10-05 13:23:46 -06008598 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 -06008599 ASSERT_TRUE(image.initialized());
8600
8601 VkImageMemoryBarrier barrier = {};
8602 VkImageSubresourceRange range;
8603 barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
8604 barrier.srcAccessMask = 0;
8605 barrier.srcAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
8606 barrier.dstAccessMask = VK_ACCESS_MEMORY_READ_BIT;
8607 barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8608 barrier.newLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
8609 barrier.image = image.handle();
8610 range.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8611 range.baseMipLevel = 0;
8612 range.levelCount = 1;
8613 range.baseArrayLayer = 0;
8614 range.layerCount = 1;
8615 barrier.subresourceRange = range;
8616 VkCommandBufferObj cmdbuf(m_device, m_commandPool);
8617 cmdbuf.BeginCommandBuffer();
8618 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
8619 &barrier);
8620 barrier.oldLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
8621 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
8622 barrier.srcAccessMask = 0;
8623 barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
8624 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
8625 &barrier);
8626
8627 m_errorMonitor->VerifyFound();
8628}
8629
Karl Schultz6addd812016-02-02 17:17:23 -07008630TEST_F(VkLayerTest, IdxBufferAlignmentError) {
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008631 // Bind a BeginRenderPass within an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07008632 VkResult err;
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008633
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008634 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdBindIndexBuffer() offset (0x7) does not fall on ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008635
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008636 ASSERT_NO_FATAL_FAILURE(InitState());
8637 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008638 uint32_t qfi = 0;
8639 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008640 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
8641 buffCI.size = 1024;
8642 buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
8643 buffCI.queueFamilyIndexCount = 1;
8644 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008645
8646 VkBuffer ib;
Chia-I Wuf7458c52015-10-26 21:10:41 +08008647 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008648 ASSERT_VK_SUCCESS(err);
8649
Tony Barbour552f6c02016-12-21 14:34:07 -07008650 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008651 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07008652 // vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
8653 // VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008654 // Should error before calling to driver so don't care about actual data
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008655 vkCmdBindIndexBuffer(m_commandBuffer->GetBufferHandle(), ib, 7, VK_INDEX_TYPE_UINT16);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008656
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008657 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06008658
Chia-I Wuf7458c52015-10-26 21:10:41 +08008659 vkDestroyBuffer(m_device->device(), ib, NULL);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008660}
8661
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07008662TEST_F(VkLayerTest, InvalidQueueFamilyIndex) {
8663 // Create an out-of-range queueFamilyIndex
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008664 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8665 "vkCreateBuffer: pCreateInfo->pQueueFamilyIndices[0] (777) must be one "
8666 "of the indices specified when the device was created, via the "
8667 "VkDeviceQueueCreateInfo structure.");
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07008668
8669 ASSERT_NO_FATAL_FAILURE(InitState());
8670 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8671 VkBufferCreateInfo buffCI = {};
8672 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
8673 buffCI.size = 1024;
8674 buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
8675 buffCI.queueFamilyIndexCount = 1;
8676 // Introduce failure by specifying invalid queue_family_index
8677 uint32_t qfi = 777;
8678 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis24aab042016-03-24 10:54:18 -06008679 buffCI.sharingMode = VK_SHARING_MODE_CONCURRENT; // qfi only matters in CONCURRENT mode
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07008680
8681 VkBuffer ib;
8682 vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
8683
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008684 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06008685 vkDestroyBuffer(m_device->device(), ib, NULL);
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07008686}
8687
Karl Schultz6addd812016-02-02 17:17:23 -07008688TEST_F(VkLayerTest, ExecuteCommandsPrimaryCB) {
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -06008689TEST_DESCRIPTION("Attempt vkCmdExecuteCommands with a primary command buffer"
Tobin Ehlis0c94db02016-07-19 10:49:32 -06008690 " (should only be secondary)");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008691
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06008692 ASSERT_NO_FATAL_FAILURE(InitState());
8693 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06008694
Chris Forbesf29a84f2016-10-06 18:39:28 +13008695 // An empty primary command buffer
8696 VkCommandBufferObj cb(m_device, m_commandPool);
8697 cb.BeginCommandBuffer();
8698 cb.EndCommandBuffer();
Tobin Ehlis0c94db02016-07-19 10:49:32 -06008699
Chris Forbesf29a84f2016-10-06 18:39:28 +13008700 m_commandBuffer->BeginCommandBuffer();
8701 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
8702 VkCommandBuffer handle = cb.handle();
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06008703
Chris Forbesf29a84f2016-10-06 18:39:28 +13008704 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdExecuteCommands() called w/ Primary Cmd Buffer ");
8705 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &handle);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008706 m_errorMonitor->VerifyFound();
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06008707}
8708
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008709TEST_F(VkLayerTest, DSUsageBitsErrors) {
8710 TEST_DESCRIPTION("Attempt to update descriptor sets for images and buffers "
8711 "that do not have correct usage bits sets.");
8712 VkResult err;
8713
8714 ASSERT_NO_FATAL_FAILURE(InitState());
8715 VkDescriptorPoolSize ds_type_count[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
8716 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
8717 ds_type_count[i].type = VkDescriptorType(i);
8718 ds_type_count[i].descriptorCount = 1;
8719 }
8720 VkDescriptorPoolCreateInfo ds_pool_ci = {};
8721 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8722 ds_pool_ci.pNext = NULL;
8723 ds_pool_ci.maxSets = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
8724 ds_pool_ci.poolSizeCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
8725 ds_pool_ci.pPoolSizes = ds_type_count;
8726
8727 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008728 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008729 ASSERT_VK_SUCCESS(err);
8730
8731 // Create 10 layouts where each has a single descriptor of different type
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008732 VkDescriptorSetLayoutBinding dsl_binding[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008733 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
8734 dsl_binding[i].binding = 0;
8735 dsl_binding[i].descriptorType = VkDescriptorType(i);
8736 dsl_binding[i].descriptorCount = 1;
8737 dsl_binding[i].stageFlags = VK_SHADER_STAGE_ALL;
8738 dsl_binding[i].pImmutableSamplers = NULL;
8739 }
8740
8741 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
8742 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8743 ds_layout_ci.pNext = NULL;
8744 ds_layout_ci.bindingCount = 1;
8745 VkDescriptorSetLayout ds_layouts[VK_DESCRIPTOR_TYPE_RANGE_SIZE];
8746 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
8747 ds_layout_ci.pBindings = dsl_binding + i;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008748 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, ds_layouts + i);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008749 ASSERT_VK_SUCCESS(err);
8750 }
8751 VkDescriptorSet descriptor_sets[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
8752 VkDescriptorSetAllocateInfo alloc_info = {};
8753 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
8754 alloc_info.descriptorSetCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
8755 alloc_info.descriptorPool = ds_pool;
8756 alloc_info.pSetLayouts = ds_layouts;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008757 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptor_sets);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008758 ASSERT_VK_SUCCESS(err);
8759
8760 // Create a buffer & bufferView to be used for invalid updates
8761 VkBufferCreateInfo buff_ci = {};
8762 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
8763 // This usage is not valid for any descriptor type
8764 buff_ci.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
8765 buff_ci.size = 256;
8766 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
8767 VkBuffer buffer;
8768 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
8769 ASSERT_VK_SUCCESS(err);
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07008770 VkMemoryRequirements mem_reqs;
8771 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
8772 VkMemoryAllocateInfo mem_alloc_info = {};
8773 mem_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
8774 mem_alloc_info.pNext = NULL;
8775 mem_alloc_info.memoryTypeIndex = 0;
8776 mem_alloc_info.allocationSize = mem_reqs.size;
8777 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc_info, 0);
8778 if (!pass) {
8779 vkDestroyBuffer(m_device->device(), buffer, NULL);
8780 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
8781 return;
8782 }
8783 VkDeviceMemory mem;
8784 err = vkAllocateMemory(m_device->device(), &mem_alloc_info, NULL, &mem);
8785 ASSERT_VK_SUCCESS(err);
8786 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
8787 ASSERT_VK_SUCCESS(err);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008788
8789 VkBufferViewCreateInfo buff_view_ci = {};
8790 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
8791 buff_view_ci.buffer = buffer;
8792 buff_view_ci.format = VK_FORMAT_R8_UNORM;
8793 buff_view_ci.range = VK_WHOLE_SIZE;
8794 VkBufferView buff_view;
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07008795 // Note that this hits VALIDATION_ERROR_00694 due to no usage bit set, but we want call to go through
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008796 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buff_view);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008797 ASSERT_VK_SUCCESS(err);
8798
8799 // Create an image to be used for invalid updates
8800 VkImageCreateInfo image_ci = {};
8801 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
8802 image_ci.imageType = VK_IMAGE_TYPE_2D;
8803 image_ci.format = VK_FORMAT_R8G8B8A8_UNORM;
8804 image_ci.extent.width = 64;
8805 image_ci.extent.height = 64;
8806 image_ci.extent.depth = 1;
8807 image_ci.mipLevels = 1;
8808 image_ci.arrayLayers = 1;
8809 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
8810 image_ci.tiling = VK_IMAGE_TILING_LINEAR;
8811 image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
8812 // This usage is not valid for any descriptor type
8813 image_ci.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
8814 image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
8815 VkImage image;
8816 err = vkCreateImage(m_device->device(), &image_ci, NULL, &image);
8817 ASSERT_VK_SUCCESS(err);
8818 // Bind memory to image
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008819 VkDeviceMemory image_mem;
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07008820
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008821 VkMemoryAllocateInfo mem_alloc = {};
8822 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
8823 mem_alloc.pNext = NULL;
8824 mem_alloc.allocationSize = 0;
8825 mem_alloc.memoryTypeIndex = 0;
8826 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
8827 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008828 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008829 ASSERT_TRUE(pass);
8830 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
8831 ASSERT_VK_SUCCESS(err);
8832 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
8833 ASSERT_VK_SUCCESS(err);
8834 // Now create view for image
8835 VkImageViewCreateInfo image_view_ci = {};
8836 image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
8837 image_view_ci.image = image;
8838 image_view_ci.format = VK_FORMAT_R8G8B8A8_UNORM;
8839 image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D;
8840 image_view_ci.subresourceRange.layerCount = 1;
8841 image_view_ci.subresourceRange.baseArrayLayer = 0;
8842 image_view_ci.subresourceRange.levelCount = 1;
8843 image_view_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8844 VkImageView image_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008845 err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, &image_view);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008846 ASSERT_VK_SUCCESS(err);
8847
8848 VkDescriptorBufferInfo buff_info = {};
8849 buff_info.buffer = buffer;
8850 VkDescriptorImageInfo img_info = {};
8851 img_info.imageView = image_view;
8852 VkWriteDescriptorSet descriptor_write = {};
8853 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
8854 descriptor_write.dstBinding = 0;
8855 descriptor_write.descriptorCount = 1;
8856 descriptor_write.pTexelBufferView = &buff_view;
8857 descriptor_write.pBufferInfo = &buff_info;
8858 descriptor_write.pImageInfo = &img_info;
8859
8860 // These error messages align with VkDescriptorType struct
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07008861 UNIQUE_VALIDATION_ERROR_CODE error_codes[] = {
8862 VALIDATION_ERROR_00943, // placeholder, no error for SAMPLER descriptor
8863 VALIDATION_ERROR_00943, // COMBINED_IMAGE_SAMPLER
8864 VALIDATION_ERROR_00943, // SAMPLED_IMAGE
8865 VALIDATION_ERROR_00943, // STORAGE_IMAGE
8866 VALIDATION_ERROR_00950, // UNIFORM_TEXEL_BUFFER
8867 VALIDATION_ERROR_00951, // STORAGE_TEXEL_BUFFER
8868 VALIDATION_ERROR_00946, // UNIFORM_BUFFER
8869 VALIDATION_ERROR_00947, // STORAGE_BUFFER
8870 VALIDATION_ERROR_00946, // UNIFORM_BUFFER_DYNAMIC
8871 VALIDATION_ERROR_00947, // STORAGE_BUFFER_DYNAMIC
8872 VALIDATION_ERROR_00943 // INPUT_ATTACHMENT
8873 };
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008874 // Start loop at 1 as SAMPLER desc type has no usage bit error
8875 for (uint32_t i = 1; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
8876 descriptor_write.descriptorType = VkDescriptorType(i);
8877 descriptor_write.dstSet = descriptor_sets[i];
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07008878 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, error_codes[i]);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008879
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008880 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008881
8882 m_errorMonitor->VerifyFound();
8883 vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[i], NULL);
8884 }
8885 vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[0], NULL);
8886 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06008887 vkFreeMemory(m_device->device(), image_mem, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008888 vkDestroyImageView(m_device->device(), image_view, NULL);
8889 vkDestroyBuffer(m_device->device(), buffer, NULL);
8890 vkDestroyBufferView(m_device->device(), buff_view, NULL);
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07008891 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008892 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
8893}
8894
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008895TEST_F(VkLayerTest, DSBufferInfoErrors) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008896 TEST_DESCRIPTION("Attempt to update buffer descriptor set that has incorrect "
8897 "parameters in VkDescriptorBufferInfo struct. This includes:\n"
8898 "1. offset value greater than buffer size\n"
8899 "2. range value of 0\n"
8900 "3. range value greater than buffer (size - offset)");
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008901 VkResult err;
8902
8903 ASSERT_NO_FATAL_FAILURE(InitState());
8904 VkDescriptorPoolSize ds_type_count = {};
8905 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8906 ds_type_count.descriptorCount = 1;
8907
8908 VkDescriptorPoolCreateInfo ds_pool_ci = {};
8909 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8910 ds_pool_ci.pNext = NULL;
8911 ds_pool_ci.maxSets = 1;
8912 ds_pool_ci.poolSizeCount = 1;
8913 ds_pool_ci.pPoolSizes = &ds_type_count;
8914
8915 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008916 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008917 ASSERT_VK_SUCCESS(err);
8918
8919 // Create layout with single uniform buffer descriptor
8920 VkDescriptorSetLayoutBinding dsl_binding = {};
8921 dsl_binding.binding = 0;
8922 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8923 dsl_binding.descriptorCount = 1;
8924 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8925 dsl_binding.pImmutableSamplers = NULL;
8926
8927 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
8928 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8929 ds_layout_ci.pNext = NULL;
8930 ds_layout_ci.bindingCount = 1;
8931 ds_layout_ci.pBindings = &dsl_binding;
8932 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008933 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008934 ASSERT_VK_SUCCESS(err);
8935
8936 VkDescriptorSet descriptor_set = {};
8937 VkDescriptorSetAllocateInfo alloc_info = {};
8938 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
8939 alloc_info.descriptorSetCount = 1;
8940 alloc_info.descriptorPool = ds_pool;
8941 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008942 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008943 ASSERT_VK_SUCCESS(err);
8944
8945 // Create a buffer to be used for invalid updates
8946 VkBufferCreateInfo buff_ci = {};
8947 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
8948 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
8949 buff_ci.size = 256;
8950 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
8951 VkBuffer buffer;
8952 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
8953 ASSERT_VK_SUCCESS(err);
8954 // Have to bind memory to buffer before descriptor update
8955 VkMemoryAllocateInfo mem_alloc = {};
8956 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
8957 mem_alloc.pNext = NULL;
8958 mem_alloc.allocationSize = 256;
8959 mem_alloc.memoryTypeIndex = 0;
8960
8961 VkMemoryRequirements mem_reqs;
8962 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008963 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008964 if (!pass) {
8965 vkDestroyBuffer(m_device->device(), buffer, NULL);
8966 return;
8967 }
8968
8969 VkDeviceMemory mem;
8970 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
8971 ASSERT_VK_SUCCESS(err);
8972 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
8973 ASSERT_VK_SUCCESS(err);
8974
8975 VkDescriptorBufferInfo buff_info = {};
8976 buff_info.buffer = buffer;
8977 // First make offset 1 larger than buffer size
8978 buff_info.offset = 257;
8979 buff_info.range = VK_WHOLE_SIZE;
8980 VkWriteDescriptorSet descriptor_write = {};
8981 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
8982 descriptor_write.dstBinding = 0;
8983 descriptor_write.descriptorCount = 1;
8984 descriptor_write.pTexelBufferView = nullptr;
8985 descriptor_write.pBufferInfo = &buff_info;
8986 descriptor_write.pImageInfo = nullptr;
8987
8988 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8989 descriptor_write.dstSet = descriptor_set;
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07008990 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00959);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008991
8992 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8993
8994 m_errorMonitor->VerifyFound();
8995 // Now cause error due to range of 0
8996 buff_info.offset = 0;
8997 buff_info.range = 0;
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07008998 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00960);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008999
9000 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9001
9002 m_errorMonitor->VerifyFound();
9003 // Now cause error due to range exceeding buffer size - offset
9004 buff_info.offset = 128;
9005 buff_info.range = 200;
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07009006 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00961);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009007
9008 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9009
9010 m_errorMonitor->VerifyFound();
Mark Lobodzinski4bb54092016-07-06 14:27:19 -06009011 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009012 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9013 vkDestroyBuffer(m_device->device(), buffer, NULL);
9014 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
9015 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9016}
9017
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009018TEST_F(VkLayerTest, DSAspectBitsErrors) {
9019 // TODO : Initially only catching case where DEPTH & STENCIL aspect bits
9020 // are set, but could expand this test to hit more cases.
9021 TEST_DESCRIPTION("Attempt to update descriptor sets for images "
9022 "that do not have correct aspect bits sets.");
9023 VkResult err;
9024
9025 ASSERT_NO_FATAL_FAILURE(InitState());
9026 VkDescriptorPoolSize ds_type_count = {};
9027 ds_type_count.type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
9028 ds_type_count.descriptorCount = 1;
9029
9030 VkDescriptorPoolCreateInfo ds_pool_ci = {};
9031 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9032 ds_pool_ci.pNext = NULL;
9033 ds_pool_ci.maxSets = 5;
9034 ds_pool_ci.poolSizeCount = 1;
9035 ds_pool_ci.pPoolSizes = &ds_type_count;
9036
9037 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009038 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009039 ASSERT_VK_SUCCESS(err);
9040
9041 VkDescriptorSetLayoutBinding dsl_binding = {};
9042 dsl_binding.binding = 0;
9043 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
9044 dsl_binding.descriptorCount = 1;
9045 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9046 dsl_binding.pImmutableSamplers = NULL;
9047
9048 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9049 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9050 ds_layout_ci.pNext = NULL;
9051 ds_layout_ci.bindingCount = 1;
9052 ds_layout_ci.pBindings = &dsl_binding;
9053 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009054 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009055 ASSERT_VK_SUCCESS(err);
9056
9057 VkDescriptorSet descriptor_set = {};
9058 VkDescriptorSetAllocateInfo alloc_info = {};
9059 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
9060 alloc_info.descriptorSetCount = 1;
9061 alloc_info.descriptorPool = ds_pool;
9062 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009063 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009064 ASSERT_VK_SUCCESS(err);
9065
9066 // Create an image to be used for invalid updates
9067 VkImageCreateInfo image_ci = {};
9068 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
9069 image_ci.imageType = VK_IMAGE_TYPE_2D;
9070 image_ci.format = VK_FORMAT_D24_UNORM_S8_UINT;
9071 image_ci.extent.width = 64;
9072 image_ci.extent.height = 64;
9073 image_ci.extent.depth = 1;
9074 image_ci.mipLevels = 1;
9075 image_ci.arrayLayers = 1;
9076 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
9077 image_ci.tiling = VK_IMAGE_TILING_LINEAR;
9078 image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
9079 image_ci.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
9080 image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
9081 VkImage image;
9082 err = vkCreateImage(m_device->device(), &image_ci, NULL, &image);
9083 ASSERT_VK_SUCCESS(err);
9084 // Bind memory to image
9085 VkMemoryRequirements mem_reqs;
9086 VkDeviceMemory image_mem;
9087 bool pass;
9088 VkMemoryAllocateInfo mem_alloc = {};
9089 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
9090 mem_alloc.pNext = NULL;
9091 mem_alloc.allocationSize = 0;
9092 mem_alloc.memoryTypeIndex = 0;
9093 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
9094 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009095 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009096 ASSERT_TRUE(pass);
9097 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
9098 ASSERT_VK_SUCCESS(err);
9099 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
9100 ASSERT_VK_SUCCESS(err);
9101 // Now create view for image
9102 VkImageViewCreateInfo image_view_ci = {};
9103 image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
9104 image_view_ci.image = image;
9105 image_view_ci.format = VK_FORMAT_D24_UNORM_S8_UINT;
9106 image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D;
9107 image_view_ci.subresourceRange.layerCount = 1;
9108 image_view_ci.subresourceRange.baseArrayLayer = 0;
9109 image_view_ci.subresourceRange.levelCount = 1;
9110 // Setting both depth & stencil aspect bits is illegal for descriptor
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009111 image_view_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009112
9113 VkImageView image_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009114 err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, &image_view);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009115 ASSERT_VK_SUCCESS(err);
9116
9117 VkDescriptorImageInfo img_info = {};
9118 img_info.imageView = image_view;
9119 VkWriteDescriptorSet descriptor_write = {};
9120 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
9121 descriptor_write.dstBinding = 0;
9122 descriptor_write.descriptorCount = 1;
9123 descriptor_write.pTexelBufferView = NULL;
9124 descriptor_write.pBufferInfo = NULL;
9125 descriptor_write.pImageInfo = &img_info;
9126 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
9127 descriptor_write.dstSet = descriptor_set;
9128 const char *error_msg = " please only set either VK_IMAGE_ASPECT_DEPTH_BIT "
9129 "or VK_IMAGE_ASPECT_STENCIL_BIT ";
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009130 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, error_msg);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009131
9132 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9133
9134 m_errorMonitor->VerifyFound();
9135 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9136 vkDestroyImage(m_device->device(), image, NULL);
9137 vkFreeMemory(m_device->device(), image_mem, NULL);
9138 vkDestroyImageView(m_device->device(), image_view, NULL);
9139 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
9140 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9141}
9142
Karl Schultz6addd812016-02-02 17:17:23 -07009143TEST_F(VkLayerTest, DSTypeMismatch) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009144 // Create DS w/ layout of one type and attempt Update w/ mis-matched type
Karl Schultz6addd812016-02-02 17:17:23 -07009145 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009146
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009147 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9148 " binding #0 with type VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER but update "
9149 "type is VK_DESCRIPTOR_TYPE_SAMPLER");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009150
Tobin Ehlis3b780662015-05-28 12:11:26 -06009151 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07009152 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009153 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009154 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9155 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009156
9157 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009158 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9159 ds_pool_ci.pNext = NULL;
9160 ds_pool_ci.maxSets = 1;
9161 ds_pool_ci.poolSizeCount = 1;
9162 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06009163
Tobin Ehlis3b780662015-05-28 12:11:26 -06009164 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009165 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009166 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -06009167 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009168 dsl_binding.binding = 0;
9169 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9170 dsl_binding.descriptorCount = 1;
9171 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9172 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009173
Tony Barboureb254902015-07-15 12:50:33 -06009174 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009175 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9176 ds_layout_ci.pNext = NULL;
9177 ds_layout_ci.bindingCount = 1;
9178 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06009179
Tobin Ehlis3b780662015-05-28 12:11:26 -06009180 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009181 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009182 ASSERT_VK_SUCCESS(err);
9183
9184 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009185 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009186 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009187 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009188 alloc_info.descriptorPool = ds_pool;
9189 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009190 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009191 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009192
Tobin Ehlis30db8f82016-05-05 08:19:48 -06009193 VkSamplerCreateInfo sampler_ci = {};
9194 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9195 sampler_ci.pNext = NULL;
9196 sampler_ci.magFilter = VK_FILTER_NEAREST;
9197 sampler_ci.minFilter = VK_FILTER_NEAREST;
9198 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9199 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9200 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9201 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9202 sampler_ci.mipLodBias = 1.0;
9203 sampler_ci.anisotropyEnable = VK_FALSE;
9204 sampler_ci.maxAnisotropy = 1;
9205 sampler_ci.compareEnable = VK_FALSE;
9206 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9207 sampler_ci.minLod = 1.0;
9208 sampler_ci.maxLod = 1.0;
9209 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9210 sampler_ci.unnormalizedCoordinates = VK_FALSE;
9211 VkSampler sampler;
9212 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
9213 ASSERT_VK_SUCCESS(err);
9214
9215 VkDescriptorImageInfo info = {};
9216 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009217
9218 VkWriteDescriptorSet descriptor_write;
9219 memset(&descriptor_write, 0, sizeof(descriptor_write));
9220 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009221 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009222 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009223 // This is a mismatched type for the layout which expects BUFFER
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009224 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06009225 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009226
9227 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9228
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009229 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009230
Chia-I Wuf7458c52015-10-26 21:10:41 +08009231 vkDestroySampler(m_device->device(), sampler, NULL);
9232 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9233 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009234}
9235
Karl Schultz6addd812016-02-02 17:17:23 -07009236TEST_F(VkLayerTest, DSUpdateOutOfBounds) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009237 // For overlapping Update, have arrayIndex exceed that of layout
Karl Schultz6addd812016-02-02 17:17:23 -07009238 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009239
Tobin Ehlisf922ef82016-11-30 10:19:14 -07009240 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00938);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009241
Tobin Ehlis3b780662015-05-28 12:11:26 -06009242 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07009243 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009244 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009245 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9246 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009247
9248 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009249 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9250 ds_pool_ci.pNext = NULL;
9251 ds_pool_ci.maxSets = 1;
9252 ds_pool_ci.poolSizeCount = 1;
9253 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06009254
Tobin Ehlis3b780662015-05-28 12:11:26 -06009255 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009256 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009257 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009258
Tony Barboureb254902015-07-15 12:50:33 -06009259 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009260 dsl_binding.binding = 0;
9261 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9262 dsl_binding.descriptorCount = 1;
9263 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9264 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -06009265
9266 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009267 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9268 ds_layout_ci.pNext = NULL;
9269 ds_layout_ci.bindingCount = 1;
9270 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06009271
Tobin Ehlis3b780662015-05-28 12:11:26 -06009272 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009273 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009274 ASSERT_VK_SUCCESS(err);
9275
9276 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009277 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009278 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009279 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009280 alloc_info.descriptorPool = ds_pool;
9281 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009282 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009283 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009284
Tobin Ehlis30db8f82016-05-05 08:19:48 -06009285 // Correctly update descriptor to avoid "NOT_UPDATED" error
9286 VkDescriptorBufferInfo buff_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009287 buff_info.buffer = VkBuffer(0); // Don't care about buffer handle for this test
Tobin Ehlis30db8f82016-05-05 08:19:48 -06009288 buff_info.offset = 0;
9289 buff_info.range = 1024;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009290
9291 VkWriteDescriptorSet descriptor_write;
9292 memset(&descriptor_write, 0, sizeof(descriptor_write));
9293 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009294 descriptor_write.dstSet = descriptorSet;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009295 descriptor_write.dstArrayElement = 1; /* This index out of bounds for the update */
Chia-I Wud50a7d72015-10-26 20:48:51 +08009296 descriptor_write.descriptorCount = 1;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06009297 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9298 descriptor_write.pBufferInfo = &buff_info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009299
9300 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9301
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009302 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009303
Chia-I Wuf7458c52015-10-26 21:10:41 +08009304 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9305 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009306}
9307
Karl Schultz6addd812016-02-02 17:17:23 -07009308TEST_F(VkLayerTest, InvalidDSUpdateIndex) {
Tobin Ehlisc8d352d2016-11-21 10:33:40 -07009309 // Create layout w/ count of 1 and attempt update to that layout w/ binding index 2
Karl Schultz6addd812016-02-02 17:17:23 -07009310 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009311
Tobin Ehlisc8d352d2016-11-21 10:33:40 -07009312 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00936);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009313
Tobin Ehlis3b780662015-05-28 12:11:26 -06009314 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07009315 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009316 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009317 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9318 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009319
9320 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009321 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9322 ds_pool_ci.pNext = NULL;
9323 ds_pool_ci.maxSets = 1;
9324 ds_pool_ci.poolSizeCount = 1;
9325 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06009326
Tobin Ehlis3b780662015-05-28 12:11:26 -06009327 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009328 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009329 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009330
Tony Barboureb254902015-07-15 12:50:33 -06009331 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009332 dsl_binding.binding = 0;
9333 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9334 dsl_binding.descriptorCount = 1;
9335 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9336 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -06009337
9338 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009339 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9340 ds_layout_ci.pNext = NULL;
9341 ds_layout_ci.bindingCount = 1;
9342 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009343 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009344 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009345 ASSERT_VK_SUCCESS(err);
9346
9347 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009348 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009349 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009350 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009351 alloc_info.descriptorPool = ds_pool;
9352 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009353 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009354 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009355
Tony Barboureb254902015-07-15 12:50:33 -06009356 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009357 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9358 sampler_ci.pNext = NULL;
9359 sampler_ci.magFilter = VK_FILTER_NEAREST;
9360 sampler_ci.minFilter = VK_FILTER_NEAREST;
9361 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9362 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9363 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9364 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9365 sampler_ci.mipLodBias = 1.0;
9366 sampler_ci.anisotropyEnable = VK_FALSE;
9367 sampler_ci.maxAnisotropy = 1;
9368 sampler_ci.compareEnable = VK_FALSE;
9369 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9370 sampler_ci.minLod = 1.0;
9371 sampler_ci.maxLod = 1.0;
9372 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9373 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tony Barboureb254902015-07-15 12:50:33 -06009374
Tobin Ehlis3b780662015-05-28 12:11:26 -06009375 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009376 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009377 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009378
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06009379 VkDescriptorImageInfo info = {};
9380 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009381
9382 VkWriteDescriptorSet descriptor_write;
9383 memset(&descriptor_write, 0, sizeof(descriptor_write));
9384 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009385 descriptor_write.dstSet = descriptorSet;
9386 descriptor_write.dstBinding = 2;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009387 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009388 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009389 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06009390 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009391
9392 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9393
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009394 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009395
Chia-I Wuf7458c52015-10-26 21:10:41 +08009396 vkDestroySampler(m_device->device(), sampler, NULL);
9397 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9398 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009399}
9400
Tobin Ehlise202b2d2016-11-21 10:36:16 -07009401TEST_F(VkLayerTest, DSUpdateEmptyBinding) {
9402 // Create layout w/ empty binding and attempt to update it
9403 VkResult err;
9404
9405 ASSERT_NO_FATAL_FAILURE(InitState());
9406
9407 VkDescriptorPoolSize ds_type_count = {};
9408 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
9409 ds_type_count.descriptorCount = 1;
9410
9411 VkDescriptorPoolCreateInfo ds_pool_ci = {};
9412 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9413 ds_pool_ci.pNext = NULL;
9414 ds_pool_ci.maxSets = 1;
9415 ds_pool_ci.poolSizeCount = 1;
9416 ds_pool_ci.pPoolSizes = &ds_type_count;
9417
9418 VkDescriptorPool ds_pool;
9419 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
9420 ASSERT_VK_SUCCESS(err);
9421
9422 VkDescriptorSetLayoutBinding dsl_binding = {};
9423 dsl_binding.binding = 0;
9424 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9425 dsl_binding.descriptorCount = 0;
9426 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9427 dsl_binding.pImmutableSamplers = NULL;
9428
9429 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9430 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9431 ds_layout_ci.pNext = NULL;
9432 ds_layout_ci.bindingCount = 1;
9433 ds_layout_ci.pBindings = &dsl_binding;
9434 VkDescriptorSetLayout ds_layout;
9435 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
9436 ASSERT_VK_SUCCESS(err);
9437
9438 VkDescriptorSet descriptor_set;
9439 VkDescriptorSetAllocateInfo alloc_info = {};
9440 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
9441 alloc_info.descriptorSetCount = 1;
9442 alloc_info.descriptorPool = ds_pool;
9443 alloc_info.pSetLayouts = &ds_layout;
9444 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
9445 ASSERT_VK_SUCCESS(err);
9446
9447 VkSamplerCreateInfo sampler_ci = {};
9448 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9449 sampler_ci.magFilter = VK_FILTER_NEAREST;
9450 sampler_ci.minFilter = VK_FILTER_NEAREST;
9451 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9452 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9453 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9454 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9455 sampler_ci.mipLodBias = 1.0;
9456 sampler_ci.maxAnisotropy = 1;
9457 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9458 sampler_ci.minLod = 1.0;
9459 sampler_ci.maxLod = 1.0;
9460 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9461
9462 VkSampler sampler;
9463 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
9464 ASSERT_VK_SUCCESS(err);
9465
9466 VkDescriptorImageInfo info = {};
9467 info.sampler = sampler;
9468
9469 VkWriteDescriptorSet descriptor_write;
9470 memset(&descriptor_write, 0, sizeof(descriptor_write));
9471 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
9472 descriptor_write.dstSet = descriptor_set;
9473 descriptor_write.dstBinding = 0;
9474 descriptor_write.descriptorCount = 1; // Lie here to avoid parameter_validation error
9475 // This is the wrong type, but empty binding error will be flagged first
9476 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9477 descriptor_write.pImageInfo = &info;
9478
9479 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02348);
9480 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9481 m_errorMonitor->VerifyFound();
9482
9483 vkDestroySampler(m_device->device(), sampler, NULL);
9484 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9485 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9486}
9487
Karl Schultz6addd812016-02-02 17:17:23 -07009488TEST_F(VkLayerTest, InvalidDSUpdateStruct) {
9489 // Call UpdateDS w/ struct type other than valid VK_STRUCTUR_TYPE_UPDATE_*
9490 // types
9491 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009492
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009493 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 -06009494
Tobin Ehlis3b780662015-05-28 12:11:26 -06009495 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski209b5292015-09-17 09:44:05 -06009496
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009497 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009498 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9499 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009500
9501 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009502 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9503 ds_pool_ci.pNext = NULL;
9504 ds_pool_ci.maxSets = 1;
9505 ds_pool_ci.poolSizeCount = 1;
9506 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06009507
Tobin Ehlis3b780662015-05-28 12:11:26 -06009508 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009509 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009510 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -06009511 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009512 dsl_binding.binding = 0;
9513 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9514 dsl_binding.descriptorCount = 1;
9515 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9516 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009517
Tony Barboureb254902015-07-15 12:50:33 -06009518 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009519 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9520 ds_layout_ci.pNext = NULL;
9521 ds_layout_ci.bindingCount = 1;
9522 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06009523
Tobin Ehlis3b780662015-05-28 12:11:26 -06009524 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009525 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009526 ASSERT_VK_SUCCESS(err);
9527
9528 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009529 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009530 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009531 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009532 alloc_info.descriptorPool = ds_pool;
9533 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009534 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009535 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009536
Tony Barboureb254902015-07-15 12:50:33 -06009537 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009538 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9539 sampler_ci.pNext = NULL;
9540 sampler_ci.magFilter = VK_FILTER_NEAREST;
9541 sampler_ci.minFilter = VK_FILTER_NEAREST;
9542 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9543 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9544 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9545 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9546 sampler_ci.mipLodBias = 1.0;
9547 sampler_ci.anisotropyEnable = VK_FALSE;
9548 sampler_ci.maxAnisotropy = 1;
9549 sampler_ci.compareEnable = VK_FALSE;
9550 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9551 sampler_ci.minLod = 1.0;
9552 sampler_ci.maxLod = 1.0;
9553 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9554 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009555 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009556 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009557 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009558
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06009559 VkDescriptorImageInfo info = {};
9560 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009561
9562 VkWriteDescriptorSet descriptor_write;
9563 memset(&descriptor_write, 0, sizeof(descriptor_write));
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009564 descriptor_write.sType = (VkStructureType)0x99999999; /* Intentionally broken struct type */
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009565 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009566 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009567 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009568 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06009569 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009570
9571 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9572
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009573 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009574
Chia-I Wuf7458c52015-10-26 21:10:41 +08009575 vkDestroySampler(m_device->device(), sampler, NULL);
9576 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9577 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009578}
9579
Karl Schultz6addd812016-02-02 17:17:23 -07009580TEST_F(VkLayerTest, SampleDescriptorUpdateError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009581 // Create a single Sampler descriptor and send it an invalid Sampler
Karl Schultz6addd812016-02-02 17:17:23 -07009582 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009583
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07009584 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00942);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009585
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009586 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07009587 // TODO : Farm Descriptor setup code to helper function(s) to reduce copied
9588 // code
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009589 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009590 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
9591 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009592
9593 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009594 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9595 ds_pool_ci.pNext = NULL;
9596 ds_pool_ci.maxSets = 1;
9597 ds_pool_ci.poolSizeCount = 1;
9598 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009599
9600 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009601 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009602 ASSERT_VK_SUCCESS(err);
9603
9604 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009605 dsl_binding.binding = 0;
9606 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9607 dsl_binding.descriptorCount = 1;
9608 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9609 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009610
9611 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009612 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9613 ds_layout_ci.pNext = NULL;
9614 ds_layout_ci.bindingCount = 1;
9615 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009616 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009617 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009618 ASSERT_VK_SUCCESS(err);
9619
9620 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009621 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009622 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009623 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009624 alloc_info.descriptorPool = ds_pool;
9625 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009626 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009627 ASSERT_VK_SUCCESS(err);
9628
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009629 VkSampler sampler = (VkSampler)((size_t)0xbaadbeef); // Sampler with invalid handle
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009630
9631 VkDescriptorImageInfo descriptor_info;
9632 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
9633 descriptor_info.sampler = sampler;
9634
9635 VkWriteDescriptorSet descriptor_write;
9636 memset(&descriptor_write, 0, sizeof(descriptor_write));
9637 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009638 descriptor_write.dstSet = descriptorSet;
9639 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009640 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009641 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9642 descriptor_write.pImageInfo = &descriptor_info;
9643
9644 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9645
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009646 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009647
Chia-I Wuf7458c52015-10-26 21:10:41 +08009648 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9649 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009650}
9651
Karl Schultz6addd812016-02-02 17:17:23 -07009652TEST_F(VkLayerTest, ImageViewDescriptorUpdateError) {
9653 // Create a single combined Image/Sampler descriptor and send it an invalid
9654 // imageView
9655 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009656
Karl Schultzf78bcdd2016-11-30 12:36:01 -07009657 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00943);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009658
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009659 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009660 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009661 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
9662 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009663
9664 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009665 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9666 ds_pool_ci.pNext = NULL;
9667 ds_pool_ci.maxSets = 1;
9668 ds_pool_ci.poolSizeCount = 1;
9669 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009670
9671 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009672 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009673 ASSERT_VK_SUCCESS(err);
9674
9675 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009676 dsl_binding.binding = 0;
9677 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
9678 dsl_binding.descriptorCount = 1;
9679 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9680 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009681
9682 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009683 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9684 ds_layout_ci.pNext = NULL;
9685 ds_layout_ci.bindingCount = 1;
9686 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009687 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009688 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009689 ASSERT_VK_SUCCESS(err);
9690
9691 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009692 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009693 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009694 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009695 alloc_info.descriptorPool = ds_pool;
9696 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009697 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009698 ASSERT_VK_SUCCESS(err);
9699
9700 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009701 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9702 sampler_ci.pNext = NULL;
9703 sampler_ci.magFilter = VK_FILTER_NEAREST;
9704 sampler_ci.minFilter = VK_FILTER_NEAREST;
9705 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9706 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9707 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9708 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9709 sampler_ci.mipLodBias = 1.0;
9710 sampler_ci.anisotropyEnable = VK_FALSE;
9711 sampler_ci.maxAnisotropy = 1;
9712 sampler_ci.compareEnable = VK_FALSE;
9713 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9714 sampler_ci.minLod = 1.0;
9715 sampler_ci.maxLod = 1.0;
9716 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9717 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009718
9719 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009720 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009721 ASSERT_VK_SUCCESS(err);
9722
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009723 VkImageView view = (VkImageView)((size_t)0xbaadbeef); // invalid imageView object
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009724
9725 VkDescriptorImageInfo descriptor_info;
9726 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
9727 descriptor_info.sampler = sampler;
9728 descriptor_info.imageView = view;
9729
9730 VkWriteDescriptorSet descriptor_write;
9731 memset(&descriptor_write, 0, sizeof(descriptor_write));
9732 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009733 descriptor_write.dstSet = descriptorSet;
9734 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009735 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009736 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
9737 descriptor_write.pImageInfo = &descriptor_info;
9738
9739 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9740
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009741 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009742
Chia-I Wuf7458c52015-10-26 21:10:41 +08009743 vkDestroySampler(m_device->device(), sampler, NULL);
9744 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9745 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009746}
9747
Karl Schultz6addd812016-02-02 17:17:23 -07009748TEST_F(VkLayerTest, CopyDescriptorUpdateErrors) {
9749 // Create DS w/ layout of 2 types, write update 1 and attempt to copy-update
9750 // into the other
9751 VkResult err;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009752
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009753 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " binding #1 with type "
9754 "VK_DESCRIPTOR_TYPE_SAMPLER. Types do "
9755 "not match.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009756
Tobin Ehlis04356f92015-10-27 16:35:27 -06009757 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07009758 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009759 VkDescriptorPoolSize ds_type_count[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009760 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9761 ds_type_count[0].descriptorCount = 1;
9762 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLER;
9763 ds_type_count[1].descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009764
9765 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009766 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9767 ds_pool_ci.pNext = NULL;
9768 ds_pool_ci.maxSets = 1;
9769 ds_pool_ci.poolSizeCount = 2;
9770 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009771
9772 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009773 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis04356f92015-10-27 16:35:27 -06009774 ASSERT_VK_SUCCESS(err);
9775 VkDescriptorSetLayoutBinding dsl_binding[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009776 dsl_binding[0].binding = 0;
9777 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9778 dsl_binding[0].descriptorCount = 1;
9779 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
9780 dsl_binding[0].pImmutableSamplers = NULL;
9781 dsl_binding[1].binding = 1;
9782 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9783 dsl_binding[1].descriptorCount = 1;
9784 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
9785 dsl_binding[1].pImmutableSamplers = NULL;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009786
9787 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009788 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9789 ds_layout_ci.pNext = NULL;
9790 ds_layout_ci.bindingCount = 2;
9791 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009792
9793 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009794 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis04356f92015-10-27 16:35:27 -06009795 ASSERT_VK_SUCCESS(err);
9796
9797 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009798 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009799 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009800 alloc_info.descriptorSetCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009801 alloc_info.descriptorPool = ds_pool;
9802 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009803 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis04356f92015-10-27 16:35:27 -06009804 ASSERT_VK_SUCCESS(err);
9805
9806 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009807 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9808 sampler_ci.pNext = NULL;
9809 sampler_ci.magFilter = VK_FILTER_NEAREST;
9810 sampler_ci.minFilter = VK_FILTER_NEAREST;
9811 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9812 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9813 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9814 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9815 sampler_ci.mipLodBias = 1.0;
9816 sampler_ci.anisotropyEnable = VK_FALSE;
9817 sampler_ci.maxAnisotropy = 1;
9818 sampler_ci.compareEnable = VK_FALSE;
9819 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9820 sampler_ci.minLod = 1.0;
9821 sampler_ci.maxLod = 1.0;
9822 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9823 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009824
9825 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009826 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis04356f92015-10-27 16:35:27 -06009827 ASSERT_VK_SUCCESS(err);
9828
9829 VkDescriptorImageInfo info = {};
9830 info.sampler = sampler;
9831
9832 VkWriteDescriptorSet descriptor_write;
9833 memset(&descriptor_write, 0, sizeof(VkWriteDescriptorSet));
9834 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009835 descriptor_write.dstSet = descriptorSet;
9836 descriptor_write.dstBinding = 1; // SAMPLER binding from layout above
Chia-I Wud50a7d72015-10-26 20:48:51 +08009837 descriptor_write.descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009838 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9839 descriptor_write.pImageInfo = &info;
9840 // This write update should succeed
9841 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9842 // Now perform a copy update that fails due to type mismatch
9843 VkCopyDescriptorSet copy_ds_update;
9844 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
9845 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
9846 copy_ds_update.srcSet = descriptorSet;
Mark Young29927482016-05-04 14:38:51 -06009847 copy_ds_update.srcBinding = 1; // Copy from SAMPLER binding
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009848 copy_ds_update.dstSet = descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -07009849 copy_ds_update.dstBinding = 0; // ERROR : copy to UNIFORM binding
Chia-I Wud50a7d72015-10-26 20:48:51 +08009850 copy_ds_update.descriptorCount = 1; // copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -06009851 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
9852
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009853 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -06009854 // Now perform a copy update that fails due to binding out of bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009855 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 -06009856 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
9857 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
9858 copy_ds_update.srcSet = descriptorSet;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009859 copy_ds_update.srcBinding = 3; // ERROR : Invalid binding for matching layout
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009860 copy_ds_update.dstSet = descriptorSet;
9861 copy_ds_update.dstBinding = 0;
Mark Young29927482016-05-04 14:38:51 -06009862 copy_ds_update.descriptorCount = 1; // Copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -06009863 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
9864
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009865 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009866
Tobin Ehlis04356f92015-10-27 16:35:27 -06009867 // Now perform a copy update that fails due to binding out of bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009868 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " binding#1 with offset index of 1 plus "
9869 "update array offset of 0 and update of "
9870 "5 descriptors oversteps total number "
9871 "of descriptors in set: 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009872
Tobin Ehlis04356f92015-10-27 16:35:27 -06009873 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
9874 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
9875 copy_ds_update.srcSet = descriptorSet;
9876 copy_ds_update.srcBinding = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009877 copy_ds_update.dstSet = descriptorSet;
9878 copy_ds_update.dstBinding = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009879 copy_ds_update.descriptorCount = 5; // ERROR copy 5 descriptors (out of bounds for layout)
Tobin Ehlis04356f92015-10-27 16:35:27 -06009880 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
9881
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009882 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -06009883
Chia-I Wuf7458c52015-10-26 21:10:41 +08009884 vkDestroySampler(m_device->device(), sampler, NULL);
9885 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9886 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis04356f92015-10-27 16:35:27 -06009887}
9888
Karl Schultz6addd812016-02-02 17:17:23 -07009889TEST_F(VkLayerTest, NumSamplesMismatch) {
9890 // Create CommandBuffer where MSAA samples doesn't match RenderPass
9891 // sampleCount
9892 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009893
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009894 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Num samples mismatch! ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009895
Tobin Ehlis3b780662015-05-28 12:11:26 -06009896 ASSERT_NO_FATAL_FAILURE(InitState());
9897 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009898 VkDescriptorPoolSize ds_type_count = {};
Tony Barboureb254902015-07-15 12:50:33 -06009899 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009900 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009901
9902 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009903 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9904 ds_pool_ci.pNext = NULL;
9905 ds_pool_ci.maxSets = 1;
9906 ds_pool_ci.poolSizeCount = 1;
9907 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06009908
Tobin Ehlis3b780662015-05-28 12:11:26 -06009909 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009910 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009911 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009912
Tony Barboureb254902015-07-15 12:50:33 -06009913 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08009914 dsl_binding.binding = 0;
Tony Barboureb254902015-07-15 12:50:33 -06009915 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08009916 dsl_binding.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009917 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9918 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009919
Tony Barboureb254902015-07-15 12:50:33 -06009920 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9921 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9922 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009923 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07009924 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06009925
Tobin Ehlis3b780662015-05-28 12:11:26 -06009926 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009927 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009928 ASSERT_VK_SUCCESS(err);
9929
9930 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009931 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009932 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009933 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009934 alloc_info.descriptorPool = ds_pool;
9935 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009936 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009937 ASSERT_VK_SUCCESS(err);
9938
Tony Barboureb254902015-07-15 12:50:33 -06009939 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009940 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07009941 pipe_ms_state_ci.pNext = NULL;
9942 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
9943 pipe_ms_state_ci.sampleShadingEnable = 0;
9944 pipe_ms_state_ci.minSampleShading = 1.0;
9945 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009946
Tony Barboureb254902015-07-15 12:50:33 -06009947 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009948 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9949 pipeline_layout_ci.pNext = NULL;
9950 pipeline_layout_ci.setLayoutCount = 1;
9951 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009952
9953 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009954 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009955 ASSERT_VK_SUCCESS(err);
9956
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009957 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
9958 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
9959 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -06009960 VkPipelineObj pipe(m_device);
9961 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06009962 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -06009963 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -06009964 pipe.SetMSAA(&pipe_ms_state_ci);
9965 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tobin Ehlis3b780662015-05-28 12:11:26 -06009966
Tony Barbour552f6c02016-12-21 14:34:07 -07009967 m_commandBuffer->BeginCommandBuffer();
9968 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009969 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis3b780662015-05-28 12:11:26 -06009970
Mark Young29927482016-05-04 14:38:51 -06009971 // Render triangle (the error should trigger on the attempt to draw).
9972 Draw(3, 1, 0, 0);
9973
9974 // Finalize recording of the command buffer
Tony Barbour552f6c02016-12-21 14:34:07 -07009975 m_commandBuffer->EndRenderPass();
9976 m_commandBuffer->EndCommandBuffer();
Mark Young29927482016-05-04 14:38:51 -06009977
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009978 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009979
Chia-I Wuf7458c52015-10-26 21:10:41 +08009980 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9981 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9982 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009983}
Mark Young29927482016-05-04 14:38:51 -06009984
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009985TEST_F(VkLayerTest, RenderPassIncompatible) {
9986 TEST_DESCRIPTION("Hit RenderPass incompatible cases. "
9987 "Initial case is drawing with an active renderpass that's "
Mike Weiblencce7ec72016-10-17 19:33:05 -06009988 "not compatible with the bound pipeline state object's creation renderpass");
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009989 VkResult err;
9990
9991 ASSERT_NO_FATAL_FAILURE(InitState());
9992 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9993
9994 VkDescriptorSetLayoutBinding dsl_binding = {};
9995 dsl_binding.binding = 0;
9996 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9997 dsl_binding.descriptorCount = 1;
9998 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9999 dsl_binding.pImmutableSamplers = NULL;
10000
10001 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10002 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10003 ds_layout_ci.pNext = NULL;
10004 ds_layout_ci.bindingCount = 1;
10005 ds_layout_ci.pBindings = &dsl_binding;
10006
10007 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010008 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010009 ASSERT_VK_SUCCESS(err);
10010
10011 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
10012 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10013 pipeline_layout_ci.pNext = NULL;
10014 pipeline_layout_ci.setLayoutCount = 1;
10015 pipeline_layout_ci.pSetLayouts = &ds_layout;
10016
10017 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010018 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010019 ASSERT_VK_SUCCESS(err);
10020
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010021 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
10022 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
10023 // but add it to be able to run on more devices
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010024 // Create a renderpass that will be incompatible with default renderpass
10025 VkAttachmentReference attach = {};
10026 attach.layout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
10027 VkAttachmentReference color_att = {};
10028 color_att.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
10029 VkSubpassDescription subpass = {};
10030 subpass.inputAttachmentCount = 1;
10031 subpass.pInputAttachments = &attach;
10032 subpass.colorAttachmentCount = 1;
10033 subpass.pColorAttachments = &color_att;
10034 VkRenderPassCreateInfo rpci = {};
10035 rpci.subpassCount = 1;
10036 rpci.pSubpasses = &subpass;
10037 rpci.attachmentCount = 1;
10038 VkAttachmentDescription attach_desc = {};
10039 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
Cody Northropbd16af12016-06-21 09:25:48 -060010040 // Format incompatible with PSO RP color attach format B8G8R8A8_UNORM
10041 attach_desc.format = VK_FORMAT_R8G8B8A8_UNORM;
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010042 rpci.pAttachments = &attach_desc;
10043 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
10044 VkRenderPass rp;
10045 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10046 VkPipelineObj pipe(m_device);
10047 pipe.AddShader(&vs);
10048 pipe.AddShader(&fs);
10049 pipe.AddColorAttachment();
10050 VkViewport view_port = {};
10051 m_viewports.push_back(view_port);
10052 pipe.SetViewport(m_viewports);
10053 VkRect2D rect = {};
10054 m_scissors.push_back(rect);
10055 pipe.SetScissor(m_scissors);
10056 pipe.CreateVKPipeline(pipeline_layout, renderPass());
10057
10058 VkCommandBufferInheritanceInfo cbii = {};
10059 cbii.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
10060 cbii.renderPass = rp;
10061 cbii.subpass = 0;
10062 VkCommandBufferBeginInfo cbbi = {};
10063 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
10064 cbbi.pInheritanceInfo = &cbii;
10065 vkBeginCommandBuffer(m_commandBuffer->handle(), &cbbi);
10066 VkRenderPassBeginInfo rpbi = {};
10067 rpbi.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
10068 rpbi.framebuffer = m_framebuffer;
10069 rpbi.renderPass = rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010070 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
10071 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010072
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010073 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is incompatible w/ gfx pipeline ");
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010074 // Render triangle (the error should trigger on the attempt to draw).
10075 Draw(3, 1, 0, 0);
10076
10077 // Finalize recording of the command buffer
Tony Barbour552f6c02016-12-21 14:34:07 -070010078 m_commandBuffer->EndRenderPass();
10079 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010080
10081 m_errorMonitor->VerifyFound();
10082
10083 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10084 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10085 vkDestroyRenderPass(m_device->device(), rp, NULL);
10086}
10087
Mark Youngc89c6312016-03-31 16:03:20 -060010088TEST_F(VkLayerTest, NumBlendAttachMismatch) {
10089 // Create Pipeline where the number of blend attachments doesn't match the
10090 // number of color attachments. In this case, we don't add any color
10091 // blend attachments even though we have a color attachment.
10092 VkResult err;
10093
10094 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010095 "Render pass subpass 0 mismatch with blending state defined and blend state attachment");
Mark Youngc89c6312016-03-31 16:03:20 -060010096
10097 ASSERT_NO_FATAL_FAILURE(InitState());
10098 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10099 VkDescriptorPoolSize ds_type_count = {};
10100 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10101 ds_type_count.descriptorCount = 1;
10102
10103 VkDescriptorPoolCreateInfo ds_pool_ci = {};
10104 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10105 ds_pool_ci.pNext = NULL;
10106 ds_pool_ci.maxSets = 1;
10107 ds_pool_ci.poolSizeCount = 1;
10108 ds_pool_ci.pPoolSizes = &ds_type_count;
10109
10110 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010111 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Mark Youngc89c6312016-03-31 16:03:20 -060010112 ASSERT_VK_SUCCESS(err);
10113
10114 VkDescriptorSetLayoutBinding dsl_binding = {};
10115 dsl_binding.binding = 0;
10116 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10117 dsl_binding.descriptorCount = 1;
10118 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10119 dsl_binding.pImmutableSamplers = NULL;
10120
10121 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10122 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10123 ds_layout_ci.pNext = NULL;
10124 ds_layout_ci.bindingCount = 1;
10125 ds_layout_ci.pBindings = &dsl_binding;
10126
10127 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010128 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Youngc89c6312016-03-31 16:03:20 -060010129 ASSERT_VK_SUCCESS(err);
10130
10131 VkDescriptorSet descriptorSet;
10132 VkDescriptorSetAllocateInfo alloc_info = {};
10133 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
10134 alloc_info.descriptorSetCount = 1;
10135 alloc_info.descriptorPool = ds_pool;
10136 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010137 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Youngc89c6312016-03-31 16:03:20 -060010138 ASSERT_VK_SUCCESS(err);
10139
10140 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010141 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Mark Youngc89c6312016-03-31 16:03:20 -060010142 pipe_ms_state_ci.pNext = NULL;
10143 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
10144 pipe_ms_state_ci.sampleShadingEnable = 0;
10145 pipe_ms_state_ci.minSampleShading = 1.0;
10146 pipe_ms_state_ci.pSampleMask = NULL;
10147
10148 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
10149 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10150 pipeline_layout_ci.pNext = NULL;
10151 pipeline_layout_ci.setLayoutCount = 1;
10152 pipeline_layout_ci.pSetLayouts = &ds_layout;
10153
10154 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010155 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Mark Youngc89c6312016-03-31 16:03:20 -060010156 ASSERT_VK_SUCCESS(err);
10157
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010158 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
10159 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
10160 // but add it to be able to run on more devices
Mark Youngc89c6312016-03-31 16:03:20 -060010161 VkPipelineObj pipe(m_device);
10162 pipe.AddShader(&vs);
10163 pipe.AddShader(&fs);
10164 pipe.SetMSAA(&pipe_ms_state_ci);
10165 pipe.CreateVKPipeline(pipeline_layout, renderPass());
10166
Tony Barbour552f6c02016-12-21 14:34:07 -070010167 m_commandBuffer->BeginCommandBuffer();
10168 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010169 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Mark Youngc89c6312016-03-31 16:03:20 -060010170
Mark Young29927482016-05-04 14:38:51 -060010171 // Render triangle (the error should trigger on the attempt to draw).
10172 Draw(3, 1, 0, 0);
10173
10174 // Finalize recording of the command buffer
Tony Barbour552f6c02016-12-21 14:34:07 -070010175 m_commandBuffer->EndRenderPass();
10176 m_commandBuffer->EndCommandBuffer();
Mark Young29927482016-05-04 14:38:51 -060010177
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010178 m_errorMonitor->VerifyFound();
Mark Youngc89c6312016-03-31 16:03:20 -060010179
10180 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10181 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10182 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
10183}
Mark Young29927482016-05-04 14:38:51 -060010184
Mark Muellerd4914412016-06-13 17:52:06 -060010185TEST_F(VkLayerTest, MissingClearAttachment) {
10186 TEST_DESCRIPTION("Points to a wrong colorAttachment index in a VkClearAttachment "
10187 "structure passed to vkCmdClearAttachments");
Cody Northropc31a84f2016-08-22 10:41:47 -060010188 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070010189 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01114);
Mark Muellerd4914412016-06-13 17:52:06 -060010190
10191 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailCmdClearAttachments);
10192 m_errorMonitor->VerifyFound();
10193}
10194
Karl Schultz6addd812016-02-02 17:17:23 -070010195TEST_F(VkLayerTest, ClearCmdNoDraw) {
10196 // Create CommandBuffer where we add ClearCmd for FB Color attachment prior
10197 // to issuing a Draw
10198 VkResult err;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010199
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010200 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Mike Weiblencce7ec72016-10-17 19:33:05 -060010201 "vkCmdClearAttachments() issued on command buffer object ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010202
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010203 ASSERT_NO_FATAL_FAILURE(InitState());
10204 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -060010205
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010206 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010207 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10208 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010209
10210 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010211 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10212 ds_pool_ci.pNext = NULL;
10213 ds_pool_ci.maxSets = 1;
10214 ds_pool_ci.poolSizeCount = 1;
10215 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060010216
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010217 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010218 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010219 ASSERT_VK_SUCCESS(err);
10220
Tony Barboureb254902015-07-15 12:50:33 -060010221 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010222 dsl_binding.binding = 0;
10223 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10224 dsl_binding.descriptorCount = 1;
10225 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10226 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010227
Tony Barboureb254902015-07-15 12:50:33 -060010228 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010229 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10230 ds_layout_ci.pNext = NULL;
10231 ds_layout_ci.bindingCount = 1;
10232 ds_layout_ci.pBindings = &dsl_binding;
Mark Lobodzinski209b5292015-09-17 09:44:05 -060010233
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010234 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010235 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010236 ASSERT_VK_SUCCESS(err);
10237
10238 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010239 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010240 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010241 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060010242 alloc_info.descriptorPool = ds_pool;
10243 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010244 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010245 ASSERT_VK_SUCCESS(err);
10246
Tony Barboureb254902015-07-15 12:50:33 -060010247 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010248 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070010249 pipe_ms_state_ci.pNext = NULL;
10250 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
10251 pipe_ms_state_ci.sampleShadingEnable = 0;
10252 pipe_ms_state_ci.minSampleShading = 1.0;
10253 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010254
Tony Barboureb254902015-07-15 12:50:33 -060010255 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010256 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10257 pipeline_layout_ci.pNext = NULL;
10258 pipeline_layout_ci.setLayoutCount = 1;
10259 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010260
10261 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010262 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010263 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski209b5292015-09-17 09:44:05 -060010264
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010265 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -060010266 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -070010267 // on more devices
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010268 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010269
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010270 VkPipelineObj pipe(m_device);
10271 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -060010272 pipe.AddShader(&fs);
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010273 pipe.SetMSAA(&pipe_ms_state_ci);
10274 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -060010275
Tony Barbour552f6c02016-12-21 14:34:07 -070010276 m_commandBuffer->BeginCommandBuffer();
10277 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010278
Karl Schultz6addd812016-02-02 17:17:23 -070010279 // Main thing we care about for this test is that the VkImage obj we're
10280 // clearing matches Color Attachment of FB
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010281 // Also pass down other dummy params to keep driver and paramchecker happy
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -060010282 VkClearAttachment color_attachment;
10283 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10284 color_attachment.clearValue.color.float32[0] = 1.0;
10285 color_attachment.clearValue.color.float32[1] = 1.0;
10286 color_attachment.clearValue.color.float32[2] = 1.0;
10287 color_attachment.clearValue.color.float32[3] = 1.0;
10288 color_attachment.colorAttachment = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010289 VkClearRect clear_rect = {{{0, 0}, {(uint32_t)m_width, (uint32_t)m_height}}};
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010290
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010291 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010292
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010293 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010294
Chia-I Wuf7458c52015-10-26 21:10:41 +080010295 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10296 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10297 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010298}
10299
Karl Schultz6addd812016-02-02 17:17:23 -070010300TEST_F(VkLayerTest, VtxBufferBadIndex) {
10301 VkResult err;
Tobin Ehlis502480b2015-06-24 15:53:07 -060010302
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010303 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10304 "but no vertex buffers are attached to this Pipeline State Object");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010305
Tobin Ehlis502480b2015-06-24 15:53:07 -060010306 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisd332f282015-10-02 11:00:56 -060010307 ASSERT_NO_FATAL_FAILURE(InitViewport());
Tobin Ehlis502480b2015-06-24 15:53:07 -060010308 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -060010309
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010310 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010311 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10312 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010313
10314 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010315 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10316 ds_pool_ci.pNext = NULL;
10317 ds_pool_ci.maxSets = 1;
10318 ds_pool_ci.poolSizeCount = 1;
10319 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060010320
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -060010321 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010322 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis502480b2015-06-24 15:53:07 -060010323 ASSERT_VK_SUCCESS(err);
10324
Tony Barboureb254902015-07-15 12:50:33 -060010325 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010326 dsl_binding.binding = 0;
10327 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10328 dsl_binding.descriptorCount = 1;
10329 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10330 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -060010331
Tony Barboureb254902015-07-15 12:50:33 -060010332 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010333 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10334 ds_layout_ci.pNext = NULL;
10335 ds_layout_ci.bindingCount = 1;
10336 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060010337
Tobin Ehlis502480b2015-06-24 15:53:07 -060010338 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010339 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -060010340 ASSERT_VK_SUCCESS(err);
10341
10342 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010343 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010344 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010345 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060010346 alloc_info.descriptorPool = ds_pool;
10347 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010348 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis502480b2015-06-24 15:53:07 -060010349 ASSERT_VK_SUCCESS(err);
10350
Tony Barboureb254902015-07-15 12:50:33 -060010351 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010352 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070010353 pipe_ms_state_ci.pNext = NULL;
10354 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
10355 pipe_ms_state_ci.sampleShadingEnable = 0;
10356 pipe_ms_state_ci.minSampleShading = 1.0;
10357 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -060010358
Tony Barboureb254902015-07-15 12:50:33 -060010359 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010360 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10361 pipeline_layout_ci.pNext = NULL;
10362 pipeline_layout_ci.setLayoutCount = 1;
10363 pipeline_layout_ci.pSetLayouts = &ds_layout;
10364 VkPipelineLayout pipeline_layout;
Tobin Ehlis502480b2015-06-24 15:53:07 -060010365
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010366 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -060010367 ASSERT_VK_SUCCESS(err);
10368
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010369 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
10370 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
10371 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010372 VkPipelineObj pipe(m_device);
10373 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -060010374 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -060010375 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010376 pipe.SetMSAA(&pipe_ms_state_ci);
Tobin Ehlisd332f282015-10-02 11:00:56 -060010377 pipe.SetViewport(m_viewports);
10378 pipe.SetScissor(m_scissors);
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010379 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -060010380
Tony Barbour552f6c02016-12-21 14:34:07 -070010381 m_commandBuffer->BeginCommandBuffer();
10382 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010383 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisf7bf4502015-09-09 15:12:35 -060010384 // Don't care about actual data, just need to get to draw to flag error
10385 static const float vbo_data[3] = {1.f, 0.f, 1.f};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010386 VkConstantBufferObj vbo(m_device, sizeof(vbo_data), sizeof(float), (const void *)&vbo_data);
Tobin Ehlisf7bf4502015-09-09 15:12:35 -060010387 BindVertexBuffer(&vbo, (VkDeviceSize)0, 1); // VBO idx 1, but no VBO in PSO
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -060010388 Draw(1, 0, 0, 0);
Tobin Ehlis502480b2015-06-24 15:53:07 -060010389
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010390 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010391
Chia-I Wuf7458c52015-10-26 21:10:41 +080010392 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10393 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10394 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis502480b2015-06-24 15:53:07 -060010395}
Mark Muellerdfe37552016-07-07 14:47:42 -060010396
Mark Mueller2ee294f2016-08-04 12:59:48 -060010397TEST_F(VkLayerTest, MismatchCountQueueCreateRequestedFeature) {
10398 TEST_DESCRIPTION("Use an invalid count in a vkEnumeratePhysicalDevices call."
10399 "Use invalid Queue Family Index in vkCreateDevice");
Cody Northropc31a84f2016-08-22 10:41:47 -060010400 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Mueller2ee294f2016-08-04 12:59:48 -060010401
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010402 const char *mismatch_count_message = "Call to vkEnumeratePhysicalDevices() "
10403 "w/ pPhysicalDeviceCount value ";
Mark Mueller2ee294f2016-08-04 12:59:48 -060010404
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010405 const char *invalid_queueFamilyIndex_message = "Invalid queue create request in vkCreateDevice(). Invalid "
10406 "queueFamilyIndex ";
Mark Mueller2ee294f2016-08-04 12:59:48 -060010407
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010408 const char *unavailable_feature_message = "While calling vkCreateDevice(), requesting feature #";
Mark Mueller2ee294f2016-08-04 12:59:48 -060010409
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010410 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, mismatch_count_message);
Mark Mueller880fce52016-08-17 15:23:23 -060010411 // The following test fails with recent NVidia drivers.
10412 // By the time core_validation is reached, the NVidia
10413 // driver has sanitized the invalid condition and core_validation
10414 // is not introduced to the failure condition. This is not the case
10415 // with AMD and Mesa drivers. Futher investigation is required
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010416 // uint32_t count = static_cast<uint32_t>(~0);
10417 // VkPhysicalDevice physical_device;
10418 // vkEnumeratePhysicalDevices(instance(), &count, &physical_device);
10419 // m_errorMonitor->VerifyFound();
Mark Mueller2ee294f2016-08-04 12:59:48 -060010420
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010421 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_queueFamilyIndex_message);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010422 float queue_priority = 0.0;
10423
10424 VkDeviceQueueCreateInfo queue_create_info = {};
10425 queue_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
10426 queue_create_info.queueCount = 1;
10427 queue_create_info.pQueuePriorities = &queue_priority;
10428 queue_create_info.queueFamilyIndex = static_cast<uint32_t>(~0);
10429
10430 VkPhysicalDeviceFeatures features = m_device->phy().features();
10431 VkDevice testDevice;
10432 VkDeviceCreateInfo device_create_info = {};
10433 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
10434 device_create_info.queueCreateInfoCount = 1;
10435 device_create_info.pQueueCreateInfos = &queue_create_info;
10436 device_create_info.pEnabledFeatures = &features;
10437 vkCreateDevice(gpu(), &device_create_info, nullptr, &testDevice);
10438 m_errorMonitor->VerifyFound();
10439
10440 queue_create_info.queueFamilyIndex = 1;
10441
10442 unsigned feature_count = sizeof(VkPhysicalDeviceFeatures) / sizeof(VkBool32);
10443 VkBool32 *feature_array = reinterpret_cast<VkBool32 *>(&features);
10444 for (unsigned i = 0; i < feature_count; i++) {
10445 if (VK_FALSE == feature_array[i]) {
10446 feature_array[i] = VK_TRUE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010447 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, unavailable_feature_message);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010448 device_create_info.pEnabledFeatures = &features;
10449 vkCreateDevice(gpu(), &device_create_info, nullptr, &testDevice);
10450 m_errorMonitor->VerifyFound();
10451 break;
10452 }
10453 }
10454}
10455
Tobin Ehlis16edf082016-11-21 12:33:49 -070010456TEST_F(VkLayerTest, InvalidQueryPoolCreate) {
10457 TEST_DESCRIPTION("Attempt to create a query pool for PIPELINE_STATISTICS without enabling pipeline stats for the device.");
10458
10459 ASSERT_NO_FATAL_FAILURE(InitState());
10460
10461 const std::vector<VkQueueFamilyProperties> queue_props = m_device->queue_props;
10462 std::vector<VkDeviceQueueCreateInfo> queue_info;
10463 queue_info.reserve(queue_props.size());
10464 std::vector<std::vector<float>> queue_priorities;
10465 for (uint32_t i = 0; i < (uint32_t)queue_props.size(); i++) {
10466 VkDeviceQueueCreateInfo qi{};
10467 qi.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
10468 qi.queueFamilyIndex = i;
10469 qi.queueCount = queue_props[i].queueCount;
10470 queue_priorities.emplace_back(qi.queueCount, 0.0f);
10471 qi.pQueuePriorities = queue_priorities[i].data();
10472 queue_info.push_back(qi);
10473 }
10474
10475 std::vector<const char *> device_extension_names;
10476
10477 VkDevice local_device;
10478 VkDeviceCreateInfo device_create_info = {};
10479 auto features = m_device->phy().features();
10480 // Intentionally disable pipeline stats
10481 features.pipelineStatisticsQuery = VK_FALSE;
10482 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
10483 device_create_info.pNext = NULL;
10484 device_create_info.queueCreateInfoCount = queue_info.size();
10485 device_create_info.pQueueCreateInfos = queue_info.data();
10486 device_create_info.enabledLayerCount = 0;
10487 device_create_info.ppEnabledLayerNames = NULL;
10488 device_create_info.pEnabledFeatures = &features;
10489 VkResult err = vkCreateDevice(gpu(), &device_create_info, nullptr, &local_device);
10490 ASSERT_VK_SUCCESS(err);
10491
10492 VkQueryPoolCreateInfo qpci{};
10493 qpci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
10494 qpci.queryType = VK_QUERY_TYPE_PIPELINE_STATISTICS;
10495 qpci.queryCount = 1;
10496 VkQueryPool query_pool;
10497
10498 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01006);
10499 vkCreateQueryPool(local_device, &qpci, nullptr, &query_pool);
10500 m_errorMonitor->VerifyFound();
10501
10502 vkDestroyDevice(local_device, nullptr);
10503}
10504
Mark Mueller2ee294f2016-08-04 12:59:48 -060010505TEST_F(VkLayerTest, InvalidQueueIndexInvalidQuery) {
10506 TEST_DESCRIPTION("Use an invalid queue index in a vkCmdWaitEvents call."
10507 "End a command buffer with a query still in progress.");
10508
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010509 const char *invalid_queue_index = "was created with sharingMode of VK_SHARING_MODE_EXCLUSIVE. If one "
10510 "of src- or dstQueueFamilyIndex is VK_QUEUE_FAMILY_IGNORED, both "
10511 "must be.";
Mark Mueller2ee294f2016-08-04 12:59:48 -060010512
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010513 const char *invalid_query = "Ending command buffer with in progress query: queryPool 0x";
Mark Mueller2ee294f2016-08-04 12:59:48 -060010514
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010515 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_queue_index);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010516
10517 ASSERT_NO_FATAL_FAILURE(InitState());
10518
10519 VkEvent event;
10520 VkEventCreateInfo event_create_info{};
10521 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
10522 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
10523
Mark Mueller2ee294f2016-08-04 12:59:48 -060010524 VkQueue queue = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010525 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010526
Tony Barbour552f6c02016-12-21 14:34:07 -070010527 m_commandBuffer->BeginCommandBuffer();
Mark Mueller2ee294f2016-08-04 12:59:48 -060010528
10529 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010530 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 -060010531 ASSERT_TRUE(image.initialized());
10532 VkImageMemoryBarrier img_barrier = {};
10533 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
10534 img_barrier.pNext = NULL;
10535 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
10536 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
10537 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
10538 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
10539 img_barrier.image = image.handle();
10540 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
Mark Lobodzinski2a74c5c2016-08-17 13:26:28 -060010541
10542 // QueueFamilyIndex must be VK_QUEUE_FAMILY_IGNORED, this verifies
10543 // that layer validation catches the case when it is not.
10544 img_barrier.dstQueueFamilyIndex = 0;
Mark Mueller2ee294f2016-08-04 12:59:48 -060010545 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10546 img_barrier.subresourceRange.baseArrayLayer = 0;
10547 img_barrier.subresourceRange.baseMipLevel = 0;
10548 img_barrier.subresourceRange.layerCount = 1;
10549 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010550 vkCmdWaitEvents(m_commandBuffer->handle(), 1, &event, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0,
10551 nullptr, 0, nullptr, 1, &img_barrier);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010552 m_errorMonitor->VerifyFound();
10553
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010554 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_query);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010555
10556 VkQueryPool query_pool;
10557 VkQueryPoolCreateInfo query_pool_create_info = {};
10558 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
10559 query_pool_create_info.queryType = VK_QUERY_TYPE_OCCLUSION;
10560 query_pool_create_info.queryCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010561 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010562
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010563 vkCmdResetQueryPool(m_commandBuffer->handle(), query_pool, 0 /*startQuery*/, 1 /*queryCount*/);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010564 vkCmdBeginQuery(m_commandBuffer->handle(), query_pool, 0, 0);
10565
10566 vkEndCommandBuffer(m_commandBuffer->handle());
10567 m_errorMonitor->VerifyFound();
10568
10569 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
10570 vkDestroyEvent(m_device->device(), event, nullptr);
10571}
10572
Mark Muellerdfe37552016-07-07 14:47:42 -060010573TEST_F(VkLayerTest, VertexBufferInvalid) {
10574 TEST_DESCRIPTION("Submit a command buffer using deleted vertex buffer, "
10575 "delete a buffer twice, use an invalid offset for each "
10576 "buffer type, and attempt to bind a null buffer");
10577
10578 const char *deleted_buffer_in_command_buffer = "Cannot submit cmd buffer "
10579 "using deleted buffer ";
Mark Muellerdfe37552016-07-07 14:47:42 -060010580 const char *invalid_offset_message = "vkBindBufferMemory(): "
10581 "memoryOffset is 0x";
10582 const char *invalid_storage_buffer_offset_message = "vkBindBufferMemory(): "
10583 "storage memoryOffset "
10584 "is 0x";
10585 const char *invalid_texel_buffer_offset_message = "vkBindBufferMemory(): "
10586 "texel memoryOffset "
10587 "is 0x";
10588 const char *invalid_uniform_buffer_offset_message = "vkBindBufferMemory(): "
10589 "uniform memoryOffset "
10590 "is 0x";
Mark Muellerdfe37552016-07-07 14:47:42 -060010591
10592 ASSERT_NO_FATAL_FAILURE(InitState());
10593 ASSERT_NO_FATAL_FAILURE(InitViewport());
10594 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10595
10596 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010597 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Mark Muellerdfe37552016-07-07 14:47:42 -060010598 pipe_ms_state_ci.pNext = NULL;
10599 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
10600 pipe_ms_state_ci.sampleShadingEnable = 0;
10601 pipe_ms_state_ci.minSampleShading = 1.0;
10602 pipe_ms_state_ci.pSampleMask = nullptr;
10603
10604 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
10605 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10606 VkPipelineLayout pipeline_layout;
10607
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010608 VkResult err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, nullptr, &pipeline_layout);
Mark Muellerdfe37552016-07-07 14:47:42 -060010609 ASSERT_VK_SUCCESS(err);
10610
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010611 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
10612 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Muellerdfe37552016-07-07 14:47:42 -060010613 VkPipelineObj pipe(m_device);
10614 pipe.AddShader(&vs);
10615 pipe.AddShader(&fs);
10616 pipe.AddColorAttachment();
10617 pipe.SetMSAA(&pipe_ms_state_ci);
10618 pipe.SetViewport(m_viewports);
10619 pipe.SetScissor(m_scissors);
10620 pipe.CreateVKPipeline(pipeline_layout, renderPass());
10621
Tony Barbour552f6c02016-12-21 14:34:07 -070010622 m_commandBuffer->BeginCommandBuffer();
10623 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010624 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Mark Muellerdfe37552016-07-07 14:47:42 -060010625
10626 {
10627 // Create and bind a vertex buffer in a reduced scope, which will cause
10628 // it to be deleted upon leaving this scope
10629 const float vbo_data[3] = {1.f, 0.f, 1.f};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010630 VkVerticesObj draw_verticies(m_device, 1, 1, sizeof(vbo_data), 3, vbo_data);
Mark Muellerdfe37552016-07-07 14:47:42 -060010631 draw_verticies.BindVertexBuffers(m_commandBuffer->handle());
10632 draw_verticies.AddVertexInputToPipe(pipe);
10633 }
10634
10635 Draw(1, 0, 0, 0);
10636
Tony Barbour552f6c02016-12-21 14:34:07 -070010637 m_commandBuffer->EndRenderPass();
10638 m_commandBuffer->EndCommandBuffer();
Mark Muellerdfe37552016-07-07 14:47:42 -060010639
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010640 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, deleted_buffer_in_command_buffer);
Mark Muellerdfe37552016-07-07 14:47:42 -060010641 QueueCommandBuffer(false);
10642 m_errorMonitor->VerifyFound();
10643
10644 {
10645 // Create and bind a vertex buffer in a reduced scope, and delete it
10646 // twice, the second through the destructor
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010647 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eDoubleDelete);
Karl Schultzf78bcdd2016-11-30 12:36:01 -070010648 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00680);
Mark Muellerdfe37552016-07-07 14:47:42 -060010649 buffer_test.TestDoubleDestroy();
10650 }
10651 m_errorMonitor->VerifyFound();
10652
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010653 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidMemoryOffset)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060010654 // Create and bind a memory buffer with an invalid offset.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010655 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_offset_message);
10656 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT, VkBufferTest::eInvalidMemoryOffset);
10657 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010658 m_errorMonitor->VerifyFound();
10659 }
10660
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010661 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset,
10662 VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060010663 // Create and bind a memory buffer with an invalid offset again,
10664 // but look for a texel buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010665 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_texel_buffer_offset_message);
10666 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
10667 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010668 m_errorMonitor->VerifyFound();
10669 }
10670
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010671 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060010672 // Create and bind a memory buffer with an invalid offset again, but
10673 // look for a uniform buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010674 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_uniform_buffer_offset_message);
10675 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
10676 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010677 m_errorMonitor->VerifyFound();
10678 }
10679
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010680 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060010681 // Create and bind a memory buffer with an invalid offset again, but
10682 // look for a storage buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010683 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_storage_buffer_offset_message);
10684 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
10685 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010686 m_errorMonitor->VerifyFound();
10687 }
10688
10689 {
10690 // Attempt to bind a null buffer.
Karl Schultzf78bcdd2016-11-30 12:36:01 -070010691 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00799);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010692 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eBindNullBuffer);
10693 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010694 m_errorMonitor->VerifyFound();
10695 }
10696
10697 {
10698 // Attempt to use an invalid handle to delete a buffer.
Karl Schultzf78bcdd2016-11-30 12:36:01 -070010699 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00622);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010700 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eFreeInvalidHandle);
10701 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010702 }
10703 m_errorMonitor->VerifyFound();
10704
10705 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10706}
10707
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010708// INVALID_IMAGE_LAYOUT tests (one other case is hit by MapMemWithoutHostVisibleBit and not here)
10709TEST_F(VkLayerTest, InvalidImageLayout) {
10710 TEST_DESCRIPTION("Hit all possible validation checks associated with the "
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010711 "DRAWSTATE_INVALID_IMAGE_LAYOUT enum. Generally these involve having"
10712 "images in the wrong layout when they're copied or transitioned.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010713 // 3 in ValidateCmdBufImageLayouts
10714 // * -1 Attempt to submit cmd buf w/ deleted image
10715 // * -2 Cmd buf submit of image w/ layout not matching first use w/ subresource
10716 // * -3 Cmd buf submit of image w/ layout not matching first use w/o subresource
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010717
10718 ASSERT_NO_FATAL_FAILURE(InitState());
10719 // Create src & dst images to use for copy operations
10720 VkImage src_image;
10721 VkImage dst_image;
Cort3b021012016-12-07 12:00:57 -080010722 VkImage depth_image;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010723
10724 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
10725 const int32_t tex_width = 32;
10726 const int32_t tex_height = 32;
10727
10728 VkImageCreateInfo image_create_info = {};
10729 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
10730 image_create_info.pNext = NULL;
10731 image_create_info.imageType = VK_IMAGE_TYPE_2D;
10732 image_create_info.format = tex_format;
10733 image_create_info.extent.width = tex_width;
10734 image_create_info.extent.height = tex_height;
10735 image_create_info.extent.depth = 1;
10736 image_create_info.mipLevels = 1;
10737 image_create_info.arrayLayers = 4;
10738 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
10739 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
10740 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Cort3b021012016-12-07 12:00:57 -080010741 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010742 image_create_info.flags = 0;
10743
10744 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &src_image);
10745 ASSERT_VK_SUCCESS(err);
Cort3b021012016-12-07 12:00:57 -080010746 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010747 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dst_image);
10748 ASSERT_VK_SUCCESS(err);
Cort3b021012016-12-07 12:00:57 -080010749 image_create_info.format = VK_FORMAT_D32_SFLOAT;
10750 image_create_info.usage |= VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
10751 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &depth_image);
10752 ASSERT_VK_SUCCESS(err);
10753
10754 // Allocate memory
10755 VkMemoryRequirements img_mem_reqs = {};
Cort530cf382016-12-08 09:59:47 -080010756 VkMemoryAllocateInfo mem_alloc = {};
Cort3b021012016-12-07 12:00:57 -080010757 VkDeviceMemory src_image_mem, dst_image_mem, depth_image_mem;
Cort530cf382016-12-08 09:59:47 -080010758 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
10759 mem_alloc.pNext = NULL;
10760 mem_alloc.allocationSize = 0;
10761 mem_alloc.memoryTypeIndex = 0;
Cort3b021012016-12-07 12:00:57 -080010762
10763 vkGetImageMemoryRequirements(m_device->device(), src_image, &img_mem_reqs);
Cort530cf382016-12-08 09:59:47 -080010764 mem_alloc.allocationSize = img_mem_reqs.size;
10765 bool pass = m_device->phy().set_memory_type(img_mem_reqs.memoryTypeBits, &mem_alloc, 0);
Cort3b021012016-12-07 12:00:57 -080010766 ASSERT_TRUE(pass);
Cort530cf382016-12-08 09:59:47 -080010767 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &src_image_mem);
Cort3b021012016-12-07 12:00:57 -080010768 ASSERT_VK_SUCCESS(err);
10769
10770 vkGetImageMemoryRequirements(m_device->device(), dst_image, &img_mem_reqs);
Cort530cf382016-12-08 09:59:47 -080010771 mem_alloc.allocationSize = img_mem_reqs.size;
10772 pass = m_device->phy().set_memory_type(img_mem_reqs.memoryTypeBits, &mem_alloc, 0);
Cort3b021012016-12-07 12:00:57 -080010773 ASSERT_VK_SUCCESS(err);
Cort530cf382016-12-08 09:59:47 -080010774 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &dst_image_mem);
Cort3b021012016-12-07 12:00:57 -080010775 ASSERT_VK_SUCCESS(err);
10776
10777 vkGetImageMemoryRequirements(m_device->device(), depth_image, &img_mem_reqs);
Cort530cf382016-12-08 09:59:47 -080010778 mem_alloc.allocationSize = img_mem_reqs.size;
10779 pass = m_device->phy().set_memory_type(img_mem_reqs.memoryTypeBits, &mem_alloc, 0);
Cort3b021012016-12-07 12:00:57 -080010780 ASSERT_VK_SUCCESS(err);
Cort530cf382016-12-08 09:59:47 -080010781 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &depth_image_mem);
Cort3b021012016-12-07 12:00:57 -080010782 ASSERT_VK_SUCCESS(err);
10783
10784 err = vkBindImageMemory(m_device->device(), src_image, src_image_mem, 0);
10785 ASSERT_VK_SUCCESS(err);
10786 err = vkBindImageMemory(m_device->device(), dst_image, dst_image_mem, 0);
10787 ASSERT_VK_SUCCESS(err);
10788 err = vkBindImageMemory(m_device->device(), depth_image, depth_image_mem, 0);
10789 ASSERT_VK_SUCCESS(err);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010790
Tony Barbour552f6c02016-12-21 14:34:07 -070010791 m_commandBuffer->BeginCommandBuffer();
Cort530cf382016-12-08 09:59:47 -080010792 VkImageCopy copy_region;
10793 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10794 copy_region.srcSubresource.mipLevel = 0;
10795 copy_region.srcSubresource.baseArrayLayer = 0;
10796 copy_region.srcSubresource.layerCount = 1;
10797 copy_region.srcOffset.x = 0;
10798 copy_region.srcOffset.y = 0;
10799 copy_region.srcOffset.z = 0;
10800 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10801 copy_region.dstSubresource.mipLevel = 0;
10802 copy_region.dstSubresource.baseArrayLayer = 0;
10803 copy_region.dstSubresource.layerCount = 1;
10804 copy_region.dstOffset.x = 0;
10805 copy_region.dstOffset.y = 0;
10806 copy_region.dstOffset.z = 0;
10807 copy_region.extent.width = 1;
10808 copy_region.extent.height = 1;
10809 copy_region.extent.depth = 1;
10810
10811 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10812 "Layout for input image should be TRANSFER_SRC_OPTIMAL instead of GENERAL.");
10813 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 -060010814 m_errorMonitor->VerifyFound();
10815 // Now cause error due to src image layout changing
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010816 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot copy from an image whose source layout is "
10817 "VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current "
10818 "layout VK_IMAGE_LAYOUT_GENERAL.");
Cort530cf382016-12-08 09:59:47 -080010819 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 -060010820 m_errorMonitor->VerifyFound();
10821 // Final src error is due to bad layout type
10822 m_errorMonitor->SetDesiredFailureMsg(
10823 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10824 "Layout for input image is VK_IMAGE_LAYOUT_UNDEFINED but can only be TRANSFER_SRC_OPTIMAL or GENERAL.");
Cort530cf382016-12-08 09:59:47 -080010825 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 -060010826 m_errorMonitor->VerifyFound();
10827 // Now verify same checks for dst
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010828 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10829 "Layout for output image should be TRANSFER_DST_OPTIMAL instead of GENERAL.");
Cort530cf382016-12-08 09:59:47 -080010830 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 -060010831 m_errorMonitor->VerifyFound();
10832 // Now cause error due to src image layout changing
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010833 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot copy from an image whose dest layout is "
10834 "VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current "
10835 "layout VK_IMAGE_LAYOUT_GENERAL.");
Cort530cf382016-12-08 09:59:47 -080010836 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 -060010837 m_errorMonitor->VerifyFound();
10838 m_errorMonitor->SetDesiredFailureMsg(
10839 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10840 "Layout for output image is VK_IMAGE_LAYOUT_UNDEFINED but can only be TRANSFER_DST_OPTIMAL or GENERAL.");
Cort530cf382016-12-08 09:59:47 -080010841 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 -060010842 m_errorMonitor->VerifyFound();
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010010843
Cort3b021012016-12-07 12:00:57 -080010844 // Convert dst and depth images to TRANSFER_DST for subsequent tests
10845 VkImageMemoryBarrier transfer_dst_image_barrier[1] = {};
10846 transfer_dst_image_barrier[0].sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
10847 transfer_dst_image_barrier[0].oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
10848 transfer_dst_image_barrier[0].newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
10849 transfer_dst_image_barrier[0].srcAccessMask = 0;
10850 transfer_dst_image_barrier[0].dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
10851 transfer_dst_image_barrier[0].image = dst_image;
10852 transfer_dst_image_barrier[0].subresourceRange.layerCount = image_create_info.arrayLayers;
10853 transfer_dst_image_barrier[0].subresourceRange.levelCount = image_create_info.mipLevels;
10854 transfer_dst_image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10855 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
10856 NULL, 0, NULL, 1, transfer_dst_image_barrier);
10857 transfer_dst_image_barrier[0].image = depth_image;
10858 transfer_dst_image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
10859 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
10860 NULL, 0, NULL, 1, transfer_dst_image_barrier);
10861
10862 // Cause errors due to clearing with invalid image layouts
Cort530cf382016-12-08 09:59:47 -080010863 VkClearColorValue color_clear_value = {};
10864 VkImageSubresourceRange clear_range;
10865 clear_range.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10866 clear_range.baseMipLevel = 0;
10867 clear_range.baseArrayLayer = 0;
10868 clear_range.layerCount = 1;
10869 clear_range.levelCount = 1;
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010010870
Cort3b021012016-12-07 12:00:57 -080010871 // Fail due to explicitly prohibited layout for color clear (only GENERAL and TRANSFER_DST are permitted).
10872 // Since the image is currently not in UNDEFINED layout, this will emit two errors.
10873 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01086);
10874 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01085);
Cort530cf382016-12-08 09:59:47 -080010875 m_commandBuffer->ClearColorImage(dst_image, VK_IMAGE_LAYOUT_UNDEFINED, &color_clear_value, 1, &clear_range);
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010010876 m_errorMonitor->VerifyFound();
Cort3b021012016-12-07 12:00:57 -080010877 // Fail due to provided layout not matching actual current layout for color clear.
10878 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01085);
Cort530cf382016-12-08 09:59:47 -080010879 m_commandBuffer->ClearColorImage(dst_image, VK_IMAGE_LAYOUT_GENERAL, &color_clear_value, 1, &clear_range);
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010010880 m_errorMonitor->VerifyFound();
Cort3b021012016-12-07 12:00:57 -080010881
Cort530cf382016-12-08 09:59:47 -080010882 VkClearDepthStencilValue depth_clear_value = {};
10883 clear_range.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
Cort3b021012016-12-07 12:00:57 -080010884
10885 // Fail due to explicitly prohibited layout for depth clear (only GENERAL and TRANSFER_DST are permitted).
10886 // Since the image is currently not in UNDEFINED layout, this will emit two errors.
10887 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01101);
10888 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01100);
Cort530cf382016-12-08 09:59:47 -080010889 m_commandBuffer->ClearDepthStencilImage(depth_image, VK_IMAGE_LAYOUT_UNDEFINED, &depth_clear_value, 1, &clear_range);
Cort3b021012016-12-07 12:00:57 -080010890 m_errorMonitor->VerifyFound();
10891 // Fail due to provided layout not matching actual current layout for depth clear.
10892 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01100);
Cort530cf382016-12-08 09:59:47 -080010893 m_commandBuffer->ClearDepthStencilImage(depth_image, VK_IMAGE_LAYOUT_GENERAL, &depth_clear_value, 1, &clear_range);
Cort3b021012016-12-07 12:00:57 -080010894 m_errorMonitor->VerifyFound();
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010010895
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010896 // Now cause error due to bad image layout transition in PipelineBarrier
10897 VkImageMemoryBarrier image_barrier[1] = {};
Cort3b021012016-12-07 12:00:57 -080010898 image_barrier[0].sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010899 image_barrier[0].oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
Cort3b021012016-12-07 12:00:57 -080010900 image_barrier[0].newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010901 image_barrier[0].image = src_image;
Cort3b021012016-12-07 12:00:57 -080010902 image_barrier[0].subresourceRange.layerCount = image_create_info.arrayLayers;
10903 image_barrier[0].subresourceRange.levelCount = image_create_info.mipLevels;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010904 image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010905 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "You cannot transition the layout from "
10906 "VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL when "
10907 "current layout is VK_IMAGE_LAYOUT_GENERAL.");
10908 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
10909 NULL, 0, NULL, 1, image_barrier);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010910 m_errorMonitor->VerifyFound();
10911
10912 // Finally some layout errors at RenderPass create time
10913 // Just hacking in specific state to get to the errors we want so don't copy this unless you know what you're doing.
10914 VkAttachmentReference attach = {};
10915 // perf warning for GENERAL layout w/ non-DS input attachment
10916 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
10917 VkSubpassDescription subpass = {};
10918 subpass.inputAttachmentCount = 1;
10919 subpass.pInputAttachments = &attach;
10920 VkRenderPassCreateInfo rpci = {};
10921 rpci.subpassCount = 1;
10922 rpci.pSubpasses = &subpass;
10923 rpci.attachmentCount = 1;
10924 VkAttachmentDescription attach_desc = {};
10925 attach_desc.format = VK_FORMAT_UNDEFINED;
10926 rpci.pAttachments = &attach_desc;
Tobin Ehlis1efce022016-05-11 10:40:34 -060010927 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010928 VkRenderPass rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010929 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10930 "Layout for input attachment is GENERAL but should be READ_ONLY_OPTIMAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010931 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10932 m_errorMonitor->VerifyFound();
10933 // error w/ non-general layout
10934 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
10935
10936 m_errorMonitor->SetDesiredFailureMsg(
10937 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10938 "Layout for input attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be READ_ONLY_OPTIMAL or GENERAL.");
10939 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10940 m_errorMonitor->VerifyFound();
10941 subpass.inputAttachmentCount = 0;
10942 subpass.colorAttachmentCount = 1;
10943 subpass.pColorAttachments = &attach;
10944 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
10945 // perf warning for GENERAL layout on color attachment
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010946 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10947 "Layout for color attachment is GENERAL but should be COLOR_ATTACHMENT_OPTIMAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010948 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10949 m_errorMonitor->VerifyFound();
10950 // error w/ non-color opt or GENERAL layout for color attachment
10951 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
10952 m_errorMonitor->SetDesiredFailureMsg(
10953 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10954 "Layout for color attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be COLOR_ATTACHMENT_OPTIMAL or GENERAL.");
10955 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10956 m_errorMonitor->VerifyFound();
10957 subpass.colorAttachmentCount = 0;
10958 subpass.pDepthStencilAttachment = &attach;
10959 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
10960 // perf warning for GENERAL layout on DS attachment
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010961 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10962 "GENERAL layout for depth attachment may not give optimal performance.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010963 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10964 m_errorMonitor->VerifyFound();
10965 // error w/ non-ds opt or GENERAL layout for color attachment
10966 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010967 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10968 "Layout for depth attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be "
10969 "DEPTH_STENCIL_ATTACHMENT_OPTIMAL, DEPTH_STENCIL_READ_ONLY_OPTIMAL or GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010970 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10971 m_errorMonitor->VerifyFound();
Tobin Ehlis1efce022016-05-11 10:40:34 -060010972 // For this error we need a valid renderpass so create default one
10973 attach.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
10974 attach.attachment = 0;
10975 attach_desc.format = VK_FORMAT_D24_UNORM_S8_UINT;
10976 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
10977 attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
10978 attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
10979 attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
10980 // Can't do a CLEAR load on READ_ONLY initialLayout
10981 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
10982 attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
10983 attach_desc.finalLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010984 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " with invalid first layout "
10985 "VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_"
10986 "ONLY_OPTIMAL");
Tobin Ehlis1efce022016-05-11 10:40:34 -060010987 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10988 m_errorMonitor->VerifyFound();
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010989
Cort3b021012016-12-07 12:00:57 -080010990 vkFreeMemory(m_device->device(), src_image_mem, NULL);
10991 vkFreeMemory(m_device->device(), dst_image_mem, NULL);
10992 vkFreeMemory(m_device->device(), depth_image_mem, NULL);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010993 vkDestroyImage(m_device->device(), src_image, NULL);
10994 vkDestroyImage(m_device->device(), dst_image, NULL);
Cort3b021012016-12-07 12:00:57 -080010995 vkDestroyImage(m_device->device(), depth_image, NULL);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010996}
Tobin Ehlisd8d89182016-07-18 20:13:11 -060010997
Tobin Ehlise0936662016-10-11 08:10:51 -060010998TEST_F(VkLayerTest, InvalidStorageImageLayout) {
10999 TEST_DESCRIPTION("Attempt to update a STORAGE_IMAGE descriptor w/o GENERAL layout.");
11000 VkResult err;
11001
11002 ASSERT_NO_FATAL_FAILURE(InitState());
11003
11004 const VkFormat tex_format = VK_FORMAT_R8G8B8A8_UNORM;
11005 VkImageTiling tiling;
11006 VkFormatProperties format_properties;
11007 vkGetPhysicalDeviceFormatProperties(gpu(), tex_format, &format_properties);
11008 if (format_properties.linearTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
11009 tiling = VK_IMAGE_TILING_LINEAR;
11010 } else if (format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
11011 tiling = VK_IMAGE_TILING_OPTIMAL;
11012 } else {
11013 printf("Device does not support VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT; "
11014 "skipped.\n");
11015 return;
11016 }
11017
11018 VkDescriptorPoolSize ds_type = {};
11019 ds_type.type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
11020 ds_type.descriptorCount = 1;
11021
11022 VkDescriptorPoolCreateInfo ds_pool_ci = {};
11023 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11024 ds_pool_ci.maxSets = 1;
11025 ds_pool_ci.poolSizeCount = 1;
11026 ds_pool_ci.pPoolSizes = &ds_type;
11027 ds_pool_ci.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
11028
11029 VkDescriptorPool ds_pool;
11030 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
11031 ASSERT_VK_SUCCESS(err);
11032
11033 VkDescriptorSetLayoutBinding dsl_binding = {};
11034 dsl_binding.binding = 0;
11035 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
11036 dsl_binding.descriptorCount = 1;
11037 dsl_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
11038 dsl_binding.pImmutableSamplers = NULL;
11039
11040 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11041 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11042 ds_layout_ci.pNext = NULL;
11043 ds_layout_ci.bindingCount = 1;
11044 ds_layout_ci.pBindings = &dsl_binding;
11045
11046 VkDescriptorSetLayout ds_layout;
11047 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
11048 ASSERT_VK_SUCCESS(err);
11049
11050 VkDescriptorSetAllocateInfo alloc_info = {};
11051 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11052 alloc_info.descriptorSetCount = 1;
11053 alloc_info.descriptorPool = ds_pool;
11054 alloc_info.pSetLayouts = &ds_layout;
11055 VkDescriptorSet descriptor_set;
11056 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
11057 ASSERT_VK_SUCCESS(err);
11058
11059 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11060 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11061 pipeline_layout_ci.pNext = NULL;
11062 pipeline_layout_ci.setLayoutCount = 1;
11063 pipeline_layout_ci.pSetLayouts = &ds_layout;
11064 VkPipelineLayout pipeline_layout;
11065 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
11066 ASSERT_VK_SUCCESS(err);
11067
11068 VkImageObj image(m_device);
11069 image.init(32, 32, tex_format, VK_IMAGE_USAGE_STORAGE_BIT, tiling, 0);
11070 ASSERT_TRUE(image.initialized());
11071 VkImageView view = image.targetView(tex_format);
11072
11073 VkDescriptorImageInfo image_info = {};
11074 image_info.imageView = view;
11075 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
11076
11077 VkWriteDescriptorSet descriptor_write = {};
11078 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
11079 descriptor_write.dstSet = descriptor_set;
11080 descriptor_write.dstBinding = 0;
11081 descriptor_write.descriptorCount = 1;
11082 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
11083 descriptor_write.pImageInfo = &image_info;
11084
11085 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11086 " of VK_DESCRIPTOR_TYPE_STORAGE_IMAGE type is being updated with layout "
11087 "VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL but according to spec ");
11088 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11089 m_errorMonitor->VerifyFound();
11090
11091 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11092 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11093 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
11094 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
11095}
11096
Mark Mueller93b938f2016-08-18 10:27:40 -060011097TEST_F(VkLayerTest, SimultaneousUse) {
11098 TEST_DESCRIPTION("Use vkCmdExecuteCommands with invalid state "
11099 "in primary and secondary command buffers.");
11100
11101 ASSERT_NO_FATAL_FAILURE(InitState());
11102 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11103
Mike Weiblen95dd0f92016-10-19 12:28:27 -060011104 const char *simultaneous_use_message1 = "without VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set!";
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011105 const char *simultaneous_use_message2 = "does not have VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set and "
11106 "will cause primary command buffer";
Mark Mueller93b938f2016-08-18 10:27:40 -060011107
11108 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011109 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Mueller93b938f2016-08-18 10:27:40 -060011110 command_buffer_allocate_info.commandPool = m_commandPool;
11111 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
11112 command_buffer_allocate_info.commandBufferCount = 1;
11113
11114 VkCommandBuffer secondary_command_buffer;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011115 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer));
Mark Mueller93b938f2016-08-18 10:27:40 -060011116 VkCommandBufferBeginInfo command_buffer_begin_info = {};
11117 VkCommandBufferInheritanceInfo command_buffer_inheritance_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011118 command_buffer_inheritance_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
Mark Mueller93b938f2016-08-18 10:27:40 -060011119 command_buffer_inheritance_info.renderPass = m_renderPass;
11120 command_buffer_inheritance_info.framebuffer = m_framebuffer;
Rene Lindsay24cf6c52017-01-04 12:06:59 -070011121
Mark Mueller93b938f2016-08-18 10:27:40 -060011122 command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011123 command_buffer_begin_info.flags =
11124 VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT | VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT;
Mark Mueller93b938f2016-08-18 10:27:40 -060011125 command_buffer_begin_info.pInheritanceInfo = &command_buffer_inheritance_info;
11126
11127 vkBeginCommandBuffer(secondary_command_buffer, &command_buffer_begin_info);
11128 vkEndCommandBuffer(secondary_command_buffer);
11129
Mark Mueller93b938f2016-08-18 10:27:40 -060011130 VkSubmitInfo submit_info = {};
11131 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11132 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011133 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Mueller93b938f2016-08-18 10:27:40 -060011134
Mark Mueller4042b652016-09-05 22:52:21 -060011135 vkBeginCommandBuffer(m_commandBuffer->handle(), &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011136 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
11137 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, simultaneous_use_message1);
11138 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Rene Lindsay24cf6c52017-01-04 12:06:59 -070011139 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller93b938f2016-08-18 10:27:40 -060011140 m_errorMonitor->VerifyFound();
Mark Mueller4042b652016-09-05 22:52:21 -060011141 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
11142 vkEndCommandBuffer(m_commandBuffer->handle());
Mark Mueller93b938f2016-08-18 10:27:40 -060011143
11144 m_errorMonitor->SetDesiredFailureMsg(0, "");
Mark Mueller93b938f2016-08-18 10:27:40 -060011145 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11146
Mark Mueller4042b652016-09-05 22:52:21 -060011147 command_buffer_begin_info.flags = VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT;
Mark Mueller93b938f2016-08-18 10:27:40 -060011148 vkBeginCommandBuffer(m_commandBuffer->handle(), &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011149 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
Mark Mueller4042b652016-09-05 22:52:21 -060011150
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011151 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, simultaneous_use_message2);
11152 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller93b938f2016-08-18 10:27:40 -060011153 m_errorMonitor->VerifyFound();
Mark Mueller4042b652016-09-05 22:52:21 -060011154 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
11155 vkEndCommandBuffer(m_commandBuffer->handle());
Rene Lindsay24cf6c52017-01-04 12:06:59 -070011156
11157 vkQueueWaitIdle(m_device->m_queue);
Mark Mueller93b938f2016-08-18 10:27:40 -060011158}
11159
Mark Mueller917f6bc2016-08-30 10:57:19 -060011160TEST_F(VkLayerTest, InUseDestroyedSignaled) {
11161 TEST_DESCRIPTION("Use vkCmdExecuteCommands with invalid state "
11162 "in primary and secondary command buffers. "
Mark Muellerc8d441e2016-08-23 17:36:00 -060011163 "Delete objects that are inuse. Call VkQueueSubmit "
11164 "with an event that has been deleted.");
Mark Mueller917f6bc2016-08-30 10:57:19 -060011165
11166 ASSERT_NO_FATAL_FAILURE(InitState());
11167 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11168
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011169 const char *submit_with_deleted_event_message = "Cannot submit cmd buffer using deleted event 0x";
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011170 const char *cannot_destroy_fence_message = "Fence 0x";
Mark Mueller917f6bc2016-08-30 10:57:19 -060011171
Tony Barbour552f6c02016-12-21 14:34:07 -070011172 m_commandBuffer->BeginCommandBuffer();
Mark Mueller917f6bc2016-08-30 10:57:19 -060011173
11174 VkEvent event;
11175 VkEventCreateInfo event_create_info = {};
11176 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
11177 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011178 vkCmdSetEvent(m_commandBuffer->handle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Mark Mueller917f6bc2016-08-30 10:57:19 -060011179
Tony Barbour552f6c02016-12-21 14:34:07 -070011180 m_commandBuffer->EndCommandBuffer();
Mark Muellerc8d441e2016-08-23 17:36:00 -060011181 vkDestroyEvent(m_device->device(), event, nullptr);
11182
11183 VkSubmitInfo submit_info = {};
11184 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11185 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011186 submit_info.pCommandBuffers = &m_commandBuffer->handle();
11187 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, submit_with_deleted_event_message);
Mark Muellerc8d441e2016-08-23 17:36:00 -060011188 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11189 m_errorMonitor->VerifyFound();
11190
11191 m_errorMonitor->SetDesiredFailureMsg(0, "");
11192 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
11193
11194 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
11195
Mark Mueller917f6bc2016-08-30 10:57:19 -060011196 VkSemaphoreCreateInfo semaphore_create_info = {};
11197 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
11198 VkSemaphore semaphore;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011199 ASSERT_VK_SUCCESS(vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore));
Mark Mueller917f6bc2016-08-30 10:57:19 -060011200 VkFenceCreateInfo fence_create_info = {};
11201 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
11202 VkFence fence;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011203 ASSERT_VK_SUCCESS(vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence));
Mark Mueller917f6bc2016-08-30 10:57:19 -060011204
11205 VkDescriptorPoolSize descriptor_pool_type_count = {};
Mark Mueller4042b652016-09-05 22:52:21 -060011206 descriptor_pool_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Mark Mueller917f6bc2016-08-30 10:57:19 -060011207 descriptor_pool_type_count.descriptorCount = 1;
11208
11209 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
11210 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11211 descriptor_pool_create_info.maxSets = 1;
11212 descriptor_pool_create_info.poolSizeCount = 1;
11213 descriptor_pool_create_info.pPoolSizes = &descriptor_pool_type_count;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011214 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
Mark Mueller917f6bc2016-08-30 10:57:19 -060011215
11216 VkDescriptorPool descriptorset_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011217 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
Mark Mueller917f6bc2016-08-30 10:57:19 -060011218
11219 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
Mark Mueller4042b652016-09-05 22:52:21 -060011220 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Mark Mueller917f6bc2016-08-30 10:57:19 -060011221 descriptorset_layout_binding.descriptorCount = 1;
11222 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_ALL;
11223
11224 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011225 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060011226 descriptorset_layout_create_info.bindingCount = 1;
11227 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
11228
11229 VkDescriptorSetLayout descriptorset_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011230 ASSERT_VK_SUCCESS(
11231 vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
Mark Mueller917f6bc2016-08-30 10:57:19 -060011232
11233 VkDescriptorSet descriptorset;
11234 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011235 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060011236 descriptorset_allocate_info.descriptorSetCount = 1;
11237 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
11238 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011239 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
Mark Mueller917f6bc2016-08-30 10:57:19 -060011240
Mark Mueller4042b652016-09-05 22:52:21 -060011241 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
11242
11243 VkDescriptorBufferInfo buffer_info = {};
11244 buffer_info.buffer = buffer_test.GetBuffer();
11245 buffer_info.offset = 0;
11246 buffer_info.range = 1024;
11247
11248 VkWriteDescriptorSet write_descriptor_set = {};
11249 write_descriptor_set.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
11250 write_descriptor_set.dstSet = descriptorset;
11251 write_descriptor_set.descriptorCount = 1;
11252 write_descriptor_set.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11253 write_descriptor_set.pBufferInfo = &buffer_info;
11254
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011255 vkUpdateDescriptorSets(m_device->device(), 1, &write_descriptor_set, 0, nullptr);
Mark Mueller4042b652016-09-05 22:52:21 -060011256
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011257 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
11258 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Mueller917f6bc2016-08-30 10:57:19 -060011259
11260 VkPipelineObj pipe(m_device);
11261 pipe.AddColorAttachment();
11262 pipe.AddShader(&vs);
11263 pipe.AddShader(&fs);
11264
11265 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011266 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060011267 pipeline_layout_create_info.setLayoutCount = 1;
11268 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
11269
11270 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011271 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
Mark Mueller917f6bc2016-08-30 10:57:19 -060011272
11273 pipe.CreateVKPipeline(pipeline_layout, m_renderPass);
11274
Tony Barbour552f6c02016-12-21 14:34:07 -070011275 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011276 vkCmdSetEvent(m_commandBuffer->handle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Mark Muellerc8d441e2016-08-23 17:36:00 -060011277
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011278 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
11279 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
11280 &descriptorset, 0, NULL);
Mark Mueller917f6bc2016-08-30 10:57:19 -060011281
Tony Barbour552f6c02016-12-21 14:34:07 -070011282 m_commandBuffer->EndCommandBuffer();
Mark Mueller917f6bc2016-08-30 10:57:19 -060011283
Mark Mueller917f6bc2016-08-30 10:57:19 -060011284 submit_info.signalSemaphoreCount = 1;
11285 submit_info.pSignalSemaphores = &semaphore;
11286 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
Mark Muellerc8d441e2016-08-23 17:36:00 -060011287
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070011288 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00213);
Mark Mueller917f6bc2016-08-30 10:57:19 -060011289 vkDestroyEvent(m_device->device(), event, nullptr);
11290 m_errorMonitor->VerifyFound();
11291
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070011292 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00199);
Mark Mueller917f6bc2016-08-30 10:57:19 -060011293 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
11294 m_errorMonitor->VerifyFound();
11295
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011296 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, cannot_destroy_fence_message);
Mark Mueller917f6bc2016-08-30 10:57:19 -060011297 vkDestroyFence(m_device->device(), fence, nullptr);
11298 m_errorMonitor->VerifyFound();
11299
Tobin Ehlis122207b2016-09-01 08:50:06 -070011300 vkQueueWaitIdle(m_device->m_queue);
Mark Mueller917f6bc2016-08-30 10:57:19 -060011301 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
11302 vkDestroyFence(m_device->device(), fence, nullptr);
11303 vkDestroyEvent(m_device->device(), event, nullptr);
11304 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011305 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
Mark Mueller917f6bc2016-08-30 10:57:19 -060011306 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
11307}
11308
Tobin Ehlis2adda372016-09-01 08:51:06 -070011309TEST_F(VkLayerTest, QueryPoolInUseDestroyedSignaled) {
11310 TEST_DESCRIPTION("Delete in-use query pool.");
11311
11312 ASSERT_NO_FATAL_FAILURE(InitState());
11313 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11314
11315 VkQueryPool query_pool;
11316 VkQueryPoolCreateInfo query_pool_ci{};
11317 query_pool_ci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
11318 query_pool_ci.queryType = VK_QUERY_TYPE_TIMESTAMP;
11319 query_pool_ci.queryCount = 1;
11320 vkCreateQueryPool(m_device->device(), &query_pool_ci, nullptr, &query_pool);
Tony Barbour552f6c02016-12-21 14:34:07 -070011321 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlis2adda372016-09-01 08:51:06 -070011322 // Reset query pool to create binding with cmd buffer
11323 vkCmdResetQueryPool(m_commandBuffer->handle(), query_pool, 0, 1);
11324
Tony Barbour552f6c02016-12-21 14:34:07 -070011325 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis2adda372016-09-01 08:51:06 -070011326
11327 VkSubmitInfo submit_info = {};
11328 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11329 submit_info.commandBufferCount = 1;
11330 submit_info.pCommandBuffers = &m_commandBuffer->handle();
11331 // Submit cmd buffer and then destroy query pool while in-flight
11332 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11333
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070011334 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01012);
Tobin Ehlis2adda372016-09-01 08:51:06 -070011335 vkDestroyQueryPool(m_device->handle(), query_pool, NULL);
11336 m_errorMonitor->VerifyFound();
11337
11338 vkQueueWaitIdle(m_device->m_queue);
11339 // Now that cmd buffer done we can safely destroy query_pool
11340 vkDestroyQueryPool(m_device->handle(), query_pool, NULL);
11341}
11342
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060011343TEST_F(VkLayerTest, PipelineInUseDestroyedSignaled) {
11344 TEST_DESCRIPTION("Delete in-use pipeline.");
11345
11346 ASSERT_NO_FATAL_FAILURE(InitState());
11347 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11348
11349 // Empty pipeline layout used for binding PSO
11350 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11351 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11352 pipeline_layout_ci.setLayoutCount = 0;
11353 pipeline_layout_ci.pSetLayouts = NULL;
11354
11355 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011356 VkResult err = vkCreatePipelineLayout(m_device->handle(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060011357 ASSERT_VK_SUCCESS(err);
11358
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070011359 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00555);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060011360 // Create PSO to be used for draw-time errors below
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011361 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
11362 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060011363 // Store pipeline handle so we can actually delete it before test finishes
11364 VkPipeline delete_this_pipeline;
11365 { // Scope pipeline so it will be auto-deleted
11366 VkPipelineObj pipe(m_device);
11367 pipe.AddShader(&vs);
11368 pipe.AddShader(&fs);
11369 pipe.AddColorAttachment();
11370 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11371 delete_this_pipeline = pipe.handle();
11372
Tony Barbour552f6c02016-12-21 14:34:07 -070011373 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060011374 // Bind pipeline to cmd buffer
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011375 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060011376
Tony Barbour552f6c02016-12-21 14:34:07 -070011377 m_commandBuffer->EndCommandBuffer();
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060011378
11379 VkSubmitInfo submit_info = {};
11380 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11381 submit_info.commandBufferCount = 1;
11382 submit_info.pCommandBuffers = &m_commandBuffer->handle();
11383 // Submit cmd buffer and then pipeline destroyed while in-flight
11384 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11385 } // Pipeline deletion triggered here
11386 m_errorMonitor->VerifyFound();
11387 // Make sure queue finished and then actually delete pipeline
11388 vkQueueWaitIdle(m_device->m_queue);
11389 vkDestroyPipeline(m_device->handle(), delete_this_pipeline, nullptr);
11390 vkDestroyPipelineLayout(m_device->handle(), pipeline_layout, nullptr);
11391}
11392
Tobin Ehlis7d965da2016-09-19 16:15:45 -060011393TEST_F(VkLayerTest, ImageViewInUseDestroyedSignaled) {
11394 TEST_DESCRIPTION("Delete in-use imageView.");
11395
11396 ASSERT_NO_FATAL_FAILURE(InitState());
11397 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11398
11399 VkDescriptorPoolSize ds_type_count;
11400 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11401 ds_type_count.descriptorCount = 1;
11402
11403 VkDescriptorPoolCreateInfo ds_pool_ci = {};
11404 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11405 ds_pool_ci.maxSets = 1;
11406 ds_pool_ci.poolSizeCount = 1;
11407 ds_pool_ci.pPoolSizes = &ds_type_count;
11408
11409 VkDescriptorPool ds_pool;
11410 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
11411 ASSERT_VK_SUCCESS(err);
11412
11413 VkSamplerCreateInfo sampler_ci = {};
11414 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
11415 sampler_ci.pNext = NULL;
11416 sampler_ci.magFilter = VK_FILTER_NEAREST;
11417 sampler_ci.minFilter = VK_FILTER_NEAREST;
11418 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
11419 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11420 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11421 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11422 sampler_ci.mipLodBias = 1.0;
11423 sampler_ci.anisotropyEnable = VK_FALSE;
11424 sampler_ci.maxAnisotropy = 1;
11425 sampler_ci.compareEnable = VK_FALSE;
11426 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
11427 sampler_ci.minLod = 1.0;
11428 sampler_ci.maxLod = 1.0;
11429 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
11430 sampler_ci.unnormalizedCoordinates = VK_FALSE;
11431 VkSampler sampler;
11432
11433 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
11434 ASSERT_VK_SUCCESS(err);
11435
11436 VkDescriptorSetLayoutBinding layout_binding;
11437 layout_binding.binding = 0;
11438 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11439 layout_binding.descriptorCount = 1;
11440 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
11441 layout_binding.pImmutableSamplers = NULL;
11442
11443 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11444 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11445 ds_layout_ci.bindingCount = 1;
11446 ds_layout_ci.pBindings = &layout_binding;
11447 VkDescriptorSetLayout ds_layout;
11448 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
11449 ASSERT_VK_SUCCESS(err);
11450
11451 VkDescriptorSetAllocateInfo alloc_info = {};
11452 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11453 alloc_info.descriptorSetCount = 1;
11454 alloc_info.descriptorPool = ds_pool;
11455 alloc_info.pSetLayouts = &ds_layout;
11456 VkDescriptorSet descriptor_set;
11457 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
11458 ASSERT_VK_SUCCESS(err);
11459
11460 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11461 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11462 pipeline_layout_ci.pNext = NULL;
11463 pipeline_layout_ci.setLayoutCount = 1;
11464 pipeline_layout_ci.pSetLayouts = &ds_layout;
11465
11466 VkPipelineLayout pipeline_layout;
11467 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
11468 ASSERT_VK_SUCCESS(err);
11469
11470 VkImageObj image(m_device);
11471 image.init(128, 128, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
11472 ASSERT_TRUE(image.initialized());
11473
11474 VkImageView view;
11475 VkImageViewCreateInfo ivci = {};
11476 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
11477 ivci.image = image.handle();
11478 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
11479 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
11480 ivci.subresourceRange.layerCount = 1;
11481 ivci.subresourceRange.baseMipLevel = 0;
11482 ivci.subresourceRange.levelCount = 1;
11483 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11484
11485 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
11486 ASSERT_VK_SUCCESS(err);
11487
11488 VkDescriptorImageInfo image_info{};
11489 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
11490 image_info.imageView = view;
11491 image_info.sampler = sampler;
11492
11493 VkWriteDescriptorSet descriptor_write = {};
11494 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
11495 descriptor_write.dstSet = descriptor_set;
11496 descriptor_write.dstBinding = 0;
11497 descriptor_write.descriptorCount = 1;
11498 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11499 descriptor_write.pImageInfo = &image_info;
11500
11501 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11502
11503 // Create PSO to use the sampler
11504 char const *vsSource = "#version 450\n"
11505 "\n"
11506 "out gl_PerVertex { \n"
11507 " vec4 gl_Position;\n"
11508 "};\n"
11509 "void main(){\n"
11510 " gl_Position = vec4(1);\n"
11511 "}\n";
11512 char const *fsSource = "#version 450\n"
11513 "\n"
11514 "layout(set=0, binding=0) uniform sampler2D s;\n"
11515 "layout(location=0) out vec4 x;\n"
11516 "void main(){\n"
11517 " x = texture(s, vec2(1));\n"
11518 "}\n";
11519 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
11520 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
11521 VkPipelineObj pipe(m_device);
11522 pipe.AddShader(&vs);
11523 pipe.AddShader(&fs);
11524 pipe.AddColorAttachment();
11525 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11526
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070011527 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00776);
Tobin Ehlis7d965da2016-09-19 16:15:45 -060011528
Tony Barbour552f6c02016-12-21 14:34:07 -070011529 m_commandBuffer->BeginCommandBuffer();
11530 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis7d965da2016-09-19 16:15:45 -060011531 // Bind pipeline to cmd buffer
11532 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
11533 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
11534 &descriptor_set, 0, nullptr);
11535 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -070011536 m_commandBuffer->EndRenderPass();
11537 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis7d965da2016-09-19 16:15:45 -060011538 // Submit cmd buffer then destroy sampler
11539 VkSubmitInfo submit_info = {};
11540 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11541 submit_info.commandBufferCount = 1;
11542 submit_info.pCommandBuffers = &m_commandBuffer->handle();
11543 // Submit cmd buffer and then destroy imageView while in-flight
11544 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11545
11546 vkDestroyImageView(m_device->device(), view, nullptr);
11547 m_errorMonitor->VerifyFound();
11548 vkQueueWaitIdle(m_device->m_queue);
11549 // Now we can actually destroy imageView
11550 vkDestroyImageView(m_device->device(), view, NULL);
11551 vkDestroySampler(m_device->device(), sampler, nullptr);
11552 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11553 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11554 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
11555}
11556
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060011557TEST_F(VkLayerTest, BufferViewInUseDestroyedSignaled) {
11558 TEST_DESCRIPTION("Delete in-use bufferView.");
11559
11560 ASSERT_NO_FATAL_FAILURE(InitState());
11561 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11562
11563 VkDescriptorPoolSize ds_type_count;
11564 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
11565 ds_type_count.descriptorCount = 1;
11566
11567 VkDescriptorPoolCreateInfo ds_pool_ci = {};
11568 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11569 ds_pool_ci.maxSets = 1;
11570 ds_pool_ci.poolSizeCount = 1;
11571 ds_pool_ci.pPoolSizes = &ds_type_count;
11572
11573 VkDescriptorPool ds_pool;
11574 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
11575 ASSERT_VK_SUCCESS(err);
11576
11577 VkDescriptorSetLayoutBinding layout_binding;
11578 layout_binding.binding = 0;
11579 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
11580 layout_binding.descriptorCount = 1;
11581 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
11582 layout_binding.pImmutableSamplers = NULL;
11583
11584 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11585 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11586 ds_layout_ci.bindingCount = 1;
11587 ds_layout_ci.pBindings = &layout_binding;
11588 VkDescriptorSetLayout ds_layout;
11589 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
11590 ASSERT_VK_SUCCESS(err);
11591
11592 VkDescriptorSetAllocateInfo alloc_info = {};
11593 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11594 alloc_info.descriptorSetCount = 1;
11595 alloc_info.descriptorPool = ds_pool;
11596 alloc_info.pSetLayouts = &ds_layout;
11597 VkDescriptorSet descriptor_set;
11598 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
11599 ASSERT_VK_SUCCESS(err);
11600
11601 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11602 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11603 pipeline_layout_ci.pNext = NULL;
11604 pipeline_layout_ci.setLayoutCount = 1;
11605 pipeline_layout_ci.pSetLayouts = &ds_layout;
11606
11607 VkPipelineLayout pipeline_layout;
11608 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
11609 ASSERT_VK_SUCCESS(err);
11610
11611 VkBuffer buffer;
11612 uint32_t queue_family_index = 0;
11613 VkBufferCreateInfo buffer_create_info = {};
11614 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
11615 buffer_create_info.size = 1024;
11616 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
11617 buffer_create_info.queueFamilyIndexCount = 1;
11618 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
11619
11620 err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
11621 ASSERT_VK_SUCCESS(err);
11622
11623 VkMemoryRequirements memory_reqs;
11624 VkDeviceMemory buffer_memory;
11625
11626 VkMemoryAllocateInfo memory_info = {};
11627 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
11628 memory_info.allocationSize = 0;
11629 memory_info.memoryTypeIndex = 0;
11630
11631 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
11632 memory_info.allocationSize = memory_reqs.size;
11633 bool pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
11634 ASSERT_TRUE(pass);
11635
11636 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
11637 ASSERT_VK_SUCCESS(err);
11638 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
11639 ASSERT_VK_SUCCESS(err);
11640
11641 VkBufferView view;
11642 VkBufferViewCreateInfo bvci = {};
11643 bvci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
11644 bvci.buffer = buffer;
11645 bvci.format = VK_FORMAT_R8_UNORM;
11646 bvci.range = VK_WHOLE_SIZE;
11647
11648 err = vkCreateBufferView(m_device->device(), &bvci, NULL, &view);
11649 ASSERT_VK_SUCCESS(err);
11650
11651 VkWriteDescriptorSet descriptor_write = {};
11652 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
11653 descriptor_write.dstSet = descriptor_set;
11654 descriptor_write.dstBinding = 0;
11655 descriptor_write.descriptorCount = 1;
11656 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
11657 descriptor_write.pTexelBufferView = &view;
11658
11659 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11660
11661 char const *vsSource = "#version 450\n"
11662 "\n"
11663 "out gl_PerVertex { \n"
11664 " vec4 gl_Position;\n"
11665 "};\n"
11666 "void main(){\n"
11667 " gl_Position = vec4(1);\n"
11668 "}\n";
11669 char const *fsSource = "#version 450\n"
11670 "\n"
11671 "layout(set=0, binding=0, r8) uniform imageBuffer s;\n"
11672 "layout(location=0) out vec4 x;\n"
11673 "void main(){\n"
11674 " x = imageLoad(s, 0);\n"
11675 "}\n";
11676 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
11677 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
11678 VkPipelineObj pipe(m_device);
11679 pipe.AddShader(&vs);
11680 pipe.AddShader(&fs);
11681 pipe.AddColorAttachment();
11682 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11683
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070011684 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00701);
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060011685
Tony Barbour552f6c02016-12-21 14:34:07 -070011686 m_commandBuffer->BeginCommandBuffer();
11687 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060011688 VkViewport viewport = {0, 0, 16, 16, 0, 1};
11689 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
11690 VkRect2D scissor = {{0, 0}, {16, 16}};
11691 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
11692 // Bind pipeline to cmd buffer
11693 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
11694 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
11695 &descriptor_set, 0, nullptr);
11696 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -070011697 m_commandBuffer->EndRenderPass();
11698 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060011699
11700 VkSubmitInfo submit_info = {};
11701 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11702 submit_info.commandBufferCount = 1;
11703 submit_info.pCommandBuffers = &m_commandBuffer->handle();
11704 // Submit cmd buffer and then destroy bufferView while in-flight
11705 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11706
11707 vkDestroyBufferView(m_device->device(), view, nullptr);
11708 m_errorMonitor->VerifyFound();
11709 vkQueueWaitIdle(m_device->m_queue);
11710 // Now we can actually destroy bufferView
11711 vkDestroyBufferView(m_device->device(), view, NULL);
11712 vkDestroyBuffer(m_device->device(), buffer, NULL);
11713 vkFreeMemory(m_device->device(), buffer_memory, NULL);
11714 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11715 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11716 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
11717}
11718
Tobin Ehlis209532e2016-09-07 13:52:18 -060011719TEST_F(VkLayerTest, SamplerInUseDestroyedSignaled) {
11720 TEST_DESCRIPTION("Delete in-use sampler.");
11721
11722 ASSERT_NO_FATAL_FAILURE(InitState());
11723 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11724
11725 VkDescriptorPoolSize ds_type_count;
11726 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11727 ds_type_count.descriptorCount = 1;
11728
11729 VkDescriptorPoolCreateInfo ds_pool_ci = {};
11730 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11731 ds_pool_ci.maxSets = 1;
11732 ds_pool_ci.poolSizeCount = 1;
11733 ds_pool_ci.pPoolSizes = &ds_type_count;
11734
11735 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011736 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis209532e2016-09-07 13:52:18 -060011737 ASSERT_VK_SUCCESS(err);
11738
11739 VkSamplerCreateInfo sampler_ci = {};
11740 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
11741 sampler_ci.pNext = NULL;
11742 sampler_ci.magFilter = VK_FILTER_NEAREST;
11743 sampler_ci.minFilter = VK_FILTER_NEAREST;
11744 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
11745 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11746 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11747 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11748 sampler_ci.mipLodBias = 1.0;
11749 sampler_ci.anisotropyEnable = VK_FALSE;
11750 sampler_ci.maxAnisotropy = 1;
11751 sampler_ci.compareEnable = VK_FALSE;
11752 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
11753 sampler_ci.minLod = 1.0;
11754 sampler_ci.maxLod = 1.0;
11755 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
11756 sampler_ci.unnormalizedCoordinates = VK_FALSE;
11757 VkSampler sampler;
11758
11759 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
11760 ASSERT_VK_SUCCESS(err);
11761
11762 VkDescriptorSetLayoutBinding layout_binding;
11763 layout_binding.binding = 0;
Tobin Ehlis94fc0ad2016-09-19 16:23:01 -060011764 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
Tobin Ehlis209532e2016-09-07 13:52:18 -060011765 layout_binding.descriptorCount = 1;
11766 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
11767 layout_binding.pImmutableSamplers = NULL;
11768
11769 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11770 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11771 ds_layout_ci.bindingCount = 1;
11772 ds_layout_ci.pBindings = &layout_binding;
11773 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011774 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis209532e2016-09-07 13:52:18 -060011775 ASSERT_VK_SUCCESS(err);
11776
11777 VkDescriptorSetAllocateInfo alloc_info = {};
11778 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11779 alloc_info.descriptorSetCount = 1;
11780 alloc_info.descriptorPool = ds_pool;
11781 alloc_info.pSetLayouts = &ds_layout;
11782 VkDescriptorSet descriptor_set;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011783 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis209532e2016-09-07 13:52:18 -060011784 ASSERT_VK_SUCCESS(err);
11785
11786 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11787 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11788 pipeline_layout_ci.pNext = NULL;
11789 pipeline_layout_ci.setLayoutCount = 1;
11790 pipeline_layout_ci.pSetLayouts = &ds_layout;
11791
11792 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011793 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis209532e2016-09-07 13:52:18 -060011794 ASSERT_VK_SUCCESS(err);
11795
11796 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011797 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 -060011798 ASSERT_TRUE(image.initialized());
11799
11800 VkImageView view;
11801 VkImageViewCreateInfo ivci = {};
11802 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
11803 ivci.image = image.handle();
11804 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
11805 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
11806 ivci.subresourceRange.layerCount = 1;
11807 ivci.subresourceRange.baseMipLevel = 0;
11808 ivci.subresourceRange.levelCount = 1;
11809 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11810
11811 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
11812 ASSERT_VK_SUCCESS(err);
11813
11814 VkDescriptorImageInfo image_info{};
11815 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
11816 image_info.imageView = view;
11817 image_info.sampler = sampler;
11818
11819 VkWriteDescriptorSet descriptor_write = {};
11820 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
11821 descriptor_write.dstSet = descriptor_set;
11822 descriptor_write.dstBinding = 0;
11823 descriptor_write.descriptorCount = 1;
11824 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11825 descriptor_write.pImageInfo = &image_info;
11826
11827 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11828
11829 // Create PSO to use the sampler
11830 char const *vsSource = "#version 450\n"
11831 "\n"
11832 "out gl_PerVertex { \n"
11833 " vec4 gl_Position;\n"
11834 "};\n"
11835 "void main(){\n"
11836 " gl_Position = vec4(1);\n"
11837 "}\n";
11838 char const *fsSource = "#version 450\n"
11839 "\n"
11840 "layout(set=0, binding=0) uniform sampler2D s;\n"
11841 "layout(location=0) out vec4 x;\n"
11842 "void main(){\n"
11843 " x = texture(s, vec2(1));\n"
11844 "}\n";
11845 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
11846 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
11847 VkPipelineObj pipe(m_device);
11848 pipe.AddShader(&vs);
11849 pipe.AddShader(&fs);
11850 pipe.AddColorAttachment();
11851 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11852
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070011853 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00837);
Tobin Ehlis209532e2016-09-07 13:52:18 -060011854
Tony Barbour552f6c02016-12-21 14:34:07 -070011855 m_commandBuffer->BeginCommandBuffer();
11856 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis209532e2016-09-07 13:52:18 -060011857 // Bind pipeline to cmd buffer
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011858 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
11859 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
11860 &descriptor_set, 0, nullptr);
Tobin Ehlis209532e2016-09-07 13:52:18 -060011861 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -070011862 m_commandBuffer->EndRenderPass();
11863 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis209532e2016-09-07 13:52:18 -060011864 // Submit cmd buffer then destroy sampler
11865 VkSubmitInfo submit_info = {};
11866 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11867 submit_info.commandBufferCount = 1;
11868 submit_info.pCommandBuffers = &m_commandBuffer->handle();
11869 // Submit cmd buffer and then destroy sampler while in-flight
11870 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11871
11872 vkDestroySampler(m_device->device(), sampler, nullptr);
11873 m_errorMonitor->VerifyFound();
11874 vkQueueWaitIdle(m_device->m_queue);
11875 // Now we can actually destroy sampler
11876 vkDestroySampler(m_device->device(), sampler, nullptr);
11877 vkDestroyImageView(m_device->device(), view, NULL);
11878 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11879 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11880 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
11881}
11882
Mark Mueller1cd9f412016-08-25 13:23:52 -060011883TEST_F(VkLayerTest, QueueForwardProgressFenceWait) {
Mark Mueller96a56d52016-08-24 10:28:05 -060011884 TEST_DESCRIPTION("Call VkQueueSubmit with a semaphore that is already "
Mark Mueller1cd9f412016-08-25 13:23:52 -060011885 "signaled but not waited on by the queue. Wait on a "
11886 "fence that has not yet been submitted to a queue.");
Mark Mueller96a56d52016-08-24 10:28:05 -060011887
11888 ASSERT_NO_FATAL_FAILURE(InitState());
11889 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11890
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011891 const char *queue_forward_progress_message = " that has already been signaled but not waited on by queue 0x";
11892 const char *invalid_fence_wait_message = " which has not been submitted on a Queue or during "
11893 "acquire next image.";
Mark Mueller96a56d52016-08-24 10:28:05 -060011894
Tony Barbour552f6c02016-12-21 14:34:07 -070011895 m_commandBuffer->BeginCommandBuffer();
11896 m_commandBuffer->EndCommandBuffer();
Mark Mueller96a56d52016-08-24 10:28:05 -060011897
11898 VkSemaphoreCreateInfo semaphore_create_info = {};
11899 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
11900 VkSemaphore semaphore;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011901 ASSERT_VK_SUCCESS(vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore));
Mark Mueller96a56d52016-08-24 10:28:05 -060011902 VkSubmitInfo submit_info = {};
11903 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11904 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011905 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Mueller96a56d52016-08-24 10:28:05 -060011906 submit_info.signalSemaphoreCount = 1;
11907 submit_info.pSignalSemaphores = &semaphore;
11908 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11909 m_errorMonitor->SetDesiredFailureMsg(0, "");
11910 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
Tony Barbour552f6c02016-12-21 14:34:07 -070011911 m_commandBuffer->BeginCommandBuffer();
11912 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011913 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, queue_forward_progress_message);
Mark Mueller96a56d52016-08-24 10:28:05 -060011914 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11915 m_errorMonitor->VerifyFound();
11916
Mark Mueller1cd9f412016-08-25 13:23:52 -060011917 VkFenceCreateInfo fence_create_info = {};
11918 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
11919 VkFence fence;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011920 ASSERT_VK_SUCCESS(vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence));
Mark Mueller1cd9f412016-08-25 13:23:52 -060011921
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011922 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, invalid_fence_wait_message);
Mark Mueller1cd9f412016-08-25 13:23:52 -060011923 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
11924 m_errorMonitor->VerifyFound();
11925
Mark Mueller4042b652016-09-05 22:52:21 -060011926 vkDeviceWaitIdle(m_device->device());
Mark Mueller1cd9f412016-08-25 13:23:52 -060011927 vkDestroyFence(m_device->device(), fence, nullptr);
Mark Mueller96a56d52016-08-24 10:28:05 -060011928 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
11929}
11930
Tobin Ehlis4af23302016-07-19 10:50:30 -060011931TEST_F(VkLayerTest, FramebufferIncompatible) {
11932 TEST_DESCRIPTION("Bind a secondary command buffer with with a framebuffer "
11933 "that does not match the framebuffer for the active "
11934 "renderpass.");
11935 ASSERT_NO_FATAL_FAILURE(InitState());
11936 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11937
11938 // A renderpass with one color attachment.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011939 VkAttachmentDescription attachment = {0,
11940 VK_FORMAT_B8G8R8A8_UNORM,
11941 VK_SAMPLE_COUNT_1_BIT,
11942 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
11943 VK_ATTACHMENT_STORE_OP_STORE,
11944 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
11945 VK_ATTACHMENT_STORE_OP_DONT_CARE,
11946 VK_IMAGE_LAYOUT_UNDEFINED,
11947 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis4af23302016-07-19 10:50:30 -060011948
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011949 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis4af23302016-07-19 10:50:30 -060011950
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011951 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Tobin Ehlis4af23302016-07-19 10:50:30 -060011952
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011953 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
Tobin Ehlis4af23302016-07-19 10:50:30 -060011954
11955 VkRenderPass rp;
11956 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
11957 ASSERT_VK_SUCCESS(err);
11958
11959 // A compatible framebuffer.
11960 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011961 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 -060011962 ASSERT_TRUE(image.initialized());
11963
11964 VkImageViewCreateInfo ivci = {
11965 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
11966 nullptr,
11967 0,
11968 image.handle(),
11969 VK_IMAGE_VIEW_TYPE_2D,
11970 VK_FORMAT_B8G8R8A8_UNORM,
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011971 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
11972 VK_COMPONENT_SWIZZLE_IDENTITY},
Tobin Ehlis4af23302016-07-19 10:50:30 -060011973 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
11974 };
11975 VkImageView view;
11976 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
11977 ASSERT_VK_SUCCESS(err);
11978
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011979 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Tobin Ehlis4af23302016-07-19 10:50:30 -060011980 VkFramebuffer fb;
11981 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
11982 ASSERT_VK_SUCCESS(err);
11983
11984 VkCommandBufferAllocateInfo cbai = {};
11985 cbai.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
11986 cbai.commandPool = m_commandPool;
11987 cbai.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
11988 cbai.commandBufferCount = 1;
11989
11990 VkCommandBuffer sec_cb;
11991 err = vkAllocateCommandBuffers(m_device->device(), &cbai, &sec_cb);
11992 ASSERT_VK_SUCCESS(err);
11993 VkCommandBufferBeginInfo cbbi = {};
11994 VkCommandBufferInheritanceInfo cbii = {};
Chris Forbes98420382016-11-28 17:56:51 +130011995 cbii.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
Tobin Ehlis4af23302016-07-19 10:50:30 -060011996 cbii.renderPass = renderPass();
11997 cbii.framebuffer = fb;
11998 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
11999 cbbi.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012000 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 -060012001 cbbi.pInheritanceInfo = &cbii;
12002 vkBeginCommandBuffer(sec_cb, &cbbi);
12003 vkEndCommandBuffer(sec_cb);
12004
Chris Forbes3400bc52016-09-13 18:10:34 +120012005 VkCommandBufferBeginInfo cbbi2 = {
12006 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr,
12007 0, nullptr
12008 };
12009 vkBeginCommandBuffer(m_commandBuffer->GetBufferHandle(), &cbbi2);
12010 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
Tobin Ehlis4af23302016-07-19 10:50:30 -060012011
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012012 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mike Weiblencce7ec72016-10-17 19:33:05 -060012013 " that is not the same as the primary command buffer's current active framebuffer ");
Tobin Ehlis4af23302016-07-19 10:50:30 -060012014 vkCmdExecuteCommands(m_commandBuffer->GetBufferHandle(), 1, &sec_cb);
12015 m_errorMonitor->VerifyFound();
12016 // Cleanup
12017 vkDestroyImageView(m_device->device(), view, NULL);
12018 vkDestroyRenderPass(m_device->device(), rp, NULL);
12019 vkDestroyFramebuffer(m_device->device(), fb, NULL);
12020}
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012021
12022TEST_F(VkLayerTest, ColorBlendLogicOpTests) {
12023 TEST_DESCRIPTION("If logicOp is available on the device, set it to an "
12024 "invalid value. If logicOp is not available, attempt to "
12025 "use it and verify that we see the correct error.");
12026 ASSERT_NO_FATAL_FAILURE(InitState());
12027 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12028
12029 auto features = m_device->phy().features();
12030 // Set the expected error depending on whether or not logicOp available
12031 if (VK_FALSE == features.logicOp) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012032 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "If logic operations feature not "
12033 "enabled, logicOpEnable must be "
12034 "VK_FALSE");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012035 } else {
Chris Forbes34797bc2016-10-03 15:28:49 +130012036 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "pColorBlendState->logicOp (16)");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012037 }
12038 // Create a pipeline using logicOp
12039 VkResult err;
12040
12041 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
12042 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12043
12044 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012045 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012046 ASSERT_VK_SUCCESS(err);
12047
12048 VkPipelineViewportStateCreateInfo vp_state_ci = {};
12049 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
12050 vp_state_ci.viewportCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012051 VkViewport vp = {}; // Just need dummy vp to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012052 vp_state_ci.pViewports = &vp;
12053 vp_state_ci.scissorCount = 1;
12054 VkRect2D scissors = {}; // Dummy scissors to point to
12055 vp_state_ci.pScissors = &scissors;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012056
12057 VkPipelineShaderStageCreateInfo shaderStages[2];
12058 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
12059
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012060 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
12061 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012062 shaderStages[0] = vs.GetStageCreateInfo();
12063 shaderStages[1] = fs.GetStageCreateInfo();
12064
12065 VkPipelineVertexInputStateCreateInfo vi_ci = {};
12066 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
12067
12068 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
12069 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
12070 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
12071
12072 VkPipelineRasterizationStateCreateInfo rs_ci = {};
12073 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Chris Forbes14088512016-10-03 14:28:00 +130012074 rs_ci.lineWidth = 1.0f;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012075
12076 VkPipelineColorBlendAttachmentState att = {};
12077 att.blendEnable = VK_FALSE;
12078 att.colorWriteMask = 0xf;
12079
12080 VkPipelineColorBlendStateCreateInfo cb_ci = {};
12081 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
12082 // Enable logicOp & set logicOp to value 1 beyond allowed entries
12083 cb_ci.logicOpEnable = VK_TRUE;
12084 cb_ci.logicOp = VK_LOGIC_OP_RANGE_SIZE; // This should cause an error
12085 cb_ci.attachmentCount = 1;
12086 cb_ci.pAttachments = &att;
12087
Chris Forbes8aeacbf2016-10-03 14:25:08 +130012088 VkPipelineMultisampleStateCreateInfo ms_ci = {};
12089 ms_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
12090 ms_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
12091
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012092 VkGraphicsPipelineCreateInfo gp_ci = {};
12093 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
12094 gp_ci.stageCount = 2;
12095 gp_ci.pStages = shaderStages;
12096 gp_ci.pVertexInputState = &vi_ci;
12097 gp_ci.pInputAssemblyState = &ia_ci;
12098 gp_ci.pViewportState = &vp_state_ci;
12099 gp_ci.pRasterizationState = &rs_ci;
12100 gp_ci.pColorBlendState = &cb_ci;
Chris Forbes8aeacbf2016-10-03 14:25:08 +130012101 gp_ci.pMultisampleState = &ms_ci;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012102 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
12103 gp_ci.layout = pipeline_layout;
12104 gp_ci.renderPass = renderPass();
12105
12106 VkPipelineCacheCreateInfo pc_ci = {};
12107 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
12108
12109 VkPipeline pipeline;
12110 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012111 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012112 ASSERT_VK_SUCCESS(err);
12113
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012114 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012115 m_errorMonitor->VerifyFound();
12116 if (VK_SUCCESS == err) {
12117 vkDestroyPipeline(m_device->device(), pipeline, NULL);
12118 }
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012119 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
12120 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
12121}
Mark Lobodzinski209b5292015-09-17 09:44:05 -060012122#endif // DRAW_STATE_TESTS
12123
Tobin Ehlis0788f522015-05-26 16:11:58 -060012124#if THREADING_TESTS
Mike Stroyanaccf7692015-05-12 16:00:45 -060012125#if GTEST_IS_THREADSAFE
12126struct thread_data_struct {
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012127 VkCommandBuffer commandBuffer;
Mike Stroyanaccf7692015-05-12 16:00:45 -060012128 VkEvent event;
12129 bool bailout;
12130};
12131
Karl Schultz6addd812016-02-02 17:17:23 -070012132extern "C" void *AddToCommandBuffer(void *arg) {
12133 struct thread_data_struct *data = (struct thread_data_struct *)arg;
Mike Stroyanaccf7692015-05-12 16:00:45 -060012134
Mike Stroyana6d14942016-07-13 15:10:05 -060012135 for (int i = 0; i < 80000; i++) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012136 vkCmdSetEvent(data->commandBuffer, data->event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Mike Stroyanaccf7692015-05-12 16:00:45 -060012137 if (data->bailout) {
12138 break;
12139 }
12140 }
12141 return NULL;
12142}
12143
Karl Schultz6addd812016-02-02 17:17:23 -070012144TEST_F(VkLayerTest, ThreadCommandBufferCollision) {
Mike Stroyan4268d1f2015-07-13 14:45:35 -060012145 test_platform_thread thread;
Mike Stroyanaccf7692015-05-12 16:00:45 -060012146
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012147 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "THREADING ERROR");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012148
Mike Stroyanaccf7692015-05-12 16:00:45 -060012149 ASSERT_NO_FATAL_FAILURE(InitState());
12150 ASSERT_NO_FATAL_FAILURE(InitViewport());
12151 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12152
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012153 // Calls AllocateCommandBuffers
12154 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Mark Lobodzinski5495d132015-09-30 16:19:16 -060012155
12156 // Avoid creating RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012157 commandBuffer.BeginCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -060012158
12159 VkEventCreateInfo event_info;
12160 VkEvent event;
Mike Stroyanaccf7692015-05-12 16:00:45 -060012161 VkResult err;
12162
12163 memset(&event_info, 0, sizeof(event_info));
12164 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
12165
Chia-I Wuf7458c52015-10-26 21:10:41 +080012166 err = vkCreateEvent(device(), &event_info, NULL, &event);
Mike Stroyanaccf7692015-05-12 16:00:45 -060012167 ASSERT_VK_SUCCESS(err);
12168
Mike Stroyanaccf7692015-05-12 16:00:45 -060012169 err = vkResetEvent(device(), event);
12170 ASSERT_VK_SUCCESS(err);
12171
12172 struct thread_data_struct data;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012173 data.commandBuffer = commandBuffer.GetBufferHandle();
Mike Stroyanaccf7692015-05-12 16:00:45 -060012174 data.event = event;
12175 data.bailout = false;
12176 m_errorMonitor->SetBailout(&data.bailout);
Mike Stroyana6d14942016-07-13 15:10:05 -060012177
12178 // First do some correct operations using multiple threads.
12179 // Add many entries to command buffer from another thread.
12180 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
12181 // Make non-conflicting calls from this thread at the same time.
12182 for (int i = 0; i < 80000; i++) {
Mike Stroyand6343902016-07-14 08:56:16 -060012183 uint32_t count;
12184 vkEnumeratePhysicalDevices(instance(), &count, NULL);
Mike Stroyana6d14942016-07-13 15:10:05 -060012185 }
12186 test_platform_thread_join(thread, NULL);
12187
12188 // Then do some incorrect operations using multiple threads.
Mike Stroyanaccf7692015-05-12 16:00:45 -060012189 // Add many entries to command buffer from another thread.
Mike Stroyan4268d1f2015-07-13 14:45:35 -060012190 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
Mike Stroyanaccf7692015-05-12 16:00:45 -060012191 // Add many entries to command buffer from this thread at the same time.
12192 AddToCommandBuffer(&data);
Mark Lobodzinski5495d132015-09-30 16:19:16 -060012193
Mike Stroyan4268d1f2015-07-13 14:45:35 -060012194 test_platform_thread_join(thread, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012195 commandBuffer.EndCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -060012196
Mike Stroyan10b8cb72016-01-22 15:22:03 -070012197 m_errorMonitor->SetBailout(NULL);
12198
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012199 m_errorMonitor->VerifyFound();
Mike Stroyanaccf7692015-05-12 16:00:45 -060012200
Chia-I Wuf7458c52015-10-26 21:10:41 +080012201 vkDestroyEvent(device(), event, NULL);
Mike Stroyanaccf7692015-05-12 16:00:45 -060012202}
Mark Lobodzinski209b5292015-09-17 09:44:05 -060012203#endif // GTEST_IS_THREADSAFE
12204#endif // THREADING_TESTS
12205
Chris Forbes9f7ff632015-05-25 11:13:08 +120012206#if SHADER_CHECKER_TESTS
Karl Schultz6addd812016-02-02 17:17:23 -070012207TEST_F(VkLayerTest, InvalidSPIRVCodeSize) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012208 TEST_DESCRIPTION("Test that an error is produced for a spirv module "
12209 "with an impossible code size");
12210
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012211 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012212
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012213 ASSERT_NO_FATAL_FAILURE(InitState());
12214 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12215
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012216 VkShaderModule module;
12217 VkShaderModuleCreateInfo moduleCreateInfo;
12218 struct icd_spv_header spv;
12219
12220 spv.magic = ICD_SPV_MAGIC;
12221 spv.version = ICD_SPV_VERSION;
12222 spv.gen_magic = 0;
12223
12224 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
12225 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -070012226 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012227 moduleCreateInfo.codeSize = 4;
12228 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080012229 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012230
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012231 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012232}
12233
Karl Schultz6addd812016-02-02 17:17:23 -070012234TEST_F(VkLayerTest, InvalidSPIRVMagic) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012235 TEST_DESCRIPTION("Test that an error is produced for a spirv module "
12236 "with a bad magic number");
12237
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012238 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid SPIR-V magic number");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012239
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012240 ASSERT_NO_FATAL_FAILURE(InitState());
12241 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12242
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012243 VkShaderModule module;
12244 VkShaderModuleCreateInfo moduleCreateInfo;
12245 struct icd_spv_header spv;
12246
12247 spv.magic = ~ICD_SPV_MAGIC;
12248 spv.version = ICD_SPV_VERSION;
12249 spv.gen_magic = 0;
12250
12251 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
12252 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -070012253 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012254 moduleCreateInfo.codeSize = sizeof(spv) + 10;
12255 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080012256 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012257
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012258 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012259}
12260
Chris Forbesb4afd0f2016-04-04 10:48:35 +120012261#if 0
12262// Not currently covered by SPIRV-Tools validator
Karl Schultz6addd812016-02-02 17:17:23 -070012263TEST_F(VkLayerTest, InvalidSPIRVVersion) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -070012264 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbesb4afd0f2016-04-04 10:48:35 +120012265 "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012266
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012267 ASSERT_NO_FATAL_FAILURE(InitState());
12268 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12269
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012270 VkShaderModule module;
12271 VkShaderModuleCreateInfo moduleCreateInfo;
12272 struct icd_spv_header spv;
12273
12274 spv.magic = ICD_SPV_MAGIC;
12275 spv.version = ~ICD_SPV_VERSION;
12276 spv.gen_magic = 0;
12277
12278 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
12279 moduleCreateInfo.pNext = NULL;
12280
Karl Schultz6addd812016-02-02 17:17:23 -070012281 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012282 moduleCreateInfo.codeSize = sizeof(spv) + 10;
12283 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080012284 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012285
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012286 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012287}
Chris Forbesb4afd0f2016-04-04 10:48:35 +120012288#endif
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012289
Karl Schultz6addd812016-02-02 17:17:23 -070012290TEST_F(VkLayerTest, CreatePipelineVertexOutputNotConsumed) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012291 TEST_DESCRIPTION("Test that a warning is produced for a vertex output that "
12292 "is not consumed by the fragment stage");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012293 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "not consumed by fragment shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012294
Chris Forbes9f7ff632015-05-25 11:13:08 +120012295 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060012296 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes9f7ff632015-05-25 11:13:08 +120012297
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012298 char const *vsSource = "#version 450\n"
12299 "\n"
12300 "layout(location=0) out float x;\n"
12301 "out gl_PerVertex {\n"
12302 " vec4 gl_Position;\n"
12303 "};\n"
12304 "void main(){\n"
12305 " gl_Position = vec4(1);\n"
12306 " x = 0;\n"
12307 "}\n";
12308 char const *fsSource = "#version 450\n"
12309 "\n"
12310 "layout(location=0) out vec4 color;\n"
12311 "void main(){\n"
12312 " color = vec4(1);\n"
12313 "}\n";
Chris Forbes9f7ff632015-05-25 11:13:08 +120012314
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012315 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12316 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes9f7ff632015-05-25 11:13:08 +120012317
12318 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080012319 pipe.AddColorAttachment();
Chris Forbes9f7ff632015-05-25 11:13:08 +120012320 pipe.AddShader(&vs);
12321 pipe.AddShader(&fs);
12322
Chris Forbes9f7ff632015-05-25 11:13:08 +120012323 VkDescriptorSetObj descriptorSet(m_device);
12324 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012325 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes9f7ff632015-05-25 11:13:08 +120012326
Tony Barbour5781e8f2015-08-04 16:23:11 -060012327 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes9f7ff632015-05-25 11:13:08 +120012328
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012329 m_errorMonitor->VerifyFound();
Chris Forbes9f7ff632015-05-25 11:13:08 +120012330}
Chris Forbes9f7ff632015-05-25 11:13:08 +120012331
Mark Mueller098c9cb2016-09-08 09:01:57 -060012332TEST_F(VkLayerTest, CreatePipelineCheckShaderBadSpecialization) {
12333 TEST_DESCRIPTION("Challenge core_validation with shader validation issues related to vkCreateGraphicsPipelines.");
12334
12335 ASSERT_NO_FATAL_FAILURE(InitState());
12336 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12337
12338 const char *bad_specialization_message =
12339 "Specialization entry 0 (for constant id 0) references memory outside provided specialization data ";
12340
12341 char const *vsSource =
12342 "#version 450\n"
12343 "\n"
12344 "out gl_PerVertex {\n"
12345 " vec4 gl_Position;\n"
12346 "};\n"
12347 "void main(){\n"
12348 " gl_Position = vec4(1);\n"
12349 "}\n";
12350
12351 char const *fsSource =
12352 "#version 450\n"
12353 "\n"
12354 "layout (constant_id = 0) const float r = 0.0f;\n"
12355 "layout(location = 0) out vec4 uFragColor;\n"
12356 "void main(){\n"
12357 " uFragColor = vec4(r,1,0,1);\n"
12358 "}\n";
12359
12360 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12361 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12362
12363 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
12364 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12365
12366 VkPipelineLayout pipeline_layout;
12367 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
12368
12369 VkPipelineViewportStateCreateInfo vp_state_create_info = {};
12370 vp_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
12371 vp_state_create_info.viewportCount = 1;
12372 VkViewport viewport = {};
12373 vp_state_create_info.pViewports = &viewport;
12374 vp_state_create_info.scissorCount = 1;
12375 VkRect2D scissors = {};
12376 vp_state_create_info.pScissors = &scissors;
12377
12378 VkDynamicState scissor_state = VK_DYNAMIC_STATE_SCISSOR;
12379
12380 VkPipelineDynamicStateCreateInfo pipeline_dynamic_state_create_info = {};
12381 pipeline_dynamic_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
12382 pipeline_dynamic_state_create_info.dynamicStateCount = 1;
12383 pipeline_dynamic_state_create_info.pDynamicStates = &scissor_state;
12384
12385 VkPipelineShaderStageCreateInfo shader_stage_create_info[2] = {
12386 vs.GetStageCreateInfo(),
12387 fs.GetStageCreateInfo()
12388 };
12389
12390 VkPipelineVertexInputStateCreateInfo vertex_input_create_info = {};
12391 vertex_input_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
12392
12393 VkPipelineInputAssemblyStateCreateInfo input_assembly_create_info = {};
12394 input_assembly_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
12395 input_assembly_create_info.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
12396
12397 VkPipelineRasterizationStateCreateInfo rasterization_state_create_info = {};
12398 rasterization_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
12399 rasterization_state_create_info.pNext = nullptr;
12400 rasterization_state_create_info.lineWidth = 1.0f;
12401 rasterization_state_create_info.rasterizerDiscardEnable = true;
12402
12403 VkPipelineColorBlendAttachmentState color_blend_attachment_state = {};
12404 color_blend_attachment_state.blendEnable = VK_FALSE;
12405 color_blend_attachment_state.colorWriteMask = 0xf;
12406
12407 VkPipelineColorBlendStateCreateInfo color_blend_state_create_info = {};
12408 color_blend_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
12409 color_blend_state_create_info.attachmentCount = 1;
12410 color_blend_state_create_info.pAttachments = &color_blend_attachment_state;
12411
12412 VkGraphicsPipelineCreateInfo graphicspipe_create_info = {};
12413 graphicspipe_create_info.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
12414 graphicspipe_create_info.stageCount = 2;
12415 graphicspipe_create_info.pStages = shader_stage_create_info;
12416 graphicspipe_create_info.pVertexInputState = &vertex_input_create_info;
12417 graphicspipe_create_info.pInputAssemblyState = &input_assembly_create_info;
12418 graphicspipe_create_info.pViewportState = &vp_state_create_info;
12419 graphicspipe_create_info.pRasterizationState = &rasterization_state_create_info;
12420 graphicspipe_create_info.pColorBlendState = &color_blend_state_create_info;
12421 graphicspipe_create_info.pDynamicState = &pipeline_dynamic_state_create_info;
12422 graphicspipe_create_info.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
12423 graphicspipe_create_info.layout = pipeline_layout;
12424 graphicspipe_create_info.renderPass = renderPass();
12425
12426 VkPipelineCacheCreateInfo pipeline_cache_create_info = {};
12427 pipeline_cache_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
12428
12429 VkPipelineCache pipelineCache;
12430 ASSERT_VK_SUCCESS(vkCreatePipelineCache(m_device->device(), &pipeline_cache_create_info, nullptr, &pipelineCache));
12431
12432 // This structure maps constant ids to data locations.
12433 const VkSpecializationMapEntry entry =
12434 // id, offset, size
12435 {0, 4, sizeof(uint32_t)}; // Challenge core validation by using a bogus offset.
12436
12437 uint32_t data = 1;
12438
12439 // Set up the info describing spec map and data
12440 const VkSpecializationInfo specialization_info = {
12441 1,
12442 &entry,
12443 1 * sizeof(float),
12444 &data,
12445 };
12446 shader_stage_create_info[0].pSpecializationInfo = &specialization_info;
12447
12448 VkPipeline pipeline;
12449 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bad_specialization_message);
12450 vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &graphicspipe_create_info, nullptr, &pipeline);
12451 m_errorMonitor->VerifyFound();
12452
12453 vkDestroyPipelineCache(m_device->device(), pipelineCache, nullptr);
12454 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
12455}
12456
12457TEST_F(VkLayerTest, CreatePipelineCheckShaderDescriptorTypeMismatch) {
12458 TEST_DESCRIPTION("Challenge core_validation with shader validation issues related to vkCreateGraphicsPipelines.");
12459
12460 ASSERT_NO_FATAL_FAILURE(InitState());
12461 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12462
12463 const char *descriptor_type_mismatch_message = "Type mismatch on descriptor slot 0.0 (used as type ";
12464
12465 VkDescriptorPoolSize descriptor_pool_type_count[2] = {};
12466 descriptor_pool_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
12467 descriptor_pool_type_count[0].descriptorCount = 1;
12468 descriptor_pool_type_count[1].type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
12469 descriptor_pool_type_count[1].descriptorCount = 1;
12470
12471 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
12472 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12473 descriptor_pool_create_info.maxSets = 1;
12474 descriptor_pool_create_info.poolSizeCount = 2;
12475 descriptor_pool_create_info.pPoolSizes = descriptor_pool_type_count;
12476 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
12477
12478 VkDescriptorPool descriptorset_pool;
12479 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
12480
12481 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
12482 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
12483 descriptorset_layout_binding.descriptorCount = 1;
12484 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_ALL;
12485
12486 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
12487 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
12488 descriptorset_layout_create_info.bindingCount = 1;
12489 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
12490
12491 VkDescriptorSetLayout descriptorset_layout;
12492 ASSERT_VK_SUCCESS(vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
12493
12494 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
12495 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
12496 descriptorset_allocate_info.descriptorSetCount = 1;
12497 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
12498 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
12499 VkDescriptorSet descriptorset;
12500 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
12501
12502 // Challenge core_validation with a non uniform buffer type.
12503 VkBufferTest storage_buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT);
12504
Mark Mueller098c9cb2016-09-08 09:01:57 -060012505 char const *vsSource =
12506 "#version 450\n"
12507 "\n"
12508 "layout (std140, set = 0, binding = 0) uniform buf {\n"
12509 " mat4 mvp;\n"
12510 "} ubuf;\n"
12511 "out gl_PerVertex {\n"
12512 " vec4 gl_Position;\n"
12513 "};\n"
12514 "void main(){\n"
12515 " gl_Position = ubuf.mvp * vec4(1);\n"
12516 "}\n";
12517
12518 char const *fsSource =
12519 "#version 450\n"
12520 "\n"
12521 "layout(location = 0) out vec4 uFragColor;\n"
12522 "void main(){\n"
12523 " uFragColor = vec4(0,1,0,1);\n"
12524 "}\n";
12525
12526 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12527 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12528
12529 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
12530 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12531 pipeline_layout_create_info.setLayoutCount = 1;
12532 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
12533
12534 VkPipelineLayout pipeline_layout;
12535 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
12536
12537 VkPipelineObj pipe(m_device);
12538 pipe.AddColorAttachment();
12539 pipe.AddShader(&vs);
12540 pipe.AddShader(&fs);
12541
12542 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, descriptor_type_mismatch_message);
12543 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12544 m_errorMonitor->VerifyFound();
12545
12546 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
12547 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
12548 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
12549}
12550
12551TEST_F(VkLayerTest, CreatePipelineCheckShaderDescriptorNotAccessible) {
12552 TEST_DESCRIPTION(
12553 "Create a pipeline in which a descriptor used by a shader stage does not include that stage in its stageFlags.");
12554
12555 ASSERT_NO_FATAL_FAILURE(InitState());
12556 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12557
12558 const char *descriptor_not_accessible_message = "Shader uses descriptor slot 0.0 (used as type ";
12559
12560 VkDescriptorPoolSize descriptor_pool_type_count = {};
12561 descriptor_pool_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
12562 descriptor_pool_type_count.descriptorCount = 1;
12563
12564 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
12565 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12566 descriptor_pool_create_info.maxSets = 1;
12567 descriptor_pool_create_info.poolSizeCount = 1;
12568 descriptor_pool_create_info.pPoolSizes = &descriptor_pool_type_count;
12569 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
12570
12571 VkDescriptorPool descriptorset_pool;
12572 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
12573
12574 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
12575 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
12576 descriptorset_layout_binding.descriptorCount = 1;
12577 // Intentionally make the uniform buffer inaccessible to the vertex shader to challenge core_validation
12578 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
12579
12580 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
12581 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
12582 descriptorset_layout_create_info.bindingCount = 1;
12583 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
12584
12585 VkDescriptorSetLayout descriptorset_layout;
12586 ASSERT_VK_SUCCESS(vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info,
12587 nullptr, &descriptorset_layout));
12588
12589 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
12590 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
12591 descriptorset_allocate_info.descriptorSetCount = 1;
12592 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
12593 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
12594 VkDescriptorSet descriptorset;
12595 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
12596
12597 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
12598
Mark Mueller098c9cb2016-09-08 09:01:57 -060012599 char const *vsSource =
12600 "#version 450\n"
12601 "\n"
12602 "layout (std140, set = 0, binding = 0) uniform buf {\n"
12603 " mat4 mvp;\n"
12604 "} ubuf;\n"
12605 "out gl_PerVertex {\n"
12606 " vec4 gl_Position;\n"
12607 "};\n"
12608 "void main(){\n"
12609 " gl_Position = ubuf.mvp * vec4(1);\n"
12610 "}\n";
12611
12612 char const *fsSource =
12613 "#version 450\n"
12614 "\n"
12615 "layout(location = 0) out vec4 uFragColor;\n"
12616 "void main(){\n"
12617 " uFragColor = vec4(0,1,0,1);\n"
12618 "}\n";
12619
12620 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12621 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12622
12623 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
12624 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12625 pipeline_layout_create_info.setLayoutCount = 1;
12626 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
12627
12628 VkPipelineLayout pipeline_layout;
12629 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
12630
12631 VkPipelineObj pipe(m_device);
12632 pipe.AddColorAttachment();
12633 pipe.AddShader(&vs);
12634 pipe.AddShader(&fs);
12635
12636 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, descriptor_not_accessible_message);
12637 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12638 m_errorMonitor->VerifyFound();
12639
12640 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
12641 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
12642 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
12643}
12644
12645TEST_F(VkLayerTest, CreatePipelineCheckShaderPushConstantNotAccessible) {
12646 TEST_DESCRIPTION("Create a graphics pipleine in which a push constant range containing a push constant block member is not "
12647 "accessible from the current shader stage.");
12648
12649 ASSERT_NO_FATAL_FAILURE(InitState());
12650 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12651
12652 const char *push_constant_not_accessible_message =
12653 "Push constant range covering variable starting at offset 0 not accessible from stage VK_SHADER_STAGE_VERTEX_BIT";
12654
12655 char const *vsSource =
12656 "#version 450\n"
12657 "\n"
12658 "layout(push_constant, std430) uniform foo { float x; } consts;\n"
12659 "out gl_PerVertex {\n"
12660 " vec4 gl_Position;\n"
12661 "};\n"
12662 "void main(){\n"
12663 " gl_Position = vec4(consts.x);\n"
12664 "}\n";
12665
12666 char const *fsSource =
12667 "#version 450\n"
12668 "\n"
12669 "layout(location = 0) out vec4 uFragColor;\n"
12670 "void main(){\n"
12671 " uFragColor = vec4(0,1,0,1);\n"
12672 "}\n";
12673
12674 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12675 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12676
12677 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
12678 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12679
12680 // Set up a push constant range
12681 VkPushConstantRange push_constant_ranges = {};
12682 // Set to the wrong stage to challenge core_validation
12683 push_constant_ranges.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
12684 push_constant_ranges.size = 4;
12685
12686 pipeline_layout_create_info.pPushConstantRanges = &push_constant_ranges;
12687 pipeline_layout_create_info.pushConstantRangeCount = 1;
12688
12689 VkPipelineLayout pipeline_layout;
12690 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
12691
12692 VkPipelineObj pipe(m_device);
12693 pipe.AddColorAttachment();
12694 pipe.AddShader(&vs);
12695 pipe.AddShader(&fs);
12696
12697 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, push_constant_not_accessible_message);
12698 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12699 m_errorMonitor->VerifyFound();
12700
12701 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
12702}
12703
12704TEST_F(VkLayerTest, CreatePipelineCheckShaderNotEnabled) {
12705 TEST_DESCRIPTION(
12706 "Create a graphics pipeline in which a capability declared by the shader requires a feature not enabled on the device.");
12707
12708 ASSERT_NO_FATAL_FAILURE(InitState());
12709 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12710
12711 const char *feature_not_enabled_message =
12712 "Shader requires VkPhysicalDeviceFeatures::shaderFloat64 but is not enabled on the device";
12713
12714 // Some awkward steps are required to test with custom device features.
12715 std::vector<const char *> device_extension_names;
12716 auto features = m_device->phy().features();
12717 // Disable support for 64 bit floats
12718 features.shaderFloat64 = false;
12719 // The sacrificial device object
12720 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
12721
12722 char const *vsSource = "#version 450\n"
12723 "\n"
12724 "out gl_PerVertex {\n"
12725 " vec4 gl_Position;\n"
12726 "};\n"
12727 "void main(){\n"
12728 " gl_Position = vec4(1);\n"
12729 "}\n";
12730 char const *fsSource = "#version 450\n"
12731 "\n"
12732 "layout(location=0) out vec4 color;\n"
12733 "void main(){\n"
12734 " dvec4 green = vec4(0.0, 1.0, 0.0, 1.0);\n"
12735 " color = vec4(green);\n"
12736 "}\n";
12737
12738 VkShaderObj vs(&test_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12739 VkShaderObj fs(&test_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12740
12741 VkRenderpassObj render_pass(&test_device);
Mark Mueller098c9cb2016-09-08 09:01:57 -060012742
12743 VkPipelineObj pipe(&test_device);
12744 pipe.AddColorAttachment();
12745 pipe.AddShader(&vs);
12746 pipe.AddShader(&fs);
12747
12748 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
12749 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12750 VkPipelineLayout pipeline_layout;
12751 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(test_device.device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
12752
12753 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, feature_not_enabled_message);
12754 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
12755 m_errorMonitor->VerifyFound();
12756
12757 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, nullptr);
12758}
12759
12760TEST_F(VkLayerTest, CreatePipelineCheckShaderBadCapability) {
12761 TEST_DESCRIPTION("Create a graphics pipeline in which a capability declared by the shader is not supported by Vulkan shaders.");
12762
12763 ASSERT_NO_FATAL_FAILURE(InitState());
12764 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12765
12766 const char *bad_capability_message = "Shader declares capability 53, not supported in Vulkan.";
12767
12768 char const *vsSource = "#version 450\n"
12769 "\n"
12770 "out gl_PerVertex {\n"
12771 " vec4 gl_Position;\n"
12772 "};\n"
12773 "layout(xfb_buffer = 1) out;"
12774 "void main(){\n"
12775 " gl_Position = vec4(1);\n"
12776 "}\n";
12777 char const *fsSource = "#version 450\n"
12778 "\n"
12779 "layout(location=0) out vec4 color;\n"
12780 "void main(){\n"
12781 " dvec4 green = vec4(0.0, 1.0, 0.0, 1.0);\n"
12782 " color = vec4(green);\n"
12783 "}\n";
12784
12785 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12786 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12787
12788 VkPipelineObj pipe(m_device);
12789 pipe.AddColorAttachment();
12790 pipe.AddShader(&vs);
12791 pipe.AddShader(&fs);
12792
12793 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
12794 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12795 VkPipelineLayout pipeline_layout;
12796 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
12797
12798 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bad_capability_message);
12799 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12800 m_errorMonitor->VerifyFound();
12801
12802 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
12803}
12804
Karl Schultz6addd812016-02-02 17:17:23 -070012805TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvided) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012806 TEST_DESCRIPTION("Test that an error is produced for a fragment shader input "
12807 "which is not present in the outputs of the previous stage");
12808
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012809 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not written by vertex shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012810
Chris Forbes59cb88d2015-05-25 11:13:13 +120012811 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060012812 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes59cb88d2015-05-25 11:13:13 +120012813
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 "layout(location=0) in float x;\n"
12825 "layout(location=0) out vec4 color;\n"
12826 "void main(){\n"
12827 " color = vec4(x);\n"
12828 "}\n";
Chris Forbes59cb88d2015-05-25 11:13:13 +120012829
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012830 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12831 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes59cb88d2015-05-25 11:13:13 +120012832
12833 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080012834 pipe.AddColorAttachment();
Chris Forbes59cb88d2015-05-25 11:13:13 +120012835 pipe.AddShader(&vs);
12836 pipe.AddShader(&fs);
12837
Chris Forbes59cb88d2015-05-25 11:13:13 +120012838 VkDescriptorSetObj descriptorSet(m_device);
12839 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012840 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes59cb88d2015-05-25 11:13:13 +120012841
Tony Barbour5781e8f2015-08-04 16:23:11 -060012842 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes59cb88d2015-05-25 11:13:13 +120012843
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012844 m_errorMonitor->VerifyFound();
Chris Forbes59cb88d2015-05-25 11:13:13 +120012845}
12846
Karl Schultz6addd812016-02-02 17:17:23 -070012847TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvidedInBlock) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012848 TEST_DESCRIPTION("Test that an error is produced for a fragment shader input "
12849 "within an interace block, which is not present in the outputs "
12850 "of the previous stage.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012851 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not written by vertex shader");
Chris Forbesa3e85f62016-01-15 14:53:11 +130012852
12853 ASSERT_NO_FATAL_FAILURE(InitState());
12854 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12855
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012856 char const *vsSource = "#version 450\n"
12857 "\n"
12858 "out gl_PerVertex {\n"
12859 " vec4 gl_Position;\n"
12860 "};\n"
12861 "void main(){\n"
12862 " gl_Position = vec4(1);\n"
12863 "}\n";
12864 char const *fsSource = "#version 450\n"
12865 "\n"
12866 "in block { layout(location=0) float x; } ins;\n"
12867 "layout(location=0) out vec4 color;\n"
12868 "void main(){\n"
12869 " color = vec4(ins.x);\n"
12870 "}\n";
Chris Forbesa3e85f62016-01-15 14:53:11 +130012871
12872 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12873 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12874
12875 VkPipelineObj pipe(m_device);
12876 pipe.AddColorAttachment();
12877 pipe.AddShader(&vs);
12878 pipe.AddShader(&fs);
12879
12880 VkDescriptorSetObj descriptorSet(m_device);
12881 descriptorSet.AppendDummy();
12882 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12883
12884 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12885
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012886 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +130012887}
12888
Karl Schultz6addd812016-02-02 17:17:23 -070012889TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchArraySize) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012890 TEST_DESCRIPTION("Test that an error is produced for mismatched array sizes "
Mike Weiblencce7ec72016-10-17 19:33:05 -060012891 "across the vertex->fragment shader interface");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012892 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0.0: 'ptr to "
12893 "output arr[2] of float32' vs 'ptr to "
12894 "input arr[3] of float32'");
Chris Forbes0036fd12016-01-26 14:19:49 +130012895
12896 ASSERT_NO_FATAL_FAILURE(InitState());
12897 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12898
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012899 char const *vsSource = "#version 450\n"
12900 "\n"
12901 "layout(location=0) out float x[2];\n"
12902 "out gl_PerVertex {\n"
12903 " vec4 gl_Position;\n"
12904 "};\n"
12905 "void main(){\n"
12906 " x[0] = 0; x[1] = 0;\n"
12907 " gl_Position = vec4(1);\n"
12908 "}\n";
12909 char const *fsSource = "#version 450\n"
12910 "\n"
12911 "layout(location=0) in float x[3];\n"
12912 "layout(location=0) out vec4 color;\n"
12913 "void main(){\n"
12914 " color = vec4(x[0] + x[1] + x[2]);\n"
12915 "}\n";
Chris Forbes0036fd12016-01-26 14:19:49 +130012916
12917 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12918 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12919
12920 VkPipelineObj pipe(m_device);
12921 pipe.AddColorAttachment();
12922 pipe.AddShader(&vs);
12923 pipe.AddShader(&fs);
12924
12925 VkDescriptorSetObj descriptorSet(m_device);
12926 descriptorSet.AppendDummy();
12927 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12928
12929 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12930
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012931 m_errorMonitor->VerifyFound();
Chris Forbes0036fd12016-01-26 14:19:49 +130012932}
12933
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060012934
Karl Schultz6addd812016-02-02 17:17:23 -070012935TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012936 TEST_DESCRIPTION("Test that an error is produced for mismatched types across "
Mike Weiblencce7ec72016-10-17 19:33:05 -060012937 "the vertex->fragment shader interface");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012938 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012939
Chris Forbesb56af562015-05-25 11:13:17 +120012940 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060012941 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesb56af562015-05-25 11:13:17 +120012942
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012943 char const *vsSource = "#version 450\n"
12944 "\n"
12945 "layout(location=0) out int x;\n"
12946 "out gl_PerVertex {\n"
12947 " vec4 gl_Position;\n"
12948 "};\n"
12949 "void main(){\n"
12950 " x = 0;\n"
12951 " gl_Position = vec4(1);\n"
12952 "}\n";
12953 char const *fsSource = "#version 450\n"
12954 "\n"
12955 "layout(location=0) in float x;\n" /* VS writes int */
12956 "layout(location=0) out vec4 color;\n"
12957 "void main(){\n"
12958 " color = vec4(x);\n"
12959 "}\n";
Chris Forbesb56af562015-05-25 11:13:17 +120012960
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012961 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12962 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesb56af562015-05-25 11:13:17 +120012963
12964 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080012965 pipe.AddColorAttachment();
Chris Forbesb56af562015-05-25 11:13:17 +120012966 pipe.AddShader(&vs);
12967 pipe.AddShader(&fs);
12968
Chris Forbesb56af562015-05-25 11:13:17 +120012969 VkDescriptorSetObj descriptorSet(m_device);
12970 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012971 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesb56af562015-05-25 11:13:17 +120012972
Tony Barbour5781e8f2015-08-04 16:23:11 -060012973 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesb56af562015-05-25 11:13:17 +120012974
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012975 m_errorMonitor->VerifyFound();
Chris Forbesb56af562015-05-25 11:13:17 +120012976}
12977
Karl Schultz6addd812016-02-02 17:17:23 -070012978TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchInBlock) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012979 TEST_DESCRIPTION("Test that an error is produced for mismatched types across "
Mike Weiblencce7ec72016-10-17 19:33:05 -060012980 "the vertex->fragment shader interface, when the variable is contained within "
Chris Forbes1cc79542016-07-20 11:13:44 +120012981 "an interface block");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012982 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0");
Chris Forbesa3e85f62016-01-15 14:53:11 +130012983
12984 ASSERT_NO_FATAL_FAILURE(InitState());
12985 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12986
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012987 char const *vsSource = "#version 450\n"
12988 "\n"
12989 "out block { layout(location=0) int x; } outs;\n"
12990 "out gl_PerVertex {\n"
12991 " vec4 gl_Position;\n"
12992 "};\n"
12993 "void main(){\n"
12994 " outs.x = 0;\n"
12995 " gl_Position = vec4(1);\n"
12996 "}\n";
12997 char const *fsSource = "#version 450\n"
12998 "\n"
12999 "in block { layout(location=0) float x; } ins;\n" /* VS writes int */
13000 "layout(location=0) out vec4 color;\n"
13001 "void main(){\n"
13002 " color = vec4(ins.x);\n"
13003 "}\n";
Chris Forbesa3e85f62016-01-15 14:53:11 +130013004
13005 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13006 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13007
13008 VkPipelineObj pipe(m_device);
13009 pipe.AddColorAttachment();
13010 pipe.AddShader(&vs);
13011 pipe.AddShader(&fs);
13012
13013 VkDescriptorSetObj descriptorSet(m_device);
13014 descriptorSet.AppendDummy();
13015 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13016
13017 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13018
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013019 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +130013020}
13021
13022TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByLocation) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013023 TEST_DESCRIPTION("Test that an error is produced for location mismatches across "
Mike Weiblencce7ec72016-10-17 19:33:05 -060013024 "the vertex->fragment shader interface; This should manifest as a not-written/not-consumed "
Chris Forbes1cc79542016-07-20 11:13:44 +120013025 "pair, but flushes out broken walking of the interfaces");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013026 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 +130013027
13028 ASSERT_NO_FATAL_FAILURE(InitState());
13029 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13030
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013031 char const *vsSource = "#version 450\n"
13032 "\n"
13033 "out block { layout(location=1) float x; } outs;\n"
13034 "out gl_PerVertex {\n"
13035 " vec4 gl_Position;\n"
13036 "};\n"
13037 "void main(){\n"
13038 " outs.x = 0;\n"
13039 " gl_Position = vec4(1);\n"
13040 "}\n";
13041 char const *fsSource = "#version 450\n"
13042 "\n"
13043 "in block { layout(location=0) float x; } ins;\n"
13044 "layout(location=0) out vec4 color;\n"
13045 "void main(){\n"
13046 " color = vec4(ins.x);\n"
13047 "}\n";
Chris Forbese9928822016-02-17 14:44:52 +130013048
13049 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13050 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13051
13052 VkPipelineObj pipe(m_device);
13053 pipe.AddColorAttachment();
13054 pipe.AddShader(&vs);
13055 pipe.AddShader(&fs);
13056
13057 VkDescriptorSetObj descriptorSet(m_device);
13058 descriptorSet.AppendDummy();
13059 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13060
13061 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13062
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013063 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +130013064}
13065
13066TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByComponent) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013067 TEST_DESCRIPTION("Test that an error is produced for component mismatches across the "
Mike Weiblencce7ec72016-10-17 19:33:05 -060013068 "vertex->fragment shader interface. It's not enough to have the same set of locations in "
Chris Forbes1cc79542016-07-20 11:13:44 +120013069 "use; matching is defined in terms of spirv variables.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013070 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 +130013071
13072 ASSERT_NO_FATAL_FAILURE(InitState());
13073 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13074
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013075 char const *vsSource = "#version 450\n"
13076 "\n"
13077 "out block { layout(location=0, component=0) float x; } outs;\n"
13078 "out gl_PerVertex {\n"
13079 " vec4 gl_Position;\n"
13080 "};\n"
13081 "void main(){\n"
13082 " outs.x = 0;\n"
13083 " gl_Position = vec4(1);\n"
13084 "}\n";
13085 char const *fsSource = "#version 450\n"
13086 "\n"
13087 "in block { layout(location=0, component=1) float x; } ins;\n"
13088 "layout(location=0) out vec4 color;\n"
13089 "void main(){\n"
13090 " color = vec4(ins.x);\n"
13091 "}\n";
Chris Forbese9928822016-02-17 14:44:52 +130013092
13093 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13094 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13095
13096 VkPipelineObj pipe(m_device);
13097 pipe.AddColorAttachment();
13098 pipe.AddShader(&vs);
13099 pipe.AddShader(&fs);
13100
13101 VkDescriptorSetObj descriptorSet(m_device);
13102 descriptorSet.AppendDummy();
13103 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13104
13105 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13106
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013107 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +130013108}
13109
Chris Forbes1f3b0152016-11-30 12:48:40 +130013110TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByPrecision) {
13111 TEST_DESCRIPTION("Test that the RelaxedPrecision decoration is validated to match");
13112
13113 ASSERT_NO_FATAL_FAILURE(InitState());
13114 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13115
13116 char const *vsSource = "#version 450\n"
13117 "layout(location=0) out mediump float x;\n"
13118 "void main() { gl_Position = vec4(0); x = 1.0; }\n";
13119 char const *fsSource = "#version 450\n"
13120 "layout(location=0) in highp float x;\n"
13121 "layout(location=0) out vec4 color;\n"
13122 "void main() { color = vec4(x); }\n";
13123
13124 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13125 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13126
13127 VkPipelineObj pipe(m_device);
13128 pipe.AddColorAttachment();
13129 pipe.AddShader(&vs);
13130 pipe.AddShader(&fs);
13131
13132 VkDescriptorSetObj descriptorSet(m_device);
13133 descriptorSet.AppendDummy();
13134 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13135
13136 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "differ in precision");
13137
13138 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13139
13140 m_errorMonitor->VerifyFound();
13141}
13142
Chris Forbes870a39e2016-11-30 12:55:56 +130013143TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByPrecisionBlock) {
13144 TEST_DESCRIPTION("Test that the RelaxedPrecision decoration is validated to match");
13145
13146 ASSERT_NO_FATAL_FAILURE(InitState());
13147 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13148
13149 char const *vsSource = "#version 450\n"
13150 "out block { layout(location=0) mediump float x; };\n"
13151 "void main() { gl_Position = vec4(0); x = 1.0; }\n";
13152 char const *fsSource = "#version 450\n"
13153 "in block { layout(location=0) highp float x; };\n"
13154 "layout(location=0) out vec4 color;\n"
13155 "void main() { color = vec4(x); }\n";
13156
13157 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13158 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13159
13160 VkPipelineObj pipe(m_device);
13161 pipe.AddColorAttachment();
13162 pipe.AddShader(&vs);
13163 pipe.AddShader(&fs);
13164
13165 VkDescriptorSetObj descriptorSet(m_device);
13166 descriptorSet.AppendDummy();
13167 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13168
13169 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "differ in precision");
13170
13171 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13172
13173 m_errorMonitor->VerifyFound();
13174}
13175
Karl Schultz6addd812016-02-02 17:17:23 -070013176TEST_F(VkLayerTest, CreatePipelineAttribNotConsumed) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013177 TEST_DESCRIPTION("Test that a warning is produced for a vertex attribute which is "
13178 "not consumed by the vertex shader");
Mike Weiblencce7ec72016-10-17 19:33:05 -060013179 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "location 0 not consumed by vertex shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013180
Chris Forbesde136e02015-05-25 11:13:28 +120013181 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013182 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesde136e02015-05-25 11:13:28 +120013183
13184 VkVertexInputBindingDescription input_binding;
13185 memset(&input_binding, 0, sizeof(input_binding));
13186
13187 VkVertexInputAttributeDescription input_attrib;
13188 memset(&input_attrib, 0, sizeof(input_attrib));
13189 input_attrib.format = VK_FORMAT_R32_SFLOAT;
13190
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013191 char const *vsSource = "#version 450\n"
13192 "\n"
13193 "out gl_PerVertex {\n"
13194 " vec4 gl_Position;\n"
13195 "};\n"
13196 "void main(){\n"
13197 " gl_Position = vec4(1);\n"
13198 "}\n";
13199 char const *fsSource = "#version 450\n"
13200 "\n"
13201 "layout(location=0) out vec4 color;\n"
13202 "void main(){\n"
13203 " color = vec4(1);\n"
13204 "}\n";
Chris Forbesde136e02015-05-25 11:13:28 +120013205
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013206 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13207 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesde136e02015-05-25 11:13:28 +120013208
13209 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013210 pipe.AddColorAttachment();
Chris Forbesde136e02015-05-25 11:13:28 +120013211 pipe.AddShader(&vs);
13212 pipe.AddShader(&fs);
13213
13214 pipe.AddVertexInputBindings(&input_binding, 1);
13215 pipe.AddVertexInputAttribs(&input_attrib, 1);
13216
Chris Forbesde136e02015-05-25 11:13:28 +120013217 VkDescriptorSetObj descriptorSet(m_device);
13218 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013219 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesde136e02015-05-25 11:13:28 +120013220
Tony Barbour5781e8f2015-08-04 16:23:11 -060013221 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesde136e02015-05-25 11:13:28 +120013222
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013223 m_errorMonitor->VerifyFound();
Chris Forbesde136e02015-05-25 11:13:28 +120013224}
13225
Karl Schultz6addd812016-02-02 17:17:23 -070013226TEST_F(VkLayerTest, CreatePipelineAttribLocationMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013227 TEST_DESCRIPTION("Test that a warning is produced for a location mismatch on "
13228 "vertex attributes. This flushes out bad behavior in the interface walker");
Mike Weiblencce7ec72016-10-17 19:33:05 -060013229 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "location 0 not consumed by vertex shader");
Chris Forbes7d83cd52016-01-15 11:32:03 +130013230
13231 ASSERT_NO_FATAL_FAILURE(InitState());
13232 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13233
13234 VkVertexInputBindingDescription input_binding;
13235 memset(&input_binding, 0, sizeof(input_binding));
13236
13237 VkVertexInputAttributeDescription input_attrib;
13238 memset(&input_attrib, 0, sizeof(input_attrib));
13239 input_attrib.format = VK_FORMAT_R32_SFLOAT;
13240
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013241 char const *vsSource = "#version 450\n"
13242 "\n"
13243 "layout(location=1) in float x;\n"
13244 "out gl_PerVertex {\n"
13245 " vec4 gl_Position;\n"
13246 "};\n"
13247 "void main(){\n"
13248 " gl_Position = vec4(x);\n"
13249 "}\n";
13250 char const *fsSource = "#version 450\n"
13251 "\n"
13252 "layout(location=0) out vec4 color;\n"
13253 "void main(){\n"
13254 " color = vec4(1);\n"
13255 "}\n";
Chris Forbes7d83cd52016-01-15 11:32:03 +130013256
13257 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13258 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13259
13260 VkPipelineObj pipe(m_device);
13261 pipe.AddColorAttachment();
13262 pipe.AddShader(&vs);
13263 pipe.AddShader(&fs);
13264
13265 pipe.AddVertexInputBindings(&input_binding, 1);
13266 pipe.AddVertexInputAttribs(&input_attrib, 1);
13267
13268 VkDescriptorSetObj descriptorSet(m_device);
13269 descriptorSet.AppendDummy();
13270 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13271
13272 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13273
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013274 m_errorMonitor->VerifyFound();
Chris Forbes7d83cd52016-01-15 11:32:03 +130013275}
13276
Karl Schultz6addd812016-02-02 17:17:23 -070013277TEST_F(VkLayerTest, CreatePipelineAttribNotProvided) {
Mike Weiblen15bd38e2016-10-03 19:19:41 -060013278 TEST_DESCRIPTION("Test that an error is produced for a vertex shader input which is not "
Chris Forbes1cc79542016-07-20 11:13:44 +120013279 "provided by a vertex attribute");
Mike Weiblen15bd38e2016-10-03 19:19:41 -060013280 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 -060013281
Chris Forbes62e8e502015-05-25 11:13:29 +120013282 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013283 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes62e8e502015-05-25 11:13:29 +120013284
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013285 char const *vsSource = "#version 450\n"
13286 "\n"
13287 "layout(location=0) in vec4 x;\n" /* not provided */
13288 "out gl_PerVertex {\n"
13289 " vec4 gl_Position;\n"
13290 "};\n"
13291 "void main(){\n"
13292 " gl_Position = x;\n"
13293 "}\n";
13294 char const *fsSource = "#version 450\n"
13295 "\n"
13296 "layout(location=0) out vec4 color;\n"
13297 "void main(){\n"
13298 " color = vec4(1);\n"
13299 "}\n";
Chris Forbes62e8e502015-05-25 11:13:29 +120013300
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013301 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13302 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes62e8e502015-05-25 11:13:29 +120013303
13304 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013305 pipe.AddColorAttachment();
Chris Forbes62e8e502015-05-25 11:13:29 +120013306 pipe.AddShader(&vs);
13307 pipe.AddShader(&fs);
13308
Chris Forbes62e8e502015-05-25 11:13:29 +120013309 VkDescriptorSetObj descriptorSet(m_device);
13310 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013311 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes62e8e502015-05-25 11:13:29 +120013312
Tony Barbour5781e8f2015-08-04 16:23:11 -060013313 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes62e8e502015-05-25 11:13:29 +120013314
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013315 m_errorMonitor->VerifyFound();
Chris Forbes62e8e502015-05-25 11:13:29 +120013316}
13317
Karl Schultz6addd812016-02-02 17:17:23 -070013318TEST_F(VkLayerTest, CreatePipelineAttribTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013319 TEST_DESCRIPTION("Test that an error is produced for a mismatch between the "
13320 "fundamental type (float/int/uint) of an attribute and the "
Mike Weiblen15bd38e2016-10-03 19:19:41 -060013321 "vertex shader input that consumes it");
13322 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 -060013323
Chris Forbesc97d98e2015-05-25 11:13:31 +120013324 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013325 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesc97d98e2015-05-25 11:13:31 +120013326
13327 VkVertexInputBindingDescription input_binding;
13328 memset(&input_binding, 0, sizeof(input_binding));
13329
13330 VkVertexInputAttributeDescription input_attrib;
13331 memset(&input_attrib, 0, sizeof(input_attrib));
13332 input_attrib.format = VK_FORMAT_R32_SFLOAT;
13333
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013334 char const *vsSource = "#version 450\n"
13335 "\n"
13336 "layout(location=0) in int x;\n" /* attrib provided float */
13337 "out gl_PerVertex {\n"
13338 " vec4 gl_Position;\n"
13339 "};\n"
13340 "void main(){\n"
13341 " gl_Position = vec4(x);\n"
13342 "}\n";
13343 char const *fsSource = "#version 450\n"
13344 "\n"
13345 "layout(location=0) out vec4 color;\n"
13346 "void main(){\n"
13347 " color = vec4(1);\n"
13348 "}\n";
Chris Forbesc97d98e2015-05-25 11:13:31 +120013349
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013350 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13351 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesc97d98e2015-05-25 11:13:31 +120013352
13353 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013354 pipe.AddColorAttachment();
Chris Forbesc97d98e2015-05-25 11:13:31 +120013355 pipe.AddShader(&vs);
13356 pipe.AddShader(&fs);
13357
13358 pipe.AddVertexInputBindings(&input_binding, 1);
13359 pipe.AddVertexInputAttribs(&input_attrib, 1);
13360
Chris Forbesc97d98e2015-05-25 11:13:31 +120013361 VkDescriptorSetObj descriptorSet(m_device);
13362 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013363 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesc97d98e2015-05-25 11:13:31 +120013364
Tony Barbour5781e8f2015-08-04 16:23:11 -060013365 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesc97d98e2015-05-25 11:13:31 +120013366
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013367 m_errorMonitor->VerifyFound();
Chris Forbesc97d98e2015-05-25 11:13:31 +120013368}
13369
Chris Forbesc68b43c2016-04-06 11:18:47 +120013370TEST_F(VkLayerTest, CreatePipelineDuplicateStage) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013371 TEST_DESCRIPTION("Test that an error is produced for a pipeline containing multiple "
13372 "shaders for the same stage");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013373 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13374 "Multiple shaders provided for stage VK_SHADER_STAGE_VERTEX_BIT");
Chris Forbesc68b43c2016-04-06 11:18:47 +120013375
13376 ASSERT_NO_FATAL_FAILURE(InitState());
13377 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13378
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013379 char const *vsSource = "#version 450\n"
13380 "\n"
13381 "out gl_PerVertex {\n"
13382 " vec4 gl_Position;\n"
13383 "};\n"
13384 "void main(){\n"
13385 " gl_Position = vec4(1);\n"
13386 "}\n";
13387 char const *fsSource = "#version 450\n"
13388 "\n"
13389 "layout(location=0) out vec4 color;\n"
13390 "void main(){\n"
13391 " color = vec4(1);\n"
13392 "}\n";
Chris Forbesc68b43c2016-04-06 11:18:47 +120013393
13394 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13395 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13396
13397 VkPipelineObj pipe(m_device);
13398 pipe.AddColorAttachment();
13399 pipe.AddShader(&vs);
Mike Weiblencce7ec72016-10-17 19:33:05 -060013400 pipe.AddShader(&vs); // intentionally duplicate vertex shader attachment
Chris Forbesc68b43c2016-04-06 11:18:47 +120013401 pipe.AddShader(&fs);
13402
13403 VkDescriptorSetObj descriptorSet(m_device);
13404 descriptorSet.AppendDummy();
13405 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13406
13407 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13408
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013409 m_errorMonitor->VerifyFound();
Chris Forbesc68b43c2016-04-06 11:18:47 +120013410}
13411
Chris Forbes82ff92a2016-09-09 10:50:24 +120013412TEST_F(VkLayerTest, CreatePipelineMissingEntrypoint) {
13413 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13414 "No entrypoint found named `foo`");
13415
13416 ASSERT_NO_FATAL_FAILURE(InitState());
13417 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13418
13419 char const *vsSource = "#version 450\n"
13420 "out gl_PerVertex {\n"
13421 " vec4 gl_Position;\n"
13422 "};\n"
13423 "void main(){\n"
13424 " gl_Position = vec4(0);\n"
13425 "}\n";
13426 char const *fsSource = "#version 450\n"
13427 "\n"
13428 "layout(location=0) out vec4 color;\n"
13429 "void main(){\n"
13430 " color = vec4(1);\n"
13431 "}\n";
13432
13433 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13434 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this, "foo");
13435
13436 VkPipelineObj pipe(m_device);
13437 pipe.AddColorAttachment();
13438 pipe.AddShader(&vs);
13439 pipe.AddShader(&fs);
13440
13441 VkDescriptorSetObj descriptorSet(m_device);
13442 descriptorSet.AppendDummy();
13443 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13444
13445 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13446
13447 m_errorMonitor->VerifyFound();
13448}
13449
Chris Forbesae9d8cd2016-09-13 16:32:57 +120013450TEST_F(VkLayerTest, CreatePipelineDepthStencilRequired) {
13451 m_errorMonitor->SetDesiredFailureMsg(
13452 VK_DEBUG_REPORT_ERROR_BIT_EXT,
13453 "pDepthStencilState is NULL when rasterization is enabled and subpass "
13454 "uses a depth/stencil attachment");
13455
13456 ASSERT_NO_FATAL_FAILURE(InitState());
13457 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13458
13459 char const *vsSource = "#version 450\n"
13460 "void main(){ gl_Position = vec4(0); }\n";
13461 char const *fsSource = "#version 450\n"
13462 "\n"
13463 "layout(location=0) out vec4 color;\n"
13464 "void main(){\n"
13465 " color = vec4(1);\n"
13466 "}\n";
13467
13468 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13469 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13470
13471 VkPipelineObj pipe(m_device);
13472 pipe.AddColorAttachment();
13473 pipe.AddShader(&vs);
13474 pipe.AddShader(&fs);
13475
13476 VkDescriptorSetObj descriptorSet(m_device);
13477 descriptorSet.AppendDummy();
13478 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13479
13480 VkAttachmentDescription attachments[] = {
13481 { 0, VK_FORMAT_B8G8R8A8_UNORM, VK_SAMPLE_COUNT_1_BIT,
13482 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
13483 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
13484 VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
13485 },
13486 { 0, VK_FORMAT_D16_UNORM, VK_SAMPLE_COUNT_1_BIT,
13487 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
13488 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
13489 VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
13490 },
13491 };
13492 VkAttachmentReference refs[] = {
13493 { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL },
13494 { 1, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL },
13495 };
13496 VkSubpassDescription subpass = {
13497 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr,
13498 1, &refs[0], nullptr, &refs[1],
13499 0, nullptr
13500 };
13501 VkRenderPassCreateInfo rpci = {
13502 VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr,
13503 0, 2, attachments, 1, &subpass, 0, nullptr
13504 };
13505 VkRenderPass rp;
13506 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
13507 ASSERT_VK_SUCCESS(err);
13508
13509 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), rp);
13510
13511 m_errorMonitor->VerifyFound();
13512
13513 vkDestroyRenderPass(m_device->device(), rp, nullptr);
13514}
13515
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013516TEST_F(VkLayerTest, CreatePipelineTessPatchDecorationMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013517 TEST_DESCRIPTION("Test that an error is produced for a variable output from "
13518 "the TCS without the patch decoration, but consumed in the TES "
13519 "with the decoration.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013520 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is per-vertex in tessellation control shader stage "
13521 "but per-patch in tessellation evaluation shader stage");
Chris Forbesa0193bc2016-04-04 19:19:47 +120013522
13523 ASSERT_NO_FATAL_FAILURE(InitState());
13524 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13525
Chris Forbesc1e852d2016-04-04 19:26:42 +120013526 if (!m_device->phy().features().tessellationShader) {
13527 printf("Device does not support tessellation shaders; skipped.\n");
13528 return;
13529 }
13530
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013531 char const *vsSource = "#version 450\n"
13532 "void main(){}\n";
13533 char const *tcsSource = "#version 450\n"
13534 "layout(location=0) out int x[];\n"
13535 "layout(vertices=3) out;\n"
13536 "void main(){\n"
13537 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
13538 " gl_TessLevelInner[0] = 1;\n"
13539 " x[gl_InvocationID] = gl_InvocationID;\n"
13540 "}\n";
13541 char const *tesSource = "#version 450\n"
13542 "layout(triangles, equal_spacing, cw) in;\n"
13543 "layout(location=0) patch in int x;\n"
13544 "out gl_PerVertex { vec4 gl_Position; };\n"
13545 "void main(){\n"
13546 " gl_Position.xyz = gl_TessCoord;\n"
13547 " gl_Position.w = x;\n"
13548 "}\n";
13549 char const *fsSource = "#version 450\n"
13550 "layout(location=0) out vec4 color;\n"
13551 "void main(){\n"
13552 " color = vec4(1);\n"
13553 "}\n";
Chris Forbesa0193bc2016-04-04 19:19:47 +120013554
13555 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13556 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
13557 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
13558 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13559
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013560 VkPipelineInputAssemblyStateCreateInfo iasci{VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, nullptr, 0,
13561 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, VK_FALSE};
Chris Forbesa0193bc2016-04-04 19:19:47 +120013562
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013563 VkPipelineTessellationStateCreateInfo tsci{VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, nullptr, 0, 3};
Chris Forbesa0193bc2016-04-04 19:19:47 +120013564
13565 VkPipelineObj pipe(m_device);
13566 pipe.SetInputAssembly(&iasci);
13567 pipe.SetTessellation(&tsci);
13568 pipe.AddColorAttachment();
13569 pipe.AddShader(&vs);
13570 pipe.AddShader(&tcs);
13571 pipe.AddShader(&tes);
13572 pipe.AddShader(&fs);
13573
13574 VkDescriptorSetObj descriptorSet(m_device);
13575 descriptorSet.AppendDummy();
13576 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13577
13578 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13579
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013580 m_errorMonitor->VerifyFound();
Chris Forbesa0193bc2016-04-04 19:19:47 +120013581}
13582
Karl Schultz6addd812016-02-02 17:17:23 -070013583TEST_F(VkLayerTest, CreatePipelineAttribBindingConflict) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013584 TEST_DESCRIPTION("Test that an error is produced for a vertex attribute setup where multiple "
13585 "bindings provide the same location");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013586 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13587 "Duplicate vertex input binding descriptions for binding 0");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013588
Chris Forbes280ba2c2015-06-12 11:16:41 +120013589 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013590 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes280ba2c2015-06-12 11:16:41 +120013591
13592 /* Two binding descriptions for binding 0 */
13593 VkVertexInputBindingDescription input_bindings[2];
13594 memset(input_bindings, 0, sizeof(input_bindings));
13595
13596 VkVertexInputAttributeDescription input_attrib;
13597 memset(&input_attrib, 0, sizeof(input_attrib));
13598 input_attrib.format = VK_FORMAT_R32_SFLOAT;
13599
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013600 char const *vsSource = "#version 450\n"
13601 "\n"
13602 "layout(location=0) in float x;\n" /* attrib provided float */
13603 "out gl_PerVertex {\n"
13604 " vec4 gl_Position;\n"
13605 "};\n"
13606 "void main(){\n"
13607 " gl_Position = vec4(x);\n"
13608 "}\n";
13609 char const *fsSource = "#version 450\n"
13610 "\n"
13611 "layout(location=0) out vec4 color;\n"
13612 "void main(){\n"
13613 " color = vec4(1);\n"
13614 "}\n";
Chris Forbes280ba2c2015-06-12 11:16:41 +120013615
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013616 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13617 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes280ba2c2015-06-12 11:16:41 +120013618
13619 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013620 pipe.AddColorAttachment();
Chris Forbes280ba2c2015-06-12 11:16:41 +120013621 pipe.AddShader(&vs);
13622 pipe.AddShader(&fs);
13623
13624 pipe.AddVertexInputBindings(input_bindings, 2);
13625 pipe.AddVertexInputAttribs(&input_attrib, 1);
13626
Chris Forbes280ba2c2015-06-12 11:16:41 +120013627 VkDescriptorSetObj descriptorSet(m_device);
13628 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013629 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes280ba2c2015-06-12 11:16:41 +120013630
Tony Barbour5781e8f2015-08-04 16:23:11 -060013631 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes280ba2c2015-06-12 11:16:41 +120013632
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013633 m_errorMonitor->VerifyFound();
Chris Forbes280ba2c2015-06-12 11:16:41 +120013634}
Chris Forbes8f68b562015-05-25 11:13:32 +120013635
Karl Schultz6addd812016-02-02 17:17:23 -070013636TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotWritten) {
Mike Weiblencce7ec72016-10-17 19:33:05 -060013637 TEST_DESCRIPTION("Test that an error is produced for a fragment shader which does not "
Chris Forbes1cc79542016-07-20 11:13:44 +120013638 "provide an output for one of the pipeline's color attachments");
Mike Weiblencce7ec72016-10-17 19:33:05 -060013639 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attachment 0 not written by fragment shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013640
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013641 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013642
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013643 char const *vsSource = "#version 450\n"
13644 "\n"
13645 "out gl_PerVertex {\n"
13646 " vec4 gl_Position;\n"
13647 "};\n"
13648 "void main(){\n"
13649 " gl_Position = vec4(1);\n"
13650 "}\n";
13651 char const *fsSource = "#version 450\n"
13652 "\n"
13653 "void main(){\n"
13654 "}\n";
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013655
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013656 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13657 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013658
13659 VkPipelineObj pipe(m_device);
13660 pipe.AddShader(&vs);
13661 pipe.AddShader(&fs);
13662
Chia-I Wu08accc62015-07-07 11:50:03 +080013663 /* set up CB 0, not written */
13664 pipe.AddColorAttachment();
13665 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013666
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013667 VkDescriptorSetObj descriptorSet(m_device);
13668 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013669 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013670
Tony Barbour5781e8f2015-08-04 16:23:11 -060013671 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013672
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013673 m_errorMonitor->VerifyFound();
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013674}
13675
Karl Schultz6addd812016-02-02 17:17:23 -070013676TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotConsumed) {
Mike Weiblencce7ec72016-10-17 19:33:05 -060013677 TEST_DESCRIPTION("Test that a warning is produced for a fragment shader which provides a spurious "
Chris Forbes1cc79542016-07-20 11:13:44 +120013678 "output with no matching attachment");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013679 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
Mike Weiblencce7ec72016-10-17 19:33:05 -060013680 "fragment shader writes to output location 1 with no matching attachment");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013681
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013682 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013683
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013684 char const *vsSource = "#version 450\n"
13685 "\n"
13686 "out gl_PerVertex {\n"
13687 " vec4 gl_Position;\n"
13688 "};\n"
13689 "void main(){\n"
13690 " gl_Position = vec4(1);\n"
13691 "}\n";
13692 char const *fsSource = "#version 450\n"
13693 "\n"
13694 "layout(location=0) out vec4 x;\n"
13695 "layout(location=1) out vec4 y;\n" /* no matching attachment for this */
13696 "void main(){\n"
13697 " x = vec4(1);\n"
13698 " y = vec4(1);\n"
13699 "}\n";
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013700
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013701 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13702 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013703
13704 VkPipelineObj pipe(m_device);
13705 pipe.AddShader(&vs);
13706 pipe.AddShader(&fs);
13707
Chia-I Wu08accc62015-07-07 11:50:03 +080013708 /* set up CB 0, not written */
13709 pipe.AddColorAttachment();
13710 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013711 /* FS writes CB 1, but we don't configure it */
13712
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013713 VkDescriptorSetObj descriptorSet(m_device);
13714 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013715 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013716
Tony Barbour5781e8f2015-08-04 16:23:11 -060013717 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013718
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013719 m_errorMonitor->VerifyFound();
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013720}
13721
Karl Schultz6addd812016-02-02 17:17:23 -070013722TEST_F(VkLayerTest, CreatePipelineFragmentOutputTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013723 TEST_DESCRIPTION("Test that an error is produced for a mismatch between the fundamental "
Mike Weiblencce7ec72016-10-17 19:33:05 -060013724 "type of an fragment shader output variable, and the format of the corresponding attachment");
13725 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "does not match fragment shader output type");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013726
Chris Forbesa36d69e2015-05-25 11:13:44 +120013727 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesa36d69e2015-05-25 11:13:44 +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 ivec4 x;\n" /* not UNORM */
13740 "void main(){\n"
13741 " x = ivec4(1);\n"
13742 "}\n";
Chris Forbesa36d69e2015-05-25 11:13:44 +120013743
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013744 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13745 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesa36d69e2015-05-25 11:13:44 +120013746
13747 VkPipelineObj pipe(m_device);
13748 pipe.AddShader(&vs);
13749 pipe.AddShader(&fs);
13750
Chia-I Wu08accc62015-07-07 11:50:03 +080013751 /* set up CB 0; type is UNORM by default */
13752 pipe.AddColorAttachment();
13753 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesa36d69e2015-05-25 11:13:44 +120013754
Chris Forbesa36d69e2015-05-25 11:13:44 +120013755 VkDescriptorSetObj descriptorSet(m_device);
13756 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013757 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesa36d69e2015-05-25 11:13:44 +120013758
Tony Barbour5781e8f2015-08-04 16:23:11 -060013759 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesa36d69e2015-05-25 11:13:44 +120013760
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013761 m_errorMonitor->VerifyFound();
Chris Forbesa36d69e2015-05-25 11:13:44 +120013762}
Chris Forbes7b1b8932015-06-05 14:43:36 +120013763
Karl Schultz6addd812016-02-02 17:17:23 -070013764TEST_F(VkLayerTest, CreatePipelineUniformBlockNotProvided) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013765 TEST_DESCRIPTION("Test that an error is produced for a shader consuming a uniform "
13766 "block which has no corresponding binding in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013767 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not declared in pipeline layout");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013768
Chris Forbes556c76c2015-08-14 12:04:59 +120013769 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes556c76c2015-08-14 12:04:59 +120013770
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013771 char const *vsSource = "#version 450\n"
13772 "\n"
13773 "out gl_PerVertex {\n"
13774 " vec4 gl_Position;\n"
13775 "};\n"
13776 "void main(){\n"
13777 " gl_Position = vec4(1);\n"
13778 "}\n";
13779 char const *fsSource = "#version 450\n"
13780 "\n"
13781 "layout(location=0) out vec4 x;\n"
13782 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
13783 "void main(){\n"
13784 " x = vec4(bar.y);\n"
13785 "}\n";
Chris Forbes556c76c2015-08-14 12:04:59 +120013786
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013787 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13788 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes556c76c2015-08-14 12:04:59 +120013789
Chris Forbes556c76c2015-08-14 12:04:59 +120013790 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);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013799 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes556c76c2015-08-14 12:04:59 +120013800
13801 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13802
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013803 m_errorMonitor->VerifyFound();
Chris Forbes556c76c2015-08-14 12:04:59 +120013804}
13805
Chris Forbes5c59e902016-02-26 16:56:09 +130013806TEST_F(VkLayerTest, CreatePipelinePushConstantsNotInLayout) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013807 TEST_DESCRIPTION("Test that an error is produced for a shader consuming push constants "
13808 "which are not provided in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013809 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not declared in layout");
Chris Forbes5c59e902016-02-26 16:56:09 +130013810
13811 ASSERT_NO_FATAL_FAILURE(InitState());
13812
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013813 char const *vsSource = "#version 450\n"
13814 "\n"
13815 "layout(push_constant, std430) uniform foo { float x; } consts;\n"
13816 "out gl_PerVertex {\n"
13817 " vec4 gl_Position;\n"
13818 "};\n"
13819 "void main(){\n"
13820 " gl_Position = vec4(consts.x);\n"
13821 "}\n";
13822 char const *fsSource = "#version 450\n"
13823 "\n"
13824 "layout(location=0) out vec4 x;\n"
13825 "void main(){\n"
13826 " x = vec4(1);\n"
13827 "}\n";
Chris Forbes5c59e902016-02-26 16:56:09 +130013828
13829 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13830 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13831
13832 VkPipelineObj pipe(m_device);
13833 pipe.AddShader(&vs);
13834 pipe.AddShader(&fs);
13835
13836 /* set up CB 0; type is UNORM by default */
13837 pipe.AddColorAttachment();
13838 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13839
13840 VkDescriptorSetObj descriptorSet(m_device);
13841 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13842
13843 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13844
13845 /* should have generated an error -- no push constant ranges provided! */
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013846 m_errorMonitor->VerifyFound();
Chris Forbes5c59e902016-02-26 16:56:09 +130013847}
13848
Chris Forbes3fb17902016-08-22 14:57:55 +120013849TEST_F(VkLayerTest, CreatePipelineInputAttachmentMissing) {
13850 TEST_DESCRIPTION("Test that an error is produced for a shader consuming an input attachment "
13851 "which is not included in the subpass description");
13852 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13853 "consumes input attachment index 0 but not provided in subpass");
13854
13855 ASSERT_NO_FATAL_FAILURE(InitState());
13856
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013857 char const *vsSource = "#version 450\n"
13858 "\n"
13859 "out gl_PerVertex {\n"
13860 " vec4 gl_Position;\n"
13861 "};\n"
13862 "void main(){\n"
13863 " gl_Position = vec4(1);\n"
13864 "}\n";
13865 char const *fsSource = "#version 450\n"
13866 "\n"
13867 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
13868 "layout(location=0) out vec4 color;\n"
13869 "void main() {\n"
13870 " color = subpassLoad(x);\n"
13871 "}\n";
Chris Forbes3fb17902016-08-22 14:57:55 +120013872
13873 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13874 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13875
13876 VkPipelineObj pipe(m_device);
13877 pipe.AddShader(&vs);
13878 pipe.AddShader(&fs);
13879 pipe.AddColorAttachment();
13880 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13881
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013882 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
13883 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes3fb17902016-08-22 14:57:55 +120013884 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013885 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes3fb17902016-08-22 14:57:55 +120013886 ASSERT_VK_SUCCESS(err);
13887
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013888 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes3fb17902016-08-22 14:57:55 +120013889 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013890 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes3fb17902016-08-22 14:57:55 +120013891 ASSERT_VK_SUCCESS(err);
13892
13893 // error here.
13894 pipe.CreateVKPipeline(pl, renderPass());
13895
13896 m_errorMonitor->VerifyFound();
13897
13898 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
13899 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
13900}
13901
Chris Forbes5a9a0472016-08-22 16:02:09 +120013902TEST_F(VkLayerTest, CreatePipelineInputAttachmentTypeMismatch) {
13903 TEST_DESCRIPTION("Test that an error is produced for a shader consuming an input attachment "
13904 "with a format having a different fundamental type");
13905 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13906 "input attachment 0 format of VK_FORMAT_R8G8B8A8_UINT does not match");
13907
13908 ASSERT_NO_FATAL_FAILURE(InitState());
13909
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013910 char const *vsSource = "#version 450\n"
13911 "\n"
13912 "out gl_PerVertex {\n"
13913 " vec4 gl_Position;\n"
13914 "};\n"
13915 "void main(){\n"
13916 " gl_Position = vec4(1);\n"
13917 "}\n";
13918 char const *fsSource = "#version 450\n"
13919 "\n"
13920 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
13921 "layout(location=0) out vec4 color;\n"
13922 "void main() {\n"
13923 " color = subpassLoad(x);\n"
13924 "}\n";
Chris Forbes5a9a0472016-08-22 16:02:09 +120013925
13926 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13927 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13928
13929 VkPipelineObj pipe(m_device);
13930 pipe.AddShader(&vs);
13931 pipe.AddShader(&fs);
13932 pipe.AddColorAttachment();
13933 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13934
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013935 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
13936 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes5a9a0472016-08-22 16:02:09 +120013937 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013938 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes5a9a0472016-08-22 16:02:09 +120013939 ASSERT_VK_SUCCESS(err);
13940
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013941 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120013942 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013943 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes5a9a0472016-08-22 16:02:09 +120013944 ASSERT_VK_SUCCESS(err);
13945
13946 VkAttachmentDescription descs[2] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013947 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
13948 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
13949 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
13950 {0, VK_FORMAT_R8G8B8A8_UINT, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
13951 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 +120013952 };
13953 VkAttachmentReference color = {
13954 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
13955 };
13956 VkAttachmentReference input = {
13957 1, VK_IMAGE_LAYOUT_GENERAL,
13958 };
13959
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013960 VkSubpassDescription sd = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 1, &input, 1, &color, nullptr, nullptr, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120013961
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013962 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, descs, 1, &sd, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120013963 VkRenderPass rp;
13964 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
13965 ASSERT_VK_SUCCESS(err);
13966
13967 // error here.
13968 pipe.CreateVKPipeline(pl, rp);
13969
13970 m_errorMonitor->VerifyFound();
13971
13972 vkDestroyRenderPass(m_device->device(), rp, nullptr);
13973 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
13974 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
13975}
13976
Chris Forbes541f7b02016-08-22 15:30:27 +120013977TEST_F(VkLayerTest, CreatePipelineInputAttachmentMissingArray) {
13978 TEST_DESCRIPTION("Test that an error is produced for a shader consuming an input attachment "
13979 "which is not included in the subpass description -- array case");
13980 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13981 "consumes input attachment index 1 but not provided in subpass");
13982
13983 ASSERT_NO_FATAL_FAILURE(InitState());
13984
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013985 char const *vsSource = "#version 450\n"
13986 "\n"
13987 "out gl_PerVertex {\n"
13988 " vec4 gl_Position;\n"
13989 "};\n"
13990 "void main(){\n"
13991 " gl_Position = vec4(1);\n"
13992 "}\n";
13993 char const *fsSource = "#version 450\n"
13994 "\n"
13995 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput xs[2];\n"
13996 "layout(location=0) out vec4 color;\n"
13997 "void main() {\n"
13998 " color = subpassLoad(xs[1]);\n"
13999 "}\n";
Chris Forbes541f7b02016-08-22 15:30:27 +120014000
14001 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14002 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14003
14004 VkPipelineObj pipe(m_device);
14005 pipe.AddShader(&vs);
14006 pipe.AddShader(&fs);
14007 pipe.AddColorAttachment();
14008 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14009
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014010 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 2, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
14011 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes541f7b02016-08-22 15:30:27 +120014012 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014013 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes541f7b02016-08-22 15:30:27 +120014014 ASSERT_VK_SUCCESS(err);
14015
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014016 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes541f7b02016-08-22 15:30:27 +120014017 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014018 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes541f7b02016-08-22 15:30:27 +120014019 ASSERT_VK_SUCCESS(err);
14020
14021 // error here.
14022 pipe.CreateVKPipeline(pl, renderPass());
14023
14024 m_errorMonitor->VerifyFound();
14025
14026 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
14027 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
14028}
14029
Chris Forbes10eb9ae2016-05-31 16:09:42 +120014030TEST_F(VkLayerTest, CreateComputePipelineMissingDescriptor) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014031 TEST_DESCRIPTION("Test that an error is produced for a compute pipeline consuming a "
14032 "descriptor which is not provided in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014033 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Shader uses descriptor slot 0.0");
Chris Forbes10eb9ae2016-05-31 16:09:42 +120014034
14035 ASSERT_NO_FATAL_FAILURE(InitState());
14036
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014037 char const *csSource = "#version 450\n"
14038 "\n"
14039 "layout(local_size_x=1) in;\n"
14040 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
14041 "void main(){\n"
14042 " x = vec4(1);\n"
14043 "}\n";
Chris Forbes10eb9ae2016-05-31 16:09:42 +120014044
14045 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
14046
14047 VkDescriptorSetObj descriptorSet(m_device);
14048 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14049
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014050 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
14051 nullptr,
14052 0,
14053 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
14054 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
14055 descriptorSet.GetPipelineLayout(),
14056 VK_NULL_HANDLE,
14057 -1};
Chris Forbes10eb9ae2016-05-31 16:09:42 +120014058
14059 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014060 VkResult err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes10eb9ae2016-05-31 16:09:42 +120014061
14062 m_errorMonitor->VerifyFound();
14063
14064 if (err == VK_SUCCESS) {
14065 vkDestroyPipeline(m_device->device(), pipe, nullptr);
14066 }
14067}
14068
Chris Forbes22a9b092016-07-19 14:34:05 +120014069TEST_F(VkLayerTest, CreateComputePipelineDescriptorTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014070 TEST_DESCRIPTION("Test that an error is produced for a pipeline consuming a "
14071 "descriptor-backed resource of a mismatched type");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014072 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14073 "but descriptor of type VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER");
Chris Forbes22a9b092016-07-19 14:34:05 +120014074
14075 ASSERT_NO_FATAL_FAILURE(InitState());
14076
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014077 VkDescriptorSetLayoutBinding binding = {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr};
14078 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &binding};
Chris Forbes22a9b092016-07-19 14:34:05 +120014079 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014080 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes22a9b092016-07-19 14:34:05 +120014081 ASSERT_VK_SUCCESS(err);
14082
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014083 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes22a9b092016-07-19 14:34:05 +120014084 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014085 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes22a9b092016-07-19 14:34:05 +120014086 ASSERT_VK_SUCCESS(err);
14087
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014088 char const *csSource = "#version 450\n"
14089 "\n"
14090 "layout(local_size_x=1) in;\n"
14091 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
14092 "void main() {\n"
14093 " x.x = 1.0f;\n"
14094 "}\n";
Chris Forbes22a9b092016-07-19 14:34:05 +120014095 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
14096
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014097 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
14098 nullptr,
14099 0,
14100 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
14101 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
14102 pl,
14103 VK_NULL_HANDLE,
14104 -1};
Chris Forbes22a9b092016-07-19 14:34:05 +120014105
14106 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014107 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes22a9b092016-07-19 14:34:05 +120014108
14109 m_errorMonitor->VerifyFound();
14110
14111 if (err == VK_SUCCESS) {
14112 vkDestroyPipeline(m_device->device(), pipe, nullptr);
14113 }
14114
14115 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
14116 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
14117}
14118
Chris Forbes50020592016-07-27 13:52:41 +120014119TEST_F(VkLayerTest, DrawTimeImageViewTypeMismatchWithPipeline) {
14120 TEST_DESCRIPTION("Test that an error is produced when an image view type "
14121 "does not match the dimensionality declared in the shader");
14122
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014123 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 +120014124
14125 ASSERT_NO_FATAL_FAILURE(InitState());
14126 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14127
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014128 char const *vsSource = "#version 450\n"
14129 "\n"
14130 "out gl_PerVertex { vec4 gl_Position; };\n"
14131 "void main() { gl_Position = vec4(0); }\n";
14132 char const *fsSource = "#version 450\n"
14133 "\n"
14134 "layout(set=0, binding=0) uniform sampler3D s;\n"
14135 "layout(location=0) out vec4 color;\n"
14136 "void main() {\n"
14137 " color = texture(s, vec3(0));\n"
14138 "}\n";
Chris Forbes50020592016-07-27 13:52:41 +120014139 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14140 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14141
14142 VkPipelineObj pipe(m_device);
14143 pipe.AddShader(&vs);
14144 pipe.AddShader(&fs);
14145 pipe.AddColorAttachment();
14146
14147 VkTextureObj texture(m_device, nullptr);
14148 VkSamplerObj sampler(m_device);
14149
14150 VkDescriptorSetObj descriptorSet(m_device);
14151 descriptorSet.AppendSamplerTexture(&sampler, &texture);
14152 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14153
14154 VkResult err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14155 ASSERT_VK_SUCCESS(err);
14156
Tony Barbour552f6c02016-12-21 14:34:07 -070014157 m_commandBuffer->BeginCommandBuffer();
14158 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Chris Forbes50020592016-07-27 13:52:41 +120014159
14160 m_commandBuffer->BindPipeline(pipe);
14161 m_commandBuffer->BindDescriptorSet(descriptorSet);
14162
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014163 VkViewport viewport = {0, 0, 16, 16, 0, 1};
Chris Forbes50020592016-07-27 13:52:41 +120014164 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014165 VkRect2D scissor = {{0, 0}, {16, 16}};
Chris Forbes50020592016-07-27 13:52:41 +120014166 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
14167
14168 // error produced here.
14169 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
14170
14171 m_errorMonitor->VerifyFound();
14172
Tony Barbour552f6c02016-12-21 14:34:07 -070014173 m_commandBuffer->EndRenderPass();
14174 m_commandBuffer->EndCommandBuffer();
Chris Forbes50020592016-07-27 13:52:41 +120014175}
14176
Chris Forbes5533bfc2016-07-27 14:12:34 +120014177TEST_F(VkLayerTest, DrawTimeImageMultisampleMismatchWithPipeline) {
14178 TEST_DESCRIPTION("Test that an error is produced when a multisampled images "
14179 "are consumed via singlesample images types in the shader, or vice versa.");
14180
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014181 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "requires bound image to have multiple samples");
Chris Forbes5533bfc2016-07-27 14:12:34 +120014182
14183 ASSERT_NO_FATAL_FAILURE(InitState());
14184 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14185
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014186 char const *vsSource = "#version 450\n"
14187 "\n"
14188 "out gl_PerVertex { vec4 gl_Position; };\n"
14189 "void main() { gl_Position = vec4(0); }\n";
14190 char const *fsSource = "#version 450\n"
14191 "\n"
14192 "layout(set=0, binding=0) uniform sampler2DMS s;\n"
14193 "layout(location=0) out vec4 color;\n"
14194 "void main() {\n"
14195 " color = texelFetch(s, ivec2(0), 0);\n"
14196 "}\n";
Chris Forbes5533bfc2016-07-27 14:12:34 +120014197 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14198 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14199
14200 VkPipelineObj pipe(m_device);
14201 pipe.AddShader(&vs);
14202 pipe.AddShader(&fs);
14203 pipe.AddColorAttachment();
14204
14205 VkTextureObj texture(m_device, nullptr);
14206 VkSamplerObj sampler(m_device);
14207
14208 VkDescriptorSetObj descriptorSet(m_device);
14209 descriptorSet.AppendSamplerTexture(&sampler, &texture);
14210 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14211
14212 VkResult err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14213 ASSERT_VK_SUCCESS(err);
14214
Tony Barbour552f6c02016-12-21 14:34:07 -070014215 m_commandBuffer->BeginCommandBuffer();
14216 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Chris Forbes5533bfc2016-07-27 14:12:34 +120014217
14218 m_commandBuffer->BindPipeline(pipe);
14219 m_commandBuffer->BindDescriptorSet(descriptorSet);
14220
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014221 VkViewport viewport = {0, 0, 16, 16, 0, 1};
Chris Forbes5533bfc2016-07-27 14:12:34 +120014222 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014223 VkRect2D scissor = {{0, 0}, {16, 16}};
Chris Forbes5533bfc2016-07-27 14:12:34 +120014224 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
14225
14226 // error produced here.
14227 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
14228
14229 m_errorMonitor->VerifyFound();
14230
Tony Barbour552f6c02016-12-21 14:34:07 -070014231 m_commandBuffer->EndRenderPass();
14232 m_commandBuffer->EndCommandBuffer();
Chris Forbes5533bfc2016-07-27 14:12:34 +120014233}
14234
Mark Lobodzinski209b5292015-09-17 09:44:05 -060014235#endif // SHADER_CHECKER_TESTS
14236
14237#if DEVICE_LIMITS_TESTS
Mark Youngc48c4c12016-04-11 14:26:49 -060014238TEST_F(VkLayerTest, CreateImageLimitsViolationMaxWidth) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014239 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "CreateImage extents exceed allowable limits for format");
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060014240
14241 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060014242
14243 // Create an image
14244 VkImage image;
14245
Karl Schultz6addd812016-02-02 17:17:23 -070014246 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
14247 const int32_t tex_width = 32;
14248 const int32_t tex_height = 32;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060014249
14250 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014251 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14252 image_create_info.pNext = NULL;
14253 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14254 image_create_info.format = tex_format;
14255 image_create_info.extent.width = tex_width;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060014256 image_create_info.extent.height = tex_height;
Karl Schultz6addd812016-02-02 17:17:23 -070014257 image_create_info.extent.depth = 1;
14258 image_create_info.mipLevels = 1;
14259 image_create_info.arrayLayers = 1;
14260 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14261 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
14262 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
14263 image_create_info.flags = 0;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060014264
14265 // Introduce error by sending down a bogus width extent
14266 image_create_info.extent.width = 65536;
Chia-I Wuf7458c52015-10-26 21:10:41 +080014267 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060014268
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014269 m_errorMonitor->VerifyFound();
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060014270}
14271
Mark Youngc48c4c12016-04-11 14:26:49 -060014272TEST_F(VkLayerTest, CreateImageLimitsViolationMinWidth) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014273 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14274 "CreateImage extents is 0 for at least one required dimension");
Mark Youngc48c4c12016-04-11 14:26:49 -060014275
14276 ASSERT_NO_FATAL_FAILURE(InitState());
14277
14278 // Create an image
14279 VkImage image;
14280
14281 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
14282 const int32_t tex_width = 32;
14283 const int32_t tex_height = 32;
14284
14285 VkImageCreateInfo image_create_info = {};
14286 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14287 image_create_info.pNext = NULL;
14288 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14289 image_create_info.format = tex_format;
14290 image_create_info.extent.width = tex_width;
14291 image_create_info.extent.height = tex_height;
14292 image_create_info.extent.depth = 1;
14293 image_create_info.mipLevels = 1;
14294 image_create_info.arrayLayers = 1;
14295 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14296 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
14297 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
14298 image_create_info.flags = 0;
14299
14300 // Introduce error by sending down a bogus width extent
14301 image_create_info.extent.width = 0;
14302 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
14303
14304 m_errorMonitor->VerifyFound();
14305}
Mark Lobodzinski209b5292015-09-17 09:44:05 -060014306#endif // DEVICE_LIMITS_TESTS
Chris Forbesa36d69e2015-05-25 11:13:44 +120014307
Tobin Ehliscde08892015-09-22 10:11:37 -060014308#if IMAGE_TESTS
Mark Lobodzinski66e5eab2016-11-15 13:30:38 -070014309
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060014310TEST_F(VkLayerTest, AttachmentDescriptionUndefinedFormat) {
14311 TEST_DESCRIPTION("Create a render pass with an attachment description "
14312 "format set to VK_FORMAT_UNDEFINED");
14313
14314 ASSERT_NO_FATAL_FAILURE(InitState());
14315 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14316
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014317 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "format is VK_FORMAT_UNDEFINED");
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060014318
14319 VkAttachmentReference color_attach = {};
14320 color_attach.layout = VK_IMAGE_LAYOUT_GENERAL;
14321 color_attach.attachment = 0;
14322 VkSubpassDescription subpass = {};
14323 subpass.colorAttachmentCount = 1;
14324 subpass.pColorAttachments = &color_attach;
14325
14326 VkRenderPassCreateInfo rpci = {};
14327 rpci.subpassCount = 1;
14328 rpci.pSubpasses = &subpass;
14329 rpci.attachmentCount = 1;
14330 VkAttachmentDescription attach_desc = {};
14331 attach_desc.format = VK_FORMAT_UNDEFINED;
14332 rpci.pAttachments = &attach_desc;
14333 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
14334 VkRenderPass rp;
14335 VkResult result = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
14336
14337 m_errorMonitor->VerifyFound();
14338
14339 if (result == VK_SUCCESS) {
14340 vkDestroyRenderPass(m_device->device(), rp, NULL);
14341 }
14342}
14343
Karl Schultz6addd812016-02-02 17:17:23 -070014344TEST_F(VkLayerTest, InvalidImageView) {
14345 VkResult err;
Tobin Ehliscde08892015-09-22 10:11:37 -060014346
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070014347 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00768);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014348
Tobin Ehliscde08892015-09-22 10:11:37 -060014349 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehliscde08892015-09-22 10:11:37 -060014350
Mike Stroyana3082432015-09-25 13:39:21 -060014351 // Create an image and try to create a view with bad baseMipLevel
Karl Schultz6addd812016-02-02 17:17:23 -070014352 VkImage image;
Tobin Ehliscde08892015-09-22 10:11:37 -060014353
Karl Schultz6addd812016-02-02 17:17:23 -070014354 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
14355 const int32_t tex_width = 32;
14356 const int32_t tex_height = 32;
Tobin Ehliscde08892015-09-22 10:11:37 -060014357
14358 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014359 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14360 image_create_info.pNext = NULL;
14361 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14362 image_create_info.format = tex_format;
14363 image_create_info.extent.width = tex_width;
14364 image_create_info.extent.height = tex_height;
14365 image_create_info.extent.depth = 1;
14366 image_create_info.mipLevels = 1;
14367 image_create_info.arrayLayers = 1;
14368 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14369 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
14370 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
14371 image_create_info.flags = 0;
Tobin Ehliscde08892015-09-22 10:11:37 -060014372
Chia-I Wuf7458c52015-10-26 21:10:41 +080014373 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehliscde08892015-09-22 10:11:37 -060014374 ASSERT_VK_SUCCESS(err);
14375
14376 VkImageViewCreateInfo image_view_create_info = {};
Chris Forbes53bef902016-11-28 17:53:04 +130014377 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070014378 image_view_create_info.image = image;
14379 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
14380 image_view_create_info.format = tex_format;
14381 image_view_create_info.subresourceRange.layerCount = 1;
14382 image_view_create_info.subresourceRange.baseMipLevel = 10; // cause an error
14383 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014384 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehliscde08892015-09-22 10:11:37 -060014385
14386 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014387 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehliscde08892015-09-22 10:11:37 -060014388
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014389 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -060014390 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehliscde08892015-09-22 10:11:37 -060014391}
Mike Stroyana3082432015-09-25 13:39:21 -060014392
Mark Youngd339ba32016-05-30 13:28:35 -060014393TEST_F(VkLayerTest, CreateImageViewNoMemoryBoundToImage) {
14394 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -060014395 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -060014396 " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Mark Youngd339ba32016-05-30 13:28:35 -060014397
14398 ASSERT_NO_FATAL_FAILURE(InitState());
14399
14400 // Create an image and try to create a view with no memory backing the image
14401 VkImage image;
14402
14403 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
14404 const int32_t tex_width = 32;
14405 const int32_t tex_height = 32;
14406
14407 VkImageCreateInfo image_create_info = {};
14408 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14409 image_create_info.pNext = NULL;
14410 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14411 image_create_info.format = tex_format;
14412 image_create_info.extent.width = tex_width;
14413 image_create_info.extent.height = tex_height;
14414 image_create_info.extent.depth = 1;
14415 image_create_info.mipLevels = 1;
14416 image_create_info.arrayLayers = 1;
14417 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14418 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
14419 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
14420 image_create_info.flags = 0;
14421
14422 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
14423 ASSERT_VK_SUCCESS(err);
14424
14425 VkImageViewCreateInfo image_view_create_info = {};
Chris Forbes53bef902016-11-28 17:53:04 +130014426 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Mark Youngd339ba32016-05-30 13:28:35 -060014427 image_view_create_info.image = image;
14428 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
14429 image_view_create_info.format = tex_format;
14430 image_view_create_info.subresourceRange.layerCount = 1;
14431 image_view_create_info.subresourceRange.baseMipLevel = 0;
14432 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014433 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Youngd339ba32016-05-30 13:28:35 -060014434
14435 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014436 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Youngd339ba32016-05-30 13:28:35 -060014437
14438 m_errorMonitor->VerifyFound();
14439 vkDestroyImage(m_device->device(), image, NULL);
14440 // If last error is success, it still created the view, so delete it.
14441 if (err == VK_SUCCESS) {
14442 vkDestroyImageView(m_device->device(), view, NULL);
14443 }
Mark Youngd339ba32016-05-30 13:28:35 -060014444}
14445
Karl Schultz6addd812016-02-02 17:17:23 -070014446TEST_F(VkLayerTest, InvalidImageViewAspect) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014447 TEST_DESCRIPTION("Create an image and try to create a view with an invalid aspectMask");
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070014448 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00741);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014449
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060014450 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060014451
Karl Schultz6addd812016-02-02 17:17:23 -070014452 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060014453 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014454 image.init(32, 32, tex_format, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_LINEAR, 0);
Tobin Ehlis1f567a22016-05-25 16:15:18 -060014455 ASSERT_TRUE(image.initialized());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060014456
14457 VkImageViewCreateInfo image_view_create_info = {};
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060014458 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060014459 image_view_create_info.image = image.handle();
Karl Schultz6addd812016-02-02 17:17:23 -070014460 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
14461 image_view_create_info.format = tex_format;
14462 image_view_create_info.subresourceRange.baseMipLevel = 0;
14463 image_view_create_info.subresourceRange.levelCount = 1;
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060014464 image_view_create_info.subresourceRange.layerCount = 1;
Karl Schultz6addd812016-02-02 17:17:23 -070014465 // Cause an error by setting an invalid image aspect
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014466 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060014467
14468 VkImageView view;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060014469 vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060014470
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014471 m_errorMonitor->VerifyFound();
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060014472}
14473
Mark Lobodzinskidb117632016-03-31 10:45:56 -060014474TEST_F(VkLayerTest, CopyImageLayerCountMismatch) {
Karl Schultz6addd812016-02-02 17:17:23 -070014475 VkResult err;
14476 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060014477
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070014478 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01198);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014479
Mike Stroyana3082432015-09-25 13:39:21 -060014480 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060014481
14482 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070014483 VkImage srcImage;
14484 VkImage dstImage;
14485 VkDeviceMemory srcMem;
14486 VkDeviceMemory destMem;
14487 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060014488
14489 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014490 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14491 image_create_info.pNext = NULL;
14492 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14493 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
14494 image_create_info.extent.width = 32;
14495 image_create_info.extent.height = 32;
14496 image_create_info.extent.depth = 1;
14497 image_create_info.mipLevels = 1;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060014498 image_create_info.arrayLayers = 4;
Karl Schultz6addd812016-02-02 17:17:23 -070014499 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14500 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
14501 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
14502 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014503
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014504 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014505 ASSERT_VK_SUCCESS(err);
14506
Mark Lobodzinski867787a2016-10-14 11:49:55 -060014507 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014508 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014509 ASSERT_VK_SUCCESS(err);
14510
14511 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014512 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014513 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
14514 memAlloc.pNext = NULL;
14515 memAlloc.allocationSize = 0;
14516 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014517
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060014518 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014519 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014520 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014521 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014522 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014523 ASSERT_VK_SUCCESS(err);
14524
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014525 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014526 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014527 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060014528 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014529 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014530 ASSERT_VK_SUCCESS(err);
14531
14532 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
14533 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014534 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060014535 ASSERT_VK_SUCCESS(err);
14536
Tony Barbour552f6c02016-12-21 14:34:07 -070014537 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060014538 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014539 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014540 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060014541 copyRegion.srcSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060014542 copyRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060014543 copyRegion.srcOffset.x = 0;
14544 copyRegion.srcOffset.y = 0;
14545 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014546 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014547 copyRegion.dstSubresource.mipLevel = 0;
14548 copyRegion.dstSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060014549 // Introduce failure by forcing the dst layerCount to differ from src
14550 copyRegion.dstSubresource.layerCount = 3;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014551 copyRegion.dstOffset.x = 0;
14552 copyRegion.dstOffset.y = 0;
14553 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014554 copyRegion.extent.width = 1;
14555 copyRegion.extent.height = 1;
14556 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014557 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070014558 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060014559
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014560 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060014561
Chia-I Wuf7458c52015-10-26 21:10:41 +080014562 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014563 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080014564 vkFreeMemory(m_device->device(), srcMem, NULL);
14565 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060014566}
14567
Tony Barbourd6673642016-05-05 14:46:39 -060014568TEST_F(VkLayerTest, ImageLayerUnsupportedFormat) {
14569
14570 TEST_DESCRIPTION("Creating images with unsuported formats ");
14571
14572 ASSERT_NO_FATAL_FAILURE(InitState());
14573 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14574 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014575 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 -060014576 VK_IMAGE_TILING_OPTIMAL, 0);
14577 ASSERT_TRUE(image.initialized());
14578
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014579 // Create image with unsupported format - Expect FORMAT_UNSUPPORTED
Chris Forbesf4d8e332016-11-28 17:51:10 +130014580 VkImageCreateInfo image_create_info = {};
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014581 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014582 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14583 image_create_info.format = VK_FORMAT_UNDEFINED;
14584 image_create_info.extent.width = 32;
14585 image_create_info.extent.height = 32;
14586 image_create_info.extent.depth = 1;
14587 image_create_info.mipLevels = 1;
14588 image_create_info.arrayLayers = 1;
14589 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14590 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
14591 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014592
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014593 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14594 "vkCreateImage: VkFormat for image must not be VK_FORMAT_UNDEFINED");
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014595
14596 VkImage localImage;
14597 vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage);
14598 m_errorMonitor->VerifyFound();
14599
Tony Barbourd6673642016-05-05 14:46:39 -060014600 VkFormat unsupported = VK_FORMAT_UNDEFINED;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014601 // Look for a format that is COMPLETELY unsupported with this hardware
Tony Barbourd6673642016-05-05 14:46:39 -060014602 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
14603 VkFormat format = static_cast<VkFormat>(f);
14604 VkFormatProperties fProps = m_device->format_properties(format);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014605 if (format != VK_FORMAT_UNDEFINED && fProps.linearTilingFeatures == 0 && fProps.optimalTilingFeatures == 0) {
Tony Barbourd6673642016-05-05 14:46:39 -060014606 unsupported = format;
14607 break;
14608 }
14609 }
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014610
Tony Barbourd6673642016-05-05 14:46:39 -060014611 if (unsupported != VK_FORMAT_UNDEFINED) {
Tony Barbourd6673642016-05-05 14:46:39 -060014612 image_create_info.format = unsupported;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014613 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is an unsupported format");
Tony Barbourd6673642016-05-05 14:46:39 -060014614
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014615 vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage);
Tony Barbourd6673642016-05-05 14:46:39 -060014616 m_errorMonitor->VerifyFound();
14617 }
14618}
14619
14620TEST_F(VkLayerTest, ImageLayerViewTests) {
14621 VkResult ret;
14622 TEST_DESCRIPTION("Passing bad parameters to CreateImageView");
14623
14624 ASSERT_NO_FATAL_FAILURE(InitState());
14625
14626 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014627 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 -060014628 VK_IMAGE_TILING_OPTIMAL, 0);
14629 ASSERT_TRUE(image.initialized());
14630
14631 VkImageView imgView;
14632 VkImageViewCreateInfo imgViewInfo = {};
14633 imgViewInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
14634 imgViewInfo.image = image.handle();
14635 imgViewInfo.viewType = VK_IMAGE_VIEW_TYPE_2D;
14636 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
14637 imgViewInfo.subresourceRange.layerCount = 1;
14638 imgViewInfo.subresourceRange.baseMipLevel = 0;
14639 imgViewInfo.subresourceRange.levelCount = 1;
14640 imgViewInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14641
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070014642 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00768);
Tony Barbourd6673642016-05-05 14:46:39 -060014643 // View can't have baseMipLevel >= image's mipLevels - Expect
14644 // VIEW_CREATE_ERROR
14645 imgViewInfo.subresourceRange.baseMipLevel = 1;
14646 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14647 m_errorMonitor->VerifyFound();
14648 imgViewInfo.subresourceRange.baseMipLevel = 0;
14649
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070014650 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00769);
Tony Barbourd6673642016-05-05 14:46:39 -060014651 // View can't have baseArrayLayer >= image's arraySize - Expect
14652 // VIEW_CREATE_ERROR
14653 imgViewInfo.subresourceRange.baseArrayLayer = 1;
14654 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14655 m_errorMonitor->VerifyFound();
14656 imgViewInfo.subresourceRange.baseArrayLayer = 0;
14657
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014658 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with 0 in "
14659 "pCreateInfo->subresourceRange."
14660 "levelCount");
Tony Barbourd6673642016-05-05 14:46:39 -060014661 // View's levelCount can't be 0 - Expect VIEW_CREATE_ERROR
14662 imgViewInfo.subresourceRange.levelCount = 0;
14663 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14664 m_errorMonitor->VerifyFound();
14665 imgViewInfo.subresourceRange.levelCount = 1;
14666
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014667 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with 0 in "
14668 "pCreateInfo->subresourceRange."
14669 "layerCount");
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060014670 m_errorMonitor->SetDesiredFailureMsg(
14671 VK_DEBUG_REPORT_ERROR_BIT_EXT,
14672 "if pCreateInfo->viewType is VK_IMAGE_TYPE_2D, pCreateInfo->subresourceRange.layerCount must be 1");
Tony Barbourd6673642016-05-05 14:46:39 -060014673 // View's layerCount can't be 0 - Expect VIEW_CREATE_ERROR
14674 imgViewInfo.subresourceRange.layerCount = 0;
14675 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14676 m_errorMonitor->VerifyFound();
14677 imgViewInfo.subresourceRange.layerCount = 1;
14678
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014679 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "but both must be color formats");
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060014680 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Formats MUST be IDENTICAL unless "
14681 "VK_IMAGE_CREATE_MUTABLE_FORMAT BIT "
14682 "was set on image creation.");
Tony Barbourd6673642016-05-05 14:46:39 -060014683 // Can't use depth format for view into color image - Expect INVALID_FORMAT
14684 imgViewInfo.format = VK_FORMAT_D24_UNORM_S8_UINT;
14685 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14686 m_errorMonitor->VerifyFound();
14687 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
14688
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070014689 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02172);
Tony Barbourd6673642016-05-05 14:46:39 -060014690 // Same compatibility class but no MUTABLE_FORMAT bit - Expect
14691 // VIEW_CREATE_ERROR
14692 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UINT;
14693 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14694 m_errorMonitor->VerifyFound();
14695 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
14696
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070014697 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02171);
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060014698 // TODO: Update framework to easily passing mutable flag into ImageObj init
14699 // For now just allowing image for this one test to not have memory bound
14700 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14701 " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Tony Barbourd6673642016-05-05 14:46:39 -060014702 // Have MUTABLE_FORMAT bit but not in same compatibility class - Expect
14703 // VIEW_CREATE_ERROR
14704 VkImageCreateInfo mutImgInfo = image.create_info();
14705 VkImage mutImage;
14706 mutImgInfo.format = VK_FORMAT_R8_UINT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014707 assert(m_device->format_properties(VK_FORMAT_R8_UINT).optimalTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT);
Tony Barbourd6673642016-05-05 14:46:39 -060014708 mutImgInfo.flags = VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT;
14709 mutImgInfo.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
14710 ret = vkCreateImage(m_device->handle(), &mutImgInfo, NULL, &mutImage);
14711 ASSERT_VK_SUCCESS(ret);
14712 imgViewInfo.image = mutImage;
14713 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14714 m_errorMonitor->VerifyFound();
14715 imgViewInfo.image = image.handle();
14716 vkDestroyImage(m_device->handle(), mutImage, NULL);
14717}
14718
14719TEST_F(VkLayerTest, MiscImageLayerTests) {
14720
14721 TEST_DESCRIPTION("Image layer tests that don't belong elsewhare");
14722
14723 ASSERT_NO_FATAL_FAILURE(InitState());
14724
Rene Lindsay135204f2016-12-22 17:11:09 -070014725 // TODO: Ideally we should check if a format is supported, before using it.
Tony Barbourd6673642016-05-05 14:46:39 -060014726 VkImageObj image(m_device);
Rene Lindsay135204f2016-12-22 17:11:09 -070014727 image.init(128, 128, VK_FORMAT_R16G16B16A16_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
14728 VK_IMAGE_TILING_OPTIMAL, 0); // 64bpp
Tony Barbourd6673642016-05-05 14:46:39 -060014729 ASSERT_TRUE(image.initialized());
Tony Barbourd6673642016-05-05 14:46:39 -060014730 vk_testing::Buffer buffer;
14731 VkMemoryPropertyFlags reqs = 0;
Rene Lindsay135204f2016-12-22 17:11:09 -070014732 buffer.init_as_src(*m_device, 128 * 128 * 8, reqs);
Tony Barbourd6673642016-05-05 14:46:39 -060014733 VkBufferImageCopy region = {};
14734 region.bufferRowLength = 128;
14735 region.bufferImageHeight = 128;
14736 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14737 // layerCount can't be 0 - Expect MISMATCHED_IMAGE_ASPECT
Mark Lobodzinski3702e932016-11-22 11:40:48 -070014738 region.imageSubresource.layerCount = 1;
Tony Barbourd6673642016-05-05 14:46:39 -060014739 region.imageExtent.height = 4;
14740 region.imageExtent.width = 4;
14741 region.imageExtent.depth = 1;
Rene Lindsay135204f2016-12-22 17:11:09 -070014742
14743 VkImageObj image2(m_device);
14744 image2.init(128, 128, VK_FORMAT_R8G8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
14745 VK_IMAGE_TILING_OPTIMAL, 0); // 16bpp
14746 ASSERT_TRUE(image2.initialized());
14747 vk_testing::Buffer buffer2;
14748 VkMemoryPropertyFlags reqs2 = 0;
14749 buffer2.init_as_src(*m_device, 128 * 128 * 2, reqs2);
14750 VkBufferImageCopy region2 = {};
14751 region2.bufferRowLength = 128;
14752 region2.bufferImageHeight = 128;
14753 region2.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14754 // layerCount can't be 0 - Expect MISMATCHED_IMAGE_ASPECT
14755 region2.imageSubresource.layerCount = 1;
14756 region2.imageExtent.height = 4;
14757 region2.imageExtent.width = 4;
14758 region2.imageExtent.depth = 1;
Tony Barbourd6673642016-05-05 14:46:39 -060014759 m_commandBuffer->BeginCommandBuffer();
Tony Barbourd6673642016-05-05 14:46:39 -060014760
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070014761 // Image must have offset.z of 0 and extent.depth of 1
14762 // Introduce failure by setting imageExtent.depth to 0
14763 region.imageExtent.depth = 0;
14764 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01269);
14765 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
14766 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
14767 m_errorMonitor->VerifyFound();
14768
14769 region.imageExtent.depth = 1;
14770
14771 // Image must have offset.z of 0 and extent.depth of 1
14772 // Introduce failure by setting imageOffset.z to 4
14773 region.imageOffset.z = 4;
14774 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01269);
14775 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
14776 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
14777 m_errorMonitor->VerifyFound();
14778
14779 region.imageOffset.z = 0;
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060014780 // BufferOffset must be a multiple of the calling command's VkImage parameter's texel size
14781 // Introduce failure by setting bufferOffset to 1 and 1/2 texels
Rene Lindsay135204f2016-12-22 17:11:09 -070014782 region.bufferOffset = 4;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070014783 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01263);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014784 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
14785 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060014786 m_errorMonitor->VerifyFound();
14787
14788 // BufferOffset must be a multiple of 4
14789 // Introduce failure by setting bufferOffset to a value not divisible by 4
Rene Lindsay135204f2016-12-22 17:11:09 -070014790 region2.bufferOffset = 6;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070014791 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01264);
Rene Lindsay135204f2016-12-22 17:11:09 -070014792 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer2.handle(), image2.handle(),
14793 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region2);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060014794 m_errorMonitor->VerifyFound();
14795
14796 // BufferRowLength must be 0, or greater than or equal to the width member of imageExtent
14797 region.bufferOffset = 0;
14798 region.imageExtent.height = 128;
14799 region.imageExtent.width = 128;
14800 // Introduce failure by setting bufferRowLength > 0 but less than width
14801 region.bufferRowLength = 64;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070014802 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01265);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014803 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
14804 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060014805 m_errorMonitor->VerifyFound();
14806
14807 // BufferImageHeight must be 0, or greater than or equal to the height member of imageExtent
14808 region.bufferRowLength = 128;
14809 // Introduce failure by setting bufferRowHeight > 0 but less than height
14810 region.bufferImageHeight = 64;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070014811 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01266);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014812 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
14813 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060014814 m_errorMonitor->VerifyFound();
14815
14816 region.bufferImageHeight = 128;
Dave Houlton34df4cb2016-12-01 16:43:06 -070014817 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "If the format of srcImage is an "
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014818 "integer-based format then filter must be VK_FILTER_NEAREST");
Tony Barbourd6673642016-05-05 14:46:39 -060014819 // Expect INVALID_FILTER
14820 VkImageObj intImage1(m_device);
Rene Lindsaya35e1cb2016-12-26 10:30:05 -070014821 intImage1.init(128, 128, VK_FORMAT_R8_UINT, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT,
14822 VK_IMAGE_TILING_OPTIMAL, 0);
Tony Barbourd6673642016-05-05 14:46:39 -060014823 VkImageObj intImage2(m_device);
Rene Lindsaya35e1cb2016-12-26 10:30:05 -070014824 intImage2.init(128, 128, VK_FORMAT_R8_UINT, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
14825 VK_IMAGE_TILING_OPTIMAL, 0);
Tony Barbourd6673642016-05-05 14:46:39 -060014826 VkImageBlit blitRegion = {};
14827 blitRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14828 blitRegion.srcSubresource.baseArrayLayer = 0;
14829 blitRegion.srcSubresource.layerCount = 1;
14830 blitRegion.srcSubresource.mipLevel = 0;
14831 blitRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14832 blitRegion.dstSubresource.baseArrayLayer = 0;
14833 blitRegion.dstSubresource.layerCount = 1;
14834 blitRegion.dstSubresource.mipLevel = 0;
14835
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014836 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), intImage1.handle(), intImage1.layout(), intImage2.handle(),
Rene Lindsaya35e1cb2016-12-26 10:30:05 -070014837 intImage2.layout(), 1, &blitRegion, VK_FILTER_LINEAR);
Tony Barbourd6673642016-05-05 14:46:39 -060014838 m_errorMonitor->VerifyFound();
14839
Mark Lobodzinskib02ea642016-08-17 13:03:57 -060014840 // Look for NULL-blit warning
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014841 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "Offsets specify a zero-volume area.");
14842 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), intImage1.handle(), intImage1.layout(), intImage2.handle(),
14843 intImage2.layout(), 1, &blitRegion, VK_FILTER_LINEAR);
Mark Lobodzinskib02ea642016-08-17 13:03:57 -060014844 m_errorMonitor->VerifyFound();
14845
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014846 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with 0 in ppMemoryBarriers");
Tony Barbourd6673642016-05-05 14:46:39 -060014847 VkImageMemoryBarrier img_barrier;
14848 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
14849 img_barrier.pNext = NULL;
14850 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
14851 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
14852 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
14853 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
14854 img_barrier.image = image.handle();
14855 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
14856 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
14857 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14858 img_barrier.subresourceRange.baseArrayLayer = 0;
14859 img_barrier.subresourceRange.baseMipLevel = 0;
14860 // layerCount should not be 0 - Expect INVALID_IMAGE_RESOURCE
14861 img_barrier.subresourceRange.layerCount = 0;
14862 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014863 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
14864 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbourd6673642016-05-05 14:46:39 -060014865 m_errorMonitor->VerifyFound();
14866 img_barrier.subresourceRange.layerCount = 1;
14867}
14868
14869TEST_F(VkLayerTest, ImageFormatLimits) {
14870
14871 TEST_DESCRIPTION("Exceed the limits of image format ");
14872
Cody Northropc31a84f2016-08-22 10:41:47 -060014873 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014874 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "CreateImage extents exceed allowable limits for format");
Tony Barbourd6673642016-05-05 14:46:39 -060014875 VkImageCreateInfo image_create_info = {};
14876 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14877 image_create_info.pNext = NULL;
14878 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14879 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
14880 image_create_info.extent.width = 32;
14881 image_create_info.extent.height = 32;
14882 image_create_info.extent.depth = 1;
14883 image_create_info.mipLevels = 1;
14884 image_create_info.arrayLayers = 1;
14885 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14886 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
14887 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
14888 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
14889 image_create_info.flags = 0;
14890
14891 VkImage nullImg;
14892 VkImageFormatProperties imgFmtProps;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014893 vkGetPhysicalDeviceImageFormatProperties(gpu(), image_create_info.format, image_create_info.imageType, image_create_info.tiling,
14894 image_create_info.usage, image_create_info.flags, &imgFmtProps);
Tony Barbourd6673642016-05-05 14:46:39 -060014895 image_create_info.extent.depth = imgFmtProps.maxExtent.depth + 1;
14896 // Expect INVALID_FORMAT_LIMITS_VIOLATION
14897 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
14898 m_errorMonitor->VerifyFound();
14899 image_create_info.extent.depth = 1;
14900
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014901 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "exceeds allowable maximum supported by format of");
Tony Barbourd6673642016-05-05 14:46:39 -060014902 image_create_info.mipLevels = imgFmtProps.maxMipLevels + 1;
14903 // Expect INVALID_FORMAT_LIMITS_VIOLATION
14904 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
14905 m_errorMonitor->VerifyFound();
14906 image_create_info.mipLevels = 1;
14907
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014908 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "exceeds allowable maximum supported by format of");
Tony Barbourd6673642016-05-05 14:46:39 -060014909 image_create_info.arrayLayers = imgFmtProps.maxArrayLayers + 1;
14910 // Expect INVALID_FORMAT_LIMITS_VIOLATION
14911 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
14912 m_errorMonitor->VerifyFound();
14913 image_create_info.arrayLayers = 1;
14914
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014915 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is not supported by format");
Tony Barbourd6673642016-05-05 14:46:39 -060014916 int samples = imgFmtProps.sampleCounts >> 1;
14917 image_create_info.samples = (VkSampleCountFlagBits)samples;
14918 // Expect INVALID_FORMAT_LIMITS_VIOLATION
14919 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
14920 m_errorMonitor->VerifyFound();
14921 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14922
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014923 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "pCreateInfo->initialLayout, must be "
14924 "VK_IMAGE_LAYOUT_UNDEFINED or "
14925 "VK_IMAGE_LAYOUT_PREINITIALIZED");
Tony Barbourd6673642016-05-05 14:46:39 -060014926 image_create_info.initialLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
14927 // Expect INVALID_LAYOUT
14928 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
14929 m_errorMonitor->VerifyFound();
14930 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
14931}
14932
Mark Lobodzinskicea14992016-10-14 10:59:42 -060014933TEST_F(VkLayerTest, CopyImageSrcSizeExceeded) {
14934
14935 // Image copy with source region specified greater than src image size
Mark Lobodzinski629d47b2016-10-18 13:34:58 -060014936 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01175);
Mark Lobodzinskicea14992016-10-14 10:59:42 -060014937
14938 ASSERT_NO_FATAL_FAILURE(InitState());
14939
14940 VkImageObj src_image(m_device);
14941 src_image.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_LINEAR, 0);
14942 VkImageObj dst_image(m_device);
14943 dst_image.init(64, 64, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
14944
Tony Barbour552f6c02016-12-21 14:34:07 -070014945 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060014946 VkImageCopy copy_region;
14947 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14948 copy_region.srcSubresource.mipLevel = 0;
14949 copy_region.srcSubresource.baseArrayLayer = 0;
14950 copy_region.srcSubresource.layerCount = 0;
14951 copy_region.srcOffset.x = 0;
14952 copy_region.srcOffset.y = 0;
14953 copy_region.srcOffset.z = 0;
14954 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14955 copy_region.dstSubresource.mipLevel = 0;
14956 copy_region.dstSubresource.baseArrayLayer = 0;
14957 copy_region.dstSubresource.layerCount = 0;
14958 copy_region.dstOffset.x = 0;
14959 copy_region.dstOffset.y = 0;
14960 copy_region.dstOffset.z = 0;
14961 copy_region.extent.width = 64;
14962 copy_region.extent.height = 64;
14963 copy_region.extent.depth = 1;
14964 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
14965 &copy_region);
Tony Barbour552f6c02016-12-21 14:34:07 -070014966 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060014967
14968 m_errorMonitor->VerifyFound();
14969}
14970
14971TEST_F(VkLayerTest, CopyImageDstSizeExceeded) {
14972
14973 // Image copy with dest region specified greater than dest image size
Mark Lobodzinski629d47b2016-10-18 13:34:58 -060014974 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01176);
Mark Lobodzinskicea14992016-10-14 10:59:42 -060014975
14976 ASSERT_NO_FATAL_FAILURE(InitState());
14977
14978 VkImageObj src_image(m_device);
14979 src_image.init(64, 64, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_LINEAR, 0);
14980 VkImageObj dst_image(m_device);
14981 dst_image.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
14982
Tony Barbour552f6c02016-12-21 14:34:07 -070014983 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060014984 VkImageCopy copy_region;
14985 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14986 copy_region.srcSubresource.mipLevel = 0;
14987 copy_region.srcSubresource.baseArrayLayer = 0;
14988 copy_region.srcSubresource.layerCount = 0;
14989 copy_region.srcOffset.x = 0;
14990 copy_region.srcOffset.y = 0;
14991 copy_region.srcOffset.z = 0;
14992 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14993 copy_region.dstSubresource.mipLevel = 0;
14994 copy_region.dstSubresource.baseArrayLayer = 0;
14995 copy_region.dstSubresource.layerCount = 0;
14996 copy_region.dstOffset.x = 0;
14997 copy_region.dstOffset.y = 0;
14998 copy_region.dstOffset.z = 0;
14999 copy_region.extent.width = 64;
15000 copy_region.extent.height = 64;
15001 copy_region.extent.depth = 1;
15002 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
15003 &copy_region);
Tony Barbour552f6c02016-12-21 14:34:07 -070015004 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060015005
15006 m_errorMonitor->VerifyFound();
15007}
15008
Karl Schultz6addd812016-02-02 17:17:23 -070015009TEST_F(VkLayerTest, CopyImageFormatSizeMismatch) {
Karl Schultzbdb75952016-04-19 11:36:49 -060015010 VkResult err;
15011 bool pass;
15012
15013 // Create color images with different format sizes and try to copy between them
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070015014 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01184);
Karl Schultzbdb75952016-04-19 11:36:49 -060015015
15016 ASSERT_NO_FATAL_FAILURE(InitState());
15017
15018 // Create two images of different types and try to copy between them
15019 VkImage srcImage;
15020 VkImage dstImage;
15021 VkDeviceMemory srcMem;
15022 VkDeviceMemory destMem;
15023 VkMemoryRequirements memReqs;
15024
15025 VkImageCreateInfo image_create_info = {};
15026 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15027 image_create_info.pNext = NULL;
15028 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15029 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
15030 image_create_info.extent.width = 32;
15031 image_create_info.extent.height = 32;
15032 image_create_info.extent.depth = 1;
15033 image_create_info.mipLevels = 1;
15034 image_create_info.arrayLayers = 1;
15035 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15036 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15037 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
15038 image_create_info.flags = 0;
15039
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015040 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Karl Schultzbdb75952016-04-19 11:36:49 -060015041 ASSERT_VK_SUCCESS(err);
15042
15043 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
15044 // Introduce failure by creating second image with a different-sized format.
15045 image_create_info.format = VK_FORMAT_R5G5B5A1_UNORM_PACK16;
15046
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015047 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Karl Schultzbdb75952016-04-19 11:36:49 -060015048 ASSERT_VK_SUCCESS(err);
15049
15050 // Allocate memory
15051 VkMemoryAllocateInfo memAlloc = {};
15052 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15053 memAlloc.pNext = NULL;
15054 memAlloc.allocationSize = 0;
15055 memAlloc.memoryTypeIndex = 0;
15056
15057 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
15058 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015059 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -060015060 ASSERT_TRUE(pass);
15061 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
15062 ASSERT_VK_SUCCESS(err);
15063
15064 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
15065 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015066 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -060015067 ASSERT_TRUE(pass);
15068 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
15069 ASSERT_VK_SUCCESS(err);
15070
15071 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
15072 ASSERT_VK_SUCCESS(err);
15073 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
15074 ASSERT_VK_SUCCESS(err);
15075
Tony Barbour552f6c02016-12-21 14:34:07 -070015076 m_commandBuffer->BeginCommandBuffer();
Karl Schultzbdb75952016-04-19 11:36:49 -060015077 VkImageCopy copyRegion;
15078 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15079 copyRegion.srcSubresource.mipLevel = 0;
15080 copyRegion.srcSubresource.baseArrayLayer = 0;
15081 copyRegion.srcSubresource.layerCount = 0;
15082 copyRegion.srcOffset.x = 0;
15083 copyRegion.srcOffset.y = 0;
15084 copyRegion.srcOffset.z = 0;
15085 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15086 copyRegion.dstSubresource.mipLevel = 0;
15087 copyRegion.dstSubresource.baseArrayLayer = 0;
15088 copyRegion.dstSubresource.layerCount = 0;
15089 copyRegion.dstOffset.x = 0;
15090 copyRegion.dstOffset.y = 0;
15091 copyRegion.dstOffset.z = 0;
15092 copyRegion.extent.width = 1;
15093 copyRegion.extent.height = 1;
15094 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015095 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070015096 m_commandBuffer->EndCommandBuffer();
Karl Schultzbdb75952016-04-19 11:36:49 -060015097
15098 m_errorMonitor->VerifyFound();
15099
15100 vkDestroyImage(m_device->device(), srcImage, NULL);
15101 vkDestroyImage(m_device->device(), dstImage, NULL);
15102 vkFreeMemory(m_device->device(), srcMem, NULL);
15103 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060015104}
15105
Karl Schultz6addd812016-02-02 17:17:23 -070015106TEST_F(VkLayerTest, CopyImageDepthStencilFormatMismatch) {
15107 VkResult err;
15108 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060015109
Mark Lobodzinskidb117632016-03-31 10:45:56 -060015110 // Create a color image and a depth/stencil image and try to copy between them
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015111 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15112 "vkCmdCopyImage called with unmatched source and dest image depth");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015113
Mike Stroyana3082432015-09-25 13:39:21 -060015114 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060015115
15116 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070015117 VkImage srcImage;
15118 VkImage dstImage;
15119 VkDeviceMemory srcMem;
15120 VkDeviceMemory destMem;
15121 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060015122
15123 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015124 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15125 image_create_info.pNext = NULL;
15126 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15127 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
15128 image_create_info.extent.width = 32;
15129 image_create_info.extent.height = 32;
15130 image_create_info.extent.depth = 1;
15131 image_create_info.mipLevels = 1;
15132 image_create_info.arrayLayers = 1;
15133 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15134 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15135 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
15136 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015137
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015138 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015139 ASSERT_VK_SUCCESS(err);
15140
Karl Schultzbdb75952016-04-19 11:36:49 -060015141 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
15142
Mark Lobodzinskidb117632016-03-31 10:45:56 -060015143 // Introduce failure by creating second image with a depth/stencil format
Karl Schultz6addd812016-02-02 17:17:23 -070015144 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060015145 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
Mark Lobodzinski867787a2016-10-14 11:49:55 -060015146 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015147
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015148 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015149 ASSERT_VK_SUCCESS(err);
15150
15151 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015152 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015153 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15154 memAlloc.pNext = NULL;
15155 memAlloc.allocationSize = 0;
15156 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015157
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060015158 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015159 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015160 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015161 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015162 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015163 ASSERT_VK_SUCCESS(err);
15164
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015165 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015166 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015167 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015168 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015169 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015170 ASSERT_VK_SUCCESS(err);
15171
15172 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
15173 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015174 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060015175 ASSERT_VK_SUCCESS(err);
15176
Tony Barbour552f6c02016-12-21 14:34:07 -070015177 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060015178 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015179 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015180 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060015181 copyRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015182 copyRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015183 copyRegion.srcOffset.x = 0;
15184 copyRegion.srcOffset.y = 0;
15185 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015186 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015187 copyRegion.dstSubresource.mipLevel = 0;
15188 copyRegion.dstSubresource.baseArrayLayer = 0;
15189 copyRegion.dstSubresource.layerCount = 0;
15190 copyRegion.dstOffset.x = 0;
15191 copyRegion.dstOffset.y = 0;
15192 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015193 copyRegion.extent.width = 1;
15194 copyRegion.extent.height = 1;
15195 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015196 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070015197 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060015198
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015199 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060015200
Chia-I Wuf7458c52015-10-26 21:10:41 +080015201 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015202 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080015203 vkFreeMemory(m_device->device(), srcMem, NULL);
15204 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060015205}
15206
Karl Schultz6addd812016-02-02 17:17:23 -070015207TEST_F(VkLayerTest, ResolveImageLowSampleCount) {
15208 VkResult err;
15209 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060015210
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015211 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15212 "vkCmdResolveImage called with source sample count less than 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015213
Mike Stroyana3082432015-09-25 13:39:21 -060015214 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060015215
15216 // Create two images of sample count 1 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070015217 VkImage srcImage;
15218 VkImage dstImage;
15219 VkDeviceMemory srcMem;
15220 VkDeviceMemory destMem;
15221 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060015222
15223 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015224 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15225 image_create_info.pNext = NULL;
15226 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15227 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
15228 image_create_info.extent.width = 32;
15229 image_create_info.extent.height = 1;
15230 image_create_info.extent.depth = 1;
15231 image_create_info.mipLevels = 1;
15232 image_create_info.arrayLayers = 1;
15233 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15234 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15235 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
15236 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015237
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015238 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015239 ASSERT_VK_SUCCESS(err);
15240
Karl Schultz6addd812016-02-02 17:17:23 -070015241 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015242
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015243 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015244 ASSERT_VK_SUCCESS(err);
15245
15246 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015247 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015248 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15249 memAlloc.pNext = NULL;
15250 memAlloc.allocationSize = 0;
15251 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015252
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060015253 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015254 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015255 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015256 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015257 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015258 ASSERT_VK_SUCCESS(err);
15259
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015260 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015261 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015262 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015263 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015264 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015265 ASSERT_VK_SUCCESS(err);
15266
15267 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
15268 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015269 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060015270 ASSERT_VK_SUCCESS(err);
15271
Tony Barbour552f6c02016-12-21 14:34:07 -070015272 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060015273 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070015274 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
15275 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060015276 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015277 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015278 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060015279 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130015280 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060015281 resolveRegion.srcOffset.x = 0;
15282 resolveRegion.srcOffset.y = 0;
15283 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015284 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015285 resolveRegion.dstSubresource.mipLevel = 0;
15286 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130015287 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015288 resolveRegion.dstOffset.x = 0;
15289 resolveRegion.dstOffset.y = 0;
15290 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015291 resolveRegion.extent.width = 1;
15292 resolveRegion.extent.height = 1;
15293 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015294 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070015295 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060015296
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015297 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060015298
Chia-I Wuf7458c52015-10-26 21:10:41 +080015299 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015300 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080015301 vkFreeMemory(m_device->device(), srcMem, NULL);
15302 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060015303}
15304
Karl Schultz6addd812016-02-02 17:17:23 -070015305TEST_F(VkLayerTest, ResolveImageHighSampleCount) {
15306 VkResult err;
15307 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060015308
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015309 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15310 "vkCmdResolveImage called with dest sample count greater than 1.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015311
Mike Stroyana3082432015-09-25 13:39:21 -060015312 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060015313
Chris Forbesa7530692016-05-08 12:35:39 +120015314 // Create two images of sample count 4 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070015315 VkImage srcImage;
15316 VkImage dstImage;
15317 VkDeviceMemory srcMem;
15318 VkDeviceMemory destMem;
15319 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060015320
15321 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015322 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15323 image_create_info.pNext = NULL;
15324 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15325 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
15326 image_create_info.extent.width = 32;
15327 image_create_info.extent.height = 1;
15328 image_create_info.extent.depth = 1;
15329 image_create_info.mipLevels = 1;
15330 image_create_info.arrayLayers = 1;
Chris Forbesa7530692016-05-08 12:35:39 +120015331 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070015332 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15333 // Note: Some implementations expect color attachment usage for any
15334 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015335 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070015336 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015337
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015338 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015339 ASSERT_VK_SUCCESS(err);
15340
Karl Schultz6addd812016-02-02 17:17:23 -070015341 // Note: Some implementations expect color attachment usage for any
15342 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015343 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015344
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015345 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015346 ASSERT_VK_SUCCESS(err);
15347
15348 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015349 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015350 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15351 memAlloc.pNext = NULL;
15352 memAlloc.allocationSize = 0;
15353 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015354
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060015355 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015356 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015357 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015358 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015359 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015360 ASSERT_VK_SUCCESS(err);
15361
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015362 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015363 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015364 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015365 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015366 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015367 ASSERT_VK_SUCCESS(err);
15368
15369 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
15370 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015371 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060015372 ASSERT_VK_SUCCESS(err);
15373
Tony Barbour552f6c02016-12-21 14:34:07 -070015374 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060015375 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070015376 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
15377 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060015378 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015379 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015380 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060015381 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130015382 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060015383 resolveRegion.srcOffset.x = 0;
15384 resolveRegion.srcOffset.y = 0;
15385 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015386 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015387 resolveRegion.dstSubresource.mipLevel = 0;
15388 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130015389 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015390 resolveRegion.dstOffset.x = 0;
15391 resolveRegion.dstOffset.y = 0;
15392 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015393 resolveRegion.extent.width = 1;
15394 resolveRegion.extent.height = 1;
15395 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015396 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070015397 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060015398
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015399 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060015400
Chia-I Wuf7458c52015-10-26 21:10:41 +080015401 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015402 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080015403 vkFreeMemory(m_device->device(), srcMem, NULL);
15404 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060015405}
15406
Karl Schultz6addd812016-02-02 17:17:23 -070015407TEST_F(VkLayerTest, ResolveImageFormatMismatch) {
15408 VkResult err;
15409 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060015410
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015411 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15412 "vkCmdResolveImage called with unmatched source and dest formats.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015413
Mike Stroyana3082432015-09-25 13:39:21 -060015414 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060015415
15416 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070015417 VkImage srcImage;
15418 VkImage dstImage;
15419 VkDeviceMemory srcMem;
15420 VkDeviceMemory destMem;
15421 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060015422
15423 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015424 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15425 image_create_info.pNext = NULL;
15426 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15427 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
15428 image_create_info.extent.width = 32;
15429 image_create_info.extent.height = 1;
15430 image_create_info.extent.depth = 1;
15431 image_create_info.mipLevels = 1;
15432 image_create_info.arrayLayers = 1;
15433 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
15434 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15435 // Note: Some implementations expect color attachment usage for any
15436 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015437 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070015438 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015439
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015440 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015441 ASSERT_VK_SUCCESS(err);
15442
Karl Schultz6addd812016-02-02 17:17:23 -070015443 // Set format to something other than source image
15444 image_create_info.format = VK_FORMAT_R32_SFLOAT;
15445 // Note: Some implementations expect color attachment usage for any
15446 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015447 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070015448 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015449
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015450 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015451 ASSERT_VK_SUCCESS(err);
15452
15453 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015454 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015455 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15456 memAlloc.pNext = NULL;
15457 memAlloc.allocationSize = 0;
15458 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015459
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060015460 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015461 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015462 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015463 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015464 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015465 ASSERT_VK_SUCCESS(err);
15466
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015467 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015468 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015469 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015470 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015471 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015472 ASSERT_VK_SUCCESS(err);
15473
15474 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
15475 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015476 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060015477 ASSERT_VK_SUCCESS(err);
15478
Tony Barbour552f6c02016-12-21 14:34:07 -070015479 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060015480 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070015481 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
15482 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060015483 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015484 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015485 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060015486 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130015487 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060015488 resolveRegion.srcOffset.x = 0;
15489 resolveRegion.srcOffset.y = 0;
15490 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015491 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015492 resolveRegion.dstSubresource.mipLevel = 0;
15493 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130015494 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015495 resolveRegion.dstOffset.x = 0;
15496 resolveRegion.dstOffset.y = 0;
15497 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015498 resolveRegion.extent.width = 1;
15499 resolveRegion.extent.height = 1;
15500 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015501 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070015502 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060015503
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015504 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060015505
Chia-I Wuf7458c52015-10-26 21:10:41 +080015506 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015507 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080015508 vkFreeMemory(m_device->device(), srcMem, NULL);
15509 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060015510}
15511
Karl Schultz6addd812016-02-02 17:17:23 -070015512TEST_F(VkLayerTest, ResolveImageTypeMismatch) {
15513 VkResult err;
15514 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060015515
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015516 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15517 "vkCmdResolveImage called with unmatched source and dest image types.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015518
Mike Stroyana3082432015-09-25 13:39:21 -060015519 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060015520
15521 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070015522 VkImage srcImage;
15523 VkImage dstImage;
15524 VkDeviceMemory srcMem;
15525 VkDeviceMemory destMem;
15526 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060015527
15528 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015529 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15530 image_create_info.pNext = NULL;
15531 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15532 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
15533 image_create_info.extent.width = 32;
15534 image_create_info.extent.height = 1;
15535 image_create_info.extent.depth = 1;
15536 image_create_info.mipLevels = 1;
15537 image_create_info.arrayLayers = 1;
15538 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
15539 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15540 // Note: Some implementations expect color attachment usage for any
15541 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015542 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070015543 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015544
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015545 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015546 ASSERT_VK_SUCCESS(err);
15547
Karl Schultz6addd812016-02-02 17:17:23 -070015548 image_create_info.imageType = VK_IMAGE_TYPE_1D;
15549 // Note: Some implementations expect color attachment usage for any
15550 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015551 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070015552 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015553
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015554 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015555 ASSERT_VK_SUCCESS(err);
15556
15557 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015558 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015559 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15560 memAlloc.pNext = NULL;
15561 memAlloc.allocationSize = 0;
15562 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015563
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060015564 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015565 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015566 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015567 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015568 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015569 ASSERT_VK_SUCCESS(err);
15570
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015571 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015572 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015573 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015574 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015575 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015576 ASSERT_VK_SUCCESS(err);
15577
15578 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
15579 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015580 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060015581 ASSERT_VK_SUCCESS(err);
15582
Tony Barbour552f6c02016-12-21 14:34:07 -070015583 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060015584 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070015585 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
15586 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060015587 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015588 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015589 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060015590 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130015591 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060015592 resolveRegion.srcOffset.x = 0;
15593 resolveRegion.srcOffset.y = 0;
15594 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015595 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015596 resolveRegion.dstSubresource.mipLevel = 0;
15597 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130015598 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015599 resolveRegion.dstOffset.x = 0;
15600 resolveRegion.dstOffset.y = 0;
15601 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015602 resolveRegion.extent.width = 1;
15603 resolveRegion.extent.height = 1;
15604 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015605 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070015606 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060015607
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015608 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060015609
Chia-I Wuf7458c52015-10-26 21:10:41 +080015610 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015611 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080015612 vkFreeMemory(m_device->device(), srcMem, NULL);
15613 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060015614}
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015615
Karl Schultz6addd812016-02-02 17:17:23 -070015616TEST_F(VkLayerTest, DepthStencilImageViewWithColorAspectBitError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015617 // Create a single Image descriptor and cause it to first hit an error due
Karl Schultz6addd812016-02-02 17:17:23 -070015618 // to using a DS format, then cause it to hit error due to COLOR_BIT not
15619 // set in aspect
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015620 // The image format check comes 2nd in validation so we trigger it first,
15621 // then when we cause aspect fail next, bad format check will be preempted
Karl Schultz6addd812016-02-02 17:17:23 -070015622 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015623
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015624 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15625 "Combination depth/stencil image formats can have only the ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015626
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015627 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015628
Chia-I Wu1b99bb22015-10-27 19:25:11 +080015629 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015630 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
15631 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015632
15633 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015634 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
15635 ds_pool_ci.pNext = NULL;
15636 ds_pool_ci.maxSets = 1;
15637 ds_pool_ci.poolSizeCount = 1;
15638 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015639
15640 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015641 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015642 ASSERT_VK_SUCCESS(err);
15643
15644 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015645 dsl_binding.binding = 0;
15646 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
15647 dsl_binding.descriptorCount = 1;
15648 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
15649 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015650
15651 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015652 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
15653 ds_layout_ci.pNext = NULL;
15654 ds_layout_ci.bindingCount = 1;
15655 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015656 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015657 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015658 ASSERT_VK_SUCCESS(err);
15659
15660 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015661 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080015662 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070015663 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015664 alloc_info.descriptorPool = ds_pool;
15665 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015666 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015667 ASSERT_VK_SUCCESS(err);
15668
Karl Schultz6addd812016-02-02 17:17:23 -070015669 VkImage image_bad;
15670 VkImage image_good;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015671 // One bad format and one good format for Color attachment
Tobin Ehlis269f0322016-05-25 16:24:21 -060015672 const VkFormat tex_format_bad = VK_FORMAT_D24_UNORM_S8_UINT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015673 const VkFormat tex_format_good = VK_FORMAT_B8G8R8A8_UNORM;
Karl Schultz6addd812016-02-02 17:17:23 -070015674 const int32_t tex_width = 32;
15675 const int32_t tex_height = 32;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015676
15677 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015678 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15679 image_create_info.pNext = NULL;
15680 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15681 image_create_info.format = tex_format_bad;
15682 image_create_info.extent.width = tex_width;
15683 image_create_info.extent.height = tex_height;
15684 image_create_info.extent.depth = 1;
15685 image_create_info.mipLevels = 1;
15686 image_create_info.arrayLayers = 1;
15687 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15688 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015689 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070015690 image_create_info.flags = 0;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015691
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015692 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_bad);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015693 ASSERT_VK_SUCCESS(err);
15694 image_create_info.format = tex_format_good;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015695 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
15696 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_good);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015697 ASSERT_VK_SUCCESS(err);
15698
Rene Lindsayf1e89c82016-12-28 13:18:31 -070015699 // ---Bind image memory---
15700 VkMemoryRequirements img_mem_reqs;
15701 vkGetImageMemoryRequirements(m_device->device(), image_bad, &img_mem_reqs);
15702 VkMemoryAllocateInfo image_alloc_info = {};
15703 image_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15704 image_alloc_info.pNext = NULL;
15705 image_alloc_info.memoryTypeIndex = 0;
15706 image_alloc_info.allocationSize = img_mem_reqs.size;
15707 bool pass = m_device->phy().set_memory_type(img_mem_reqs.memoryTypeBits, &image_alloc_info, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
15708 ASSERT_TRUE(pass);
15709 VkDeviceMemory mem;
15710 err = vkAllocateMemory(m_device->device(), &image_alloc_info, NULL, &mem);
15711 ASSERT_VK_SUCCESS(err);
15712 err = vkBindImageMemory(m_device->device(), image_bad, mem, 0);
15713 ASSERT_VK_SUCCESS(err);
15714 // -----------------------
15715
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015716 VkImageViewCreateInfo image_view_create_info = {};
Chris Forbes53bef902016-11-28 17:53:04 +130015717 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070015718 image_view_create_info.image = image_bad;
15719 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
15720 image_view_create_info.format = tex_format_bad;
15721 image_view_create_info.subresourceRange.baseArrayLayer = 0;
15722 image_view_create_info.subresourceRange.baseMipLevel = 0;
15723 image_view_create_info.subresourceRange.layerCount = 1;
15724 image_view_create_info.subresourceRange.levelCount = 1;
Rene Lindsayf1e89c82016-12-28 13:18:31 -070015725 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_DEPTH_BIT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015726
15727 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015728 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015729
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015730 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015731
Chia-I Wuf7458c52015-10-26 21:10:41 +080015732 vkDestroyImage(m_device->device(), image_bad, NULL);
15733 vkDestroyImage(m_device->device(), image_good, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080015734 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
15735 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Rene Lindsayf1e89c82016-12-28 13:18:31 -070015736
15737 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015738}
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015739
15740TEST_F(VkLayerTest, ClearImageErrors) {
15741 TEST_DESCRIPTION("Call ClearColorImage w/ a depth|stencil image and "
15742 "ClearDepthStencilImage with a color image.");
15743
15744 ASSERT_NO_FATAL_FAILURE(InitState());
15745 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15746
Tony Barbour552f6c02016-12-21 14:34:07 -070015747 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015748
15749 // Color image
15750 VkClearColorValue clear_color;
15751 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
15752 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
15753 const VkFormat color_format = VK_FORMAT_B8G8R8A8_UNORM;
15754 const int32_t img_width = 32;
15755 const int32_t img_height = 32;
15756 VkImageCreateInfo image_create_info = {};
15757 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15758 image_create_info.pNext = NULL;
15759 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15760 image_create_info.format = color_format;
15761 image_create_info.extent.width = img_width;
15762 image_create_info.extent.height = img_height;
15763 image_create_info.extent.depth = 1;
15764 image_create_info.mipLevels = 1;
15765 image_create_info.arrayLayers = 1;
15766 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15767 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15768 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
15769
15770 vk_testing::Image color_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015771 color_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015772
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015773 const VkImageSubresourceRange color_range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015774
15775 // Depth/Stencil image
15776 VkClearDepthStencilValue clear_value = {0};
15777 reqs = 0; // don't need HOST_VISIBLE DS image
15778 VkImageCreateInfo ds_image_create_info = vk_testing::Image::create_info();
15779 ds_image_create_info.imageType = VK_IMAGE_TYPE_2D;
15780 ds_image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
15781 ds_image_create_info.extent.width = 64;
15782 ds_image_create_info.extent.height = 64;
15783 ds_image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Rene Lindsaya1fc64a2016-12-27 15:18:54 -070015784 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 -060015785
15786 vk_testing::Image ds_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015787 ds_image.init(*m_device, (const VkImageCreateInfo &)ds_image_create_info, reqs);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015788
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015789 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 -060015790
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015791 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdClearColorImage called with depth/stencil image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015792
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015793 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), ds_image.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015794 &color_range);
15795
15796 m_errorMonitor->VerifyFound();
15797
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015798 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdClearColorImage called with "
15799 "image created without "
15800 "VK_IMAGE_USAGE_TRANSFER_DST_BIT");
Tony Barbour26434b92016-06-02 09:43:50 -060015801
Rene Lindsaya1fc64a2016-12-27 15:18:54 -070015802 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), color_image.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
Tony Barbour26434b92016-06-02 09:43:50 -060015803 &color_range);
15804
15805 m_errorMonitor->VerifyFound();
15806
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015807 // Call CmdClearDepthStencilImage with color image
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015808 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15809 "vkCmdClearDepthStencilImage called without a depth/stencil image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015810
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015811 vkCmdClearDepthStencilImage(m_commandBuffer->GetBufferHandle(), color_image.handle(),
Rene Lindsaya1fc64a2016-12-27 15:18:54 -070015812 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, &clear_value, 1, &ds_range);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015813
15814 m_errorMonitor->VerifyFound();
15815}
Tobin Ehliscde08892015-09-22 10:11:37 -060015816#endif // IMAGE_TESTS
15817
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060015818
15819// WSI Enabled Tests
15820//
Chris Forbes09368e42016-10-13 11:59:22 +130015821#if 0
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060015822TEST_F(VkWsiEnabledLayerTest, TestEnabledWsi) {
15823
15824#if defined(VK_USE_PLATFORM_XCB_KHR)
15825 VkSurfaceKHR surface = VK_NULL_HANDLE;
15826
15827 VkResult err;
15828 bool pass;
15829 VkSwapchainKHR swapchain = VK_NULL_HANDLE;
15830 VkSwapchainCreateInfoKHR swapchain_create_info = {};
15831 // uint32_t swapchain_image_count = 0;
15832 // VkImage swapchain_images[1] = {VK_NULL_HANDLE};
15833 // uint32_t image_index = 0;
15834 // VkPresentInfoKHR present_info = {};
15835
15836 ASSERT_NO_FATAL_FAILURE(InitState());
15837
15838 // Use the create function from one of the VK_KHR_*_surface extension in
15839 // order to create a surface, testing all known errors in the process,
15840 // before successfully creating a surface:
15841 // First, try to create a surface without a VkXcbSurfaceCreateInfoKHR:
15842 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pCreateInfo specified as NULL");
15843 err = vkCreateXcbSurfaceKHR(instance(), NULL, NULL, &surface);
15844 pass = (err != VK_SUCCESS);
15845 ASSERT_TRUE(pass);
15846 m_errorMonitor->VerifyFound();
15847
15848 // Next, try to create a surface with the wrong
15849 // VkXcbSurfaceCreateInfoKHR::sType:
15850 VkXcbSurfaceCreateInfoKHR xcb_create_info = {};
15851 xcb_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
15852 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pCreateInfo->sType must be");
15853 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
15854 pass = (err != VK_SUCCESS);
15855 ASSERT_TRUE(pass);
15856 m_errorMonitor->VerifyFound();
15857
15858 // Create a native window, and then correctly create a surface:
15859 xcb_connection_t *connection;
15860 xcb_screen_t *screen;
15861 xcb_window_t xcb_window;
15862 xcb_intern_atom_reply_t *atom_wm_delete_window;
15863
15864 const xcb_setup_t *setup;
15865 xcb_screen_iterator_t iter;
15866 int scr;
15867 uint32_t value_mask, value_list[32];
15868 int width = 1;
15869 int height = 1;
15870
15871 connection = xcb_connect(NULL, &scr);
15872 ASSERT_TRUE(connection != NULL);
15873 setup = xcb_get_setup(connection);
15874 iter = xcb_setup_roots_iterator(setup);
15875 while (scr-- > 0)
15876 xcb_screen_next(&iter);
15877 screen = iter.data;
15878
15879 xcb_window = xcb_generate_id(connection);
15880
15881 value_mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK;
15882 value_list[0] = screen->black_pixel;
15883 value_list[1] = XCB_EVENT_MASK_KEY_RELEASE | XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_STRUCTURE_NOTIFY;
15884
15885 xcb_create_window(connection, XCB_COPY_FROM_PARENT, xcb_window, screen->root, 0, 0, width, height, 0,
15886 XCB_WINDOW_CLASS_INPUT_OUTPUT, screen->root_visual, value_mask, value_list);
15887
15888 /* Magic code that will send notification when window is destroyed */
15889 xcb_intern_atom_cookie_t cookie = xcb_intern_atom(connection, 1, 12, "WM_PROTOCOLS");
15890 xcb_intern_atom_reply_t *reply = xcb_intern_atom_reply(connection, cookie, 0);
15891
15892 xcb_intern_atom_cookie_t cookie2 = xcb_intern_atom(connection, 0, 16, "WM_DELETE_WINDOW");
15893 atom_wm_delete_window = xcb_intern_atom_reply(connection, cookie2, 0);
15894 xcb_change_property(connection, XCB_PROP_MODE_REPLACE, xcb_window, (*reply).atom, 4, 32, 1, &(*atom_wm_delete_window).atom);
15895 free(reply);
15896
15897 xcb_map_window(connection, xcb_window);
15898
15899 // Force the x/y coordinates to 100,100 results are identical in consecutive
15900 // runs
15901 const uint32_t coords[] = { 100, 100 };
15902 xcb_configure_window(connection, xcb_window, XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y, coords);
15903
15904 // Finally, try to correctly create a surface:
15905 xcb_create_info.sType = VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR;
15906 xcb_create_info.pNext = NULL;
15907 xcb_create_info.flags = 0;
15908 xcb_create_info.connection = connection;
15909 xcb_create_info.window = xcb_window;
15910 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
15911 pass = (err == VK_SUCCESS);
15912 ASSERT_TRUE(pass);
15913
15914 // Check if surface supports presentation:
15915
15916 // 1st, do so without having queried the queue families:
15917 VkBool32 supported = false;
15918 // TODO: Get the following error to come out:
15919 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15920 "called before calling the vkGetPhysicalDeviceQueueFamilyProperties "
15921 "function");
15922 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
15923 pass = (err != VK_SUCCESS);
15924 // ASSERT_TRUE(pass);
15925 // m_errorMonitor->VerifyFound();
15926
15927 // Next, query a queue family index that's too large:
15928 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with a queueFamilyIndex that is too large");
15929 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 100000, surface, &supported);
15930 pass = (err != VK_SUCCESS);
15931 ASSERT_TRUE(pass);
15932 m_errorMonitor->VerifyFound();
15933
15934 // Finally, do so correctly:
15935 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
15936 // SUPPORTED
15937 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
15938 pass = (err == VK_SUCCESS);
15939 ASSERT_TRUE(pass);
15940
15941 // Before proceeding, try to create a swapchain without having called
15942 // vkGetPhysicalDeviceSurfaceCapabilitiesKHR():
15943 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
15944 swapchain_create_info.pNext = NULL;
15945 swapchain_create_info.flags = 0;
15946 swapchain_create_info.imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
15947 swapchain_create_info.surface = surface;
15948 swapchain_create_info.imageArrayLayers = 1;
15949 swapchain_create_info.preTransform = VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR;
15950 swapchain_create_info.compositeAlpha = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR;
15951 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15952 "called before calling vkGetPhysicalDeviceSurfaceCapabilitiesKHR().");
15953 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
15954 pass = (err != VK_SUCCESS);
15955 ASSERT_TRUE(pass);
15956 m_errorMonitor->VerifyFound();
15957
15958 // Get the surface capabilities:
15959 VkSurfaceCapabilitiesKHR surface_capabilities;
15960
15961 // Do so correctly (only error logged by this entrypoint is if the
15962 // extension isn't enabled):
15963 err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), surface, &surface_capabilities);
15964 pass = (err == VK_SUCCESS);
15965 ASSERT_TRUE(pass);
15966
15967 // Get the surface formats:
15968 uint32_t surface_format_count;
15969
15970 // First, try without a pointer to surface_format_count:
15971 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pSurfaceFormatCount "
15972 "specified as NULL");
15973 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, NULL, NULL);
15974 pass = (err == VK_SUCCESS);
15975 ASSERT_TRUE(pass);
15976 m_errorMonitor->VerifyFound();
15977
15978 // Next, call with a non-NULL pSurfaceFormats, even though we haven't
15979 // correctly done a 1st try (to get the count):
15980 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "but no prior positive value has been seen for");
15981 surface_format_count = 0;
15982 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, (VkSurfaceFormatKHR *)&surface_format_count);
15983 pass = (err == VK_SUCCESS);
15984 ASSERT_TRUE(pass);
15985 m_errorMonitor->VerifyFound();
15986
15987 // Next, correctly do a 1st try (with a NULL pointer to surface_formats):
15988 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, NULL);
15989 pass = (err == VK_SUCCESS);
15990 ASSERT_TRUE(pass);
15991
15992 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
15993 VkSurfaceFormatKHR *surface_formats = (VkSurfaceFormatKHR *)malloc(surface_format_count * sizeof(VkSurfaceFormatKHR));
15994
15995 // Next, do a 2nd try with surface_format_count being set too high:
15996 surface_format_count += 5;
15997 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is greater than the value");
15998 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, surface_formats);
15999 pass = (err == VK_SUCCESS);
16000 ASSERT_TRUE(pass);
16001 m_errorMonitor->VerifyFound();
16002
16003 // Finally, do a correct 1st and 2nd try:
16004 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, NULL);
16005 pass = (err == VK_SUCCESS);
16006 ASSERT_TRUE(pass);
16007 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, surface_formats);
16008 pass = (err == VK_SUCCESS);
16009 ASSERT_TRUE(pass);
16010
16011 // Get the surface present modes:
16012 uint32_t surface_present_mode_count;
16013
16014 // First, try without a pointer to surface_format_count:
16015 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pPresentModeCount "
16016 "specified as NULL");
16017
16018 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, NULL, NULL);
16019 pass = (err == VK_SUCCESS);
16020 ASSERT_TRUE(pass);
16021 m_errorMonitor->VerifyFound();
16022
16023 // Next, call with a non-NULL VkPresentModeKHR, even though we haven't
16024 // correctly done a 1st try (to get the count):
16025 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "but no prior positive value has been seen for");
16026 surface_present_mode_count = 0;
16027 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count,
16028 (VkPresentModeKHR *)&surface_present_mode_count);
16029 pass = (err == VK_SUCCESS);
16030 ASSERT_TRUE(pass);
16031 m_errorMonitor->VerifyFound();
16032
16033 // Next, correctly do a 1st try (with a NULL pointer to surface_formats):
16034 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, NULL);
16035 pass = (err == VK_SUCCESS);
16036 ASSERT_TRUE(pass);
16037
16038 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
16039 VkPresentModeKHR *surface_present_modes = (VkPresentModeKHR *)malloc(surface_present_mode_count * sizeof(VkPresentModeKHR));
16040
16041 // Next, do a 2nd try with surface_format_count being set too high:
16042 surface_present_mode_count += 5;
16043 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is greater than the value");
16044 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, surface_present_modes);
16045 pass = (err == VK_SUCCESS);
16046 ASSERT_TRUE(pass);
16047 m_errorMonitor->VerifyFound();
16048
16049 // Finally, do a correct 1st and 2nd try:
16050 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, NULL);
16051 pass = (err == VK_SUCCESS);
16052 ASSERT_TRUE(pass);
16053 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, surface_present_modes);
16054 pass = (err == VK_SUCCESS);
16055 ASSERT_TRUE(pass);
16056
16057 // Create a swapchain:
16058
16059 // First, try without a pointer to swapchain_create_info:
16060 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pCreateInfo "
16061 "specified as NULL");
16062
16063 err = vkCreateSwapchainKHR(m_device->device(), NULL, NULL, &swapchain);
16064 pass = (err != VK_SUCCESS);
16065 ASSERT_TRUE(pass);
16066 m_errorMonitor->VerifyFound();
16067
16068 // Next, call with a non-NULL swapchain_create_info, that has the wrong
16069 // sType:
16070 swapchain_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
16071 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pCreateInfo->sType must be");
16072
16073 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
16074 pass = (err != VK_SUCCESS);
16075 ASSERT_TRUE(pass);
16076 m_errorMonitor->VerifyFound();
16077
16078 // Next, call with a NULL swapchain pointer:
16079 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
16080 swapchain_create_info.pNext = NULL;
16081 swapchain_create_info.flags = 0;
16082 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pSwapchain "
16083 "specified as NULL");
16084
16085 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, NULL);
16086 pass = (err != VK_SUCCESS);
16087 ASSERT_TRUE(pass);
16088 m_errorMonitor->VerifyFound();
16089
16090 // TODO: Enhance swapchain layer so that
16091 // swapchain_create_info.queueFamilyIndexCount is checked against something?
16092
16093 // Next, call with a queue family index that's too large:
16094 uint32_t queueFamilyIndex[2] = { 100000, 0 };
16095 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
16096 swapchain_create_info.queueFamilyIndexCount = 2;
16097 swapchain_create_info.pQueueFamilyIndices = queueFamilyIndex;
16098 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with a queueFamilyIndex that is too large");
16099 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
16100 pass = (err != VK_SUCCESS);
16101 ASSERT_TRUE(pass);
16102 m_errorMonitor->VerifyFound();
16103
16104 // Next, call a queueFamilyIndexCount that's too small for CONCURRENT:
16105 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
16106 swapchain_create_info.queueFamilyIndexCount = 1;
16107 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16108 "but with a bad value(s) for pCreateInfo->queueFamilyIndexCount or "
16109 "pCreateInfo->pQueueFamilyIndices).");
16110 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
16111 pass = (err != VK_SUCCESS);
16112 ASSERT_TRUE(pass);
16113 m_errorMonitor->VerifyFound();
16114
16115 // Next, call with an invalid imageSharingMode:
16116 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_MAX_ENUM;
16117 swapchain_create_info.queueFamilyIndexCount = 1;
16118 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16119 "called with a non-supported pCreateInfo->imageSharingMode (i.e.");
16120 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
16121 pass = (err != VK_SUCCESS);
16122 ASSERT_TRUE(pass);
16123 m_errorMonitor->VerifyFound();
16124 // Fix for the future:
16125 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
16126 // SUPPORTED
16127 swapchain_create_info.queueFamilyIndexCount = 0;
16128 queueFamilyIndex[0] = 0;
16129 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE;
16130
16131 // TODO: CONTINUE TESTING VALIDATION OF vkCreateSwapchainKHR() ...
16132 // Get the images from a swapchain:
16133 // Acquire an image from a swapchain:
16134 // Present an image to a swapchain:
16135 // Destroy the swapchain:
16136
16137 // TODOs:
16138 //
16139 // - Try destroying the device without first destroying the swapchain
16140 //
16141 // - Try destroying the device without first destroying the surface
16142 //
16143 // - Try destroying the surface without first destroying the swapchain
16144
16145 // Destroy the surface:
16146 vkDestroySurfaceKHR(instance(), surface, NULL);
16147
16148 // Tear down the window:
16149 xcb_destroy_window(connection, xcb_window);
16150 xcb_disconnect(connection);
16151
16152#else // VK_USE_PLATFORM_XCB_KHR
16153 return;
16154#endif // VK_USE_PLATFORM_XCB_KHR
16155}
Chris Forbes09368e42016-10-13 11:59:22 +130016156#endif
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016157
16158//
16159// POSITIVE VALIDATION TESTS
16160//
16161// These tests do not expect to encounter ANY validation errors pass only if this is true
16162
Tobin Ehlise0006882016-11-03 10:14:28 -060016163TEST_F(VkPositiveLayerTest, SecondaryCommandBufferImageLayoutTransitions) {
16164 TEST_DESCRIPTION("Perform an image layout transition in a secondary command buffer followed "
16165 "by a transition in the primary.");
16166 VkResult err;
16167 m_errorMonitor->ExpectSuccess();
16168 ASSERT_NO_FATAL_FAILURE(InitState());
16169 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
16170 // Allocate a secondary and primary cmd buffer
16171 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
16172 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
16173 command_buffer_allocate_info.commandPool = m_commandPool;
16174 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
16175 command_buffer_allocate_info.commandBufferCount = 1;
16176
16177 VkCommandBuffer secondary_command_buffer;
16178 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer));
16179 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
16180 VkCommandBuffer primary_command_buffer;
16181 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &primary_command_buffer));
16182 VkCommandBufferBeginInfo command_buffer_begin_info = {};
16183 VkCommandBufferInheritanceInfo command_buffer_inheritance_info = {};
16184 command_buffer_inheritance_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
16185 command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
16186 command_buffer_begin_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
16187 command_buffer_begin_info.pInheritanceInfo = &command_buffer_inheritance_info;
16188
16189 err = vkBeginCommandBuffer(secondary_command_buffer, &command_buffer_begin_info);
16190 ASSERT_VK_SUCCESS(err);
16191 VkImageObj image(m_device);
16192 image.init(128, 128, VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
16193 ASSERT_TRUE(image.initialized());
16194 VkImageMemoryBarrier img_barrier = {};
16195 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
16196 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
16197 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
16198 img_barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
16199 img_barrier.newLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
16200 img_barrier.image = image.handle();
16201 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
16202 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
16203 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
16204 img_barrier.subresourceRange.baseArrayLayer = 0;
16205 img_barrier.subresourceRange.baseMipLevel = 0;
16206 img_barrier.subresourceRange.layerCount = 1;
16207 img_barrier.subresourceRange.levelCount = 1;
16208 vkCmdPipelineBarrier(secondary_command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr,
16209 0, nullptr, 1, &img_barrier);
16210 err = vkEndCommandBuffer(secondary_command_buffer);
16211 ASSERT_VK_SUCCESS(err);
16212
16213 // Now update primary cmd buffer to execute secondary and transitions image
16214 command_buffer_begin_info.pInheritanceInfo = nullptr;
16215 err = vkBeginCommandBuffer(primary_command_buffer, &command_buffer_begin_info);
16216 ASSERT_VK_SUCCESS(err);
16217 vkCmdExecuteCommands(primary_command_buffer, 1, &secondary_command_buffer);
16218 VkImageMemoryBarrier img_barrier2 = {};
16219 img_barrier2.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
16220 img_barrier2.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
16221 img_barrier2.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
16222 img_barrier2.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
16223 img_barrier2.newLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
16224 img_barrier2.image = image.handle();
16225 img_barrier2.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
16226 img_barrier2.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
16227 img_barrier2.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
16228 img_barrier2.subresourceRange.baseArrayLayer = 0;
16229 img_barrier2.subresourceRange.baseMipLevel = 0;
16230 img_barrier2.subresourceRange.layerCount = 1;
16231 img_barrier2.subresourceRange.levelCount = 1;
16232 vkCmdPipelineBarrier(primary_command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0,
16233 nullptr, 1, &img_barrier2);
16234 err = vkEndCommandBuffer(primary_command_buffer);
16235 ASSERT_VK_SUCCESS(err);
16236 VkSubmitInfo submit_info = {};
16237 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
16238 submit_info.commandBufferCount = 1;
16239 submit_info.pCommandBuffers = &primary_command_buffer;
16240 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
16241 ASSERT_VK_SUCCESS(err);
16242 m_errorMonitor->VerifyNotFound();
16243 err = vkDeviceWaitIdle(m_device->device());
16244 ASSERT_VK_SUCCESS(err);
16245 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &secondary_command_buffer);
16246 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &primary_command_buffer);
16247}
16248
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016249// This is a positive test. No failures are expected.
16250TEST_F(VkPositiveLayerTest, IgnoreUnrelatedDescriptor) {
16251 TEST_DESCRIPTION("Ensure that the vkUpdateDescriptorSets validation code "
16252 "is ignoring VkWriteDescriptorSet members that are not "
16253 "related to the descriptor type specified by "
16254 "VkWriteDescriptorSet::descriptorType. Correct "
16255 "validation behavior will result in the test running to "
16256 "completion without validation errors.");
16257
16258 const uintptr_t invalid_ptr = 0xcdcdcdcd;
16259
16260 ASSERT_NO_FATAL_FAILURE(InitState());
16261
16262 // Image Case
16263 {
16264 m_errorMonitor->ExpectSuccess();
16265
16266 VkImage image;
16267 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
16268 const int32_t tex_width = 32;
16269 const int32_t tex_height = 32;
16270 VkImageCreateInfo image_create_info = {};
16271 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16272 image_create_info.pNext = NULL;
16273 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16274 image_create_info.format = tex_format;
16275 image_create_info.extent.width = tex_width;
16276 image_create_info.extent.height = tex_height;
16277 image_create_info.extent.depth = 1;
16278 image_create_info.mipLevels = 1;
16279 image_create_info.arrayLayers = 1;
16280 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16281 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
16282 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
16283 image_create_info.flags = 0;
16284 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
16285 ASSERT_VK_SUCCESS(err);
16286
16287 VkMemoryRequirements memory_reqs;
16288 VkDeviceMemory image_memory;
16289 bool pass;
16290 VkMemoryAllocateInfo memory_info = {};
16291 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16292 memory_info.pNext = NULL;
16293 memory_info.allocationSize = 0;
16294 memory_info.memoryTypeIndex = 0;
16295 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
16296 memory_info.allocationSize = memory_reqs.size;
16297 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
16298 ASSERT_TRUE(pass);
16299 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
16300 ASSERT_VK_SUCCESS(err);
16301 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
16302 ASSERT_VK_SUCCESS(err);
16303
16304 VkImageViewCreateInfo image_view_create_info = {};
16305 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
16306 image_view_create_info.image = image;
16307 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
16308 image_view_create_info.format = tex_format;
16309 image_view_create_info.subresourceRange.layerCount = 1;
16310 image_view_create_info.subresourceRange.baseMipLevel = 0;
16311 image_view_create_info.subresourceRange.levelCount = 1;
16312 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16313
16314 VkImageView view;
16315 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
16316 ASSERT_VK_SUCCESS(err);
16317
16318 VkDescriptorPoolSize ds_type_count = {};
16319 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
16320 ds_type_count.descriptorCount = 1;
16321
16322 VkDescriptorPoolCreateInfo ds_pool_ci = {};
16323 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
16324 ds_pool_ci.pNext = NULL;
16325 ds_pool_ci.maxSets = 1;
16326 ds_pool_ci.poolSizeCount = 1;
16327 ds_pool_ci.pPoolSizes = &ds_type_count;
16328
16329 VkDescriptorPool ds_pool;
16330 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
16331 ASSERT_VK_SUCCESS(err);
16332
16333 VkDescriptorSetLayoutBinding dsl_binding = {};
16334 dsl_binding.binding = 0;
16335 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
16336 dsl_binding.descriptorCount = 1;
16337 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
16338 dsl_binding.pImmutableSamplers = NULL;
16339
16340 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
16341 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
16342 ds_layout_ci.pNext = NULL;
16343 ds_layout_ci.bindingCount = 1;
16344 ds_layout_ci.pBindings = &dsl_binding;
16345 VkDescriptorSetLayout ds_layout;
16346 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
16347 ASSERT_VK_SUCCESS(err);
16348
16349 VkDescriptorSet descriptor_set;
16350 VkDescriptorSetAllocateInfo alloc_info = {};
16351 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
16352 alloc_info.descriptorSetCount = 1;
16353 alloc_info.descriptorPool = ds_pool;
16354 alloc_info.pSetLayouts = &ds_layout;
16355 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
16356 ASSERT_VK_SUCCESS(err);
16357
16358 VkDescriptorImageInfo image_info = {};
16359 image_info.imageView = view;
16360 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
16361
16362 VkWriteDescriptorSet descriptor_write;
16363 memset(&descriptor_write, 0, sizeof(descriptor_write));
16364 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
16365 descriptor_write.dstSet = descriptor_set;
16366 descriptor_write.dstBinding = 0;
16367 descriptor_write.descriptorCount = 1;
16368 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
16369 descriptor_write.pImageInfo = &image_info;
16370
16371 // Set pBufferInfo and pTexelBufferView to invalid values, which should
16372 // be
16373 // ignored for descriptorType == VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE.
16374 // This will most likely produce a crash if the parameter_validation
16375 // layer
16376 // does not correctly ignore pBufferInfo.
16377 descriptor_write.pBufferInfo = reinterpret_cast<const VkDescriptorBufferInfo *>(invalid_ptr);
16378 descriptor_write.pTexelBufferView = reinterpret_cast<const VkBufferView *>(invalid_ptr);
16379
16380 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
16381
16382 m_errorMonitor->VerifyNotFound();
16383
16384 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
16385 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
16386 vkDestroyImageView(m_device->device(), view, NULL);
16387 vkDestroyImage(m_device->device(), image, NULL);
16388 vkFreeMemory(m_device->device(), image_memory, NULL);
16389 }
16390
16391 // Buffer Case
16392 {
16393 m_errorMonitor->ExpectSuccess();
16394
16395 VkBuffer buffer;
16396 uint32_t queue_family_index = 0;
16397 VkBufferCreateInfo buffer_create_info = {};
16398 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
16399 buffer_create_info.size = 1024;
16400 buffer_create_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
16401 buffer_create_info.queueFamilyIndexCount = 1;
16402 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
16403
16404 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
16405 ASSERT_VK_SUCCESS(err);
16406
16407 VkMemoryRequirements memory_reqs;
16408 VkDeviceMemory buffer_memory;
16409 bool pass;
16410 VkMemoryAllocateInfo memory_info = {};
16411 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16412 memory_info.pNext = NULL;
16413 memory_info.allocationSize = 0;
16414 memory_info.memoryTypeIndex = 0;
16415
16416 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
16417 memory_info.allocationSize = memory_reqs.size;
16418 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
16419 ASSERT_TRUE(pass);
16420
16421 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
16422 ASSERT_VK_SUCCESS(err);
16423 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
16424 ASSERT_VK_SUCCESS(err);
16425
16426 VkDescriptorPoolSize ds_type_count = {};
16427 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16428 ds_type_count.descriptorCount = 1;
16429
16430 VkDescriptorPoolCreateInfo ds_pool_ci = {};
16431 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
16432 ds_pool_ci.pNext = NULL;
16433 ds_pool_ci.maxSets = 1;
16434 ds_pool_ci.poolSizeCount = 1;
16435 ds_pool_ci.pPoolSizes = &ds_type_count;
16436
16437 VkDescriptorPool ds_pool;
16438 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
16439 ASSERT_VK_SUCCESS(err);
16440
16441 VkDescriptorSetLayoutBinding dsl_binding = {};
16442 dsl_binding.binding = 0;
16443 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16444 dsl_binding.descriptorCount = 1;
16445 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
16446 dsl_binding.pImmutableSamplers = NULL;
16447
16448 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
16449 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
16450 ds_layout_ci.pNext = NULL;
16451 ds_layout_ci.bindingCount = 1;
16452 ds_layout_ci.pBindings = &dsl_binding;
16453 VkDescriptorSetLayout ds_layout;
16454 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
16455 ASSERT_VK_SUCCESS(err);
16456
16457 VkDescriptorSet descriptor_set;
16458 VkDescriptorSetAllocateInfo alloc_info = {};
16459 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
16460 alloc_info.descriptorSetCount = 1;
16461 alloc_info.descriptorPool = ds_pool;
16462 alloc_info.pSetLayouts = &ds_layout;
16463 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
16464 ASSERT_VK_SUCCESS(err);
16465
16466 VkDescriptorBufferInfo buffer_info = {};
16467 buffer_info.buffer = buffer;
16468 buffer_info.offset = 0;
16469 buffer_info.range = 1024;
16470
16471 VkWriteDescriptorSet descriptor_write;
16472 memset(&descriptor_write, 0, sizeof(descriptor_write));
16473 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
16474 descriptor_write.dstSet = descriptor_set;
16475 descriptor_write.dstBinding = 0;
16476 descriptor_write.descriptorCount = 1;
16477 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16478 descriptor_write.pBufferInfo = &buffer_info;
16479
16480 // Set pImageInfo and pTexelBufferView to invalid values, which should
16481 // be
16482 // ignored for descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER.
16483 // This will most likely produce a crash if the parameter_validation
16484 // layer
16485 // does not correctly ignore pImageInfo.
16486 descriptor_write.pImageInfo = reinterpret_cast<const VkDescriptorImageInfo *>(invalid_ptr);
16487 descriptor_write.pTexelBufferView = reinterpret_cast<const VkBufferView *>(invalid_ptr);
16488
16489 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
16490
16491 m_errorMonitor->VerifyNotFound();
16492
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016493 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
16494 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
16495 vkDestroyBuffer(m_device->device(), buffer, NULL);
16496 vkFreeMemory(m_device->device(), buffer_memory, NULL);
16497 }
16498
16499 // Texel Buffer Case
16500 {
16501 m_errorMonitor->ExpectSuccess();
16502
16503 VkBuffer buffer;
16504 uint32_t queue_family_index = 0;
16505 VkBufferCreateInfo buffer_create_info = {};
16506 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
16507 buffer_create_info.size = 1024;
16508 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
16509 buffer_create_info.queueFamilyIndexCount = 1;
16510 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
16511
16512 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
16513 ASSERT_VK_SUCCESS(err);
16514
16515 VkMemoryRequirements memory_reqs;
16516 VkDeviceMemory buffer_memory;
16517 bool pass;
16518 VkMemoryAllocateInfo memory_info = {};
16519 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16520 memory_info.pNext = NULL;
16521 memory_info.allocationSize = 0;
16522 memory_info.memoryTypeIndex = 0;
16523
16524 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
16525 memory_info.allocationSize = memory_reqs.size;
16526 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
16527 ASSERT_TRUE(pass);
16528
16529 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
16530 ASSERT_VK_SUCCESS(err);
16531 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
16532 ASSERT_VK_SUCCESS(err);
16533
16534 VkBufferViewCreateInfo buff_view_ci = {};
16535 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
16536 buff_view_ci.buffer = buffer;
16537 buff_view_ci.format = VK_FORMAT_R8_UNORM;
16538 buff_view_ci.range = VK_WHOLE_SIZE;
16539 VkBufferView buffer_view;
16540 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buffer_view);
16541
16542 VkDescriptorPoolSize ds_type_count = {};
16543 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
16544 ds_type_count.descriptorCount = 1;
16545
16546 VkDescriptorPoolCreateInfo ds_pool_ci = {};
16547 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
16548 ds_pool_ci.pNext = NULL;
16549 ds_pool_ci.maxSets = 1;
16550 ds_pool_ci.poolSizeCount = 1;
16551 ds_pool_ci.pPoolSizes = &ds_type_count;
16552
16553 VkDescriptorPool ds_pool;
16554 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
16555 ASSERT_VK_SUCCESS(err);
16556
16557 VkDescriptorSetLayoutBinding dsl_binding = {};
16558 dsl_binding.binding = 0;
16559 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
16560 dsl_binding.descriptorCount = 1;
16561 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
16562 dsl_binding.pImmutableSamplers = NULL;
16563
16564 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
16565 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
16566 ds_layout_ci.pNext = NULL;
16567 ds_layout_ci.bindingCount = 1;
16568 ds_layout_ci.pBindings = &dsl_binding;
16569 VkDescriptorSetLayout ds_layout;
16570 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
16571 ASSERT_VK_SUCCESS(err);
16572
16573 VkDescriptorSet descriptor_set;
16574 VkDescriptorSetAllocateInfo alloc_info = {};
16575 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
16576 alloc_info.descriptorSetCount = 1;
16577 alloc_info.descriptorPool = ds_pool;
16578 alloc_info.pSetLayouts = &ds_layout;
16579 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
16580 ASSERT_VK_SUCCESS(err);
16581
16582 VkWriteDescriptorSet descriptor_write;
16583 memset(&descriptor_write, 0, sizeof(descriptor_write));
16584 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
16585 descriptor_write.dstSet = descriptor_set;
16586 descriptor_write.dstBinding = 0;
16587 descriptor_write.descriptorCount = 1;
16588 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
16589 descriptor_write.pTexelBufferView = &buffer_view;
16590
16591 // Set pImageInfo and pBufferInfo to invalid values, which should be
16592 // ignored for descriptorType ==
16593 // VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER.
16594 // This will most likely produce a crash if the parameter_validation
16595 // layer
16596 // does not correctly ignore pImageInfo and pBufferInfo.
16597 descriptor_write.pImageInfo = reinterpret_cast<const VkDescriptorImageInfo *>(invalid_ptr);
16598 descriptor_write.pBufferInfo = reinterpret_cast<const VkDescriptorBufferInfo *>(invalid_ptr);
16599
16600 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
16601
16602 m_errorMonitor->VerifyNotFound();
16603
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016604 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
16605 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
16606 vkDestroyBufferView(m_device->device(), buffer_view, NULL);
16607 vkDestroyBuffer(m_device->device(), buffer, NULL);
16608 vkFreeMemory(m_device->device(), buffer_memory, NULL);
16609 }
16610}
16611
Tobin Ehlisf7428442016-10-25 07:58:24 -060016612TEST_F(VkLayerTest, DuplicateDescriptorBinding) {
16613 TEST_DESCRIPTION("Create a descriptor set layout with a duplicate binding number.");
16614
16615 ASSERT_NO_FATAL_FAILURE(InitState());
16616 // Create layout where two binding #s are "1"
16617 static const uint32_t NUM_BINDINGS = 3;
16618 VkDescriptorSetLayoutBinding dsl_binding[NUM_BINDINGS] = {};
16619 dsl_binding[0].binding = 1;
16620 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16621 dsl_binding[0].descriptorCount = 1;
16622 dsl_binding[0].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
16623 dsl_binding[0].pImmutableSamplers = NULL;
16624 dsl_binding[1].binding = 0;
16625 dsl_binding[1].descriptorCount = 1;
16626 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16627 dsl_binding[1].descriptorCount = 1;
16628 dsl_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
16629 dsl_binding[1].pImmutableSamplers = NULL;
16630 dsl_binding[2].binding = 1; // Duplicate binding should cause error
16631 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16632 dsl_binding[2].descriptorCount = 1;
16633 dsl_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
16634 dsl_binding[2].pImmutableSamplers = NULL;
16635
16636 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
16637 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
16638 ds_layout_ci.pNext = NULL;
16639 ds_layout_ci.bindingCount = NUM_BINDINGS;
16640 ds_layout_ci.pBindings = dsl_binding;
16641 VkDescriptorSetLayout ds_layout;
16642 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02345);
16643 vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
16644 m_errorMonitor->VerifyFound();
16645}
16646
Mike Weiblen9a0f55d2016-10-31 22:35:00 -060016647TEST_F(VkLayerTest, ViewportAndScissorBoundsChecking) {
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060016648 TEST_DESCRIPTION("Verify errors are detected on misuse of SetViewport and SetScissor.");
16649
16650 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060016651
Tony Barbour552f6c02016-12-21 14:34:07 -070016652 m_commandBuffer->BeginCommandBuffer();
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060016653
Mike Weiblen9a0f55d2016-10-31 22:35:00 -060016654 const VkPhysicalDeviceLimits &limits = m_device->props.limits;
16655
16656 {
16657 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01448);
16658 VkViewport viewport = {0, 0, static_cast<float>(limits.maxViewportDimensions[0] + 1), 16, 0, 1};
16659 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
16660 m_errorMonitor->VerifyFound();
16661 }
16662
16663 {
16664 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01449);
16665 VkViewport viewport = {0, 0, 16, static_cast<float>(limits.maxViewportDimensions[1] + 1), 0, 1};
16666 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
16667 m_errorMonitor->VerifyFound();
16668 }
16669
16670 {
16671 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01450);
16672 VkViewport viewport = {limits.viewportBoundsRange[0] - 1, 0, 16, 16, 0, 1};
16673 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
16674 m_errorMonitor->VerifyFound();
16675 }
16676
16677 {
16678 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01450);
16679 VkViewport viewport = {0, limits.viewportBoundsRange[0] - 1, 16, 16, 0, 1};
16680 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
16681 m_errorMonitor->VerifyFound();
16682 }
16683
16684 {
16685 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01451);
16686 VkViewport viewport = {limits.viewportBoundsRange[1], 0, 16, 16, 0, 1};
16687 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
16688 m_errorMonitor->VerifyFound();
16689 }
16690
16691 {
16692 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01452);
16693 VkViewport viewport = {0, limits.viewportBoundsRange[1], 16, 16, 0, 1};
16694 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
16695 m_errorMonitor->VerifyFound();
16696 }
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060016697
16698 {
16699 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01489);
16700 VkRect2D scissor = {{-1, 0}, {16, 16}};
16701 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
16702 m_errorMonitor->VerifyFound();
16703 }
16704
16705 {
16706 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01489);
16707 VkRect2D scissor = {{0, -2}, {16, 16}};
16708 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
16709 m_errorMonitor->VerifyFound();
16710 }
16711
16712 {
16713 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01490);
16714 VkRect2D scissor = {{100, 100}, {INT_MAX, 16}};
16715 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
16716 m_errorMonitor->VerifyFound();
16717 }
16718
16719 {
16720 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01491);
16721 VkRect2D scissor = {{100, 100}, {16, INT_MAX}};
16722 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
16723 m_errorMonitor->VerifyFound();
16724 }
16725
Tony Barbour552f6c02016-12-21 14:34:07 -070016726 m_commandBuffer->EndCommandBuffer();
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060016727}
16728
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016729// This is a positive test. No failures are expected.
16730TEST_F(VkPositiveLayerTest, EmptyDescriptorUpdateTest) {
16731 TEST_DESCRIPTION("Update last descriptor in a set that includes an empty binding");
16732 VkResult err;
16733
16734 ASSERT_NO_FATAL_FAILURE(InitState());
16735 m_errorMonitor->ExpectSuccess();
16736 VkDescriptorPoolSize ds_type_count = {};
16737 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16738 ds_type_count.descriptorCount = 2;
16739
16740 VkDescriptorPoolCreateInfo ds_pool_ci = {};
16741 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
16742 ds_pool_ci.pNext = NULL;
16743 ds_pool_ci.maxSets = 1;
16744 ds_pool_ci.poolSizeCount = 1;
16745 ds_pool_ci.pPoolSizes = &ds_type_count;
16746
16747 VkDescriptorPool ds_pool;
16748 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
16749 ASSERT_VK_SUCCESS(err);
16750
16751 // Create layout with two uniform buffer descriptors w/ empty binding between them
16752 static const uint32_t NUM_BINDINGS = 3;
16753 VkDescriptorSetLayoutBinding dsl_binding[NUM_BINDINGS] = {};
16754 dsl_binding[0].binding = 0;
16755 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16756 dsl_binding[0].descriptorCount = 1;
16757 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
16758 dsl_binding[0].pImmutableSamplers = NULL;
16759 dsl_binding[1].binding = 1;
16760 dsl_binding[1].descriptorCount = 0; // empty binding
16761 dsl_binding[2].binding = 2;
16762 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16763 dsl_binding[2].descriptorCount = 1;
16764 dsl_binding[2].stageFlags = VK_SHADER_STAGE_ALL;
16765 dsl_binding[2].pImmutableSamplers = NULL;
16766
16767 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
16768 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
16769 ds_layout_ci.pNext = NULL;
16770 ds_layout_ci.bindingCount = NUM_BINDINGS;
16771 ds_layout_ci.pBindings = dsl_binding;
16772 VkDescriptorSetLayout ds_layout;
16773 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
16774 ASSERT_VK_SUCCESS(err);
16775
16776 VkDescriptorSet descriptor_set = {};
16777 VkDescriptorSetAllocateInfo alloc_info = {};
16778 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
16779 alloc_info.descriptorSetCount = 1;
16780 alloc_info.descriptorPool = ds_pool;
16781 alloc_info.pSetLayouts = &ds_layout;
16782 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
16783 ASSERT_VK_SUCCESS(err);
16784
16785 // Create a buffer to be used for update
16786 VkBufferCreateInfo buff_ci = {};
16787 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
16788 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
16789 buff_ci.size = 256;
16790 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
16791 VkBuffer buffer;
16792 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
16793 ASSERT_VK_SUCCESS(err);
16794 // Have to bind memory to buffer before descriptor update
16795 VkMemoryAllocateInfo mem_alloc = {};
16796 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16797 mem_alloc.pNext = NULL;
16798 mem_alloc.allocationSize = 512; // one allocation for both buffers
16799 mem_alloc.memoryTypeIndex = 0;
16800
16801 VkMemoryRequirements mem_reqs;
16802 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
16803 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
16804 if (!pass) {
16805 vkDestroyBuffer(m_device->device(), buffer, NULL);
16806 return;
16807 }
16808
16809 VkDeviceMemory mem;
16810 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
16811 ASSERT_VK_SUCCESS(err);
16812 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
16813 ASSERT_VK_SUCCESS(err);
16814
16815 // Only update the descriptor at binding 2
16816 VkDescriptorBufferInfo buff_info = {};
16817 buff_info.buffer = buffer;
16818 buff_info.offset = 0;
16819 buff_info.range = VK_WHOLE_SIZE;
16820 VkWriteDescriptorSet descriptor_write = {};
16821 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
16822 descriptor_write.dstBinding = 2;
16823 descriptor_write.descriptorCount = 1;
16824 descriptor_write.pTexelBufferView = nullptr;
16825 descriptor_write.pBufferInfo = &buff_info;
16826 descriptor_write.pImageInfo = nullptr;
16827 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16828 descriptor_write.dstSet = descriptor_set;
16829
16830 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
16831
16832 m_errorMonitor->VerifyNotFound();
16833 // Cleanup
16834 vkFreeMemory(m_device->device(), mem, NULL);
16835 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
16836 vkDestroyBuffer(m_device->device(), buffer, NULL);
16837 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
16838}
16839
16840// This is a positive test. No failures are expected.
16841TEST_F(VkPositiveLayerTest, TestAliasedMemoryTracking) {
16842 VkResult err;
16843 bool pass;
16844
16845 TEST_DESCRIPTION("Create a buffer, allocate memory, bind memory, destroy "
16846 "the buffer, create an image, and bind the same memory to "
16847 "it");
16848
16849 m_errorMonitor->ExpectSuccess();
16850
16851 ASSERT_NO_FATAL_FAILURE(InitState());
16852
16853 VkBuffer buffer;
16854 VkImage image;
16855 VkDeviceMemory mem;
16856 VkMemoryRequirements mem_reqs;
16857
16858 VkBufferCreateInfo buf_info = {};
16859 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
16860 buf_info.pNext = NULL;
16861 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
16862 buf_info.size = 256;
16863 buf_info.queueFamilyIndexCount = 0;
16864 buf_info.pQueueFamilyIndices = NULL;
16865 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
16866 buf_info.flags = 0;
16867 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
16868 ASSERT_VK_SUCCESS(err);
16869
16870 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
16871
16872 VkMemoryAllocateInfo alloc_info = {};
16873 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16874 alloc_info.pNext = NULL;
16875 alloc_info.memoryTypeIndex = 0;
16876
16877 // Ensure memory is big enough for both bindings
16878 alloc_info.allocationSize = 0x10000;
16879
16880 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
16881 if (!pass) {
16882 vkDestroyBuffer(m_device->device(), buffer, NULL);
16883 return;
16884 }
16885
16886 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
16887 ASSERT_VK_SUCCESS(err);
16888
16889 uint8_t *pData;
16890 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
16891 ASSERT_VK_SUCCESS(err);
16892
16893 memset(pData, 0xCADECADE, static_cast<size_t>(mem_reqs.size));
16894
16895 vkUnmapMemory(m_device->device(), mem);
16896
16897 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
16898 ASSERT_VK_SUCCESS(err);
16899
16900 // NOW, destroy the buffer. Obviously, the resource no longer occupies this
16901 // memory. In fact, it was never used by the GPU.
16902 // Just be be sure, wait for idle.
16903 vkDestroyBuffer(m_device->device(), buffer, NULL);
16904 vkDeviceWaitIdle(m_device->device());
16905
Tobin Ehlis6a005702016-12-28 15:25:56 -070016906 // Use optimal as some platforms report linear support but then fail image creation
16907 VkImageTiling image_tiling = VK_IMAGE_TILING_OPTIMAL;
16908 VkImageFormatProperties image_format_properties;
16909 vkGetPhysicalDeviceImageFormatProperties(gpu(), VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_TYPE_2D, image_tiling,
16910 VK_IMAGE_USAGE_TRANSFER_SRC_BIT, 0, &image_format_properties);
16911 if (image_format_properties.maxExtent.width == 0) {
16912 printf("Image format not supported; skipped.\n");
16913 vkFreeMemory(m_device->device(), mem, NULL);
16914 return;
16915 }
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016916 VkImageCreateInfo image_create_info = {};
16917 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16918 image_create_info.pNext = NULL;
16919 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16920 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
16921 image_create_info.extent.width = 64;
16922 image_create_info.extent.height = 64;
16923 image_create_info.extent.depth = 1;
16924 image_create_info.mipLevels = 1;
16925 image_create_info.arrayLayers = 1;
16926 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehlis6a005702016-12-28 15:25:56 -070016927 image_create_info.tiling = image_tiling;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016928 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
16929 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
16930 image_create_info.queueFamilyIndexCount = 0;
16931 image_create_info.pQueueFamilyIndices = NULL;
16932 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
16933 image_create_info.flags = 0;
16934
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016935 /* Create a mappable image. It will be the texture if linear images are ok
16936 * to be textures or it will be the staging image if they are not.
16937 */
16938 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
16939 ASSERT_VK_SUCCESS(err);
16940
16941 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
16942
Tobin Ehlis6a005702016-12-28 15:25:56 -070016943 VkMemoryAllocateInfo mem_alloc = {};
16944 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16945 mem_alloc.pNext = NULL;
16946 mem_alloc.allocationSize = 0;
16947 mem_alloc.memoryTypeIndex = 0;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016948 mem_alloc.allocationSize = mem_reqs.size;
16949
16950 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
16951 if (!pass) {
Tobin Ehlis6a005702016-12-28 15:25:56 -070016952 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016953 vkDestroyImage(m_device->device(), image, NULL);
16954 return;
16955 }
16956
16957 // VALIDATION FAILURE:
16958 err = vkBindImageMemory(m_device->device(), image, mem, 0);
16959 ASSERT_VK_SUCCESS(err);
16960
16961 m_errorMonitor->VerifyNotFound();
16962
16963 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016964 vkDestroyImage(m_device->device(), image, NULL);
16965}
16966
Tobin Ehlis953e8392016-11-17 10:54:13 -070016967TEST_F(VkPositiveLayerTest, DynamicOffsetWithInactiveBinding) {
16968 // Create a descriptorSet w/ dynamic descriptors where 1 binding is inactive
16969 // We previously had a bug where dynamic offset of inactive bindings was still being used
16970 VkResult err;
16971 m_errorMonitor->ExpectSuccess();
16972
16973 ASSERT_NO_FATAL_FAILURE(InitState());
16974 ASSERT_NO_FATAL_FAILURE(InitViewport());
16975 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
16976
16977 VkDescriptorPoolSize ds_type_count = {};
16978 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
16979 ds_type_count.descriptorCount = 3;
16980
16981 VkDescriptorPoolCreateInfo ds_pool_ci = {};
16982 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
16983 ds_pool_ci.pNext = NULL;
16984 ds_pool_ci.maxSets = 1;
16985 ds_pool_ci.poolSizeCount = 1;
16986 ds_pool_ci.pPoolSizes = &ds_type_count;
16987
16988 VkDescriptorPool ds_pool;
16989 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
16990 ASSERT_VK_SUCCESS(err);
16991
16992 const uint32_t BINDING_COUNT = 3;
16993 VkDescriptorSetLayoutBinding dsl_binding[BINDING_COUNT] = {};
Tobin Ehlis0050fba2016-11-30 10:22:02 -070016994 dsl_binding[0].binding = 2;
Tobin Ehlis953e8392016-11-17 10:54:13 -070016995 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
16996 dsl_binding[0].descriptorCount = 1;
16997 dsl_binding[0].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
16998 dsl_binding[0].pImmutableSamplers = NULL;
Tobin Ehlis0050fba2016-11-30 10:22:02 -070016999 dsl_binding[1].binding = 0;
Tobin Ehlis953e8392016-11-17 10:54:13 -070017000 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
17001 dsl_binding[1].descriptorCount = 1;
17002 dsl_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
17003 dsl_binding[1].pImmutableSamplers = NULL;
Tobin Ehlis0050fba2016-11-30 10:22:02 -070017004 dsl_binding[2].binding = 1;
Tobin Ehlis953e8392016-11-17 10:54:13 -070017005 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
17006 dsl_binding[2].descriptorCount = 1;
17007 dsl_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
17008 dsl_binding[2].pImmutableSamplers = NULL;
17009
17010 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
17011 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
17012 ds_layout_ci.pNext = NULL;
17013 ds_layout_ci.bindingCount = BINDING_COUNT;
17014 ds_layout_ci.pBindings = dsl_binding;
17015 VkDescriptorSetLayout ds_layout;
17016 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
17017 ASSERT_VK_SUCCESS(err);
17018
17019 VkDescriptorSet descriptor_set;
17020 VkDescriptorSetAllocateInfo alloc_info = {};
17021 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
17022 alloc_info.descriptorSetCount = 1;
17023 alloc_info.descriptorPool = ds_pool;
17024 alloc_info.pSetLayouts = &ds_layout;
17025 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
17026 ASSERT_VK_SUCCESS(err);
17027
17028 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
17029 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
17030 pipeline_layout_ci.pNext = NULL;
17031 pipeline_layout_ci.setLayoutCount = 1;
17032 pipeline_layout_ci.pSetLayouts = &ds_layout;
17033
17034 VkPipelineLayout pipeline_layout;
17035 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
17036 ASSERT_VK_SUCCESS(err);
17037
17038 // Create two buffers to update the descriptors with
17039 // The first will be 2k and used for bindings 0 & 1, the second is 1k for binding 2
17040 uint32_t qfi = 0;
17041 VkBufferCreateInfo buffCI = {};
17042 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
17043 buffCI.size = 2048;
17044 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
17045 buffCI.queueFamilyIndexCount = 1;
17046 buffCI.pQueueFamilyIndices = &qfi;
17047
17048 VkBuffer dyub1;
17049 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub1);
17050 ASSERT_VK_SUCCESS(err);
17051 // buffer2
17052 buffCI.size = 1024;
17053 VkBuffer dyub2;
17054 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub2);
17055 ASSERT_VK_SUCCESS(err);
17056 // Allocate memory and bind to buffers
17057 VkMemoryAllocateInfo mem_alloc[2] = {};
17058 mem_alloc[0].sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17059 mem_alloc[0].pNext = NULL;
17060 mem_alloc[0].memoryTypeIndex = 0;
17061 mem_alloc[1].sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17062 mem_alloc[1].pNext = NULL;
17063 mem_alloc[1].memoryTypeIndex = 0;
17064
17065 VkMemoryRequirements mem_reqs1;
17066 vkGetBufferMemoryRequirements(m_device->device(), dyub1, &mem_reqs1);
17067 VkMemoryRequirements mem_reqs2;
17068 vkGetBufferMemoryRequirements(m_device->device(), dyub2, &mem_reqs2);
17069 mem_alloc[0].allocationSize = mem_reqs1.size;
17070 bool pass = m_device->phy().set_memory_type(mem_reqs1.memoryTypeBits, &mem_alloc[0], 0);
17071 mem_alloc[1].allocationSize = mem_reqs2.size;
17072 pass &= m_device->phy().set_memory_type(mem_reqs2.memoryTypeBits, &mem_alloc[1], 0);
17073 if (!pass) {
17074 vkDestroyBuffer(m_device->device(), dyub1, NULL);
17075 vkDestroyBuffer(m_device->device(), dyub2, NULL);
17076 return;
17077 }
17078
17079 VkDeviceMemory mem1;
17080 err = vkAllocateMemory(m_device->device(), &mem_alloc[0], NULL, &mem1);
17081 ASSERT_VK_SUCCESS(err);
17082 err = vkBindBufferMemory(m_device->device(), dyub1, mem1, 0);
17083 ASSERT_VK_SUCCESS(err);
17084 VkDeviceMemory mem2;
17085 err = vkAllocateMemory(m_device->device(), &mem_alloc[1], NULL, &mem2);
17086 ASSERT_VK_SUCCESS(err);
17087 err = vkBindBufferMemory(m_device->device(), dyub2, mem2, 0);
17088 ASSERT_VK_SUCCESS(err);
17089 // Update descriptors
17090 VkDescriptorBufferInfo buff_info[BINDING_COUNT] = {};
17091 buff_info[0].buffer = dyub1;
17092 buff_info[0].offset = 0;
17093 buff_info[0].range = 256;
17094 buff_info[1].buffer = dyub1;
17095 buff_info[1].offset = 256;
17096 buff_info[1].range = 512;
17097 buff_info[2].buffer = dyub2;
17098 buff_info[2].offset = 0;
17099 buff_info[2].range = 512;
17100
17101 VkWriteDescriptorSet descriptor_write;
17102 memset(&descriptor_write, 0, sizeof(descriptor_write));
17103 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
17104 descriptor_write.dstSet = descriptor_set;
17105 descriptor_write.dstBinding = 0;
17106 descriptor_write.descriptorCount = BINDING_COUNT;
17107 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
17108 descriptor_write.pBufferInfo = buff_info;
17109
17110 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
17111
Tony Barbour552f6c02016-12-21 14:34:07 -070017112 m_commandBuffer->BeginCommandBuffer();
17113 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis953e8392016-11-17 10:54:13 -070017114
17115 // Create PSO to be used for draw-time errors below
17116 char const *vsSource = "#version 450\n"
17117 "\n"
17118 "out gl_PerVertex { \n"
17119 " vec4 gl_Position;\n"
17120 "};\n"
17121 "void main(){\n"
17122 " gl_Position = vec4(1);\n"
17123 "}\n";
17124 char const *fsSource = "#version 450\n"
17125 "\n"
17126 "layout(location=0) out vec4 x;\n"
17127 "layout(set=0) layout(binding=0) uniform foo1 { int x; int y; } bar1;\n"
17128 "layout(set=0) layout(binding=2) uniform foo2 { int x; int y; } bar2;\n"
17129 "void main(){\n"
17130 " x = vec4(bar1.y) + vec4(bar2.y);\n"
17131 "}\n";
17132 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
17133 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
17134 VkPipelineObj pipe(m_device);
17135 pipe.SetViewport(m_viewports);
17136 pipe.SetScissor(m_scissors);
17137 pipe.AddShader(&vs);
17138 pipe.AddShader(&fs);
17139 pipe.AddColorAttachment();
17140 pipe.CreateVKPipeline(pipeline_layout, renderPass());
17141
17142 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
17143 // This update should succeed, but offset of inactive binding 1 oversteps binding 2 buffer size
17144 // we used to have a bug in this case.
17145 uint32_t dyn_off[BINDING_COUNT] = {0, 1024, 256};
17146 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
17147 &descriptor_set, BINDING_COUNT, dyn_off);
17148 Draw(1, 0, 0, 0);
17149 m_errorMonitor->VerifyNotFound();
17150
17151 vkDestroyBuffer(m_device->device(), dyub1, NULL);
17152 vkDestroyBuffer(m_device->device(), dyub2, NULL);
17153 vkFreeMemory(m_device->device(), mem1, NULL);
17154 vkFreeMemory(m_device->device(), mem2, NULL);
17155
17156 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
17157 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
17158 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
17159}
17160
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017161TEST_F(VkPositiveLayerTest, NonCoherentMemoryMapping) {
17162
17163 TEST_DESCRIPTION("Ensure that validations handling of non-coherent memory "
17164 "mapping while using VK_WHOLE_SIZE does not cause access "
17165 "violations");
17166 VkResult err;
17167 uint8_t *pData;
17168 ASSERT_NO_FATAL_FAILURE(InitState());
17169
17170 VkDeviceMemory mem;
17171 VkMemoryRequirements mem_reqs;
17172 mem_reqs.memoryTypeBits = 0xFFFFFFFF;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017173 const VkDeviceSize atom_size = m_device->props.limits.nonCoherentAtomSize;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017174 VkMemoryAllocateInfo alloc_info = {};
17175 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17176 alloc_info.pNext = NULL;
17177 alloc_info.memoryTypeIndex = 0;
17178
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017179 static const VkDeviceSize allocation_size = 32 * atom_size;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017180 alloc_info.allocationSize = allocation_size;
17181
17182 // Find a memory configurations WITHOUT a COHERENT bit, otherwise exit
17183 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT,
17184 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
17185 if (!pass) {
17186 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info,
17187 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT,
17188 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
17189 if (!pass) {
17190 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info,
17191 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT |
17192 VK_MEMORY_PROPERTY_HOST_CACHED_BIT,
17193 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
17194 if (!pass) {
17195 return;
17196 }
17197 }
17198 }
17199
17200 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
17201 ASSERT_VK_SUCCESS(err);
17202
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017203 // Map/Flush/Invalidate using WHOLE_SIZE and zero offsets and entire mapped range
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017204 m_errorMonitor->ExpectSuccess();
17205 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, (void **)&pData);
17206 ASSERT_VK_SUCCESS(err);
17207 VkMappedMemoryRange mmr = {};
17208 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
17209 mmr.memory = mem;
17210 mmr.offset = 0;
17211 mmr.size = VK_WHOLE_SIZE;
17212 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
17213 ASSERT_VK_SUCCESS(err);
17214 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
17215 ASSERT_VK_SUCCESS(err);
17216 m_errorMonitor->VerifyNotFound();
17217 vkUnmapMemory(m_device->device(), mem);
17218
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017219 // Map/Flush/Invalidate using WHOLE_SIZE and an offset and entire mapped range
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017220 m_errorMonitor->ExpectSuccess();
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017221 err = vkMapMemory(m_device->device(), mem, 5 * atom_size, VK_WHOLE_SIZE, 0, (void **)&pData);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017222 ASSERT_VK_SUCCESS(err);
17223 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
17224 mmr.memory = mem;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017225 mmr.offset = 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 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
17230 ASSERT_VK_SUCCESS(err);
17231 m_errorMonitor->VerifyNotFound();
17232 vkUnmapMemory(m_device->device(), mem);
17233
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017234 // Map with offset and size
17235 // Flush/Invalidate subrange of mapped area with offset and size
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017236 m_errorMonitor->ExpectSuccess();
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017237 err = vkMapMemory(m_device->device(), mem, 3 * atom_size, 9 * atom_size, 0, (void **)&pData);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017238 ASSERT_VK_SUCCESS(err);
17239 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
17240 mmr.memory = mem;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017241 mmr.offset = 4 * atom_size;
17242 mmr.size = 2 * atom_size;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017243 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
17244 ASSERT_VK_SUCCESS(err);
17245 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
17246 ASSERT_VK_SUCCESS(err);
17247 m_errorMonitor->VerifyNotFound();
17248 vkUnmapMemory(m_device->device(), mem);
17249
17250 // Map without offset and flush WHOLE_SIZE with two separate offsets
17251 m_errorMonitor->ExpectSuccess();
17252 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, (void **)&pData);
17253 ASSERT_VK_SUCCESS(err);
17254 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
17255 mmr.memory = mem;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017256 mmr.offset = allocation_size - (4 * atom_size);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017257 mmr.size = VK_WHOLE_SIZE;
17258 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
17259 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017260 mmr.offset = allocation_size - (6 * atom_size);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017261 mmr.size = VK_WHOLE_SIZE;
17262 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
17263 ASSERT_VK_SUCCESS(err);
17264 m_errorMonitor->VerifyNotFound();
17265 vkUnmapMemory(m_device->device(), mem);
17266
17267 vkFreeMemory(m_device->device(), mem, NULL);
17268}
17269
17270// This is a positive test. We used to expect error in this case but spec now allows it
17271TEST_F(VkPositiveLayerTest, ResetUnsignaledFence) {
17272 m_errorMonitor->ExpectSuccess();
17273 vk_testing::Fence testFence;
17274 VkFenceCreateInfo fenceInfo = {};
17275 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
17276 fenceInfo.pNext = NULL;
17277
17278 ASSERT_NO_FATAL_FAILURE(InitState());
17279 testFence.init(*m_device, fenceInfo);
17280 VkFence fences[1] = { testFence.handle() };
17281 VkResult result = vkResetFences(m_device->device(), 1, fences);
17282 ASSERT_VK_SUCCESS(result);
17283
17284 m_errorMonitor->VerifyNotFound();
17285}
17286
17287TEST_F(VkPositiveLayerTest, CommandBufferSimultaneousUseSync) {
17288 m_errorMonitor->ExpectSuccess();
17289
17290 ASSERT_NO_FATAL_FAILURE(InitState());
17291 VkResult err;
17292
17293 // Record (empty!) command buffer that can be submitted multiple times
17294 // simultaneously.
17295 VkCommandBufferBeginInfo cbbi = { VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr,
17296 VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT, nullptr };
17297 m_commandBuffer->BeginCommandBuffer(&cbbi);
17298 m_commandBuffer->EndCommandBuffer();
17299
17300 VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
17301 VkFence fence;
17302 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
17303 ASSERT_VK_SUCCESS(err);
17304
17305 VkSemaphoreCreateInfo sci = { VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0 };
17306 VkSemaphore s1, s2;
17307 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s1);
17308 ASSERT_VK_SUCCESS(err);
17309 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s2);
17310 ASSERT_VK_SUCCESS(err);
17311
17312 // Submit CB once signaling s1, with fence so we can roll forward to its retirement.
17313 VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 1, &m_commandBuffer->handle(), 1, &s1 };
17314 err = vkQueueSubmit(m_device->m_queue, 1, &si, fence);
17315 ASSERT_VK_SUCCESS(err);
17316
17317 // Submit CB again, signaling s2.
17318 si.pSignalSemaphores = &s2;
17319 err = vkQueueSubmit(m_device->m_queue, 1, &si, VK_NULL_HANDLE);
17320 ASSERT_VK_SUCCESS(err);
17321
17322 // Wait for fence.
17323 err = vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
17324 ASSERT_VK_SUCCESS(err);
17325
17326 // CB is still in flight from second submission, but semaphore s1 is no
17327 // longer in flight. delete it.
17328 vkDestroySemaphore(m_device->device(), s1, nullptr);
17329
17330 m_errorMonitor->VerifyNotFound();
17331
17332 // Force device idle and clean up remaining objects
17333 vkDeviceWaitIdle(m_device->device());
17334 vkDestroySemaphore(m_device->device(), s2, nullptr);
17335 vkDestroyFence(m_device->device(), fence, nullptr);
17336}
17337
17338TEST_F(VkPositiveLayerTest, FenceCreateSignaledWaitHandling) {
17339 m_errorMonitor->ExpectSuccess();
17340
17341 ASSERT_NO_FATAL_FAILURE(InitState());
17342 VkResult err;
17343
17344 // A fence created signaled
17345 VkFenceCreateInfo fci1 = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, VK_FENCE_CREATE_SIGNALED_BIT };
17346 VkFence f1;
17347 err = vkCreateFence(m_device->device(), &fci1, nullptr, &f1);
17348 ASSERT_VK_SUCCESS(err);
17349
17350 // A fence created not
17351 VkFenceCreateInfo fci2 = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
17352 VkFence f2;
17353 err = vkCreateFence(m_device->device(), &fci2, nullptr, &f2);
17354 ASSERT_VK_SUCCESS(err);
17355
17356 // Submit the unsignaled fence
17357 VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 0, nullptr, 0, nullptr };
17358 err = vkQueueSubmit(m_device->m_queue, 1, &si, f2);
17359
17360 // Wait on both fences, with signaled first.
17361 VkFence fences[] = { f1, f2 };
17362 vkWaitForFences(m_device->device(), 2, fences, VK_TRUE, UINT64_MAX);
17363
17364 // Should have both retired!
17365 vkDestroyFence(m_device->device(), f1, nullptr);
17366 vkDestroyFence(m_device->device(), f2, nullptr);
17367
17368 m_errorMonitor->VerifyNotFound();
17369}
17370
17371TEST_F(VkPositiveLayerTest, ValidUsage) {
17372 TEST_DESCRIPTION("Verify that creating an image view from an image with valid usage "
17373 "doesn't generate validation errors");
17374
17375 ASSERT_NO_FATAL_FAILURE(InitState());
17376
17377 m_errorMonitor->ExpectSuccess();
17378 // Verify that we can create a view with usage INPUT_ATTACHMENT
17379 VkImageObj image(m_device);
17380 image.init(128, 128, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
17381 ASSERT_TRUE(image.initialized());
17382 VkImageView imageView;
17383 VkImageViewCreateInfo ivci = {};
17384 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
17385 ivci.image = image.handle();
17386 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
17387 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
17388 ivci.subresourceRange.layerCount = 1;
17389 ivci.subresourceRange.baseMipLevel = 0;
17390 ivci.subresourceRange.levelCount = 1;
17391 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
17392
17393 vkCreateImageView(m_device->device(), &ivci, NULL, &imageView);
17394 m_errorMonitor->VerifyNotFound();
17395 vkDestroyImageView(m_device->device(), imageView, NULL);
17396}
17397
17398// This is a positive test. No failures are expected.
17399TEST_F(VkPositiveLayerTest, BindSparse) {
17400 TEST_DESCRIPTION("Bind 2 memory ranges to one image using vkQueueBindSparse, destroy the image"
17401 "and then free the memory");
17402
17403 ASSERT_NO_FATAL_FAILURE(InitState());
17404
17405 auto index = m_device->graphics_queue_node_index_;
17406 if (!(m_device->queue_props[index].queueFlags & VK_QUEUE_SPARSE_BINDING_BIT))
17407 return;
17408
17409 m_errorMonitor->ExpectSuccess();
17410
17411 VkImage image;
17412 VkImageCreateInfo image_create_info = {};
17413 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
17414 image_create_info.pNext = NULL;
17415 image_create_info.imageType = VK_IMAGE_TYPE_2D;
17416 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
17417 image_create_info.extent.width = 64;
17418 image_create_info.extent.height = 64;
17419 image_create_info.extent.depth = 1;
17420 image_create_info.mipLevels = 1;
17421 image_create_info.arrayLayers = 1;
17422 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
17423 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
17424 image_create_info.usage = VK_IMAGE_USAGE_STORAGE_BIT;
17425 image_create_info.flags = VK_IMAGE_CREATE_SPARSE_BINDING_BIT;
17426 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
17427 ASSERT_VK_SUCCESS(err);
17428
17429 VkMemoryRequirements memory_reqs;
17430 VkDeviceMemory memory_one, memory_two;
17431 bool pass;
17432 VkMemoryAllocateInfo memory_info = {};
17433 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17434 memory_info.pNext = NULL;
17435 memory_info.allocationSize = 0;
17436 memory_info.memoryTypeIndex = 0;
17437 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
17438 // Find an image big enough to allow sparse mapping of 2 memory regions
17439 // Increase the image size until it is at least twice the
17440 // size of the required alignment, to ensure we can bind both
17441 // allocated memory blocks to the image on aligned offsets.
17442 while (memory_reqs.size < (memory_reqs.alignment * 2)) {
17443 vkDestroyImage(m_device->device(), image, nullptr);
17444 image_create_info.extent.width *= 2;
17445 image_create_info.extent.height *= 2;
17446 err = vkCreateImage(m_device->device(), &image_create_info, nullptr, &image);
17447 ASSERT_VK_SUCCESS(err);
17448 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
17449 }
17450 // Allocate 2 memory regions of minimum alignment size, bind one at 0, the other
17451 // at the end of the first
17452 memory_info.allocationSize = memory_reqs.alignment;
17453 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
17454 ASSERT_TRUE(pass);
17455 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &memory_one);
17456 ASSERT_VK_SUCCESS(err);
17457 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &memory_two);
17458 ASSERT_VK_SUCCESS(err);
17459 VkSparseMemoryBind binds[2];
17460 binds[0].flags = 0;
17461 binds[0].memory = memory_one;
17462 binds[0].memoryOffset = 0;
17463 binds[0].resourceOffset = 0;
17464 binds[0].size = memory_info.allocationSize;
17465 binds[1].flags = 0;
17466 binds[1].memory = memory_two;
17467 binds[1].memoryOffset = 0;
17468 binds[1].resourceOffset = memory_info.allocationSize;
17469 binds[1].size = memory_info.allocationSize;
17470
17471 VkSparseImageOpaqueMemoryBindInfo opaqueBindInfo;
17472 opaqueBindInfo.image = image;
17473 opaqueBindInfo.bindCount = 2;
17474 opaqueBindInfo.pBinds = binds;
17475
17476 VkFence fence = VK_NULL_HANDLE;
17477 VkBindSparseInfo bindSparseInfo = {};
17478 bindSparseInfo.sType = VK_STRUCTURE_TYPE_BIND_SPARSE_INFO;
17479 bindSparseInfo.imageOpaqueBindCount = 1;
17480 bindSparseInfo.pImageOpaqueBinds = &opaqueBindInfo;
17481
17482 vkQueueBindSparse(m_device->m_queue, 1, &bindSparseInfo, fence);
17483 vkQueueWaitIdle(m_device->m_queue);
17484 vkDestroyImage(m_device->device(), image, NULL);
17485 vkFreeMemory(m_device->device(), memory_one, NULL);
17486 vkFreeMemory(m_device->device(), memory_two, NULL);
17487 m_errorMonitor->VerifyNotFound();
17488}
17489
17490TEST_F(VkPositiveLayerTest, RenderPassInitialLayoutUndefined) {
17491 TEST_DESCRIPTION("Ensure that CmdBeginRenderPass with an attachment's "
17492 "initialLayout of VK_IMAGE_LAYOUT_UNDEFINED works when "
17493 "the command buffer has prior knowledge of that "
17494 "attachment's layout.");
17495
17496 m_errorMonitor->ExpectSuccess();
17497
17498 ASSERT_NO_FATAL_FAILURE(InitState());
17499
17500 // A renderpass with one color attachment.
17501 VkAttachmentDescription attachment = { 0,
17502 VK_FORMAT_R8G8B8A8_UNORM,
17503 VK_SAMPLE_COUNT_1_BIT,
17504 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
17505 VK_ATTACHMENT_STORE_OP_STORE,
17506 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
17507 VK_ATTACHMENT_STORE_OP_DONT_CARE,
17508 VK_IMAGE_LAYOUT_UNDEFINED,
17509 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
17510
17511 VkAttachmentReference att_ref = { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
17512
17513 VkSubpassDescription subpass = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr };
17514
17515 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr };
17516
17517 VkRenderPass rp;
17518 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
17519 ASSERT_VK_SUCCESS(err);
17520
17521 // A compatible framebuffer.
17522 VkImageObj image(m_device);
17523 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
17524 ASSERT_TRUE(image.initialized());
17525
17526 VkImageViewCreateInfo ivci = {
17527 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
17528 nullptr,
17529 0,
17530 image.handle(),
17531 VK_IMAGE_VIEW_TYPE_2D,
17532 VK_FORMAT_R8G8B8A8_UNORM,
17533 { VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
17534 VK_COMPONENT_SWIZZLE_IDENTITY },
17535 { VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 },
17536 };
17537 VkImageView view;
17538 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
17539 ASSERT_VK_SUCCESS(err);
17540
17541 VkFramebufferCreateInfo fci = { VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1 };
17542 VkFramebuffer fb;
17543 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
17544 ASSERT_VK_SUCCESS(err);
17545
17546 // Record a single command buffer which uses this renderpass twice. The
17547 // bug is triggered at the beginning of the second renderpass, when the
17548 // command buffer already has a layout recorded for the attachment.
17549 VkRenderPassBeginInfo rpbi = { VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb,{ { 0, 0 },{ 32, 32 } }, 0, nullptr };
Tony Barbour552f6c02016-12-21 14:34:07 -070017550 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017551 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
17552 vkCmdEndRenderPass(m_commandBuffer->handle());
17553 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
17554
17555 m_errorMonitor->VerifyNotFound();
17556
17557 vkCmdEndRenderPass(m_commandBuffer->handle());
Tony Barbour552f6c02016-12-21 14:34:07 -070017558 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017559
17560 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
17561 vkDestroyRenderPass(m_device->device(), rp, nullptr);
17562 vkDestroyImageView(m_device->device(), view, nullptr);
17563}
17564
17565TEST_F(VkPositiveLayerTest, FramebufferBindingDestroyCommandPool) {
17566 TEST_DESCRIPTION("This test should pass. Create a Framebuffer and "
17567 "command buffer, bind them together, then destroy "
17568 "command pool and framebuffer and verify there are no "
17569 "errors.");
17570
17571 m_errorMonitor->ExpectSuccess();
17572
17573 ASSERT_NO_FATAL_FAILURE(InitState());
17574
17575 // A renderpass with one color attachment.
17576 VkAttachmentDescription attachment = { 0,
17577 VK_FORMAT_R8G8B8A8_UNORM,
17578 VK_SAMPLE_COUNT_1_BIT,
17579 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
17580 VK_ATTACHMENT_STORE_OP_STORE,
17581 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
17582 VK_ATTACHMENT_STORE_OP_DONT_CARE,
17583 VK_IMAGE_LAYOUT_UNDEFINED,
17584 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
17585
17586 VkAttachmentReference att_ref = { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
17587
17588 VkSubpassDescription subpass = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr };
17589
17590 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr };
17591
17592 VkRenderPass rp;
17593 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
17594 ASSERT_VK_SUCCESS(err);
17595
17596 // A compatible framebuffer.
17597 VkImageObj image(m_device);
17598 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
17599 ASSERT_TRUE(image.initialized());
17600
17601 VkImageViewCreateInfo ivci = {
17602 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
17603 nullptr,
17604 0,
17605 image.handle(),
17606 VK_IMAGE_VIEW_TYPE_2D,
17607 VK_FORMAT_R8G8B8A8_UNORM,
17608 { VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
17609 VK_COMPONENT_SWIZZLE_IDENTITY },
17610 { VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 },
17611 };
17612 VkImageView view;
17613 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
17614 ASSERT_VK_SUCCESS(err);
17615
17616 VkFramebufferCreateInfo fci = { VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1 };
17617 VkFramebuffer fb;
17618 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
17619 ASSERT_VK_SUCCESS(err);
17620
17621 // Explicitly create a command buffer to bind the FB to so that we can then
17622 // destroy the command pool in order to implicitly free command buffer
17623 VkCommandPool command_pool;
17624 VkCommandPoolCreateInfo pool_create_info{};
17625 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17626 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
17627 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17628 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
17629
17630 VkCommandBuffer command_buffer;
17631 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
17632 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17633 command_buffer_allocate_info.commandPool = command_pool;
17634 command_buffer_allocate_info.commandBufferCount = 1;
17635 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17636 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
17637
17638 // Begin our cmd buffer with renderpass using our framebuffer
17639 VkRenderPassBeginInfo rpbi = { VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb,{ { 0, 0 },{ 32, 32 } }, 0, nullptr };
17640 VkCommandBufferBeginInfo begin_info{};
17641 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17642 vkBeginCommandBuffer(command_buffer, &begin_info);
17643
17644 vkCmdBeginRenderPass(command_buffer, &rpbi, VK_SUBPASS_CONTENTS_INLINE);
17645 vkCmdEndRenderPass(command_buffer);
17646 vkEndCommandBuffer(command_buffer);
17647 vkDestroyImageView(m_device->device(), view, nullptr);
17648 // Destroy command pool to implicitly free command buffer
17649 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
17650 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
17651 vkDestroyRenderPass(m_device->device(), rp, nullptr);
17652 m_errorMonitor->VerifyNotFound();
17653}
17654
17655TEST_F(VkPositiveLayerTest, RenderPassSubpassZeroTransitionsApplied) {
17656 TEST_DESCRIPTION("Ensure that CmdBeginRenderPass applies the layout "
17657 "transitions for the first subpass");
17658
17659 m_errorMonitor->ExpectSuccess();
17660
17661 ASSERT_NO_FATAL_FAILURE(InitState());
17662
17663 // A renderpass with one color attachment.
17664 VkAttachmentDescription attachment = { 0,
17665 VK_FORMAT_R8G8B8A8_UNORM,
17666 VK_SAMPLE_COUNT_1_BIT,
17667 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
17668 VK_ATTACHMENT_STORE_OP_STORE,
17669 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
17670 VK_ATTACHMENT_STORE_OP_DONT_CARE,
17671 VK_IMAGE_LAYOUT_UNDEFINED,
17672 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
17673
17674 VkAttachmentReference att_ref = { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
17675
17676 VkSubpassDescription subpass = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr };
17677
17678 VkSubpassDependency dep = { 0,
17679 0,
17680 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
17681 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
17682 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
17683 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
17684 VK_DEPENDENCY_BY_REGION_BIT };
17685
17686 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 1, &dep };
17687
17688 VkResult err;
17689 VkRenderPass rp;
17690 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
17691 ASSERT_VK_SUCCESS(err);
17692
17693 // A compatible framebuffer.
17694 VkImageObj image(m_device);
17695 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
17696 ASSERT_TRUE(image.initialized());
17697
17698 VkImageViewCreateInfo ivci = {
17699 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
17700 nullptr,
17701 0,
17702 image.handle(),
17703 VK_IMAGE_VIEW_TYPE_2D,
17704 VK_FORMAT_R8G8B8A8_UNORM,
17705 { VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
17706 VK_COMPONENT_SWIZZLE_IDENTITY },
17707 { VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 },
17708 };
17709 VkImageView view;
17710 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
17711 ASSERT_VK_SUCCESS(err);
17712
17713 VkFramebufferCreateInfo fci = { VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1 };
17714 VkFramebuffer fb;
17715 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
17716 ASSERT_VK_SUCCESS(err);
17717
17718 // Record a single command buffer which issues a pipeline barrier w/
17719 // image memory barrier for the attachment. This detects the previously
17720 // missing tracking of the subpass layout by throwing a validation error
17721 // if it doesn't occur.
17722 VkRenderPassBeginInfo rpbi = { VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb,{ { 0, 0 },{ 32, 32 } }, 0, nullptr };
Tony Barbour552f6c02016-12-21 14:34:07 -070017723 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017724 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
17725
17726 VkImageMemoryBarrier imb = { VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,
17727 nullptr,
17728 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
17729 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
17730 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
17731 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
17732 VK_QUEUE_FAMILY_IGNORED,
17733 VK_QUEUE_FAMILY_IGNORED,
17734 image.handle(),
17735 { VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 } };
17736 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
17737 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_DEPENDENCY_BY_REGION_BIT, 0, nullptr, 0, nullptr, 1,
17738 &imb);
17739
17740 vkCmdEndRenderPass(m_commandBuffer->handle());
17741 m_errorMonitor->VerifyNotFound();
Tony Barbour552f6c02016-12-21 14:34:07 -070017742 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017743
17744 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
17745 vkDestroyRenderPass(m_device->device(), rp, nullptr);
17746 vkDestroyImageView(m_device->device(), view, nullptr);
17747}
17748
17749TEST_F(VkPositiveLayerTest, DepthStencilLayoutTransitionForDepthOnlyImageview) {
17750 TEST_DESCRIPTION("Validate that when an imageView of a depth/stencil image "
17751 "is used as a depth/stencil framebuffer attachment, the "
17752 "aspectMask is ignored and both depth and stencil image "
17753 "subresources are used.");
17754
17755 VkFormatProperties format_properties;
17756 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_D32_SFLOAT_S8_UINT, &format_properties);
17757 if (!(format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)) {
17758 return;
17759 }
17760
17761 m_errorMonitor->ExpectSuccess();
17762
17763 ASSERT_NO_FATAL_FAILURE(InitState());
17764
17765 VkAttachmentDescription attachment = { 0,
17766 VK_FORMAT_D32_SFLOAT_S8_UINT,
17767 VK_SAMPLE_COUNT_1_BIT,
17768 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
17769 VK_ATTACHMENT_STORE_OP_STORE,
17770 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
17771 VK_ATTACHMENT_STORE_OP_DONT_CARE,
17772 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
17773 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL };
17774
17775 VkAttachmentReference att_ref = { 0, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL };
17776
17777 VkSubpassDescription subpass = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, &att_ref, 0, nullptr };
17778
17779 VkSubpassDependency dep = { 0,
17780 0,
17781 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
17782 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
17783 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
17784 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
17785 VK_DEPENDENCY_BY_REGION_BIT};
17786
17787 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 1, &dep };
17788
17789 VkResult err;
17790 VkRenderPass rp;
17791 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
17792 ASSERT_VK_SUCCESS(err);
17793
17794 VkImageObj image(m_device);
17795 image.init_no_layout(32, 32, VK_FORMAT_D32_SFLOAT_S8_UINT,
17796 0x26, // usage
17797 VK_IMAGE_TILING_OPTIMAL, 0);
17798 ASSERT_TRUE(image.initialized());
17799 image.SetLayout(0x6, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL);
17800
17801 VkImageViewCreateInfo ivci = {
17802 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
17803 nullptr,
17804 0,
17805 image.handle(),
17806 VK_IMAGE_VIEW_TYPE_2D,
17807 VK_FORMAT_D32_SFLOAT_S8_UINT,
17808 { VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A },
17809 { 0x2, 0, 1, 0, 1 },
17810 };
17811 VkImageView view;
17812 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
17813 ASSERT_VK_SUCCESS(err);
17814
17815 VkFramebufferCreateInfo fci = { VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1 };
17816 VkFramebuffer fb;
17817 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
17818 ASSERT_VK_SUCCESS(err);
17819
17820 VkRenderPassBeginInfo rpbi = { VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb,{ { 0, 0 },{ 32, 32 } }, 0, nullptr };
Tony Barbour552f6c02016-12-21 14:34:07 -070017821 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017822 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
17823
17824 VkImageMemoryBarrier imb = {};
17825 imb.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
17826 imb.pNext = nullptr;
17827 imb.srcAccessMask = VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
17828 imb.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
17829 imb.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
17830 imb.newLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
17831 imb.srcQueueFamilyIndex = 0;
17832 imb.dstQueueFamilyIndex = 0;
17833 imb.image = image.handle();
17834 imb.subresourceRange.aspectMask = 0x6;
17835 imb.subresourceRange.baseMipLevel = 0;
17836 imb.subresourceRange.levelCount = 0x1;
17837 imb.subresourceRange.baseArrayLayer = 0;
17838 imb.subresourceRange.layerCount = 0x1;
17839
17840 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
17841 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_DEPENDENCY_BY_REGION_BIT, 0, nullptr, 0, nullptr, 1,
17842 &imb);
17843
17844 vkCmdEndRenderPass(m_commandBuffer->handle());
Tony Barbour552f6c02016-12-21 14:34:07 -070017845 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017846 QueueCommandBuffer(false);
17847 m_errorMonitor->VerifyNotFound();
17848
17849 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
17850 vkDestroyRenderPass(m_device->device(), rp, nullptr);
17851 vkDestroyImageView(m_device->device(), view, nullptr);
17852}
17853
17854TEST_F(VkPositiveLayerTest, RenderPassTransitionsAttachmentUnused) {
17855 TEST_DESCRIPTION("Ensure that layout transitions work correctly without "
17856 "errors, when an attachment reference is "
17857 "VK_ATTACHMENT_UNUSED");
17858
17859 m_errorMonitor->ExpectSuccess();
17860
17861 ASSERT_NO_FATAL_FAILURE(InitState());
17862
17863 // A renderpass with no attachments
17864 VkAttachmentReference att_ref = { VK_ATTACHMENT_UNUSED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
17865
17866 VkSubpassDescription subpass = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr };
17867
17868 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 1, &subpass, 0, nullptr };
17869
17870 VkRenderPass rp;
17871 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
17872 ASSERT_VK_SUCCESS(err);
17873
17874 // A compatible framebuffer.
17875 VkFramebufferCreateInfo fci = { VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 0, nullptr, 32, 32, 1 };
17876 VkFramebuffer fb;
17877 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
17878 ASSERT_VK_SUCCESS(err);
17879
17880 // Record a command buffer which just begins and ends the renderpass. The
17881 // bug manifests in BeginRenderPass.
17882 VkRenderPassBeginInfo rpbi = { VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb,{ { 0, 0 },{ 32, 32 } }, 0, nullptr };
Tony Barbour552f6c02016-12-21 14:34:07 -070017883 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017884 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
17885 vkCmdEndRenderPass(m_commandBuffer->handle());
17886 m_errorMonitor->VerifyNotFound();
Tony Barbour552f6c02016-12-21 14:34:07 -070017887 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017888
17889 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
17890 vkDestroyRenderPass(m_device->device(), rp, nullptr);
17891}
17892
17893// This is a positive test. No errors are expected.
17894TEST_F(VkPositiveLayerTest, StencilLoadOp) {
17895 TEST_DESCRIPTION("Create a stencil-only attachment with a LOAD_OP set to "
17896 "CLEAR. stencil[Load|Store]Op used to be ignored.");
17897 VkResult result = VK_SUCCESS;
17898 VkImageFormatProperties formatProps;
17899 vkGetPhysicalDeviceImageFormatProperties(gpu(), VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
17900 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT, 0,
17901 &formatProps);
17902 if (formatProps.maxExtent.width < 100 || formatProps.maxExtent.height < 100) {
17903 return;
17904 }
17905
17906 ASSERT_NO_FATAL_FAILURE(InitState());
17907 VkFormat depth_stencil_fmt = VK_FORMAT_D24_UNORM_S8_UINT;
17908 m_depthStencil->Init(m_device, 100, 100, depth_stencil_fmt,
17909 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT);
17910 VkAttachmentDescription att = {};
17911 VkAttachmentReference ref = {};
17912 att.format = depth_stencil_fmt;
17913 att.samples = VK_SAMPLE_COUNT_1_BIT;
17914 att.loadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
17915 att.storeOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
17916 att.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
17917 att.stencilStoreOp = VK_ATTACHMENT_STORE_OP_STORE;
17918 att.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
17919 att.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
17920
17921 VkClearValue clear;
17922 clear.depthStencil.depth = 1.0;
17923 clear.depthStencil.stencil = 0;
17924 ref.attachment = 0;
17925 ref.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
17926
17927 VkSubpassDescription subpass = {};
17928 subpass.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;
17929 subpass.flags = 0;
17930 subpass.inputAttachmentCount = 0;
17931 subpass.pInputAttachments = NULL;
17932 subpass.colorAttachmentCount = 0;
17933 subpass.pColorAttachments = NULL;
17934 subpass.pResolveAttachments = NULL;
17935 subpass.pDepthStencilAttachment = &ref;
17936 subpass.preserveAttachmentCount = 0;
17937 subpass.pPreserveAttachments = NULL;
17938
17939 VkRenderPass rp;
17940 VkRenderPassCreateInfo rp_info = {};
17941 rp_info.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
17942 rp_info.attachmentCount = 1;
17943 rp_info.pAttachments = &att;
17944 rp_info.subpassCount = 1;
17945 rp_info.pSubpasses = &subpass;
17946 result = vkCreateRenderPass(device(), &rp_info, NULL, &rp);
17947 ASSERT_VK_SUCCESS(result);
17948
17949 VkImageView *depthView = m_depthStencil->BindInfo();
17950 VkFramebufferCreateInfo fb_info = {};
17951 fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
17952 fb_info.pNext = NULL;
17953 fb_info.renderPass = rp;
17954 fb_info.attachmentCount = 1;
17955 fb_info.pAttachments = depthView;
17956 fb_info.width = 100;
17957 fb_info.height = 100;
17958 fb_info.layers = 1;
17959 VkFramebuffer fb;
17960 result = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
17961 ASSERT_VK_SUCCESS(result);
17962
17963 VkRenderPassBeginInfo rpbinfo = {};
17964 rpbinfo.clearValueCount = 1;
17965 rpbinfo.pClearValues = &clear;
17966 rpbinfo.pNext = NULL;
17967 rpbinfo.renderPass = rp;
17968 rpbinfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
17969 rpbinfo.renderArea.extent.width = 100;
17970 rpbinfo.renderArea.extent.height = 100;
17971 rpbinfo.renderArea.offset.x = 0;
17972 rpbinfo.renderArea.offset.y = 0;
17973 rpbinfo.framebuffer = fb;
17974
17975 VkFence fence = {};
17976 VkFenceCreateInfo fence_ci = {};
17977 fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
17978 fence_ci.pNext = nullptr;
17979 fence_ci.flags = 0;
17980 result = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fence);
17981 ASSERT_VK_SUCCESS(result);
17982
17983 m_commandBuffer->BeginCommandBuffer();
17984 m_commandBuffer->BeginRenderPass(rpbinfo);
17985 m_commandBuffer->EndRenderPass();
17986 m_commandBuffer->EndCommandBuffer();
17987 m_commandBuffer->QueueCommandBuffer(fence);
17988
17989 VkImageObj destImage(m_device);
17990 destImage.init(100, 100, depth_stencil_fmt, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
17991 VK_IMAGE_TILING_OPTIMAL, 0);
17992 VkImageMemoryBarrier barrier = {};
17993 VkImageSubresourceRange range;
17994 barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
17995 barrier.srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
17996 barrier.dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT;
17997 barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
17998 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
17999 barrier.image = m_depthStencil->handle();
18000 range.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
18001 range.baseMipLevel = 0;
18002 range.levelCount = 1;
18003 range.baseArrayLayer = 0;
18004 range.layerCount = 1;
18005 barrier.subresourceRange = range;
18006 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
18007 VkCommandBufferObj cmdbuf(m_device, m_commandPool);
18008 cmdbuf.BeginCommandBuffer();
18009 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
18010 &barrier);
18011 barrier.srcAccessMask = 0;
18012 barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
18013 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
18014 barrier.image = destImage.handle();
18015 barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
18016 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
18017 &barrier);
18018 VkImageCopy cregion;
18019 cregion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
18020 cregion.srcSubresource.mipLevel = 0;
18021 cregion.srcSubresource.baseArrayLayer = 0;
18022 cregion.srcSubresource.layerCount = 1;
18023 cregion.srcOffset.x = 0;
18024 cregion.srcOffset.y = 0;
18025 cregion.srcOffset.z = 0;
18026 cregion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
18027 cregion.dstSubresource.mipLevel = 0;
18028 cregion.dstSubresource.baseArrayLayer = 0;
18029 cregion.dstSubresource.layerCount = 1;
18030 cregion.dstOffset.x = 0;
18031 cregion.dstOffset.y = 0;
18032 cregion.dstOffset.z = 0;
18033 cregion.extent.width = 100;
18034 cregion.extent.height = 100;
18035 cregion.extent.depth = 1;
18036 cmdbuf.CopyImage(m_depthStencil->handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, destImage.handle(),
18037 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &cregion);
18038 cmdbuf.EndCommandBuffer();
18039
18040 VkSubmitInfo submit_info;
18041 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18042 submit_info.pNext = NULL;
18043 submit_info.waitSemaphoreCount = 0;
18044 submit_info.pWaitSemaphores = NULL;
18045 submit_info.pWaitDstStageMask = NULL;
18046 submit_info.commandBufferCount = 1;
18047 submit_info.pCommandBuffers = &cmdbuf.handle();
18048 submit_info.signalSemaphoreCount = 0;
18049 submit_info.pSignalSemaphores = NULL;
18050
18051 m_errorMonitor->ExpectSuccess();
18052 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
18053 m_errorMonitor->VerifyNotFound();
18054
18055 vkQueueWaitIdle(m_device->m_queue);
18056 vkDestroyFence(m_device->device(), fence, nullptr);
18057 vkDestroyRenderPass(m_device->device(), rp, nullptr);
18058 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
18059}
18060
18061// This is a positive test. No errors should be generated.
18062TEST_F(VkPositiveLayerTest, WaitEventThenSet) {
18063 TEST_DESCRIPTION("Wait on a event then set it after the wait has been submitted.");
18064
18065 m_errorMonitor->ExpectSuccess();
18066 ASSERT_NO_FATAL_FAILURE(InitState());
18067
18068 VkEvent event;
18069 VkEventCreateInfo event_create_info{};
18070 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
18071 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
18072
18073 VkCommandPool command_pool;
18074 VkCommandPoolCreateInfo pool_create_info{};
18075 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18076 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18077 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18078 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18079
18080 VkCommandBuffer command_buffer;
18081 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18082 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18083 command_buffer_allocate_info.commandPool = command_pool;
18084 command_buffer_allocate_info.commandBufferCount = 1;
18085 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18086 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
18087
18088 VkQueue queue = VK_NULL_HANDLE;
18089 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
18090
18091 {
18092 VkCommandBufferBeginInfo begin_info{};
18093 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18094 vkBeginCommandBuffer(command_buffer, &begin_info);
18095
18096 vkCmdWaitEvents(command_buffer, 1, &event, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, nullptr, 0,
18097 nullptr, 0, nullptr);
18098 vkCmdResetEvent(command_buffer, event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
18099 vkEndCommandBuffer(command_buffer);
18100 }
18101 {
18102 VkSubmitInfo submit_info{};
18103 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18104 submit_info.commandBufferCount = 1;
18105 submit_info.pCommandBuffers = &command_buffer;
18106 submit_info.signalSemaphoreCount = 0;
18107 submit_info.pSignalSemaphores = nullptr;
18108 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
18109 }
18110 { vkSetEvent(m_device->device(), event); }
18111
18112 vkQueueWaitIdle(queue);
18113
18114 vkDestroyEvent(m_device->device(), event, nullptr);
18115 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
18116 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18117
18118 m_errorMonitor->VerifyNotFound();
18119}
18120// This is a positive test. No errors should be generated.
18121TEST_F(VkPositiveLayerTest, QueryAndCopySecondaryCommandBuffers) {
18122 TEST_DESCRIPTION("Issue a query on a secondary command buffery and copy it on a primary.");
18123
18124 ASSERT_NO_FATAL_FAILURE(InitState());
18125 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
18126 return;
18127
18128 m_errorMonitor->ExpectSuccess();
18129
18130 VkQueryPool query_pool;
18131 VkQueryPoolCreateInfo query_pool_create_info{};
18132 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
18133 query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP;
18134 query_pool_create_info.queryCount = 1;
18135 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
18136
18137 VkCommandPool command_pool;
18138 VkCommandPoolCreateInfo pool_create_info{};
18139 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18140 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18141 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18142 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18143
18144 VkCommandBuffer command_buffer;
18145 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18146 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18147 command_buffer_allocate_info.commandPool = command_pool;
18148 command_buffer_allocate_info.commandBufferCount = 1;
18149 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18150 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
18151
18152 VkCommandBuffer secondary_command_buffer;
18153 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
18154 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer);
18155
18156 VkQueue queue = VK_NULL_HANDLE;
18157 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
18158
18159 uint32_t qfi = 0;
18160 VkBufferCreateInfo buff_create_info = {};
18161 buff_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
18162 buff_create_info.size = 1024;
18163 buff_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
18164 buff_create_info.queueFamilyIndexCount = 1;
18165 buff_create_info.pQueueFamilyIndices = &qfi;
18166
18167 VkResult err;
18168 VkBuffer buffer;
18169 err = vkCreateBuffer(m_device->device(), &buff_create_info, NULL, &buffer);
18170 ASSERT_VK_SUCCESS(err);
18171 VkMemoryAllocateInfo mem_alloc = {};
18172 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18173 mem_alloc.pNext = NULL;
18174 mem_alloc.allocationSize = 1024;
18175 mem_alloc.memoryTypeIndex = 0;
18176
18177 VkMemoryRequirements memReqs;
18178 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
18179 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
18180 if (!pass) {
18181 vkDestroyBuffer(m_device->device(), buffer, NULL);
18182 return;
18183 }
18184
18185 VkDeviceMemory mem;
18186 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
18187 ASSERT_VK_SUCCESS(err);
18188 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
18189 ASSERT_VK_SUCCESS(err);
18190
18191 VkCommandBufferInheritanceInfo hinfo = {};
18192 hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
18193 hinfo.renderPass = VK_NULL_HANDLE;
18194 hinfo.subpass = 0;
18195 hinfo.framebuffer = VK_NULL_HANDLE;
18196 hinfo.occlusionQueryEnable = VK_FALSE;
18197 hinfo.queryFlags = 0;
18198 hinfo.pipelineStatistics = 0;
18199
18200 {
18201 VkCommandBufferBeginInfo begin_info{};
18202 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18203 begin_info.pInheritanceInfo = &hinfo;
18204 vkBeginCommandBuffer(secondary_command_buffer, &begin_info);
18205
18206 vkCmdResetQueryPool(secondary_command_buffer, query_pool, 0, 1);
18207 vkCmdWriteTimestamp(secondary_command_buffer, VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0);
18208
18209 vkEndCommandBuffer(secondary_command_buffer);
18210
18211 begin_info.pInheritanceInfo = nullptr;
18212 vkBeginCommandBuffer(command_buffer, &begin_info);
18213
18214 vkCmdExecuteCommands(command_buffer, 1, &secondary_command_buffer);
18215 vkCmdCopyQueryPoolResults(command_buffer, query_pool, 0, 1, buffer, 0, 0, 0);
18216
18217 vkEndCommandBuffer(command_buffer);
18218 }
18219 {
18220 VkSubmitInfo submit_info{};
18221 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18222 submit_info.commandBufferCount = 1;
18223 submit_info.pCommandBuffers = &command_buffer;
18224 submit_info.signalSemaphoreCount = 0;
18225 submit_info.pSignalSemaphores = nullptr;
18226 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
18227 }
18228
18229 vkQueueWaitIdle(queue);
18230
18231 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
18232 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
18233 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &secondary_command_buffer);
18234 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18235 vkDestroyBuffer(m_device->device(), buffer, NULL);
18236 vkFreeMemory(m_device->device(), mem, NULL);
18237
18238 m_errorMonitor->VerifyNotFound();
18239}
18240
18241// This is a positive test. No errors should be generated.
18242TEST_F(VkPositiveLayerTest, QueryAndCopyMultipleCommandBuffers) {
18243 TEST_DESCRIPTION("Issue a query and copy from it on a second command buffer.");
18244
18245 ASSERT_NO_FATAL_FAILURE(InitState());
18246 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
18247 return;
18248
18249 m_errorMonitor->ExpectSuccess();
18250
18251 VkQueryPool query_pool;
18252 VkQueryPoolCreateInfo query_pool_create_info{};
18253 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
18254 query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP;
18255 query_pool_create_info.queryCount = 1;
18256 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
18257
18258 VkCommandPool command_pool;
18259 VkCommandPoolCreateInfo pool_create_info{};
18260 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18261 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18262 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18263 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18264
18265 VkCommandBuffer command_buffer[2];
18266 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18267 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18268 command_buffer_allocate_info.commandPool = command_pool;
18269 command_buffer_allocate_info.commandBufferCount = 2;
18270 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18271 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18272
18273 VkQueue queue = VK_NULL_HANDLE;
18274 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
18275
18276 uint32_t qfi = 0;
18277 VkBufferCreateInfo buff_create_info = {};
18278 buff_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
18279 buff_create_info.size = 1024;
18280 buff_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
18281 buff_create_info.queueFamilyIndexCount = 1;
18282 buff_create_info.pQueueFamilyIndices = &qfi;
18283
18284 VkResult err;
18285 VkBuffer buffer;
18286 err = vkCreateBuffer(m_device->device(), &buff_create_info, NULL, &buffer);
18287 ASSERT_VK_SUCCESS(err);
18288 VkMemoryAllocateInfo mem_alloc = {};
18289 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18290 mem_alloc.pNext = NULL;
18291 mem_alloc.allocationSize = 1024;
18292 mem_alloc.memoryTypeIndex = 0;
18293
18294 VkMemoryRequirements memReqs;
18295 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
18296 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
18297 if (!pass) {
18298 vkDestroyBuffer(m_device->device(), buffer, NULL);
18299 return;
18300 }
18301
18302 VkDeviceMemory mem;
18303 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
18304 ASSERT_VK_SUCCESS(err);
18305 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
18306 ASSERT_VK_SUCCESS(err);
18307
18308 {
18309 VkCommandBufferBeginInfo begin_info{};
18310 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18311 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18312
18313 vkCmdResetQueryPool(command_buffer[0], query_pool, 0, 1);
18314 vkCmdWriteTimestamp(command_buffer[0], VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0);
18315
18316 vkEndCommandBuffer(command_buffer[0]);
18317
18318 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18319
18320 vkCmdCopyQueryPoolResults(command_buffer[1], query_pool, 0, 1, buffer, 0, 0, 0);
18321
18322 vkEndCommandBuffer(command_buffer[1]);
18323 }
18324 {
18325 VkSubmitInfo submit_info{};
18326 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18327 submit_info.commandBufferCount = 2;
18328 submit_info.pCommandBuffers = command_buffer;
18329 submit_info.signalSemaphoreCount = 0;
18330 submit_info.pSignalSemaphores = nullptr;
18331 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
18332 }
18333
18334 vkQueueWaitIdle(queue);
18335
18336 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
18337 vkFreeCommandBuffers(m_device->device(), command_pool, 2, command_buffer);
18338 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18339 vkDestroyBuffer(m_device->device(), buffer, NULL);
18340 vkFreeMemory(m_device->device(), mem, NULL);
18341
18342 m_errorMonitor->VerifyNotFound();
18343}
18344
Tony Barbourc46924f2016-11-04 11:49:52 -060018345TEST_F(VkLayerTest, ResetEventThenSet) {
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018346 TEST_DESCRIPTION("Reset an event then set it after the reset has been submitted.");
18347
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018348 ASSERT_NO_FATAL_FAILURE(InitState());
18349 VkEvent event;
18350 VkEventCreateInfo event_create_info{};
18351 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
18352 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
18353
18354 VkCommandPool command_pool;
18355 VkCommandPoolCreateInfo pool_create_info{};
18356 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18357 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18358 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18359 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18360
18361 VkCommandBuffer command_buffer;
18362 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18363 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18364 command_buffer_allocate_info.commandPool = command_pool;
18365 command_buffer_allocate_info.commandBufferCount = 1;
18366 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18367 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
18368
18369 VkQueue queue = VK_NULL_HANDLE;
18370 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
18371
18372 {
18373 VkCommandBufferBeginInfo begin_info{};
18374 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18375 vkBeginCommandBuffer(command_buffer, &begin_info);
18376
18377 vkCmdResetEvent(command_buffer, event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018378 vkEndCommandBuffer(command_buffer);
18379 }
18380 {
18381 VkSubmitInfo submit_info{};
18382 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18383 submit_info.commandBufferCount = 1;
18384 submit_info.pCommandBuffers = &command_buffer;
18385 submit_info.signalSemaphoreCount = 0;
18386 submit_info.pSignalSemaphores = nullptr;
18387 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
18388 }
18389 {
18390 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is already in use by a "
18391 "command buffer.");
18392 vkSetEvent(m_device->device(), event);
18393 m_errorMonitor->VerifyFound();
18394 }
18395
18396 vkQueueWaitIdle(queue);
18397
18398 vkDestroyEvent(m_device->device(), event, nullptr);
18399 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
18400 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18401}
18402
18403// This is a positive test. No errors should be generated.
18404TEST_F(VkPositiveLayerTest, TwoFencesThreeFrames) {
18405 TEST_DESCRIPTION("Two command buffers with two separate fences are each "
18406 "run through a Submit & WaitForFences cycle 3 times. This "
18407 "previously revealed a bug so running this positive test "
18408 "to prevent a regression.");
18409 m_errorMonitor->ExpectSuccess();
18410
18411 ASSERT_NO_FATAL_FAILURE(InitState());
18412 VkQueue queue = VK_NULL_HANDLE;
18413 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
18414
18415 static const uint32_t NUM_OBJECTS = 2;
18416 static const uint32_t NUM_FRAMES = 3;
18417 VkCommandBuffer cmd_buffers[NUM_OBJECTS] = {};
18418 VkFence fences[NUM_OBJECTS] = {};
18419
18420 VkCommandPool cmd_pool;
18421 VkCommandPoolCreateInfo cmd_pool_ci = {};
18422 cmd_pool_ci.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18423 cmd_pool_ci.queueFamilyIndex = m_device->graphics_queue_node_index_;
18424 cmd_pool_ci.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18425 VkResult err = vkCreateCommandPool(m_device->device(), &cmd_pool_ci, nullptr, &cmd_pool);
18426 ASSERT_VK_SUCCESS(err);
18427
18428 VkCommandBufferAllocateInfo cmd_buf_info = {};
18429 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18430 cmd_buf_info.commandPool = cmd_pool;
18431 cmd_buf_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18432 cmd_buf_info.commandBufferCount = 1;
18433
18434 VkFenceCreateInfo fence_ci = {};
18435 fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18436 fence_ci.pNext = nullptr;
18437 fence_ci.flags = 0;
18438
18439 for (uint32_t i = 0; i < NUM_OBJECTS; ++i) {
18440 err = vkAllocateCommandBuffers(m_device->device(), &cmd_buf_info, &cmd_buffers[i]);
18441 ASSERT_VK_SUCCESS(err);
18442 err = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fences[i]);
18443 ASSERT_VK_SUCCESS(err);
18444 }
18445
18446 for (uint32_t frame = 0; frame < NUM_FRAMES; ++frame) {
18447 for (uint32_t obj = 0; obj < NUM_OBJECTS; ++obj) {
18448 // Create empty cmd buffer
18449 VkCommandBufferBeginInfo cmdBufBeginDesc = {};
18450 cmdBufBeginDesc.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18451
18452 err = vkBeginCommandBuffer(cmd_buffers[obj], &cmdBufBeginDesc);
18453 ASSERT_VK_SUCCESS(err);
18454 err = vkEndCommandBuffer(cmd_buffers[obj]);
18455 ASSERT_VK_SUCCESS(err);
18456
18457 VkSubmitInfo submit_info = {};
18458 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18459 submit_info.commandBufferCount = 1;
18460 submit_info.pCommandBuffers = &cmd_buffers[obj];
18461 // Submit cmd buffer and wait for fence
18462 err = vkQueueSubmit(queue, 1, &submit_info, fences[obj]);
18463 ASSERT_VK_SUCCESS(err);
18464 err = vkWaitForFences(m_device->device(), 1, &fences[obj], VK_TRUE, UINT64_MAX);
18465 ASSERT_VK_SUCCESS(err);
18466 err = vkResetFences(m_device->device(), 1, &fences[obj]);
18467 ASSERT_VK_SUCCESS(err);
18468 }
18469 }
18470 m_errorMonitor->VerifyNotFound();
18471 vkDestroyCommandPool(m_device->device(), cmd_pool, NULL);
18472 for (uint32_t i = 0; i < NUM_OBJECTS; ++i) {
18473 vkDestroyFence(m_device->device(), fences[i], nullptr);
18474 }
18475}
18476// This is a positive test. No errors should be generated.
18477TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWI) {
18478
18479 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
18480 "submitted on separate queues followed by a QueueWaitIdle.");
18481
18482 ASSERT_NO_FATAL_FAILURE(InitState());
18483 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
18484 return;
18485
18486 m_errorMonitor->ExpectSuccess();
18487
18488 VkSemaphore semaphore;
18489 VkSemaphoreCreateInfo semaphore_create_info{};
18490 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
18491 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
18492
18493 VkCommandPool command_pool;
18494 VkCommandPoolCreateInfo pool_create_info{};
18495 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18496 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18497 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18498 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18499
18500 VkCommandBuffer command_buffer[2];
18501 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18502 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18503 command_buffer_allocate_info.commandPool = command_pool;
18504 command_buffer_allocate_info.commandBufferCount = 2;
18505 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18506 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18507
18508 VkQueue queue = VK_NULL_HANDLE;
18509 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
18510
18511 {
18512 VkCommandBufferBeginInfo begin_info{};
18513 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18514 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18515
18516 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
18517 nullptr, 0, nullptr, 0, nullptr);
18518
18519 VkViewport viewport{};
18520 viewport.maxDepth = 1.0f;
18521 viewport.minDepth = 0.0f;
18522 viewport.width = 512;
18523 viewport.height = 512;
18524 viewport.x = 0;
18525 viewport.y = 0;
18526 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
18527 vkEndCommandBuffer(command_buffer[0]);
18528 }
18529 {
18530 VkCommandBufferBeginInfo begin_info{};
18531 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18532 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18533
18534 VkViewport viewport{};
18535 viewport.maxDepth = 1.0f;
18536 viewport.minDepth = 0.0f;
18537 viewport.width = 512;
18538 viewport.height = 512;
18539 viewport.x = 0;
18540 viewport.y = 0;
18541 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
18542 vkEndCommandBuffer(command_buffer[1]);
18543 }
18544 {
18545 VkSubmitInfo submit_info{};
18546 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18547 submit_info.commandBufferCount = 1;
18548 submit_info.pCommandBuffers = &command_buffer[0];
18549 submit_info.signalSemaphoreCount = 1;
18550 submit_info.pSignalSemaphores = &semaphore;
18551 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
18552 }
18553 {
18554 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
18555 VkSubmitInfo submit_info{};
18556 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18557 submit_info.commandBufferCount = 1;
18558 submit_info.pCommandBuffers = &command_buffer[1];
18559 submit_info.waitSemaphoreCount = 1;
18560 submit_info.pWaitSemaphores = &semaphore;
18561 submit_info.pWaitDstStageMask = flags;
18562 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
18563 }
18564
18565 vkQueueWaitIdle(m_device->m_queue);
18566
18567 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
18568 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
18569 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18570
18571 m_errorMonitor->VerifyNotFound();
18572}
18573
18574// This is a positive test. No errors should be generated.
18575TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWIFence) {
18576
18577 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
18578 "submitted on separate queues, the second having a fence"
18579 "followed by a QueueWaitIdle.");
18580
18581 ASSERT_NO_FATAL_FAILURE(InitState());
18582 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
18583 return;
18584
18585 m_errorMonitor->ExpectSuccess();
18586
18587 VkFence fence;
18588 VkFenceCreateInfo fence_create_info{};
18589 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18590 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
18591
18592 VkSemaphore semaphore;
18593 VkSemaphoreCreateInfo semaphore_create_info{};
18594 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
18595 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
18596
18597 VkCommandPool command_pool;
18598 VkCommandPoolCreateInfo pool_create_info{};
18599 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18600 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18601 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18602 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18603
18604 VkCommandBuffer command_buffer[2];
18605 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18606 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18607 command_buffer_allocate_info.commandPool = command_pool;
18608 command_buffer_allocate_info.commandBufferCount = 2;
18609 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18610 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18611
18612 VkQueue queue = VK_NULL_HANDLE;
18613 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
18614
18615 {
18616 VkCommandBufferBeginInfo begin_info{};
18617 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18618 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18619
18620 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
18621 nullptr, 0, nullptr, 0, nullptr);
18622
18623 VkViewport viewport{};
18624 viewport.maxDepth = 1.0f;
18625 viewport.minDepth = 0.0f;
18626 viewport.width = 512;
18627 viewport.height = 512;
18628 viewport.x = 0;
18629 viewport.y = 0;
18630 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
18631 vkEndCommandBuffer(command_buffer[0]);
18632 }
18633 {
18634 VkCommandBufferBeginInfo begin_info{};
18635 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18636 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18637
18638 VkViewport viewport{};
18639 viewport.maxDepth = 1.0f;
18640 viewport.minDepth = 0.0f;
18641 viewport.width = 512;
18642 viewport.height = 512;
18643 viewport.x = 0;
18644 viewport.y = 0;
18645 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
18646 vkEndCommandBuffer(command_buffer[1]);
18647 }
18648 {
18649 VkSubmitInfo submit_info{};
18650 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18651 submit_info.commandBufferCount = 1;
18652 submit_info.pCommandBuffers = &command_buffer[0];
18653 submit_info.signalSemaphoreCount = 1;
18654 submit_info.pSignalSemaphores = &semaphore;
18655 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
18656 }
18657 {
18658 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
18659 VkSubmitInfo submit_info{};
18660 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18661 submit_info.commandBufferCount = 1;
18662 submit_info.pCommandBuffers = &command_buffer[1];
18663 submit_info.waitSemaphoreCount = 1;
18664 submit_info.pWaitSemaphores = &semaphore;
18665 submit_info.pWaitDstStageMask = flags;
18666 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
18667 }
18668
18669 vkQueueWaitIdle(m_device->m_queue);
18670
18671 vkDestroyFence(m_device->device(), fence, nullptr);
18672 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
18673 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
18674 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18675
18676 m_errorMonitor->VerifyNotFound();
18677}
18678
18679// This is a positive test. No errors should be generated.
18680TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceTwoWFF) {
18681
18682 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
18683 "submitted on separate queues, the second having a fence"
18684 "followed by two consecutive WaitForFences calls on the same fence.");
18685
18686 ASSERT_NO_FATAL_FAILURE(InitState());
18687 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
18688 return;
18689
18690 m_errorMonitor->ExpectSuccess();
18691
18692 VkFence fence;
18693 VkFenceCreateInfo fence_create_info{};
18694 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18695 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
18696
18697 VkSemaphore semaphore;
18698 VkSemaphoreCreateInfo semaphore_create_info{};
18699 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
18700 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
18701
18702 VkCommandPool command_pool;
18703 VkCommandPoolCreateInfo pool_create_info{};
18704 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18705 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18706 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18707 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18708
18709 VkCommandBuffer command_buffer[2];
18710 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18711 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18712 command_buffer_allocate_info.commandPool = command_pool;
18713 command_buffer_allocate_info.commandBufferCount = 2;
18714 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18715 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18716
18717 VkQueue queue = VK_NULL_HANDLE;
18718 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
18719
18720 {
18721 VkCommandBufferBeginInfo begin_info{};
18722 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18723 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18724
18725 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
18726 nullptr, 0, nullptr, 0, nullptr);
18727
18728 VkViewport viewport{};
18729 viewport.maxDepth = 1.0f;
18730 viewport.minDepth = 0.0f;
18731 viewport.width = 512;
18732 viewport.height = 512;
18733 viewport.x = 0;
18734 viewport.y = 0;
18735 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
18736 vkEndCommandBuffer(command_buffer[0]);
18737 }
18738 {
18739 VkCommandBufferBeginInfo begin_info{};
18740 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18741 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18742
18743 VkViewport viewport{};
18744 viewport.maxDepth = 1.0f;
18745 viewport.minDepth = 0.0f;
18746 viewport.width = 512;
18747 viewport.height = 512;
18748 viewport.x = 0;
18749 viewport.y = 0;
18750 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
18751 vkEndCommandBuffer(command_buffer[1]);
18752 }
18753 {
18754 VkSubmitInfo submit_info{};
18755 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18756 submit_info.commandBufferCount = 1;
18757 submit_info.pCommandBuffers = &command_buffer[0];
18758 submit_info.signalSemaphoreCount = 1;
18759 submit_info.pSignalSemaphores = &semaphore;
18760 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
18761 }
18762 {
18763 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
18764 VkSubmitInfo submit_info{};
18765 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18766 submit_info.commandBufferCount = 1;
18767 submit_info.pCommandBuffers = &command_buffer[1];
18768 submit_info.waitSemaphoreCount = 1;
18769 submit_info.pWaitSemaphores = &semaphore;
18770 submit_info.pWaitDstStageMask = flags;
18771 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
18772 }
18773
18774 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
18775 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
18776
18777 vkDestroyFence(m_device->device(), fence, nullptr);
18778 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
18779 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
18780 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18781
18782 m_errorMonitor->VerifyNotFound();
18783}
18784
18785TEST_F(VkPositiveLayerTest, TwoQueuesEnsureCorrectRetirementWithWorkStolen) {
18786
18787 ASSERT_NO_FATAL_FAILURE(InitState());
18788 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) {
18789 printf("Test requires two queues, skipping\n");
18790 return;
18791 }
18792
18793 VkResult err;
18794
18795 m_errorMonitor->ExpectSuccess();
18796
18797 VkQueue q0 = m_device->m_queue;
18798 VkQueue q1 = nullptr;
18799 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &q1);
18800 ASSERT_NE(q1, nullptr);
18801
18802 // An (empty) command buffer. We must have work in the first submission --
18803 // the layer treats unfenced work differently from fenced work.
18804 VkCommandPoolCreateInfo cpci = { VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, nullptr, 0, 0 };
18805 VkCommandPool pool;
18806 err = vkCreateCommandPool(m_device->device(), &cpci, nullptr, &pool);
18807 ASSERT_VK_SUCCESS(err);
18808 VkCommandBufferAllocateInfo cbai = { VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, nullptr, pool,
18809 VK_COMMAND_BUFFER_LEVEL_PRIMARY, 1 };
18810 VkCommandBuffer cb;
18811 err = vkAllocateCommandBuffers(m_device->device(), &cbai, &cb);
18812 ASSERT_VK_SUCCESS(err);
18813 VkCommandBufferBeginInfo cbbi = { VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr, 0, nullptr };
18814 err = vkBeginCommandBuffer(cb, &cbbi);
18815 ASSERT_VK_SUCCESS(err);
18816 err = vkEndCommandBuffer(cb);
18817 ASSERT_VK_SUCCESS(err);
18818
18819 // A semaphore
18820 VkSemaphoreCreateInfo sci = { VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0 };
18821 VkSemaphore s;
18822 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s);
18823 ASSERT_VK_SUCCESS(err);
18824
18825 // First submission, to q0
18826 VkSubmitInfo s0 = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 1, &cb, 1, &s };
18827
18828 err = vkQueueSubmit(q0, 1, &s0, VK_NULL_HANDLE);
18829 ASSERT_VK_SUCCESS(err);
18830
18831 // Second submission, to q1, waiting on s
18832 VkFlags waitmask = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT; // doesn't really matter what this value is.
18833 VkSubmitInfo s1 = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 1, &s, &waitmask, 0, nullptr, 0, nullptr };
18834
18835 err = vkQueueSubmit(q1, 1, &s1, VK_NULL_HANDLE);
18836 ASSERT_VK_SUCCESS(err);
18837
18838 // Wait for q0 idle
18839 err = vkQueueWaitIdle(q0);
18840 ASSERT_VK_SUCCESS(err);
18841
18842 // Command buffer should have been completed (it was on q0); reset the pool.
18843 vkFreeCommandBuffers(m_device->device(), pool, 1, &cb);
18844
18845 m_errorMonitor->VerifyNotFound();
18846
18847 // Force device completely idle and clean up resources
18848 vkDeviceWaitIdle(m_device->device());
18849 vkDestroyCommandPool(m_device->device(), pool, nullptr);
18850 vkDestroySemaphore(m_device->device(), s, nullptr);
18851}
18852
18853// This is a positive test. No errors should be generated.
18854TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFence) {
18855
18856 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
18857 "submitted on separate queues, the second having a fence, "
18858 "followed by a WaitForFences call.");
18859
18860 ASSERT_NO_FATAL_FAILURE(InitState());
18861 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
18862 return;
18863
18864 m_errorMonitor->ExpectSuccess();
18865
18866 ASSERT_NO_FATAL_FAILURE(InitState());
18867 VkFence fence;
18868 VkFenceCreateInfo fence_create_info{};
18869 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18870 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
18871
18872 VkSemaphore semaphore;
18873 VkSemaphoreCreateInfo semaphore_create_info{};
18874 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
18875 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
18876
18877 VkCommandPool command_pool;
18878 VkCommandPoolCreateInfo pool_create_info{};
18879 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18880 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18881 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18882 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18883
18884 VkCommandBuffer command_buffer[2];
18885 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18886 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18887 command_buffer_allocate_info.commandPool = command_pool;
18888 command_buffer_allocate_info.commandBufferCount = 2;
18889 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18890 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18891
18892 VkQueue queue = VK_NULL_HANDLE;
18893 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
18894
18895 {
18896 VkCommandBufferBeginInfo begin_info{};
18897 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18898 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18899
18900 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
18901 nullptr, 0, nullptr, 0, nullptr);
18902
18903 VkViewport viewport{};
18904 viewport.maxDepth = 1.0f;
18905 viewport.minDepth = 0.0f;
18906 viewport.width = 512;
18907 viewport.height = 512;
18908 viewport.x = 0;
18909 viewport.y = 0;
18910 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
18911 vkEndCommandBuffer(command_buffer[0]);
18912 }
18913 {
18914 VkCommandBufferBeginInfo begin_info{};
18915 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18916 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18917
18918 VkViewport viewport{};
18919 viewport.maxDepth = 1.0f;
18920 viewport.minDepth = 0.0f;
18921 viewport.width = 512;
18922 viewport.height = 512;
18923 viewport.x = 0;
18924 viewport.y = 0;
18925 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
18926 vkEndCommandBuffer(command_buffer[1]);
18927 }
18928 {
18929 VkSubmitInfo submit_info{};
18930 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18931 submit_info.commandBufferCount = 1;
18932 submit_info.pCommandBuffers = &command_buffer[0];
18933 submit_info.signalSemaphoreCount = 1;
18934 submit_info.pSignalSemaphores = &semaphore;
18935 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
18936 }
18937 {
18938 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
18939 VkSubmitInfo submit_info{};
18940 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18941 submit_info.commandBufferCount = 1;
18942 submit_info.pCommandBuffers = &command_buffer[1];
18943 submit_info.waitSemaphoreCount = 1;
18944 submit_info.pWaitSemaphores = &semaphore;
18945 submit_info.pWaitDstStageMask = flags;
18946 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
18947 }
18948
18949 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
18950
18951 vkDestroyFence(m_device->device(), fence, nullptr);
18952 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
18953 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
18954 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18955
18956 m_errorMonitor->VerifyNotFound();
18957}
18958
18959// This is a positive test. No errors should be generated.
18960TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueWithSemaphoreAndOneFence) {
18961
18962 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
18963 "on the same queue, sharing a signal/wait semaphore, the "
18964 "second having a fence, "
18965 "followed by a WaitForFences call.");
18966
18967 m_errorMonitor->ExpectSuccess();
18968
18969 ASSERT_NO_FATAL_FAILURE(InitState());
18970 VkFence fence;
18971 VkFenceCreateInfo fence_create_info{};
18972 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18973 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
18974
18975 VkSemaphore semaphore;
18976 VkSemaphoreCreateInfo semaphore_create_info{};
18977 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
18978 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
18979
18980 VkCommandPool command_pool;
18981 VkCommandPoolCreateInfo pool_create_info{};
18982 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18983 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18984 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18985 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18986
18987 VkCommandBuffer command_buffer[2];
18988 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18989 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18990 command_buffer_allocate_info.commandPool = command_pool;
18991 command_buffer_allocate_info.commandBufferCount = 2;
18992 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18993 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18994
18995 {
18996 VkCommandBufferBeginInfo begin_info{};
18997 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18998 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18999
19000 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
19001 nullptr, 0, nullptr, 0, nullptr);
19002
19003 VkViewport viewport{};
19004 viewport.maxDepth = 1.0f;
19005 viewport.minDepth = 0.0f;
19006 viewport.width = 512;
19007 viewport.height = 512;
19008 viewport.x = 0;
19009 viewport.y = 0;
19010 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
19011 vkEndCommandBuffer(command_buffer[0]);
19012 }
19013 {
19014 VkCommandBufferBeginInfo begin_info{};
19015 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19016 vkBeginCommandBuffer(command_buffer[1], &begin_info);
19017
19018 VkViewport viewport{};
19019 viewport.maxDepth = 1.0f;
19020 viewport.minDepth = 0.0f;
19021 viewport.width = 512;
19022 viewport.height = 512;
19023 viewport.x = 0;
19024 viewport.y = 0;
19025 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
19026 vkEndCommandBuffer(command_buffer[1]);
19027 }
19028 {
19029 VkSubmitInfo submit_info{};
19030 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19031 submit_info.commandBufferCount = 1;
19032 submit_info.pCommandBuffers = &command_buffer[0];
19033 submit_info.signalSemaphoreCount = 1;
19034 submit_info.pSignalSemaphores = &semaphore;
19035 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
19036 }
19037 {
19038 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
19039 VkSubmitInfo submit_info{};
19040 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19041 submit_info.commandBufferCount = 1;
19042 submit_info.pCommandBuffers = &command_buffer[1];
19043 submit_info.waitSemaphoreCount = 1;
19044 submit_info.pWaitSemaphores = &semaphore;
19045 submit_info.pWaitDstStageMask = flags;
19046 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
19047 }
19048
19049 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
19050
19051 vkDestroyFence(m_device->device(), fence, nullptr);
19052 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
19053 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
19054 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
19055
19056 m_errorMonitor->VerifyNotFound();
19057}
19058
19059// This is a positive test. No errors should be generated.
19060TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueNullQueueSubmitWithFence) {
19061
19062 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
19063 "on the same queue, no fences, followed by a third QueueSubmit with NO "
19064 "SubmitInfos but with a fence, followed by a WaitForFences call.");
19065
19066 m_errorMonitor->ExpectSuccess();
19067
19068 ASSERT_NO_FATAL_FAILURE(InitState());
19069 VkFence fence;
19070 VkFenceCreateInfo fence_create_info{};
19071 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
19072 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
19073
19074 VkCommandPool command_pool;
19075 VkCommandPoolCreateInfo pool_create_info{};
19076 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
19077 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
19078 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
19079 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
19080
19081 VkCommandBuffer command_buffer[2];
19082 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
19083 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
19084 command_buffer_allocate_info.commandPool = command_pool;
19085 command_buffer_allocate_info.commandBufferCount = 2;
19086 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
19087 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
19088
19089 {
19090 VkCommandBufferBeginInfo begin_info{};
19091 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19092 vkBeginCommandBuffer(command_buffer[0], &begin_info);
19093
19094 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
19095 nullptr, 0, nullptr, 0, nullptr);
19096
19097 VkViewport viewport{};
19098 viewport.maxDepth = 1.0f;
19099 viewport.minDepth = 0.0f;
19100 viewport.width = 512;
19101 viewport.height = 512;
19102 viewport.x = 0;
19103 viewport.y = 0;
19104 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
19105 vkEndCommandBuffer(command_buffer[0]);
19106 }
19107 {
19108 VkCommandBufferBeginInfo begin_info{};
19109 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19110 vkBeginCommandBuffer(command_buffer[1], &begin_info);
19111
19112 VkViewport viewport{};
19113 viewport.maxDepth = 1.0f;
19114 viewport.minDepth = 0.0f;
19115 viewport.width = 512;
19116 viewport.height = 512;
19117 viewport.x = 0;
19118 viewport.y = 0;
19119 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
19120 vkEndCommandBuffer(command_buffer[1]);
19121 }
19122 {
19123 VkSubmitInfo submit_info{};
19124 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19125 submit_info.commandBufferCount = 1;
19126 submit_info.pCommandBuffers = &command_buffer[0];
19127 submit_info.signalSemaphoreCount = 0;
19128 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
19129 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
19130 }
19131 {
19132 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
19133 VkSubmitInfo submit_info{};
19134 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19135 submit_info.commandBufferCount = 1;
19136 submit_info.pCommandBuffers = &command_buffer[1];
19137 submit_info.waitSemaphoreCount = 0;
19138 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
19139 submit_info.pWaitDstStageMask = flags;
19140 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
19141 }
19142
19143 vkQueueSubmit(m_device->m_queue, 0, NULL, fence);
19144
19145 VkResult err = vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
19146 ASSERT_VK_SUCCESS(err);
19147
19148 vkDestroyFence(m_device->device(), fence, nullptr);
19149 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
19150 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
19151
19152 m_errorMonitor->VerifyNotFound();
19153}
19154
19155// This is a positive test. No errors should be generated.
19156TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueOneFence) {
19157
19158 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
19159 "on the same queue, the second having a fence, followed "
19160 "by a WaitForFences call.");
19161
19162 m_errorMonitor->ExpectSuccess();
19163
19164 ASSERT_NO_FATAL_FAILURE(InitState());
19165 VkFence fence;
19166 VkFenceCreateInfo fence_create_info{};
19167 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
19168 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
19169
19170 VkCommandPool command_pool;
19171 VkCommandPoolCreateInfo pool_create_info{};
19172 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
19173 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
19174 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
19175 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
19176
19177 VkCommandBuffer command_buffer[2];
19178 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
19179 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
19180 command_buffer_allocate_info.commandPool = command_pool;
19181 command_buffer_allocate_info.commandBufferCount = 2;
19182 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
19183 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
19184
19185 {
19186 VkCommandBufferBeginInfo begin_info{};
19187 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19188 vkBeginCommandBuffer(command_buffer[0], &begin_info);
19189
19190 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
19191 nullptr, 0, nullptr, 0, nullptr);
19192
19193 VkViewport viewport{};
19194 viewport.maxDepth = 1.0f;
19195 viewport.minDepth = 0.0f;
19196 viewport.width = 512;
19197 viewport.height = 512;
19198 viewport.x = 0;
19199 viewport.y = 0;
19200 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
19201 vkEndCommandBuffer(command_buffer[0]);
19202 }
19203 {
19204 VkCommandBufferBeginInfo begin_info{};
19205 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19206 vkBeginCommandBuffer(command_buffer[1], &begin_info);
19207
19208 VkViewport viewport{};
19209 viewport.maxDepth = 1.0f;
19210 viewport.minDepth = 0.0f;
19211 viewport.width = 512;
19212 viewport.height = 512;
19213 viewport.x = 0;
19214 viewport.y = 0;
19215 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
19216 vkEndCommandBuffer(command_buffer[1]);
19217 }
19218 {
19219 VkSubmitInfo submit_info{};
19220 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19221 submit_info.commandBufferCount = 1;
19222 submit_info.pCommandBuffers = &command_buffer[0];
19223 submit_info.signalSemaphoreCount = 0;
19224 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
19225 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
19226 }
19227 {
19228 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
19229 VkSubmitInfo submit_info{};
19230 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19231 submit_info.commandBufferCount = 1;
19232 submit_info.pCommandBuffers = &command_buffer[1];
19233 submit_info.waitSemaphoreCount = 0;
19234 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
19235 submit_info.pWaitDstStageMask = flags;
19236 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
19237 }
19238
19239 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
19240
19241 vkDestroyFence(m_device->device(), fence, nullptr);
19242 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
19243 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
19244
19245 m_errorMonitor->VerifyNotFound();
19246}
19247
19248// This is a positive test. No errors should be generated.
19249TEST_F(VkPositiveLayerTest, TwoSubmitInfosWithSemaphoreOneQueueSubmitsOneFence) {
19250
19251 TEST_DESCRIPTION("Two command buffers each in a separate SubmitInfo sent in a single "
19252 "QueueSubmit call followed by a WaitForFences call.");
19253 ASSERT_NO_FATAL_FAILURE(InitState());
19254
19255 m_errorMonitor->ExpectSuccess();
19256
19257 VkFence fence;
19258 VkFenceCreateInfo fence_create_info{};
19259 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
19260 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
19261
19262 VkSemaphore semaphore;
19263 VkSemaphoreCreateInfo semaphore_create_info{};
19264 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
19265 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
19266
19267 VkCommandPool command_pool;
19268 VkCommandPoolCreateInfo pool_create_info{};
19269 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
19270 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
19271 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
19272 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
19273
19274 VkCommandBuffer command_buffer[2];
19275 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
19276 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
19277 command_buffer_allocate_info.commandPool = command_pool;
19278 command_buffer_allocate_info.commandBufferCount = 2;
19279 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
19280 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
19281
19282 {
19283 VkCommandBufferBeginInfo begin_info{};
19284 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19285 vkBeginCommandBuffer(command_buffer[0], &begin_info);
19286
19287 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
19288 nullptr, 0, nullptr, 0, nullptr);
19289
19290 VkViewport viewport{};
19291 viewport.maxDepth = 1.0f;
19292 viewport.minDepth = 0.0f;
19293 viewport.width = 512;
19294 viewport.height = 512;
19295 viewport.x = 0;
19296 viewport.y = 0;
19297 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
19298 vkEndCommandBuffer(command_buffer[0]);
19299 }
19300 {
19301 VkCommandBufferBeginInfo begin_info{};
19302 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19303 vkBeginCommandBuffer(command_buffer[1], &begin_info);
19304
19305 VkViewport viewport{};
19306 viewport.maxDepth = 1.0f;
19307 viewport.minDepth = 0.0f;
19308 viewport.width = 512;
19309 viewport.height = 512;
19310 viewport.x = 0;
19311 viewport.y = 0;
19312 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
19313 vkEndCommandBuffer(command_buffer[1]);
19314 }
19315 {
19316 VkSubmitInfo submit_info[2];
19317 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
19318
19319 submit_info[0].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19320 submit_info[0].pNext = NULL;
19321 submit_info[0].commandBufferCount = 1;
19322 submit_info[0].pCommandBuffers = &command_buffer[0];
19323 submit_info[0].signalSemaphoreCount = 1;
19324 submit_info[0].pSignalSemaphores = &semaphore;
19325 submit_info[0].waitSemaphoreCount = 0;
19326 submit_info[0].pWaitSemaphores = NULL;
19327 submit_info[0].pWaitDstStageMask = 0;
19328
19329 submit_info[1].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19330 submit_info[1].pNext = NULL;
19331 submit_info[1].commandBufferCount = 1;
19332 submit_info[1].pCommandBuffers = &command_buffer[1];
19333 submit_info[1].waitSemaphoreCount = 1;
19334 submit_info[1].pWaitSemaphores = &semaphore;
19335 submit_info[1].pWaitDstStageMask = flags;
19336 submit_info[1].signalSemaphoreCount = 0;
19337 submit_info[1].pSignalSemaphores = NULL;
19338 vkQueueSubmit(m_device->m_queue, 2, &submit_info[0], fence);
19339 }
19340
19341 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
19342
19343 vkDestroyFence(m_device->device(), fence, nullptr);
19344 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
19345 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
19346 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
19347
19348 m_errorMonitor->VerifyNotFound();
19349}
19350
19351TEST_F(VkPositiveLayerTest, RenderPassSecondaryCommandBuffersMultipleTimes) {
19352 m_errorMonitor->ExpectSuccess();
19353
19354 ASSERT_NO_FATAL_FAILURE(InitState());
19355 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19356
Tony Barbour552f6c02016-12-21 14:34:07 -070019357 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019358
19359 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
19360 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
19361 m_errorMonitor->VerifyNotFound();
19362 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
19363 m_errorMonitor->VerifyNotFound();
19364 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
19365 m_errorMonitor->VerifyNotFound();
19366
19367 m_commandBuffer->EndCommandBuffer();
19368 m_errorMonitor->VerifyNotFound();
19369}
19370
19371TEST_F(VkPositiveLayerTest, ValidRenderPassAttachmentLayoutWithLoadOp) {
19372 TEST_DESCRIPTION("Positive test where we create a renderpass with an "
19373 "attachment that uses LOAD_OP_CLEAR, the first subpass "
19374 "has a valid layout, and a second subpass then uses a "
19375 "valid *READ_ONLY* layout.");
19376 m_errorMonitor->ExpectSuccess();
19377 ASSERT_NO_FATAL_FAILURE(InitState());
19378
19379 VkAttachmentReference attach[2] = {};
19380 attach[0].attachment = 0;
19381 attach[0].layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
19382 attach[1].attachment = 0;
19383 attach[1].layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
19384 VkSubpassDescription subpasses[2] = {};
19385 // First subpass clears DS attach on load
19386 subpasses[0].pDepthStencilAttachment = &attach[0];
19387 // 2nd subpass reads in DS as input attachment
19388 subpasses[1].inputAttachmentCount = 1;
19389 subpasses[1].pInputAttachments = &attach[1];
19390 VkAttachmentDescription attach_desc = {};
19391 attach_desc.format = VK_FORMAT_D24_UNORM_S8_UINT;
19392 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
19393 attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
19394 attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
19395 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
19396 attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
19397 attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
19398 attach_desc.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
19399 VkRenderPassCreateInfo rpci = {};
19400 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
19401 rpci.attachmentCount = 1;
19402 rpci.pAttachments = &attach_desc;
19403 rpci.subpassCount = 2;
19404 rpci.pSubpasses = subpasses;
19405
19406 // Now create RenderPass and verify no errors
19407 VkRenderPass rp;
19408 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
19409 m_errorMonitor->VerifyNotFound();
19410
19411 vkDestroyRenderPass(m_device->device(), rp, NULL);
19412}
19413
19414TEST_F(VkPositiveLayerTest, CreatePipelineAttribMatrixType) {
19415 TEST_DESCRIPTION("Test that pipeline validation accepts matrices passed "
19416 "as vertex attributes");
19417 m_errorMonitor->ExpectSuccess();
19418
19419 ASSERT_NO_FATAL_FAILURE(InitState());
19420 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19421
19422 VkVertexInputBindingDescription input_binding;
19423 memset(&input_binding, 0, sizeof(input_binding));
19424
19425 VkVertexInputAttributeDescription input_attribs[2];
19426 memset(input_attribs, 0, sizeof(input_attribs));
19427
19428 for (int i = 0; i < 2; i++) {
19429 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
19430 input_attribs[i].location = i;
19431 }
19432
19433 char const *vsSource = "#version 450\n"
19434 "\n"
19435 "layout(location=0) in mat2x4 x;\n"
19436 "out gl_PerVertex {\n"
19437 " vec4 gl_Position;\n"
19438 "};\n"
19439 "void main(){\n"
19440 " gl_Position = x[0] + x[1];\n"
19441 "}\n";
19442 char const *fsSource = "#version 450\n"
19443 "\n"
19444 "layout(location=0) out vec4 color;\n"
19445 "void main(){\n"
19446 " color = vec4(1);\n"
19447 "}\n";
19448
19449 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19450 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19451
19452 VkPipelineObj pipe(m_device);
19453 pipe.AddColorAttachment();
19454 pipe.AddShader(&vs);
19455 pipe.AddShader(&fs);
19456
19457 pipe.AddVertexInputBindings(&input_binding, 1);
19458 pipe.AddVertexInputAttribs(input_attribs, 2);
19459
19460 VkDescriptorSetObj descriptorSet(m_device);
19461 descriptorSet.AppendDummy();
19462 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19463
19464 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
19465
19466 /* expect success */
19467 m_errorMonitor->VerifyNotFound();
19468}
19469
19470TEST_F(VkPositiveLayerTest, CreatePipelineAttribArrayType) {
19471 m_errorMonitor->ExpectSuccess();
19472
19473 ASSERT_NO_FATAL_FAILURE(InitState());
19474 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19475
19476 VkVertexInputBindingDescription input_binding;
19477 memset(&input_binding, 0, sizeof(input_binding));
19478
19479 VkVertexInputAttributeDescription input_attribs[2];
19480 memset(input_attribs, 0, sizeof(input_attribs));
19481
19482 for (int i = 0; i < 2; i++) {
19483 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
19484 input_attribs[i].location = i;
19485 }
19486
19487 char const *vsSource = "#version 450\n"
19488 "\n"
19489 "layout(location=0) in vec4 x[2];\n"
19490 "out gl_PerVertex {\n"
19491 " vec4 gl_Position;\n"
19492 "};\n"
19493 "void main(){\n"
19494 " gl_Position = x[0] + x[1];\n"
19495 "}\n";
19496 char const *fsSource = "#version 450\n"
19497 "\n"
19498 "layout(location=0) out vec4 color;\n"
19499 "void main(){\n"
19500 " color = vec4(1);\n"
19501 "}\n";
19502
19503 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19504 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19505
19506 VkPipelineObj pipe(m_device);
19507 pipe.AddColorAttachment();
19508 pipe.AddShader(&vs);
19509 pipe.AddShader(&fs);
19510
19511 pipe.AddVertexInputBindings(&input_binding, 1);
19512 pipe.AddVertexInputAttribs(input_attribs, 2);
19513
19514 VkDescriptorSetObj descriptorSet(m_device);
19515 descriptorSet.AppendDummy();
19516 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19517
19518 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
19519
19520 m_errorMonitor->VerifyNotFound();
19521}
19522
19523TEST_F(VkPositiveLayerTest, CreatePipelineAttribComponents) {
19524 TEST_DESCRIPTION("Test that pipeline validation accepts consuming a vertex attribute "
19525 "through multiple vertex shader inputs, each consuming a different "
19526 "subset of the components.");
19527 m_errorMonitor->ExpectSuccess();
19528
19529 ASSERT_NO_FATAL_FAILURE(InitState());
19530 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19531
19532 VkVertexInputBindingDescription input_binding;
19533 memset(&input_binding, 0, sizeof(input_binding));
19534
19535 VkVertexInputAttributeDescription input_attribs[3];
19536 memset(input_attribs, 0, sizeof(input_attribs));
19537
19538 for (int i = 0; i < 3; i++) {
19539 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
19540 input_attribs[i].location = i;
19541 }
19542
19543 char const *vsSource = "#version 450\n"
19544 "\n"
19545 "layout(location=0) in vec4 x;\n"
19546 "layout(location=1) in vec3 y1;\n"
19547 "layout(location=1, component=3) in float y2;\n"
19548 "layout(location=2) in vec4 z;\n"
19549 "out gl_PerVertex {\n"
19550 " vec4 gl_Position;\n"
19551 "};\n"
19552 "void main(){\n"
19553 " gl_Position = x + vec4(y1, y2) + z;\n"
19554 "}\n";
19555 char const *fsSource = "#version 450\n"
19556 "\n"
19557 "layout(location=0) out vec4 color;\n"
19558 "void main(){\n"
19559 " color = vec4(1);\n"
19560 "}\n";
19561
19562 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19563 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19564
19565 VkPipelineObj pipe(m_device);
19566 pipe.AddColorAttachment();
19567 pipe.AddShader(&vs);
19568 pipe.AddShader(&fs);
19569
19570 pipe.AddVertexInputBindings(&input_binding, 1);
19571 pipe.AddVertexInputAttribs(input_attribs, 3);
19572
19573 VkDescriptorSetObj descriptorSet(m_device);
19574 descriptorSet.AppendDummy();
19575 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19576
19577 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
19578
19579 m_errorMonitor->VerifyNotFound();
19580}
19581
19582TEST_F(VkPositiveLayerTest, CreatePipelineSimplePositive) {
19583 m_errorMonitor->ExpectSuccess();
19584
19585 ASSERT_NO_FATAL_FAILURE(InitState());
19586 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19587
19588 char const *vsSource = "#version 450\n"
19589 "out gl_PerVertex {\n"
19590 " vec4 gl_Position;\n"
19591 "};\n"
19592 "void main(){\n"
19593 " gl_Position = vec4(0);\n"
19594 "}\n";
19595 char const *fsSource = "#version 450\n"
19596 "\n"
19597 "layout(location=0) out vec4 color;\n"
19598 "void main(){\n"
19599 " color = vec4(1);\n"
19600 "}\n";
19601
19602 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19603 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19604
19605 VkPipelineObj pipe(m_device);
19606 pipe.AddColorAttachment();
19607 pipe.AddShader(&vs);
19608 pipe.AddShader(&fs);
19609
19610 VkDescriptorSetObj descriptorSet(m_device);
19611 descriptorSet.AppendDummy();
19612 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19613
19614 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
19615
19616 m_errorMonitor->VerifyNotFound();
19617}
19618
19619TEST_F(VkPositiveLayerTest, CreatePipelineRelaxedTypeMatch) {
19620 TEST_DESCRIPTION("Test that pipeline validation accepts the relaxed type matching rules "
19621 "set out in 14.1.3: fundamental type must match, and producer side must "
19622 "have at least as many components");
19623 m_errorMonitor->ExpectSuccess();
19624
19625 // VK 1.0.8 Specification, 14.1.3 "Additionally,..." block
19626
19627 ASSERT_NO_FATAL_FAILURE(InitState());
19628 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19629
19630 char const *vsSource = "#version 450\n"
19631 "out gl_PerVertex {\n"
19632 " vec4 gl_Position;\n"
19633 "};\n"
19634 "layout(location=0) out vec3 x;\n"
19635 "layout(location=1) out ivec3 y;\n"
19636 "layout(location=2) out vec3 z;\n"
19637 "void main(){\n"
19638 " gl_Position = vec4(0);\n"
19639 " x = vec3(0); y = ivec3(0); z = vec3(0);\n"
19640 "}\n";
19641 char const *fsSource = "#version 450\n"
19642 "\n"
19643 "layout(location=0) out vec4 color;\n"
19644 "layout(location=0) in float x;\n"
19645 "layout(location=1) flat in int y;\n"
19646 "layout(location=2) in vec2 z;\n"
19647 "void main(){\n"
19648 " color = vec4(1 + x + y + z.x);\n"
19649 "}\n";
19650
19651 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19652 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19653
19654 VkPipelineObj pipe(m_device);
19655 pipe.AddColorAttachment();
19656 pipe.AddShader(&vs);
19657 pipe.AddShader(&fs);
19658
19659 VkDescriptorSetObj descriptorSet(m_device);
19660 descriptorSet.AppendDummy();
19661 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19662
19663 VkResult err = VK_SUCCESS;
19664 err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
19665 ASSERT_VK_SUCCESS(err);
19666
19667 m_errorMonitor->VerifyNotFound();
19668}
19669
19670TEST_F(VkPositiveLayerTest, CreatePipelineTessPerVertex) {
19671 TEST_DESCRIPTION("Test that pipeline validation accepts per-vertex variables "
19672 "passed between the TCS and TES stages");
19673 m_errorMonitor->ExpectSuccess();
19674
19675 ASSERT_NO_FATAL_FAILURE(InitState());
19676 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19677
19678 if (!m_device->phy().features().tessellationShader) {
19679 printf("Device does not support tessellation shaders; skipped.\n");
19680 return;
19681 }
19682
19683 char const *vsSource = "#version 450\n"
19684 "void main(){}\n";
19685 char const *tcsSource = "#version 450\n"
19686 "layout(location=0) out int x[];\n"
19687 "layout(vertices=3) out;\n"
19688 "void main(){\n"
19689 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
19690 " gl_TessLevelInner[0] = 1;\n"
19691 " x[gl_InvocationID] = gl_InvocationID;\n"
19692 "}\n";
19693 char const *tesSource = "#version 450\n"
19694 "layout(triangles, equal_spacing, cw) in;\n"
19695 "layout(location=0) in int x[];\n"
19696 "out gl_PerVertex { vec4 gl_Position; };\n"
19697 "void main(){\n"
19698 " gl_Position.xyz = gl_TessCoord;\n"
19699 " gl_Position.w = x[0] + x[1] + x[2];\n"
19700 "}\n";
19701 char const *fsSource = "#version 450\n"
19702 "layout(location=0) out vec4 color;\n"
19703 "void main(){\n"
19704 " color = vec4(1);\n"
19705 "}\n";
19706
19707 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19708 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
19709 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
19710 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19711
19712 VkPipelineInputAssemblyStateCreateInfo iasci{ VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, nullptr, 0,
19713 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, VK_FALSE };
19714
19715 VkPipelineTessellationStateCreateInfo tsci{ VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, nullptr, 0, 3 };
19716
19717 VkPipelineObj pipe(m_device);
19718 pipe.SetInputAssembly(&iasci);
19719 pipe.SetTessellation(&tsci);
19720 pipe.AddColorAttachment();
19721 pipe.AddShader(&vs);
19722 pipe.AddShader(&tcs);
19723 pipe.AddShader(&tes);
19724 pipe.AddShader(&fs);
19725
19726 VkDescriptorSetObj descriptorSet(m_device);
19727 descriptorSet.AppendDummy();
19728 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19729
19730 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
19731
19732 m_errorMonitor->VerifyNotFound();
19733}
19734
19735TEST_F(VkPositiveLayerTest, CreatePipelineGeometryInputBlockPositive) {
19736 TEST_DESCRIPTION("Test that pipeline validation accepts a user-defined "
19737 "interface block passed into the geometry shader. This "
19738 "is interesting because the 'extra' array level is not "
19739 "present on the member type, but on the block instance.");
19740 m_errorMonitor->ExpectSuccess();
19741
19742 ASSERT_NO_FATAL_FAILURE(InitState());
19743 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19744
19745 if (!m_device->phy().features().geometryShader) {
19746 printf("Device does not support geometry shaders; skipped.\n");
19747 return;
19748 }
19749
19750 char const *vsSource = "#version 450\n"
19751 "layout(location=0) out VertexData { vec4 x; } vs_out;\n"
19752 "void main(){\n"
19753 " vs_out.x = vec4(1);\n"
19754 "}\n";
19755 char const *gsSource = "#version 450\n"
19756 "layout(triangles) in;\n"
19757 "layout(triangle_strip, max_vertices=3) out;\n"
19758 "layout(location=0) in VertexData { vec4 x; } gs_in[];\n"
19759 "out gl_PerVertex { vec4 gl_Position; };\n"
19760 "void main() {\n"
19761 " gl_Position = gs_in[0].x;\n"
19762 " EmitVertex();\n"
19763 "}\n";
19764 char const *fsSource = "#version 450\n"
19765 "layout(location=0) out vec4 color;\n"
19766 "void main(){\n"
19767 " color = vec4(1);\n"
19768 "}\n";
19769
19770 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19771 VkShaderObj gs(m_device, gsSource, VK_SHADER_STAGE_GEOMETRY_BIT, this);
19772 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19773
19774 VkPipelineObj pipe(m_device);
19775 pipe.AddColorAttachment();
19776 pipe.AddShader(&vs);
19777 pipe.AddShader(&gs);
19778 pipe.AddShader(&fs);
19779
19780 VkDescriptorSetObj descriptorSet(m_device);
19781 descriptorSet.AppendDummy();
19782 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19783
19784 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
19785
19786 m_errorMonitor->VerifyNotFound();
19787}
19788
19789TEST_F(VkPositiveLayerTest, CreatePipeline64BitAttributesPositive) {
19790 TEST_DESCRIPTION("Test that pipeline validation accepts basic use of 64bit vertex "
19791 "attributes. This is interesting because they consume multiple "
19792 "locations.");
19793 m_errorMonitor->ExpectSuccess();
19794
19795 ASSERT_NO_FATAL_FAILURE(InitState());
19796 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19797
19798 if (!m_device->phy().features().shaderFloat64) {
19799 printf("Device does not support 64bit vertex attributes; skipped.\n");
19800 return;
19801 }
19802
19803 VkVertexInputBindingDescription input_bindings[1];
19804 memset(input_bindings, 0, sizeof(input_bindings));
19805
19806 VkVertexInputAttributeDescription input_attribs[4];
19807 memset(input_attribs, 0, sizeof(input_attribs));
19808 input_attribs[0].location = 0;
19809 input_attribs[0].offset = 0;
19810 input_attribs[0].format = VK_FORMAT_R64G64B64A64_SFLOAT;
19811 input_attribs[1].location = 2;
19812 input_attribs[1].offset = 32;
19813 input_attribs[1].format = VK_FORMAT_R64G64B64A64_SFLOAT;
19814 input_attribs[2].location = 4;
19815 input_attribs[2].offset = 64;
19816 input_attribs[2].format = VK_FORMAT_R64G64B64A64_SFLOAT;
19817 input_attribs[3].location = 6;
19818 input_attribs[3].offset = 96;
19819 input_attribs[3].format = VK_FORMAT_R64G64B64A64_SFLOAT;
19820
19821 char const *vsSource = "#version 450\n"
19822 "\n"
19823 "layout(location=0) in dmat4 x;\n"
19824 "out gl_PerVertex {\n"
19825 " vec4 gl_Position;\n"
19826 "};\n"
19827 "void main(){\n"
19828 " gl_Position = vec4(x[0][0]);\n"
19829 "}\n";
19830 char const *fsSource = "#version 450\n"
19831 "\n"
19832 "layout(location=0) out vec4 color;\n"
19833 "void main(){\n"
19834 " color = vec4(1);\n"
19835 "}\n";
19836
19837 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19838 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19839
19840 VkPipelineObj pipe(m_device);
19841 pipe.AddColorAttachment();
19842 pipe.AddShader(&vs);
19843 pipe.AddShader(&fs);
19844
19845 pipe.AddVertexInputBindings(input_bindings, 1);
19846 pipe.AddVertexInputAttribs(input_attribs, 4);
19847
19848 VkDescriptorSetObj descriptorSet(m_device);
19849 descriptorSet.AppendDummy();
19850 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19851
19852 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
19853
19854 m_errorMonitor->VerifyNotFound();
19855}
19856
19857TEST_F(VkPositiveLayerTest, CreatePipelineInputAttachmentPositive) {
19858 TEST_DESCRIPTION("Positive test for a correctly matched input attachment");
19859 m_errorMonitor->ExpectSuccess();
19860
19861 ASSERT_NO_FATAL_FAILURE(InitState());
19862
19863 char const *vsSource = "#version 450\n"
19864 "\n"
19865 "out gl_PerVertex {\n"
19866 " vec4 gl_Position;\n"
19867 "};\n"
19868 "void main(){\n"
19869 " gl_Position = vec4(1);\n"
19870 "}\n";
19871 char const *fsSource = "#version 450\n"
19872 "\n"
19873 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
19874 "layout(location=0) out vec4 color;\n"
19875 "void main() {\n"
19876 " color = subpassLoad(x);\n"
19877 "}\n";
19878
19879 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19880 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19881
19882 VkPipelineObj pipe(m_device);
19883 pipe.AddShader(&vs);
19884 pipe.AddShader(&fs);
19885 pipe.AddColorAttachment();
19886 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19887
19888 VkDescriptorSetLayoutBinding dslb = { 0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr };
19889 VkDescriptorSetLayoutCreateInfo dslci = { VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb };
19890 VkDescriptorSetLayout dsl;
19891 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
19892 ASSERT_VK_SUCCESS(err);
19893
19894 VkPipelineLayoutCreateInfo plci = { VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr };
19895 VkPipelineLayout pl;
19896 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
19897 ASSERT_VK_SUCCESS(err);
19898
19899 VkAttachmentDescription descs[2] = {
19900 { 0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
19901 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
19902 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL },
19903 { 0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
19904 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_GENERAL, VK_IMAGE_LAYOUT_GENERAL },
19905 };
19906 VkAttachmentReference color = {
19907 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
19908 };
19909 VkAttachmentReference input = {
19910 1, VK_IMAGE_LAYOUT_GENERAL,
19911 };
19912
19913 VkSubpassDescription sd = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 1, &input, 1, &color, nullptr, nullptr, 0, nullptr };
19914
19915 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, descs, 1, &sd, 0, nullptr };
19916 VkRenderPass rp;
19917 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
19918 ASSERT_VK_SUCCESS(err);
19919
19920 // should be OK. would go wrong here if it's going to...
19921 pipe.CreateVKPipeline(pl, rp);
19922
19923 m_errorMonitor->VerifyNotFound();
19924
19925 vkDestroyRenderPass(m_device->device(), rp, nullptr);
19926 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
19927 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
19928}
19929
19930TEST_F(VkPositiveLayerTest, CreateComputePipelineMissingDescriptorUnusedPositive) {
19931 TEST_DESCRIPTION("Test that pipeline validation accepts a compute pipeline which declares a "
19932 "descriptor-backed resource which is not provided, but the shader does not "
19933 "statically use it. This is interesting because it requires compute pipelines "
19934 "to have a proper descriptor use walk, which they didn't for some time.");
19935 m_errorMonitor->ExpectSuccess();
19936
19937 ASSERT_NO_FATAL_FAILURE(InitState());
19938
19939 char const *csSource = "#version 450\n"
19940 "\n"
19941 "layout(local_size_x=1) in;\n"
19942 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
19943 "void main(){\n"
19944 " // x is not used.\n"
19945 "}\n";
19946
19947 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
19948
19949 VkDescriptorSetObj descriptorSet(m_device);
19950 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19951
19952 VkComputePipelineCreateInfo cpci = { VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
19953 nullptr,
19954 0,
19955 { VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
19956 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr },
19957 descriptorSet.GetPipelineLayout(),
19958 VK_NULL_HANDLE,
19959 -1 };
19960
19961 VkPipeline pipe;
19962 VkResult err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
19963
19964 m_errorMonitor->VerifyNotFound();
19965
19966 if (err == VK_SUCCESS) {
19967 vkDestroyPipeline(m_device->device(), pipe, nullptr);
19968 }
19969}
19970
19971TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsSampler) {
19972 TEST_DESCRIPTION("Test that pipeline validation accepts a shader consuming only the "
19973 "sampler portion of a combined image + sampler");
19974 m_errorMonitor->ExpectSuccess();
19975
19976 ASSERT_NO_FATAL_FAILURE(InitState());
19977
19978 VkDescriptorSetLayoutBinding bindings[] = {
19979 { 0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
19980 { 1, VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
19981 { 2, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
19982 };
19983 VkDescriptorSetLayoutCreateInfo dslci = { VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 3, bindings };
19984 VkDescriptorSetLayout dsl;
19985 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
19986 ASSERT_VK_SUCCESS(err);
19987
19988 VkPipelineLayoutCreateInfo plci = { VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr };
19989 VkPipelineLayout pl;
19990 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
19991 ASSERT_VK_SUCCESS(err);
19992
19993 char const *csSource = "#version 450\n"
19994 "\n"
19995 "layout(local_size_x=1) in;\n"
19996 "layout(set=0, binding=0) uniform sampler s;\n"
19997 "layout(set=0, binding=1) uniform texture2D t;\n"
19998 "layout(set=0, binding=2) buffer block { vec4 x; };\n"
19999 "void main() {\n"
20000 " x = texture(sampler2D(t, s), vec2(0));\n"
20001 "}\n";
20002 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
20003
20004 VkComputePipelineCreateInfo cpci = { VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
20005 nullptr,
20006 0,
20007 { VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
20008 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr },
20009 pl,
20010 VK_NULL_HANDLE,
20011 -1 };
20012
20013 VkPipeline pipe;
20014 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
20015
20016 m_errorMonitor->VerifyNotFound();
20017
20018 if (err == VK_SUCCESS) {
20019 vkDestroyPipeline(m_device->device(), pipe, nullptr);
20020 }
20021
20022 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
20023 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
20024}
20025
20026TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsImage) {
20027 TEST_DESCRIPTION("Test that pipeline validation accepts a shader consuming only the "
20028 "image portion of a combined image + sampler");
20029 m_errorMonitor->ExpectSuccess();
20030
20031 ASSERT_NO_FATAL_FAILURE(InitState());
20032
20033 VkDescriptorSetLayoutBinding bindings[] = {
20034 { 0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
20035 { 1, VK_DESCRIPTOR_TYPE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
20036 { 2, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
20037 };
20038 VkDescriptorSetLayoutCreateInfo dslci = { VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 3, bindings };
20039 VkDescriptorSetLayout dsl;
20040 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
20041 ASSERT_VK_SUCCESS(err);
20042
20043 VkPipelineLayoutCreateInfo plci = { VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr };
20044 VkPipelineLayout pl;
20045 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
20046 ASSERT_VK_SUCCESS(err);
20047
20048 char const *csSource = "#version 450\n"
20049 "\n"
20050 "layout(local_size_x=1) in;\n"
20051 "layout(set=0, binding=0) uniform texture2D t;\n"
20052 "layout(set=0, binding=1) uniform sampler s;\n"
20053 "layout(set=0, binding=2) buffer block { vec4 x; };\n"
20054 "void main() {\n"
20055 " x = texture(sampler2D(t, s), vec2(0));\n"
20056 "}\n";
20057 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
20058
20059 VkComputePipelineCreateInfo cpci = { VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
20060 nullptr,
20061 0,
20062 { VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
20063 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr },
20064 pl,
20065 VK_NULL_HANDLE,
20066 -1 };
20067
20068 VkPipeline pipe;
20069 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
20070
20071 m_errorMonitor->VerifyNotFound();
20072
20073 if (err == VK_SUCCESS) {
20074 vkDestroyPipeline(m_device->device(), pipe, nullptr);
20075 }
20076
20077 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
20078 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
20079}
20080
20081TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsBoth) {
20082 TEST_DESCRIPTION("Test that pipeline validation accepts a shader consuming "
20083 "both the sampler and the image of a combined image+sampler "
20084 "but via separate variables");
20085 m_errorMonitor->ExpectSuccess();
20086
20087 ASSERT_NO_FATAL_FAILURE(InitState());
20088
20089 VkDescriptorSetLayoutBinding bindings[] = {
20090 { 0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
20091 { 1, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
20092 };
20093 VkDescriptorSetLayoutCreateInfo dslci = { VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 2, bindings };
20094 VkDescriptorSetLayout dsl;
20095 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
20096 ASSERT_VK_SUCCESS(err);
20097
20098 VkPipelineLayoutCreateInfo plci = { VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr };
20099 VkPipelineLayout pl;
20100 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
20101 ASSERT_VK_SUCCESS(err);
20102
20103 char const *csSource = "#version 450\n"
20104 "\n"
20105 "layout(local_size_x=1) in;\n"
20106 "layout(set=0, binding=0) uniform texture2D t;\n"
20107 "layout(set=0, binding=0) uniform sampler s; // both binding 0!\n"
20108 "layout(set=0, binding=1) buffer block { vec4 x; };\n"
20109 "void main() {\n"
20110 " x = texture(sampler2D(t, s), vec2(0));\n"
20111 "}\n";
20112 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
20113
20114 VkComputePipelineCreateInfo cpci = { VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
20115 nullptr,
20116 0,
20117 { VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
20118 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr },
20119 pl,
20120 VK_NULL_HANDLE,
20121 -1 };
20122
20123 VkPipeline pipe;
20124 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
20125
20126 m_errorMonitor->VerifyNotFound();
20127
20128 if (err == VK_SUCCESS) {
20129 vkDestroyPipeline(m_device->device(), pipe, nullptr);
20130 }
20131
20132 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
20133 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
20134}
20135
20136TEST_F(VkPositiveLayerTest, ValidStructPNext) {
20137 TEST_DESCRIPTION("Verify that a valid pNext value is handled correctly");
20138
20139 ASSERT_NO_FATAL_FAILURE(InitState());
20140
20141 // Positive test to check parameter_validation and unique_objects support
20142 // for NV_dedicated_allocation
20143 uint32_t extension_count = 0;
20144 bool supports_nv_dedicated_allocation = false;
20145 VkResult err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, nullptr);
20146 ASSERT_VK_SUCCESS(err);
20147
20148 if (extension_count > 0) {
20149 std::vector<VkExtensionProperties> available_extensions(extension_count);
20150
20151 err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, &available_extensions[0]);
20152 ASSERT_VK_SUCCESS(err);
20153
20154 for (const auto &extension_props : available_extensions) {
20155 if (strcmp(extension_props.extensionName, VK_NV_DEDICATED_ALLOCATION_EXTENSION_NAME) == 0) {
20156 supports_nv_dedicated_allocation = true;
20157 }
20158 }
20159 }
20160
20161 if (supports_nv_dedicated_allocation) {
20162 m_errorMonitor->ExpectSuccess();
20163
20164 VkDedicatedAllocationBufferCreateInfoNV dedicated_buffer_create_info = {};
20165 dedicated_buffer_create_info.sType = VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_BUFFER_CREATE_INFO_NV;
20166 dedicated_buffer_create_info.pNext = nullptr;
20167 dedicated_buffer_create_info.dedicatedAllocation = VK_TRUE;
20168
20169 uint32_t queue_family_index = 0;
20170 VkBufferCreateInfo buffer_create_info = {};
20171 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
20172 buffer_create_info.pNext = &dedicated_buffer_create_info;
20173 buffer_create_info.size = 1024;
20174 buffer_create_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
20175 buffer_create_info.queueFamilyIndexCount = 1;
20176 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
20177
20178 VkBuffer buffer;
20179 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
20180 ASSERT_VK_SUCCESS(err);
20181
20182 VkMemoryRequirements memory_reqs;
20183 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
20184
20185 VkDedicatedAllocationMemoryAllocateInfoNV dedicated_memory_info = {};
20186 dedicated_memory_info.sType = VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_MEMORY_ALLOCATE_INFO_NV;
20187 dedicated_memory_info.pNext = nullptr;
20188 dedicated_memory_info.buffer = buffer;
20189 dedicated_memory_info.image = VK_NULL_HANDLE;
20190
20191 VkMemoryAllocateInfo memory_info = {};
20192 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
20193 memory_info.pNext = &dedicated_memory_info;
20194 memory_info.allocationSize = memory_reqs.size;
20195
20196 bool pass;
20197 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
20198 ASSERT_TRUE(pass);
20199
20200 VkDeviceMemory buffer_memory;
20201 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
20202 ASSERT_VK_SUCCESS(err);
20203
20204 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
20205 ASSERT_VK_SUCCESS(err);
20206
20207 vkDestroyBuffer(m_device->device(), buffer, NULL);
20208 vkFreeMemory(m_device->device(), buffer_memory, NULL);
20209
20210 m_errorMonitor->VerifyNotFound();
20211 }
20212}
20213
20214TEST_F(VkPositiveLayerTest, PSOPolygonModeValid) {
20215 VkResult err;
20216
20217 TEST_DESCRIPTION("Verify that using a solid polygon fill mode works correctly.");
20218
20219 ASSERT_NO_FATAL_FAILURE(InitState());
20220 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
20221
20222 std::vector<const char *> device_extension_names;
20223 auto features = m_device->phy().features();
20224 // Artificially disable support for non-solid fill modes
20225 features.fillModeNonSolid = false;
20226 // The sacrificial device object
20227 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
20228
20229 VkRenderpassObj render_pass(&test_device);
20230
20231 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
20232 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
20233 pipeline_layout_ci.setLayoutCount = 0;
20234 pipeline_layout_ci.pSetLayouts = NULL;
20235
20236 VkPipelineLayout pipeline_layout;
20237 err = vkCreatePipelineLayout(test_device.device(), &pipeline_layout_ci, NULL, &pipeline_layout);
20238 ASSERT_VK_SUCCESS(err);
20239
20240 VkPipelineRasterizationStateCreateInfo rs_ci = {};
20241 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
20242 rs_ci.pNext = nullptr;
20243 rs_ci.lineWidth = 1.0f;
20244 rs_ci.rasterizerDiscardEnable = true;
20245
20246 VkShaderObj vs(&test_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
20247 VkShaderObj fs(&test_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
20248
20249 // Set polygonMode=FILL. No error is expected
20250 m_errorMonitor->ExpectSuccess();
20251 {
20252 VkPipelineObj pipe(&test_device);
20253 pipe.AddShader(&vs);
20254 pipe.AddShader(&fs);
20255 pipe.AddColorAttachment();
20256 // Set polygonMode to a good value
20257 rs_ci.polygonMode = VK_POLYGON_MODE_FILL;
20258 pipe.SetRasterization(&rs_ci);
20259 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
20260 }
20261 m_errorMonitor->VerifyNotFound();
20262
20263 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, NULL);
20264}
20265
20266TEST_F(VkPositiveLayerTest, ValidPushConstants) {
20267 VkResult err;
20268 ASSERT_NO_FATAL_FAILURE(InitState());
20269 ASSERT_NO_FATAL_FAILURE(InitViewport());
20270 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
20271
20272 VkPipelineLayout pipeline_layout;
20273 VkPushConstantRange pc_range = {};
20274 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
20275 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
20276 pipeline_layout_ci.pushConstantRangeCount = 1;
20277 pipeline_layout_ci.pPushConstantRanges = &pc_range;
20278
20279 //
20280 // Check for invalid push constant ranges in pipeline layouts.
20281 //
20282 struct PipelineLayoutTestCase {
20283 VkPushConstantRange const range;
20284 char const *msg;
20285 };
20286
20287 // Check for overlapping ranges
20288 const uint32_t ranges_per_test = 5;
20289 struct OverlappingRangeTestCase {
20290 VkPushConstantRange const ranges[ranges_per_test];
20291 char const *msg;
20292 };
20293
20294 // Run some positive tests to make sure overlap checking in the layer is OK
20295 const std::array<OverlappingRangeTestCase, 2> overlapping_range_tests_pos = { { { { { VK_SHADER_STAGE_VERTEX_BIT, 0, 4 },
20296 { VK_SHADER_STAGE_VERTEX_BIT, 4, 4 },
20297 { VK_SHADER_STAGE_VERTEX_BIT, 8, 4 },
20298 { VK_SHADER_STAGE_VERTEX_BIT, 12, 4 },
20299 { VK_SHADER_STAGE_VERTEX_BIT, 16, 4 } },
20300 "" },
20301 { { { VK_SHADER_STAGE_VERTEX_BIT, 92, 24 },
20302 { VK_SHADER_STAGE_VERTEX_BIT, 80, 4 },
20303 { VK_SHADER_STAGE_VERTEX_BIT, 64, 8 },
20304 { VK_SHADER_STAGE_VERTEX_BIT, 4, 16 },
20305 { VK_SHADER_STAGE_VERTEX_BIT, 0, 4 } },
20306 "" } } };
20307 for (const auto &iter : overlapping_range_tests_pos) {
20308 pipeline_layout_ci.pPushConstantRanges = iter.ranges;
20309 m_errorMonitor->ExpectSuccess();
20310 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
20311 m_errorMonitor->VerifyNotFound();
20312 if (VK_SUCCESS == err) {
20313 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
20314 }
20315 }
20316
20317 //
20318 // CmdPushConstants tests
20319 //
20320 const uint8_t dummy_values[100] = {};
20321
Tony Barbour552f6c02016-12-21 14:34:07 -070020322 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020323
20324 // positive overlapping range tests with cmd
20325 const std::array<PipelineLayoutTestCase, 4> cmd_overlap_tests_pos = { {
20326 { { VK_SHADER_STAGE_VERTEX_BIT, 0, 16 }, "" },
20327 { { VK_SHADER_STAGE_VERTEX_BIT, 0, 4 }, "" },
20328 { { VK_SHADER_STAGE_VERTEX_BIT, 20, 12 }, "" },
20329 { { VK_SHADER_STAGE_VERTEX_BIT, 56, 36 }, "" },
20330 } };
20331
20332 // Setup ranges: [0,16) [20,36) [36,44) [44,52) [56,80) [80,92)
20333 const VkPushConstantRange pc_range4[] = {
20334 { VK_SHADER_STAGE_VERTEX_BIT, 20, 16 },{ VK_SHADER_STAGE_VERTEX_BIT, 0, 16 },{ VK_SHADER_STAGE_VERTEX_BIT, 44, 8 },
20335 { VK_SHADER_STAGE_VERTEX_BIT, 80, 12 },{ VK_SHADER_STAGE_VERTEX_BIT, 36, 8 },{ VK_SHADER_STAGE_VERTEX_BIT, 56, 24 },
20336 };
20337
20338 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range4) / sizeof(VkPushConstantRange);
20339 pipeline_layout_ci.pPushConstantRanges = pc_range4;
20340 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
20341 ASSERT_VK_SUCCESS(err);
20342 for (const auto &iter : cmd_overlap_tests_pos) {
20343 m_errorMonitor->ExpectSuccess();
20344 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.range.stageFlags, iter.range.offset,
20345 iter.range.size, dummy_values);
20346 m_errorMonitor->VerifyNotFound();
20347 }
20348 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
20349
Tony Barbour552f6c02016-12-21 14:34:07 -070020350 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020351}
20352
20353
20354
20355
20356
20357
20358
20359#if 0 // A few devices have issues with this test so disabling for now
20360TEST_F(VkPositiveLayerTest, LongFenceChain)
20361{
20362 m_errorMonitor->ExpectSuccess();
20363
20364 ASSERT_NO_FATAL_FAILURE(InitState());
20365 VkResult err;
20366
20367 std::vector<VkFence> fences;
20368
20369 const int chainLength = 32768;
20370
20371 for (int i = 0; i < chainLength; i++) {
20372 VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
20373 VkFence fence;
20374 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
20375 ASSERT_VK_SUCCESS(err);
20376
20377 fences.push_back(fence);
20378
20379 VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr,
20380 0, nullptr, 0, nullptr };
20381 err = vkQueueSubmit(m_device->m_queue, 1, &si, fence);
20382 ASSERT_VK_SUCCESS(err);
20383
20384 }
20385
20386 // BOOM, stack overflow.
20387 vkWaitForFences(m_device->device(), 1, &fences.back(), VK_TRUE, UINT64_MAX);
20388
20389 for (auto fence : fences)
20390 vkDestroyFence(m_device->device(), fence, nullptr);
20391
20392 m_errorMonitor->VerifyNotFound();
20393}
20394#endif
20395
20396
Cody Northrop1242dfd2016-07-13 17:24:59 -060020397#if defined(ANDROID) && defined(VALIDATION_APK)
20398static bool initialized = false;
20399static bool active = false;
20400
20401// Convert Intents to argv
20402// Ported from Hologram sample, only difference is flexible key
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020403std::vector<std::string> get_args(android_app &app, const char *intent_extra_data_key) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060020404 std::vector<std::string> args;
20405 JavaVM &vm = *app.activity->vm;
20406 JNIEnv *p_env;
20407 if (vm.AttachCurrentThread(&p_env, nullptr) != JNI_OK)
20408 return args;
20409
20410 JNIEnv &env = *p_env;
20411 jobject activity = app.activity->clazz;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020412 jmethodID get_intent_method = env.GetMethodID(env.GetObjectClass(activity), "getIntent", "()Landroid/content/Intent;");
Cody Northrop1242dfd2016-07-13 17:24:59 -060020413 jobject intent = env.CallObjectMethod(activity, get_intent_method);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020414 jmethodID get_string_extra_method =
20415 env.GetMethodID(env.GetObjectClass(intent), "getStringExtra", "(Ljava/lang/String;)Ljava/lang/String;");
Cody Northrop1242dfd2016-07-13 17:24:59 -060020416 jvalue get_string_extra_args;
20417 get_string_extra_args.l = env.NewStringUTF(intent_extra_data_key);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020418 jstring extra_str = static_cast<jstring>(env.CallObjectMethodA(intent, get_string_extra_method, &get_string_extra_args));
Cody Northrop1242dfd2016-07-13 17:24:59 -060020419
20420 std::string args_str;
20421 if (extra_str) {
20422 const char *extra_utf = env.GetStringUTFChars(extra_str, nullptr);
20423 args_str = extra_utf;
20424 env.ReleaseStringUTFChars(extra_str, extra_utf);
20425 env.DeleteLocalRef(extra_str);
20426 }
20427
20428 env.DeleteLocalRef(get_string_extra_args.l);
20429 env.DeleteLocalRef(intent);
20430 vm.DetachCurrentThread();
20431
20432 // split args_str
20433 std::stringstream ss(args_str);
20434 std::string arg;
20435 while (std::getline(ss, arg, ' ')) {
20436 if (!arg.empty())
20437 args.push_back(arg);
20438 }
20439
20440 return args;
20441}
20442
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020443static int32_t processInput(struct android_app *app, AInputEvent *event) { return 0; }
Cody Northrop1242dfd2016-07-13 17:24:59 -060020444
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020445static void processCommand(struct android_app *app, int32_t cmd) {
20446 switch (cmd) {
20447 case APP_CMD_INIT_WINDOW: {
20448 if (app->window) {
20449 initialized = true;
Cody Northrop1242dfd2016-07-13 17:24:59 -060020450 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020451 break;
20452 }
20453 case APP_CMD_GAINED_FOCUS: {
20454 active = true;
20455 break;
20456 }
20457 case APP_CMD_LOST_FOCUS: {
20458 active = false;
20459 break;
20460 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060020461 }
20462}
20463
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020464void android_main(struct android_app *app) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060020465 app_dummy();
20466
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020467 const char *appTag = "VulkanLayerValidationTests";
Cody Northrop1242dfd2016-07-13 17:24:59 -060020468
20469 int vulkanSupport = InitVulkan();
20470 if (vulkanSupport == 0) {
20471 __android_log_print(ANDROID_LOG_INFO, appTag, "==== FAILED ==== No Vulkan support found");
20472 return;
20473 }
20474
20475 app->onAppCmd = processCommand;
20476 app->onInputEvent = processInput;
20477
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020478 while (1) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060020479 int events;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020480 struct android_poll_source *source;
20481 while (ALooper_pollAll(active ? 0 : -1, NULL, &events, (void **)&source) >= 0) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060020482 if (source) {
20483 source->process(app, source);
20484 }
20485
20486 if (app->destroyRequested != 0) {
20487 VkTestFramework::Finish();
20488 return;
20489 }
20490 }
20491
20492 if (initialized && active) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020493 // Use the following key to send arguments to gtest, i.e.
20494 // --es args "--gtest_filter=-VkLayerTest.foo"
20495 const char key[] = "args";
20496 std::vector<std::string> args = get_args(*app, key);
Cody Northrop1242dfd2016-07-13 17:24:59 -060020497
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020498 std::string filter = "";
20499 if (args.size() > 0) {
20500 __android_log_print(ANDROID_LOG_INFO, appTag, "Intent args = %s", args[0].c_str());
20501 filter += args[0];
20502 } else {
20503 __android_log_print(ANDROID_LOG_INFO, appTag, "No Intent args detected");
20504 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060020505
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020506 int argc = 2;
20507 char *argv[] = {(char *)"foo", (char *)filter.c_str()};
20508 __android_log_print(ANDROID_LOG_DEBUG, appTag, "filter = %s", argv[1]);
Cody Northrop1242dfd2016-07-13 17:24:59 -060020509
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020510 // Route output to files until we can override the gtest output
20511 freopen("/sdcard/Android/data/com.example.VulkanLayerValidationTests/files/out.txt", "w", stdout);
20512 freopen("/sdcard/Android/data/com.example.VulkanLayerValidationTests/files/err.txt", "w", stderr);
Cody Northrop1242dfd2016-07-13 17:24:59 -060020513
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020514 ::testing::InitGoogleTest(&argc, argv);
20515 VkTestFramework::InitArgs(&argc, argv);
20516 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
Cody Northrop1242dfd2016-07-13 17:24:59 -060020517
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020518 int result = RUN_ALL_TESTS();
Cody Northrop1242dfd2016-07-13 17:24:59 -060020519
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020520 if (result != 0) {
20521 __android_log_print(ANDROID_LOG_INFO, appTag, "==== Tests FAILED ====");
20522 } else {
20523 __android_log_print(ANDROID_LOG_INFO, appTag, "==== Tests PASSED ====");
20524 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060020525
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020526 VkTestFramework::Finish();
Cody Northrop1242dfd2016-07-13 17:24:59 -060020527
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020528 fclose(stdout);
20529 fclose(stderr);
Cody Northrop1242dfd2016-07-13 17:24:59 -060020530
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020531 ANativeActivity_finish(app->activity);
Cody Northrop1242dfd2016-07-13 17:24:59 -060020532
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020533 return;
Cody Northrop1242dfd2016-07-13 17:24:59 -060020534 }
20535 }
20536}
20537#endif
20538
Tony Barbour300a6082015-04-07 13:44:53 -060020539int main(int argc, char **argv) {
20540 int result;
20541
Cody Northrop8e54a402016-03-08 22:25:52 -070020542#ifdef ANDROID
20543 int vulkanSupport = InitVulkan();
20544 if (vulkanSupport == 0)
20545 return 1;
20546#endif
20547
Tony Barbour300a6082015-04-07 13:44:53 -060020548 ::testing::InitGoogleTest(&argc, argv);
Tony Barbour6918cd52015-04-09 12:58:51 -060020549 VkTestFramework::InitArgs(&argc, argv);
Tony Barbour300a6082015-04-07 13:44:53 -060020550
20551 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
20552
20553 result = RUN_ALL_TESTS();
20554
Tony Barbour6918cd52015-04-09 12:58:51 -060020555 VkTestFramework::Finish();
Tony Barbour300a6082015-04-07 13:44:53 -060020556 return result;
20557}