blob: f9a7708b4825de1903f79102c38984d020b3db8e [file] [log] [blame]
Karl Schultz6addd812016-02-02 17:17:23 -07001/*
2 * Copyright (c) 2015-2016 The Khronos Group Inc.
3 * Copyright (c) 2015-2016 Valve Corporation
4 * Copyright (c) 2015-2016 LunarG, Inc.
Michael Lentine0a369f62016-02-03 16:51:46 -06005 * Copyright (c) 2015-2016 Google, Inc.
Karl Schultz6addd812016-02-02 17:17:23 -07006 *
Jon Ashburn3ebf1252016-04-19 11:30:31 -06007 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
Karl Schultz6addd812016-02-02 17:17:23 -070010 *
Jon Ashburn3ebf1252016-04-19 11:30:31 -060011 * http://www.apache.org/licenses/LICENSE-2.0
Karl Schultz6addd812016-02-02 17:17:23 -070012 *
13 * Author: Chia-I Wu <olvaffe@gmail.com>
14 * Author: Chris Forbes <chrisf@ijw.co.nz>
15 * Author: Courtney Goeltzenleuchter <courtney@LunarG.com>
16 * Author: Mark Lobodzinski <mark@lunarg.com>
17 * Author: Mike Stroyan <mike@LunarG.com>
18 * Author: Tobin Ehlis <tobine@google.com>
19 * Author: Tony Barbour <tony@LunarG.com>
Cody Northrop1242dfd2016-07-13 17:24:59 -060020 * Author: Cody Northrop <cnorthrop@google.com>
Karl Schultz6addd812016-02-02 17:17:23 -070021 */
Tony Barbour65c48b32015-11-17 10:02:56 -070022
Cody Northrop8e54a402016-03-08 22:25:52 -070023#ifdef ANDROID
24#include "vulkan_wrapper.h"
25#else
David Pinedo9316d3b2015-11-06 12:54:48 -070026#include <vulkan/vulkan.h>
Cody Northrop8e54a402016-03-08 22:25:52 -070027#endif
Cody Northrop1242dfd2016-07-13 17:24:59 -060028
29#if defined(ANDROID) && defined(VALIDATION_APK)
30#include <android/log.h>
31#include <android_native_app_glue.h>
32#endif
33
Jon Ashburn7fa7e222016-02-02 12:08:10 -070034#include "icd-spv.h"
Mark Lobodzinskice751c62016-09-08 10:45:35 -060035#include "test_common.h"
36#include "vk_layer_config.h"
Mark Lobodzinski629d47b2016-10-18 13:34:58 -060037#include "vk_validation_error_messages.h"
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060038#include "vkrenderframework.h"
39#include <limits.h>
40#include <unordered_set>
Tony Barbour300a6082015-04-07 13:44:53 -060041
Mark Lobodzinski3780e142015-05-14 15:08:13 -050042#define GLM_FORCE_RADIANS
43#include "glm/glm.hpp"
44#include <glm/gtc/matrix_transform.hpp>
45
Dustin Gravesffa90fa2016-05-06 11:20:38 -060046#define PARAMETER_VALIDATION_TESTS 1
Tobin Ehlis0788f522015-05-26 16:11:58 -060047#define MEM_TRACKER_TESTS 1
48#define OBJ_TRACKER_TESTS 1
49#define DRAW_STATE_TESTS 1
50#define THREADING_TESTS 1
Chris Forbes9f7ff632015-05-25 11:13:08 +120051#define SHADER_CHECKER_TESTS 1
Mark Lobodzinski209b5292015-09-17 09:44:05 -060052#define DEVICE_LIMITS_TESTS 1
Tobin Ehliscde08892015-09-22 10:11:37 -060053#define IMAGE_TESTS 1
Tobin Ehlis0788f522015-05-26 16:11:58 -060054
Mark Lobodzinski3780e142015-05-14 15:08:13 -050055//--------------------------------------------------------------------------------------
56// Mesh and VertexFormat Data
57//--------------------------------------------------------------------------------------
Karl Schultz6addd812016-02-02 17:17:23 -070058struct Vertex {
59 float posX, posY, posZ, posW; // Position data
60 float r, g, b, a; // Color
Mark Lobodzinski3780e142015-05-14 15:08:13 -050061};
62
Karl Schultz6addd812016-02-02 17:17:23 -070063#define XYZ1(_x_, _y_, _z_) (_x_), (_y_), (_z_), 1.f
Mark Lobodzinski3780e142015-05-14 15:08:13 -050064
65typedef enum _BsoFailSelect {
Karl Schultz6addd812016-02-02 17:17:23 -070066 BsoFailNone = 0x00000000,
67 BsoFailLineWidth = 0x00000001,
68 BsoFailDepthBias = 0x00000002,
69 BsoFailViewport = 0x00000004,
70 BsoFailScissor = 0x00000008,
71 BsoFailBlend = 0x00000010,
72 BsoFailDepthBounds = 0x00000020,
73 BsoFailStencilReadMask = 0x00000040,
74 BsoFailStencilWriteMask = 0x00000080,
75 BsoFailStencilReference = 0x00000100,
Mark Muellerd4914412016-06-13 17:52:06 -060076 BsoFailCmdClearAttachments = 0x00000200,
Tobin Ehlis379ba3b2016-07-19 11:22:29 -060077 BsoFailIndexBuffer = 0x00000400,
Mark Lobodzinski3780e142015-05-14 15:08:13 -050078} BsoFailSelect;
79
80struct vktriangle_vs_uniform {
81 // Must start with MVP
Karl Schultz6addd812016-02-02 17:17:23 -070082 float mvp[4][4];
83 float position[3][4];
84 float color[3][4];
Mark Lobodzinski3780e142015-05-14 15:08:13 -050085};
86
Mark Lobodzinskice751c62016-09-08 10:45:35 -060087static const char bindStateVertShaderText[] = "#version 450\n"
88 "vec2 vertices[3];\n"
89 "out gl_PerVertex {\n"
90 " vec4 gl_Position;\n"
91 "};\n"
92 "void main() {\n"
93 " vertices[0] = vec2(-1.0, -1.0);\n"
94 " vertices[1] = vec2( 1.0, -1.0);\n"
95 " vertices[2] = vec2( 0.0, 1.0);\n"
96 " gl_Position = vec4(vertices[gl_VertexIndex % 3], 0.0, 1.0);\n"
97 "}\n";
Mark Lobodzinski3780e142015-05-14 15:08:13 -050098
Mark Lobodzinskice751c62016-09-08 10:45:35 -060099static const char bindStateFragShaderText[] = "#version 450\n"
100 "\n"
101 "layout(location = 0) out vec4 uFragColor;\n"
102 "void main(){\n"
103 " uFragColor = vec4(0,1,0,1);\n"
104 "}\n";
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500105
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600106static VKAPI_ATTR VkBool32 VKAPI_CALL myDbgFunc(VkFlags msgFlags, VkDebugReportObjectTypeEXT objType, uint64_t srcObject,
107 size_t location, int32_t msgCode, const char *pLayerPrefix, const char *pMsg,
108 void *pUserData);
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600109
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600110// ErrorMonitor Usage:
111//
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600112// Call SetDesiredFailureMsg with: a string to be compared against all
113// encountered log messages, or a validation error enum identifying
114// desired error message. Passing NULL or VALIDATION_ERROR_MAX_ENUM
115// will match all log messages. logMsg will return true for skipCall
116// only if msg is matched or NULL.
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600117//
118// Call DesiredMsgFound to determine if the desired failure message
119// was encountered.
Tony Barbour300a6082015-04-07 13:44:53 -0600120class ErrorMonitor {
Karl Schultz6addd812016-02-02 17:17:23 -0700121 public:
122 ErrorMonitor() {
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600123 test_platform_thread_create_mutex(&m_mutex);
124 test_platform_thread_lock_mutex(&m_mutex);
Chris Forbes17756132016-09-16 14:36:39 +1200125 m_msgFlags = VK_DEBUG_REPORT_ERROR_BIT_EXT;
Karl Schultz6addd812016-02-02 17:17:23 -0700126 m_bailout = NULL;
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600127 test_platform_thread_unlock_mutex(&m_mutex);
Tony Barbour300a6082015-04-07 13:44:53 -0600128 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600129
Dustin Graves48458142016-04-29 16:11:55 -0600130 ~ErrorMonitor() { test_platform_thread_delete_mutex(&m_mutex); }
131
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600132 // ErrorMonitor will look for an error message containing the specified string
Karl Schultz6addd812016-02-02 17:17:23 -0700133 void SetDesiredFailureMsg(VkFlags msgFlags, const char *msgString) {
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600134 // Also discard all collected messages to this point
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600135 test_platform_thread_lock_mutex(&m_mutex);
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600136 m_failure_message_strings.clear();
137 // If we are looking for a matching string, ignore any IDs
138 m_desired_message_ids.clear();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600139 m_otherMsgs.clear();
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600140 m_desired_message_strings.insert(msgString);
Karl Schultz6addd812016-02-02 17:17:23 -0700141 m_msgFound = VK_FALSE;
142 m_msgFlags = msgFlags;
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600143 test_platform_thread_unlock_mutex(&m_mutex);
Tony Barbour300a6082015-04-07 13:44:53 -0600144 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600145
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600146 // ErrorMonitor will look for a message ID matching the specified one
147 void SetDesiredFailureMsg(VkFlags msgFlags, UNIQUE_VALIDATION_ERROR_CODE msg_id) {
148 // Also discard all collected messages to this point
149 test_platform_thread_lock_mutex(&m_mutex);
150 m_failure_message_strings.clear();
151 // If we are looking for IDs don't look for strings
152 m_desired_message_strings.clear();
153 m_otherMsgs.clear();
154 m_desired_message_ids.insert(msg_id);
155 m_msgFound = VK_FALSE;
156 m_msgFlags = msgFlags;
157 test_platform_thread_unlock_mutex(&m_mutex);
158 }
159
160 VkBool32 CheckForDesiredMsg(uint32_t message_code, const char *msgString) {
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600161 VkBool32 result = VK_FALSE;
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600162 test_platform_thread_lock_mutex(&m_mutex);
Mike Stroyanaccf7692015-05-12 16:00:45 -0600163 if (m_bailout != NULL) {
164 *m_bailout = true;
165 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600166 string errorString(msgString);
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600167 bool found_expected = false;
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600168
169 for (auto desired_msg : m_desired_message_strings) {
Karl Schultz05cc4e32016-10-12 13:25:23 -0600170 if (desired_msg.length() == 0) {
171 // An empty desired_msg string "" indicates a positive test - not expecting an error.
172 // Return true to avoid calling layers/driver with this error.
173 // And don't erase the "" string, so it remains if another error is found.
174 result = VK_TRUE;
Tony Barbourae58dba2016-12-13 16:30:36 -0700175 found_expected = true;
176 m_msgFound = VK_TRUE;
177 m_failure_message_strings.insert(errorString);
Karl Schultz05cc4e32016-10-12 13:25:23 -0600178 } else if (errorString.find(desired_msg) != string::npos) {
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600179 found_expected = true;
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600180 m_failure_message_strings.insert(errorString);
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600181 m_msgFound = VK_TRUE;
182 result = VK_TRUE;
183 // We only want one match for each expected error so remove from set here
184 // Since we're about the break the loop it's ok to remove from set we're iterating over
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600185 m_desired_message_strings.erase(desired_msg);
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600186 break;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600187 }
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600188 }
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600189 for (auto desired_id : m_desired_message_ids) {
190 if (desired_id == VALIDATION_ERROR_MAX_ENUM) {
191 // A message ID set to MAX_ENUM indicates a positive test - not expecting an error.
192 // Return true to avoid calling layers/driver with this error.
193 result = VK_TRUE;
194 } else if (desired_id == message_code) {
195 // Double-check that the string matches the error enum
196 if (errorString.find(validation_error_map[desired_id]) != string::npos) {
197 found_expected = true;
198 result = VK_TRUE;
199 m_msgFound = VK_TRUE;
200 m_desired_message_ids.erase(desired_id);
201 break;
202 } else {
203 // Treat this message as a regular unexpected error, but print a warning jic
204 printf("Message (%s) from MessageID %d does not correspond to expected message from error Database (%s)\n",
205 errorString.c_str(), desired_id, validation_error_map[desired_id]);
206 }
207 }
208 }
209
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600210 if (!found_expected) {
Chris Forbes5b9442b2016-09-13 16:49:57 +1200211 printf("Unexpected: %s\n", msgString);
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600212 m_otherMsgs.push_back(errorString);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600213 }
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600214 test_platform_thread_unlock_mutex(&m_mutex);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600215 return result;
Mike Stroyanaccf7692015-05-12 16:00:45 -0600216 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600217
Karl Schultz6addd812016-02-02 17:17:23 -0700218 vector<string> GetOtherFailureMsgs(void) { return m_otherMsgs; }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600219
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600220 VkDebugReportFlagsEXT GetMessageFlags(void) { return m_msgFlags; }
221
Karl Schultz6addd812016-02-02 17:17:23 -0700222 VkBool32 DesiredMsgFound(void) { return m_msgFound; }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600223
Karl Schultz6addd812016-02-02 17:17:23 -0700224 void SetBailout(bool *bailout) { m_bailout = bailout; }
Tony Barbour300a6082015-04-07 13:44:53 -0600225
Karl Schultz6addd812016-02-02 17:17:23 -0700226 void DumpFailureMsgs(void) {
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600227 vector<string> otherMsgs = GetOtherFailureMsgs();
Tony Barbour59b42282016-11-03 13:31:28 -0600228 if (otherMsgs.size()) {
229 cout << "Other error messages logged for this test were:" << endl;
230 for (auto iter = otherMsgs.begin(); iter != otherMsgs.end(); iter++) {
231 cout << " " << *iter << endl;
232 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600233 }
234 }
235
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600236 // Helpers
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200237
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600238 // ExpectSuccess now takes an optional argument allowing a custom combination of debug flags
239 void ExpectSuccess(VkDebugReportFlagsEXT message_flag_mask = VK_DEBUG_REPORT_ERROR_BIT_EXT) {
240 m_msgFlags = message_flag_mask;
241 // Match ANY message matching specified type
242 SetDesiredFailureMsg(message_flag_mask, "");
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200243 }
244
245 void VerifyFound() {
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600246 // Not seeing the desired message is a failure. /Before/ throwing, dump any other messages.
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200247 if (!DesiredMsgFound()) {
248 DumpFailureMsgs();
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600249 for (auto desired_msg : m_desired_message_strings) {
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600250 FAIL() << "Did not receive expected error '" << desired_msg << "'";
251 }
Tony Barbour59b42282016-11-03 13:31:28 -0600252 for (auto desired_id : m_desired_message_ids) {
253 FAIL() << "Did not receive expected error '" << desired_id << "'";
254 }
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200255 }
256 }
257
258 void VerifyNotFound() {
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600259 // ExpectSuccess() configured us to match anything. Any error is a failure.
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200260 if (DesiredMsgFound()) {
261 DumpFailureMsgs();
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600262 for (auto msg : m_failure_message_strings) {
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600263 FAIL() << "Expected to succeed but got error: " << msg;
264 }
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200265 }
266 }
267
Karl Schultz6addd812016-02-02 17:17:23 -0700268 private:
269 VkFlags m_msgFlags;
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600270 std::unordered_set<uint32_t>m_desired_message_ids;
271 std::unordered_set<string> m_desired_message_strings;
272 std::unordered_set<string> m_failure_message_strings;
Karl Schultz6addd812016-02-02 17:17:23 -0700273 vector<string> m_otherMsgs;
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600274 test_platform_thread_mutex m_mutex;
Karl Schultz6addd812016-02-02 17:17:23 -0700275 bool *m_bailout;
276 VkBool32 m_msgFound;
Tony Barbour300a6082015-04-07 13:44:53 -0600277};
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500278
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600279static VKAPI_ATTR VkBool32 VKAPI_CALL myDbgFunc(VkFlags msgFlags, VkDebugReportObjectTypeEXT objType, uint64_t srcObject,
280 size_t location, int32_t msgCode, const char *pLayerPrefix, const char *pMsg,
281 void *pUserData) {
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600282 ErrorMonitor *errMonitor = (ErrorMonitor *)pUserData;
283 if (msgFlags & errMonitor->GetMessageFlags()) {
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600284 return errMonitor->CheckForDesiredMsg(msgCode, pMsg);
Tony Barbour0b4d9562015-04-09 10:48:04 -0600285 }
Courtney Goeltzenleuchter06640832015-09-04 13:52:24 -0600286 return false;
Tony Barbour300a6082015-04-07 13:44:53 -0600287}
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500288
Karl Schultz6addd812016-02-02 17:17:23 -0700289class VkLayerTest : public VkRenderFramework {
290 public:
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800291 VkResult BeginCommandBuffer(VkCommandBufferObj &commandBuffer);
292 VkResult EndCommandBuffer(VkCommandBufferObj &commandBuffer);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600293 void VKTriangleTest(const char *vertShaderText, const char *fragShaderText, BsoFailSelect failMask);
294 void GenericDrawPreparation(VkCommandBufferObj *commandBuffer, VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet,
Karl Schultz6addd812016-02-02 17:17:23 -0700295 BsoFailSelect failMask);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600296 void GenericDrawPreparation(VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet, BsoFailSelect failMask) {
297 GenericDrawPreparation(m_commandBuffer, pipelineobj, descriptorSet, failMask);
Karl Schultz6addd812016-02-02 17:17:23 -0700298 }
Tony Barbour300a6082015-04-07 13:44:53 -0600299
Tony Barbourfe3351b2015-07-28 10:17:20 -0600300 /* Convenience functions that use built-in command buffer */
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600301 VkResult BeginCommandBuffer() { return BeginCommandBuffer(*m_commandBuffer); }
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800302 VkResult EndCommandBuffer() { return EndCommandBuffer(*m_commandBuffer); }
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600303 void Draw(uint32_t vertexCount, uint32_t instanceCount, uint32_t firstVertex, uint32_t firstInstance) {
304 m_commandBuffer->Draw(vertexCount, instanceCount, firstVertex, firstInstance);
Karl Schultz6addd812016-02-02 17:17:23 -0700305 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600306 void DrawIndexed(uint32_t indexCount, uint32_t instanceCount, uint32_t firstIndex, int32_t vertexOffset,
Karl Schultz6addd812016-02-02 17:17:23 -0700307 uint32_t firstInstance) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600308 m_commandBuffer->DrawIndexed(indexCount, instanceCount, firstIndex, vertexOffset, firstInstance);
Karl Schultz6addd812016-02-02 17:17:23 -0700309 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600310 void QueueCommandBuffer(bool checkSuccess = true) { m_commandBuffer->QueueCommandBuffer(checkSuccess); }
311 void QueueCommandBuffer(const VkFence &fence) { m_commandBuffer->QueueCommandBuffer(fence); }
312 void BindVertexBuffer(VkConstantBufferObj *vertexBuffer, VkDeviceSize offset, uint32_t binding) {
Karl Schultz6addd812016-02-02 17:17:23 -0700313 m_commandBuffer->BindVertexBuffer(vertexBuffer, offset, binding);
314 }
315 void BindIndexBuffer(VkIndexBufferObj *indexBuffer, VkDeviceSize offset) {
316 m_commandBuffer->BindIndexBuffer(indexBuffer, offset);
317 }
318
319 protected:
320 ErrorMonitor *m_errorMonitor;
Ian Elliott2c1daf52016-05-12 09:41:46 -0600321 bool m_enableWSI;
Tony Barbour300a6082015-04-07 13:44:53 -0600322
323 virtual void SetUp() {
Courtney Goeltzenleuchtercd69eee2015-07-06 09:10:47 -0600324 std::vector<const char *> instance_layer_names;
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600325 std::vector<const char *> instance_extension_names;
326 std::vector<const char *> device_extension_names;
Tony Barbour3fdff9e2015-04-23 12:55:36 -0600327
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700328 instance_extension_names.push_back(VK_EXT_DEBUG_REPORT_EXTENSION_NAME);
Courtney Goeltzenleuchterc2b06fe2015-06-16 15:59:11 -0600329 /*
330 * Since CreateDbgMsgCallback is an instance level extension call
331 * any extension / layer that utilizes that feature also needs
332 * to be enabled at create instance time.
333 */
Karl Schultz6addd812016-02-02 17:17:23 -0700334 // Use Threading layer first to protect others from
335 // ThreadCommandBufferCollision test
Courtney Goeltzenleuchter76885322016-02-06 17:11:22 -0700336 instance_layer_names.push_back("VK_LAYER_GOOGLE_threading");
Tobin Ehlis24aab042016-03-24 10:54:18 -0600337 instance_layer_names.push_back("VK_LAYER_LUNARG_parameter_validation");
Michael Lentine03107b42015-12-11 10:49:51 -0800338 instance_layer_names.push_back("VK_LAYER_LUNARG_object_tracker");
Tobin Ehlisc96f8062016-03-09 16:12:48 -0700339 instance_layer_names.push_back("VK_LAYER_LUNARG_core_validation");
Michael Lentine03107b42015-12-11 10:49:51 -0800340 instance_layer_names.push_back("VK_LAYER_LUNARG_image");
Ian Elliotte48a1382016-04-28 14:22:58 -0600341 instance_layer_names.push_back("VK_LAYER_LUNARG_swapchain");
Dustin Graveseaa78cd2016-01-26 16:30:22 -0700342 instance_layer_names.push_back("VK_LAYER_GOOGLE_unique_objects");
Courtney Goeltzenleuchterd971b612015-06-17 20:51:59 -0600343
Ian Elliott2c1daf52016-05-12 09:41:46 -0600344 if (m_enableWSI) {
345 instance_extension_names.push_back(VK_KHR_SURFACE_EXTENSION_NAME);
346 device_extension_names.push_back(VK_KHR_SWAPCHAIN_EXTENSION_NAME);
347#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
348#if defined(VK_USE_PLATFORM_ANDROID_KHR)
349 instance_extension_names.push_back(VK_KHR_ANDROID_SURFACE_EXTENSION_NAME);
350#endif // VK_USE_PLATFORM_ANDROID_KHR
351#if defined(VK_USE_PLATFORM_MIR_KHR)
352 instance_extension_names.push_back(VK_KHR_MIR_SURFACE_EXTENSION_NAME);
353#endif // VK_USE_PLATFORM_MIR_KHR
354#if defined(VK_USE_PLATFORM_WAYLAND_KHR)
355 instance_extension_names.push_back(VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME);
356#endif // VK_USE_PLATFORM_WAYLAND_KHR
357#if defined(VK_USE_PLATFORM_WIN32_KHR)
358 instance_extension_names.push_back(VK_KHR_WIN32_SURFACE_EXTENSION_NAME);
359#endif // VK_USE_PLATFORM_WIN32_KHR
360#endif // NEED_TO_TEST_THIS_ON_PLATFORM
361#if defined(VK_USE_PLATFORM_XCB_KHR)
362 instance_extension_names.push_back(VK_KHR_XCB_SURFACE_EXTENSION_NAME);
363#elif defined(VK_USE_PLATFORM_XLIB_KHR)
364 instance_extension_names.push_back(VK_KHR_XLIB_SURFACE_EXTENSION_NAME);
365#endif // VK_USE_PLATFORM_XLIB_KHR
366 }
367
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600368 this->app_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
Tony Barbour300a6082015-04-07 13:44:53 -0600369 this->app_info.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800370 this->app_info.pApplicationName = "layer_tests";
371 this->app_info.applicationVersion = 1;
Tony Barbour300a6082015-04-07 13:44:53 -0600372 this->app_info.pEngineName = "unittest";
373 this->app_info.engineVersion = 1;
Jon Ashburnc5012ff2016-03-22 13:57:46 -0600374 this->app_info.apiVersion = VK_API_VERSION_1_0;
Tony Barbour300a6082015-04-07 13:44:53 -0600375
Tony Barbour15524c32015-04-29 17:34:29 -0600376 m_errorMonitor = new ErrorMonitor;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600377 InitFramework(instance_layer_names, instance_extension_names, device_extension_names, myDbgFunc, m_errorMonitor);
Tony Barbour300a6082015-04-07 13:44:53 -0600378 }
379
380 virtual void TearDown() {
381 // Clean up resources before we reset
Tony Barbour300a6082015-04-07 13:44:53 -0600382 ShutdownFramework();
Tony Barbour0b4d9562015-04-09 10:48:04 -0600383 delete m_errorMonitor;
Tony Barbour300a6082015-04-07 13:44:53 -0600384 }
Ian Elliott2c1daf52016-05-12 09:41:46 -0600385
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600386 VkLayerTest() { m_enableWSI = false; }
Tony Barbour300a6082015-04-07 13:44:53 -0600387};
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500388
Karl Schultz6addd812016-02-02 17:17:23 -0700389VkResult VkLayerTest::BeginCommandBuffer(VkCommandBufferObj &commandBuffer) {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600390 VkResult result;
Tony Barbour300a6082015-04-07 13:44:53 -0600391
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800392 result = commandBuffer.BeginCommandBuffer();
Tony Barbour300a6082015-04-07 13:44:53 -0600393
394 /*
395 * For render test all drawing happens in a single render pass
396 * on a single command buffer.
397 */
Chris Forbes76a5eeb2015-06-16 14:05:59 +1200398 if (VK_SUCCESS == result && renderPass()) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800399 commandBuffer.BeginRenderPass(renderPassBeginInfo());
Tony Barbour300a6082015-04-07 13:44:53 -0600400 }
401
402 return result;
403}
404
Karl Schultz6addd812016-02-02 17:17:23 -0700405VkResult VkLayerTest::EndCommandBuffer(VkCommandBufferObj &commandBuffer) {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600406 VkResult result;
Tony Barbour300a6082015-04-07 13:44:53 -0600407
Chris Forbes76a5eeb2015-06-16 14:05:59 +1200408 if (renderPass()) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800409 commandBuffer.EndRenderPass();
Chris Forbes76a5eeb2015-06-16 14:05:59 +1200410 }
Tony Barbour300a6082015-04-07 13:44:53 -0600411
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800412 result = commandBuffer.EndCommandBuffer();
Tony Barbour300a6082015-04-07 13:44:53 -0600413
414 return result;
415}
416
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600417void VkLayerTest::VKTriangleTest(const char *vertShaderText, const char *fragShaderText, BsoFailSelect failMask) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500418 // Create identity matrix
419 int i;
420 struct vktriangle_vs_uniform data;
421
422 glm::mat4 Projection = glm::mat4(1.0f);
Karl Schultz6addd812016-02-02 17:17:23 -0700423 glm::mat4 View = glm::mat4(1.0f);
424 glm::mat4 Model = glm::mat4(1.0f);
425 glm::mat4 MVP = Projection * View * Model;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500426 const int matrixSize = sizeof(MVP);
Karl Schultz6addd812016-02-02 17:17:23 -0700427 const int bufSize = sizeof(vktriangle_vs_uniform) / sizeof(float);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500428
429 memcpy(&data.mvp, &MVP[0][0], matrixSize);
430
Karl Schultz6addd812016-02-02 17:17:23 -0700431 static const Vertex tri_data[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600432 {XYZ1(-1, -1, 0), XYZ1(1.f, 0.f, 0.f)}, {XYZ1(1, -1, 0), XYZ1(0.f, 1.f, 0.f)}, {XYZ1(0, 1, 0), XYZ1(0.f, 0.f, 1.f)},
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500433 };
434
Karl Schultz6addd812016-02-02 17:17:23 -0700435 for (i = 0; i < 3; i++) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500436 data.position[i][0] = tri_data[i].posX;
437 data.position[i][1] = tri_data[i].posY;
438 data.position[i][2] = tri_data[i].posZ;
439 data.position[i][3] = tri_data[i].posW;
Karl Schultz6addd812016-02-02 17:17:23 -0700440 data.color[i][0] = tri_data[i].r;
441 data.color[i][1] = tri_data[i].g;
442 data.color[i][2] = tri_data[i].b;
443 data.color[i][3] = tri_data[i].a;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500444 }
445
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500446 ASSERT_NO_FATAL_FAILURE(InitViewport());
447
Chris Forbesbcfaadd2016-09-16 14:13:53 +1200448 VkConstantBufferObj constantBuffer(m_device, bufSize * 2, sizeof(float), (const void *)&data,
449 VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500450
Karl Schultz6addd812016-02-02 17:17:23 -0700451 VkShaderObj vs(m_device, vertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600452 VkShaderObj ps(m_device, fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500453
454 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +0800455 pipelineobj.AddColorAttachment();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500456 pipelineobj.AddShader(&vs);
457 pipelineobj.AddShader(&ps);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600458 if (failMask & BsoFailLineWidth) {
459 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_LINE_WIDTH);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600460 VkPipelineInputAssemblyStateCreateInfo ia_state = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600461 ia_state.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600462 ia_state.topology = VK_PRIMITIVE_TOPOLOGY_LINE_LIST;
463 pipelineobj.SetInputAssembly(&ia_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600464 }
465 if (failMask & BsoFailDepthBias) {
466 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_DEPTH_BIAS);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600467 VkPipelineRasterizationStateCreateInfo rs_state = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600468 rs_state.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600469 rs_state.depthBiasEnable = VK_TRUE;
Mark Young7394fdd2016-03-31 14:56:43 -0600470 rs_state.lineWidth = 1.0f;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600471 pipelineobj.SetRasterization(&rs_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600472 }
Karl Schultz6addd812016-02-02 17:17:23 -0700473 // Viewport and scissors must stay in synch or other errors will occur than
474 // the ones we want
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600475 if (failMask & BsoFailViewport) {
476 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_VIEWPORT);
477 }
478 if (failMask & BsoFailScissor) {
479 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_SCISSOR);
480 }
481 if (failMask & BsoFailBlend) {
482 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_BLEND_CONSTANTS);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600483 VkPipelineColorBlendAttachmentState att_state = {};
484 att_state.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
485 att_state.blendEnable = VK_TRUE;
486 pipelineobj.AddColorAttachment(0, &att_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600487 }
488 if (failMask & BsoFailDepthBounds) {
489 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_DEPTH_BOUNDS);
490 }
491 if (failMask & BsoFailStencilReadMask) {
492 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK);
493 }
494 if (failMask & BsoFailStencilWriteMask) {
495 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_WRITE_MASK);
496 }
497 if (failMask & BsoFailStencilReference) {
498 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_REFERENCE);
499 }
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500500
501 VkDescriptorSetObj descriptorSet(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600502 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, constantBuffer);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500503
504 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -0600505 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500506
Tony Barbourfe3351b2015-07-28 10:17:20 -0600507 GenericDrawPreparation(pipelineobj, descriptorSet, failMask);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500508
509 // render triangle
Tobin Ehlis379ba3b2016-07-19 11:22:29 -0600510 if (failMask & BsoFailIndexBuffer) {
511 // Use DrawIndexed w/o an index buffer bound
512 DrawIndexed(3, 1, 0, 0, 0);
513 } else {
514 Draw(3, 1, 0, 0);
515 }
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500516
Mark Muellerd4914412016-06-13 17:52:06 -0600517 if (failMask & BsoFailCmdClearAttachments) {
518 VkClearAttachment color_attachment = {};
519 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
520 color_attachment.colorAttachment = 1; // Someone who knew what they were doing would use 0 for the index;
521 VkClearRect clear_rect = {{{0, 0}, {static_cast<uint32_t>(m_width), static_cast<uint32_t>(m_height)}}, 0, 0};
522
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600523 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Muellerd4914412016-06-13 17:52:06 -0600524 }
525
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500526 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -0600527 EndCommandBuffer();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500528
Tony Barbourfe3351b2015-07-28 10:17:20 -0600529 QueueCommandBuffer();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500530}
531
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600532void VkLayerTest::GenericDrawPreparation(VkCommandBufferObj *commandBuffer, VkPipelineObj &pipelineobj,
533 VkDescriptorSetObj &descriptorSet, BsoFailSelect failMask) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500534 if (m_depthStencil->Initialized()) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600535 commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, m_depthStencil);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500536 } else {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600537 commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500538 }
539
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800540 commandBuffer->PrepareAttachments();
Karl Schultz6addd812016-02-02 17:17:23 -0700541 // Make sure depthWriteEnable is set so that Depth fail test will work
542 // correctly
543 // Make sure stencilTestEnable is set so that Stencil fail test will work
544 // correctly
Tony Barboureb254902015-07-15 12:50:33 -0600545 VkStencilOpState stencil = {};
Chia-I Wu1b99bb22015-10-27 19:25:11 +0800546 stencil.failOp = VK_STENCIL_OP_KEEP;
547 stencil.passOp = VK_STENCIL_OP_KEEP;
548 stencil.depthFailOp = VK_STENCIL_OP_KEEP;
549 stencil.compareOp = VK_COMPARE_OP_NEVER;
Tony Barboureb254902015-07-15 12:50:33 -0600550
551 VkPipelineDepthStencilStateCreateInfo ds_ci = {};
552 ds_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO;
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600553 ds_ci.pNext = NULL;
554 ds_ci.depthTestEnable = VK_FALSE;
555 ds_ci.depthWriteEnable = VK_TRUE;
556 ds_ci.depthCompareOp = VK_COMPARE_OP_NEVER;
557 ds_ci.depthBoundsTestEnable = VK_FALSE;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600558 if (failMask & BsoFailDepthBounds) {
559 ds_ci.depthBoundsTestEnable = VK_TRUE;
Tobin Ehlis21c88352016-05-26 06:15:45 -0600560 ds_ci.maxDepthBounds = 0.0f;
561 ds_ci.minDepthBounds = 0.0f;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600562 }
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600563 ds_ci.stencilTestEnable = VK_TRUE;
564 ds_ci.front = stencil;
565 ds_ci.back = stencil;
Tony Barboureb254902015-07-15 12:50:33 -0600566
Tobin Ehlis4bf96d12015-06-25 11:58:41 -0600567 pipelineobj.SetDepthStencil(&ds_ci);
Tobin Ehlisd332f282015-10-02 11:00:56 -0600568 pipelineobj.SetViewport(m_viewports);
569 pipelineobj.SetScissor(m_scissors);
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800570 descriptorSet.CreateVKDescriptorSet(commandBuffer);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600571 VkResult err = pipelineobj.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Cody Northrop29a08f22015-08-27 10:20:35 -0600572 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800573 commandBuffer->BindPipeline(pipelineobj);
574 commandBuffer->BindDescriptorSet(descriptorSet);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500575}
576
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600577class VkPositiveLayerTest : public VkLayerTest {
578 public:
579 protected:
580};
581
Ian Elliott2c1daf52016-05-12 09:41:46 -0600582class VkWsiEnabledLayerTest : public VkLayerTest {
583 public:
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600584 protected:
585 VkWsiEnabledLayerTest() { m_enableWSI = true; }
Ian Elliott2c1daf52016-05-12 09:41:46 -0600586};
587
Mark Muellerdfe37552016-07-07 14:47:42 -0600588class VkBufferTest {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600589 public:
Mark Muellerdfe37552016-07-07 14:47:42 -0600590 enum eTestEnFlags {
591 eDoubleDelete,
592 eInvalidDeviceOffset,
593 eInvalidMemoryOffset,
594 eBindNullBuffer,
595 eFreeInvalidHandle,
Mark Mueller4042b652016-09-05 22:52:21 -0600596 eNone,
Mark Muellerdfe37552016-07-07 14:47:42 -0600597 };
598
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600599 enum eTestConditions { eOffsetAlignment = 1 };
Mark Muellerdfe37552016-07-07 14:47:42 -0600600
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600601 static bool GetTestConditionValid(VkDeviceObj *aVulkanDevice, eTestEnFlags aTestFlag, VkBufferUsageFlags aBufferUsage = 0) {
602 if (eInvalidDeviceOffset != aTestFlag && eInvalidMemoryOffset != aTestFlag) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600603 return true;
604 }
605 VkDeviceSize offset_limit = 0;
606 if (eInvalidMemoryOffset == aTestFlag) {
607 VkBuffer vulkanBuffer;
608 VkBufferCreateInfo buffer_create_info = {};
609 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
610 buffer_create_info.size = 32;
611 buffer_create_info.usage = aBufferUsage;
612
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600613 vkCreateBuffer(aVulkanDevice->device(), &buffer_create_info, nullptr, &vulkanBuffer);
Mark Mueller4042b652016-09-05 22:52:21 -0600614 VkMemoryRequirements memory_reqs = {};
Mark Muellerdfe37552016-07-07 14:47:42 -0600615
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600616 vkGetBufferMemoryRequirements(aVulkanDevice->device(), vulkanBuffer, &memory_reqs);
Mark Muellerdfe37552016-07-07 14:47:42 -0600617 vkDestroyBuffer(aVulkanDevice->device(), vulkanBuffer, nullptr);
618 offset_limit = memory_reqs.alignment;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600619 } else if ((VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT | VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT) & aBufferUsage) {
620 offset_limit = aVulkanDevice->props.limits.minTexelBufferOffsetAlignment;
Mark Muellerdfe37552016-07-07 14:47:42 -0600621 } else if (VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT & aBufferUsage) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600622 offset_limit = aVulkanDevice->props.limits.minUniformBufferOffsetAlignment;
Mark Muellerdfe37552016-07-07 14:47:42 -0600623 } else if (VK_BUFFER_USAGE_STORAGE_BUFFER_BIT & aBufferUsage) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600624 offset_limit = aVulkanDevice->props.limits.minStorageBufferOffsetAlignment;
Mark Muellerdfe37552016-07-07 14:47:42 -0600625 }
626 if (eOffsetAlignment < offset_limit) {
627 return true;
628 }
629 return false;
630 }
631
632 // A constructor which performs validation tests within construction.
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600633 VkBufferTest(VkDeviceObj *aVulkanDevice, VkBufferUsageFlags aBufferUsage, eTestEnFlags aTestFlag = eNone)
634 : AllocateCurrent(false), BoundCurrent(false), CreateCurrent(false), VulkanDevice(aVulkanDevice->device()) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600635
636 if (eBindNullBuffer == aTestFlag) {
637 VulkanMemory = 0;
638 vkBindBufferMemory(VulkanDevice, VulkanBuffer, VulkanMemory, 0);
639 } else {
640 VkBufferCreateInfo buffer_create_info = {};
641 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
642 buffer_create_info.size = 32;
643 buffer_create_info.usage = aBufferUsage;
644
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600645 vkCreateBuffer(VulkanDevice, &buffer_create_info, nullptr, &VulkanBuffer);
Mark Muellerdfe37552016-07-07 14:47:42 -0600646
647 CreateCurrent = true;
648
649 VkMemoryRequirements memory_requirements;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600650 vkGetBufferMemoryRequirements(VulkanDevice, VulkanBuffer, &memory_requirements);
Mark Muellerdfe37552016-07-07 14:47:42 -0600651
652 VkMemoryAllocateInfo memory_allocate_info = {};
653 memory_allocate_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
654 memory_allocate_info.allocationSize = memory_requirements.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600655 bool pass = aVulkanDevice->phy().set_memory_type(memory_requirements.memoryTypeBits, &memory_allocate_info,
656 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
Mark Muellerdfe37552016-07-07 14:47:42 -0600657 if (!pass) {
658 vkDestroyBuffer(VulkanDevice, VulkanBuffer, nullptr);
659 return;
660 }
661
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600662 vkAllocateMemory(VulkanDevice, &memory_allocate_info, NULL, &VulkanMemory);
Mark Muellerdfe37552016-07-07 14:47:42 -0600663 AllocateCurrent = true;
664 // NB: 1 is intentionally an invalid offset value
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600665 const bool offset_en = eInvalidDeviceOffset == aTestFlag || eInvalidMemoryOffset == aTestFlag;
666 vkBindBufferMemory(VulkanDevice, VulkanBuffer, VulkanMemory, offset_en ? eOffsetAlignment : 0);
Mark Muellerdfe37552016-07-07 14:47:42 -0600667 BoundCurrent = true;
668
669 InvalidDeleteEn = (eFreeInvalidHandle == aTestFlag);
670 }
671 }
672
673 ~VkBufferTest() {
674 if (CreateCurrent) {
675 vkDestroyBuffer(VulkanDevice, VulkanBuffer, nullptr);
676 }
677 if (AllocateCurrent) {
678 if (InvalidDeleteEn) {
679 union {
680 VkDeviceMemory device_memory;
681 unsigned long long index_access;
682 } bad_index;
683
684 bad_index.device_memory = VulkanMemory;
685 bad_index.index_access++;
686
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600687 vkFreeMemory(VulkanDevice, bad_index.device_memory, nullptr);
Mark Muellerdfe37552016-07-07 14:47:42 -0600688 }
689 vkFreeMemory(VulkanDevice, VulkanMemory, nullptr);
690 }
691 }
692
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600693 bool GetBufferCurrent() { return AllocateCurrent && BoundCurrent && CreateCurrent; }
Mark Muellerdfe37552016-07-07 14:47:42 -0600694
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600695 const VkBuffer &GetBuffer() { return VulkanBuffer; }
Mark Muellerdfe37552016-07-07 14:47:42 -0600696
697 void TestDoubleDestroy() {
698 // Destroy the buffer but leave the flag set, which will cause
699 // the buffer to be destroyed again in the destructor.
700 vkDestroyBuffer(VulkanDevice, VulkanBuffer, nullptr);
701 }
702
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600703 protected:
Mark Muellerdfe37552016-07-07 14:47:42 -0600704 bool AllocateCurrent;
705 bool BoundCurrent;
706 bool CreateCurrent;
707 bool InvalidDeleteEn;
708
709 VkBuffer VulkanBuffer;
710 VkDevice VulkanDevice;
711 VkDeviceMemory VulkanMemory;
Mark Muellerdfe37552016-07-07 14:47:42 -0600712};
713
714class VkVerticesObj {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600715 public:
716 VkVerticesObj(VkDeviceObj *aVulkanDevice, unsigned aAttributeCount, unsigned aBindingCount, unsigned aByteStride,
Mark Muellerdfe37552016-07-07 14:47:42 -0600717 VkDeviceSize aVertexCount, const float *aVerticies)
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600718 : BoundCurrent(false), AttributeCount(aAttributeCount), BindingCount(aBindingCount), BindId(BindIdGenerator),
Mark Muellerdfe37552016-07-07 14:47:42 -0600719 PipelineVertexInputStateCreateInfo(),
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600720 VulkanMemoryBuffer(aVulkanDevice, 1, static_cast<int>(aByteStride * aVertexCount),
721 reinterpret_cast<const void *>(aVerticies), VK_BUFFER_USAGE_VERTEX_BUFFER_BIT) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600722 BindIdGenerator++; // NB: This can wrap w/misuse
723
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600724 VertexInputAttributeDescription = new VkVertexInputAttributeDescription[AttributeCount];
725 VertexInputBindingDescription = new VkVertexInputBindingDescription[BindingCount];
Mark Muellerdfe37552016-07-07 14:47:42 -0600726
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600727 PipelineVertexInputStateCreateInfo.pVertexAttributeDescriptions = VertexInputAttributeDescription;
728 PipelineVertexInputStateCreateInfo.vertexAttributeDescriptionCount = AttributeCount;
729 PipelineVertexInputStateCreateInfo.pVertexBindingDescriptions = VertexInputBindingDescription;
730 PipelineVertexInputStateCreateInfo.vertexBindingDescriptionCount = BindingCount;
731 PipelineVertexInputStateCreateInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
Mark Muellerdfe37552016-07-07 14:47:42 -0600732
733 unsigned i = 0;
734 do {
735 VertexInputAttributeDescription[i].binding = BindId;
736 VertexInputAttributeDescription[i].location = i;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600737 VertexInputAttributeDescription[i].format = VK_FORMAT_R32G32B32_SFLOAT;
738 VertexInputAttributeDescription[i].offset = sizeof(float) * aByteStride;
Mark Muellerdfe37552016-07-07 14:47:42 -0600739 i++;
740 } while (AttributeCount < i);
741
742 i = 0;
743 do {
744 VertexInputBindingDescription[i].binding = BindId;
745 VertexInputBindingDescription[i].stride = aByteStride;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600746 VertexInputBindingDescription[i].inputRate = VK_VERTEX_INPUT_RATE_VERTEX;
Mark Muellerdfe37552016-07-07 14:47:42 -0600747 i++;
748 } while (BindingCount < i);
749 }
750
751 ~VkVerticesObj() {
752 if (VertexInputAttributeDescription) {
753 delete[] VertexInputAttributeDescription;
754 }
755 if (VertexInputBindingDescription) {
756 delete[] VertexInputBindingDescription;
757 }
758 }
759
760 bool AddVertexInputToPipe(VkPipelineObj &aPipelineObj) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600761 aPipelineObj.AddVertexInputAttribs(VertexInputAttributeDescription, AttributeCount);
762 aPipelineObj.AddVertexInputBindings(VertexInputBindingDescription, BindingCount);
Mark Muellerdfe37552016-07-07 14:47:42 -0600763 return true;
764 }
765
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600766 void BindVertexBuffers(VkCommandBuffer aCommandBuffer, unsigned aOffsetCount = 0, VkDeviceSize *aOffsetList = nullptr) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600767 VkDeviceSize *offsetList;
768 unsigned offsetCount;
769
770 if (aOffsetCount) {
771 offsetList = aOffsetList;
772 offsetCount = aOffsetCount;
773 } else {
774 offsetList = new VkDeviceSize[1]();
775 offsetCount = 1;
776 }
777
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600778 vkCmdBindVertexBuffers(aCommandBuffer, BindId, offsetCount, &VulkanMemoryBuffer.handle(), offsetList);
Mark Muellerdfe37552016-07-07 14:47:42 -0600779 BoundCurrent = true;
780
781 if (!aOffsetCount) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600782 delete[] offsetList;
Mark Muellerdfe37552016-07-07 14:47:42 -0600783 }
784 }
785
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600786 protected:
Mark Muellerdfe37552016-07-07 14:47:42 -0600787 static uint32_t BindIdGenerator;
788
789 bool BoundCurrent;
790 unsigned AttributeCount;
791 unsigned BindingCount;
792 uint32_t BindId;
793
794 VkPipelineVertexInputStateCreateInfo PipelineVertexInputStateCreateInfo;
795 VkVertexInputAttributeDescription *VertexInputAttributeDescription;
796 VkVertexInputBindingDescription *VertexInputBindingDescription;
797 VkConstantBufferObj VulkanMemoryBuffer;
798};
799
800uint32_t VkVerticesObj::BindIdGenerator;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500801// ********************************************************************************************************************
802// ********************************************************************************************************************
803// ********************************************************************************************************************
804// ********************************************************************************************************************
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600805#if PARAMETER_VALIDATION_TESTS
806TEST_F(VkLayerTest, RequiredParameter) {
807 TEST_DESCRIPTION("Specify VK_NULL_HANDLE, NULL, and 0 for required handle, "
808 "pointer, array, and array count parameters");
809
810 ASSERT_NO_FATAL_FAILURE(InitState());
811
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600812 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pFeatures specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600813 // Specify NULL for a pointer to a handle
814 // Expected to trigger an error with
815 // parameter_validation::validate_required_pointer
816 vkGetPhysicalDeviceFeatures(gpu(), NULL);
817 m_errorMonitor->VerifyFound();
818
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600819 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
820 "required parameter pQueueFamilyPropertyCount specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600821 // Specify NULL for pointer to array count
822 // Expected to trigger an error with parameter_validation::validate_array
Dustin Gravesa4bb8c12016-05-16 17:22:51 -0600823 vkGetPhysicalDeviceQueueFamilyProperties(gpu(), NULL, NULL);
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600824 m_errorMonitor->VerifyFound();
825
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600826 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter viewportCount must be greater than 0");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600827 // Specify 0 for a required array count
828 // Expected to trigger an error with parameter_validation::validate_array
829 VkViewport view_port = {};
830 m_commandBuffer->SetViewport(0, 0, &view_port);
831 m_errorMonitor->VerifyFound();
832
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600833 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pViewports specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600834 // Specify NULL for a required array
835 // Expected to trigger an error with parameter_validation::validate_array
836 m_commandBuffer->SetViewport(0, 1, NULL);
837 m_errorMonitor->VerifyFound();
838
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600839 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter memory specified as VK_NULL_HANDLE");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600840 // Specify VK_NULL_HANDLE for a required handle
841 // Expected to trigger an error with
842 // parameter_validation::validate_required_handle
843 vkUnmapMemory(device(), VK_NULL_HANDLE);
844 m_errorMonitor->VerifyFound();
845
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600846 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
847 "required parameter pFences[0] specified as VK_NULL_HANDLE");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600848 // Specify VK_NULL_HANDLE for a required handle array entry
849 // Expected to trigger an error with
850 // parameter_validation::validate_required_handle_array
851 VkFence fence = VK_NULL_HANDLE;
852 vkResetFences(device(), 1, &fence);
853 m_errorMonitor->VerifyFound();
854
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600855 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pAllocateInfo specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600856 // Specify NULL for a required struct pointer
857 // Expected to trigger an error with
858 // parameter_validation::validate_struct_type
859 VkDeviceMemory memory = VK_NULL_HANDLE;
860 vkAllocateMemory(device(), NULL, NULL, &memory);
861 m_errorMonitor->VerifyFound();
862
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600863 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "value of faceMask must not be 0");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600864 // Specify 0 for a required VkFlags parameter
865 // Expected to trigger an error with parameter_validation::validate_flags
866 m_commandBuffer->SetStencilReference(0, 0);
867 m_errorMonitor->VerifyFound();
868
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600869 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "value of pSubmits[0].pWaitDstStageMask[0] must not be 0");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600870 // Specify 0 for a required VkFlags array entry
871 // Expected to trigger an error with
872 // parameter_validation::validate_flags_array
873 VkSemaphore semaphore = VK_NULL_HANDLE;
874 VkPipelineStageFlags stageFlags = 0;
875 VkSubmitInfo submitInfo = {};
876 submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
877 submitInfo.waitSemaphoreCount = 1;
878 submitInfo.pWaitSemaphores = &semaphore;
879 submitInfo.pWaitDstStageMask = &stageFlags;
880 vkQueueSubmit(m_device->m_queue, 1, &submitInfo, VK_NULL_HANDLE);
881 m_errorMonitor->VerifyFound();
882}
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600883
Dustin Gravesfce74c02016-05-10 11:42:58 -0600884TEST_F(VkLayerTest, ReservedParameter) {
885 TEST_DESCRIPTION("Specify a non-zero value for a reserved parameter");
886
887 ASSERT_NO_FATAL_FAILURE(InitState());
888
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600889 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " must be 0");
Dustin Gravesfce74c02016-05-10 11:42:58 -0600890 // Specify 0 for a reserved VkFlags parameter
891 // Expected to trigger an error with
892 // parameter_validation::validate_reserved_flags
893 VkEvent event_handle = VK_NULL_HANDLE;
894 VkEventCreateInfo event_info = {};
895 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
896 event_info.flags = 1;
897 vkCreateEvent(device(), &event_info, NULL, &event_handle);
898 m_errorMonitor->VerifyFound();
899}
900
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600901TEST_F(VkLayerTest, InvalidStructSType) {
902 TEST_DESCRIPTION("Specify an invalid VkStructureType for a Vulkan "
903 "structure's sType field");
904
905 ASSERT_NO_FATAL_FAILURE(InitState());
906
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600907 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pAllocateInfo->sType must be");
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600908 // Zero struct memory, effectively setting sType to
909 // VK_STRUCTURE_TYPE_APPLICATION_INFO
910 // Expected to trigger an error with
911 // parameter_validation::validate_struct_type
912 VkMemoryAllocateInfo alloc_info = {};
913 VkDeviceMemory memory = VK_NULL_HANDLE;
914 vkAllocateMemory(device(), &alloc_info, NULL, &memory);
915 m_errorMonitor->VerifyFound();
916
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600917 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pSubmits[0].sType must be");
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600918 // Zero struct memory, effectively setting sType to
919 // VK_STRUCTURE_TYPE_APPLICATION_INFO
920 // Expected to trigger an error with
921 // parameter_validation::validate_struct_type_array
922 VkSubmitInfo submit_info = {};
923 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
924 m_errorMonitor->VerifyFound();
925}
926
927TEST_F(VkLayerTest, InvalidStructPNext) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600928 TEST_DESCRIPTION("Specify an invalid value for a Vulkan structure's pNext field");
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600929
930 ASSERT_NO_FATAL_FAILURE(InitState());
931
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600932 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "value of pCreateInfo->pNext must be NULL");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600933 // Set VkMemoryAllocateInfo::pNext to a non-NULL value, when pNext must be NULL.
Karl Schultz38b50992016-07-11 16:09:09 -0600934 // Need to pick a function that has no allowed pNext structure types.
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600935 // Expected to trigger an error with parameter_validation::validate_struct_pnext
Karl Schultz38b50992016-07-11 16:09:09 -0600936 VkEvent event = VK_NULL_HANDLE;
Karl Schultz70db3902016-07-11 16:22:10 -0600937 VkEventCreateInfo event_alloc_info = {};
Karl Schultz38b50992016-07-11 16:09:09 -0600938 // Zero-initialization will provide the correct sType
939 VkApplicationInfo app_info = {};
940 event_alloc_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
941 event_alloc_info.pNext = &app_info;
942 vkCreateEvent(device(), &event_alloc_info, NULL, &event);
943 m_errorMonitor->VerifyFound();
944
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600945 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
946 " chain includes a structure with unexpected VkStructureType ");
Karl Schultz38b50992016-07-11 16:09:09 -0600947 // Set VkMemoryAllocateInfo::pNext to a non-NULL value, but use
948 // a function that has allowed pNext structure types and specify
949 // a structure type that is not allowed.
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600950 // Expected to trigger an error with parameter_validation::validate_struct_pnext
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600951 VkDeviceMemory memory = VK_NULL_HANDLE;
Dustin Graves47b6cba2016-05-10 17:34:38 -0600952 VkMemoryAllocateInfo memory_alloc_info = {};
953 memory_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
954 memory_alloc_info.pNext = &app_info;
955 vkAllocateMemory(device(), &memory_alloc_info, NULL, &memory);
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600956 m_errorMonitor->VerifyFound();
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600957}
Dustin Graves5d33d532016-05-09 16:21:12 -0600958
959TEST_F(VkLayerTest, UnrecognizedValue) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600960 TEST_DESCRIPTION("Specify unrecognized Vulkan enumeration, flags, and VkBool32 values");
Dustin Graves5d33d532016-05-09 16:21:12 -0600961
962 ASSERT_NO_FATAL_FAILURE(InitState());
963
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600964 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "does not fall within the begin..end "
965 "range of the core VkFormat "
966 "enumeration tokens");
Dustin Graves5d33d532016-05-09 16:21:12 -0600967 // Specify an invalid VkFormat value
968 // Expected to trigger an error with
969 // parameter_validation::validate_ranged_enum
970 VkFormatProperties format_properties;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600971 vkGetPhysicalDeviceFormatProperties(gpu(), static_cast<VkFormat>(8000), &format_properties);
Dustin Graves5d33d532016-05-09 16:21:12 -0600972 m_errorMonitor->VerifyFound();
973
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600974 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "contains flag bits that are not recognized members of");
Dustin Graves5d33d532016-05-09 16:21:12 -0600975 // Specify an invalid VkFlags bitmask value
976 // Expected to trigger an error with parameter_validation::validate_flags
977 VkImageFormatProperties image_format_properties;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600978 vkGetPhysicalDeviceImageFormatProperties(gpu(), VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
979 static_cast<VkImageUsageFlags>(1 << 25), 0, &image_format_properties);
Dustin Graves5d33d532016-05-09 16:21:12 -0600980 m_errorMonitor->VerifyFound();
981
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600982 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "contains flag bits that are not recognized members of");
Dustin Graves5d33d532016-05-09 16:21:12 -0600983 // Specify an invalid VkFlags array entry
984 // Expected to trigger an error with
985 // parameter_validation::validate_flags_array
986 VkSemaphore semaphore = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600987 VkPipelineStageFlags stage_flags = static_cast<VkPipelineStageFlags>(1 << 25);
Dustin Graves5d33d532016-05-09 16:21:12 -0600988 VkSubmitInfo submit_info = {};
989 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
990 submit_info.waitSemaphoreCount = 1;
991 submit_info.pWaitSemaphores = &semaphore;
992 submit_info.pWaitDstStageMask = &stage_flags;
993 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
994 m_errorMonitor->VerifyFound();
995
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600996 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "is neither VK_TRUE nor VK_FALSE");
Dustin Graves5d33d532016-05-09 16:21:12 -0600997 // Specify an invalid VkBool32 value
998 // Expected to trigger a warning with
999 // parameter_validation::validate_bool32
1000 VkSampler sampler = VK_NULL_HANDLE;
1001 VkSamplerCreateInfo sampler_info = {};
1002 sampler_info.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
1003 sampler_info.pNext = NULL;
1004 sampler_info.magFilter = VK_FILTER_NEAREST;
1005 sampler_info.minFilter = VK_FILTER_NEAREST;
1006 sampler_info.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
1007 sampler_info.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
1008 sampler_info.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
1009 sampler_info.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
1010 sampler_info.mipLodBias = 1.0;
1011 sampler_info.maxAnisotropy = 1;
1012 sampler_info.compareEnable = VK_FALSE;
1013 sampler_info.compareOp = VK_COMPARE_OP_NEVER;
1014 sampler_info.minLod = 1.0;
1015 sampler_info.maxLod = 1.0;
1016 sampler_info.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
1017 sampler_info.unnormalizedCoordinates = VK_FALSE;
1018 // Not VK_TRUE or VK_FALSE
1019 sampler_info.anisotropyEnable = 3;
1020 vkCreateSampler(m_device->device(), &sampler_info, NULL, &sampler);
1021 m_errorMonitor->VerifyFound();
1022}
Dustin Gravesfce74c02016-05-10 11:42:58 -06001023
1024TEST_F(VkLayerTest, FailedReturnValue) {
1025 TEST_DESCRIPTION("Check for a message describing a VkResult failure code");
1026
1027 ASSERT_NO_FATAL_FAILURE(InitState());
1028
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001029 // Find an unsupported image format
1030 VkFormat unsupported = VK_FORMAT_UNDEFINED;
1031 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
1032 VkFormat format = static_cast<VkFormat>(f);
1033 VkFormatProperties fProps = m_device->format_properties(format);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001034 if (format != VK_FORMAT_UNDEFINED && fProps.linearTilingFeatures == 0 && fProps.optimalTilingFeatures == 0) {
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001035 unsupported = format;
1036 break;
1037 }
1038 }
1039
1040 if (unsupported != VK_FORMAT_UNDEFINED) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001041 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
1042 "the requested format is not supported on this device");
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001043 // Specify an unsupported VkFormat value to generate a
1044 // VK_ERROR_FORMAT_NOT_SUPPORTED return code
1045 // Expected to trigger a warning from
1046 // parameter_validation::validate_result
1047 VkImageFormatProperties image_format_properties;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001048 VkResult err = vkGetPhysicalDeviceImageFormatProperties(gpu(), unsupported, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
1049 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, 0, &image_format_properties);
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001050 ASSERT_TRUE(err == VK_ERROR_FORMAT_NOT_SUPPORTED);
1051 m_errorMonitor->VerifyFound();
1052 }
Dustin Gravesfce74c02016-05-10 11:42:58 -06001053}
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001054
1055TEST_F(VkLayerTest, UpdateBufferAlignment) {
1056 TEST_DESCRIPTION("Check alignment parameters for vkCmdUpdateBuffer");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001057 uint32_t updateData[] = {1, 2, 3, 4, 5, 6, 7, 8};
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001058
1059 ASSERT_NO_FATAL_FAILURE(InitState());
1060
1061 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
1062 vk_testing::Buffer buffer;
1063 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
1064
1065 BeginCommandBuffer();
1066 // Introduce failure by using dstOffset that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001067 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001068 m_commandBuffer->UpdateBuffer(buffer.handle(), 1, 4, updateData);
1069 m_errorMonitor->VerifyFound();
1070
1071 // Introduce failure by using dataSize that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001072 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001073 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, 6, updateData);
1074 m_errorMonitor->VerifyFound();
1075
1076 // Introduce failure by using dataSize that is < 0
1077 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001078 "must be greater than zero and less than or equal to 65536");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001079 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, -44, updateData);
1080 m_errorMonitor->VerifyFound();
1081
1082 // Introduce failure by using dataSize that is > 65536
1083 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001084 "must be greater than zero and less than or equal to 65536");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001085 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, 80000, updateData);
1086 m_errorMonitor->VerifyFound();
1087
1088 EndCommandBuffer();
1089}
1090
1091TEST_F(VkLayerTest, FillBufferAlignment) {
1092 TEST_DESCRIPTION("Check alignment parameters for vkCmdFillBuffer");
1093
1094 ASSERT_NO_FATAL_FAILURE(InitState());
1095
1096 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
1097 vk_testing::Buffer buffer;
1098 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
1099
1100 BeginCommandBuffer();
1101
1102 // Introduce failure by using dstOffset that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001103 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001104 m_commandBuffer->FillBuffer(buffer.handle(), 1, 4, 0x11111111);
1105 m_errorMonitor->VerifyFound();
1106
1107 // Introduce failure by using size that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001108 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001109 m_commandBuffer->FillBuffer(buffer.handle(), 0, 6, 0x11111111);
1110 m_errorMonitor->VerifyFound();
1111
1112 // Introduce failure by using size that is zero
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001113 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "must be greater than zero");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001114 m_commandBuffer->FillBuffer(buffer.handle(), 0, 0, 0x11111111);
1115 m_errorMonitor->VerifyFound();
1116
1117 EndCommandBuffer();
1118}
Dustin Graves40f35822016-06-23 11:12:53 -06001119
Cortd889ff92016-07-27 09:51:27 -07001120TEST_F(VkLayerTest, PSOPolygonModeInvalid) {
1121 VkResult err;
1122
1123 TEST_DESCRIPTION("Attempt to use a non-solid polygon fill mode in a "
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001124 "pipeline when this feature is not enabled.");
Cortd889ff92016-07-27 09:51:27 -07001125
1126 ASSERT_NO_FATAL_FAILURE(InitState());
1127 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1128
1129 std::vector<const char *> device_extension_names;
1130 auto features = m_device->phy().features();
1131 // Artificially disable support for non-solid fill modes
1132 features.fillModeNonSolid = false;
1133 // The sacrificial device object
1134 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
1135
1136 VkRenderpassObj render_pass(&test_device);
1137
1138 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1139 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1140 pipeline_layout_ci.setLayoutCount = 0;
1141 pipeline_layout_ci.pSetLayouts = NULL;
1142
1143 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001144 err = vkCreatePipelineLayout(test_device.device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Cortd889ff92016-07-27 09:51:27 -07001145 ASSERT_VK_SUCCESS(err);
1146
1147 VkPipelineRasterizationStateCreateInfo rs_ci = {};
1148 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
1149 rs_ci.pNext = nullptr;
1150 rs_ci.lineWidth = 1.0f;
1151 rs_ci.rasterizerDiscardEnable = true;
1152
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001153 VkShaderObj vs(&test_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
1154 VkShaderObj fs(&test_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Cortd889ff92016-07-27 09:51:27 -07001155
Mark Lobodzinski5e644732016-08-15 16:51:19 -06001156 // Set polygonMode to unsupported value POINT, should fail
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001157 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1158 "polygonMode cannot be VK_POLYGON_MODE_POINT or VK_POLYGON_MODE_LINE");
Cortd889ff92016-07-27 09:51:27 -07001159 {
1160 VkPipelineObj pipe(&test_device);
1161 pipe.AddShader(&vs);
1162 pipe.AddShader(&fs);
1163 pipe.AddColorAttachment();
1164 // Introduce failure by setting unsupported polygon mode
1165 rs_ci.polygonMode = VK_POLYGON_MODE_POINT;
1166 pipe.SetRasterization(&rs_ci);
1167 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
1168 }
1169 m_errorMonitor->VerifyFound();
1170
1171 // Try again with polygonMode=LINE, should fail
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001172 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1173 "polygonMode cannot be VK_POLYGON_MODE_POINT or VK_POLYGON_MODE_LINE");
Cortd889ff92016-07-27 09:51:27 -07001174 {
1175 VkPipelineObj pipe(&test_device);
1176 pipe.AddShader(&vs);
1177 pipe.AddShader(&fs);
1178 pipe.AddColorAttachment();
1179 // Introduce failure by setting unsupported polygon mode
1180 rs_ci.polygonMode = VK_POLYGON_MODE_LINE;
1181 pipe.SetRasterization(&rs_ci);
1182 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
1183 }
1184 m_errorMonitor->VerifyFound();
1185
Cortd889ff92016-07-27 09:51:27 -07001186 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, NULL);
1187}
1188
Dustin Gravesffa90fa2016-05-06 11:20:38 -06001189#endif // PARAMETER_VALIDATION_TESTS
1190
Tobin Ehlis0788f522015-05-26 16:11:58 -06001191#if MEM_TRACKER_TESTS
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001192#if 0
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001193TEST_F(VkLayerTest, CallResetCommandBufferBeforeCompletion)
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001194{
1195 vk_testing::Fence testFence;
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001196 VkFenceCreateInfo fenceInfo = {};
1197 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1198 fenceInfo.pNext = NULL;
1199 fenceInfo.flags = 0;
1200
Mike Weiblencce7ec72016-10-17 19:33:05 -06001201 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Resetting command buffer");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001202
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001203 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbourc1eb1a52015-07-20 13:00:10 -06001204
1205 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
1206 vk_testing::Buffer buffer;
1207 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001208
Tony Barbourfe3351b2015-07-28 10:17:20 -06001209 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001210 m_commandBuffer->FillBuffer(buffer.handle(), 0, 4, 0x11111111);
Tony Barbourfe3351b2015-07-28 10:17:20 -06001211 EndCommandBuffer();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001212
1213 testFence.init(*m_device, fenceInfo);
1214
1215 // Bypass framework since it does the waits automatically
1216 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001217 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08001218 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1219 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001220 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001221 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07001222 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001223 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001224 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08001225 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001226 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06001227
1228 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001229 ASSERT_VK_SUCCESS( err );
1230
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001231 // Introduce failure by calling begin again before checking fence
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001232 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001233
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001234 m_errorMonitor->VerifyFound();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001235}
1236
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001237TEST_F(VkLayerTest, CallBeginCommandBufferBeforeCompletion)
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001238{
1239 vk_testing::Fence testFence;
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001240 VkFenceCreateInfo fenceInfo = {};
1241 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1242 fenceInfo.pNext = NULL;
1243 fenceInfo.flags = 0;
1244
Mike Weiblencce7ec72016-10-17 19:33:05 -06001245 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Calling vkBeginCommandBuffer() on active command buffer");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001246
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001247 ASSERT_NO_FATAL_FAILURE(InitState());
1248 ASSERT_NO_FATAL_FAILURE(InitViewport());
1249 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1250
Tony Barbourfe3351b2015-07-28 10:17:20 -06001251 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001252 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbourfe3351b2015-07-28 10:17:20 -06001253 EndCommandBuffer();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001254
1255 testFence.init(*m_device, fenceInfo);
1256
1257 // Bypass framework since it does the waits automatically
1258 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001259 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08001260 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1261 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001262 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001263 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07001264 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001265 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001266 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08001267 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001268 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06001269
1270 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001271 ASSERT_VK_SUCCESS( err );
1272
Jon Ashburnf19916e2016-01-11 13:12:43 -07001273 VkCommandBufferInheritanceInfo hinfo = {};
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001274 VkCommandBufferBeginInfo info = {};
1275 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
1276 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001277 info.renderPass = VK_NULL_HANDLE;
1278 info.subpass = 0;
1279 info.framebuffer = VK_NULL_HANDLE;
Chia-I Wub8d47ae2015-11-11 10:18:12 +08001280 info.occlusionQueryEnable = VK_FALSE;
1281 info.queryFlags = 0;
1282 info.pipelineStatistics = 0;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001283
1284 // Introduce failure by calling BCB again before checking fence
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001285 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001286
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001287 m_errorMonitor->VerifyFound();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001288}
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001289#endif
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001290
Tobin Ehlisf11be982016-05-11 13:52:53 -06001291TEST_F(VkLayerTest, InvalidMemoryAliasing) {
1292 TEST_DESCRIPTION("Create a buffer and image, allocate memory, and bind the "
1293 "buffer and image to memory such that they will alias.");
1294 VkResult err;
1295 bool pass;
1296 ASSERT_NO_FATAL_FAILURE(InitState());
1297
Tobin Ehlis077ded32016-05-12 17:39:13 -06001298 VkBuffer buffer, buffer2;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001299 VkImage image;
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001300 VkImage image2;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001301 VkDeviceMemory mem; // buffer will be bound first
1302 VkDeviceMemory mem_img; // image bound first
Tobin Ehlis077ded32016-05-12 17:39:13 -06001303 VkMemoryRequirements buff_mem_reqs, img_mem_reqs;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001304
1305 VkBufferCreateInfo buf_info = {};
1306 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1307 buf_info.pNext = NULL;
1308 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
1309 buf_info.size = 256;
1310 buf_info.queueFamilyIndexCount = 0;
1311 buf_info.pQueueFamilyIndices = NULL;
1312 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1313 buf_info.flags = 0;
1314 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1315 ASSERT_VK_SUCCESS(err);
1316
Tobin Ehlis077ded32016-05-12 17:39:13 -06001317 vkGetBufferMemoryRequirements(m_device->device(), buffer, &buff_mem_reqs);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001318
1319 VkImageCreateInfo image_create_info = {};
1320 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1321 image_create_info.pNext = NULL;
1322 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1323 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
1324 image_create_info.extent.width = 64;
1325 image_create_info.extent.height = 64;
1326 image_create_info.extent.depth = 1;
1327 image_create_info.mipLevels = 1;
1328 image_create_info.arrayLayers = 1;
1329 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehlis12a4b5e2016-08-08 12:33:11 -06001330 // Image tiling must be optimal to trigger error when aliasing linear buffer
1331 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001332 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
1333 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
1334 image_create_info.queueFamilyIndexCount = 0;
1335 image_create_info.pQueueFamilyIndices = NULL;
1336 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1337 image_create_info.flags = 0;
1338
Tobin Ehlisf11be982016-05-11 13:52:53 -06001339 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1340 ASSERT_VK_SUCCESS(err);
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001341 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image2);
1342 ASSERT_VK_SUCCESS(err);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001343
Tobin Ehlis077ded32016-05-12 17:39:13 -06001344 vkGetImageMemoryRequirements(m_device->device(), image, &img_mem_reqs);
1345
1346 VkMemoryAllocateInfo alloc_info = {};
1347 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1348 alloc_info.pNext = NULL;
1349 alloc_info.memoryTypeIndex = 0;
1350 // Ensure memory is big enough for both bindings
1351 alloc_info.allocationSize = buff_mem_reqs.size + img_mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001352 pass = m_device->phy().set_memory_type(buff_mem_reqs.memoryTypeBits & img_mem_reqs.memoryTypeBits, &alloc_info,
1353 VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001354 if (!pass) {
Tobin Ehlis077ded32016-05-12 17:39:13 -06001355 vkDestroyBuffer(m_device->device(), buffer, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001356 vkDestroyImage(m_device->device(), image, NULL);
1357 return;
1358 }
Tobin Ehlis077ded32016-05-12 17:39:13 -06001359 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
1360 ASSERT_VK_SUCCESS(err);
1361 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
1362 ASSERT_VK_SUCCESS(err);
1363
Tobin Ehlis32b2bbc2016-12-13 17:33:41 -07001364 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, " is aliased with linear buffer 0x");
Tobin Ehlis077ded32016-05-12 17:39:13 -06001365 // VALIDATION FAILURE due to image mapping overlapping buffer mapping
Tobin Ehlisf11be982016-05-11 13:52:53 -06001366 err = vkBindImageMemory(m_device->device(), image, mem, 0);
1367 m_errorMonitor->VerifyFound();
1368
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001369 // Now correctly bind image2 to second mem allocation before incorrectly
Tobin Ehlis077ded32016-05-12 17:39:13 -06001370 // aliasing buffer2
1371 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer2);
1372 ASSERT_VK_SUCCESS(err);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001373 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem_img);
1374 ASSERT_VK_SUCCESS(err);
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001375 err = vkBindImageMemory(m_device->device(), image2, mem_img, 0);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001376 ASSERT_VK_SUCCESS(err);
Tobin Ehlis32b2bbc2016-12-13 17:33:41 -07001377 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "is aliased with non-linear image 0x");
Tobin Ehlis077ded32016-05-12 17:39:13 -06001378 err = vkBindBufferMemory(m_device->device(), buffer2, mem_img, 0);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001379 m_errorMonitor->VerifyFound();
1380
1381 vkDestroyBuffer(m_device->device(), buffer, NULL);
Tobin Ehlis077ded32016-05-12 17:39:13 -06001382 vkDestroyBuffer(m_device->device(), buffer2, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001383 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001384 vkDestroyImage(m_device->device(), image2, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001385 vkFreeMemory(m_device->device(), mem, NULL);
1386 vkFreeMemory(m_device->device(), mem_img, NULL);
1387}
1388
Tobin Ehlis35372522016-05-12 08:32:31 -06001389TEST_F(VkLayerTest, InvalidMemoryMapping) {
1390 TEST_DESCRIPTION("Attempt to map memory in a number of incorrect ways");
1391 VkResult err;
1392 bool pass;
1393 ASSERT_NO_FATAL_FAILURE(InitState());
1394
1395 VkBuffer buffer;
1396 VkDeviceMemory mem;
1397 VkMemoryRequirements mem_reqs;
1398
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001399 const VkDeviceSize atom_size = m_device->props.limits.nonCoherentAtomSize;
1400
Tobin Ehlis35372522016-05-12 08:32:31 -06001401 VkBufferCreateInfo buf_info = {};
1402 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1403 buf_info.pNext = NULL;
1404 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
1405 buf_info.size = 256;
1406 buf_info.queueFamilyIndexCount = 0;
1407 buf_info.pQueueFamilyIndices = NULL;
1408 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1409 buf_info.flags = 0;
1410 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1411 ASSERT_VK_SUCCESS(err);
1412
1413 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
1414 VkMemoryAllocateInfo alloc_info = {};
1415 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1416 alloc_info.pNext = NULL;
1417 alloc_info.memoryTypeIndex = 0;
1418
1419 // Ensure memory is big enough for both bindings
1420 static const VkDeviceSize allocation_size = 0x10000;
1421 alloc_info.allocationSize = allocation_size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001422 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 -06001423 if (!pass) {
1424 vkDestroyBuffer(m_device->device(), buffer, NULL);
1425 return;
1426 }
1427 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
1428 ASSERT_VK_SUCCESS(err);
1429
1430 uint8_t *pData;
1431 // Attempt to map memory size 0 is invalid
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001432 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 -06001433 err = vkMapMemory(m_device->device(), mem, 0, 0, 0, (void **)&pData);
1434 m_errorMonitor->VerifyFound();
1435 // Map memory twice
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001436 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001437 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001438 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1439 "VkMapMemory: Attempting to map memory on an already-mapped object ");
1440 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001441 m_errorMonitor->VerifyFound();
1442
1443 // Unmap the memory to avoid re-map error
1444 vkUnmapMemory(m_device->device(), mem);
1445 // overstep allocation with VK_WHOLE_SIZE
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001446 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1447 " with size of VK_WHOLE_SIZE oversteps total array size 0x");
1448 err = vkMapMemory(m_device->device(), mem, allocation_size + 1, VK_WHOLE_SIZE, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001449 m_errorMonitor->VerifyFound();
1450 // overstep allocation w/o VK_WHOLE_SIZE
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001451 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " oversteps total array size 0x");
1452 err = vkMapMemory(m_device->device(), mem, 1, allocation_size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001453 m_errorMonitor->VerifyFound();
1454 // Now error due to unmapping memory that's not mapped
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001455 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Unmapping Memory without memory being mapped: ");
Tobin Ehlis35372522016-05-12 08:32:31 -06001456 vkUnmapMemory(m_device->device(), mem);
1457 m_errorMonitor->VerifyFound();
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001458
Tobin Ehlis35372522016-05-12 08:32:31 -06001459 // Now map memory and cause errors due to flushing invalid ranges
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001460 err = vkMapMemory(m_device->device(), mem, 4 * atom_size, VK_WHOLE_SIZE, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001461 ASSERT_VK_SUCCESS(err);
1462 VkMappedMemoryRange mmr = {};
Chris Forbes3aec0892016-06-13 10:29:26 +12001463 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
Tobin Ehlis35372522016-05-12 08:32:31 -06001464 mmr.memory = mem;
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001465 mmr.offset = atom_size; // Error b/c offset less than offset of mapped mem
Mark Lobodzinskib3c675e2016-11-15 08:56:03 -07001466 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00642);
Tobin Ehlis35372522016-05-12 08:32:31 -06001467 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1468 m_errorMonitor->VerifyFound();
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001469
Tobin Ehlis35372522016-05-12 08:32:31 -06001470 // Now flush range that oversteps mapped range
1471 vkUnmapMemory(m_device->device(), mem);
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001472 err = vkMapMemory(m_device->device(), mem, 0, 4 * atom_size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001473 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001474 mmr.offset = atom_size;
1475 mmr.size = 4 * atom_size; // Flushing bounds exceed mapped bounds
Mark Lobodzinskib3c675e2016-11-15 08:56:03 -07001476 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00642);
1477 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1478 m_errorMonitor->VerifyFound();
1479
1480 // Now flush range with VK_WHOLE_SIZE that oversteps offset
1481 vkUnmapMemory(m_device->device(), mem);
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001482 err = vkMapMemory(m_device->device(), mem, 2 * atom_size, 4 * atom_size, 0, (void **)&pData);
Mark Lobodzinskib3c675e2016-11-15 08:56:03 -07001483 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001484 mmr.offset = atom_size;
Mark Lobodzinskib3c675e2016-11-15 08:56:03 -07001485 mmr.size = VK_WHOLE_SIZE;
1486 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00643);
Tobin Ehlis35372522016-05-12 08:32:31 -06001487 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1488 m_errorMonitor->VerifyFound();
1489
Mark Lobodzinski3826a4f2016-11-15 09:38:51 -07001490 // Some platforms have an atomsize of 1 which makes the test meaningless
1491 if (atom_size > 3) {
1492 // Now with an offset NOT a multiple of the device limit
1493 vkUnmapMemory(m_device->device(), mem);
1494 err = vkMapMemory(m_device->device(), mem, 0, 4 * atom_size, 0, (void **)&pData);
1495 ASSERT_VK_SUCCESS(err);
1496 mmr.offset = 3; // Not a multiple of atom_size
1497 mmr.size = VK_WHOLE_SIZE;
1498 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00644);
1499 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1500 m_errorMonitor->VerifyFound();
1501
1502 // Now with a size NOT a multiple of the device limit
1503 vkUnmapMemory(m_device->device(), mem);
1504 err = vkMapMemory(m_device->device(), mem, 0, 4 * atom_size, 0, (void **)&pData);
1505 ASSERT_VK_SUCCESS(err);
1506 mmr.offset = atom_size;
1507 mmr.size = 2 * atom_size + 1; // Not a multiple of atom_size
1508 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00645);
1509 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1510 m_errorMonitor->VerifyFound();
1511 }
1512
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001513 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT,
1514 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Tobin Ehlis35372522016-05-12 08:32:31 -06001515 if (!pass) {
1516 vkFreeMemory(m_device->device(), mem, NULL);
1517 vkDestroyBuffer(m_device->device(), buffer, NULL);
1518 return;
1519 }
1520 // TODO : If we can get HOST_VISIBLE w/o HOST_COHERENT we can test cases of
1521 // MEMTRACK_INVALID_MAP in validateAndCopyNoncoherentMemoryToDriver()
1522
1523 vkDestroyBuffer(m_device->device(), buffer, NULL);
1524 vkFreeMemory(m_device->device(), mem, NULL);
1525}
1526
Chris Forbes09368e42016-10-13 11:59:22 +13001527#if 0 // disabled until PV gets real extension enable checks
Ian Elliott1c32c772016-04-28 14:47:13 -06001528TEST_F(VkLayerTest, EnableWsiBeforeUse) {
1529 VkResult err;
1530 bool pass;
1531
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001532 // FIXME: After we turn on this code for non-Linux platforms, uncomment the
1533 // following declaration (which is temporarily being moved below):
1534 // VkSurfaceKHR surface = VK_NULL_HANDLE;
Ian Elliott1c32c772016-04-28 14:47:13 -06001535 VkSwapchainKHR swapchain = VK_NULL_HANDLE;
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001536 VkSwapchainCreateInfoKHR swapchain_create_info = {VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR};
Ian Elliott1c32c772016-04-28 14:47:13 -06001537 uint32_t swapchain_image_count = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001538 // VkImage swapchain_images[1] = {VK_NULL_HANDLE};
Ian Elliott1c32c772016-04-28 14:47:13 -06001539 uint32_t image_index = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001540 // VkPresentInfoKHR present_info = {};
Ian Elliott1c32c772016-04-28 14:47:13 -06001541
1542 ASSERT_NO_FATAL_FAILURE(InitState());
1543
Ian Elliott3f06ce52016-04-29 14:46:21 -06001544#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
1545#if defined(VK_USE_PLATFORM_ANDROID_KHR)
1546 // Use the functions from the VK_KHR_android_surface extension without
1547 // enabling that extension:
1548
1549 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001550 VkAndroidSurfaceCreateInfoKHR android_create_info = {VK_STRUCTURE_TYPE_ANDROID_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001551 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1552 err = vkCreateAndroidSurfaceKHR(instance(), &android_create_info, NULL, &surface);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001553 pass = (err != VK_SUCCESS);
1554 ASSERT_TRUE(pass);
1555 m_errorMonitor->VerifyFound();
1556#endif // VK_USE_PLATFORM_ANDROID_KHR
1557
Ian Elliott3f06ce52016-04-29 14:46:21 -06001558#if defined(VK_USE_PLATFORM_MIR_KHR)
1559 // Use the functions from the VK_KHR_mir_surface extension without enabling
1560 // that extension:
1561
1562 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001563 VkMirSurfaceCreateInfoKHR mir_create_info = {VK_STRUCTURE_TYPE_MIR_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001564 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott3f06ce52016-04-29 14:46:21 -06001565 err = vkCreateMirSurfaceKHR(instance(), &mir_create_info, NULL, &surface);
1566 pass = (err != VK_SUCCESS);
1567 ASSERT_TRUE(pass);
1568 m_errorMonitor->VerifyFound();
1569
1570 // Tell whether an mir_connection supports presentation:
1571 MirConnection *mir_connection = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001572 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1573 vkGetPhysicalDeviceMirPresentationSupportKHR(gpu(), 0, mir_connection, visual_id);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001574 m_errorMonitor->VerifyFound();
1575#endif // VK_USE_PLATFORM_MIR_KHR
1576
Ian Elliott3f06ce52016-04-29 14:46:21 -06001577#if defined(VK_USE_PLATFORM_WAYLAND_KHR)
1578 // Use the functions from the VK_KHR_wayland_surface extension without
1579 // enabling that extension:
1580
1581 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001582 VkWaylandSurfaceCreateInfoKHR wayland_create_info = {VK_STRUCTURE_TYPE_WAYLAND_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001583 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1584 err = vkCreateWaylandSurfaceKHR(instance(), &wayland_create_info, NULL, &surface);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001585 pass = (err != VK_SUCCESS);
1586 ASSERT_TRUE(pass);
1587 m_errorMonitor->VerifyFound();
1588
1589 // Tell whether an wayland_display supports presentation:
1590 struct wl_display wayland_display = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001591 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1592 vkGetPhysicalDeviceWaylandPresentationSupportKHR(gpu(), 0, &wayland_display);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001593 m_errorMonitor->VerifyFound();
1594#endif // VK_USE_PLATFORM_WAYLAND_KHR
Ian Elliott489eec02016-05-05 14:12:44 -06001595#endif // NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott3f06ce52016-04-29 14:46:21 -06001596
Ian Elliott3f06ce52016-04-29 14:46:21 -06001597#if defined(VK_USE_PLATFORM_WIN32_KHR)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001598 // FIXME: REMOVE THIS HERE, AND UNCOMMENT ABOVE, WHEN THIS TEST HAS BEEN PORTED
1599 // TO NON-LINUX PLATFORMS:
1600 VkSurfaceKHR surface = VK_NULL_HANDLE;
Ian Elliott3f06ce52016-04-29 14:46:21 -06001601 // Use the functions from the VK_KHR_win32_surface extension without
1602 // enabling that extension:
1603
1604 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001605 VkWin32SurfaceCreateInfoKHR win32_create_info = {VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001606 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1607 err = vkCreateWin32SurfaceKHR(instance(), &win32_create_info, NULL, &surface);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001608 pass = (err != VK_SUCCESS);
1609 ASSERT_TRUE(pass);
1610 m_errorMonitor->VerifyFound();
1611
1612 // Tell whether win32 supports presentation:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001613 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott489eec02016-05-05 14:12:44 -06001614 vkGetPhysicalDeviceWin32PresentationSupportKHR(gpu(), 0);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001615 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001616// Set this (for now, until all platforms are supported and tested):
1617#define NEED_TO_TEST_THIS_ON_PLATFORM
1618#endif // VK_USE_PLATFORM_WIN32_KHR
Tony Barbour2e7bd402016-11-14 14:46:33 -07001619#if defined(VK_USE_PLATFORM_XCB_KHR) || defined (VK_USE_PLATFORM_XLIB_KHR)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001620 // FIXME: REMOVE THIS HERE, AND UNCOMMENT ABOVE, WHEN THIS TEST HAS BEEN PORTED
1621 // TO NON-LINUX PLATFORMS:
1622 VkSurfaceKHR surface = VK_NULL_HANDLE;
Tony Barbour2e7bd402016-11-14 14:46:33 -07001623#endif
1624#if defined(VK_USE_PLATFORM_XCB_KHR)
Ian Elliott1c32c772016-04-28 14:47:13 -06001625 // Use the functions from the VK_KHR_xcb_surface extension without enabling
1626 // that extension:
1627
1628 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001629 VkXcbSurfaceCreateInfoKHR xcb_create_info = {VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001630 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001631 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
1632 pass = (err != VK_SUCCESS);
1633 ASSERT_TRUE(pass);
1634 m_errorMonitor->VerifyFound();
1635
1636 // Tell whether an xcb_visualid_t supports presentation:
Ian Elliott3f06ce52016-04-29 14:46:21 -06001637 xcb_connection_t *xcb_connection = NULL;
Ian Elliott1c32c772016-04-28 14:47:13 -06001638 xcb_visualid_t visual_id = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001639 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1640 vkGetPhysicalDeviceXcbPresentationSupportKHR(gpu(), 0, xcb_connection, visual_id);
Ian Elliott1c32c772016-04-28 14:47:13 -06001641 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001642// Set this (for now, until all platforms are supported and tested):
1643#define NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06001644#endif // VK_USE_PLATFORM_XCB_KHR
1645
Ian Elliott12630812016-04-29 14:35:43 -06001646#if defined(VK_USE_PLATFORM_XLIB_KHR)
1647 // Use the functions from the VK_KHR_xlib_surface extension without enabling
1648 // that extension:
1649
1650 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001651 VkXlibSurfaceCreateInfoKHR xlib_create_info = {VK_STRUCTURE_TYPE_XLIB_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001652 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott12630812016-04-29 14:35:43 -06001653 err = vkCreateXlibSurfaceKHR(instance(), &xlib_create_info, NULL, &surface);
1654 pass = (err != VK_SUCCESS);
1655 ASSERT_TRUE(pass);
1656 m_errorMonitor->VerifyFound();
1657
1658 // Tell whether an Xlib VisualID supports presentation:
1659 Display *dpy = NULL;
1660 VisualID visual = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001661 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott12630812016-04-29 14:35:43 -06001662 vkGetPhysicalDeviceXlibPresentationSupportKHR(gpu(), 0, dpy, visual);
1663 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001664// Set this (for now, until all platforms are supported and tested):
1665#define NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott12630812016-04-29 14:35:43 -06001666#endif // VK_USE_PLATFORM_XLIB_KHR
1667
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001668// Use the functions from the VK_KHR_surface extension without enabling
1669// that extension:
Ian Elliott1c32c772016-04-28 14:47:13 -06001670
Ian Elliott489eec02016-05-05 14:12:44 -06001671#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06001672 // Destroy a surface:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001673 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001674 vkDestroySurfaceKHR(instance(), surface, NULL);
1675 m_errorMonitor->VerifyFound();
1676
1677 // Check if surface supports presentation:
1678 VkBool32 supported = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001679 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001680 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
1681 pass = (err != VK_SUCCESS);
1682 ASSERT_TRUE(pass);
1683 m_errorMonitor->VerifyFound();
1684
1685 // Check surface capabilities:
1686 VkSurfaceCapabilitiesKHR capabilities = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001687 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1688 err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), surface, &capabilities);
Ian Elliott1c32c772016-04-28 14:47:13 -06001689 pass = (err != VK_SUCCESS);
1690 ASSERT_TRUE(pass);
1691 m_errorMonitor->VerifyFound();
1692
1693 // Check surface formats:
1694 uint32_t format_count = 0;
1695 VkSurfaceFormatKHR *formats = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001696 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1697 err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &format_count, formats);
Ian Elliott1c32c772016-04-28 14:47:13 -06001698 pass = (err != VK_SUCCESS);
1699 ASSERT_TRUE(pass);
1700 m_errorMonitor->VerifyFound();
1701
1702 // Check surface present modes:
1703 uint32_t present_mode_count = 0;
1704 VkSurfaceFormatKHR *present_modes = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001705 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1706 err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &present_mode_count, present_modes);
Ian Elliott1c32c772016-04-28 14:47:13 -06001707 pass = (err != VK_SUCCESS);
1708 ASSERT_TRUE(pass);
1709 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001710#endif // NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06001711
Ian Elliott1c32c772016-04-28 14:47:13 -06001712 // Use the functions from the VK_KHR_swapchain extension without enabling
1713 // that extension:
1714
1715 // Create a swapchain:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001716 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001717 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
1718 swapchain_create_info.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001719 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
Ian Elliott1c32c772016-04-28 14:47:13 -06001720 pass = (err != VK_SUCCESS);
1721 ASSERT_TRUE(pass);
1722 m_errorMonitor->VerifyFound();
1723
1724 // Get the images from the swapchain:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001725 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1726 err = vkGetSwapchainImagesKHR(m_device->device(), swapchain, &swapchain_image_count, NULL);
Ian Elliott1c32c772016-04-28 14:47:13 -06001727 pass = (err != VK_SUCCESS);
1728 ASSERT_TRUE(pass);
1729 m_errorMonitor->VerifyFound();
1730
Chris Forbeseb7d5502016-09-13 18:19:21 +12001731 // Add a fence to avoid (justifiable) error about not providing fence OR semaphore
1732 VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
1733 VkFence fence;
1734 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
1735
Ian Elliott1c32c772016-04-28 14:47:13 -06001736 // Try to acquire an image:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001737 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Chris Forbeseb7d5502016-09-13 18:19:21 +12001738 err = vkAcquireNextImageKHR(m_device->device(), swapchain, 0, VK_NULL_HANDLE, fence, &image_index);
Ian Elliott1c32c772016-04-28 14:47:13 -06001739 pass = (err != VK_SUCCESS);
1740 ASSERT_TRUE(pass);
1741 m_errorMonitor->VerifyFound();
1742
Chris Forbeseb7d5502016-09-13 18:19:21 +12001743 vkDestroyFence(m_device->device(), fence, nullptr);
1744
Ian Elliott1c32c772016-04-28 14:47:13 -06001745 // Try to present an image:
Ian Elliott2c1daf52016-05-12 09:41:46 -06001746 //
1747 // NOTE: Currently can't test this because a real swapchain is needed (as
1748 // opposed to the fake one we created) in order for the layer to lookup the
1749 // VkDevice used to enable the extension:
Ian Elliott1c32c772016-04-28 14:47:13 -06001750
1751 // Destroy the swapchain:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001752 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001753 vkDestroySwapchainKHR(m_device->device(), swapchain, NULL);
1754 m_errorMonitor->VerifyFound();
1755}
Chris Forbes09368e42016-10-13 11:59:22 +13001756#endif
Ian Elliott1c32c772016-04-28 14:47:13 -06001757
Karl Schultz6addd812016-02-02 17:17:23 -07001758TEST_F(VkLayerTest, MapMemWithoutHostVisibleBit) {
1759 VkResult err;
1760 bool pass;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001761
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001762 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1763 "Mapping Memory without VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001764
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001765 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001766
1767 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07001768 VkImage image;
1769 VkDeviceMemory mem;
1770 VkMemoryRequirements mem_reqs;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001771
Karl Schultz6addd812016-02-02 17:17:23 -07001772 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
1773 const int32_t tex_width = 32;
1774 const int32_t tex_height = 32;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001775
Tony Barboureb254902015-07-15 12:50:33 -06001776 VkImageCreateInfo image_create_info = {};
1777 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07001778 image_create_info.pNext = NULL;
1779 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1780 image_create_info.format = tex_format;
1781 image_create_info.extent.width = tex_width;
1782 image_create_info.extent.height = tex_height;
1783 image_create_info.extent.depth = 1;
1784 image_create_info.mipLevels = 1;
1785 image_create_info.arrayLayers = 1;
1786 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
1787 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
1788 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
1789 image_create_info.flags = 0;
Chris Forbese65e4d02016-09-13 17:39:18 +12001790 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001791
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001792 VkMemoryAllocateInfo mem_alloc = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08001793 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07001794 mem_alloc.pNext = NULL;
1795 mem_alloc.allocationSize = 0;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001796
Chia-I Wuf7458c52015-10-26 21:10:41 +08001797 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001798 ASSERT_VK_SUCCESS(err);
1799
Karl Schultz6addd812016-02-02 17:17:23 -07001800 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001801
Mark Lobodzinski23065352015-05-29 09:32:35 -05001802 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001803
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001804 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 -07001805 if (!pass) { // If we can't find any unmappable memory this test doesn't
1806 // make sense
Chia-I Wuf7458c52015-10-26 21:10:41 +08001807 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbour02fdc7d2015-08-04 16:13:01 -06001808 return;
Mike Stroyand1c84a52015-08-18 14:40:24 -06001809 }
Mike Stroyan713b2d72015-08-04 10:49:29 -06001810
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001811 // allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001812 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001813 ASSERT_VK_SUCCESS(err);
1814
1815 // Try to bind free memory that has been freed
Tony Barbour67e99152015-07-10 14:10:27 -06001816 err = vkBindImageMemory(m_device->device(), image, mem, 0);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001817 ASSERT_VK_SUCCESS(err);
1818
1819 // Map memory as if to initialize the image
1820 void *mappedAddress = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001821 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, &mappedAddress);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001822
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001823 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06001824
Chia-I Wuf7458c52015-10-26 21:10:41 +08001825 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06001826 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001827}
1828
Karl Schultz6addd812016-02-02 17:17:23 -07001829TEST_F(VkLayerTest, RebindMemory) {
1830 VkResult err;
1831 bool pass;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001832
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001833 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "which has already been bound to mem object");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001834
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001835 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001836
1837 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07001838 VkImage image;
1839 VkDeviceMemory mem1;
1840 VkDeviceMemory mem2;
1841 VkMemoryRequirements mem_reqs;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001842
Karl Schultz6addd812016-02-02 17:17:23 -07001843 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
1844 const int32_t tex_width = 32;
1845 const int32_t tex_height = 32;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001846
Tony Barboureb254902015-07-15 12:50:33 -06001847 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07001848 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1849 image_create_info.pNext = NULL;
1850 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1851 image_create_info.format = tex_format;
1852 image_create_info.extent.width = tex_width;
1853 image_create_info.extent.height = tex_height;
1854 image_create_info.extent.depth = 1;
1855 image_create_info.mipLevels = 1;
1856 image_create_info.arrayLayers = 1;
1857 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
1858 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
1859 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
1860 image_create_info.flags = 0;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001861
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001862 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07001863 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1864 mem_alloc.pNext = NULL;
1865 mem_alloc.allocationSize = 0;
1866 mem_alloc.memoryTypeIndex = 0;
Tony Barboureb254902015-07-15 12:50:33 -06001867
Karl Schultz6addd812016-02-02 17:17:23 -07001868 // Introduce failure, do NOT set memProps to
1869 // VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
Tony Barboureb254902015-07-15 12:50:33 -06001870 mem_alloc.memoryTypeIndex = 1;
Chia-I Wuf7458c52015-10-26 21:10:41 +08001871 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001872 ASSERT_VK_SUCCESS(err);
1873
Karl Schultz6addd812016-02-02 17:17:23 -07001874 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001875
1876 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001877 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06001878 ASSERT_TRUE(pass);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001879
1880 // allocate 2 memory objects
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001881 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem1);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001882 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001883 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem2);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001884 ASSERT_VK_SUCCESS(err);
1885
1886 // Bind first memory object to Image object
Tony Barbour67e99152015-07-10 14:10:27 -06001887 err = vkBindImageMemory(m_device->device(), image, mem1, 0);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001888 ASSERT_VK_SUCCESS(err);
1889
Karl Schultz6addd812016-02-02 17:17:23 -07001890 // Introduce validation failure, try to bind a different memory object to
1891 // the same image object
Tony Barbour67e99152015-07-10 14:10:27 -06001892 err = vkBindImageMemory(m_device->device(), image, mem2, 0);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001893
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001894 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06001895
Chia-I Wuf7458c52015-10-26 21:10:41 +08001896 vkDestroyImage(m_device->device(), image, NULL);
1897 vkFreeMemory(m_device->device(), mem1, NULL);
1898 vkFreeMemory(m_device->device(), mem2, NULL);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001899}
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001900
Karl Schultz6addd812016-02-02 17:17:23 -07001901TEST_F(VkLayerTest, SubmitSignaledFence) {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001902 vk_testing::Fence testFence;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001903
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001904 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "submitted in SIGNALED state. Fences "
1905 "must be reset before being submitted");
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001906
1907 VkFenceCreateInfo fenceInfo = {};
Tony Barbour0b4d9562015-04-09 10:48:04 -06001908 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1909 fenceInfo.pNext = NULL;
1910 fenceInfo.flags = VK_FENCE_CREATE_SIGNALED_BIT;
Tony Barbour300a6082015-04-07 13:44:53 -06001911
Tony Barbour300a6082015-04-07 13:44:53 -06001912 ASSERT_NO_FATAL_FAILURE(InitState());
1913 ASSERT_NO_FATAL_FAILURE(InitViewport());
1914 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1915
Tony Barbourfe3351b2015-07-28 10:17:20 -06001916 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001917 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbourfe3351b2015-07-28 10:17:20 -06001918 EndCommandBuffer();
Tony Barbour300a6082015-04-07 13:44:53 -06001919
1920 testFence.init(*m_device, fenceInfo);
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001921
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001922 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08001923 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1924 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001925 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001926 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07001927 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001928 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001929 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08001930 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001931 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06001932
1933 vkQueueSubmit(m_device->m_queue, 1, &submit_info, testFence.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07001934 vkQueueWaitIdle(m_device->m_queue);
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001935
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001936 m_errorMonitor->VerifyFound();
Tony Barbour0b4d9562015-04-09 10:48:04 -06001937}
Chris Forbes4e44c912016-06-16 10:20:00 +12001938
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001939TEST_F(VkLayerTest, InvalidUsageBits) {
1940 TEST_DESCRIPTION("Specify wrong usage for image then create conflicting view of image "
1941 "Initialize buffer with wrong usage then perform copy expecting errors "
1942 "from both the image and the buffer (2 calls)");
1943 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid usage flag for image ");
Tobin Ehlis41376e12015-07-03 08:45:14 -06001944
1945 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesd2b5fe42016-11-28 18:00:00 +13001946
1947 auto format = VK_FORMAT_D24_UNORM_S8_UINT;
1948
Tony Barbourf92621a2016-05-02 14:28:12 -06001949 VkImageObj image(m_device);
Tony Barbour75d79f02016-08-30 09:39:07 -06001950 // Initialize image with USAGE_TRANSIENT_ATTACHMENT
Chris Forbesd2b5fe42016-11-28 18:00:00 +13001951 image.init(128, 128, format, VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
Karl Schultzb5bc11e2016-05-04 08:36:08 -06001952 ASSERT_TRUE(image.initialized());
Tobin Ehlis41376e12015-07-03 08:45:14 -06001953
Tony Barbourf92621a2016-05-02 14:28:12 -06001954 VkImageView dsv;
1955 VkImageViewCreateInfo dsvci = {};
1956 dsvci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
1957 dsvci.image = image.handle();
1958 dsvci.viewType = VK_IMAGE_VIEW_TYPE_2D;
Chris Forbesd2b5fe42016-11-28 18:00:00 +13001959 dsvci.format = format;
Tony Barbourf92621a2016-05-02 14:28:12 -06001960 dsvci.subresourceRange.layerCount = 1;
1961 dsvci.subresourceRange.baseMipLevel = 0;
1962 dsvci.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001963 dsvci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
Tobin Ehlis41376e12015-07-03 08:45:14 -06001964
Tony Barbourf92621a2016-05-02 14:28:12 -06001965 // Create a view with depth / stencil aspect for image with different usage
1966 vkCreateImageView(m_device->device(), &dsvci, NULL, &dsv);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001967
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001968 m_errorMonitor->VerifyFound();
Tony Barbourf92621a2016-05-02 14:28:12 -06001969
1970 // Initialize buffer with TRANSFER_DST usage
1971 vk_testing::Buffer buffer;
1972 VkMemoryPropertyFlags reqs = 0;
1973 buffer.init_as_dst(*m_device, 128 * 128, reqs);
1974 VkBufferImageCopy region = {};
1975 region.bufferRowLength = 128;
1976 region.bufferImageHeight = 128;
1977 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
1978 region.imageSubresource.layerCount = 1;
1979 region.imageExtent.height = 16;
1980 region.imageExtent.width = 16;
1981 region.imageExtent.depth = 1;
1982
Tony Barbourf92621a2016-05-02 14:28:12 -06001983 // Buffer usage not set to TRANSFER_SRC and image usage not set to
1984 // TRANSFER_DST
1985 BeginCommandBuffer();
Tony Barbourf92621a2016-05-02 14:28:12 -06001986
Chris Forbesda581202016-10-06 18:25:26 +13001987 // two separate errors from this call:
1988 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "image should have VK_IMAGE_USAGE_TRANSFER_DST_BIT");
1989 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "buffer should have VK_BUFFER_USAGE_TRANSFER_SRC_BIT");
1990
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001991 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
1992 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Tony Barbourf92621a2016-05-02 14:28:12 -06001993 m_errorMonitor->VerifyFound();
Tobin Ehlis41376e12015-07-03 08:45:14 -06001994}
Tony Barbour75d79f02016-08-30 09:39:07 -06001995
Tony Barbour75d79f02016-08-30 09:39:07 -06001996
Mark Lobodzinski209b5292015-09-17 09:44:05 -06001997#endif // MEM_TRACKER_TESTS
1998
Tobin Ehlis4bf96d12015-06-25 11:58:41 -06001999#if OBJ_TRACKER_TESTS
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002000
2001TEST_F(VkLayerTest, LeakAnObject) {
2002 VkResult err;
2003
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002004 TEST_DESCRIPTION("Create a fence and destroy its device without first destroying the fence.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002005
2006 // Note that we have to create a new device since destroying the
2007 // framework's device causes Teardown() to fail and just calling Teardown
2008 // will destroy the errorMonitor.
2009
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002010 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "has not been destroyed.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002011
2012 ASSERT_NO_FATAL_FAILURE(InitState());
2013
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002014 const std::vector<VkQueueFamilyProperties> queue_props = m_device->queue_props;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002015 std::vector<VkDeviceQueueCreateInfo> queue_info;
2016 queue_info.reserve(queue_props.size());
2017 std::vector<std::vector<float>> queue_priorities;
2018 for (uint32_t i = 0; i < (uint32_t)queue_props.size(); i++) {
2019 VkDeviceQueueCreateInfo qi = {};
2020 qi.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
2021 qi.pNext = NULL;
2022 qi.queueFamilyIndex = i;
2023 qi.queueCount = queue_props[i].queueCount;
2024 queue_priorities.emplace_back(qi.queueCount, 0.0f);
2025 qi.pQueuePriorities = queue_priorities[i].data();
2026 queue_info.push_back(qi);
2027 }
2028
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002029 std::vector<const char *> device_extension_names;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002030
2031 // The sacrificial device object
2032 VkDevice testDevice;
2033 VkDeviceCreateInfo device_create_info = {};
2034 auto features = m_device->phy().features();
2035 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
2036 device_create_info.pNext = NULL;
2037 device_create_info.queueCreateInfoCount = queue_info.size();
2038 device_create_info.pQueueCreateInfos = queue_info.data();
Tony Barbour4c70d102016-08-08 16:06:56 -06002039 device_create_info.enabledLayerCount = 0;
2040 device_create_info.ppEnabledLayerNames = NULL;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002041 device_create_info.pEnabledFeatures = &features;
2042 err = vkCreateDevice(gpu(), &device_create_info, NULL, &testDevice);
2043 ASSERT_VK_SUCCESS(err);
2044
2045 VkFence fence;
2046 VkFenceCreateInfo fence_create_info = {};
2047 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
2048 fence_create_info.pNext = NULL;
2049 fence_create_info.flags = 0;
2050 err = vkCreateFence(testDevice, &fence_create_info, NULL, &fence);
2051 ASSERT_VK_SUCCESS(err);
2052
2053 // Induce failure by not calling vkDestroyFence
2054 vkDestroyDevice(testDevice, NULL);
2055 m_errorMonitor->VerifyFound();
2056}
2057
2058TEST_F(VkLayerTest, InvalidCommandPoolConsistency) {
2059
2060 TEST_DESCRIPTION("Allocate command buffers from one command pool and "
2061 "attempt to delete them from another.");
2062
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002063 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "FreeCommandBuffers is attempting to free Command Buffer");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002064
Cody Northropc31a84f2016-08-22 10:41:47 -06002065 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002066 VkCommandPool command_pool_one;
2067 VkCommandPool command_pool_two;
2068
2069 VkCommandPoolCreateInfo pool_create_info{};
2070 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
2071 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
2072 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
2073
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002074 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool_one);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002075
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002076 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool_two);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002077
Chris Forbes5ab04ec2016-11-28 18:03:11 +13002078 VkCommandBuffer cb;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002079 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002080 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002081 command_buffer_allocate_info.commandPool = command_pool_one;
Chris Forbes5ab04ec2016-11-28 18:03:11 +13002082 command_buffer_allocate_info.commandBufferCount = 1;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002083 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Chris Forbes5ab04ec2016-11-28 18:03:11 +13002084 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &cb);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002085
Chris Forbes5ab04ec2016-11-28 18:03:11 +13002086 vkFreeCommandBuffers(m_device->device(), command_pool_two, 1, &cb);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002087
2088 m_errorMonitor->VerifyFound();
2089
2090 vkDestroyCommandPool(m_device->device(), command_pool_one, NULL);
2091 vkDestroyCommandPool(m_device->device(), command_pool_two, NULL);
2092}
2093
2094TEST_F(VkLayerTest, InvalidDescriptorPoolConsistency) {
2095 VkResult err;
2096
2097 TEST_DESCRIPTION("Allocate descriptor sets from one DS pool and "
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002098 "attempt to delete them from another.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002099
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002100 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "FreeDescriptorSets is attempting to free descriptorSet");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002101
2102 ASSERT_NO_FATAL_FAILURE(InitState());
2103 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2104
2105 VkDescriptorPoolSize ds_type_count = {};
2106 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
2107 ds_type_count.descriptorCount = 1;
2108
2109 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2110 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2111 ds_pool_ci.pNext = NULL;
2112 ds_pool_ci.flags = 0;
2113 ds_pool_ci.maxSets = 1;
2114 ds_pool_ci.poolSizeCount = 1;
2115 ds_pool_ci.pPoolSizes = &ds_type_count;
2116
2117 VkDescriptorPool ds_pool_one;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002118 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool_one);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002119 ASSERT_VK_SUCCESS(err);
2120
2121 // Create a second descriptor pool
2122 VkDescriptorPool ds_pool_two;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002123 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool_two);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002124 ASSERT_VK_SUCCESS(err);
2125
2126 VkDescriptorSetLayoutBinding dsl_binding = {};
2127 dsl_binding.binding = 0;
2128 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
2129 dsl_binding.descriptorCount = 1;
2130 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2131 dsl_binding.pImmutableSamplers = NULL;
2132
2133 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2134 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2135 ds_layout_ci.pNext = NULL;
2136 ds_layout_ci.bindingCount = 1;
2137 ds_layout_ci.pBindings = &dsl_binding;
2138
2139 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002140 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002141 ASSERT_VK_SUCCESS(err);
2142
2143 VkDescriptorSet descriptorSet;
2144 VkDescriptorSetAllocateInfo alloc_info = {};
2145 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
2146 alloc_info.descriptorSetCount = 1;
2147 alloc_info.descriptorPool = ds_pool_one;
2148 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002149 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002150 ASSERT_VK_SUCCESS(err);
2151
2152 err = vkFreeDescriptorSets(m_device->device(), ds_pool_two, 1, &descriptorSet);
2153
2154 m_errorMonitor->VerifyFound();
2155
2156 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2157 vkDestroyDescriptorPool(m_device->device(), ds_pool_one, NULL);
2158 vkDestroyDescriptorPool(m_device->device(), ds_pool_two, NULL);
2159}
2160
2161TEST_F(VkLayerTest, CreateUnknownObject) {
Karl Schultzf78bcdd2016-11-30 12:36:01 -07002162 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00788);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002163
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002164 TEST_DESCRIPTION("Pass an invalid image object handle into a Vulkan API call.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002165
2166 ASSERT_NO_FATAL_FAILURE(InitState());
2167
2168 // Pass bogus handle into GetImageMemoryRequirements
2169 VkMemoryRequirements mem_reqs;
2170 uint64_t fakeImageHandle = 0xCADECADE;
2171 VkImage fauxImage = reinterpret_cast<VkImage &>(fakeImageHandle);
2172
2173 vkGetImageMemoryRequirements(m_device->device(), fauxImage, &mem_reqs);
2174
2175 m_errorMonitor->VerifyFound();
2176}
2177
Karl Schultz6addd812016-02-02 17:17:23 -07002178TEST_F(VkLayerTest, PipelineNotBound) {
2179 VkResult err;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002180
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002181 TEST_DESCRIPTION("Pass in an invalid pipeline object handle into a Vulkan API call.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002182
Karl Schultzf78bcdd2016-11-30 12:36:01 -07002183 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00601);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002184
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002185 ASSERT_NO_FATAL_FAILURE(InitState());
2186 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002187
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002188 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002189 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2190 ds_type_count.descriptorCount = 1;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002191
2192 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002193 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2194 ds_pool_ci.pNext = NULL;
2195 ds_pool_ci.maxSets = 1;
2196 ds_pool_ci.poolSizeCount = 1;
2197 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002198
2199 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002200 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002201 ASSERT_VK_SUCCESS(err);
2202
2203 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002204 dsl_binding.binding = 0;
2205 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2206 dsl_binding.descriptorCount = 1;
2207 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2208 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002209
2210 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002211 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2212 ds_layout_ci.pNext = NULL;
2213 ds_layout_ci.bindingCount = 1;
2214 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002215
2216 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002217 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002218 ASSERT_VK_SUCCESS(err);
2219
2220 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002221 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08002222 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07002223 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06002224 alloc_info.descriptorPool = ds_pool;
2225 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002226 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002227 ASSERT_VK_SUCCESS(err);
2228
2229 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002230 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
2231 pipeline_layout_ci.pNext = NULL;
2232 pipeline_layout_ci.setLayoutCount = 1;
2233 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002234
2235 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002236 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002237 ASSERT_VK_SUCCESS(err);
2238
Mark Youngad779052016-01-06 14:26:04 -07002239 VkPipeline badPipeline = (VkPipeline)((size_t)0xbaadb1be);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002240
2241 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002242 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, badPipeline);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002243
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002244 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002245
Chia-I Wuf7458c52015-10-26 21:10:41 +08002246 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
2247 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2248 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002249}
Mike Stroyan80fc6c32016-06-20 15:42:29 -06002250
Mark Lobodzinskibc185762016-06-15 16:28:53 -06002251TEST_F(VkLayerTest, BindImageInvalidMemoryType) {
2252 VkResult err;
2253
2254 TEST_DESCRIPTION("Test validation check for an invalid memory type index "
2255 "during bind[Buffer|Image]Memory time");
2256
Mark Lobodzinskibc185762016-06-15 16:28:53 -06002257 ASSERT_NO_FATAL_FAILURE(InitState());
2258
2259 // Create an image, allocate memory, set a bad typeIndex and then try to
2260 // bind it
2261 VkImage image;
2262 VkDeviceMemory mem;
2263 VkMemoryRequirements mem_reqs;
2264 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2265 const int32_t tex_width = 32;
2266 const int32_t tex_height = 32;
2267
2268 VkImageCreateInfo image_create_info = {};
2269 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2270 image_create_info.pNext = NULL;
2271 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2272 image_create_info.format = tex_format;
2273 image_create_info.extent.width = tex_width;
2274 image_create_info.extent.height = tex_height;
2275 image_create_info.extent.depth = 1;
2276 image_create_info.mipLevels = 1;
2277 image_create_info.arrayLayers = 1;
2278 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2279 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
2280 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2281 image_create_info.flags = 0;
2282
2283 VkMemoryAllocateInfo mem_alloc = {};
2284 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2285 mem_alloc.pNext = NULL;
2286 mem_alloc.allocationSize = 0;
2287 mem_alloc.memoryTypeIndex = 0;
2288
2289 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
2290 ASSERT_VK_SUCCESS(err);
2291
2292 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
2293 mem_alloc.allocationSize = mem_reqs.size;
Mike Stroyan80fc6c32016-06-20 15:42:29 -06002294
2295 // Introduce Failure, select invalid TypeIndex
2296 VkPhysicalDeviceMemoryProperties memory_info;
2297
2298 vkGetPhysicalDeviceMemoryProperties(gpu(), &memory_info);
2299 unsigned int i;
2300 for (i = 0; i < memory_info.memoryTypeCount; i++) {
2301 if ((mem_reqs.memoryTypeBits & (1 << i)) == 0) {
2302 mem_alloc.memoryTypeIndex = i;
2303 break;
2304 }
2305 }
2306 if (i >= memory_info.memoryTypeCount) {
2307 printf("No invalid memory type index could be found; skipped.\n");
2308 vkDestroyImage(m_device->device(), image, NULL);
2309 return;
2310 }
2311
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002312 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 -06002313
2314 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
2315 ASSERT_VK_SUCCESS(err);
2316
2317 err = vkBindImageMemory(m_device->device(), image, mem, 0);
2318 (void)err;
2319
2320 m_errorMonitor->VerifyFound();
2321
2322 vkDestroyImage(m_device->device(), image, NULL);
2323 vkFreeMemory(m_device->device(), mem, NULL);
2324}
Mike Stroyan80fc6c32016-06-20 15:42:29 -06002325
Karl Schultz6addd812016-02-02 17:17:23 -07002326TEST_F(VkLayerTest, BindInvalidMemory) {
2327 VkResult err;
2328 bool pass;
Tobin Ehlisec598302015-09-15 15:02:17 -06002329
Karl Schultzf78bcdd2016-11-30 12:36:01 -07002330 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00809);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002331
Tobin Ehlisec598302015-09-15 15:02:17 -06002332 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisec598302015-09-15 15:02:17 -06002333
2334 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07002335 VkImage image;
2336 VkDeviceMemory mem;
2337 VkMemoryRequirements mem_reqs;
Tobin Ehlisec598302015-09-15 15:02:17 -06002338
Karl Schultz6addd812016-02-02 17:17:23 -07002339 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2340 const int32_t tex_width = 32;
2341 const int32_t tex_height = 32;
Tobin Ehlisec598302015-09-15 15:02:17 -06002342
2343 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002344 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2345 image_create_info.pNext = NULL;
2346 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2347 image_create_info.format = tex_format;
2348 image_create_info.extent.width = tex_width;
2349 image_create_info.extent.height = tex_height;
2350 image_create_info.extent.depth = 1;
2351 image_create_info.mipLevels = 1;
2352 image_create_info.arrayLayers = 1;
2353 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2354 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2355 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2356 image_create_info.flags = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002357
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002358 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002359 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2360 mem_alloc.pNext = NULL;
2361 mem_alloc.allocationSize = 0;
2362 mem_alloc.memoryTypeIndex = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002363
Chia-I Wuf7458c52015-10-26 21:10:41 +08002364 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlisec598302015-09-15 15:02:17 -06002365 ASSERT_VK_SUCCESS(err);
2366
Karl Schultz6addd812016-02-02 17:17:23 -07002367 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Tobin Ehlisec598302015-09-15 15:02:17 -06002368
2369 mem_alloc.allocationSize = mem_reqs.size;
2370
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002371 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06002372 ASSERT_TRUE(pass);
Tobin Ehlisec598302015-09-15 15:02:17 -06002373
2374 // allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002375 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlisec598302015-09-15 15:02:17 -06002376 ASSERT_VK_SUCCESS(err);
2377
2378 // Introduce validation failure, free memory before binding
Chia-I Wuf7458c52015-10-26 21:10:41 +08002379 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002380
2381 // Try to bind free memory that has been freed
2382 err = vkBindImageMemory(m_device->device(), image, mem, 0);
2383 // This may very well return an error.
2384 (void)err;
2385
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002386 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002387
Chia-I Wuf7458c52015-10-26 21:10:41 +08002388 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002389}
2390
Karl Schultz6addd812016-02-02 17:17:23 -07002391TEST_F(VkLayerTest, BindMemoryToDestroyedObject) {
2392 VkResult err;
2393 bool pass;
Tobin Ehlisec598302015-09-15 15:02:17 -06002394
Karl Schultzf78bcdd2016-11-30 12:36:01 -07002395 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00808);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002396
Tobin Ehlisec598302015-09-15 15:02:17 -06002397 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisec598302015-09-15 15:02:17 -06002398
Karl Schultz6addd812016-02-02 17:17:23 -07002399 // Create an image object, allocate memory, destroy the object and then try
2400 // to bind it
2401 VkImage image;
2402 VkDeviceMemory mem;
2403 VkMemoryRequirements mem_reqs;
Tobin Ehlisec598302015-09-15 15:02:17 -06002404
Karl Schultz6addd812016-02-02 17:17:23 -07002405 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2406 const int32_t tex_width = 32;
2407 const int32_t tex_height = 32;
Tobin Ehlisec598302015-09-15 15:02:17 -06002408
2409 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002410 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2411 image_create_info.pNext = NULL;
2412 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2413 image_create_info.format = tex_format;
2414 image_create_info.extent.width = tex_width;
2415 image_create_info.extent.height = tex_height;
2416 image_create_info.extent.depth = 1;
2417 image_create_info.mipLevels = 1;
2418 image_create_info.arrayLayers = 1;
2419 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2420 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2421 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2422 image_create_info.flags = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002423
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002424 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002425 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2426 mem_alloc.pNext = NULL;
2427 mem_alloc.allocationSize = 0;
2428 mem_alloc.memoryTypeIndex = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002429
Chia-I Wuf7458c52015-10-26 21:10:41 +08002430 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlisec598302015-09-15 15:02:17 -06002431 ASSERT_VK_SUCCESS(err);
2432
Karl Schultz6addd812016-02-02 17:17:23 -07002433 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Tobin Ehlisec598302015-09-15 15:02:17 -06002434
2435 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002436 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06002437 ASSERT_TRUE(pass);
Tobin Ehlisec598302015-09-15 15:02:17 -06002438
2439 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002440 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlisec598302015-09-15 15:02:17 -06002441 ASSERT_VK_SUCCESS(err);
2442
2443 // Introduce validation failure, destroy Image object before binding
Chia-I Wuf7458c52015-10-26 21:10:41 +08002444 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002445 ASSERT_VK_SUCCESS(err);
2446
2447 // Now Try to bind memory to this destroyed object
2448 err = vkBindImageMemory(m_device->device(), image, mem, 0);
2449 // This may very well return an error.
Karl Schultz6addd812016-02-02 17:17:23 -07002450 (void)err;
Tobin Ehlisec598302015-09-15 15:02:17 -06002451
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002452 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002453
Chia-I Wuf7458c52015-10-26 21:10:41 +08002454 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002455}
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002456
Mark Lobodzinski209b5292015-09-17 09:44:05 -06002457#endif // OBJ_TRACKER_TESTS
2458
Tobin Ehlis0788f522015-05-26 16:11:58 -06002459#if DRAW_STATE_TESTS
Mark Lobodzinskic808d442016-04-14 10:57:23 -06002460
Mark Lobodzinski66e5eab2016-11-15 13:30:38 -07002461TEST_F(VkLayerTest, CreatePipelineBadVertexAttributeFormat) {
2462 TEST_DESCRIPTION("Test that pipeline validation catches invalid vertex attribute formats");
2463
2464 ASSERT_NO_FATAL_FAILURE(InitState());
2465 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2466
2467 VkVertexInputBindingDescription input_binding;
2468 memset(&input_binding, 0, sizeof(input_binding));
2469
2470 VkVertexInputAttributeDescription input_attribs;
2471 memset(&input_attribs, 0, sizeof(input_attribs));
2472
2473 // Pick a really bad format for this purpose and make sure it should fail
2474 input_attribs.format = VK_FORMAT_BC2_UNORM_BLOCK;
2475 VkFormatProperties format_props = m_device->format_properties(input_attribs.format);
2476 if ((format_props.bufferFeatures & VK_FORMAT_FEATURE_VERTEX_BUFFER_BIT) != 0) {
2477 printf("Format unsuitable for test; skipped.\n");
2478 return;
2479 }
2480
2481 input_attribs.location = 0;
2482 char const *vsSource = "#version 450\n"
2483 "\n"
2484 "out gl_PerVertex {\n"
2485 " vec4 gl_Position;\n"
2486 "};\n"
2487 "void main(){\n"
2488 " gl_Position = vec4(1);\n"
2489 "}\n";
2490 char const *fsSource = "#version 450\n"
2491 "\n"
2492 "layout(location=0) out vec4 color;\n"
2493 "void main(){\n"
2494 " color = vec4(1);\n"
2495 "}\n";
2496
2497 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01413);
2498 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
2499 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
2500
2501 VkPipelineObj pipe(m_device);
2502 pipe.AddColorAttachment();
2503 pipe.AddShader(&vs);
2504 pipe.AddShader(&fs);
2505
2506 pipe.AddVertexInputBindings(&input_binding, 1);
2507 pipe.AddVertexInputAttribs(&input_attribs, 1);
2508
2509 VkDescriptorSetObj descriptorSet(m_device);
2510 descriptorSet.AppendDummy();
2511 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
2512
2513 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
2514
2515 m_errorMonitor->VerifyFound();
2516}
2517
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002518TEST_F(VkLayerTest, ImageSampleCounts) {
2519
2520 TEST_DESCRIPTION("Use bad sample counts in image transfer calls to trigger "
2521 "validation errors.");
2522 ASSERT_NO_FATAL_FAILURE(InitState());
2523
2524 VkMemoryPropertyFlags reqs = 0;
2525 VkImageCreateInfo image_create_info = {};
2526 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2527 image_create_info.pNext = NULL;
2528 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2529 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
2530 image_create_info.extent.width = 256;
2531 image_create_info.extent.height = 256;
2532 image_create_info.extent.depth = 1;
2533 image_create_info.mipLevels = 1;
2534 image_create_info.arrayLayers = 1;
2535 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
2536 image_create_info.flags = 0;
2537
2538 VkImageBlit blit_region = {};
2539 blit_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2540 blit_region.srcSubresource.baseArrayLayer = 0;
2541 blit_region.srcSubresource.layerCount = 1;
2542 blit_region.srcSubresource.mipLevel = 0;
2543 blit_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2544 blit_region.dstSubresource.baseArrayLayer = 0;
2545 blit_region.dstSubresource.layerCount = 1;
2546 blit_region.dstSubresource.mipLevel = 0;
2547
2548 // Create two images, the source with sampleCount = 2, and attempt to blit
2549 // between them
2550 {
2551 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002552 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002553 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002554 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002555 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002556 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002557 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002558 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002559 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002560 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "was created with a sample count "
2561 "of VK_SAMPLE_COUNT_2_BIT but "
2562 "must be VK_SAMPLE_COUNT_1_BIT");
2563 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
2564 dst_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, 1, &blit_region, VK_FILTER_NEAREST);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002565 m_errorMonitor->VerifyFound();
2566 m_commandBuffer->EndCommandBuffer();
2567 }
2568
2569 // Create two images, the dest with sampleCount = 4, and attempt to blit
2570 // between them
2571 {
2572 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002573 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002574 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002575 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002576 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002577 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002578 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002579 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002580 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002581 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "was created with a sample count "
2582 "of VK_SAMPLE_COUNT_4_BIT but "
2583 "must be VK_SAMPLE_COUNT_1_BIT");
2584 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
2585 dst_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, 1, &blit_region, VK_FILTER_NEAREST);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002586 m_errorMonitor->VerifyFound();
2587 m_commandBuffer->EndCommandBuffer();
2588 }
2589
2590 VkBufferImageCopy copy_region = {};
2591 copy_region.bufferRowLength = 128;
2592 copy_region.bufferImageHeight = 128;
2593 copy_region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2594 copy_region.imageSubresource.layerCount = 1;
2595 copy_region.imageExtent.height = 64;
2596 copy_region.imageExtent.width = 64;
2597 copy_region.imageExtent.depth = 1;
2598
2599 // Create src buffer and dst image with sampleCount = 4 and attempt to copy
2600 // buffer to image
2601 {
2602 vk_testing::Buffer src_buffer;
2603 VkMemoryPropertyFlags reqs = 0;
2604 src_buffer.init_as_src(*m_device, 128 * 128 * 4, reqs);
2605 image_create_info.samples = VK_SAMPLE_COUNT_8_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002606 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002607 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002608 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002609 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002610 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "was created with a sample count "
2611 "of VK_SAMPLE_COUNT_8_BIT but "
2612 "must be VK_SAMPLE_COUNT_1_BIT");
2613 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), src_buffer.handle(), dst_image.handle(),
2614 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &copy_region);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002615 m_errorMonitor->VerifyFound();
2616 m_commandBuffer->EndCommandBuffer();
2617 }
2618
2619 // Create dst buffer and src image with sampleCount = 2 and attempt to copy
2620 // image to buffer
2621 {
2622 vk_testing::Buffer dst_buffer;
2623 dst_buffer.init_as_dst(*m_device, 128 * 128 * 4, reqs);
2624 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002625 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002626 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002627 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002628 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002629 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "was created with a sample count "
2630 "of VK_SAMPLE_COUNT_2_BIT but "
2631 "must be VK_SAMPLE_COUNT_1_BIT");
2632 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002633 dst_buffer.handle(), 1, &copy_region);
2634 m_errorMonitor->VerifyFound();
2635 m_commandBuffer->EndCommandBuffer();
2636 }
2637}
2638
Mike Stroyanac5afeb2016-10-17 13:58:10 -06002639TEST_F(VkLayerTest, BlitImageFormats) {
2640
2641 // Image blit with mismatched formats
2642 const char * expected_message =
2643 "vkCmdBlitImage: If one of srcImage and dstImage images has signed/unsigned integer format,"
2644 " the other one must also have signed/unsigned integer format";
2645
2646 ASSERT_NO_FATAL_FAILURE(InitState());
2647
2648 VkImageObj src_image(m_device);
2649 src_image.init(64, 64, VK_FORMAT_A2B10G10R10_UINT_PACK32, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_LINEAR, 0);
2650 VkImageObj dst_image(m_device);
2651 dst_image.init(64, 64, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
2652 VkImageObj dst_image2(m_device);
Mike Stroyan131f3e72016-10-18 11:10:23 -06002653 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 -06002654
2655 VkImageBlit blitRegion = {};
2656 blitRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2657 blitRegion.srcSubresource.baseArrayLayer = 0;
2658 blitRegion.srcSubresource.layerCount = 1;
2659 blitRegion.srcSubresource.mipLevel = 0;
2660 blitRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2661 blitRegion.dstSubresource.baseArrayLayer = 0;
2662 blitRegion.dstSubresource.layerCount = 1;
2663 blitRegion.dstSubresource.mipLevel = 0;
2664
2665 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, expected_message);
2666
2667 // Unsigned int vs not an int
2668 BeginCommandBuffer();
2669 vkCmdBlitImage(m_commandBuffer->handle(), src_image.image(), src_image.layout(), dst_image.image(),
2670 dst_image.layout(), 1, &blitRegion, VK_FILTER_NEAREST);
2671
2672 m_errorMonitor->VerifyFound();
2673
2674 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, expected_message);
2675
2676 // Unsigned int vs signed int
2677 vkCmdBlitImage(m_commandBuffer->handle(), src_image.image(), src_image.layout(), dst_image2.image(),
2678 dst_image2.layout(), 1, &blitRegion, VK_FILTER_NEAREST);
2679
2680 m_errorMonitor->VerifyFound();
2681
2682 EndCommandBuffer();
2683}
2684
2685
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002686TEST_F(VkLayerTest, DSImageTransferGranularityTests) {
2687 VkResult err;
2688 bool pass;
2689
2690 TEST_DESCRIPTION("Tests for validaiton of Queue Family property minImageTransferGranularity.");
2691 ASSERT_NO_FATAL_FAILURE(InitState());
2692
2693 // If w/d/h granularity is 1, test is not meaningful
2694 // TODO: When virtual device limits are available, create a set of limits for this test that
2695 // will always have a granularity of > 1 for w, h, and d
2696 auto index = m_device->graphics_queue_node_index_;
2697 auto queue_family_properties = m_device->phy().queue_properties();
2698
2699 if ((queue_family_properties[index].minImageTransferGranularity.depth < 4) ||
2700 (queue_family_properties[index].minImageTransferGranularity.width < 4) ||
2701 (queue_family_properties[index].minImageTransferGranularity.height < 4)) {
2702 return;
2703 }
2704
2705 // Create two images of different types and try to copy between them
2706 VkImage srcImage;
2707 VkImage dstImage;
2708 VkDeviceMemory srcMem;
2709 VkDeviceMemory destMem;
2710 VkMemoryRequirements memReqs;
2711
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002712 VkImageCreateInfo image_create_info = {};
2713 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2714 image_create_info.pNext = NULL;
2715 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2716 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
2717 image_create_info.extent.width = 32;
2718 image_create_info.extent.height = 32;
2719 image_create_info.extent.depth = 1;
2720 image_create_info.mipLevels = 1;
2721 image_create_info.arrayLayers = 4;
2722 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2723 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
2724 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
2725 image_create_info.flags = 0;
2726
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002727 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002728 ASSERT_VK_SUCCESS(err);
2729
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002730 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002731 ASSERT_VK_SUCCESS(err);
2732
2733 // Allocate memory
2734 VkMemoryAllocateInfo memAlloc = {};
2735 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2736 memAlloc.pNext = NULL;
2737 memAlloc.allocationSize = 0;
2738 memAlloc.memoryTypeIndex = 0;
2739
2740 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
2741 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002742 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002743 ASSERT_TRUE(pass);
2744 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
2745 ASSERT_VK_SUCCESS(err);
2746
2747 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
2748 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002749 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002750 ASSERT_VK_SUCCESS(err);
2751 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
2752 ASSERT_VK_SUCCESS(err);
2753
2754 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
2755 ASSERT_VK_SUCCESS(err);
2756 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
2757 ASSERT_VK_SUCCESS(err);
2758
2759 BeginCommandBuffer();
2760 VkImageCopy copyRegion;
2761 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2762 copyRegion.srcSubresource.mipLevel = 0;
2763 copyRegion.srcSubresource.baseArrayLayer = 0;
2764 copyRegion.srcSubresource.layerCount = 1;
2765 copyRegion.srcOffset.x = 0;
2766 copyRegion.srcOffset.y = 0;
2767 copyRegion.srcOffset.z = 0;
2768 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2769 copyRegion.dstSubresource.mipLevel = 0;
2770 copyRegion.dstSubresource.baseArrayLayer = 0;
2771 copyRegion.dstSubresource.layerCount = 1;
2772 copyRegion.dstOffset.x = 0;
2773 copyRegion.dstOffset.y = 0;
2774 copyRegion.dstOffset.z = 0;
2775 copyRegion.extent.width = 1;
2776 copyRegion.extent.height = 1;
2777 copyRegion.extent.depth = 1;
2778
2779 // Introduce failure by setting srcOffset to a bad granularity value
2780 copyRegion.srcOffset.y = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002781 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2782 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002783 m_errorMonitor->VerifyFound();
2784
2785 // Introduce failure by setting extent to a bad granularity value
2786 copyRegion.srcOffset.y = 0;
2787 copyRegion.extent.width = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002788 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2789 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002790 m_errorMonitor->VerifyFound();
2791
2792 // Now do some buffer/image copies
2793 vk_testing::Buffer buffer;
2794 VkMemoryPropertyFlags reqs = 0;
2795 buffer.init_as_dst(*m_device, 128 * 128, reqs);
2796 VkBufferImageCopy region = {};
2797 region.bufferOffset = 0;
2798 region.bufferRowLength = 3;
2799 region.bufferImageHeight = 128;
2800 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2801 region.imageSubresource.layerCount = 1;
2802 region.imageExtent.height = 16;
2803 region.imageExtent.width = 16;
2804 region.imageExtent.depth = 1;
2805 region.imageOffset.x = 0;
2806 region.imageOffset.y = 0;
2807 region.imageOffset.z = 0;
2808
2809 // Introduce failure by setting bufferRowLength to a bad granularity value
2810 region.bufferRowLength = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002811 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2812 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
2813 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002814 m_errorMonitor->VerifyFound();
2815 region.bufferRowLength = 128;
2816
2817 // Introduce failure by setting bufferOffset to a bad granularity value
2818 region.bufferOffset = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002819 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2820 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
2821 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002822 m_errorMonitor->VerifyFound();
2823 region.bufferOffset = 0;
2824
2825 // Introduce failure by setting bufferImageHeight to a bad granularity value
2826 region.bufferImageHeight = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002827 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2828 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
2829 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002830 m_errorMonitor->VerifyFound();
2831 region.bufferImageHeight = 128;
2832
2833 // Introduce failure by setting imageExtent to a bad granularity value
2834 region.imageExtent.width = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002835 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2836 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
2837 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002838 m_errorMonitor->VerifyFound();
2839 region.imageExtent.width = 16;
2840
2841 // Introduce failure by setting imageOffset to a bad granularity value
2842 region.imageOffset.z = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002843 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2844 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
2845 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002846 m_errorMonitor->VerifyFound();
2847
2848 EndCommandBuffer();
2849
2850 vkDestroyImage(m_device->device(), srcImage, NULL);
2851 vkDestroyImage(m_device->device(), dstImage, NULL);
2852 vkFreeMemory(m_device->device(), srcMem, NULL);
2853 vkFreeMemory(m_device->device(), destMem, NULL);
2854}
2855
Mark Lobodzinski570efc62016-08-09 16:43:19 -06002856TEST_F(VkLayerTest, MismatchedQueueFamiliesOnSubmit) {
Mark Lobodzinski570efc62016-08-09 16:43:19 -06002857 TEST_DESCRIPTION("Submit command buffer created using one queue family and "
2858 "attempt to submit them on a queue created in a different "
2859 "queue family.");
2860
Cody Northropc31a84f2016-08-22 10:41:47 -06002861 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski570efc62016-08-09 16:43:19 -06002862 // This test is meaningless unless we have multiple queue families
2863 auto queue_family_properties = m_device->phy().queue_properties();
2864 if (queue_family_properties.size() < 2) {
2865 return;
2866 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002867 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is being submitted on queue ");
Mark Lobodzinski570efc62016-08-09 16:43:19 -06002868 // Get safe index of another queue family
2869 uint32_t other_queue_family = (m_device->graphics_queue_node_index_ == 0) ? 1 : 0;
2870 ASSERT_NO_FATAL_FAILURE(InitState());
2871 // Create a second queue using a different queue family
2872 VkQueue other_queue;
2873 vkGetDeviceQueue(m_device->device(), other_queue_family, 0, &other_queue);
2874
2875 // Record an empty cmd buffer
2876 VkCommandBufferBeginInfo cmdBufBeginDesc = {};
2877 cmdBufBeginDesc.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
2878 vkBeginCommandBuffer(m_commandBuffer->handle(), &cmdBufBeginDesc);
2879 vkEndCommandBuffer(m_commandBuffer->handle());
2880
2881 // And submit on the wrong queue
2882 VkSubmitInfo submit_info = {};
2883 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
2884 submit_info.commandBufferCount = 1;
2885 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Tobin Ehlisfd213ea2016-08-10 17:10:46 -06002886 vkQueueSubmit(other_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Lobodzinski570efc62016-08-09 16:43:19 -06002887
2888 m_errorMonitor->VerifyFound();
Mark Lobodzinski570efc62016-08-09 16:43:19 -06002889}
2890
Chris Forbes4c24a922016-11-16 08:59:10 +13002891TEST_F(VkLayerTest, RenderPassAttachmentIndexOutOfRange) {
2892 ASSERT_NO_FATAL_FAILURE(InitState());
2893
Chris Forbes2d9b2a82016-11-21 10:45:39 +13002894 // There are no attachments, but refer to attachment 0.
2895 VkAttachmentReference ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Chris Forbes4c24a922016-11-16 08:59:10 +13002896 VkSubpassDescription subpasses[] = {
Chris Forbes2d9b2a82016-11-21 10:45:39 +13002897 {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &ref, nullptr,
2898 nullptr, 0, nullptr},
Chris Forbes4c24a922016-11-16 08:59:10 +13002899 };
2900
Chris Forbes2d9b2a82016-11-21 10:45:39 +13002901 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO,
2902 nullptr,
2903 0,
2904 0,
2905 nullptr,
2906 1,
2907 subpasses,
2908 0,
2909 nullptr};
Chris Forbes4c24a922016-11-16 08:59:10 +13002910 VkRenderPass rp;
2911
Chris Forbes2d9b2a82016-11-21 10:45:39 +13002912 // "... must be less than the total number of attachments ..."
Chris Forbes4c24a922016-11-16 08:59:10 +13002913 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbes2d9b2a82016-11-21 10:45:39 +13002914 VALIDATION_ERROR_00325);
Chris Forbes4c24a922016-11-16 08:59:10 +13002915 vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
2916 m_errorMonitor->VerifyFound();
2917}
2918
Chris Forbesa58c4522016-09-28 15:19:39 +13002919TEST_F(VkLayerTest, RenderPassPipelineSubpassMismatch) {
2920 TEST_DESCRIPTION("Use a pipeline for the wrong subpass in a render pass instance");
2921 ASSERT_NO_FATAL_FAILURE(InitState());
2922
2923 // A renderpass with two subpasses, both writing the same attachment.
2924 VkAttachmentDescription attach[] = {
2925 { 0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT,
2926 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
2927 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
2928 VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL
2929 },
2930 };
2931 VkAttachmentReference ref = { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
2932 VkSubpassDescription subpasses[] = {
2933 { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr,
2934 1, &ref, nullptr, nullptr, 0, nullptr },
2935 { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr,
2936 1, &ref, nullptr, nullptr, 0, nullptr },
2937 };
2938 VkSubpassDependency dep = {
2939 0, 1,
2940 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
2941 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
2942 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
2943 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
2944 VK_DEPENDENCY_BY_REGION_BIT
2945 };
2946 VkRenderPassCreateInfo rpci = {
2947 VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr,
2948 0, 1, attach, 2, subpasses, 1, &dep
2949 };
2950 VkRenderPass rp;
2951 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
2952 ASSERT_VK_SUCCESS(err);
2953
2954 VkImageObj image(m_device);
2955 image.init_no_layout(32, 32, VK_FORMAT_R8G8B8A8_UNORM,
2956 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT,
2957 VK_IMAGE_TILING_OPTIMAL, 0);
2958 VkImageView imageView = image.targetView(VK_FORMAT_R8G8B8A8_UNORM);
2959
2960 VkFramebufferCreateInfo fbci = {
2961 VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr,
2962 0, rp, 1, &imageView, 32, 32, 1
2963 };
2964 VkFramebuffer fb;
2965 err = vkCreateFramebuffer(m_device->device(), &fbci, nullptr, &fb);
2966 ASSERT_VK_SUCCESS(err);
2967
2968 char const *vsSource =
2969 "#version 450\n"
2970 "void main() { gl_Position = vec4(1); }\n";
2971 char const *fsSource =
2972 "#version 450\n"
2973 "layout(location=0) out vec4 color;\n"
2974 "void main() { color = vec4(1); }\n";
2975
2976 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
2977 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
2978 VkPipelineObj pipe(m_device);
2979 pipe.AddColorAttachment();
2980 pipe.AddShader(&vs);
2981 pipe.AddShader(&fs);
2982 VkViewport view_port = {};
2983 m_viewports.push_back(view_port);
2984 pipe.SetViewport(m_viewports);
2985 VkRect2D rect = {};
2986 m_scissors.push_back(rect);
2987 pipe.SetScissor(m_scissors);
2988
2989 VkPipelineLayoutCreateInfo plci = {
2990 VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr,
2991 0, 0, nullptr, 0, nullptr
2992 };
2993 VkPipelineLayout pl;
2994 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
2995 ASSERT_VK_SUCCESS(err);
2996 pipe.CreateVKPipeline(pl, rp);
2997
2998 BeginCommandBuffer();
2999
3000 VkRenderPassBeginInfo rpbi = {
3001 VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr,
3002 rp, fb, { { 0, 0, }, { 32, 32 } }, 0, nullptr
3003 };
3004
3005 // subtest 1: bind in the wrong subpass
3006 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
3007 vkCmdNextSubpass(m_commandBuffer->handle(), VK_SUBPASS_CONTENTS_INLINE);
3008 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3009 "built for subpass 0 but used in subpass 1");
3010 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
3011 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
3012 m_errorMonitor->VerifyFound();
3013
3014 vkCmdEndRenderPass(m_commandBuffer->handle());
3015
3016 // subtest 2: bind in correct subpass, then transition to next subpass
3017 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
3018 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
3019 vkCmdNextSubpass(m_commandBuffer->handle(), VK_SUBPASS_CONTENTS_INLINE);
3020 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3021 "built for subpass 0 but used in subpass 1");
3022 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
3023 m_errorMonitor->VerifyFound();
3024
3025 vkCmdEndRenderPass(m_commandBuffer->handle());
3026
3027 EndCommandBuffer();
3028
3029 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
3030 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
3031 vkDestroyRenderPass(m_device->device(), rp, nullptr);
3032}
3033
Tony Barbour4e919972016-08-09 13:27:40 -06003034TEST_F(VkLayerTest, RenderPassInvalidRenderArea) {
3035 TEST_DESCRIPTION("Generate INVALID_RENDER_AREA error by beginning renderpass"
3036 "with extent outside of framebuffer");
3037 ASSERT_NO_FATAL_FAILURE(InitState());
3038 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3039
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003040 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot execute a render pass with renderArea "
3041 "not within the bound of the framebuffer.");
Tony Barbour4e919972016-08-09 13:27:40 -06003042
3043 // Framebuffer for render target is 256x256, exceed that for INVALID_RENDER_AREA
3044 m_renderPassBeginInfo.renderArea.extent.width = 257;
3045 m_renderPassBeginInfo.renderArea.extent.height = 257;
3046 BeginCommandBuffer();
3047 m_errorMonitor->VerifyFound();
3048}
3049
3050TEST_F(VkLayerTest, DisabledIndependentBlend) {
3051 TEST_DESCRIPTION("Generate INDEPENDENT_BLEND by disabling independent "
3052 "blend and then specifying different blend states for two "
3053 "attachements");
Cody Northrop5703cc72016-08-19 09:57:10 -06003054 VkPhysicalDeviceFeatures features = {};
3055 features.independentBlend = VK_FALSE;
Cody Northropc31a84f2016-08-22 10:41:47 -06003056 ASSERT_NO_FATAL_FAILURE(InitState(&features));
Tony Barbour4e919972016-08-09 13:27:40 -06003057
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003058 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3059 "Invalid Pipeline CreateInfo: If independent blend feature not "
3060 "enabled, all elements of pAttachments must be identical");
Tony Barbour4e919972016-08-09 13:27:40 -06003061
Cody Northropc31a84f2016-08-22 10:41:47 -06003062 VkDescriptorSetObj descriptorSet(m_device);
3063 descriptorSet.AppendDummy();
3064 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Tony Barbour4e919972016-08-09 13:27:40 -06003065
Cody Northropc31a84f2016-08-22 10:41:47 -06003066 VkPipelineObj pipeline(m_device);
3067 VkRenderpassObj renderpass(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003068 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Cody Northropc31a84f2016-08-22 10:41:47 -06003069 pipeline.AddShader(&vs);
Cody Northrop5703cc72016-08-19 09:57:10 -06003070
Cody Northropc31a84f2016-08-22 10:41:47 -06003071 VkPipelineColorBlendAttachmentState att_state1 = {}, att_state2 = {};
3072 att_state1.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
3073 att_state1.blendEnable = VK_TRUE;
3074 att_state2.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
3075 att_state2.blendEnable = VK_FALSE;
3076 pipeline.AddColorAttachment(0, &att_state1);
3077 pipeline.AddColorAttachment(1, &att_state2);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003078 pipeline.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderpass.handle());
Cody Northropc31a84f2016-08-22 10:41:47 -06003079 m_errorMonitor->VerifyFound();
Tony Barbour4e919972016-08-09 13:27:40 -06003080}
3081
Chris Forbes26ec2122016-11-29 08:58:33 +13003082#if 0
Tony Barbour4e919972016-08-09 13:27:40 -06003083TEST_F(VkLayerTest, RenderPassDepthStencilAttachmentUnused) {
3084 TEST_DESCRIPTION("Specify no depth attachement in renderpass then specify "
3085 "depth attachments in subpass");
Cody Northropc31a84f2016-08-22 10:41:47 -06003086 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbour4e919972016-08-09 13:27:40 -06003087
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003088 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3089 "vkCreateRenderPass has no depth/stencil attachment, yet subpass");
Tony Barbour4e919972016-08-09 13:27:40 -06003090
3091 // Create a renderPass with a single color attachment
3092 VkAttachmentReference attach = {};
3093 attach.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
3094 VkSubpassDescription subpass = {};
3095 VkRenderPassCreateInfo rpci = {};
3096 rpci.subpassCount = 1;
3097 rpci.pSubpasses = &subpass;
3098 rpci.attachmentCount = 1;
3099 VkAttachmentDescription attach_desc = {};
3100 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
3101 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
3102 rpci.pAttachments = &attach_desc;
3103 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3104 VkRenderPass rp;
3105 subpass.pDepthStencilAttachment = &attach;
3106 subpass.pColorAttachments = NULL;
3107 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3108 m_errorMonitor->VerifyFound();
3109}
Chris Forbes26ec2122016-11-29 08:58:33 +13003110#endif
Tony Barbour4e919972016-08-09 13:27:40 -06003111
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003112TEST_F(VkLayerTest, UnusedPreserveAttachment) {
3113 TEST_DESCRIPTION("Create a framebuffer where a subpass has a preserve "
3114 "attachment reference of VK_ATTACHMENT_UNUSED");
3115
3116 ASSERT_NO_FATAL_FAILURE(InitState());
3117 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3118
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003119 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "must not be VK_ATTACHMENT_UNUSED");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003120
3121 VkAttachmentReference color_attach = {};
3122 color_attach.layout = VK_IMAGE_LAYOUT_GENERAL;
3123 color_attach.attachment = 0;
3124 uint32_t preserve_attachment = VK_ATTACHMENT_UNUSED;
3125 VkSubpassDescription subpass = {};
3126 subpass.colorAttachmentCount = 1;
3127 subpass.pColorAttachments = &color_attach;
3128 subpass.preserveAttachmentCount = 1;
3129 subpass.pPreserveAttachments = &preserve_attachment;
3130
3131 VkRenderPassCreateInfo rpci = {};
3132 rpci.subpassCount = 1;
3133 rpci.pSubpasses = &subpass;
3134 rpci.attachmentCount = 1;
3135 VkAttachmentDescription attach_desc = {};
3136 attach_desc.format = VK_FORMAT_UNDEFINED;
3137 rpci.pAttachments = &attach_desc;
3138 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3139 VkRenderPass rp;
Mark Lobodzinskia4feeeb2016-06-17 12:00:46 -06003140 VkResult result = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003141
3142 m_errorMonitor->VerifyFound();
3143
Mark Lobodzinskia4feeeb2016-06-17 12:00:46 -06003144 if (result == VK_SUCCESS) {
3145 vkDestroyRenderPass(m_device->device(), rp, NULL);
3146 }
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003147}
3148
Chris Forbesc5389742016-06-29 11:49:23 +12003149TEST_F(VkLayerTest, CreateRenderPassResolveRequiresColorMsaa) {
Chris Forbes6655bb32016-07-01 18:27:30 +12003150 TEST_DESCRIPTION("Ensure that CreateRenderPass produces a validation error "
3151 "when the source of a subpass multisample resolve "
3152 "does not have multiple samples.");
3153
Chris Forbesc5389742016-06-29 11:49:23 +12003154 ASSERT_NO_FATAL_FAILURE(InitState());
3155
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003156 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3157 "Subpass 0 requests multisample resolve from attachment 0 which has "
3158 "VK_SAMPLE_COUNT_1_BIT");
Chris Forbesc5389742016-06-29 11:49:23 +12003159
3160 VkAttachmentDescription attachments[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003161 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3162 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3163 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3164 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3165 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3166 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbesc5389742016-06-29 11:49:23 +12003167 };
3168
3169 VkAttachmentReference color = {
3170 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3171 };
3172
3173 VkAttachmentReference resolve = {
3174 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3175 };
3176
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003177 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &color, &resolve, nullptr, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003178
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003179 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003180
3181 VkRenderPass rp;
3182 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3183
3184 m_errorMonitor->VerifyFound();
3185
3186 if (err == VK_SUCCESS)
3187 vkDestroyRenderPass(m_device->device(), rp, nullptr);
3188}
3189
3190TEST_F(VkLayerTest, CreateRenderPassResolveRequiresSingleSampleDest) {
Chris Forbes6655bb32016-07-01 18:27:30 +12003191 TEST_DESCRIPTION("Ensure CreateRenderPass produces a validation error "
3192 "when a subpass multisample resolve operation is "
3193 "requested, and the destination of that resolve has "
3194 "multiple samples.");
3195
Chris Forbesc5389742016-06-29 11:49:23 +12003196 ASSERT_NO_FATAL_FAILURE(InitState());
3197
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003198 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3199 "Subpass 0 requests multisample resolve into attachment 1, which "
3200 "must have VK_SAMPLE_COUNT_1_BIT but has VK_SAMPLE_COUNT_4_BIT");
Chris Forbesc5389742016-06-29 11:49:23 +12003201
3202 VkAttachmentDescription attachments[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003203 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3204 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3205 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3206 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3207 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3208 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbesc5389742016-06-29 11:49:23 +12003209 };
3210
3211 VkAttachmentReference color = {
3212 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3213 };
3214
3215 VkAttachmentReference resolve = {
3216 1, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3217 };
3218
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003219 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &color, &resolve, nullptr, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003220
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003221 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003222
3223 VkRenderPass rp;
3224 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3225
3226 m_errorMonitor->VerifyFound();
3227
3228 if (err == VK_SUCCESS)
3229 vkDestroyRenderPass(m_device->device(), rp, nullptr);
3230}
3231
Chris Forbes3f128ef2016-06-29 14:58:53 +12003232TEST_F(VkLayerTest, CreateRenderPassSubpassSampleCountConsistency) {
Chris Forbes6655bb32016-07-01 18:27:30 +12003233 TEST_DESCRIPTION("Ensure CreateRenderPass produces a validation error "
3234 "when the color and depth attachments used by a subpass "
3235 "have inconsistent sample counts");
3236
Chris Forbes3f128ef2016-06-29 14:58:53 +12003237 ASSERT_NO_FATAL_FAILURE(InitState());
3238
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003239 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3240 "Subpass 0 attempts to render to attachments with inconsistent sample counts");
Chris Forbes3f128ef2016-06-29 14:58:53 +12003241
3242 VkAttachmentDescription attachments[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003243 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3244 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3245 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3246 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3247 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3248 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbes3f128ef2016-06-29 14:58:53 +12003249 };
3250
3251 VkAttachmentReference color[] = {
3252 {
3253 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3254 },
3255 {
3256 1, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3257 },
3258 };
3259
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003260 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 2, color, nullptr, nullptr, 0, nullptr};
Chris Forbes3f128ef2016-06-29 14:58:53 +12003261
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003262 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbes3f128ef2016-06-29 14:58:53 +12003263
3264 VkRenderPass rp;
3265 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3266
3267 m_errorMonitor->VerifyFound();
3268
3269 if (err == VK_SUCCESS)
3270 vkDestroyRenderPass(m_device->device(), rp, nullptr);
3271}
3272
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003273TEST_F(VkLayerTest, FramebufferCreateErrors) {
3274 TEST_DESCRIPTION("Hit errors when attempting to create a framebuffer :\n"
Mike Weiblencce7ec72016-10-17 19:33:05 -06003275 " 1. Mismatch between framebuffer & renderPass attachmentCount\n"
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003276 " 2. Use a color image as depthStencil attachment\n"
Mike Weiblencce7ec72016-10-17 19:33:05 -06003277 " 3. Mismatch framebuffer & renderPass attachment formats\n"
3278 " 4. Mismatch framebuffer & renderPass attachment #samples\n"
3279 " 5. Framebuffer attachment w/ non-1 mip-levels\n"
3280 " 6. Framebuffer attachment where dimensions don't match\n"
3281 " 7. Framebuffer attachment w/o identity swizzle\n"
3282 " 8. framebuffer dimensions exceed physical device limits\n");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003283
3284 ASSERT_NO_FATAL_FAILURE(InitState());
3285 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3286
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003287 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3288 "vkCreateFramebuffer(): VkFramebufferCreateInfo attachmentCount of 2 "
3289 "does not match attachmentCount of 1 of ");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003290
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003291 // Create a renderPass with a single color attachment
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003292 VkAttachmentReference attach = {};
3293 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
3294 VkSubpassDescription subpass = {};
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003295 subpass.pColorAttachments = &attach;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003296 VkRenderPassCreateInfo rpci = {};
3297 rpci.subpassCount = 1;
3298 rpci.pSubpasses = &subpass;
3299 rpci.attachmentCount = 1;
3300 VkAttachmentDescription attach_desc = {};
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003301 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis77d717c2016-06-22 14:19:19 -06003302 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003303 rpci.pAttachments = &attach_desc;
3304 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3305 VkRenderPass rp;
3306 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3307 ASSERT_VK_SUCCESS(err);
3308
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003309 VkImageView ivs[2];
3310 ivs[0] = m_renderTargets[0]->targetView(VK_FORMAT_B8G8R8A8_UNORM);
3311 ivs[1] = m_renderTargets[0]->targetView(VK_FORMAT_B8G8R8A8_UNORM);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003312 VkFramebufferCreateInfo fb_info = {};
3313 fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
3314 fb_info.pNext = NULL;
3315 fb_info.renderPass = rp;
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003316 // Set mis-matching attachmentCount
3317 fb_info.attachmentCount = 2;
3318 fb_info.pAttachments = ivs;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003319 fb_info.width = 100;
3320 fb_info.height = 100;
3321 fb_info.layers = 1;
3322
3323 VkFramebuffer fb;
3324 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3325
3326 m_errorMonitor->VerifyFound();
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003327 if (err == VK_SUCCESS) {
3328 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3329 }
3330 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003331
3332 // Create a renderPass with a depth-stencil attachment created with
3333 // IMAGE_USAGE_COLOR_ATTACHMENT
3334 // Add our color attachment to pDepthStencilAttachment
3335 subpass.pDepthStencilAttachment = &attach;
3336 subpass.pColorAttachments = NULL;
3337 VkRenderPass rp_ds;
3338 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp_ds);
3339 ASSERT_VK_SUCCESS(err);
3340 // Set correct attachment count, but attachment has COLOR usage bit set
3341 fb_info.attachmentCount = 1;
3342 fb_info.renderPass = rp_ds;
3343
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003344 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " conflicts with the image's IMAGE_USAGE flags ");
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003345 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3346
3347 m_errorMonitor->VerifyFound();
3348 if (err == VK_SUCCESS) {
3349 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3350 }
3351 vkDestroyRenderPass(m_device->device(), rp_ds, NULL);
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003352
3353 // Create new renderpass with alternate attachment format from fb
3354 attach_desc.format = VK_FORMAT_R8G8B8A8_UNORM;
3355 subpass.pDepthStencilAttachment = NULL;
3356 subpass.pColorAttachments = &attach;
3357 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3358 ASSERT_VK_SUCCESS(err);
3359
3360 // Cause error due to mis-matched formats between rp & fb
3361 // rp attachment 0 now has RGBA8 but corresponding fb attach is BGRA8
3362 fb_info.renderPass = rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003363 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3364 " has format of VK_FORMAT_B8G8R8A8_UNORM that does not match ");
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003365 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3366
3367 m_errorMonitor->VerifyFound();
3368 if (err == VK_SUCCESS) {
3369 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3370 }
Tobin Ehlis77d717c2016-06-22 14:19:19 -06003371 vkDestroyRenderPass(m_device->device(), rp, NULL);
3372
3373 // Create new renderpass with alternate sample count from fb
3374 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
3375 attach_desc.samples = VK_SAMPLE_COUNT_4_BIT;
3376 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3377 ASSERT_VK_SUCCESS(err);
3378
3379 // Cause error due to mis-matched sample count between rp & fb
3380 fb_info.renderPass = rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003381 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has VK_SAMPLE_COUNT_1_BIT samples "
3382 "that do not match the "
3383 "VK_SAMPLE_COUNT_4_BIT ");
Tobin Ehlis77d717c2016-06-22 14:19:19 -06003384 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3385
3386 m_errorMonitor->VerifyFound();
3387 if (err == VK_SUCCESS) {
3388 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3389 }
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003390
3391 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003392
3393 // Create a custom imageView with non-1 mip levels
3394 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003395 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 -06003396 ASSERT_TRUE(image.initialized());
3397
3398 VkImageView view;
3399 VkImageViewCreateInfo ivci = {};
3400 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
3401 ivci.image = image.handle();
3402 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
3403 ivci.format = VK_FORMAT_B8G8R8A8_UNORM;
3404 ivci.subresourceRange.layerCount = 1;
3405 ivci.subresourceRange.baseMipLevel = 0;
3406 // Set level count 2 (only 1 is allowed for FB attachment)
3407 ivci.subresourceRange.levelCount = 2;
3408 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3409 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
3410 ASSERT_VK_SUCCESS(err);
3411 // Re-create renderpass to have matching sample count
3412 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
3413 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3414 ASSERT_VK_SUCCESS(err);
3415
3416 fb_info.renderPass = rp;
3417 fb_info.pAttachments = &view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003418 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has mip levelCount of 2 but only ");
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003419 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3420
3421 m_errorMonitor->VerifyFound();
3422 if (err == VK_SUCCESS) {
3423 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3424 }
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003425 vkDestroyImageView(m_device->device(), view, NULL);
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06003426 // Update view to original color buffer and grow FB dimensions too big
3427 fb_info.pAttachments = ivs;
3428 fb_info.height = 1024;
3429 fb_info.width = 1024;
3430 fb_info.layers = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003431 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " Attachment dimensions must be at "
3432 "least as large. ");
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06003433 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3434
3435 m_errorMonitor->VerifyFound();
3436 if (err == VK_SUCCESS) {
3437 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3438 }
Tobin Ehlisb1f303b2016-06-23 08:19:55 -06003439 // Create view attachment with non-identity swizzle
3440 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
3441 ivci.image = image.handle();
3442 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
3443 ivci.format = VK_FORMAT_B8G8R8A8_UNORM;
3444 ivci.subresourceRange.layerCount = 1;
3445 ivci.subresourceRange.baseMipLevel = 0;
3446 ivci.subresourceRange.levelCount = 1;
3447 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3448 ivci.components.r = VK_COMPONENT_SWIZZLE_G;
3449 ivci.components.g = VK_COMPONENT_SWIZZLE_R;
3450 ivci.components.b = VK_COMPONENT_SWIZZLE_A;
3451 ivci.components.a = VK_COMPONENT_SWIZZLE_B;
3452 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
3453 ASSERT_VK_SUCCESS(err);
3454
3455 fb_info.pAttachments = &view;
3456 fb_info.height = 100;
3457 fb_info.width = 100;
3458 fb_info.layers = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003459 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has non-identy swizzle. All "
3460 "framebuffer attachments must have "
3461 "been created with the identity "
3462 "swizzle. ");
Tobin Ehlisb1f303b2016-06-23 08:19:55 -06003463 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3464
3465 m_errorMonitor->VerifyFound();
3466 if (err == VK_SUCCESS) {
3467 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3468 }
3469 vkDestroyImageView(m_device->device(), view, NULL);
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06003470 // Request fb that exceeds max dimensions
3471 // reset attachment to color attachment
3472 fb_info.pAttachments = ivs;
3473 fb_info.width = m_device->props.limits.maxFramebufferWidth + 1;
3474 fb_info.height = m_device->props.limits.maxFramebufferHeight + 1;
3475 fb_info.layers = m_device->props.limits.maxFramebufferLayers + 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003476 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " Requested VkFramebufferCreateInfo "
3477 "dimensions exceed physical device "
3478 "limits. ");
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06003479 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3480
3481 m_errorMonitor->VerifyFound();
3482 if (err == VK_SUCCESS) {
3483 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3484 }
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06003485
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003486 vkDestroyRenderPass(m_device->device(), rp, NULL);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003487}
3488
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003489TEST_F(VkLayerTest, DynamicDepthBiasNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003490 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Depth Bias dynamic "
3491 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003492
Cody Northropc31a84f2016-08-22 10:41:47 -06003493 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003494 // Dynamic depth bias
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003495 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic depth bias state not set for this command buffer");
3496 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthBias);
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003497 m_errorMonitor->VerifyFound();
3498}
3499
3500TEST_F(VkLayerTest, DynamicLineWidthNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003501 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Line Width dynamic "
3502 "state is required but not correctly bound.");
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003503
Cody Northropc31a84f2016-08-22 10:41:47 -06003504 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003505 // Dynamic line width
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003506 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic line width state not set for this command buffer");
3507 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailLineWidth);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003508 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003509}
3510
3511TEST_F(VkLayerTest, DynamicViewportNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003512 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Viewport dynamic "
3513 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003514
Cody Northropc31a84f2016-08-22 10:41:47 -06003515 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003516 // Dynamic viewport state
Mike Weiblen95dd0f92016-10-19 12:28:27 -06003517 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 -06003518 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailViewport);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003519 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003520}
3521
3522TEST_F(VkLayerTest, DynamicScissorNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003523 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Scissor dynamic "
3524 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003525
Cody Northropc31a84f2016-08-22 10:41:47 -06003526 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003527 // Dynamic scissor state
Mike Weiblen95dd0f92016-10-19 12:28:27 -06003528 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 -06003529 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailScissor);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003530 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003531}
3532
Cortd713fe82016-07-27 09:51:27 -07003533TEST_F(VkLayerTest, DynamicBlendConstantsNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003534 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Blend Constants "
3535 "dynamic state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003536
3537 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis21c88352016-05-26 06:15:45 -06003538 // Dynamic blend constant state
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003539 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3540 "Dynamic blend constants state not set for this command buffer");
3541 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailBlend);
Tobin Ehlis21c88352016-05-26 06:15:45 -06003542 m_errorMonitor->VerifyFound();
3543}
3544
3545TEST_F(VkLayerTest, DynamicDepthBoundsNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003546 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Depth Bounds dynamic "
3547 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003548
3549 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis21c88352016-05-26 06:15:45 -06003550 if (!m_device->phy().features().depthBounds) {
3551 printf("Device does not support depthBounds test; skipped.\n");
3552 return;
3553 }
3554 // Dynamic depth bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003555 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3556 "Dynamic depth bounds state not set for this command buffer");
3557 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthBounds);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003558 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003559}
3560
3561TEST_F(VkLayerTest, DynamicStencilReadNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003562 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Stencil Read dynamic "
3563 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003564
3565 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003566 // Dynamic stencil read mask
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003567 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3568 "Dynamic stencil read mask state not set for this command buffer");
3569 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilReadMask);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003570 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003571}
3572
3573TEST_F(VkLayerTest, DynamicStencilWriteNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003574 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Stencil Write dynamic"
3575 " state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003576
3577 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003578 // Dynamic stencil write mask
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003579 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3580 "Dynamic stencil write mask state not set for this command buffer");
3581 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilWriteMask);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003582 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003583}
3584
3585TEST_F(VkLayerTest, DynamicStencilRefNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003586 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Stencil Ref dynamic "
3587 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003588
3589 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003590 // Dynamic stencil reference
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003591 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3592 "Dynamic stencil reference state not set for this command buffer");
3593 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilReference);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003594 m_errorMonitor->VerifyFound();
Tobin Ehlis963a4042015-09-29 08:18:34 -06003595}
3596
Tobin Ehlis379ba3b2016-07-19 11:22:29 -06003597TEST_F(VkLayerTest, IndexBufferNotBound) {
3598 TEST_DESCRIPTION("Run an indexed draw call without an index buffer bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003599
3600 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003601 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3602 "Index buffer object not bound to this command buffer when Indexed ");
3603 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailIndexBuffer);
Tobin Ehlis379ba3b2016-07-19 11:22:29 -06003604 m_errorMonitor->VerifyFound();
3605}
3606
Karl Schultz6addd812016-02-02 17:17:23 -07003607TEST_F(VkLayerTest, CommandBufferTwoSubmits) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003608 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3609 "was begun w/ VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set, but has "
3610 "been submitted");
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003611
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003612 ASSERT_NO_FATAL_FAILURE(InitState());
3613 ASSERT_NO_FATAL_FAILURE(InitViewport());
3614 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3615
Karl Schultz6addd812016-02-02 17:17:23 -07003616 // We luck out b/c by default the framework creates CB w/ the
3617 // VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003618 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003619 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003620 EndCommandBuffer();
3621
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003622 // Bypass framework since it does the waits automatically
3623 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06003624 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08003625 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3626 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003627 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06003628 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07003629 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003630 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003631 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08003632 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06003633 submit_info.pSignalSemaphores = NULL;
3634
Chris Forbes40028e22016-06-13 09:59:34 +12003635 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Karl Schultz6addd812016-02-02 17:17:23 -07003636 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski89cad1a2016-11-11 15:51:31 -07003637 vkQueueWaitIdle(m_device->m_queue);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003638
Karl Schultz6addd812016-02-02 17:17:23 -07003639 // Cause validation error by re-submitting cmd buffer that should only be
3640 // submitted once
Chris Forbes40028e22016-06-13 09:59:34 +12003641 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Lobodzinski89cad1a2016-11-11 15:51:31 -07003642 vkQueueWaitIdle(m_device->m_queue);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003643
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003644 m_errorMonitor->VerifyFound();
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003645}
3646
Karl Schultz6addd812016-02-02 17:17:23 -07003647TEST_F(VkLayerTest, AllocDescriptorFromEmptyPool) {
Tobin Ehlis14cd5852016-11-23 12:52:48 -07003648 TEST_DESCRIPTION("Attempt to allocate more sets and descriptors than descriptor pool has available.");
Karl Schultz6addd812016-02-02 17:17:23 -07003649 VkResult err;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003650
3651 ASSERT_NO_FATAL_FAILURE(InitState());
3652 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003653
Karl Schultz6addd812016-02-02 17:17:23 -07003654 // Create Pool w/ 1 Sampler descriptor, but try to alloc Uniform Buffer
3655 // descriptor from it
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003656 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003657 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
Tobin Ehlis14cd5852016-11-23 12:52:48 -07003658 ds_type_count.descriptorCount = 2;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003659
3660 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003661 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3662 ds_pool_ci.pNext = NULL;
3663 ds_pool_ci.flags = 0;
3664 ds_pool_ci.maxSets = 1;
3665 ds_pool_ci.poolSizeCount = 1;
3666 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003667
3668 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003669 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003670 ASSERT_VK_SUCCESS(err);
3671
Tobin Ehlis14cd5852016-11-23 12:52:48 -07003672 VkDescriptorSetLayoutBinding dsl_binding_samp = {};
3673 dsl_binding_samp.binding = 0;
3674 dsl_binding_samp.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
3675 dsl_binding_samp.descriptorCount = 1;
3676 dsl_binding_samp.stageFlags = VK_SHADER_STAGE_ALL;
3677 dsl_binding_samp.pImmutableSamplers = NULL;
3678
3679 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3680 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3681 ds_layout_ci.pNext = NULL;
3682 ds_layout_ci.bindingCount = 1;
3683 ds_layout_ci.pBindings = &dsl_binding_samp;
3684
3685 VkDescriptorSetLayout ds_layout_samp;
3686 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout_samp);
3687 ASSERT_VK_SUCCESS(err);
3688
3689 // Try to allocate 2 sets when pool only has 1 set
3690 VkDescriptorSet descriptor_sets[2];
3691 VkDescriptorSetLayout set_layouts[2] = {ds_layout_samp, ds_layout_samp};
3692 VkDescriptorSetAllocateInfo alloc_info = {};
3693 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
3694 alloc_info.descriptorSetCount = 2;
3695 alloc_info.descriptorPool = ds_pool;
3696 alloc_info.pSetLayouts = set_layouts;
3697 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00911);
3698 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptor_sets);
3699 m_errorMonitor->VerifyFound();
3700
3701 alloc_info.descriptorSetCount = 1;
3702 // Create layout w/ descriptor type not available in pool
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003703 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003704 dsl_binding.binding = 0;
3705 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3706 dsl_binding.descriptorCount = 1;
3707 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3708 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003709
Karl Schultz6addd812016-02-02 17:17:23 -07003710 ds_layout_ci.bindingCount = 1;
3711 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003712
Tobin Ehlis14cd5852016-11-23 12:52:48 -07003713 VkDescriptorSetLayout ds_layout_ub;
3714 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout_ub);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003715 ASSERT_VK_SUCCESS(err);
3716
Tobin Ehlis14cd5852016-11-23 12:52:48 -07003717 VkDescriptorSet descriptor_set;
Jon Ashburnf19916e2016-01-11 13:12:43 -07003718 alloc_info.descriptorSetCount = 1;
Tobin Ehlis14cd5852016-11-23 12:52:48 -07003719 alloc_info.pSetLayouts = &ds_layout_ub;
3720 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00912);
3721 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003722
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003723 m_errorMonitor->VerifyFound();
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003724
Karl Schultz2825ab92016-12-02 08:23:14 -07003725 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_samp, NULL);
Tobin Ehlis14cd5852016-11-23 12:52:48 -07003726 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_ub, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +08003727 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003728}
3729
Karl Schultz6addd812016-02-02 17:17:23 -07003730TEST_F(VkLayerTest, FreeDescriptorFromOneShotPool) {
3731 VkResult err;
Tobin Ehlise735c692015-10-08 13:13:50 -06003732
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003733 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3734 "It is invalid to call vkFreeDescriptorSets() with a pool created "
3735 "without setting VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003736
Tobin Ehlise735c692015-10-08 13:13:50 -06003737 ASSERT_NO_FATAL_FAILURE(InitState());
3738 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise735c692015-10-08 13:13:50 -06003739
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003740 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003741 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3742 ds_type_count.descriptorCount = 1;
Tobin Ehlise735c692015-10-08 13:13:50 -06003743
3744 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003745 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3746 ds_pool_ci.pNext = NULL;
3747 ds_pool_ci.maxSets = 1;
3748 ds_pool_ci.poolSizeCount = 1;
3749 ds_pool_ci.flags = 0;
3750 // Not specifying VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT means
3751 // app can only call vkResetDescriptorPool on this pool.;
3752 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise735c692015-10-08 13:13:50 -06003753
3754 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003755 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise735c692015-10-08 13:13:50 -06003756 ASSERT_VK_SUCCESS(err);
3757
3758 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003759 dsl_binding.binding = 0;
3760 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3761 dsl_binding.descriptorCount = 1;
3762 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3763 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlise735c692015-10-08 13:13:50 -06003764
3765 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003766 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3767 ds_layout_ci.pNext = NULL;
3768 ds_layout_ci.bindingCount = 1;
3769 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise735c692015-10-08 13:13:50 -06003770
3771 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003772 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise735c692015-10-08 13:13:50 -06003773 ASSERT_VK_SUCCESS(err);
3774
3775 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003776 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08003777 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07003778 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06003779 alloc_info.descriptorPool = ds_pool;
3780 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003781 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise735c692015-10-08 13:13:50 -06003782 ASSERT_VK_SUCCESS(err);
3783
3784 err = vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003785 m_errorMonitor->VerifyFound();
Tobin Ehlise735c692015-10-08 13:13:50 -06003786
Chia-I Wuf7458c52015-10-26 21:10:41 +08003787 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3788 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise735c692015-10-08 13:13:50 -06003789}
3790
Karl Schultz6addd812016-02-02 17:17:23 -07003791TEST_F(VkLayerTest, InvalidDescriptorPool) {
Karl Schultzbdb75952016-04-19 11:36:49 -06003792 // Attempt to clear Descriptor Pool with bad object.
3793 // ObjectTracker should catch this.
Cody Northropc31a84f2016-08-22 10:41:47 -06003794
3795 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultzf78bcdd2016-11-30 12:36:01 -07003796 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00930);
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06003797 uint64_t fake_pool_handle = 0xbaad6001;
3798 VkDescriptorPool bad_pool = reinterpret_cast<VkDescriptorPool &>(fake_pool_handle);
3799 vkResetDescriptorPool(device(), bad_pool, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -06003800 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003801}
3802
Karl Schultzf78bcdd2016-11-30 12:36:01 -07003803TEST_F(VkLayerTest, InvalidDescriptorSet) {
Karl Schultzbdb75952016-04-19 11:36:49 -06003804 // Attempt to bind an invalid Descriptor Set to a valid Command Buffer
3805 // ObjectTracker should catch this.
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003806 // Create a valid cmd buffer
Karl Schultzbdb75952016-04-19 11:36:49 -06003807 // call vkCmdBindDescriptorSets w/ false Descriptor Set
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06003808
3809 uint64_t fake_set_handle = 0xbaad6001;
3810 VkDescriptorSet bad_set = reinterpret_cast<VkDescriptorSet &>(fake_set_handle);
Karl Schultzbdb75952016-04-19 11:36:49 -06003811 VkResult err;
Karl Schultzf78bcdd2016-11-30 12:36:01 -07003812 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00982);
Karl Schultzbdb75952016-04-19 11:36:49 -06003813
3814 ASSERT_NO_FATAL_FAILURE(InitState());
3815
3816 VkDescriptorSetLayoutBinding layout_bindings[1] = {};
3817 layout_bindings[0].binding = 0;
3818 layout_bindings[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3819 layout_bindings[0].descriptorCount = 1;
3820 layout_bindings[0].stageFlags = VK_SHADER_STAGE_VERTEX_BIT;
3821 layout_bindings[0].pImmutableSamplers = NULL;
3822
3823 VkDescriptorSetLayout descriptor_set_layout;
3824 VkDescriptorSetLayoutCreateInfo dslci = {};
3825 dslci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3826 dslci.pNext = NULL;
3827 dslci.bindingCount = 1;
3828 dslci.pBindings = layout_bindings;
3829 err = vkCreateDescriptorSetLayout(device(), &dslci, NULL, &descriptor_set_layout);
Karl Schultz5cb21112016-04-21 17:17:40 -06003830 ASSERT_VK_SUCCESS(err);
Karl Schultzbdb75952016-04-19 11:36:49 -06003831
3832 VkPipelineLayout pipeline_layout;
3833 VkPipelineLayoutCreateInfo plci = {};
3834 plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
3835 plci.pNext = NULL;
3836 plci.setLayoutCount = 1;
3837 plci.pSetLayouts = &descriptor_set_layout;
3838 err = vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout);
Karl Schultz5cb21112016-04-21 17:17:40 -06003839 ASSERT_VK_SUCCESS(err);
Karl Schultzbdb75952016-04-19 11:36:49 -06003840
3841 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003842 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1, &bad_set, 0,
3843 NULL);
Karl Schultzbdb75952016-04-19 11:36:49 -06003844 m_errorMonitor->VerifyFound();
3845 EndCommandBuffer();
3846 vkDestroyPipelineLayout(device(), pipeline_layout, NULL);
3847 vkDestroyDescriptorSetLayout(device(), descriptor_set_layout, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003848}
3849
Karl Schultz6addd812016-02-02 17:17:23 -07003850TEST_F(VkLayerTest, InvalidDescriptorSetLayout) {
Karl Schultzbdb75952016-04-19 11:36:49 -06003851 // Attempt to create a Pipeline Layout with an invalid Descriptor Set Layout.
3852 // ObjectTracker should catch this.
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06003853 uint64_t fake_layout_handle = 0xbaad6001;
3854 VkDescriptorSetLayout bad_layout = reinterpret_cast<VkDescriptorSetLayout &>(fake_layout_handle);
Karl Schultzf78bcdd2016-11-30 12:36:01 -07003855 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00875);
Cody Northropc31a84f2016-08-22 10:41:47 -06003856 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultzbdb75952016-04-19 11:36:49 -06003857 VkPipelineLayout pipeline_layout;
3858 VkPipelineLayoutCreateInfo plci = {};
3859 plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
3860 plci.pNext = NULL;
3861 plci.setLayoutCount = 1;
3862 plci.pSetLayouts = &bad_layout;
3863 vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout);
3864
3865 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003866}
3867
Mark Muellerd4914412016-06-13 17:52:06 -06003868TEST_F(VkLayerTest, WriteDescriptorSetIntegrityCheck) {
3869 TEST_DESCRIPTION("This test verifies some requirements of chapter 13.2.3 of the Vulkan Spec "
3870 "1) A uniform buffer update must have a valid buffer index."
3871 "2) When using an array of descriptors in a single WriteDescriptor,"
3872 " the descriptor types and stageflags must all be the same."
3873 "3) Immutable Sampler state must match across descriptors");
3874
3875 const char *invalid_BufferInfo_ErrorMessage =
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003876 "vkUpdateDescriptorSets: if pDescriptorWrites[0].descriptorType is VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, "
3877 "VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC or "
3878 "VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC, pDescriptorWrites[0].pBufferInfo must not be NULL";
3879 const char *stateFlag_ErrorMessage = "Attempting write update to descriptor set ";
3880 const char *immutable_ErrorMessage = "Attempting write update to descriptor set ";
Mark Muellerd4914412016-06-13 17:52:06 -06003881
Mark Muellerd4914412016-06-13 17:52:06 -06003882 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_BufferInfo_ErrorMessage);
3883
3884 ASSERT_NO_FATAL_FAILURE(InitState());
3885 VkDescriptorPoolSize ds_type_count[4] = {};
3886 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3887 ds_type_count[0].descriptorCount = 1;
Tony Barboure132c5f2016-12-12 11:50:20 -07003888 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLER;
Mark Muellerd4914412016-06-13 17:52:06 -06003889 ds_type_count[1].descriptorCount = 1;
Tony Barboure132c5f2016-12-12 11:50:20 -07003890 ds_type_count[2].type = VK_DESCRIPTOR_TYPE_SAMPLER;
Mark Muellerd4914412016-06-13 17:52:06 -06003891 ds_type_count[2].descriptorCount = 1;
3892 ds_type_count[3].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
3893 ds_type_count[3].descriptorCount = 1;
3894
3895 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3896 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3897 ds_pool_ci.maxSets = 1;
3898 ds_pool_ci.poolSizeCount = sizeof(ds_type_count) / sizeof(VkDescriptorPoolSize);
3899 ds_pool_ci.pPoolSizes = ds_type_count;
3900
3901 VkDescriptorPool ds_pool;
3902 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
3903 ASSERT_VK_SUCCESS(err);
3904
Mark Muellerb9896722016-06-16 09:54:29 -06003905 VkDescriptorSetLayoutBinding layout_binding[3] = {};
Mark Muellerd4914412016-06-13 17:52:06 -06003906 layout_binding[0].binding = 0;
3907 layout_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3908 layout_binding[0].descriptorCount = 1;
3909 layout_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
3910 layout_binding[0].pImmutableSamplers = NULL;
3911
3912 layout_binding[1].binding = 1;
3913 layout_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
3914 layout_binding[1].descriptorCount = 1;
3915 layout_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
3916 layout_binding[1].pImmutableSamplers = NULL;
3917
3918 VkSamplerCreateInfo sampler_ci = {};
3919 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
3920 sampler_ci.pNext = NULL;
3921 sampler_ci.magFilter = VK_FILTER_NEAREST;
3922 sampler_ci.minFilter = VK_FILTER_NEAREST;
3923 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
3924 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3925 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3926 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3927 sampler_ci.mipLodBias = 1.0;
3928 sampler_ci.anisotropyEnable = VK_FALSE;
3929 sampler_ci.maxAnisotropy = 1;
3930 sampler_ci.compareEnable = VK_FALSE;
3931 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
3932 sampler_ci.minLod = 1.0;
3933 sampler_ci.maxLod = 1.0;
3934 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
3935 sampler_ci.unnormalizedCoordinates = VK_FALSE;
3936 VkSampler sampler;
3937
3938 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
3939 ASSERT_VK_SUCCESS(err);
3940
3941 layout_binding[2].binding = 2;
3942 layout_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
3943 layout_binding[2].descriptorCount = 1;
3944 layout_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
3945 layout_binding[2].pImmutableSamplers = static_cast<VkSampler *>(&sampler);
3946
Mark Muellerd4914412016-06-13 17:52:06 -06003947 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3948 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3949 ds_layout_ci.bindingCount = sizeof(layout_binding) / sizeof(VkDescriptorSetLayoutBinding);
3950 ds_layout_ci.pBindings = layout_binding;
3951 VkDescriptorSetLayout ds_layout;
3952 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
3953 ASSERT_VK_SUCCESS(err);
3954
3955 VkDescriptorSetAllocateInfo alloc_info = {};
3956 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
3957 alloc_info.descriptorSetCount = 1;
3958 alloc_info.descriptorPool = ds_pool;
3959 alloc_info.pSetLayouts = &ds_layout;
3960 VkDescriptorSet descriptorSet;
3961 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
3962 ASSERT_VK_SUCCESS(err);
3963
3964 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
3965 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
3966 pipeline_layout_ci.pNext = NULL;
3967 pipeline_layout_ci.setLayoutCount = 1;
3968 pipeline_layout_ci.pSetLayouts = &ds_layout;
3969
3970 VkPipelineLayout pipeline_layout;
3971 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
3972 ASSERT_VK_SUCCESS(err);
3973
Mark Mueller5c838ce2016-06-16 09:54:29 -06003974 VkWriteDescriptorSet descriptor_write = {};
Mark Muellerd4914412016-06-13 17:52:06 -06003975 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
3976 descriptor_write.dstSet = descriptorSet;
3977 descriptor_write.dstBinding = 0;
3978 descriptor_write.descriptorCount = 1;
3979 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3980
Mark Mueller5c838ce2016-06-16 09:54:29 -06003981 // 1) The uniform buffer is intentionally invalid here
Mark Muellerd4914412016-06-13 17:52:06 -06003982 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
3983 m_errorMonitor->VerifyFound();
3984
3985 // Create a buffer to update the descriptor with
3986 uint32_t qfi = 0;
3987 VkBufferCreateInfo buffCI = {};
3988 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
3989 buffCI.size = 1024;
3990 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
3991 buffCI.queueFamilyIndexCount = 1;
3992 buffCI.pQueueFamilyIndices = &qfi;
3993
3994 VkBuffer dyub;
3995 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
3996 ASSERT_VK_SUCCESS(err);
Mark Muellerd4914412016-06-13 17:52:06 -06003997
Tony Barboure132c5f2016-12-12 11:50:20 -07003998 VkDeviceMemory mem;
3999 VkMemoryRequirements mem_reqs;
4000 vkGetBufferMemoryRequirements(m_device->device(), dyub, &mem_reqs);
4001
4002 VkMemoryAllocateInfo mem_alloc_info = {};
4003 mem_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4004 mem_alloc_info.allocationSize = mem_reqs.size;
4005 m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
4006 err = vkAllocateMemory(m_device->device(), &mem_alloc_info, NULL, &mem);
4007 ASSERT_VK_SUCCESS(err);
4008
4009 err = vkBindBufferMemory(m_device->device(), dyub, mem, 0);
4010 ASSERT_VK_SUCCESS(err);
4011
4012 VkDescriptorBufferInfo buffInfo[2] = {};
4013 buffInfo[0].buffer = dyub;
4014 buffInfo[0].offset = 0;
4015 buffInfo[0].range = 1024;
4016 buffInfo[1].buffer = dyub;
4017 buffInfo[1].offset = 0;
4018 buffInfo[1].range = 1024;
4019 descriptor_write.pBufferInfo = buffInfo;
Mark Muellerd4914412016-06-13 17:52:06 -06004020 descriptor_write.descriptorCount = 2;
4021
Mark Mueller5c838ce2016-06-16 09:54:29 -06004022 // 2) The stateFlags don't match between the first and second descriptor
Mark Muellerd4914412016-06-13 17:52:06 -06004023 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, stateFlag_ErrorMessage);
4024 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4025 m_errorMonitor->VerifyFound();
4026
Mark Mueller5c838ce2016-06-16 09:54:29 -06004027 // 3) The second descriptor has a null_ptr pImmutableSamplers and
4028 // the third descriptor contains an immutable sampler
Mark Muellerd4914412016-06-13 17:52:06 -06004029 descriptor_write.dstBinding = 1;
4030 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Mark Mueller5c838ce2016-06-16 09:54:29 -06004031
Mark Mueller5c838ce2016-06-16 09:54:29 -06004032 // Make pImageInfo index non-null to avoid complaints of it missing
4033 VkDescriptorImageInfo imageInfo = {};
4034 imageInfo.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
4035 descriptor_write.pImageInfo = &imageInfo;
Mark Muellerd4914412016-06-13 17:52:06 -06004036 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, immutable_ErrorMessage);
4037 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4038 m_errorMonitor->VerifyFound();
4039
Mark Muellerd4914412016-06-13 17:52:06 -06004040 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tony Barboure132c5f2016-12-12 11:50:20 -07004041 vkFreeMemory(m_device->device(), mem, NULL);
Mark Muellerd4914412016-06-13 17:52:06 -06004042 vkDestroySampler(m_device->device(), sampler, NULL);
4043 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4044 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4045 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
4046}
4047
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004048TEST_F(VkLayerTest, InvalidCmdBufferBufferDestroyed) {
4049 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4050 "due to a buffer dependency being destroyed.");
4051 ASSERT_NO_FATAL_FAILURE(InitState());
4052
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004053 VkBuffer buffer;
4054 VkDeviceMemory mem;
4055 VkMemoryRequirements mem_reqs;
4056
4057 VkBufferCreateInfo buf_info = {};
4058 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes3d5882f2016-09-16 17:37:17 +12004059 buf_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004060 buf_info.size = 256;
4061 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
4062 VkResult err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
4063 ASSERT_VK_SUCCESS(err);
4064
4065 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
4066
4067 VkMemoryAllocateInfo alloc_info = {};
4068 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4069 alloc_info.allocationSize = 256;
4070 bool pass = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004071 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 -06004072 if (!pass) {
4073 vkDestroyBuffer(m_device->device(), buffer, NULL);
4074 return;
4075 }
4076 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
4077 ASSERT_VK_SUCCESS(err);
4078
4079 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
4080 ASSERT_VK_SUCCESS(err);
4081
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004082 m_commandBuffer->BeginCommandBuffer();
Chris Forbes3d5882f2016-09-16 17:37:17 +12004083 vkCmdFillBuffer(m_commandBuffer->GetBufferHandle(), buffer, 0, VK_WHOLE_SIZE, 0);
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004084 m_commandBuffer->EndCommandBuffer();
4085
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004086 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound buffer ");
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004087 // Destroy buffer dependency prior to submit to cause ERROR
4088 vkDestroyBuffer(m_device->device(), buffer, NULL);
4089
4090 VkSubmitInfo submit_info = {};
4091 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4092 submit_info.commandBufferCount = 1;
4093 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4094 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4095
4096 m_errorMonitor->VerifyFound();
4097 vkFreeMemory(m_device->handle(), mem, NULL);
4098}
4099
Tobin Ehlisea413442016-09-28 10:23:59 -06004100TEST_F(VkLayerTest, InvalidCmdBufferBufferViewDestroyed) {
4101 TEST_DESCRIPTION("Delete bufferView bound to cmd buffer, then attempt to submit cmd buffer.");
4102
4103 ASSERT_NO_FATAL_FAILURE(InitState());
4104 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4105
4106 VkDescriptorPoolSize ds_type_count;
4107 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
4108 ds_type_count.descriptorCount = 1;
4109
4110 VkDescriptorPoolCreateInfo ds_pool_ci = {};
4111 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4112 ds_pool_ci.maxSets = 1;
4113 ds_pool_ci.poolSizeCount = 1;
4114 ds_pool_ci.pPoolSizes = &ds_type_count;
4115
4116 VkDescriptorPool ds_pool;
4117 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
4118 ASSERT_VK_SUCCESS(err);
4119
4120 VkDescriptorSetLayoutBinding layout_binding;
4121 layout_binding.binding = 0;
4122 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
4123 layout_binding.descriptorCount = 1;
4124 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
4125 layout_binding.pImmutableSamplers = NULL;
4126
4127 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
4128 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4129 ds_layout_ci.bindingCount = 1;
4130 ds_layout_ci.pBindings = &layout_binding;
4131 VkDescriptorSetLayout ds_layout;
4132 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
4133 ASSERT_VK_SUCCESS(err);
4134
4135 VkDescriptorSetAllocateInfo alloc_info = {};
4136 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
4137 alloc_info.descriptorSetCount = 1;
4138 alloc_info.descriptorPool = ds_pool;
4139 alloc_info.pSetLayouts = &ds_layout;
4140 VkDescriptorSet descriptor_set;
4141 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
4142 ASSERT_VK_SUCCESS(err);
4143
4144 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4145 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4146 pipeline_layout_ci.pNext = NULL;
4147 pipeline_layout_ci.setLayoutCount = 1;
4148 pipeline_layout_ci.pSetLayouts = &ds_layout;
4149
4150 VkPipelineLayout pipeline_layout;
4151 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
4152 ASSERT_VK_SUCCESS(err);
4153
4154 VkBuffer buffer;
4155 uint32_t queue_family_index = 0;
4156 VkBufferCreateInfo buffer_create_info = {};
4157 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
4158 buffer_create_info.size = 1024;
4159 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
4160 buffer_create_info.queueFamilyIndexCount = 1;
4161 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
4162
4163 err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
4164 ASSERT_VK_SUCCESS(err);
4165
4166 VkMemoryRequirements memory_reqs;
4167 VkDeviceMemory buffer_memory;
4168
4169 VkMemoryAllocateInfo memory_info = {};
4170 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4171 memory_info.allocationSize = 0;
4172 memory_info.memoryTypeIndex = 0;
4173
4174 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
4175 memory_info.allocationSize = memory_reqs.size;
4176 bool pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
4177 ASSERT_TRUE(pass);
4178
4179 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
4180 ASSERT_VK_SUCCESS(err);
4181 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
4182 ASSERT_VK_SUCCESS(err);
4183
4184 VkBufferView view;
4185 VkBufferViewCreateInfo bvci = {};
4186 bvci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
4187 bvci.buffer = buffer;
4188 bvci.format = VK_FORMAT_R8_UNORM;
4189 bvci.range = VK_WHOLE_SIZE;
4190
4191 err = vkCreateBufferView(m_device->device(), &bvci, NULL, &view);
4192 ASSERT_VK_SUCCESS(err);
4193
4194 VkWriteDescriptorSet descriptor_write = {};
4195 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
4196 descriptor_write.dstSet = descriptor_set;
4197 descriptor_write.dstBinding = 0;
4198 descriptor_write.descriptorCount = 1;
4199 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
4200 descriptor_write.pTexelBufferView = &view;
4201
4202 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4203
4204 char const *vsSource = "#version 450\n"
4205 "\n"
4206 "out gl_PerVertex { \n"
4207 " vec4 gl_Position;\n"
4208 "};\n"
4209 "void main(){\n"
4210 " gl_Position = vec4(1);\n"
4211 "}\n";
4212 char const *fsSource = "#version 450\n"
4213 "\n"
4214 "layout(set=0, binding=0, r8) uniform imageBuffer s;\n"
4215 "layout(location=0) out vec4 x;\n"
4216 "void main(){\n"
4217 " x = imageLoad(s, 0);\n"
4218 "}\n";
4219 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4220 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
4221 VkPipelineObj pipe(m_device);
4222 pipe.AddShader(&vs);
4223 pipe.AddShader(&fs);
4224 pipe.AddColorAttachment();
4225 pipe.CreateVKPipeline(pipeline_layout, renderPass());
4226
4227 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot submit cmd buffer using deleted buffer view ");
4228 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound buffer view ");
4229
4230 BeginCommandBuffer();
4231 VkViewport viewport = {0, 0, 16, 16, 0, 1};
4232 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
4233 VkRect2D scissor = {{0, 0}, {16, 16}};
4234 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
4235 // Bind pipeline to cmd buffer
4236 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
4237 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
4238 &descriptor_set, 0, nullptr);
4239 Draw(1, 0, 0, 0);
4240 EndCommandBuffer();
4241
4242 // Delete BufferView in order to invalidate cmd buffer
4243 vkDestroyBufferView(m_device->device(), view, NULL);
4244 // Now attempt submit of cmd buffer
4245 VkSubmitInfo submit_info = {};
4246 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4247 submit_info.commandBufferCount = 1;
4248 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4249 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4250 m_errorMonitor->VerifyFound();
4251
4252 // Clean-up
4253 vkDestroyBuffer(m_device->device(), buffer, NULL);
4254 vkFreeMemory(m_device->device(), buffer_memory, NULL);
4255 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4256 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4257 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
4258}
4259
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004260TEST_F(VkLayerTest, InvalidCmdBufferImageDestroyed) {
4261 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4262 "due to an image dependency being destroyed.");
4263 ASSERT_NO_FATAL_FAILURE(InitState());
4264
4265 VkImage image;
4266 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
4267 VkImageCreateInfo image_create_info = {};
4268 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4269 image_create_info.pNext = NULL;
4270 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4271 image_create_info.format = tex_format;
4272 image_create_info.extent.width = 32;
4273 image_create_info.extent.height = 32;
4274 image_create_info.extent.depth = 1;
4275 image_create_info.mipLevels = 1;
4276 image_create_info.arrayLayers = 1;
4277 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
4278 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004279 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004280 image_create_info.flags = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004281 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004282 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004283 // Have to bind memory to image before recording cmd in cmd buffer using it
4284 VkMemoryRequirements mem_reqs;
4285 VkDeviceMemory image_mem;
4286 bool pass;
4287 VkMemoryAllocateInfo mem_alloc = {};
4288 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4289 mem_alloc.pNext = NULL;
4290 mem_alloc.memoryTypeIndex = 0;
4291 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
4292 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004293 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004294 ASSERT_TRUE(pass);
4295 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
4296 ASSERT_VK_SUCCESS(err);
4297 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
4298 ASSERT_VK_SUCCESS(err);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004299
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004300 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlis764d7072016-07-01 12:54:29 -06004301 VkClearColorValue ccv;
4302 ccv.float32[0] = 1.0f;
4303 ccv.float32[1] = 1.0f;
4304 ccv.float32[2] = 1.0f;
4305 ccv.float32[3] = 1.0f;
4306 VkImageSubresourceRange isr = {};
4307 isr.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004308 isr.baseArrayLayer = 0;
4309 isr.baseMipLevel = 0;
Tobin Ehlis764d7072016-07-01 12:54:29 -06004310 isr.layerCount = 1;
4311 isr.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004312 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), image, VK_IMAGE_LAYOUT_GENERAL, &ccv, 1, &isr);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004313 m_commandBuffer->EndCommandBuffer();
4314
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004315 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004316 // Destroy image dependency prior to submit to cause ERROR
4317 vkDestroyImage(m_device->device(), image, NULL);
4318
4319 VkSubmitInfo submit_info = {};
4320 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4321 submit_info.commandBufferCount = 1;
4322 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4323 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4324
4325 m_errorMonitor->VerifyFound();
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004326 vkFreeMemory(m_device->device(), image_mem, nullptr);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004327}
4328
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004329TEST_F(VkLayerTest, InvalidCmdBufferFramebufferImageDestroyed) {
4330 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4331 "due to a framebuffer image dependency being destroyed.");
4332 VkFormatProperties format_properties;
4333 VkResult err = VK_SUCCESS;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004334 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
4335 if (!(format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)) {
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004336 return;
4337 }
4338
4339 ASSERT_NO_FATAL_FAILURE(InitState());
4340 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4341
4342 VkImageCreateInfo image_ci = {};
4343 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4344 image_ci.pNext = NULL;
4345 image_ci.imageType = VK_IMAGE_TYPE_2D;
4346 image_ci.format = VK_FORMAT_B8G8R8A8_UNORM;
4347 image_ci.extent.width = 32;
4348 image_ci.extent.height = 32;
4349 image_ci.extent.depth = 1;
4350 image_ci.mipLevels = 1;
4351 image_ci.arrayLayers = 1;
4352 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
4353 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004354 image_ci.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_SAMPLED_BIT;
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004355 image_ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
4356 image_ci.flags = 0;
4357 VkImage image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004358 ASSERT_VK_SUCCESS(vkCreateImage(m_device->handle(), &image_ci, NULL, &image));
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004359
4360 VkMemoryRequirements memory_reqs;
4361 VkDeviceMemory image_memory;
4362 bool pass;
4363 VkMemoryAllocateInfo memory_info = {};
4364 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4365 memory_info.pNext = NULL;
4366 memory_info.allocationSize = 0;
4367 memory_info.memoryTypeIndex = 0;
4368 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
4369 memory_info.allocationSize = memory_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004370 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004371 ASSERT_TRUE(pass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004372 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004373 ASSERT_VK_SUCCESS(err);
4374 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
4375 ASSERT_VK_SUCCESS(err);
4376
4377 VkImageViewCreateInfo ivci = {
4378 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
4379 nullptr,
4380 0,
4381 image,
4382 VK_IMAGE_VIEW_TYPE_2D,
4383 VK_FORMAT_B8G8R8A8_UNORM,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004384 {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A},
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004385 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
4386 };
4387 VkImageView view;
4388 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
4389 ASSERT_VK_SUCCESS(err);
4390
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004391 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 32, 32, 1};
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004392 VkFramebuffer fb;
4393 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
4394 ASSERT_VK_SUCCESS(err);
4395
4396 // Just use default renderpass with our framebuffer
4397 m_renderPassBeginInfo.framebuffer = fb;
4398 // Create Null cmd buffer for submit
4399 BeginCommandBuffer();
4400 EndCommandBuffer();
4401 // Destroy image attached to framebuffer to invalidate cmd buffer
4402 vkDestroyImage(m_device->device(), image, NULL);
4403 // Now attempt to submit cmd buffer and verify error
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004404 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004405 QueueCommandBuffer(false);
4406 m_errorMonitor->VerifyFound();
4407
4408 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
4409 vkDestroyImageView(m_device->device(), view, nullptr);
4410 vkFreeMemory(m_device->device(), image_memory, nullptr);
4411}
4412
Tobin Ehlisb329f992016-10-12 13:20:29 -06004413TEST_F(VkLayerTest, FramebufferInUseDestroyedSignaled) {
4414 TEST_DESCRIPTION("Delete in-use framebuffer.");
4415 VkFormatProperties format_properties;
4416 VkResult err = VK_SUCCESS;
4417 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
4418
4419 ASSERT_NO_FATAL_FAILURE(InitState());
4420 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4421
4422 VkImageObj image(m_device);
4423 image.init(256, 256, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
4424 ASSERT_TRUE(image.initialized());
4425 VkImageView view = image.targetView(VK_FORMAT_B8G8R8A8_UNORM);
4426
4427 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 256, 256, 1};
4428 VkFramebuffer fb;
4429 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
4430 ASSERT_VK_SUCCESS(err);
4431
4432 // Just use default renderpass with our framebuffer
4433 m_renderPassBeginInfo.framebuffer = fb;
4434 // Create Null cmd buffer for submit
4435 BeginCommandBuffer();
4436 EndCommandBuffer();
4437 // Submit cmd buffer to put it in-flight
4438 VkSubmitInfo submit_info = {};
4439 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4440 submit_info.commandBufferCount = 1;
4441 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4442 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4443 // Destroy framebuffer while in-flight
4444 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete framebuffer 0x");
4445 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4446 m_errorMonitor->VerifyFound();
4447 // Wait for queue to complete so we can safely destroy everything
4448 vkQueueWaitIdle(m_device->m_queue);
4449 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
4450}
4451
Tobin Ehlis88becd72016-09-21 14:33:41 -06004452TEST_F(VkLayerTest, FramebufferImageInUseDestroyedSignaled) {
4453 TEST_DESCRIPTION("Delete in-use image that's child of framebuffer.");
4454 VkFormatProperties format_properties;
4455 VkResult err = VK_SUCCESS;
4456 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
Tobin Ehlis88becd72016-09-21 14:33:41 -06004457
4458 ASSERT_NO_FATAL_FAILURE(InitState());
4459 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4460
4461 VkImageCreateInfo image_ci = {};
4462 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4463 image_ci.pNext = NULL;
4464 image_ci.imageType = VK_IMAGE_TYPE_2D;
4465 image_ci.format = VK_FORMAT_B8G8R8A8_UNORM;
4466 image_ci.extent.width = 256;
4467 image_ci.extent.height = 256;
4468 image_ci.extent.depth = 1;
4469 image_ci.mipLevels = 1;
4470 image_ci.arrayLayers = 1;
4471 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
4472 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
Tobin Ehlisc8ca0312016-09-22 07:30:05 -06004473 image_ci.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Tobin Ehlis88becd72016-09-21 14:33:41 -06004474 image_ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
4475 image_ci.flags = 0;
4476 VkImage image;
4477 ASSERT_VK_SUCCESS(vkCreateImage(m_device->handle(), &image_ci, NULL, &image));
4478
4479 VkMemoryRequirements memory_reqs;
4480 VkDeviceMemory image_memory;
4481 bool pass;
4482 VkMemoryAllocateInfo memory_info = {};
4483 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4484 memory_info.pNext = NULL;
4485 memory_info.allocationSize = 0;
4486 memory_info.memoryTypeIndex = 0;
4487 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
4488 memory_info.allocationSize = memory_reqs.size;
4489 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
4490 ASSERT_TRUE(pass);
4491 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
4492 ASSERT_VK_SUCCESS(err);
4493 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
4494 ASSERT_VK_SUCCESS(err);
4495
4496 VkImageViewCreateInfo ivci = {
4497 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
4498 nullptr,
4499 0,
4500 image,
4501 VK_IMAGE_VIEW_TYPE_2D,
4502 VK_FORMAT_B8G8R8A8_UNORM,
4503 {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A},
4504 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
4505 };
4506 VkImageView view;
4507 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
4508 ASSERT_VK_SUCCESS(err);
4509
4510 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 256, 256, 1};
4511 VkFramebuffer fb;
4512 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
4513 ASSERT_VK_SUCCESS(err);
4514
4515 // Just use default renderpass with our framebuffer
4516 m_renderPassBeginInfo.framebuffer = fb;
4517 // Create Null cmd buffer for submit
4518 BeginCommandBuffer();
4519 EndCommandBuffer();
4520 // Submit cmd buffer to put it (and attached imageView) in-flight
4521 VkSubmitInfo submit_info = {};
4522 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4523 submit_info.commandBufferCount = 1;
4524 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4525 // Submit cmd buffer to put framebuffer and children in-flight
4526 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4527 // Destroy image attached to framebuffer while in-flight
4528 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete image 0x");
4529 vkDestroyImage(m_device->device(), image, NULL);
4530 m_errorMonitor->VerifyFound();
4531 // Wait for queue to complete so we can safely destroy image and other objects
4532 vkQueueWaitIdle(m_device->m_queue);
4533 vkDestroyImage(m_device->device(), image, NULL);
4534 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
4535 vkDestroyImageView(m_device->device(), view, nullptr);
4536 vkFreeMemory(m_device->device(), image_memory, nullptr);
4537}
4538
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06004539TEST_F(VkLayerTest, RenderPassInUseDestroyedSignaled) {
4540 TEST_DESCRIPTION("Delete in-use renderPass.");
4541
4542 ASSERT_NO_FATAL_FAILURE(InitState());
4543 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4544
4545 // Create simple renderpass
4546 VkAttachmentReference attach = {};
4547 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
4548 VkSubpassDescription subpass = {};
4549 subpass.pColorAttachments = &attach;
4550 VkRenderPassCreateInfo rpci = {};
4551 rpci.subpassCount = 1;
4552 rpci.pSubpasses = &subpass;
4553 rpci.attachmentCount = 1;
4554 VkAttachmentDescription attach_desc = {};
4555 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
4556 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
4557 rpci.pAttachments = &attach_desc;
4558 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
4559 VkRenderPass rp;
4560 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
4561 ASSERT_VK_SUCCESS(err);
4562
4563 // Create a pipeline that uses the given renderpass
4564 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4565 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4566
4567 VkPipelineLayout pipeline_layout;
4568 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
4569 ASSERT_VK_SUCCESS(err);
4570
4571 VkPipelineViewportStateCreateInfo vp_state_ci = {};
4572 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
4573 vp_state_ci.viewportCount = 1;
4574 VkViewport vp = {}; // Just need dummy vp to point to
4575 vp_state_ci.pViewports = &vp;
4576 vp_state_ci.scissorCount = 1;
4577 VkRect2D scissors = {}; // Dummy scissors to point to
4578 vp_state_ci.pScissors = &scissors;
4579
4580 VkPipelineShaderStageCreateInfo shaderStages[2];
4581 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
4582
4583 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
4584 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
4585 // but add it to be able to run on more devices
4586 shaderStages[0] = vs.GetStageCreateInfo();
4587 shaderStages[1] = fs.GetStageCreateInfo();
4588
4589 VkPipelineVertexInputStateCreateInfo vi_ci = {};
4590 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
4591
4592 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
4593 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
4594 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
4595
4596 VkPipelineRasterizationStateCreateInfo rs_ci = {};
4597 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
4598 rs_ci.rasterizerDiscardEnable = true;
4599 rs_ci.lineWidth = 1.0f;
4600
4601 VkPipelineColorBlendAttachmentState att = {};
4602 att.blendEnable = VK_FALSE;
4603 att.colorWriteMask = 0xf;
4604
4605 VkPipelineColorBlendStateCreateInfo cb_ci = {};
4606 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
4607 cb_ci.attachmentCount = 1;
4608 cb_ci.pAttachments = &att;
4609
4610 VkGraphicsPipelineCreateInfo gp_ci = {};
4611 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
4612 gp_ci.stageCount = 2;
4613 gp_ci.pStages = shaderStages;
4614 gp_ci.pVertexInputState = &vi_ci;
4615 gp_ci.pInputAssemblyState = &ia_ci;
4616 gp_ci.pViewportState = &vp_state_ci;
4617 gp_ci.pRasterizationState = &rs_ci;
4618 gp_ci.pColorBlendState = &cb_ci;
4619 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
4620 gp_ci.layout = pipeline_layout;
4621 gp_ci.renderPass = rp;
4622
4623 VkPipelineCacheCreateInfo pc_ci = {};
4624 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
4625
4626 VkPipeline pipeline;
4627 VkPipelineCache pipe_cache;
4628 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipe_cache);
4629 ASSERT_VK_SUCCESS(err);
4630
4631 err = vkCreateGraphicsPipelines(m_device->device(), pipe_cache, 1, &gp_ci, NULL, &pipeline);
4632 ASSERT_VK_SUCCESS(err);
4633 // Bind pipeline to cmd buffer, will also bind renderpass
4634 m_commandBuffer->BeginCommandBuffer();
4635 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
4636 m_commandBuffer->EndCommandBuffer();
4637
4638 VkSubmitInfo submit_info = {};
4639 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4640 submit_info.commandBufferCount = 1;
4641 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4642 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4643
4644 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00393);
4645 vkDestroyRenderPass(m_device->device(), rp, nullptr);
4646 m_errorMonitor->VerifyFound();
4647
4648 // Wait for queue to complete so we can safely destroy everything
4649 vkQueueWaitIdle(m_device->m_queue);
4650 vkDestroyRenderPass(m_device->device(), rp, nullptr);
4651 vkDestroyPipeline(m_device->device(), pipeline, nullptr);
4652 vkDestroyPipelineCache(m_device->device(), pipe_cache, nullptr);
4653 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
4654}
4655
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004656TEST_F(VkLayerTest, ImageMemoryNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004657 TEST_DESCRIPTION("Attempt to draw with an image which has not had memory bound to it.");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004658 ASSERT_NO_FATAL_FAILURE(InitState());
4659
4660 VkImage image;
4661 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
4662 VkImageCreateInfo image_create_info = {};
4663 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4664 image_create_info.pNext = NULL;
4665 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4666 image_create_info.format = tex_format;
4667 image_create_info.extent.width = 32;
4668 image_create_info.extent.height = 32;
4669 image_create_info.extent.depth = 1;
4670 image_create_info.mipLevels = 1;
4671 image_create_info.arrayLayers = 1;
4672 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
4673 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004674 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004675 image_create_info.flags = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004676 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004677 ASSERT_VK_SUCCESS(err);
4678 // Have to bind memory to image before recording cmd in cmd buffer using it
4679 VkMemoryRequirements mem_reqs;
4680 VkDeviceMemory image_mem;
4681 bool pass;
4682 VkMemoryAllocateInfo mem_alloc = {};
4683 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4684 mem_alloc.pNext = NULL;
4685 mem_alloc.memoryTypeIndex = 0;
4686 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
4687 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004688 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004689 ASSERT_TRUE(pass);
4690 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
4691 ASSERT_VK_SUCCESS(err);
4692
Tobin Ehlisfed999f2016-09-21 15:09:45 -06004693 // Introduce error, do not call vkBindImageMemory(m_device->device(), image, image_mem, 0);
4694 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06004695 " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004696
4697 m_commandBuffer->BeginCommandBuffer();
4698 VkClearColorValue ccv;
4699 ccv.float32[0] = 1.0f;
4700 ccv.float32[1] = 1.0f;
4701 ccv.float32[2] = 1.0f;
4702 ccv.float32[3] = 1.0f;
4703 VkImageSubresourceRange isr = {};
4704 isr.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
4705 isr.baseArrayLayer = 0;
4706 isr.baseMipLevel = 0;
4707 isr.layerCount = 1;
4708 isr.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004709 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), image, VK_IMAGE_LAYOUT_GENERAL, &ccv, 1, &isr);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004710 m_commandBuffer->EndCommandBuffer();
4711
4712 m_errorMonitor->VerifyFound();
4713 vkDestroyImage(m_device->device(), image, NULL);
4714 vkFreeMemory(m_device->device(), image_mem, nullptr);
4715}
4716
4717TEST_F(VkLayerTest, BufferMemoryNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004718 TEST_DESCRIPTION("Attempt to copy from a buffer which has not had memory bound to it.");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004719 ASSERT_NO_FATAL_FAILURE(InitState());
4720
4721 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004722 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 -06004723 VK_IMAGE_TILING_OPTIMAL, 0);
4724 ASSERT_TRUE(image.initialized());
4725
4726 VkBuffer buffer;
4727 VkDeviceMemory mem;
4728 VkMemoryRequirements mem_reqs;
4729
4730 VkBufferCreateInfo buf_info = {};
4731 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes8d260dd2016-09-16 17:42:42 +12004732 buf_info.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004733 buf_info.size = 256;
4734 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
4735 VkResult err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
4736 ASSERT_VK_SUCCESS(err);
4737
4738 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
4739
4740 VkMemoryAllocateInfo alloc_info = {};
4741 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4742 alloc_info.allocationSize = 256;
4743 bool pass = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004744 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 -06004745 if (!pass) {
4746 vkDestroyBuffer(m_device->device(), buffer, NULL);
4747 return;
4748 }
4749 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
4750 ASSERT_VK_SUCCESS(err);
4751
Tobin Ehlisfed999f2016-09-21 15:09:45 -06004752 // Introduce failure by not calling vkBindBufferMemory(m_device->device(), buffer, mem, 0);
4753 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06004754 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004755 VkBufferImageCopy region = {};
4756 region.bufferRowLength = 128;
4757 region.bufferImageHeight = 128;
4758 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
4759
4760 region.imageSubresource.layerCount = 1;
4761 region.imageExtent.height = 4;
4762 region.imageExtent.width = 4;
4763 region.imageExtent.depth = 1;
4764 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004765 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer, image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
4766 &region);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004767 m_commandBuffer->EndCommandBuffer();
4768
4769 m_errorMonitor->VerifyFound();
4770
4771 vkDestroyBuffer(m_device->device(), buffer, NULL);
4772 vkFreeMemory(m_device->handle(), mem, NULL);
4773}
4774
Tobin Ehlis85940f52016-07-07 16:57:21 -06004775TEST_F(VkLayerTest, InvalidCmdBufferEventDestroyed) {
4776 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4777 "due to an event dependency being destroyed.");
4778 ASSERT_NO_FATAL_FAILURE(InitState());
4779
4780 VkEvent event;
4781 VkEventCreateInfo evci = {};
4782 evci.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
4783 VkResult result = vkCreateEvent(m_device->device(), &evci, NULL, &event);
4784 ASSERT_VK_SUCCESS(result);
4785
4786 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004787 vkCmdSetEvent(m_commandBuffer->GetBufferHandle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Tobin Ehlis85940f52016-07-07 16:57:21 -06004788 m_commandBuffer->EndCommandBuffer();
4789
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004790 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound event ");
Tobin Ehlis85940f52016-07-07 16:57:21 -06004791 // Destroy event dependency prior to submit to cause ERROR
4792 vkDestroyEvent(m_device->device(), event, NULL);
4793
4794 VkSubmitInfo submit_info = {};
4795 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4796 submit_info.commandBufferCount = 1;
4797 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4798 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4799
4800 m_errorMonitor->VerifyFound();
4801}
4802
Tobin Ehlisdbea7552016-07-08 14:33:31 -06004803TEST_F(VkLayerTest, InvalidCmdBufferQueryPoolDestroyed) {
4804 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4805 "due to a query pool dependency being destroyed.");
4806 ASSERT_NO_FATAL_FAILURE(InitState());
4807
4808 VkQueryPool query_pool;
4809 VkQueryPoolCreateInfo qpci{};
4810 qpci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
4811 qpci.queryType = VK_QUERY_TYPE_TIMESTAMP;
4812 qpci.queryCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004813 VkResult result = vkCreateQueryPool(m_device->device(), &qpci, nullptr, &query_pool);
Tobin Ehlisdbea7552016-07-08 14:33:31 -06004814 ASSERT_VK_SUCCESS(result);
4815
4816 m_commandBuffer->BeginCommandBuffer();
4817 vkCmdResetQueryPool(m_commandBuffer->GetBufferHandle(), query_pool, 0, 1);
4818 m_commandBuffer->EndCommandBuffer();
4819
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004820 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound query pool ");
Tobin Ehlisdbea7552016-07-08 14:33:31 -06004821 // Destroy query pool dependency prior to submit to cause ERROR
4822 vkDestroyQueryPool(m_device->device(), query_pool, NULL);
4823
4824 VkSubmitInfo submit_info = {};
4825 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4826 submit_info.commandBufferCount = 1;
4827 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4828 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4829
4830 m_errorMonitor->VerifyFound();
4831}
4832
Tobin Ehlis24130d92016-07-08 15:50:53 -06004833TEST_F(VkLayerTest, InvalidCmdBufferPipelineDestroyed) {
4834 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4835 "due to a pipeline dependency being destroyed.");
4836 ASSERT_NO_FATAL_FAILURE(InitState());
4837 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4838
4839 VkResult err;
4840
4841 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4842 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4843
4844 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004845 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis24130d92016-07-08 15:50:53 -06004846 ASSERT_VK_SUCCESS(err);
4847
4848 VkPipelineViewportStateCreateInfo vp_state_ci = {};
4849 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
4850 vp_state_ci.viewportCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004851 VkViewport vp = {}; // Just need dummy vp to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -06004852 vp_state_ci.pViewports = &vp;
Tobin Ehlis24130d92016-07-08 15:50:53 -06004853 vp_state_ci.scissorCount = 1;
4854 VkRect2D scissors = {}; // Dummy scissors to point to
4855 vp_state_ci.pScissors = &scissors;
Tobin Ehlis24130d92016-07-08 15:50:53 -06004856
4857 VkPipelineShaderStageCreateInfo shaderStages[2];
4858 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
4859
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004860 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
4861 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
4862 // but add it to be able to run on more devices
Tobin Ehlis24130d92016-07-08 15:50:53 -06004863 shaderStages[0] = vs.GetStageCreateInfo();
4864 shaderStages[1] = fs.GetStageCreateInfo();
4865
4866 VkPipelineVertexInputStateCreateInfo vi_ci = {};
4867 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
4868
4869 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
4870 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
4871 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
4872
4873 VkPipelineRasterizationStateCreateInfo rs_ci = {};
4874 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Chris Forbese06ba252016-09-16 17:48:53 +12004875 rs_ci.rasterizerDiscardEnable = true;
4876 rs_ci.lineWidth = 1.0f;
Tobin Ehlis24130d92016-07-08 15:50:53 -06004877
4878 VkPipelineColorBlendAttachmentState att = {};
4879 att.blendEnable = VK_FALSE;
4880 att.colorWriteMask = 0xf;
4881
4882 VkPipelineColorBlendStateCreateInfo cb_ci = {};
4883 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
4884 cb_ci.attachmentCount = 1;
4885 cb_ci.pAttachments = &att;
4886
4887 VkGraphicsPipelineCreateInfo gp_ci = {};
4888 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
4889 gp_ci.stageCount = 2;
4890 gp_ci.pStages = shaderStages;
4891 gp_ci.pVertexInputState = &vi_ci;
4892 gp_ci.pInputAssemblyState = &ia_ci;
4893 gp_ci.pViewportState = &vp_state_ci;
4894 gp_ci.pRasterizationState = &rs_ci;
4895 gp_ci.pColorBlendState = &cb_ci;
Tobin Ehlis24130d92016-07-08 15:50:53 -06004896 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
4897 gp_ci.layout = pipeline_layout;
4898 gp_ci.renderPass = renderPass();
4899
4900 VkPipelineCacheCreateInfo pc_ci = {};
4901 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
4902
4903 VkPipeline pipeline;
4904 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004905 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis24130d92016-07-08 15:50:53 -06004906 ASSERT_VK_SUCCESS(err);
4907
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004908 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis24130d92016-07-08 15:50:53 -06004909 ASSERT_VK_SUCCESS(err);
4910
4911 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004912 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Tobin Ehlis24130d92016-07-08 15:50:53 -06004913 m_commandBuffer->EndCommandBuffer();
4914 // Now destroy pipeline in order to cause error when submitting
4915 vkDestroyPipeline(m_device->device(), pipeline, nullptr);
4916
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004917 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound pipeline ");
Tobin Ehlis24130d92016-07-08 15:50:53 -06004918
4919 VkSubmitInfo submit_info = {};
4920 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4921 submit_info.commandBufferCount = 1;
4922 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4923 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4924
4925 m_errorMonitor->VerifyFound();
4926 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
4927 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4928}
4929
Tobin Ehlis31289162016-08-17 14:57:58 -06004930TEST_F(VkLayerTest, InvalidCmdBufferDescriptorSetBufferDestroyed) {
4931 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4932 "due to a bound descriptor set with a buffer dependency "
4933 "being destroyed.");
4934 ASSERT_NO_FATAL_FAILURE(InitState());
4935 ASSERT_NO_FATAL_FAILURE(InitViewport());
4936 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4937
4938 VkDescriptorPoolSize ds_type_count = {};
4939 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4940 ds_type_count.descriptorCount = 1;
4941
4942 VkDescriptorPoolCreateInfo ds_pool_ci = {};
4943 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4944 ds_pool_ci.pNext = NULL;
4945 ds_pool_ci.maxSets = 1;
4946 ds_pool_ci.poolSizeCount = 1;
4947 ds_pool_ci.pPoolSizes = &ds_type_count;
4948
4949 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004950 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis31289162016-08-17 14:57:58 -06004951 ASSERT_VK_SUCCESS(err);
4952
4953 VkDescriptorSetLayoutBinding dsl_binding = {};
4954 dsl_binding.binding = 0;
4955 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4956 dsl_binding.descriptorCount = 1;
4957 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
4958 dsl_binding.pImmutableSamplers = NULL;
4959
4960 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
4961 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4962 ds_layout_ci.pNext = NULL;
4963 ds_layout_ci.bindingCount = 1;
4964 ds_layout_ci.pBindings = &dsl_binding;
4965 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004966 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis31289162016-08-17 14:57:58 -06004967 ASSERT_VK_SUCCESS(err);
4968
4969 VkDescriptorSet descriptorSet;
4970 VkDescriptorSetAllocateInfo alloc_info = {};
4971 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
4972 alloc_info.descriptorSetCount = 1;
4973 alloc_info.descriptorPool = ds_pool;
4974 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004975 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis31289162016-08-17 14:57:58 -06004976 ASSERT_VK_SUCCESS(err);
4977
4978 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4979 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4980 pipeline_layout_ci.pNext = NULL;
4981 pipeline_layout_ci.setLayoutCount = 1;
4982 pipeline_layout_ci.pSetLayouts = &ds_layout;
4983
4984 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004985 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis31289162016-08-17 14:57:58 -06004986 ASSERT_VK_SUCCESS(err);
4987
4988 // Create a buffer to update the descriptor with
4989 uint32_t qfi = 0;
4990 VkBufferCreateInfo buffCI = {};
4991 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
4992 buffCI.size = 1024;
4993 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
4994 buffCI.queueFamilyIndexCount = 1;
4995 buffCI.pQueueFamilyIndices = &qfi;
4996
4997 VkBuffer buffer;
4998 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &buffer);
4999 ASSERT_VK_SUCCESS(err);
5000 // Allocate memory and bind to buffer so we can make it to the appropriate
5001 // error
5002 VkMemoryAllocateInfo mem_alloc = {};
5003 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5004 mem_alloc.pNext = NULL;
5005 mem_alloc.allocationSize = 1024;
5006 mem_alloc.memoryTypeIndex = 0;
5007
5008 VkMemoryRequirements memReqs;
5009 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005010 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis31289162016-08-17 14:57:58 -06005011 if (!pass) {
5012 vkDestroyBuffer(m_device->device(), buffer, NULL);
5013 return;
5014 }
5015
5016 VkDeviceMemory mem;
5017 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
5018 ASSERT_VK_SUCCESS(err);
5019 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
5020 ASSERT_VK_SUCCESS(err);
5021 // Correctly update descriptor to avoid "NOT_UPDATED" error
5022 VkDescriptorBufferInfo buffInfo = {};
5023 buffInfo.buffer = buffer;
5024 buffInfo.offset = 0;
5025 buffInfo.range = 1024;
5026
5027 VkWriteDescriptorSet descriptor_write;
5028 memset(&descriptor_write, 0, sizeof(descriptor_write));
5029 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5030 descriptor_write.dstSet = descriptorSet;
5031 descriptor_write.dstBinding = 0;
5032 descriptor_write.descriptorCount = 1;
5033 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5034 descriptor_write.pBufferInfo = &buffInfo;
5035
5036 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5037
5038 // Create PSO to be used for draw-time errors below
5039 char const *vsSource = "#version 450\n"
5040 "\n"
5041 "out gl_PerVertex { \n"
5042 " vec4 gl_Position;\n"
5043 "};\n"
5044 "void main(){\n"
5045 " gl_Position = vec4(1);\n"
5046 "}\n";
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005047 char const *fsSource = "#version 450\n"
5048 "\n"
5049 "layout(location=0) out vec4 x;\n"
5050 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
5051 "void main(){\n"
5052 " x = vec4(bar.y);\n"
5053 "}\n";
Tobin Ehlis31289162016-08-17 14:57:58 -06005054 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5055 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5056 VkPipelineObj pipe(m_device);
5057 pipe.AddShader(&vs);
5058 pipe.AddShader(&fs);
5059 pipe.AddColorAttachment();
5060 pipe.CreateVKPipeline(pipeline_layout, renderPass());
5061
5062 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005063 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5064 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5065 &descriptorSet, 0, NULL);
Tobin Ehlis31289162016-08-17 14:57:58 -06005066 Draw(1, 0, 0, 0);
5067 EndCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005068 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound buffer ");
Tobin Ehlis31289162016-08-17 14:57:58 -06005069 // Destroy buffer should invalidate the cmd buffer, causing error on submit
5070 vkDestroyBuffer(m_device->device(), buffer, NULL);
5071 // Attempt to submit cmd buffer
5072 VkSubmitInfo submit_info = {};
5073 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5074 submit_info.commandBufferCount = 1;
5075 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5076 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5077 m_errorMonitor->VerifyFound();
5078 // Cleanup
5079 vkFreeMemory(m_device->device(), mem, NULL);
5080
5081 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5082 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5083 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5084}
5085
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005086TEST_F(VkLayerTest, InvalidCmdBufferDescriptorSetImageSamplerDestroyed) {
5087 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
5088 "due to a bound descriptor sets with a combined image "
5089 "sampler having their image, sampler, and descriptor set "
5090 "each respectively destroyed and then attempting to "
Mark Mueller917f6bc2016-08-30 10:57:19 -06005091 "submit associated cmd buffers. Attempt to destroy a "
5092 "DescriptorSet that is in use.");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005093 ASSERT_NO_FATAL_FAILURE(InitState());
5094 ASSERT_NO_FATAL_FAILURE(InitViewport());
5095 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5096
5097 VkDescriptorPoolSize ds_type_count = {};
5098 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5099 ds_type_count.descriptorCount = 1;
5100
5101 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5102 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5103 ds_pool_ci.pNext = NULL;
5104 ds_pool_ci.maxSets = 1;
5105 ds_pool_ci.poolSizeCount = 1;
5106 ds_pool_ci.pPoolSizes = &ds_type_count;
5107
5108 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005109 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005110 ASSERT_VK_SUCCESS(err);
5111
5112 VkDescriptorSetLayoutBinding dsl_binding = {};
5113 dsl_binding.binding = 0;
5114 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5115 dsl_binding.descriptorCount = 1;
5116 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5117 dsl_binding.pImmutableSamplers = NULL;
5118
5119 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5120 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5121 ds_layout_ci.pNext = NULL;
5122 ds_layout_ci.bindingCount = 1;
5123 ds_layout_ci.pBindings = &dsl_binding;
5124 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005125 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005126 ASSERT_VK_SUCCESS(err);
5127
5128 VkDescriptorSet descriptorSet;
5129 VkDescriptorSetAllocateInfo alloc_info = {};
5130 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
5131 alloc_info.descriptorSetCount = 1;
5132 alloc_info.descriptorPool = ds_pool;
5133 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005134 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005135 ASSERT_VK_SUCCESS(err);
5136
5137 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5138 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5139 pipeline_layout_ci.pNext = NULL;
5140 pipeline_layout_ci.setLayoutCount = 1;
5141 pipeline_layout_ci.pSetLayouts = &ds_layout;
5142
5143 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005144 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005145 ASSERT_VK_SUCCESS(err);
5146
5147 // Create images to update the descriptor with
5148 VkImage image;
5149 VkImage image2;
5150 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
5151 const int32_t tex_width = 32;
5152 const int32_t tex_height = 32;
5153 VkImageCreateInfo image_create_info = {};
5154 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5155 image_create_info.pNext = NULL;
5156 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5157 image_create_info.format = tex_format;
5158 image_create_info.extent.width = tex_width;
5159 image_create_info.extent.height = tex_height;
5160 image_create_info.extent.depth = 1;
5161 image_create_info.mipLevels = 1;
5162 image_create_info.arrayLayers = 1;
5163 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
5164 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
5165 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
5166 image_create_info.flags = 0;
5167 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
5168 ASSERT_VK_SUCCESS(err);
5169 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image2);
5170 ASSERT_VK_SUCCESS(err);
5171
5172 VkMemoryRequirements memory_reqs;
5173 VkDeviceMemory image_memory;
5174 bool pass;
5175 VkMemoryAllocateInfo memory_info = {};
5176 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5177 memory_info.pNext = NULL;
5178 memory_info.allocationSize = 0;
5179 memory_info.memoryTypeIndex = 0;
5180 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
5181 // Allocate enough memory for both images
5182 memory_info.allocationSize = memory_reqs.size * 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005183 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005184 ASSERT_TRUE(pass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005185 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005186 ASSERT_VK_SUCCESS(err);
5187 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
5188 ASSERT_VK_SUCCESS(err);
5189 // Bind second image to memory right after first image
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005190 err = vkBindImageMemory(m_device->device(), image2, image_memory, memory_reqs.size);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005191 ASSERT_VK_SUCCESS(err);
5192
5193 VkImageViewCreateInfo image_view_create_info = {};
5194 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
5195 image_view_create_info.image = image;
5196 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
5197 image_view_create_info.format = tex_format;
5198 image_view_create_info.subresourceRange.layerCount = 1;
5199 image_view_create_info.subresourceRange.baseMipLevel = 0;
5200 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005201 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005202
5203 VkImageView view;
5204 VkImageView view2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005205 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005206 ASSERT_VK_SUCCESS(err);
5207 image_view_create_info.image = image2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005208 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view2);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005209 ASSERT_VK_SUCCESS(err);
5210 // Create Samplers
5211 VkSamplerCreateInfo sampler_ci = {};
5212 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
5213 sampler_ci.pNext = NULL;
5214 sampler_ci.magFilter = VK_FILTER_NEAREST;
5215 sampler_ci.minFilter = VK_FILTER_NEAREST;
5216 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
5217 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5218 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5219 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5220 sampler_ci.mipLodBias = 1.0;
5221 sampler_ci.anisotropyEnable = VK_FALSE;
5222 sampler_ci.maxAnisotropy = 1;
5223 sampler_ci.compareEnable = VK_FALSE;
5224 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
5225 sampler_ci.minLod = 1.0;
5226 sampler_ci.maxLod = 1.0;
5227 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
5228 sampler_ci.unnormalizedCoordinates = VK_FALSE;
5229 VkSampler sampler;
5230 VkSampler sampler2;
5231 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
5232 ASSERT_VK_SUCCESS(err);
5233 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler2);
5234 ASSERT_VK_SUCCESS(err);
5235 // Update descriptor with image and sampler
5236 VkDescriptorImageInfo img_info = {};
5237 img_info.sampler = sampler;
5238 img_info.imageView = view;
5239 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
5240
5241 VkWriteDescriptorSet descriptor_write;
5242 memset(&descriptor_write, 0, sizeof(descriptor_write));
5243 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5244 descriptor_write.dstSet = descriptorSet;
5245 descriptor_write.dstBinding = 0;
5246 descriptor_write.descriptorCount = 1;
5247 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5248 descriptor_write.pImageInfo = &img_info;
5249
5250 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5251
5252 // Create PSO to be used for draw-time errors below
5253 char const *vsSource = "#version 450\n"
5254 "\n"
5255 "out gl_PerVertex { \n"
5256 " vec4 gl_Position;\n"
5257 "};\n"
5258 "void main(){\n"
5259 " gl_Position = vec4(1);\n"
5260 "}\n";
5261 char const *fsSource = "#version 450\n"
5262 "\n"
5263 "layout(set=0, binding=0) uniform sampler2D s;\n"
5264 "layout(location=0) out vec4 x;\n"
5265 "void main(){\n"
5266 " x = texture(s, vec2(1));\n"
5267 "}\n";
5268 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5269 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5270 VkPipelineObj pipe(m_device);
5271 pipe.AddShader(&vs);
5272 pipe.AddShader(&fs);
5273 pipe.AddColorAttachment();
5274 pipe.CreateVKPipeline(pipeline_layout, renderPass());
5275
5276 // First error case is destroying sampler prior to cmd buffer submission
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005277 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot submit cmd buffer using deleted sampler ");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005278 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005279 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5280 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5281 &descriptorSet, 0, NULL);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005282 Draw(1, 0, 0, 0);
5283 EndCommandBuffer();
5284 // Destroy sampler invalidates the cmd buffer, causing error on submit
5285 vkDestroySampler(m_device->device(), sampler, NULL);
5286 // Attempt to submit cmd buffer
5287 VkSubmitInfo submit_info = {};
5288 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5289 submit_info.commandBufferCount = 1;
5290 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5291 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5292 m_errorMonitor->VerifyFound();
5293 // Now re-update descriptor with valid sampler and delete image
5294 img_info.sampler = sampler2;
5295 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005296 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005297 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005298 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5299 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5300 &descriptorSet, 0, NULL);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005301 Draw(1, 0, 0, 0);
5302 EndCommandBuffer();
5303 // Destroy image invalidates the cmd buffer, causing error on submit
5304 vkDestroyImage(m_device->device(), image, NULL);
5305 // Attempt to submit cmd buffer
5306 submit_info = {};
5307 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5308 submit_info.commandBufferCount = 1;
5309 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5310 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5311 m_errorMonitor->VerifyFound();
5312 // Now update descriptor to be valid, but then free descriptor
5313 img_info.imageView = view2;
5314 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005315 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound descriptor set ");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005316 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005317 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5318 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5319 &descriptorSet, 0, NULL);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005320 Draw(1, 0, 0, 0);
5321 EndCommandBuffer();
5322 // Destroy descriptor set invalidates the cb, causing error on submit
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005323 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot call vkFreeDescriptorSets() on descriptor set 0x");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005324 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
Mark Mueller917f6bc2016-08-30 10:57:19 -06005325 m_errorMonitor->VerifyFound();
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005326 // Attempt to submit cmd buffer
5327 submit_info = {};
5328 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5329 submit_info.commandBufferCount = 1;
5330 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5331 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5332 m_errorMonitor->VerifyFound();
5333 // Cleanup
5334 vkFreeMemory(m_device->device(), image_memory, NULL);
5335 vkDestroySampler(m_device->device(), sampler2, NULL);
5336 vkDestroyImage(m_device->device(), image2, NULL);
5337 vkDestroyImageView(m_device->device(), view, NULL);
5338 vkDestroyImageView(m_device->device(), view2, NULL);
5339 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5340 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5341 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5342}
5343
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06005344TEST_F(VkLayerTest, DescriptorPoolInUseDestroyedSignaled) {
5345 TEST_DESCRIPTION("Delete a DescriptorPool with a DescriptorSet that is in use.");
5346 ASSERT_NO_FATAL_FAILURE(InitState());
5347 ASSERT_NO_FATAL_FAILURE(InitViewport());
5348 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5349
5350 VkDescriptorPoolSize ds_type_count = {};
5351 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5352 ds_type_count.descriptorCount = 1;
5353
5354 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5355 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5356 ds_pool_ci.pNext = NULL;
5357 ds_pool_ci.maxSets = 1;
5358 ds_pool_ci.poolSizeCount = 1;
5359 ds_pool_ci.pPoolSizes = &ds_type_count;
5360
5361 VkDescriptorPool ds_pool;
5362 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
5363 ASSERT_VK_SUCCESS(err);
5364
5365 VkDescriptorSetLayoutBinding dsl_binding = {};
5366 dsl_binding.binding = 0;
5367 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5368 dsl_binding.descriptorCount = 1;
5369 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5370 dsl_binding.pImmutableSamplers = NULL;
5371
5372 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5373 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5374 ds_layout_ci.pNext = NULL;
5375 ds_layout_ci.bindingCount = 1;
5376 ds_layout_ci.pBindings = &dsl_binding;
5377 VkDescriptorSetLayout ds_layout;
5378 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
5379 ASSERT_VK_SUCCESS(err);
5380
5381 VkDescriptorSet descriptor_set;
5382 VkDescriptorSetAllocateInfo alloc_info = {};
5383 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
5384 alloc_info.descriptorSetCount = 1;
5385 alloc_info.descriptorPool = ds_pool;
5386 alloc_info.pSetLayouts = &ds_layout;
5387 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
5388 ASSERT_VK_SUCCESS(err);
5389
5390 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5391 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5392 pipeline_layout_ci.pNext = NULL;
5393 pipeline_layout_ci.setLayoutCount = 1;
5394 pipeline_layout_ci.pSetLayouts = &ds_layout;
5395
5396 VkPipelineLayout pipeline_layout;
5397 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
5398 ASSERT_VK_SUCCESS(err);
5399
5400 // Create image to update the descriptor with
5401 VkImageObj image(m_device);
5402 image.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
5403 ASSERT_TRUE(image.initialized());
5404
5405 VkImageView view = image.targetView(VK_FORMAT_B8G8R8A8_UNORM);
5406 // Create Sampler
5407 VkSamplerCreateInfo sampler_ci = {};
5408 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
5409 sampler_ci.pNext = NULL;
5410 sampler_ci.magFilter = VK_FILTER_NEAREST;
5411 sampler_ci.minFilter = VK_FILTER_NEAREST;
5412 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
5413 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5414 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5415 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5416 sampler_ci.mipLodBias = 1.0;
5417 sampler_ci.anisotropyEnable = VK_FALSE;
5418 sampler_ci.maxAnisotropy = 1;
5419 sampler_ci.compareEnable = VK_FALSE;
5420 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
5421 sampler_ci.minLod = 1.0;
5422 sampler_ci.maxLod = 1.0;
5423 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
5424 sampler_ci.unnormalizedCoordinates = VK_FALSE;
5425 VkSampler sampler;
5426 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
5427 ASSERT_VK_SUCCESS(err);
5428 // Update descriptor with image and sampler
5429 VkDescriptorImageInfo img_info = {};
5430 img_info.sampler = sampler;
5431 img_info.imageView = view;
5432 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
5433
5434 VkWriteDescriptorSet descriptor_write;
5435 memset(&descriptor_write, 0, sizeof(descriptor_write));
5436 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5437 descriptor_write.dstSet = descriptor_set;
5438 descriptor_write.dstBinding = 0;
5439 descriptor_write.descriptorCount = 1;
5440 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5441 descriptor_write.pImageInfo = &img_info;
5442
5443 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5444
5445 // Create PSO to be used for draw-time errors below
5446 char const *vsSource = "#version 450\n"
5447 "\n"
5448 "out gl_PerVertex { \n"
5449 " vec4 gl_Position;\n"
5450 "};\n"
5451 "void main(){\n"
5452 " gl_Position = vec4(1);\n"
5453 "}\n";
5454 char const *fsSource = "#version 450\n"
5455 "\n"
5456 "layout(set=0, binding=0) uniform sampler2D s;\n"
5457 "layout(location=0) out vec4 x;\n"
5458 "void main(){\n"
5459 " x = texture(s, vec2(1));\n"
5460 "}\n";
5461 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5462 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5463 VkPipelineObj pipe(m_device);
5464 pipe.AddShader(&vs);
5465 pipe.AddShader(&fs);
5466 pipe.AddColorAttachment();
5467 pipe.CreateVKPipeline(pipeline_layout, renderPass());
5468
5469 BeginCommandBuffer();
5470 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5471 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5472 &descriptor_set, 0, NULL);
5473 Draw(1, 0, 0, 0);
5474 EndCommandBuffer();
5475 // Submit cmd buffer to put pool in-flight
5476 VkSubmitInfo submit_info = {};
5477 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5478 submit_info.commandBufferCount = 1;
5479 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5480 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5481 // Destroy pool while in-flight, causing error
5482 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete descriptor pool ");
5483 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5484 m_errorMonitor->VerifyFound();
5485 vkQueueWaitIdle(m_device->m_queue);
5486 // Cleanup
5487 vkDestroySampler(m_device->device(), sampler, NULL);
5488 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5489 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5490 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5491}
5492
Tobin Ehlis50a095d2016-09-21 17:32:49 -06005493TEST_F(VkLayerTest, DescriptorImageUpdateNoMemoryBound) {
5494 TEST_DESCRIPTION("Attempt an image descriptor set update where image's bound memory has been freed.");
5495 ASSERT_NO_FATAL_FAILURE(InitState());
5496 ASSERT_NO_FATAL_FAILURE(InitViewport());
5497 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5498
5499 VkDescriptorPoolSize ds_type_count = {};
5500 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5501 ds_type_count.descriptorCount = 1;
5502
5503 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5504 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5505 ds_pool_ci.pNext = NULL;
5506 ds_pool_ci.maxSets = 1;
5507 ds_pool_ci.poolSizeCount = 1;
5508 ds_pool_ci.pPoolSizes = &ds_type_count;
5509
5510 VkDescriptorPool ds_pool;
5511 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
5512 ASSERT_VK_SUCCESS(err);
5513
5514 VkDescriptorSetLayoutBinding dsl_binding = {};
5515 dsl_binding.binding = 0;
5516 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5517 dsl_binding.descriptorCount = 1;
5518 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5519 dsl_binding.pImmutableSamplers = NULL;
5520
5521 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5522 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5523 ds_layout_ci.pNext = NULL;
5524 ds_layout_ci.bindingCount = 1;
5525 ds_layout_ci.pBindings = &dsl_binding;
5526 VkDescriptorSetLayout ds_layout;
5527 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
5528 ASSERT_VK_SUCCESS(err);
5529
5530 VkDescriptorSet descriptorSet;
5531 VkDescriptorSetAllocateInfo alloc_info = {};
5532 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
5533 alloc_info.descriptorSetCount = 1;
5534 alloc_info.descriptorPool = ds_pool;
5535 alloc_info.pSetLayouts = &ds_layout;
5536 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
5537 ASSERT_VK_SUCCESS(err);
5538
5539 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5540 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5541 pipeline_layout_ci.pNext = NULL;
5542 pipeline_layout_ci.setLayoutCount = 1;
5543 pipeline_layout_ci.pSetLayouts = &ds_layout;
5544
5545 VkPipelineLayout pipeline_layout;
5546 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
5547 ASSERT_VK_SUCCESS(err);
5548
5549 // Create images to update the descriptor with
5550 VkImage image;
5551 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
5552 const int32_t tex_width = 32;
5553 const int32_t tex_height = 32;
5554 VkImageCreateInfo image_create_info = {};
5555 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5556 image_create_info.pNext = NULL;
5557 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5558 image_create_info.format = tex_format;
5559 image_create_info.extent.width = tex_width;
5560 image_create_info.extent.height = tex_height;
5561 image_create_info.extent.depth = 1;
5562 image_create_info.mipLevels = 1;
5563 image_create_info.arrayLayers = 1;
5564 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
5565 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
5566 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
5567 image_create_info.flags = 0;
5568 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
5569 ASSERT_VK_SUCCESS(err);
5570 // Initially bind memory to avoid error at bind view time. We'll break binding before update.
5571 VkMemoryRequirements memory_reqs;
5572 VkDeviceMemory image_memory;
5573 bool pass;
5574 VkMemoryAllocateInfo memory_info = {};
5575 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5576 memory_info.pNext = NULL;
5577 memory_info.allocationSize = 0;
5578 memory_info.memoryTypeIndex = 0;
5579 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
5580 // Allocate enough memory for image
5581 memory_info.allocationSize = memory_reqs.size;
5582 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
5583 ASSERT_TRUE(pass);
5584 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
5585 ASSERT_VK_SUCCESS(err);
5586 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
5587 ASSERT_VK_SUCCESS(err);
5588
5589 VkImageViewCreateInfo image_view_create_info = {};
5590 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
5591 image_view_create_info.image = image;
5592 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
5593 image_view_create_info.format = tex_format;
5594 image_view_create_info.subresourceRange.layerCount = 1;
5595 image_view_create_info.subresourceRange.baseMipLevel = 0;
5596 image_view_create_info.subresourceRange.levelCount = 1;
5597 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
5598
5599 VkImageView view;
5600 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
5601 ASSERT_VK_SUCCESS(err);
5602 // Create Samplers
5603 VkSamplerCreateInfo sampler_ci = {};
5604 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
5605 sampler_ci.pNext = NULL;
5606 sampler_ci.magFilter = VK_FILTER_NEAREST;
5607 sampler_ci.minFilter = VK_FILTER_NEAREST;
5608 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
5609 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5610 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5611 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5612 sampler_ci.mipLodBias = 1.0;
5613 sampler_ci.anisotropyEnable = VK_FALSE;
5614 sampler_ci.maxAnisotropy = 1;
5615 sampler_ci.compareEnable = VK_FALSE;
5616 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
5617 sampler_ci.minLod = 1.0;
5618 sampler_ci.maxLod = 1.0;
5619 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
5620 sampler_ci.unnormalizedCoordinates = VK_FALSE;
5621 VkSampler sampler;
5622 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
5623 ASSERT_VK_SUCCESS(err);
5624 // Update descriptor with image and sampler
5625 VkDescriptorImageInfo img_info = {};
5626 img_info.sampler = sampler;
5627 img_info.imageView = view;
5628 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
5629
5630 VkWriteDescriptorSet descriptor_write;
5631 memset(&descriptor_write, 0, sizeof(descriptor_write));
5632 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5633 descriptor_write.dstSet = descriptorSet;
5634 descriptor_write.dstBinding = 0;
5635 descriptor_write.descriptorCount = 1;
5636 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5637 descriptor_write.pImageInfo = &img_info;
5638 // Break memory binding and attempt update
5639 vkFreeMemory(m_device->device(), image_memory, nullptr);
5640 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06005641 " previously bound memory was freed. Memory must not be freed prior to this operation.");
Tobin Ehlis50a095d2016-09-21 17:32:49 -06005642 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
5643 "vkUpdateDescriptorsSets() failed write update validation for Descriptor Set 0x");
5644 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5645 m_errorMonitor->VerifyFound();
5646 // Cleanup
5647 vkDestroyImage(m_device->device(), image, NULL);
5648 vkDestroySampler(m_device->device(), sampler, NULL);
5649 vkDestroyImageView(m_device->device(), view, NULL);
5650 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5651 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5652 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5653}
5654
Karl Schultz6addd812016-02-02 17:17:23 -07005655TEST_F(VkLayerTest, InvalidPipeline) {
Karl Schultzbdb75952016-04-19 11:36:49 -06005656 // Attempt to bind an invalid Pipeline to a valid Command Buffer
5657 // ObjectTracker should catch this.
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06005658 // Create a valid cmd buffer
5659 // call vkCmdBindPipeline w/ false Pipeline
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06005660 uint64_t fake_pipeline_handle = 0xbaad6001;
5661 VkPipeline bad_pipeline = reinterpret_cast<VkPipeline &>(fake_pipeline_handle);
Karl Schultzbdb75952016-04-19 11:36:49 -06005662 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes4dbf70f2016-09-16 17:58:00 +12005663 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5664
Karl Schultzf78bcdd2016-11-30 12:36:01 -07005665 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00601);
Karl Schultzbdb75952016-04-19 11:36:49 -06005666 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005667 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, bad_pipeline);
Karl Schultzbdb75952016-04-19 11:36:49 -06005668 m_errorMonitor->VerifyFound();
Chris Forbes4dbf70f2016-09-16 17:58:00 +12005669
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06005670 // Now issue a draw call with no pipeline bound
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005671 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 -06005672 Draw(1, 0, 0, 0);
5673 m_errorMonitor->VerifyFound();
Chris Forbes4dbf70f2016-09-16 17:58:00 +12005674
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06005675 // Finally same check once more but with Dispatch/Compute
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005676 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 +12005677 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle()); // must be outside renderpass
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06005678 vkCmdDispatch(m_commandBuffer->GetBufferHandle(), 0, 0, 0);
5679 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06005680}
5681
Karl Schultz6addd812016-02-02 17:17:23 -07005682TEST_F(VkLayerTest, DescriptorSetNotUpdated) {
Tobin Ehlis5a5f5ef2016-08-17 13:56:55 -06005683 TEST_DESCRIPTION("Bind a descriptor set that hasn't been updated.");
Karl Schultz6addd812016-02-02 17:17:23 -07005684 VkResult err;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005685
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005686 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, " bound but it was never updated. ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005687
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005688 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyan713b2d72015-08-04 10:49:29 -06005689 ASSERT_NO_FATAL_FAILURE(InitViewport());
5690 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08005691 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005692 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5693 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06005694
5695 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005696 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5697 ds_pool_ci.pNext = NULL;
5698 ds_pool_ci.maxSets = 1;
5699 ds_pool_ci.poolSizeCount = 1;
5700 ds_pool_ci.pPoolSizes = &ds_type_count;
Mike Stroyan713b2d72015-08-04 10:49:29 -06005701
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005702 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005703 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005704 ASSERT_VK_SUCCESS(err);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005705
Tony Barboureb254902015-07-15 12:50:33 -06005706 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005707 dsl_binding.binding = 0;
5708 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5709 dsl_binding.descriptorCount = 1;
5710 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5711 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005712
Tony Barboureb254902015-07-15 12:50:33 -06005713 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005714 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5715 ds_layout_ci.pNext = NULL;
5716 ds_layout_ci.bindingCount = 1;
5717 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005718 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005719 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005720 ASSERT_VK_SUCCESS(err);
5721
5722 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005723 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08005724 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07005725 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06005726 alloc_info.descriptorPool = ds_pool;
5727 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005728 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005729 ASSERT_VK_SUCCESS(err);
5730
Tony Barboureb254902015-07-15 12:50:33 -06005731 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005732 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5733 pipeline_layout_ci.pNext = NULL;
5734 pipeline_layout_ci.setLayoutCount = 1;
5735 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005736
5737 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005738 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005739 ASSERT_VK_SUCCESS(err);
5740
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005741 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -06005742 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -07005743 // on more devices
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005744 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005745
Tony Barbourc95e4ac2015-08-04 17:05:26 -06005746 VkPipelineObj pipe(m_device);
5747 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06005748 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -06005749 pipe.AddColorAttachment();
Tony Barbourc95e4ac2015-08-04 17:05:26 -06005750 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06005751
5752 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005753 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5754 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5755 &descriptorSet, 0, NULL);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005756
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005757 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06005758
Chia-I Wuf7458c52015-10-26 21:10:41 +08005759 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5760 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5761 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06005762}
5763
Karl Schultz6addd812016-02-02 17:17:23 -07005764TEST_F(VkLayerTest, InvalidBufferViewObject) {
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005765 // Create a single TEXEL_BUFFER descriptor and send it an invalid bufferView
Karl Schultz6addd812016-02-02 17:17:23 -07005766 VkResult err;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005767
Karl Schultzf78bcdd2016-11-30 12:36:01 -07005768 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00940);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005769
5770 ASSERT_NO_FATAL_FAILURE(InitState());
5771 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005772 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
5773 ds_type_count.descriptorCount = 1;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005774
5775 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005776 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5777 ds_pool_ci.pNext = NULL;
5778 ds_pool_ci.maxSets = 1;
5779 ds_pool_ci.poolSizeCount = 1;
5780 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005781
5782 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005783 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005784 ASSERT_VK_SUCCESS(err);
5785
5786 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005787 dsl_binding.binding = 0;
5788 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
5789 dsl_binding.descriptorCount = 1;
5790 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5791 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005792
5793 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005794 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5795 ds_layout_ci.pNext = NULL;
5796 ds_layout_ci.bindingCount = 1;
5797 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005798 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005799 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005800 ASSERT_VK_SUCCESS(err);
5801
5802 VkDescriptorSet descriptorSet;
5803 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08005804 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07005805 alloc_info.descriptorSetCount = 1;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005806 alloc_info.descriptorPool = ds_pool;
5807 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005808 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005809 ASSERT_VK_SUCCESS(err);
5810
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005811 VkBufferView view = (VkBufferView)((size_t)0xbaadbeef); // invalid bufferView object
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005812 VkWriteDescriptorSet descriptor_write;
5813 memset(&descriptor_write, 0, sizeof(descriptor_write));
5814 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5815 descriptor_write.dstSet = descriptorSet;
5816 descriptor_write.dstBinding = 0;
5817 descriptor_write.descriptorCount = 1;
5818 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
5819 descriptor_write.pTexelBufferView = &view;
5820
5821 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5822
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005823 m_errorMonitor->VerifyFound();
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005824
5825 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5826 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5827}
5828
Mark Youngd339ba32016-05-30 13:28:35 -06005829TEST_F(VkLayerTest, CreateBufferViewNoMemoryBoundToBuffer) {
Tobin Ehlis4ff58172016-09-22 10:52:00 -06005830 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 -06005831
5832 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -06005833 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06005834 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Mark Youngd339ba32016-05-30 13:28:35 -06005835
5836 ASSERT_NO_FATAL_FAILURE(InitState());
5837
5838 // Create a buffer with no bound memory and then attempt to create
5839 // a buffer view.
5840 VkBufferCreateInfo buff_ci = {};
5841 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes4538d242016-09-13 18:13:58 +12005842 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT;
Mark Youngd339ba32016-05-30 13:28:35 -06005843 buff_ci.size = 256;
5844 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
5845 VkBuffer buffer;
5846 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
5847 ASSERT_VK_SUCCESS(err);
5848
5849 VkBufferViewCreateInfo buff_view_ci = {};
5850 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
5851 buff_view_ci.buffer = buffer;
5852 buff_view_ci.format = VK_FORMAT_R8_UNORM;
5853 buff_view_ci.range = VK_WHOLE_SIZE;
5854 VkBufferView buff_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005855 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buff_view);
Mark Youngd339ba32016-05-30 13:28:35 -06005856
5857 m_errorMonitor->VerifyFound();
5858 vkDestroyBuffer(m_device->device(), buffer, NULL);
5859 // If last error is success, it still created the view, so delete it.
5860 if (err == VK_SUCCESS) {
5861 vkDestroyBufferView(m_device->device(), buff_view, NULL);
5862 }
5863}
5864
Karl Schultz6addd812016-02-02 17:17:23 -07005865TEST_F(VkLayerTest, InvalidDynamicOffsetCases) {
5866 // Create a descriptorSet w/ dynamic descriptor and then hit 3 offset error
5867 // cases:
Tobin Ehlisf6585052015-12-17 11:48:42 -07005868 // 1. No dynamicOffset supplied
5869 // 2. Too many dynamicOffsets supplied
5870 // 3. Dynamic offset oversteps buffer being updated
Karl Schultz6addd812016-02-02 17:17:23 -07005871 VkResult err;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005872 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " requires 1 dynamicOffsets, but only "
5873 "0 dynamicOffsets are left in "
5874 "pDynamicOffsets ");
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005875
5876 ASSERT_NO_FATAL_FAILURE(InitState());
5877 ASSERT_NO_FATAL_FAILURE(InitViewport());
5878 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5879
5880 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005881 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
5882 ds_type_count.descriptorCount = 1;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005883
5884 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005885 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5886 ds_pool_ci.pNext = NULL;
5887 ds_pool_ci.maxSets = 1;
5888 ds_pool_ci.poolSizeCount = 1;
5889 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005890
5891 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005892 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005893 ASSERT_VK_SUCCESS(err);
5894
5895 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005896 dsl_binding.binding = 0;
5897 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
5898 dsl_binding.descriptorCount = 1;
5899 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5900 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005901
5902 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005903 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5904 ds_layout_ci.pNext = NULL;
5905 ds_layout_ci.bindingCount = 1;
5906 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005907 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005908 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005909 ASSERT_VK_SUCCESS(err);
5910
5911 VkDescriptorSet descriptorSet;
5912 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08005913 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07005914 alloc_info.descriptorSetCount = 1;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005915 alloc_info.descriptorPool = ds_pool;
5916 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005917 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005918 ASSERT_VK_SUCCESS(err);
5919
5920 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005921 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5922 pipeline_layout_ci.pNext = NULL;
5923 pipeline_layout_ci.setLayoutCount = 1;
5924 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005925
5926 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005927 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005928 ASSERT_VK_SUCCESS(err);
5929
5930 // Create a buffer to update the descriptor with
5931 uint32_t qfi = 0;
5932 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005933 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
5934 buffCI.size = 1024;
5935 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
5936 buffCI.queueFamilyIndexCount = 1;
5937 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005938
5939 VkBuffer dyub;
5940 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
5941 ASSERT_VK_SUCCESS(err);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06005942 // Allocate memory and bind to buffer so we can make it to the appropriate
5943 // error
5944 VkMemoryAllocateInfo mem_alloc = {};
5945 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5946 mem_alloc.pNext = NULL;
5947 mem_alloc.allocationSize = 1024;
Chris Forbesb6116cc2016-05-08 11:39:59 +12005948 mem_alloc.memoryTypeIndex = 0;
5949
5950 VkMemoryRequirements memReqs;
5951 vkGetBufferMemoryRequirements(m_device->device(), dyub, &memReqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005952 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
Chris Forbesb6116cc2016-05-08 11:39:59 +12005953 if (!pass) {
5954 vkDestroyBuffer(m_device->device(), dyub, NULL);
5955 return;
5956 }
5957
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06005958 VkDeviceMemory mem;
5959 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
5960 ASSERT_VK_SUCCESS(err);
5961 err = vkBindBufferMemory(m_device->device(), dyub, mem, 0);
5962 ASSERT_VK_SUCCESS(err);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005963 // Correctly update descriptor to avoid "NOT_UPDATED" error
5964 VkDescriptorBufferInfo buffInfo = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005965 buffInfo.buffer = dyub;
5966 buffInfo.offset = 0;
5967 buffInfo.range = 1024;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005968
5969 VkWriteDescriptorSet descriptor_write;
5970 memset(&descriptor_write, 0, sizeof(descriptor_write));
5971 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5972 descriptor_write.dstSet = descriptorSet;
5973 descriptor_write.dstBinding = 0;
5974 descriptor_write.descriptorCount = 1;
5975 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
5976 descriptor_write.pBufferInfo = &buffInfo;
5977
5978 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5979
5980 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005981 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5982 &descriptorSet, 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005983 m_errorMonitor->VerifyFound();
Tobin Ehlisf6585052015-12-17 11:48:42 -07005984 uint32_t pDynOff[2] = {512, 756};
5985 // Now cause error b/c too many dynOffsets in array for # of dyn descriptors
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005986 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
5987 "Attempting to bind 1 descriptorSets with 1 dynamic descriptors, but ");
5988 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5989 &descriptorSet, 2, pDynOff);
Chris Forbes7b342802016-04-07 13:20:10 +12005990 m_errorMonitor->VerifyFound();
Tobin Ehlisf6585052015-12-17 11:48:42 -07005991 // Finally cause error due to dynamicOffset being too big
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005992 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " dynamic offset 512 combined with "
5993 "offset 0 and range 1024 that "
5994 "oversteps the buffer size of 1024");
Tobin Ehlisf6585052015-12-17 11:48:42 -07005995 // Create PSO to be used for draw-time errors below
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005996 char const *vsSource = "#version 450\n"
5997 "\n"
5998 "out gl_PerVertex { \n"
5999 " vec4 gl_Position;\n"
6000 "};\n"
6001 "void main(){\n"
6002 " gl_Position = vec4(1);\n"
6003 "}\n";
6004 char const *fsSource = "#version 450\n"
6005 "\n"
6006 "layout(location=0) out vec4 x;\n"
6007 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
6008 "void main(){\n"
6009 " x = vec4(bar.y);\n"
6010 "}\n";
Tobin Ehlisf6585052015-12-17 11:48:42 -07006011 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
6012 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
6013 VkPipelineObj pipe(m_device);
6014 pipe.AddShader(&vs);
6015 pipe.AddShader(&fs);
6016 pipe.AddColorAttachment();
6017 pipe.CreateVKPipeline(pipeline_layout, renderPass());
6018
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006019 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07006020 // This update should succeed, but offset size of 512 will overstep buffer
6021 // /w range 1024 & size 1024
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006022 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6023 &descriptorSet, 1, pDynOff);
Tobin Ehlisf6585052015-12-17 11:48:42 -07006024 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006025 m_errorMonitor->VerifyFound();
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006026
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06006027 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tobin Ehlis512098e2016-05-05 09:06:12 -06006028 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06006029
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006030 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06006031 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006032 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6033}
6034
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006035TEST_F(VkLayerTest, DescriptorBufferUpdateNoMemoryBound) {
6036 TEST_DESCRIPTION("Attempt to update a descriptor with a non-sparse buffer "
6037 "that doesn't have memory bound");
6038 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -06006039 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06006040 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Tobin Ehlisfed999f2016-09-21 15:09:45 -06006041 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6042 "vkUpdateDescriptorsSets() failed write update validation for Descriptor Set 0x");
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006043
6044 ASSERT_NO_FATAL_FAILURE(InitState());
6045 ASSERT_NO_FATAL_FAILURE(InitViewport());
6046 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6047
6048 VkDescriptorPoolSize ds_type_count = {};
6049 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6050 ds_type_count.descriptorCount = 1;
6051
6052 VkDescriptorPoolCreateInfo ds_pool_ci = {};
6053 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6054 ds_pool_ci.pNext = NULL;
6055 ds_pool_ci.maxSets = 1;
6056 ds_pool_ci.poolSizeCount = 1;
6057 ds_pool_ci.pPoolSizes = &ds_type_count;
6058
6059 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006060 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006061 ASSERT_VK_SUCCESS(err);
6062
6063 VkDescriptorSetLayoutBinding dsl_binding = {};
6064 dsl_binding.binding = 0;
6065 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6066 dsl_binding.descriptorCount = 1;
6067 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6068 dsl_binding.pImmutableSamplers = NULL;
6069
6070 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
6071 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6072 ds_layout_ci.pNext = NULL;
6073 ds_layout_ci.bindingCount = 1;
6074 ds_layout_ci.pBindings = &dsl_binding;
6075 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006076 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006077 ASSERT_VK_SUCCESS(err);
6078
6079 VkDescriptorSet descriptorSet;
6080 VkDescriptorSetAllocateInfo alloc_info = {};
6081 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
6082 alloc_info.descriptorSetCount = 1;
6083 alloc_info.descriptorPool = ds_pool;
6084 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006085 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006086 ASSERT_VK_SUCCESS(err);
6087
6088 // Create a buffer to update the descriptor with
6089 uint32_t qfi = 0;
6090 VkBufferCreateInfo buffCI = {};
6091 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
6092 buffCI.size = 1024;
6093 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
6094 buffCI.queueFamilyIndexCount = 1;
6095 buffCI.pQueueFamilyIndices = &qfi;
6096
6097 VkBuffer dyub;
6098 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
6099 ASSERT_VK_SUCCESS(err);
6100
6101 // Attempt to update descriptor without binding memory to it
6102 VkDescriptorBufferInfo buffInfo = {};
6103 buffInfo.buffer = dyub;
6104 buffInfo.offset = 0;
6105 buffInfo.range = 1024;
6106
6107 VkWriteDescriptorSet descriptor_write;
6108 memset(&descriptor_write, 0, sizeof(descriptor_write));
6109 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6110 descriptor_write.dstSet = descriptorSet;
6111 descriptor_write.dstBinding = 0;
6112 descriptor_write.descriptorCount = 1;
6113 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6114 descriptor_write.pBufferInfo = &buffInfo;
6115
6116 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6117 m_errorMonitor->VerifyFound();
6118
6119 vkDestroyBuffer(m_device->device(), dyub, NULL);
6120 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6121 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6122}
6123
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006124TEST_F(VkLayerTest, InvalidPushConstants) {
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006125 VkResult err;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006126 ASSERT_NO_FATAL_FAILURE(InitState());
6127 ASSERT_NO_FATAL_FAILURE(InitViewport());
6128 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6129
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006130 VkPipelineLayout pipeline_layout;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006131 VkPushConstantRange pc_range = {};
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006132 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
6133 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6134 pipeline_layout_ci.pushConstantRangeCount = 1;
6135 pipeline_layout_ci.pPushConstantRanges = &pc_range;
6136
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006137 //
6138 // Check for invalid push constant ranges in pipeline layouts.
6139 //
6140 struct PipelineLayoutTestCase {
Karl Schultzc81037d2016-05-12 08:11:23 -06006141 VkPushConstantRange const range;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006142 char const *msg;
6143 };
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006144
Karl Schultzc81037d2016-05-12 08:11:23 -06006145 const uint32_t too_big = m_device->props.limits.maxPushConstantsSize + 0x4;
6146 const std::array<PipelineLayoutTestCase, 10> range_tests = {{
6147 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 0},
6148 "vkCreatePipelineLayout() call has push constants index 0 with "
6149 "size 0."},
6150 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 1},
6151 "vkCreatePipelineLayout() call has push constants index 0 with "
6152 "size 1."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006153 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 1},
Karl Schultzc81037d2016-05-12 08:11:23 -06006154 "vkCreatePipelineLayout() call has push constants index 0 with "
6155 "size 1."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006156 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 0},
Karl Schultzc81037d2016-05-12 08:11:23 -06006157 "vkCreatePipelineLayout() call has push constants index 0 with "
6158 "size 0."},
6159 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
6160 "vkCreatePipelineLayout() call has push constants index 0 with "
6161 "offset 1. Offset must"},
6162 {{VK_SHADER_STAGE_VERTEX_BIT, 0, too_big},
6163 "vkCreatePipelineLayout() call has push constants index 0 "
6164 "with offset "},
6165 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, too_big},
6166 "vkCreatePipelineLayout() call has push constants "
6167 "index 0 with offset "},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006168 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, 4},
Karl Schultzc81037d2016-05-12 08:11:23 -06006169 "vkCreatePipelineLayout() call has push constants index 0 "
6170 "with offset "},
6171 {{VK_SHADER_STAGE_VERTEX_BIT, 0xFFFFFFF0, 0x00000020},
6172 "vkCreatePipelineLayout() call has push "
6173 "constants index 0 with offset "},
6174 {{VK_SHADER_STAGE_VERTEX_BIT, 0x00000020, 0xFFFFFFF0},
6175 "vkCreatePipelineLayout() call has push "
6176 "constants index 0 with offset "},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006177 }};
6178
6179 // Check for invalid offset and size
Karl Schultzc81037d2016-05-12 08:11:23 -06006180 for (const auto &iter : range_tests) {
6181 pc_range = iter.range;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006182 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
6183 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006184 m_errorMonitor->VerifyFound();
6185 if (VK_SUCCESS == err) {
6186 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6187 }
6188 }
6189
6190 // Check for invalid stage flag
6191 pc_range.offset = 0;
6192 pc_range.size = 16;
6193 pc_range.stageFlags = 0;
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006194 m_errorMonitor->SetDesiredFailureMsg(
6195 VK_DEBUG_REPORT_ERROR_BIT_EXT,
6196 "vkCreatePipelineLayout: value of pCreateInfo->pPushConstantRanges[0].stageFlags must not be 0");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006197 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006198 m_errorMonitor->VerifyFound();
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006199 if (VK_SUCCESS == err) {
6200 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6201 }
6202
6203 // Check for overlapping ranges
Karl Schultzc81037d2016-05-12 08:11:23 -06006204 const uint32_t ranges_per_test = 5;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006205 struct OverlappingRangeTestCase {
Karl Schultzc81037d2016-05-12 08:11:23 -06006206 VkPushConstantRange const ranges[ranges_per_test];
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006207 char const *msg;
6208 };
6209
Karl Schultzc81037d2016-05-12 08:11:23 -06006210 const std::array<OverlappingRangeTestCase, 5> overlapping_range_tests = {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006211 {{{{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6212 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6213 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6214 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6215 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006216 "vkCreatePipelineLayout() call has push constants with overlapping ranges:"},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006217 {
6218 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6219 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
6220 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
6221 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
6222 {VK_SHADER_STAGE_VERTEX_BIT, 16, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006223 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 3:[12, 20), 4:[16, 20)",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006224 },
6225 {
6226 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
6227 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
6228 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
6229 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
6230 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006231 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 0:[16, 20), 1:[12, 20)",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006232 },
6233 {
6234 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
6235 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
6236 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
6237 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
6238 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006239 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 0:[16, 20), 3:[12, 20)",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006240 },
6241 {
6242 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
6243 {VK_SHADER_STAGE_VERTEX_BIT, 32, 4},
6244 {VK_SHADER_STAGE_VERTEX_BIT, 4, 96},
6245 {VK_SHADER_STAGE_VERTEX_BIT, 40, 8},
6246 {VK_SHADER_STAGE_VERTEX_BIT, 52, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006247 "vkCreatePipelineLayout() call has push constants with overlapping ranges:",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006248 }}};
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006249
Karl Schultzc81037d2016-05-12 08:11:23 -06006250 for (const auto &iter : overlapping_range_tests) {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006251 pipeline_layout_ci.pPushConstantRanges = iter.ranges;
Karl Schultzc81037d2016-05-12 08:11:23 -06006252 pipeline_layout_ci.pushConstantRangeCount = ranges_per_test;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006253 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, iter.msg);
6254 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006255 m_errorMonitor->VerifyFound();
6256 if (VK_SUCCESS == err) {
6257 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6258 }
6259 }
6260
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006261 //
6262 // CmdPushConstants tests
6263 //
Karl Schultzc81037d2016-05-12 08:11:23 -06006264 const uint8_t dummy_values[100] = {};
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006265
6266 // Check for invalid offset and size and if range is within layout range(s)
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006267 const std::array<PipelineLayoutTestCase, 11> cmd_range_tests = {{
6268 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 0}, "vkCmdPushConstants: parameter size must be greater than 0"},
Karl Schultzc81037d2016-05-12 08:11:23 -06006269 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 1},
6270 "vkCmdPushConstants() call has push constants with size 1. Size "
6271 "must be greater than zero and a multiple of 4."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006272 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 1},
Karl Schultzc81037d2016-05-12 08:11:23 -06006273 "vkCmdPushConstants() call has push constants with size 1. Size "
6274 "must be greater than zero and a multiple of 4."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006275 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
Karl Schultzc81037d2016-05-12 08:11:23 -06006276 "vkCmdPushConstants() call has push constants with offset 1. "
6277 "Offset must be a multiple of 4."},
6278 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
6279 "vkCmdPushConstants() call has push constants with offset 1. "
6280 "Offset must be a multiple of 4."},
6281 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 20},
6282 "vkCmdPushConstants() Push constant range [0, 20) with stageFlags = "
6283 "0x1 not within flag-matching ranges in pipeline layout"},
6284 {{VK_SHADER_STAGE_VERTEX_BIT, 60, 8},
6285 "vkCmdPushConstants() Push constant range [60, 68) with stageFlags = "
6286 "0x1 not within flag-matching ranges in pipeline layout"},
6287 {{VK_SHADER_STAGE_VERTEX_BIT, 76, 8},
6288 "vkCmdPushConstants() Push constant range [76, 84) with stageFlags = "
6289 "0x1 not within flag-matching ranges in pipeline layout"},
6290 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 80},
6291 "vkCmdPushConstants() Push constant range [0, 80) with stageFlags = "
6292 "0x1 not within flag-matching ranges in pipeline layout"},
6293 {{VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, 0, 4},
6294 "vkCmdPushConstants() stageFlags = 0x2 do not match the stageFlags in "
6295 "any of the ranges in pipeline layout"},
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006296 {{VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, 0, 16},
Karl Schultzc81037d2016-05-12 08:11:23 -06006297 "vkCmdPushConstants() stageFlags = 0x3 do not match the stageFlags in "
6298 "any of the ranges in pipeline layout"},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006299 }};
6300
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006301 BeginCommandBuffer();
6302
6303 // Setup ranges: [0,16) [64,80)
Karl Schultzc81037d2016-05-12 08:11:23 -06006304 const VkPushConstantRange pc_range2[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006305 {VK_SHADER_STAGE_VERTEX_BIT, 64, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 0, 16},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006306 };
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006307 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range2) / sizeof(VkPushConstantRange);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006308 pipeline_layout_ci.pPushConstantRanges = pc_range2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006309 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006310 ASSERT_VK_SUCCESS(err);
Karl Schultzc81037d2016-05-12 08:11:23 -06006311 for (const auto &iter : cmd_range_tests) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006312 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
6313 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.range.stageFlags, iter.range.offset,
Karl Schultzc81037d2016-05-12 08:11:23 -06006314 iter.range.size, dummy_values);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006315 m_errorMonitor->VerifyFound();
6316 }
6317
6318 // Check for invalid stage flag
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006319 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdPushConstants: value of stageFlags must not be 0");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006320 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, 0, 0, 16, dummy_values);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006321 m_errorMonitor->VerifyFound();
Karl Schultzc81037d2016-05-12 08:11:23 -06006322 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006323
Karl Schultzc81037d2016-05-12 08:11:23 -06006324 // overlapping range tests with cmd
6325 const std::array<PipelineLayoutTestCase, 3> cmd_overlap_tests = {{
6326 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 20},
6327 "vkCmdPushConstants() Push constant range [0, 20) with stageFlags = "
6328 "0x1 not within flag-matching ranges in pipeline layout"},
6329 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
6330 "vkCmdPushConstants() Push constant range [16, 20) with stageFlags = "
6331 "0x1 not within flag-matching ranges in pipeline layout"},
6332 {{VK_SHADER_STAGE_VERTEX_BIT, 40, 16},
6333 "vkCmdPushConstants() Push constant range [40, 56) with stageFlags = "
6334 "0x1 not within flag-matching ranges in pipeline layout"},
6335 }};
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006336 // Setup ranges: [0,16), [20,36), [36,44), [44,52), [80,92)
Karl Schultzc81037d2016-05-12 08:11:23 -06006337 const VkPushConstantRange pc_range3[] = {
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006338 {VK_SHADER_STAGE_VERTEX_BIT, 20, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 0, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 44, 8},
6339 {VK_SHADER_STAGE_VERTEX_BIT, 80, 12}, {VK_SHADER_STAGE_VERTEX_BIT, 36, 8},
Karl Schultzc81037d2016-05-12 08:11:23 -06006340 };
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006341 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range3) / sizeof(VkPushConstantRange);
Karl Schultzc81037d2016-05-12 08:11:23 -06006342 pipeline_layout_ci.pPushConstantRanges = pc_range3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006343 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzc81037d2016-05-12 08:11:23 -06006344 ASSERT_VK_SUCCESS(err);
Karl Schultzc81037d2016-05-12 08:11:23 -06006345 for (const auto &iter : cmd_overlap_tests) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006346 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
6347 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.range.stageFlags, iter.range.offset,
Karl Schultzc81037d2016-05-12 08:11:23 -06006348 iter.range.size, dummy_values);
6349 m_errorMonitor->VerifyFound();
6350 }
Karl Schultzc81037d2016-05-12 08:11:23 -06006351 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6352
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006353 EndCommandBuffer();
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006354}
6355
Karl Schultz6addd812016-02-02 17:17:23 -07006356TEST_F(VkLayerTest, DescriptorSetCompatibility) {
Tobin Ehlis559c6382015-11-05 09:52:49 -07006357 // Test various desriptorSet errors with bad binding combinations
Karl Schultz6addd812016-02-02 17:17:23 -07006358 VkResult err;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006359
6360 ASSERT_NO_FATAL_FAILURE(InitState());
6361 ASSERT_NO_FATAL_FAILURE(InitViewport());
6362 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6363
Mike Stroyanb8a61002016-06-20 16:00:28 -06006364 const VkFormat tex_format = VK_FORMAT_R8G8B8A8_UNORM;
6365 VkImageTiling tiling;
6366 VkFormatProperties format_properties;
6367 vkGetPhysicalDeviceFormatProperties(gpu(), tex_format, &format_properties);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006368 if (format_properties.linearTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
Mike Stroyanb8a61002016-06-20 16:00:28 -06006369 tiling = VK_IMAGE_TILING_LINEAR;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006370 } else if (format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
Mike Stroyanb8a61002016-06-20 16:00:28 -06006371 tiling = VK_IMAGE_TILING_OPTIMAL;
6372 } else {
6373 printf("Device does not support VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT; "
6374 "skipped.\n");
6375 return;
6376 }
6377
Tobin Ehlis559c6382015-11-05 09:52:49 -07006378 static const uint32_t NUM_DESCRIPTOR_TYPES = 5;
6379 VkDescriptorPoolSize ds_type_count[NUM_DESCRIPTOR_TYPES] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006380 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6381 ds_type_count[0].descriptorCount = 10;
6382 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
6383 ds_type_count[1].descriptorCount = 2;
6384 ds_type_count[2].type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
6385 ds_type_count[2].descriptorCount = 2;
6386 ds_type_count[3].type = VK_DESCRIPTOR_TYPE_SAMPLER;
6387 ds_type_count[3].descriptorCount = 5;
6388 // TODO : LunarG ILO driver currently asserts in desc.c w/ INPUT_ATTACHMENT
6389 // type
6390 // ds_type_count[4].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
6391 ds_type_count[4].type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
6392 ds_type_count[4].descriptorCount = 2;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006393
6394 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006395 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6396 ds_pool_ci.pNext = NULL;
6397 ds_pool_ci.maxSets = 5;
6398 ds_pool_ci.poolSizeCount = NUM_DESCRIPTOR_TYPES;
6399 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006400
6401 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006402 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006403 ASSERT_VK_SUCCESS(err);
6404
6405 static const uint32_t MAX_DS_TYPES_IN_LAYOUT = 2;
6406 VkDescriptorSetLayoutBinding dsl_binding[MAX_DS_TYPES_IN_LAYOUT] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006407 dsl_binding[0].binding = 0;
6408 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6409 dsl_binding[0].descriptorCount = 5;
6410 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
6411 dsl_binding[0].pImmutableSamplers = NULL;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006412
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006413 // Create layout identical to set0 layout but w/ different stageFlags
6414 VkDescriptorSetLayoutBinding dsl_fs_stage_only = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006415 dsl_fs_stage_only.binding = 0;
6416 dsl_fs_stage_only.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6417 dsl_fs_stage_only.descriptorCount = 5;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006418 dsl_fs_stage_only.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT; // Different stageFlags to cause error at
6419 // bind time
Karl Schultz6addd812016-02-02 17:17:23 -07006420 dsl_fs_stage_only.pImmutableSamplers = NULL;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006421 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006422 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6423 ds_layout_ci.pNext = NULL;
6424 ds_layout_ci.bindingCount = 1;
6425 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006426 static const uint32_t NUM_LAYOUTS = 4;
6427 VkDescriptorSetLayout ds_layout[NUM_LAYOUTS] = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006428 VkDescriptorSetLayout ds_layout_fs_only = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006429 // Create 4 unique layouts for full pipelineLayout, and 1 special fs-only
6430 // layout for error case
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006431 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[0]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006432 ASSERT_VK_SUCCESS(err);
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07006433 ds_layout_ci.pBindings = &dsl_fs_stage_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006434 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006435 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006436 dsl_binding[0].binding = 0;
6437 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006438 dsl_binding[0].descriptorCount = 2;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07006439 dsl_binding[1].binding = 1;
6440 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
6441 dsl_binding[1].descriptorCount = 2;
6442 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
6443 dsl_binding[1].pImmutableSamplers = NULL;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07006444 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006445 ds_layout_ci.bindingCount = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006446 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[1]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006447 ASSERT_VK_SUCCESS(err);
6448 dsl_binding[0].binding = 0;
6449 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006450 dsl_binding[0].descriptorCount = 5;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006451 ds_layout_ci.bindingCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006452 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[2]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006453 ASSERT_VK_SUCCESS(err);
6454 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006455 dsl_binding[0].descriptorCount = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006456 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[3]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006457 ASSERT_VK_SUCCESS(err);
6458
6459 static const uint32_t NUM_SETS = 4;
6460 VkDescriptorSet descriptorSet[NUM_SETS] = {};
6461 VkDescriptorSetAllocateInfo alloc_info = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006462 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006463 alloc_info.descriptorSetCount = NUM_LAYOUTS;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006464 alloc_info.descriptorPool = ds_pool;
6465 alloc_info.pSetLayouts = ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006466 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptorSet);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006467 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006468 VkDescriptorSet ds0_fs_only = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07006469 alloc_info.descriptorSetCount = 1;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006470 alloc_info.pSetLayouts = &ds_layout_fs_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006471 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &ds0_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006472 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006473
6474 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006475 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6476 pipeline_layout_ci.pNext = NULL;
6477 pipeline_layout_ci.setLayoutCount = NUM_LAYOUTS;
6478 pipeline_layout_ci.pSetLayouts = ds_layout;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006479
6480 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006481 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006482 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006483 // Create pipelineLayout with only one setLayout
6484 pipeline_layout_ci.setLayoutCount = 1;
6485 VkPipelineLayout single_pipe_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006486 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &single_pipe_layout);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006487 ASSERT_VK_SUCCESS(err);
6488 // Create pipelineLayout with 2 descriptor setLayout at index 0
6489 pipeline_layout_ci.pSetLayouts = &ds_layout[3];
6490 VkPipelineLayout pipe_layout_one_desc;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006491 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_one_desc);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006492 ASSERT_VK_SUCCESS(err);
6493 // Create pipelineLayout with 5 SAMPLER descriptor setLayout at index 0
6494 pipeline_layout_ci.pSetLayouts = &ds_layout[2];
6495 VkPipelineLayout pipe_layout_five_samp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006496 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_five_samp);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006497 ASSERT_VK_SUCCESS(err);
6498 // Create pipelineLayout with UB type, but stageFlags for FS only
6499 pipeline_layout_ci.pSetLayouts = &ds_layout_fs_only;
6500 VkPipelineLayout pipe_layout_fs_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006501 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006502 ASSERT_VK_SUCCESS(err);
6503 // Create pipelineLayout w/ incompatible set0 layout, but set1 is fine
6504 VkDescriptorSetLayout pl_bad_s0[2] = {};
6505 pl_bad_s0[0] = ds_layout_fs_only;
6506 pl_bad_s0[1] = ds_layout[1];
6507 pipeline_layout_ci.setLayoutCount = 2;
6508 pipeline_layout_ci.pSetLayouts = pl_bad_s0;
6509 VkPipelineLayout pipe_layout_bad_set0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006510 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_bad_set0);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006511 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006512
6513 // Create a buffer to update the descriptor with
6514 uint32_t qfi = 0;
6515 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006516 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
6517 buffCI.size = 1024;
6518 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
6519 buffCI.queueFamilyIndexCount = 1;
6520 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006521
6522 VkBuffer dyub;
6523 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
6524 ASSERT_VK_SUCCESS(err);
6525 // Correctly update descriptor to avoid "NOT_UPDATED" error
6526 static const uint32_t NUM_BUFFS = 5;
6527 VkDescriptorBufferInfo buffInfo[NUM_BUFFS] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006528 for (uint32_t i = 0; i < NUM_BUFFS; ++i) {
Tobin Ehlis559c6382015-11-05 09:52:49 -07006529 buffInfo[i].buffer = dyub;
6530 buffInfo[i].offset = 0;
6531 buffInfo[i].range = 1024;
6532 }
Karl Schultz6addd812016-02-02 17:17:23 -07006533 VkImage image;
Karl Schultz6addd812016-02-02 17:17:23 -07006534 const int32_t tex_width = 32;
6535 const int32_t tex_height = 32;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006536 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006537 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
6538 image_create_info.pNext = NULL;
6539 image_create_info.imageType = VK_IMAGE_TYPE_2D;
6540 image_create_info.format = tex_format;
6541 image_create_info.extent.width = tex_width;
6542 image_create_info.extent.height = tex_height;
6543 image_create_info.extent.depth = 1;
6544 image_create_info.mipLevels = 1;
6545 image_create_info.arrayLayers = 1;
6546 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyanb8a61002016-06-20 16:00:28 -06006547 image_create_info.tiling = tiling;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006548 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_STORAGE_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -07006549 image_create_info.flags = 0;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006550 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
6551 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006552
Karl Schultz6addd812016-02-02 17:17:23 -07006553 VkMemoryRequirements memReqs;
6554 VkDeviceMemory imageMem;
6555 bool pass;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07006556 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006557 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
6558 memAlloc.pNext = NULL;
6559 memAlloc.allocationSize = 0;
6560 memAlloc.memoryTypeIndex = 0;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07006561 vkGetImageMemoryRequirements(m_device->device(), image, &memReqs);
6562 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006563 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07006564 ASSERT_TRUE(pass);
6565 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &imageMem);
6566 ASSERT_VK_SUCCESS(err);
6567 err = vkBindImageMemory(m_device->device(), image, imageMem, 0);
6568 ASSERT_VK_SUCCESS(err);
6569
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006570 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006571 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
6572 image_view_create_info.image = image;
6573 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
6574 image_view_create_info.format = tex_format;
6575 image_view_create_info.subresourceRange.layerCount = 1;
6576 image_view_create_info.subresourceRange.baseMipLevel = 0;
6577 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006578 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006579
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006580 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006581 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006582 ASSERT_VK_SUCCESS(err);
Tobin Ehlis991d45a2016-01-06 08:48:41 -07006583 VkDescriptorImageInfo imageInfo[4] = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006584 imageInfo[0].imageView = view;
6585 imageInfo[0].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
6586 imageInfo[1].imageView = view;
6587 imageInfo[1].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
Tobin Ehlis991d45a2016-01-06 08:48:41 -07006588 imageInfo[2].imageView = view;
Tobin Ehlisa1fccbc2016-10-10 14:54:43 -06006589 imageInfo[2].imageLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis991d45a2016-01-06 08:48:41 -07006590 imageInfo[3].imageView = view;
Tobin Ehlisa1fccbc2016-10-10 14:54:43 -06006591 imageInfo[3].imageLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006592
6593 static const uint32_t NUM_SET_UPDATES = 3;
6594 VkWriteDescriptorSet descriptor_write[NUM_SET_UPDATES] = {};
6595 descriptor_write[0].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6596 descriptor_write[0].dstSet = descriptorSet[0];
6597 descriptor_write[0].dstBinding = 0;
6598 descriptor_write[0].descriptorCount = 5;
6599 descriptor_write[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6600 descriptor_write[0].pBufferInfo = buffInfo;
6601 descriptor_write[1].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6602 descriptor_write[1].dstSet = descriptorSet[1];
6603 descriptor_write[1].dstBinding = 0;
6604 descriptor_write[1].descriptorCount = 2;
6605 descriptor_write[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
6606 descriptor_write[1].pImageInfo = imageInfo;
6607 descriptor_write[2].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6608 descriptor_write[2].dstSet = descriptorSet[1];
6609 descriptor_write[2].dstBinding = 1;
6610 descriptor_write[2].descriptorCount = 2;
6611 descriptor_write[2].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
Tobin Ehlis991d45a2016-01-06 08:48:41 -07006612 descriptor_write[2].pImageInfo = &imageInfo[2];
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006613
6614 vkUpdateDescriptorSets(m_device->device(), 3, descriptor_write, 0, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006615
Tobin Ehlis88452832015-12-03 09:40:56 -07006616 // Create PSO to be used for draw-time errors below
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006617 char const *vsSource = "#version 450\n"
6618 "\n"
6619 "out gl_PerVertex {\n"
6620 " vec4 gl_Position;\n"
6621 "};\n"
6622 "void main(){\n"
6623 " gl_Position = vec4(1);\n"
6624 "}\n";
6625 char const *fsSource = "#version 450\n"
6626 "\n"
6627 "layout(location=0) out vec4 x;\n"
6628 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
6629 "void main(){\n"
6630 " x = vec4(bar.y);\n"
6631 "}\n";
Tobin Ehlis88452832015-12-03 09:40:56 -07006632 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
6633 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006634 VkPipelineObj pipe(m_device);
6635 pipe.AddShader(&vs);
6636 pipe.AddShader(&fs);
Tobin Ehlis88452832015-12-03 09:40:56 -07006637 pipe.AddColorAttachment();
6638 pipe.CreateVKPipeline(pipe_layout_fs_only, renderPass());
Tobin Ehlis559c6382015-11-05 09:52:49 -07006639
6640 BeginCommandBuffer();
Tobin Ehlis88452832015-12-03 09:40:56 -07006641
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006642 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07006643 // NOTE : I believe LunarG ilo driver has bug (LX#189) that requires binding
6644 // of PSO
6645 // here before binding DSs. Otherwise we assert in cmd_copy_dset_data() of
6646 // cmd_pipeline.c
6647 // due to the fact that cmd_alloc_dset_data() has not been called in
6648 // cmd_bind_graphics_pipeline()
6649 // TODO : Want to cause various binding incompatibility issues here to test
6650 // DrawState
Tobin Ehlis559c6382015-11-05 09:52:49 -07006651 // First cause various verify_layout_compatibility() fails
6652 // Second disturb early and late sets and verify INFO msgs
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006653 // verify_set_layout_compatibility fail cases:
6654 // 1. invalid VkPipelineLayout (layout) passed into vkCmdBindDescriptorSets
Karl Schultzf78bcdd2016-11-30 12:36:01 -07006655 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00981);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006656 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS,
6657 (VkPipelineLayout)((size_t)0xbaadb1be), 0, 1, &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006658 m_errorMonitor->VerifyFound();
6659
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006660 // 2. layoutIndex exceeds # of layouts in layout
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006661 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " attempting to bind set to index 1");
6662 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, single_pipe_layout, 0, 2,
6663 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006664 m_errorMonitor->VerifyFound();
6665
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006666 vkDestroyPipelineLayout(m_device->device(), single_pipe_layout, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07006667 // 3. Pipeline setLayout[0] has 2 descriptors, but set being bound has 5
6668 // descriptors
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006669 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has 2 descriptors, but DescriptorSetLayout ");
6670 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_one_desc, 0, 1,
6671 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006672 m_errorMonitor->VerifyFound();
6673
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006674 vkDestroyPipelineLayout(m_device->device(), pipe_layout_one_desc, NULL);
6675 // 4. same # of descriptors but mismatch in type
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006676 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is type 'VK_DESCRIPTOR_TYPE_SAMPLER' but binding ");
6677 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_five_samp, 0, 1,
6678 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006679 m_errorMonitor->VerifyFound();
6680
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006681 vkDestroyPipelineLayout(m_device->device(), pipe_layout_five_samp, NULL);
6682 // 5. same # of descriptors but mismatch in stageFlags
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006683 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6684 " has stageFlags 16 but binding 0 for DescriptorSetLayout ");
6685 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_fs_only, 0, 1,
6686 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006687 m_errorMonitor->VerifyFound();
6688
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006689 // Cause INFO messages due to disturbing previously bound Sets
6690 // First bind sets 0 & 1
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006691 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
6692 &descriptorSet[0], 0, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006693 // 1. Disturb bound set0 by re-binding set1 w/ updated pipelineLayout
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006694 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, " previously bound as set #0 was disturbed ");
6695 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_bad_set0, 1, 1,
6696 &descriptorSet[1], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006697 m_errorMonitor->VerifyFound();
6698
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006699 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
6700 &descriptorSet[0], 0, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006701 // 2. Disturb set after last bound set
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006702 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, " newly bound as set #0 so set #1 and "
6703 "any subsequent sets were disturbed ");
6704 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_fs_only, 0, 1,
6705 &ds0_fs_only, 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006706 m_errorMonitor->VerifyFound();
6707
Tobin Ehlis10fad692016-07-07 12:00:36 -06006708 // Now that we're done actively using the pipelineLayout that gfx pipeline
6709 // was created with, we should be able to delete it. Do that now to verify
6710 // that validation obeys pipelineLayout lifetime
6711 vkDestroyPipelineLayout(m_device->device(), pipe_layout_fs_only, NULL);
6712
Tobin Ehlis88452832015-12-03 09:40:56 -07006713 // Cause draw-time errors due to PSO incompatibilities
Karl Schultz6addd812016-02-02 17:17:23 -07006714 // 1. Error due to not binding required set (we actually use same code as
6715 // above to disturb set0)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006716 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
6717 &descriptorSet[0], 0, NULL);
6718 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_bad_set0, 1, 1,
6719 &descriptorSet[1], 0, NULL);
6720 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 -07006721 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006722 m_errorMonitor->VerifyFound();
6723
Tobin Ehlis991d45a2016-01-06 08:48:41 -07006724 vkDestroyPipelineLayout(m_device->device(), pipe_layout_bad_set0, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07006725 // 2. Error due to bound set not being compatible with PSO's
6726 // VkPipelineLayout (diff stageFlags in this case)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006727 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
6728 &descriptorSet[0], 0, NULL);
6729 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " bound as set #0 is not compatible with ");
Tobin Ehlis88452832015-12-03 09:40:56 -07006730 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006731 m_errorMonitor->VerifyFound();
6732
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006733 // Remaining clean-up
Karl Schultz6addd812016-02-02 17:17:23 -07006734 for (uint32_t i = 0; i < NUM_LAYOUTS; ++i) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006735 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout[i], NULL);
6736 }
6737 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_fs_only, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006738 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006739 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6740 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06006741 vkFreeMemory(m_device->device(), imageMem, NULL);
6742 vkDestroyImage(m_device->device(), image, NULL);
6743 vkDestroyImageView(m_device->device(), view, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006744}
Tobin Ehlis559c6382015-11-05 09:52:49 -07006745
Karl Schultz6addd812016-02-02 17:17:23 -07006746TEST_F(VkLayerTest, NoBeginCommandBuffer) {
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006747
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006748 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6749 "You must call vkBeginCommandBuffer() before this call to ");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006750
6751 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006752 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006753 // Call EndCommandBuffer() w/o calling BeginCommandBuffer()
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006754 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006755
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006756 m_errorMonitor->VerifyFound();
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006757}
6758
Karl Schultz6addd812016-02-02 17:17:23 -07006759TEST_F(VkLayerTest, SecondaryCommandBufferNullRenderpass) {
6760 VkResult err;
6761 VkCommandBuffer draw_cmd;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006762
Karl Schultzf78bcdd2016-11-30 12:36:01 -07006763 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00110);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006764
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006765 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006766
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006767 VkCommandBufferAllocateInfo cmd = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006768 cmd.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06006769 cmd.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006770 cmd.commandPool = m_commandPool;
6771 cmd.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006772 cmd.commandBufferCount = 1;
Cody Northropb4569702015-08-04 17:35:57 -06006773
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006774 err = vkAllocateCommandBuffers(m_device->device(), &cmd, &draw_cmd);
Mike Stroyand1c84a52015-08-18 14:40:24 -06006775 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006776
6777 // Force the failure by not setting the Renderpass and Framebuffer fields
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006778 VkCommandBufferBeginInfo cmd_buf_info = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07006779 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006780 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06006781 cmd_buf_info.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006782 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 -07006783 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006784
6785 // The error should be caught by validation of the BeginCommandBuffer call
6786 vkBeginCommandBuffer(draw_cmd, &cmd_buf_info);
6787
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006788 m_errorMonitor->VerifyFound();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006789 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &draw_cmd);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006790}
6791
Karl Schultz6addd812016-02-02 17:17:23 -07006792TEST_F(VkLayerTest, CommandBufferResetErrors) {
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006793 // Cause error due to Begin while recording CB
6794 // Then cause 2 errors for attempting to reset CB w/o having
6795 // VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT set for the pool from
6796 // which CBs were allocated. Note that this bit is off by default.
Mike Weiblencce7ec72016-10-17 19:33:05 -06006797 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot call Begin on command buffer");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006798
6799 ASSERT_NO_FATAL_FAILURE(InitState());
6800
6801 // Calls AllocateCommandBuffers
6802 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
6803
Karl Schultz6addd812016-02-02 17:17:23 -07006804 // Force the failure by setting the Renderpass and Framebuffer fields with
6805 // (fake) data
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006806 VkCommandBufferBeginInfo cmd_buf_info = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07006807 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006808 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
6809 cmd_buf_info.pNext = NULL;
6810 cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006811 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006812
6813 // Begin CB to transition to recording state
6814 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
6815 // Can't re-begin. This should trigger error
6816 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006817 m_errorMonitor->VerifyFound();
6818
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006819 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to reset command buffer ");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006820 VkCommandBufferResetFlags flags = 0; // Don't care about flags for this test
6821 // Reset attempt will trigger error due to incorrect CommandPool state
6822 vkResetCommandBuffer(commandBuffer.GetBufferHandle(), flags);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006823 m_errorMonitor->VerifyFound();
6824
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006825 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " attempts to implicitly reset cmdBuffer created from ");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006826 // Transition CB to RECORDED state
6827 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
6828 // Now attempting to Begin will implicitly reset, which triggers error
6829 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006830 m_errorMonitor->VerifyFound();
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006831}
6832
Karl Schultz6addd812016-02-02 17:17:23 -07006833TEST_F(VkLayerTest, InvalidPipelineCreateState) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006834 // Attempt to Create Gfx Pipeline w/o a VS
Karl Schultz6addd812016-02-02 17:17:23 -07006835 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006836
Mike Weiblencce7ec72016-10-17 19:33:05 -06006837 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Pipeline CreateInfo State: Vertex Shader required");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006838
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006839 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06006840 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinski209b5292015-09-17 09:44:05 -06006841
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006842 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006843 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6844 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06006845
6846 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006847 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6848 ds_pool_ci.pNext = NULL;
6849 ds_pool_ci.maxSets = 1;
6850 ds_pool_ci.poolSizeCount = 1;
6851 ds_pool_ci.pPoolSizes = &ds_type_count;
Mark Lobodzinski209b5292015-09-17 09:44:05 -06006852
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006853 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006854 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006855 ASSERT_VK_SUCCESS(err);
6856
Tony Barboureb254902015-07-15 12:50:33 -06006857 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006858 dsl_binding.binding = 0;
6859 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6860 dsl_binding.descriptorCount = 1;
6861 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6862 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006863
Tony Barboureb254902015-07-15 12:50:33 -06006864 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006865 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6866 ds_layout_ci.pNext = NULL;
6867 ds_layout_ci.bindingCount = 1;
6868 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06006869
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006870 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006871 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006872 ASSERT_VK_SUCCESS(err);
6873
6874 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006875 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006876 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006877 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06006878 alloc_info.descriptorPool = ds_pool;
6879 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006880 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006881 ASSERT_VK_SUCCESS(err);
6882
Tony Barboureb254902015-07-15 12:50:33 -06006883 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006884 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6885 pipeline_layout_ci.setLayoutCount = 1;
6886 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006887
6888 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006889 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006890 ASSERT_VK_SUCCESS(err);
6891
Tobin Ehlise68360f2015-10-01 11:15:13 -06006892 VkViewport vp = {}; // Just need dummy vp to point to
Karl Schultz6addd812016-02-02 17:17:23 -07006893 VkRect2D sc = {}; // dummy scissor to point to
Tobin Ehlise68360f2015-10-01 11:15:13 -06006894
6895 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006896 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
6897 vp_state_ci.scissorCount = 1;
6898 vp_state_ci.pScissors = &sc;
6899 vp_state_ci.viewportCount = 1;
6900 vp_state_ci.pViewports = &vp;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006901
Karl Schultzdfdb8d42016-03-08 10:30:21 -07006902 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
6903 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
6904 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
6905 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
6906 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
6907 rs_state_ci.depthClampEnable = VK_FALSE;
6908 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
6909 rs_state_ci.depthBiasEnable = VK_FALSE;
6910
Tony Barboureb254902015-07-15 12:50:33 -06006911 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006912 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
6913 gp_ci.pViewportState = &vp_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07006914 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07006915 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
6916 gp_ci.layout = pipeline_layout;
6917 gp_ci.renderPass = renderPass();
Tony Barboureb254902015-07-15 12:50:33 -06006918
6919 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006920 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
6921 pc_ci.initialDataSize = 0;
6922 pc_ci.pInitialData = 0;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006923
6924 VkPipeline pipeline;
Jon Ashburnc669cc62015-07-09 15:02:25 -06006925 VkPipelineCache pipelineCache;
6926
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006927 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Jon Ashburnc669cc62015-07-09 15:02:25 -06006928 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006929 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006930
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006931 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06006932
Chia-I Wuf7458c52015-10-26 21:10:41 +08006933 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
6934 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6935 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6936 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006937}
Tobin Ehlis912df022015-09-17 08:46:18 -06006938/*// TODO : This test should be good, but needs Tess support in compiler to run
6939TEST_F(VkLayerTest, InvalidPatchControlPoints)
6940{
6941 // Attempt to Create Gfx Pipeline w/o a VS
Tobin Ehlis912df022015-09-17 08:46:18 -06006942 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006943
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07006944 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07006945 "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH
6946primitive ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006947
Tobin Ehlis912df022015-09-17 08:46:18 -06006948 ASSERT_NO_FATAL_FAILURE(InitState());
6949 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis912df022015-09-17 08:46:18 -06006950
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006951 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlis912df022015-09-17 08:46:18 -06006952 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08006953 ds_type_count.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06006954
6955 VkDescriptorPoolCreateInfo ds_pool_ci = {};
6956 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6957 ds_pool_ci.pNext = NULL;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006958 ds_pool_ci.poolSizeCount = 1;
6959 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis912df022015-09-17 08:46:18 -06006960
6961 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07006962 err = vkCreateDescriptorPool(m_device->device(),
6963VK_DESCRIPTOR_POOL_USAGE_NON_FREE, 1, &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis912df022015-09-17 08:46:18 -06006964 ASSERT_VK_SUCCESS(err);
6965
6966 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08006967 dsl_binding.binding = 0;
Tobin Ehlis912df022015-09-17 08:46:18 -06006968 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08006969 dsl_binding.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06006970 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6971 dsl_binding.pImmutableSamplers = NULL;
6972
6973 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006974 ds_layout_ci.sType =
6975VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06006976 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08006977 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07006978 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis912df022015-09-17 08:46:18 -06006979
6980 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006981 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
6982&ds_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06006983 ASSERT_VK_SUCCESS(err);
6984
6985 VkDescriptorSet descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -07006986 err = vkAllocateDescriptorSets(m_device->device(), ds_pool,
6987VK_DESCRIPTOR_SET_USAGE_NON_FREE, 1, &ds_layout, &descriptorSet);
Tobin Ehlis912df022015-09-17 08:46:18 -06006988 ASSERT_VK_SUCCESS(err);
6989
6990 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006991 pipeline_layout_ci.sType =
6992VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06006993 pipeline_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08006994 pipeline_layout_ci.setLayoutCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06006995 pipeline_layout_ci.pSetLayouts = &ds_layout;
6996
6997 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006998 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
6999&pipeline_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06007000 ASSERT_VK_SUCCESS(err);
7001
7002 VkPipelineShaderStageCreateInfo shaderStages[3];
7003 memset(&shaderStages, 0, 3 * sizeof(VkPipelineShaderStageCreateInfo));
7004
Karl Schultz6addd812016-02-02 17:17:23 -07007005 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT,
7006this);
Tobin Ehlis912df022015-09-17 08:46:18 -06007007 // Just using VS txt for Tess shaders as we don't care about functionality
Karl Schultz6addd812016-02-02 17:17:23 -07007008 VkShaderObj
7009tc(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT,
7010this);
7011 VkShaderObj
7012te(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT,
7013this);
Tobin Ehlis912df022015-09-17 08:46:18 -06007014
Karl Schultz6addd812016-02-02 17:17:23 -07007015 shaderStages[0].sType =
7016VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06007017 shaderStages[0].stage = VK_SHADER_STAGE_VERTEX_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06007018 shaderStages[0].shader = vs.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07007019 shaderStages[1].sType =
7020VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06007021 shaderStages[1].stage = VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06007022 shaderStages[1].shader = tc.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07007023 shaderStages[2].sType =
7024VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06007025 shaderStages[2].stage = VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06007026 shaderStages[2].shader = te.handle();
7027
7028 VkPipelineInputAssemblyStateCreateInfo iaCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007029 iaCI.sType =
7030VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
Chia-I Wu515eb8f2015-10-31 00:31:16 +08007031 iaCI.topology = VK_PRIMITIVE_TOPOLOGY_PATCH_LIST;
Tobin Ehlis912df022015-09-17 08:46:18 -06007032
7033 VkPipelineTessellationStateCreateInfo tsCI = {};
7034 tsCI.sType = VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO;
7035 tsCI.patchControlPoints = 0; // This will cause an error
7036
7037 VkGraphicsPipelineCreateInfo gp_ci = {};
7038 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7039 gp_ci.pNext = NULL;
7040 gp_ci.stageCount = 3;
7041 gp_ci.pStages = shaderStages;
7042 gp_ci.pVertexInputState = NULL;
7043 gp_ci.pInputAssemblyState = &iaCI;
7044 gp_ci.pTessellationState = &tsCI;
7045 gp_ci.pViewportState = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007046 gp_ci.pRasterizationState = NULL;
Tobin Ehlis912df022015-09-17 08:46:18 -06007047 gp_ci.pMultisampleState = NULL;
7048 gp_ci.pDepthStencilState = NULL;
7049 gp_ci.pColorBlendState = NULL;
7050 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7051 gp_ci.layout = pipeline_layout;
7052 gp_ci.renderPass = renderPass();
7053
7054 VkPipelineCacheCreateInfo pc_ci = {};
7055 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
7056 pc_ci.pNext = NULL;
7057 pc_ci.initialSize = 0;
7058 pc_ci.initialData = 0;
7059 pc_ci.maxSize = 0;
7060
7061 VkPipeline pipeline;
7062 VkPipelineCache pipelineCache;
7063
Karl Schultz6addd812016-02-02 17:17:23 -07007064 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL,
7065&pipelineCache);
Tobin Ehlis912df022015-09-17 08:46:18 -06007066 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07007067 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
7068&gp_ci, NULL, &pipeline);
Tobin Ehlis912df022015-09-17 08:46:18 -06007069
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007070 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06007071
Chia-I Wuf7458c52015-10-26 21:10:41 +08007072 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7073 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7074 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7075 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis912df022015-09-17 08:46:18 -06007076}
7077*/
Tobin Ehlise68360f2015-10-01 11:15:13 -06007078// Set scissor and viewport counts to different numbers
Karl Schultz6addd812016-02-02 17:17:23 -07007079TEST_F(VkLayerTest, PSOViewportScissorCountMismatch) {
Karl Schultz6addd812016-02-02 17:17:23 -07007080 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007081
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007082 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7083 "Gfx Pipeline viewport count (1) must match scissor count (0).");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007084
Tobin Ehlise68360f2015-10-01 11:15:13 -06007085 ASSERT_NO_FATAL_FAILURE(InitState());
7086 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06007087
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007088 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007089 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7090 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007091
7092 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007093 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7094 ds_pool_ci.maxSets = 1;
7095 ds_pool_ci.poolSizeCount = 1;
7096 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007097
7098 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007099 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007100 ASSERT_VK_SUCCESS(err);
7101
7102 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007103 dsl_binding.binding = 0;
7104 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7105 dsl_binding.descriptorCount = 1;
7106 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007107
7108 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007109 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7110 ds_layout_ci.bindingCount = 1;
7111 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007112
7113 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007114 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007115 ASSERT_VK_SUCCESS(err);
7116
7117 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007118 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007119 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007120 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007121 alloc_info.descriptorPool = ds_pool;
7122 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007123 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007124 ASSERT_VK_SUCCESS(err);
7125
7126 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007127 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7128 pipeline_layout_ci.setLayoutCount = 1;
7129 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007130
7131 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007132 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007133 ASSERT_VK_SUCCESS(err);
7134
7135 VkViewport vp = {}; // Just need dummy vp to point to
7136
7137 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007138 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
7139 vp_state_ci.scissorCount = 0;
7140 vp_state_ci.viewportCount = 1; // Count mismatch should cause error
7141 vp_state_ci.pViewports = &vp;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007142
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007143 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
7144 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7145 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
7146 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
7147 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
7148 rs_state_ci.depthClampEnable = VK_FALSE;
7149 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
7150 rs_state_ci.depthBiasEnable = VK_FALSE;
7151
Cody Northropeb3a6c12015-10-05 14:44:45 -06007152 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07007153 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06007154
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007155 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
7156 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
7157 // but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08007158 shaderStages[0] = vs.GetStageCreateInfo();
7159 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007160
7161 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007162 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7163 gp_ci.stageCount = 2;
7164 gp_ci.pStages = shaderStages;
7165 gp_ci.pViewportState = &vp_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007166 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007167 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7168 gp_ci.layout = pipeline_layout;
7169 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007170
7171 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007172 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007173
7174 VkPipeline pipeline;
7175 VkPipelineCache pipelineCache;
7176
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007177 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007178 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007179 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007180
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007181 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007182
Chia-I Wuf7458c52015-10-26 21:10:41 +08007183 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7184 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7185 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7186 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007187}
Karl Schultz6addd812016-02-02 17:17:23 -07007188// Don't set viewport state in PSO. This is an error b/c we always need this
7189// state
Tobin Ehlisd332f282015-10-02 11:00:56 -06007190// for the counts even if the data is going to be set dynamically.
Karl Schultz6addd812016-02-02 17:17:23 -07007191TEST_F(VkLayerTest, PSOViewportStateNotSet) {
Tobin Ehlise68360f2015-10-01 11:15:13 -06007192 // Attempt to Create Gfx Pipeline w/o a VS
Karl Schultz6addd812016-02-02 17:17:23 -07007193 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007194
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007195 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Gfx Pipeline pViewportState is null. Even if ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007196
Tobin Ehlise68360f2015-10-01 11:15:13 -06007197 ASSERT_NO_FATAL_FAILURE(InitState());
7198 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06007199
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007200 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007201 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7202 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007203
7204 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007205 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7206 ds_pool_ci.maxSets = 1;
7207 ds_pool_ci.poolSizeCount = 1;
7208 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007209
7210 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007211 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007212 ASSERT_VK_SUCCESS(err);
7213
7214 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007215 dsl_binding.binding = 0;
7216 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7217 dsl_binding.descriptorCount = 1;
7218 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007219
7220 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007221 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7222 ds_layout_ci.bindingCount = 1;
7223 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007224
7225 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007226 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007227 ASSERT_VK_SUCCESS(err);
7228
7229 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007230 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007231 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007232 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007233 alloc_info.descriptorPool = ds_pool;
7234 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007235 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007236 ASSERT_VK_SUCCESS(err);
7237
7238 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007239 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7240 pipeline_layout_ci.setLayoutCount = 1;
7241 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007242
7243 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007244 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007245 ASSERT_VK_SUCCESS(err);
7246
7247 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
7248 // Set scissor as dynamic to avoid second error
7249 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007250 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
7251 dyn_state_ci.dynamicStateCount = 1;
7252 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007253
Cody Northropeb3a6c12015-10-05 14:44:45 -06007254 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07007255 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06007256
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007257 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
7258 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
7259 // but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08007260 shaderStages[0] = vs.GetStageCreateInfo();
7261 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007262
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007263 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
7264 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7265 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
7266 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
7267 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
7268 rs_state_ci.depthClampEnable = VK_FALSE;
7269 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
7270 rs_state_ci.depthBiasEnable = VK_FALSE;
7271
Tobin Ehlise68360f2015-10-01 11:15:13 -06007272 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007273 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7274 gp_ci.stageCount = 2;
7275 gp_ci.pStages = shaderStages;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007276 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007277 gp_ci.pViewportState = NULL; // Not setting VP state w/o dynamic vp state
7278 // should cause validation error
7279 gp_ci.pDynamicState = &dyn_state_ci;
7280 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7281 gp_ci.layout = pipeline_layout;
7282 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007283
7284 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007285 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007286
7287 VkPipeline pipeline;
7288 VkPipelineCache pipelineCache;
7289
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007290 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007291 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007292 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007293
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007294 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007295
Chia-I Wuf7458c52015-10-26 21:10:41 +08007296 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7297 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7298 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7299 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007300}
7301// Create PSO w/o non-zero viewportCount but no viewport data
Karl Schultz6addd812016-02-02 17:17:23 -07007302// Then run second test where dynamic scissor count doesn't match PSO scissor
7303// count
7304TEST_F(VkLayerTest, PSOViewportCountWithoutDataAndDynScissorMismatch) {
7305 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007306
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007307 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7308 "Gfx Pipeline viewportCount is 1, but pViewports is NULL. ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007309
Tobin Ehlise68360f2015-10-01 11:15:13 -06007310 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007311
7312 if (!m_device->phy().features().multiViewport) {
7313 printf("Device does not support multiple viewports/scissors; skipped.\n");
7314 return;
7315 }
7316
Tobin Ehlise68360f2015-10-01 11:15:13 -06007317 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06007318
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007319 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007320 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7321 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007322
7323 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007324 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7325 ds_pool_ci.maxSets = 1;
7326 ds_pool_ci.poolSizeCount = 1;
7327 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007328
7329 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007330 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007331 ASSERT_VK_SUCCESS(err);
7332
7333 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007334 dsl_binding.binding = 0;
7335 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7336 dsl_binding.descriptorCount = 1;
7337 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007338
7339 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007340 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7341 ds_layout_ci.bindingCount = 1;
7342 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007343
7344 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007345 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007346 ASSERT_VK_SUCCESS(err);
7347
7348 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007349 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007350 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007351 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007352 alloc_info.descriptorPool = ds_pool;
7353 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007354 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007355 ASSERT_VK_SUCCESS(err);
7356
7357 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007358 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7359 pipeline_layout_ci.setLayoutCount = 1;
7360 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007361
7362 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007363 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007364 ASSERT_VK_SUCCESS(err);
7365
7366 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007367 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
7368 vp_state_ci.viewportCount = 1;
7369 vp_state_ci.pViewports = NULL; // Null vp w/ count of 1 should cause error
7370 vp_state_ci.scissorCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007371 vp_state_ci.pScissors = NULL; // Scissor is dynamic (below) so this won't cause error
Tobin Ehlise68360f2015-10-01 11:15:13 -06007372
7373 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
7374 // Set scissor as dynamic to avoid that error
7375 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007376 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
7377 dyn_state_ci.dynamicStateCount = 1;
7378 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007379
Cody Northropeb3a6c12015-10-05 14:44:45 -06007380 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07007381 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06007382
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007383 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
7384 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
7385 // but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08007386 shaderStages[0] = vs.GetStageCreateInfo();
7387 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007388
Cody Northropf6622dc2015-10-06 10:33:21 -06007389 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7390 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7391 vi_ci.pNext = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007392 vi_ci.vertexBindingDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06007393 vi_ci.pVertexBindingDescriptions = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007394 vi_ci.vertexAttributeDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06007395 vi_ci.pVertexAttributeDescriptions = nullptr;
7396
7397 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7398 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7399 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7400
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007401 VkPipelineRasterizationStateCreateInfo rs_ci = {};
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007402 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Cody Northropf6622dc2015-10-06 10:33:21 -06007403 rs_ci.pNext = nullptr;
7404
Mark Youngc89c6312016-03-31 16:03:20 -06007405 VkPipelineColorBlendAttachmentState att = {};
7406 att.blendEnable = VK_FALSE;
7407 att.colorWriteMask = 0xf;
7408
Cody Northropf6622dc2015-10-06 10:33:21 -06007409 VkPipelineColorBlendStateCreateInfo cb_ci = {};
7410 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
7411 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06007412 cb_ci.attachmentCount = 1;
7413 cb_ci.pAttachments = &att;
Cody Northropf6622dc2015-10-06 10:33:21 -06007414
Tobin Ehlise68360f2015-10-01 11:15:13 -06007415 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007416 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7417 gp_ci.stageCount = 2;
7418 gp_ci.pStages = shaderStages;
7419 gp_ci.pVertexInputState = &vi_ci;
7420 gp_ci.pInputAssemblyState = &ia_ci;
7421 gp_ci.pViewportState = &vp_state_ci;
7422 gp_ci.pRasterizationState = &rs_ci;
7423 gp_ci.pColorBlendState = &cb_ci;
7424 gp_ci.pDynamicState = &dyn_state_ci;
7425 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7426 gp_ci.layout = pipeline_layout;
7427 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007428
7429 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007430 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007431
7432 VkPipeline pipeline;
7433 VkPipelineCache pipelineCache;
7434
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007435 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007436 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007437 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007438
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007439 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007440
Tobin Ehlisd332f282015-10-02 11:00:56 -06007441 // Now hit second fail case where we set scissor w/ different count than PSO
Karl Schultz6addd812016-02-02 17:17:23 -07007442 // First need to successfully create the PSO from above by setting
7443 // pViewports
Mike Weiblen95dd0f92016-10-19 12:28:27 -06007444 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 -07007445
7446 VkViewport vp = {}; // Just need dummy vp to point to
7447 vp_state_ci.pViewports = &vp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007448 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Karl Schultz6addd812016-02-02 17:17:23 -07007449 ASSERT_VK_SUCCESS(err);
7450 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007451 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007452 VkRect2D scissors[1] = {}; // don't care about data
Karl Schultz6addd812016-02-02 17:17:23 -07007453 // Count of 2 doesn't match PSO count of 1
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007454 vkCmdSetScissor(m_commandBuffer->GetBufferHandle(), 1, 1, scissors);
Karl Schultz6addd812016-02-02 17:17:23 -07007455 Draw(1, 0, 0, 0);
7456
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007457 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07007458
7459 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7460 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7461 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7462 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06007463 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07007464}
7465// Create PSO w/o non-zero scissorCount but no scissor data
7466// Then run second test where dynamic viewportCount doesn't match PSO
7467// viewportCount
7468TEST_F(VkLayerTest, PSOScissorCountWithoutDataAndDynViewportMismatch) {
7469 VkResult err;
7470
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007471 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Gfx Pipeline scissorCount is 1, but pScissors is NULL. ");
Karl Schultz6addd812016-02-02 17:17:23 -07007472
7473 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007474
7475 if (!m_device->phy().features().multiViewport) {
7476 printf("Device does not support multiple viewports/scissors; skipped.\n");
7477 return;
7478 }
7479
Karl Schultz6addd812016-02-02 17:17:23 -07007480 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7481
7482 VkDescriptorPoolSize ds_type_count = {};
7483 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7484 ds_type_count.descriptorCount = 1;
7485
7486 VkDescriptorPoolCreateInfo ds_pool_ci = {};
7487 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7488 ds_pool_ci.maxSets = 1;
7489 ds_pool_ci.poolSizeCount = 1;
7490 ds_pool_ci.pPoolSizes = &ds_type_count;
7491
7492 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007493 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Karl Schultz6addd812016-02-02 17:17:23 -07007494 ASSERT_VK_SUCCESS(err);
7495
7496 VkDescriptorSetLayoutBinding dsl_binding = {};
7497 dsl_binding.binding = 0;
7498 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7499 dsl_binding.descriptorCount = 1;
7500 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7501
7502 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
7503 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7504 ds_layout_ci.bindingCount = 1;
7505 ds_layout_ci.pBindings = &dsl_binding;
7506
7507 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007508 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Karl Schultz6addd812016-02-02 17:17:23 -07007509 ASSERT_VK_SUCCESS(err);
7510
7511 VkDescriptorSet descriptorSet;
7512 VkDescriptorSetAllocateInfo alloc_info = {};
7513 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
7514 alloc_info.descriptorSetCount = 1;
7515 alloc_info.descriptorPool = ds_pool;
7516 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007517 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Karl Schultz6addd812016-02-02 17:17:23 -07007518 ASSERT_VK_SUCCESS(err);
7519
7520 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
7521 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7522 pipeline_layout_ci.setLayoutCount = 1;
7523 pipeline_layout_ci.pSetLayouts = &ds_layout;
7524
7525 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007526 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultz6addd812016-02-02 17:17:23 -07007527 ASSERT_VK_SUCCESS(err);
7528
7529 VkPipelineViewportStateCreateInfo vp_state_ci = {};
7530 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
7531 vp_state_ci.scissorCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007532 vp_state_ci.pScissors = NULL; // Null scissor w/ count of 1 should cause error
Karl Schultz6addd812016-02-02 17:17:23 -07007533 vp_state_ci.viewportCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007534 vp_state_ci.pViewports = NULL; // vp is dynamic (below) so this won't cause error
Karl Schultz6addd812016-02-02 17:17:23 -07007535
7536 VkDynamicState vp_state = VK_DYNAMIC_STATE_VIEWPORT;
7537 // Set scissor as dynamic to avoid that error
7538 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
7539 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
7540 dyn_state_ci.dynamicStateCount = 1;
7541 dyn_state_ci.pDynamicStates = &vp_state;
7542
7543 VkPipelineShaderStageCreateInfo shaderStages[2];
7544 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
7545
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007546 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
7547 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
7548 // but add it to be able to run on more devices
Karl Schultz6addd812016-02-02 17:17:23 -07007549 shaderStages[0] = vs.GetStageCreateInfo();
7550 shaderStages[1] = fs.GetStageCreateInfo();
7551
7552 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7553 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7554 vi_ci.pNext = nullptr;
7555 vi_ci.vertexBindingDescriptionCount = 0;
7556 vi_ci.pVertexBindingDescriptions = nullptr;
7557 vi_ci.vertexAttributeDescriptionCount = 0;
7558 vi_ci.pVertexAttributeDescriptions = nullptr;
7559
7560 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7561 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7562 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7563
7564 VkPipelineRasterizationStateCreateInfo rs_ci = {};
7565 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7566 rs_ci.pNext = nullptr;
7567
Mark Youngc89c6312016-03-31 16:03:20 -06007568 VkPipelineColorBlendAttachmentState att = {};
7569 att.blendEnable = VK_FALSE;
7570 att.colorWriteMask = 0xf;
7571
Karl Schultz6addd812016-02-02 17:17:23 -07007572 VkPipelineColorBlendStateCreateInfo cb_ci = {};
7573 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
7574 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06007575 cb_ci.attachmentCount = 1;
7576 cb_ci.pAttachments = &att;
Karl Schultz6addd812016-02-02 17:17:23 -07007577
7578 VkGraphicsPipelineCreateInfo gp_ci = {};
7579 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7580 gp_ci.stageCount = 2;
7581 gp_ci.pStages = shaderStages;
7582 gp_ci.pVertexInputState = &vi_ci;
7583 gp_ci.pInputAssemblyState = &ia_ci;
7584 gp_ci.pViewportState = &vp_state_ci;
7585 gp_ci.pRasterizationState = &rs_ci;
7586 gp_ci.pColorBlendState = &cb_ci;
7587 gp_ci.pDynamicState = &dyn_state_ci;
7588 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7589 gp_ci.layout = pipeline_layout;
7590 gp_ci.renderPass = renderPass();
7591
7592 VkPipelineCacheCreateInfo pc_ci = {};
7593 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
7594
7595 VkPipeline pipeline;
7596 VkPipelineCache pipelineCache;
7597
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007598 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Karl Schultz6addd812016-02-02 17:17:23 -07007599 ASSERT_VK_SUCCESS(err);
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
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007602 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07007603
7604 // Now hit second fail case where we set scissor w/ different count than PSO
7605 // First need to successfully create the PSO from above by setting
7606 // pViewports
Mike Weiblen95dd0f92016-10-19 12:28:27 -06007607 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic viewport(s) 0 are used by pipeline state object, ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007608
Tobin Ehlisd332f282015-10-02 11:00:56 -06007609 VkRect2D sc = {}; // Just need dummy vp to point to
7610 vp_state_ci.pScissors = &sc;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007611 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlisd332f282015-10-02 11:00:56 -06007612 ASSERT_VK_SUCCESS(err);
7613 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007614 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007615 VkViewport viewports[1] = {}; // don't care about data
Tobin Ehlisd332f282015-10-02 11:00:56 -06007616 // Count of 2 doesn't match PSO count of 1
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007617 vkCmdSetViewport(m_commandBuffer->GetBufferHandle(), 1, 1, viewports);
Tobin Ehlisd332f282015-10-02 11:00:56 -06007618 Draw(1, 0, 0, 0);
7619
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007620 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007621
Chia-I Wuf7458c52015-10-26 21:10:41 +08007622 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7623 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7624 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7625 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06007626 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007627}
7628
Mark Young7394fdd2016-03-31 14:56:43 -06007629TEST_F(VkLayerTest, PSOLineWidthInvalid) {
7630 VkResult err;
7631
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007632 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to -1");
Mark Young7394fdd2016-03-31 14:56:43 -06007633
7634 ASSERT_NO_FATAL_FAILURE(InitState());
7635 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7636
7637 VkDescriptorPoolSize ds_type_count = {};
7638 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7639 ds_type_count.descriptorCount = 1;
7640
7641 VkDescriptorPoolCreateInfo ds_pool_ci = {};
7642 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7643 ds_pool_ci.maxSets = 1;
7644 ds_pool_ci.poolSizeCount = 1;
7645 ds_pool_ci.pPoolSizes = &ds_type_count;
7646
7647 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007648 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Mark Young7394fdd2016-03-31 14:56:43 -06007649 ASSERT_VK_SUCCESS(err);
7650
7651 VkDescriptorSetLayoutBinding dsl_binding = {};
7652 dsl_binding.binding = 0;
7653 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7654 dsl_binding.descriptorCount = 1;
7655 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7656
7657 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
7658 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7659 ds_layout_ci.bindingCount = 1;
7660 ds_layout_ci.pBindings = &dsl_binding;
7661
7662 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007663 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Young7394fdd2016-03-31 14:56:43 -06007664 ASSERT_VK_SUCCESS(err);
7665
7666 VkDescriptorSet descriptorSet;
7667 VkDescriptorSetAllocateInfo alloc_info = {};
7668 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
7669 alloc_info.descriptorSetCount = 1;
7670 alloc_info.descriptorPool = ds_pool;
7671 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007672 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Young7394fdd2016-03-31 14:56:43 -06007673 ASSERT_VK_SUCCESS(err);
7674
7675 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
7676 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7677 pipeline_layout_ci.setLayoutCount = 1;
7678 pipeline_layout_ci.pSetLayouts = &ds_layout;
7679
7680 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007681 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Mark Young7394fdd2016-03-31 14:56:43 -06007682 ASSERT_VK_SUCCESS(err);
7683
7684 VkPipelineViewportStateCreateInfo vp_state_ci = {};
7685 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
7686 vp_state_ci.scissorCount = 1;
7687 vp_state_ci.pScissors = NULL;
7688 vp_state_ci.viewportCount = 1;
7689 vp_state_ci.pViewports = NULL;
7690
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007691 VkDynamicState dynamic_states[3] = {VK_DYNAMIC_STATE_VIEWPORT, VK_DYNAMIC_STATE_SCISSOR, VK_DYNAMIC_STATE_LINE_WIDTH};
Mark Young7394fdd2016-03-31 14:56:43 -06007692 // Set scissor as dynamic to avoid that error
7693 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
7694 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
7695 dyn_state_ci.dynamicStateCount = 2;
7696 dyn_state_ci.pDynamicStates = dynamic_states;
7697
7698 VkPipelineShaderStageCreateInfo shaderStages[2];
7699 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
7700
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007701 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
7702 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT,
Mark Young7394fdd2016-03-31 14:56:43 -06007703 this); // TODO - We shouldn't need a fragment shader
7704 // but add it to be able to run on more devices
7705 shaderStages[0] = vs.GetStageCreateInfo();
7706 shaderStages[1] = fs.GetStageCreateInfo();
7707
7708 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7709 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7710 vi_ci.pNext = nullptr;
7711 vi_ci.vertexBindingDescriptionCount = 0;
7712 vi_ci.pVertexBindingDescriptions = nullptr;
7713 vi_ci.vertexAttributeDescriptionCount = 0;
7714 vi_ci.pVertexAttributeDescriptions = nullptr;
7715
7716 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7717 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7718 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7719
7720 VkPipelineRasterizationStateCreateInfo rs_ci = {};
7721 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7722 rs_ci.pNext = nullptr;
7723
Mark Young47107952016-05-02 15:59:55 -06007724 // Check too low (line width of -1.0f).
7725 rs_ci.lineWidth = -1.0f;
Mark Young7394fdd2016-03-31 14:56:43 -06007726
7727 VkPipelineColorBlendAttachmentState att = {};
7728 att.blendEnable = VK_FALSE;
7729 att.colorWriteMask = 0xf;
7730
7731 VkPipelineColorBlendStateCreateInfo cb_ci = {};
7732 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
7733 cb_ci.pNext = nullptr;
7734 cb_ci.attachmentCount = 1;
7735 cb_ci.pAttachments = &att;
7736
7737 VkGraphicsPipelineCreateInfo gp_ci = {};
7738 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7739 gp_ci.stageCount = 2;
7740 gp_ci.pStages = shaderStages;
7741 gp_ci.pVertexInputState = &vi_ci;
7742 gp_ci.pInputAssemblyState = &ia_ci;
7743 gp_ci.pViewportState = &vp_state_ci;
7744 gp_ci.pRasterizationState = &rs_ci;
7745 gp_ci.pColorBlendState = &cb_ci;
7746 gp_ci.pDynamicState = &dyn_state_ci;
7747 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7748 gp_ci.layout = pipeline_layout;
7749 gp_ci.renderPass = renderPass();
7750
7751 VkPipelineCacheCreateInfo pc_ci = {};
7752 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
7753
7754 VkPipeline pipeline;
7755 VkPipelineCache pipelineCache;
7756
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007757 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06007758 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007759 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06007760
7761 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06007762 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06007763
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007764 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to 65536");
Mark Young7394fdd2016-03-31 14:56:43 -06007765
7766 // Check too high (line width of 65536.0f).
7767 rs_ci.lineWidth = 65536.0f;
7768
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007769 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06007770 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007771 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06007772
7773 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06007774 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06007775
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007776 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to -1");
Mark Young7394fdd2016-03-31 14:56:43 -06007777
7778 dyn_state_ci.dynamicStateCount = 3;
7779
7780 rs_ci.lineWidth = 1.0f;
7781
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007782 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06007783 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007784 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06007785 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007786 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06007787
7788 // Check too low with dynamic setting.
Mark Young47107952016-05-02 15:59:55 -06007789 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), -1.0f);
Mark Young7394fdd2016-03-31 14:56:43 -06007790 m_errorMonitor->VerifyFound();
7791
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007792 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to 65536");
Mark Young7394fdd2016-03-31 14:56:43 -06007793
7794 // Check too high with dynamic setting.
7795 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), 65536.0f);
7796 m_errorMonitor->VerifyFound();
7797 EndCommandBuffer();
7798
7799 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7800 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7801 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7802 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06007803 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06007804}
7805
Karl Schultz6addd812016-02-02 17:17:23 -07007806TEST_F(VkLayerTest, NullRenderPass) {
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007807 // Bind a NULL RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007808 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7809 "You cannot use a NULL RenderPass object in vkCmdBeginRenderPass()");
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007810
7811 ASSERT_NO_FATAL_FAILURE(InitState());
7812 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007813
Tony Barbourfe3351b2015-07-28 10:17:20 -06007814 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07007815 // Don't care about RenderPass handle b/c error should be flagged before
7816 // that
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007817 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), NULL, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007818
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007819 m_errorMonitor->VerifyFound();
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007820}
7821
Karl Schultz6addd812016-02-02 17:17:23 -07007822TEST_F(VkLayerTest, RenderPassWithinRenderPass) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007823 // Bind a BeginRenderPass within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007824 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7825 "It is invalid to issue this call inside an active render pass");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007826
7827 ASSERT_NO_FATAL_FAILURE(InitState());
7828 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007829
Tony Barbourfe3351b2015-07-28 10:17:20 -06007830 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07007831 // Just create a dummy Renderpass that's non-NULL so we can get to the
7832 // proper error
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007833 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007834
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007835 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06007836}
7837
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06007838TEST_F(VkLayerTest, RenderPassClearOpMismatch) {
7839 TEST_DESCRIPTION("Begin a renderPass where clearValueCount is less than"
7840 "the number of renderPass attachments that use loadOp"
7841 "VK_ATTACHMENT_LOAD_OP_CLEAR.");
7842
7843 ASSERT_NO_FATAL_FAILURE(InitState());
7844 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7845
7846 // Create a renderPass with a single attachment that uses loadOp CLEAR
7847 VkAttachmentReference attach = {};
7848 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
7849 VkSubpassDescription subpass = {};
7850 subpass.inputAttachmentCount = 1;
7851 subpass.pInputAttachments = &attach;
7852 VkRenderPassCreateInfo rpci = {};
7853 rpci.subpassCount = 1;
7854 rpci.pSubpasses = &subpass;
7855 rpci.attachmentCount = 1;
7856 VkAttachmentDescription attach_desc = {};
7857 attach_desc.format = VK_FORMAT_UNDEFINED;
7858 // Set loadOp to CLEAR
7859 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
7860 rpci.pAttachments = &attach_desc;
7861 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
7862 VkRenderPass rp;
7863 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
7864
7865 VkCommandBufferInheritanceInfo hinfo = {};
7866 hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
7867 hinfo.renderPass = VK_NULL_HANDLE;
7868 hinfo.subpass = 0;
7869 hinfo.framebuffer = VK_NULL_HANDLE;
7870 hinfo.occlusionQueryEnable = VK_FALSE;
7871 hinfo.queryFlags = 0;
7872 hinfo.pipelineStatistics = 0;
7873 VkCommandBufferBeginInfo info = {};
7874 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
7875 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
7876 info.pInheritanceInfo = &hinfo;
7877
7878 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
7879 VkRenderPassBeginInfo rp_begin = {};
7880 rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
7881 rp_begin.pNext = NULL;
7882 rp_begin.renderPass = renderPass();
7883 rp_begin.framebuffer = framebuffer();
7884 rp_begin.clearValueCount = 0; // Should be 1
7885
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007886 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has a clearValueCount of 0 but "
7887 "there must be at least 1 entries in "
7888 "pClearValues array to account for ");
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06007889
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007890 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rp_begin, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06007891
7892 m_errorMonitor->VerifyFound();
Mark Lobodzinski5c70ebd2016-06-09 13:45:00 -06007893
7894 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06007895}
7896
Slawomir Cygan0808f392016-11-28 17:53:23 +01007897TEST_F(VkLayerTest, RenderPassClearOpTooManyValues) {
7898 TEST_DESCRIPTION("Begin a renderPass where clearValueCount is greater than"
7899 "the number of renderPass attachments that use loadOp"
7900 "VK_ATTACHMENT_LOAD_OP_CLEAR.");
7901
7902 ASSERT_NO_FATAL_FAILURE(InitState());
7903 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7904
7905 // Create a renderPass with a single attachment that uses loadOp CLEAR
7906 VkAttachmentReference attach = {};
7907 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
7908 VkSubpassDescription subpass = {};
7909 subpass.inputAttachmentCount = 1;
7910 subpass.pInputAttachments = &attach;
7911 VkRenderPassCreateInfo rpci = {};
7912 rpci.subpassCount = 1;
7913 rpci.pSubpasses = &subpass;
7914 rpci.attachmentCount = 1;
7915 VkAttachmentDescription attach_desc = {};
7916 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
7917 // Set loadOp to CLEAR
7918 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
7919 rpci.pAttachments = &attach_desc;
7920 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
7921 VkRenderPass rp;
7922 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
7923
7924 VkCommandBufferBeginInfo info = {};
7925 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
7926 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
7927
7928 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
7929 VkRenderPassBeginInfo rp_begin = {};
7930 rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
7931 rp_begin.pNext = NULL;
7932 rp_begin.renderPass = renderPass();
7933 rp_begin.framebuffer = framebuffer();
7934 rp_begin.clearValueCount = 2; // Should be 1
7935
7936 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, " has a clearValueCount of"
7937 " 2 but only first 1 entries in pClearValues array are used");
7938
7939 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rp_begin, VK_SUBPASS_CONTENTS_INLINE);
7940
7941 m_errorMonitor->VerifyFound();
7942
7943 vkDestroyRenderPass(m_device->device(), rp, NULL);
7944}
7945
7946
Cody Northrop3bb4d962016-05-09 16:15:57 -06007947TEST_F(VkLayerTest, EndCommandBufferWithinRenderPass) {
7948
7949 TEST_DESCRIPTION("End a command buffer with an active render pass");
7950
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007951 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7952 "It is invalid to issue this call inside an active render pass");
Cody Northrop3bb4d962016-05-09 16:15:57 -06007953
7954 ASSERT_NO_FATAL_FAILURE(InitState());
7955 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7956
7957 // The framework's BeginCommandBuffer calls CreateRenderPass
7958 BeginCommandBuffer();
7959
7960 // Call directly into vkEndCommandBuffer instead of the
7961 // the framework's EndCommandBuffer, which inserts a
7962 // vkEndRenderPass
7963 vkEndCommandBuffer(m_commandBuffer->GetBufferHandle());
7964
7965 m_errorMonitor->VerifyFound();
7966
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007967 // TODO: Add test for VK_COMMAND_BUFFER_LEVEL_SECONDARY
7968 // TODO: Add test for VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT
Cody Northrop3bb4d962016-05-09 16:15:57 -06007969}
7970
Karl Schultz6addd812016-02-02 17:17:23 -07007971TEST_F(VkLayerTest, FillBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007972 // Call CmdFillBuffer within an active renderpass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007973 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7974 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007975
7976 ASSERT_NO_FATAL_FAILURE(InitState());
7977 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007978
7979 // Renderpass is started here
7980 BeginCommandBuffer();
7981
7982 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007983 vk_testing::Buffer dstBuffer;
7984 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007985
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007986 m_commandBuffer->FillBuffer(dstBuffer.handle(), 0, 4, 0x11111111);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007987
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007988 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007989}
7990
Karl Schultz6addd812016-02-02 17:17:23 -07007991TEST_F(VkLayerTest, UpdateBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007992 // Call CmdUpdateBuffer within an active renderpass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007993 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7994 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007995
7996 ASSERT_NO_FATAL_FAILURE(InitState());
7997 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007998
7999 // Renderpass is started here
8000 BeginCommandBuffer();
8001
8002 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008003 vk_testing::Buffer dstBuffer;
8004 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008005
Karl Schultz6addd812016-02-02 17:17:23 -07008006 VkDeviceSize dstOffset = 0;
8007 VkDeviceSize dataSize = 1024;
Karl Schultzee344492016-07-11 15:09:57 -06008008 const void *pData = NULL;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008009
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008010 vkCmdUpdateBuffer(m_commandBuffer->GetBufferHandle(), dstBuffer.handle(), dstOffset, dataSize, pData);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008011
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008012 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008013}
8014
Karl Schultz6addd812016-02-02 17:17:23 -07008015TEST_F(VkLayerTest, ClearColorImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008016 // Call CmdClearColorImage within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008017 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8018 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008019
8020 ASSERT_NO_FATAL_FAILURE(InitState());
8021 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008022
8023 // Renderpass is started here
8024 BeginCommandBuffer();
8025
Michael Lentine0a369f62016-02-03 16:51:46 -06008026 VkClearColorValue clear_color;
8027 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
Karl Schultz6addd812016-02-02 17:17:23 -07008028 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
8029 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
8030 const int32_t tex_width = 32;
8031 const int32_t tex_height = 32;
8032 VkImageCreateInfo image_create_info = {};
8033 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
8034 image_create_info.pNext = NULL;
8035 image_create_info.imageType = VK_IMAGE_TYPE_2D;
8036 image_create_info.format = tex_format;
8037 image_create_info.extent.width = tex_width;
8038 image_create_info.extent.height = tex_height;
8039 image_create_info.extent.depth = 1;
8040 image_create_info.mipLevels = 1;
8041 image_create_info.arrayLayers = 1;
8042 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
8043 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
8044 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008045
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008046 vk_testing::Image dstImage;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008047 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008048
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008049 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008050
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008051 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1, &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008052
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008053 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008054}
8055
Karl Schultz6addd812016-02-02 17:17:23 -07008056TEST_F(VkLayerTest, ClearDepthStencilImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008057 // Call CmdClearDepthStencilImage within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008058 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8059 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008060
8061 ASSERT_NO_FATAL_FAILURE(InitState());
8062 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008063
8064 // Renderpass is started here
8065 BeginCommandBuffer();
8066
8067 VkClearDepthStencilValue clear_value = {0};
Dustin Gravesa2e5c942016-02-11 18:28:06 -07008068 VkMemoryPropertyFlags reqs = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07008069 VkImageCreateInfo image_create_info = vk_testing::Image::create_info();
8070 image_create_info.imageType = VK_IMAGE_TYPE_2D;
8071 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
8072 image_create_info.extent.width = 64;
8073 image_create_info.extent.height = 64;
8074 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
8075 image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008076
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008077 vk_testing::Image dstImage;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008078 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008079
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008080 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_DEPTH_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008081
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008082 vkCmdClearDepthStencilImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(),
8083 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, &clear_value, 1, &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008084
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008085 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008086}
8087
Karl Schultz6addd812016-02-02 17:17:23 -07008088TEST_F(VkLayerTest, ClearColorAttachmentsOutsideRenderPass) {
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06008089 // Call CmdClearAttachmentss outside of an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07008090 VkResult err;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008091
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008092 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdClearAttachments(): This call "
8093 "must be issued inside an active "
8094 "render pass");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008095
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008096 ASSERT_NO_FATAL_FAILURE(InitState());
8097 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008098
8099 // Start no RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008100 err = m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008101 ASSERT_VK_SUCCESS(err);
8102
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06008103 VkClearAttachment color_attachment;
8104 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8105 color_attachment.clearValue.color.float32[0] = 0;
8106 color_attachment.clearValue.color.float32[1] = 0;
8107 color_attachment.clearValue.color.float32[2] = 0;
8108 color_attachment.clearValue.color.float32[3] = 0;
8109 color_attachment.colorAttachment = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07008110 VkClearRect clear_rect = {{{0, 0}, {32, 32}}};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008111 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008112
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008113 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008114}
8115
Chris Forbes3b97e932016-09-07 11:29:24 +12008116TEST_F(VkLayerTest, RenderPassExcessiveNextSubpass) {
8117 TEST_DESCRIPTION("Test that an error is produced when CmdNextSubpass is "
8118 "called too many times in a renderpass instance");
8119
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008120 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdNextSubpass(): Attempted to advance "
8121 "beyond final subpass");
Chris Forbes3b97e932016-09-07 11:29:24 +12008122
8123 ASSERT_NO_FATAL_FAILURE(InitState());
8124 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8125
8126 BeginCommandBuffer();
8127
8128 // error here.
8129 vkCmdNextSubpass(m_commandBuffer->GetBufferHandle(), VK_SUBPASS_CONTENTS_INLINE);
8130 m_errorMonitor->VerifyFound();
8131
8132 EndCommandBuffer();
8133}
8134
Chris Forbes6d624702016-09-07 13:57:05 +12008135TEST_F(VkLayerTest, RenderPassEndedBeforeFinalSubpass) {
8136 TEST_DESCRIPTION("Test that an error is produced when CmdEndRenderPass is "
8137 "called before the final subpass has been reached");
8138
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008139 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdEndRenderPass(): Called before reaching "
8140 "final subpass");
Chris Forbes6d624702016-09-07 13:57:05 +12008141
8142 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008143 VkSubpassDescription sd[2] = {{0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr},
8144 {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr}};
Chris Forbes6d624702016-09-07 13:57:05 +12008145
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008146 VkRenderPassCreateInfo rcpi = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 2, sd, 0, nullptr};
Chris Forbes6d624702016-09-07 13:57:05 +12008147
8148 VkRenderPass rp;
8149 VkResult err = vkCreateRenderPass(m_device->device(), &rcpi, nullptr, &rp);
8150 ASSERT_VK_SUCCESS(err);
8151
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008152 VkFramebufferCreateInfo fbci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 0, nullptr, 16, 16, 1};
Chris Forbes6d624702016-09-07 13:57:05 +12008153
8154 VkFramebuffer fb;
8155 err = vkCreateFramebuffer(m_device->device(), &fbci, nullptr, &fb);
8156 ASSERT_VK_SUCCESS(err);
8157
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008158 m_commandBuffer->BeginCommandBuffer(); // no implicit RP begin
Chris Forbes6d624702016-09-07 13:57:05 +12008159
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008160 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 +12008161
8162 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
8163
8164 // Error here.
8165 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
8166 m_errorMonitor->VerifyFound();
8167
8168 // Clean up.
8169 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
8170 vkDestroyRenderPass(m_device->device(), rp, nullptr);
8171}
8172
Karl Schultz9e66a292016-04-21 15:57:51 -06008173TEST_F(VkLayerTest, BufferMemoryBarrierNoBuffer) {
8174 // Try to add a buffer memory barrier with no buffer.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008175 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8176 "required parameter pBufferMemoryBarriers[0].buffer specified as VK_NULL_HANDLE");
Karl Schultz9e66a292016-04-21 15:57:51 -06008177
8178 ASSERT_NO_FATAL_FAILURE(InitState());
8179 BeginCommandBuffer();
8180
8181 VkBufferMemoryBarrier buf_barrier = {};
8182 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
8183 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8184 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
8185 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8186 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8187 buf_barrier.buffer = VK_NULL_HANDLE;
8188 buf_barrier.offset = 0;
8189 buf_barrier.size = VK_WHOLE_SIZE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008190 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8191 nullptr, 1, &buf_barrier, 0, nullptr);
Karl Schultz9e66a292016-04-21 15:57:51 -06008192
8193 m_errorMonitor->VerifyFound();
8194}
8195
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008196TEST_F(VkLayerTest, InvalidBarriers) {
8197 TEST_DESCRIPTION("A variety of ways to get VK_INVALID_BARRIER ");
8198
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008199 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Barriers cannot be set during subpass");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008200
8201 ASSERT_NO_FATAL_FAILURE(InitState());
8202 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8203
8204 VkMemoryBarrier mem_barrier = {};
8205 mem_barrier.sType = VK_STRUCTURE_TYPE_MEMORY_BARRIER;
8206 mem_barrier.pNext = NULL;
8207 mem_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8208 mem_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
8209 BeginCommandBuffer();
8210 // BeginCommandBuffer() starts a render pass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008211 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 1,
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008212 &mem_barrier, 0, nullptr, 0, nullptr);
8213 m_errorMonitor->VerifyFound();
8214
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008215 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Image Layout cannot be transitioned to UNDEFINED");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008216 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008217 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 -06008218 ASSERT_TRUE(image.initialized());
8219 VkImageMemoryBarrier img_barrier = {};
8220 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
8221 img_barrier.pNext = NULL;
8222 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8223 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
8224 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8225 // New layout can't be UNDEFINED
8226 img_barrier.newLayout = VK_IMAGE_LAYOUT_UNDEFINED;
8227 img_barrier.image = image.handle();
8228 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8229 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8230 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8231 img_barrier.subresourceRange.baseArrayLayer = 0;
8232 img_barrier.subresourceRange.baseMipLevel = 0;
8233 img_barrier.subresourceRange.layerCount = 1;
8234 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008235 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8236 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008237 m_errorMonitor->VerifyFound();
8238 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8239
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008240 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Subresource must have the sum of the "
8241 "baseArrayLayer");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008242 // baseArrayLayer + layerCount must be <= image's arrayLayers
8243 img_barrier.subresourceRange.baseArrayLayer = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008244 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8245 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008246 m_errorMonitor->VerifyFound();
8247 img_barrier.subresourceRange.baseArrayLayer = 0;
8248
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008249 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Subresource must have the sum of the baseMipLevel");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008250 // baseMipLevel + levelCount must be <= image's mipLevels
8251 img_barrier.subresourceRange.baseMipLevel = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008252 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8253 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008254 m_errorMonitor->VerifyFound();
8255 img_barrier.subresourceRange.baseMipLevel = 0;
8256
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008257 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 -06008258 vk_testing::Buffer buffer;
Mark Lobodzinskibdf378a2016-12-12 17:11:50 -07008259 VkMemoryPropertyFlags mem_reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
8260 buffer.init_as_src_and_dst(*m_device, 256, mem_reqs);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008261 VkBufferMemoryBarrier buf_barrier = {};
8262 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
8263 buf_barrier.pNext = NULL;
8264 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8265 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
8266 buf_barrier.buffer = buffer.handle();
8267 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8268 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8269 buf_barrier.offset = 0;
8270 buf_barrier.size = VK_WHOLE_SIZE;
8271 // Can't send buffer barrier during a render pass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008272 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8273 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008274 m_errorMonitor->VerifyFound();
8275 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
8276
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008277 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "which is not less than total size");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008278 buf_barrier.offset = 257;
8279 // Offset greater than total size
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008280 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8281 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008282 m_errorMonitor->VerifyFound();
8283 buf_barrier.offset = 0;
8284
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008285 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "whose sum is greater than total size");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008286 buf_barrier.size = 257;
8287 // Size greater than total size
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008288 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8289 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008290 m_errorMonitor->VerifyFound();
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008291
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008292 // Now exercise barrier aspect bit errors, first DS
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06008293 m_errorMonitor->SetDesiredFailureMsg(
8294 VK_DEBUG_REPORT_ERROR_BIT_EXT,
8295 "Combination depth/stencil image formats can have only the VK_IMAGE_ASPECT_DEPTH_BIT and VK_IMAGE_ASPECT_STENCIL_BIT set.");
8296 m_errorMonitor->SetDesiredFailureMsg(
8297 VK_DEBUG_REPORT_ERROR_BIT_EXT,
8298 "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 -06008299 VkDepthStencilObj ds_image(m_device);
8300 ds_image.Init(m_device, 128, 128, VK_FORMAT_D24_UNORM_S8_UINT);
8301 ASSERT_TRUE(ds_image.initialized());
Tobin Ehlis15684a02016-07-21 14:55:26 -06008302 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
8303 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008304 img_barrier.image = ds_image.handle();
Tobin Ehlis15684a02016-07-21 14:55:26 -06008305 // Use of COLOR aspect on DS image is error
8306 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008307 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8308 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008309 m_errorMonitor->VerifyFound();
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008310 // Now test depth-only
8311 VkFormatProperties format_props;
8312
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008313 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_D16_UNORM, &format_props);
8314 if (format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) {
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06008315 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8316 "Depth-only image formats must have the VK_IMAGE_ASPECT_DEPTH_BIT set.");
8317 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8318 "Depth-only image formats can have only the VK_IMAGE_ASPECT_DEPTH_BIT set.");
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008319 VkDepthStencilObj d_image(m_device);
8320 d_image.Init(m_device, 128, 128, VK_FORMAT_D16_UNORM);
8321 ASSERT_TRUE(d_image.initialized());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008322 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
Tobin Ehlis15684a02016-07-21 14:55:26 -06008323 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008324 img_barrier.image = d_image.handle();
Tobin Ehlis15684a02016-07-21 14:55:26 -06008325 // Use of COLOR aspect on depth image is error
8326 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008327 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
8328 0, nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008329 m_errorMonitor->VerifyFound();
8330 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008331 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_S8_UINT, &format_props);
8332 if (format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) {
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008333 // Now test stencil-only
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06008334 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8335 "Stencil-only image formats must have the VK_IMAGE_ASPECT_STENCIL_BIT set.");
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008336 VkDepthStencilObj s_image(m_device);
8337 s_image.Init(m_device, 128, 128, VK_FORMAT_S8_UINT);
8338 ASSERT_TRUE(s_image.initialized());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008339 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
Tobin Ehlis15684a02016-07-21 14:55:26 -06008340 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008341 img_barrier.image = s_image.handle();
Tobin Ehlis15684a02016-07-21 14:55:26 -06008342 // Use of COLOR aspect on depth image is error
8343 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008344 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
8345 0, nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008346 m_errorMonitor->VerifyFound();
8347 }
8348 // Finally test color
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06008349 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8350 "Color image formats must have the VK_IMAGE_ASPECT_COLOR_BIT set.");
8351 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8352 "Color image formats must have ONLY the VK_IMAGE_ASPECT_COLOR_BIT set.");
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008353 VkImageObj c_image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008354 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 -06008355 ASSERT_TRUE(c_image.initialized());
8356 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8357 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
8358 img_barrier.image = c_image.handle();
8359 // Set aspect to depth (non-color)
8360 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008361 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8362 nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008363 m_errorMonitor->VerifyFound();
Mark Lobodzinskibdf378a2016-12-12 17:11:50 -07008364
8365 // Attempt to mismatch barriers/waitEvents calls with incompatible queues
8366
8367 // Create command pool with incompatible queueflags
8368 const std::vector<VkQueueFamilyProperties> queue_props = m_device->queue_props;
8369 uint32_t queue_family_index = UINT32_MAX;
8370 for (uint32_t i = 0; i < queue_props.size(); i++) {
8371 if ((queue_props[i].queueFlags & VK_QUEUE_COMPUTE_BIT) == 0) {
8372 queue_family_index = i;
8373 break;
8374 }
8375 }
8376 if (queue_family_index == UINT32_MAX) {
8377 printf("No non-compute queue found; skipped.\n");
8378 return;
8379 }
8380 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02513);
8381
8382 VkCommandPool command_pool;
8383 VkCommandPoolCreateInfo pool_create_info{};
8384 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
8385 pool_create_info.queueFamilyIndex = queue_family_index;
8386 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
8387 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
8388
8389 // Allocate a command buffer
8390 VkCommandBuffer bad_command_buffer;
8391 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
8392 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
8393 command_buffer_allocate_info.commandPool = command_pool;
8394 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
8395 command_buffer_allocate_info.commandBufferCount = 1;
8396 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &bad_command_buffer));
8397
8398 VkCommandBufferBeginInfo cbbi = {};
8399 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
8400 vkBeginCommandBuffer(bad_command_buffer, &cbbi);
8401 buf_barrier.offset = 0;
8402 buf_barrier.size = VK_WHOLE_SIZE;
8403 vkCmdPipelineBarrier(bad_command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 1,
8404 &buf_barrier, 0, nullptr);
8405 m_errorMonitor->VerifyFound();
8406
8407 if ((queue_props[queue_family_index].queueFlags & VK_QUEUE_GRAPHICS_BIT) == 0) {
8408 vkEndCommandBuffer(bad_command_buffer);
8409 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
8410 printf("The non-compute queue does not support graphics; skipped.\n");
8411 return;
8412 }
8413 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02510);
8414 VkEvent event;
8415 VkEventCreateInfo event_create_info{};
8416 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
8417 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
8418 vkCmdWaitEvents(bad_command_buffer, 1, &event, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, nullptr, 0,
8419 nullptr, 0, nullptr);
8420 m_errorMonitor->VerifyFound();
8421
8422 vkEndCommandBuffer(bad_command_buffer);
8423 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008424}
8425
Tony Barbour18ba25c2016-09-29 13:42:40 -06008426TEST_F(VkLayerTest, LayoutFromPresentWithoutAccessMemoryRead) {
8427 // Transition an image away from PRESENT_SRC_KHR without ACCESS_MEMORY_READ in srcAccessMask
8428
8429 m_errorMonitor->SetDesiredFailureMsg(
8430 VK_DEBUG_REPORT_WARNING_BIT_EXT,
8431 "must have required access bit");
8432 ASSERT_NO_FATAL_FAILURE(InitState());
8433 VkImageObj image(m_device);
Tony Barbour256c80a2016-10-05 13:23:46 -06008434 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 -06008435 ASSERT_TRUE(image.initialized());
8436
8437 VkImageMemoryBarrier barrier = {};
8438 VkImageSubresourceRange range;
8439 barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
8440 barrier.srcAccessMask = 0;
8441 barrier.srcAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
8442 barrier.dstAccessMask = VK_ACCESS_MEMORY_READ_BIT;
8443 barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8444 barrier.newLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
8445 barrier.image = image.handle();
8446 range.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8447 range.baseMipLevel = 0;
8448 range.levelCount = 1;
8449 range.baseArrayLayer = 0;
8450 range.layerCount = 1;
8451 barrier.subresourceRange = range;
8452 VkCommandBufferObj cmdbuf(m_device, m_commandPool);
8453 cmdbuf.BeginCommandBuffer();
8454 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
8455 &barrier);
8456 barrier.oldLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
8457 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
8458 barrier.srcAccessMask = 0;
8459 barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
8460 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
8461 &barrier);
8462
8463 m_errorMonitor->VerifyFound();
8464}
8465
Karl Schultz6addd812016-02-02 17:17:23 -07008466TEST_F(VkLayerTest, IdxBufferAlignmentError) {
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008467 // Bind a BeginRenderPass within an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07008468 VkResult err;
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008469
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008470 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdBindIndexBuffer() offset (0x7) does not fall on ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008471
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008472 ASSERT_NO_FATAL_FAILURE(InitState());
8473 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008474 uint32_t qfi = 0;
8475 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008476 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
8477 buffCI.size = 1024;
8478 buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
8479 buffCI.queueFamilyIndexCount = 1;
8480 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008481
8482 VkBuffer ib;
Chia-I Wuf7458c52015-10-26 21:10:41 +08008483 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008484 ASSERT_VK_SUCCESS(err);
8485
8486 BeginCommandBuffer();
8487 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07008488 // vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
8489 // VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008490 // Should error before calling to driver so don't care about actual data
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008491 vkCmdBindIndexBuffer(m_commandBuffer->GetBufferHandle(), ib, 7, VK_INDEX_TYPE_UINT16);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008492
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008493 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06008494
Chia-I Wuf7458c52015-10-26 21:10:41 +08008495 vkDestroyBuffer(m_device->device(), ib, NULL);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008496}
8497
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07008498TEST_F(VkLayerTest, InvalidQueueFamilyIndex) {
8499 // Create an out-of-range queueFamilyIndex
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008500 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8501 "vkCreateBuffer: pCreateInfo->pQueueFamilyIndices[0] (777) must be one "
8502 "of the indices specified when the device was created, via the "
8503 "VkDeviceQueueCreateInfo structure.");
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07008504
8505 ASSERT_NO_FATAL_FAILURE(InitState());
8506 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8507 VkBufferCreateInfo buffCI = {};
8508 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
8509 buffCI.size = 1024;
8510 buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
8511 buffCI.queueFamilyIndexCount = 1;
8512 // Introduce failure by specifying invalid queue_family_index
8513 uint32_t qfi = 777;
8514 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis24aab042016-03-24 10:54:18 -06008515 buffCI.sharingMode = VK_SHARING_MODE_CONCURRENT; // qfi only matters in CONCURRENT mode
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07008516
8517 VkBuffer ib;
8518 vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
8519
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008520 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06008521 vkDestroyBuffer(m_device->device(), ib, NULL);
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07008522}
8523
Karl Schultz6addd812016-02-02 17:17:23 -07008524TEST_F(VkLayerTest, ExecuteCommandsPrimaryCB) {
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -06008525TEST_DESCRIPTION("Attempt vkCmdExecuteCommands with a primary command buffer"
Tobin Ehlis0c94db02016-07-19 10:49:32 -06008526 " (should only be secondary)");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008527
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06008528 ASSERT_NO_FATAL_FAILURE(InitState());
8529 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06008530
Chris Forbesf29a84f2016-10-06 18:39:28 +13008531 // An empty primary command buffer
8532 VkCommandBufferObj cb(m_device, m_commandPool);
8533 cb.BeginCommandBuffer();
8534 cb.EndCommandBuffer();
Tobin Ehlis0c94db02016-07-19 10:49:32 -06008535
Chris Forbesf29a84f2016-10-06 18:39:28 +13008536 m_commandBuffer->BeginCommandBuffer();
8537 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
8538 VkCommandBuffer handle = cb.handle();
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06008539
Chris Forbesf29a84f2016-10-06 18:39:28 +13008540 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdExecuteCommands() called w/ Primary Cmd Buffer ");
8541 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &handle);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008542 m_errorMonitor->VerifyFound();
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06008543}
8544
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008545TEST_F(VkLayerTest, DSUsageBitsErrors) {
8546 TEST_DESCRIPTION("Attempt to update descriptor sets for images and buffers "
8547 "that do not have correct usage bits sets.");
8548 VkResult err;
8549
8550 ASSERT_NO_FATAL_FAILURE(InitState());
8551 VkDescriptorPoolSize ds_type_count[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
8552 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
8553 ds_type_count[i].type = VkDescriptorType(i);
8554 ds_type_count[i].descriptorCount = 1;
8555 }
8556 VkDescriptorPoolCreateInfo ds_pool_ci = {};
8557 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8558 ds_pool_ci.pNext = NULL;
8559 ds_pool_ci.maxSets = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
8560 ds_pool_ci.poolSizeCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
8561 ds_pool_ci.pPoolSizes = ds_type_count;
8562
8563 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008564 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008565 ASSERT_VK_SUCCESS(err);
8566
8567 // Create 10 layouts where each has a single descriptor of different type
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008568 VkDescriptorSetLayoutBinding dsl_binding[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008569 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
8570 dsl_binding[i].binding = 0;
8571 dsl_binding[i].descriptorType = VkDescriptorType(i);
8572 dsl_binding[i].descriptorCount = 1;
8573 dsl_binding[i].stageFlags = VK_SHADER_STAGE_ALL;
8574 dsl_binding[i].pImmutableSamplers = NULL;
8575 }
8576
8577 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
8578 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8579 ds_layout_ci.pNext = NULL;
8580 ds_layout_ci.bindingCount = 1;
8581 VkDescriptorSetLayout ds_layouts[VK_DESCRIPTOR_TYPE_RANGE_SIZE];
8582 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
8583 ds_layout_ci.pBindings = dsl_binding + i;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008584 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, ds_layouts + i);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008585 ASSERT_VK_SUCCESS(err);
8586 }
8587 VkDescriptorSet descriptor_sets[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
8588 VkDescriptorSetAllocateInfo alloc_info = {};
8589 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
8590 alloc_info.descriptorSetCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
8591 alloc_info.descriptorPool = ds_pool;
8592 alloc_info.pSetLayouts = ds_layouts;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008593 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptor_sets);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008594 ASSERT_VK_SUCCESS(err);
8595
8596 // Create a buffer & bufferView to be used for invalid updates
8597 VkBufferCreateInfo buff_ci = {};
8598 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
8599 // This usage is not valid for any descriptor type
8600 buff_ci.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
8601 buff_ci.size = 256;
8602 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
8603 VkBuffer buffer;
8604 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
8605 ASSERT_VK_SUCCESS(err);
8606
8607 VkBufferViewCreateInfo buff_view_ci = {};
8608 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
8609 buff_view_ci.buffer = buffer;
8610 buff_view_ci.format = VK_FORMAT_R8_UNORM;
8611 buff_view_ci.range = VK_WHOLE_SIZE;
8612 VkBufferView buff_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008613 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buff_view);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008614 ASSERT_VK_SUCCESS(err);
8615
8616 // Create an image to be used for invalid updates
8617 VkImageCreateInfo image_ci = {};
8618 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
8619 image_ci.imageType = VK_IMAGE_TYPE_2D;
8620 image_ci.format = VK_FORMAT_R8G8B8A8_UNORM;
8621 image_ci.extent.width = 64;
8622 image_ci.extent.height = 64;
8623 image_ci.extent.depth = 1;
8624 image_ci.mipLevels = 1;
8625 image_ci.arrayLayers = 1;
8626 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
8627 image_ci.tiling = VK_IMAGE_TILING_LINEAR;
8628 image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
8629 // This usage is not valid for any descriptor type
8630 image_ci.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
8631 image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
8632 VkImage image;
8633 err = vkCreateImage(m_device->device(), &image_ci, NULL, &image);
8634 ASSERT_VK_SUCCESS(err);
8635 // Bind memory to image
8636 VkMemoryRequirements mem_reqs;
8637 VkDeviceMemory image_mem;
8638 bool pass;
8639 VkMemoryAllocateInfo mem_alloc = {};
8640 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
8641 mem_alloc.pNext = NULL;
8642 mem_alloc.allocationSize = 0;
8643 mem_alloc.memoryTypeIndex = 0;
8644 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
8645 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008646 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008647 ASSERT_TRUE(pass);
8648 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
8649 ASSERT_VK_SUCCESS(err);
8650 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
8651 ASSERT_VK_SUCCESS(err);
8652 // Now create view for image
8653 VkImageViewCreateInfo image_view_ci = {};
8654 image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
8655 image_view_ci.image = image;
8656 image_view_ci.format = VK_FORMAT_R8G8B8A8_UNORM;
8657 image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D;
8658 image_view_ci.subresourceRange.layerCount = 1;
8659 image_view_ci.subresourceRange.baseArrayLayer = 0;
8660 image_view_ci.subresourceRange.levelCount = 1;
8661 image_view_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8662 VkImageView image_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008663 err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, &image_view);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008664 ASSERT_VK_SUCCESS(err);
8665
8666 VkDescriptorBufferInfo buff_info = {};
8667 buff_info.buffer = buffer;
8668 VkDescriptorImageInfo img_info = {};
8669 img_info.imageView = image_view;
8670 VkWriteDescriptorSet descriptor_write = {};
8671 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
8672 descriptor_write.dstBinding = 0;
8673 descriptor_write.descriptorCount = 1;
8674 descriptor_write.pTexelBufferView = &buff_view;
8675 descriptor_write.pBufferInfo = &buff_info;
8676 descriptor_write.pImageInfo = &img_info;
8677
8678 // These error messages align with VkDescriptorType struct
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008679 const char *error_msgs[] = {"", // placeholder, no error for SAMPLER descriptor
8680 " does not have VK_IMAGE_USAGE_SAMPLED_BIT set.",
8681 " does not have VK_IMAGE_USAGE_SAMPLED_BIT set.",
8682 " does not have VK_IMAGE_USAGE_STORAGE_BIT set.",
8683 " does not have VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT set.",
8684 " does not have VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT set.",
8685 " does not have VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT set.",
8686 " does not have VK_BUFFER_USAGE_STORAGE_BUFFER_BIT set.",
8687 " does not have VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT set.",
8688 " does not have VK_BUFFER_USAGE_STORAGE_BUFFER_BIT set.",
8689 " does not have VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT set."};
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008690 // Start loop at 1 as SAMPLER desc type has no usage bit error
8691 for (uint32_t i = 1; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
8692 descriptor_write.descriptorType = VkDescriptorType(i);
8693 descriptor_write.dstSet = descriptor_sets[i];
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008694 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, error_msgs[i]);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008695
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008696 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008697
8698 m_errorMonitor->VerifyFound();
8699 vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[i], NULL);
8700 }
8701 vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[0], NULL);
8702 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06008703 vkFreeMemory(m_device->device(), image_mem, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008704 vkDestroyImageView(m_device->device(), image_view, NULL);
8705 vkDestroyBuffer(m_device->device(), buffer, NULL);
8706 vkDestroyBufferView(m_device->device(), buff_view, NULL);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008707 vkFreeDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_TYPE_RANGE_SIZE, descriptor_sets);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008708 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
8709}
8710
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008711TEST_F(VkLayerTest, DSBufferInfoErrors) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008712 TEST_DESCRIPTION("Attempt to update buffer descriptor set that has incorrect "
8713 "parameters in VkDescriptorBufferInfo struct. This includes:\n"
8714 "1. offset value greater than buffer size\n"
8715 "2. range value of 0\n"
8716 "3. range value greater than buffer (size - offset)");
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008717 VkResult err;
8718
8719 ASSERT_NO_FATAL_FAILURE(InitState());
8720 VkDescriptorPoolSize ds_type_count = {};
8721 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8722 ds_type_count.descriptorCount = 1;
8723
8724 VkDescriptorPoolCreateInfo ds_pool_ci = {};
8725 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8726 ds_pool_ci.pNext = NULL;
8727 ds_pool_ci.maxSets = 1;
8728 ds_pool_ci.poolSizeCount = 1;
8729 ds_pool_ci.pPoolSizes = &ds_type_count;
8730
8731 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008732 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008733 ASSERT_VK_SUCCESS(err);
8734
8735 // Create layout with single uniform buffer descriptor
8736 VkDescriptorSetLayoutBinding dsl_binding = {};
8737 dsl_binding.binding = 0;
8738 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8739 dsl_binding.descriptorCount = 1;
8740 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8741 dsl_binding.pImmutableSamplers = NULL;
8742
8743 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
8744 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8745 ds_layout_ci.pNext = NULL;
8746 ds_layout_ci.bindingCount = 1;
8747 ds_layout_ci.pBindings = &dsl_binding;
8748 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008749 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008750 ASSERT_VK_SUCCESS(err);
8751
8752 VkDescriptorSet descriptor_set = {};
8753 VkDescriptorSetAllocateInfo alloc_info = {};
8754 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
8755 alloc_info.descriptorSetCount = 1;
8756 alloc_info.descriptorPool = ds_pool;
8757 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008758 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008759 ASSERT_VK_SUCCESS(err);
8760
8761 // Create a buffer to be used for invalid updates
8762 VkBufferCreateInfo buff_ci = {};
8763 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
8764 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_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);
8770 // Have to bind memory to buffer before descriptor update
8771 VkMemoryAllocateInfo mem_alloc = {};
8772 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
8773 mem_alloc.pNext = NULL;
8774 mem_alloc.allocationSize = 256;
8775 mem_alloc.memoryTypeIndex = 0;
8776
8777 VkMemoryRequirements mem_reqs;
8778 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008779 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008780 if (!pass) {
8781 vkDestroyBuffer(m_device->device(), buffer, NULL);
8782 return;
8783 }
8784
8785 VkDeviceMemory mem;
8786 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
8787 ASSERT_VK_SUCCESS(err);
8788 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
8789 ASSERT_VK_SUCCESS(err);
8790
8791 VkDescriptorBufferInfo buff_info = {};
8792 buff_info.buffer = buffer;
8793 // First make offset 1 larger than buffer size
8794 buff_info.offset = 257;
8795 buff_info.range = VK_WHOLE_SIZE;
8796 VkWriteDescriptorSet descriptor_write = {};
8797 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
8798 descriptor_write.dstBinding = 0;
8799 descriptor_write.descriptorCount = 1;
8800 descriptor_write.pTexelBufferView = nullptr;
8801 descriptor_write.pBufferInfo = &buff_info;
8802 descriptor_write.pImageInfo = nullptr;
8803
8804 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8805 descriptor_write.dstSet = descriptor_set;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008806 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " offset of 257 is greater than buffer ");
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008807
8808 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8809
8810 m_errorMonitor->VerifyFound();
8811 // Now cause error due to range of 0
8812 buff_info.offset = 0;
8813 buff_info.range = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008814 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8815 " range is not VK_WHOLE_SIZE and is zero, which is not allowed.");
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008816
8817 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8818
8819 m_errorMonitor->VerifyFound();
8820 // Now cause error due to range exceeding buffer size - offset
8821 buff_info.offset = 128;
8822 buff_info.range = 200;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008823 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " range is 200 which is greater than buffer size ");
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008824
8825 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8826
8827 m_errorMonitor->VerifyFound();
Mark Lobodzinski4bb54092016-07-06 14:27:19 -06008828 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008829 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8830 vkDestroyBuffer(m_device->device(), buffer, NULL);
8831 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
8832 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
8833}
8834
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008835TEST_F(VkLayerTest, DSAspectBitsErrors) {
8836 // TODO : Initially only catching case where DEPTH & STENCIL aspect bits
8837 // are set, but could expand this test to hit more cases.
8838 TEST_DESCRIPTION("Attempt to update descriptor sets for images "
8839 "that do not have correct aspect bits sets.");
8840 VkResult err;
8841
8842 ASSERT_NO_FATAL_FAILURE(InitState());
8843 VkDescriptorPoolSize ds_type_count = {};
8844 ds_type_count.type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
8845 ds_type_count.descriptorCount = 1;
8846
8847 VkDescriptorPoolCreateInfo ds_pool_ci = {};
8848 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8849 ds_pool_ci.pNext = NULL;
8850 ds_pool_ci.maxSets = 5;
8851 ds_pool_ci.poolSizeCount = 1;
8852 ds_pool_ci.pPoolSizes = &ds_type_count;
8853
8854 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008855 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008856 ASSERT_VK_SUCCESS(err);
8857
8858 VkDescriptorSetLayoutBinding dsl_binding = {};
8859 dsl_binding.binding = 0;
8860 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
8861 dsl_binding.descriptorCount = 1;
8862 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8863 dsl_binding.pImmutableSamplers = NULL;
8864
8865 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
8866 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8867 ds_layout_ci.pNext = NULL;
8868 ds_layout_ci.bindingCount = 1;
8869 ds_layout_ci.pBindings = &dsl_binding;
8870 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008871 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008872 ASSERT_VK_SUCCESS(err);
8873
8874 VkDescriptorSet descriptor_set = {};
8875 VkDescriptorSetAllocateInfo alloc_info = {};
8876 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
8877 alloc_info.descriptorSetCount = 1;
8878 alloc_info.descriptorPool = ds_pool;
8879 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008880 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008881 ASSERT_VK_SUCCESS(err);
8882
8883 // Create an image to be used for invalid updates
8884 VkImageCreateInfo image_ci = {};
8885 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
8886 image_ci.imageType = VK_IMAGE_TYPE_2D;
8887 image_ci.format = VK_FORMAT_D24_UNORM_S8_UINT;
8888 image_ci.extent.width = 64;
8889 image_ci.extent.height = 64;
8890 image_ci.extent.depth = 1;
8891 image_ci.mipLevels = 1;
8892 image_ci.arrayLayers = 1;
8893 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
8894 image_ci.tiling = VK_IMAGE_TILING_LINEAR;
8895 image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
8896 image_ci.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
8897 image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
8898 VkImage image;
8899 err = vkCreateImage(m_device->device(), &image_ci, NULL, &image);
8900 ASSERT_VK_SUCCESS(err);
8901 // Bind memory to image
8902 VkMemoryRequirements mem_reqs;
8903 VkDeviceMemory image_mem;
8904 bool pass;
8905 VkMemoryAllocateInfo mem_alloc = {};
8906 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
8907 mem_alloc.pNext = NULL;
8908 mem_alloc.allocationSize = 0;
8909 mem_alloc.memoryTypeIndex = 0;
8910 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
8911 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008912 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008913 ASSERT_TRUE(pass);
8914 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
8915 ASSERT_VK_SUCCESS(err);
8916 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
8917 ASSERT_VK_SUCCESS(err);
8918 // Now create view for image
8919 VkImageViewCreateInfo image_view_ci = {};
8920 image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
8921 image_view_ci.image = image;
8922 image_view_ci.format = VK_FORMAT_D24_UNORM_S8_UINT;
8923 image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D;
8924 image_view_ci.subresourceRange.layerCount = 1;
8925 image_view_ci.subresourceRange.baseArrayLayer = 0;
8926 image_view_ci.subresourceRange.levelCount = 1;
8927 // Setting both depth & stencil aspect bits is illegal for descriptor
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008928 image_view_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008929
8930 VkImageView image_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008931 err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, &image_view);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008932 ASSERT_VK_SUCCESS(err);
8933
8934 VkDescriptorImageInfo img_info = {};
8935 img_info.imageView = image_view;
8936 VkWriteDescriptorSet descriptor_write = {};
8937 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
8938 descriptor_write.dstBinding = 0;
8939 descriptor_write.descriptorCount = 1;
8940 descriptor_write.pTexelBufferView = NULL;
8941 descriptor_write.pBufferInfo = NULL;
8942 descriptor_write.pImageInfo = &img_info;
8943 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
8944 descriptor_write.dstSet = descriptor_set;
8945 const char *error_msg = " please only set either VK_IMAGE_ASPECT_DEPTH_BIT "
8946 "or VK_IMAGE_ASPECT_STENCIL_BIT ";
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008947 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, error_msg);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008948
8949 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8950
8951 m_errorMonitor->VerifyFound();
8952 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8953 vkDestroyImage(m_device->device(), image, NULL);
8954 vkFreeMemory(m_device->device(), image_mem, NULL);
8955 vkDestroyImageView(m_device->device(), image_view, NULL);
8956 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
8957 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
8958}
8959
Karl Schultz6addd812016-02-02 17:17:23 -07008960TEST_F(VkLayerTest, DSTypeMismatch) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06008961 // Create DS w/ layout of one type and attempt Update w/ mis-matched type
Karl Schultz6addd812016-02-02 17:17:23 -07008962 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008963
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008964 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8965 " binding #0 with type VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER but update "
8966 "type is VK_DESCRIPTOR_TYPE_SAMPLER");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008967
Tobin Ehlis3b780662015-05-28 12:11:26 -06008968 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07008969 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008970 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008971 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8972 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06008973
8974 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008975 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8976 ds_pool_ci.pNext = NULL;
8977 ds_pool_ci.maxSets = 1;
8978 ds_pool_ci.poolSizeCount = 1;
8979 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06008980
Tobin Ehlis3b780662015-05-28 12:11:26 -06008981 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008982 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008983 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -06008984 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008985 dsl_binding.binding = 0;
8986 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8987 dsl_binding.descriptorCount = 1;
8988 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8989 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008990
Tony Barboureb254902015-07-15 12:50:33 -06008991 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008992 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8993 ds_layout_ci.pNext = NULL;
8994 ds_layout_ci.bindingCount = 1;
8995 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06008996
Tobin Ehlis3b780662015-05-28 12:11:26 -06008997 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008998 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008999 ASSERT_VK_SUCCESS(err);
9000
9001 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009002 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009003 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009004 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009005 alloc_info.descriptorPool = ds_pool;
9006 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009007 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009008 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009009
Tobin Ehlis30db8f82016-05-05 08:19:48 -06009010 VkSamplerCreateInfo sampler_ci = {};
9011 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9012 sampler_ci.pNext = NULL;
9013 sampler_ci.magFilter = VK_FILTER_NEAREST;
9014 sampler_ci.minFilter = VK_FILTER_NEAREST;
9015 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9016 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9017 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9018 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9019 sampler_ci.mipLodBias = 1.0;
9020 sampler_ci.anisotropyEnable = VK_FALSE;
9021 sampler_ci.maxAnisotropy = 1;
9022 sampler_ci.compareEnable = VK_FALSE;
9023 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9024 sampler_ci.minLod = 1.0;
9025 sampler_ci.maxLod = 1.0;
9026 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9027 sampler_ci.unnormalizedCoordinates = VK_FALSE;
9028 VkSampler sampler;
9029 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
9030 ASSERT_VK_SUCCESS(err);
9031
9032 VkDescriptorImageInfo info = {};
9033 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009034
9035 VkWriteDescriptorSet descriptor_write;
9036 memset(&descriptor_write, 0, sizeof(descriptor_write));
9037 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009038 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009039 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009040 // This is a mismatched type for the layout which expects BUFFER
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009041 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06009042 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009043
9044 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9045
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009046 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009047
Chia-I Wuf7458c52015-10-26 21:10:41 +08009048 vkDestroySampler(m_device->device(), sampler, NULL);
9049 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9050 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009051}
9052
Karl Schultz6addd812016-02-02 17:17:23 -07009053TEST_F(VkLayerTest, DSUpdateOutOfBounds) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009054 // For overlapping Update, have arrayIndex exceed that of layout
Karl Schultz6addd812016-02-02 17:17:23 -07009055 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009056
Tobin Ehlisf922ef82016-11-30 10:19:14 -07009057 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00938);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009058
Tobin Ehlis3b780662015-05-28 12:11:26 -06009059 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07009060 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009061 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009062 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9063 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009064
9065 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009066 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9067 ds_pool_ci.pNext = NULL;
9068 ds_pool_ci.maxSets = 1;
9069 ds_pool_ci.poolSizeCount = 1;
9070 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06009071
Tobin Ehlis3b780662015-05-28 12:11:26 -06009072 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009073 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009074 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009075
Tony Barboureb254902015-07-15 12:50:33 -06009076 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009077 dsl_binding.binding = 0;
9078 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9079 dsl_binding.descriptorCount = 1;
9080 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9081 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -06009082
9083 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009084 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9085 ds_layout_ci.pNext = NULL;
9086 ds_layout_ci.bindingCount = 1;
9087 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06009088
Tobin Ehlis3b780662015-05-28 12:11:26 -06009089 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009090 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009091 ASSERT_VK_SUCCESS(err);
9092
9093 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009094 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009095 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009096 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009097 alloc_info.descriptorPool = ds_pool;
9098 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009099 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009100 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009101
Tobin Ehlis30db8f82016-05-05 08:19:48 -06009102 // Correctly update descriptor to avoid "NOT_UPDATED" error
9103 VkDescriptorBufferInfo buff_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009104 buff_info.buffer = VkBuffer(0); // Don't care about buffer handle for this test
Tobin Ehlis30db8f82016-05-05 08:19:48 -06009105 buff_info.offset = 0;
9106 buff_info.range = 1024;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009107
9108 VkWriteDescriptorSet descriptor_write;
9109 memset(&descriptor_write, 0, sizeof(descriptor_write));
9110 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009111 descriptor_write.dstSet = descriptorSet;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009112 descriptor_write.dstArrayElement = 1; /* This index out of bounds for the update */
Chia-I Wud50a7d72015-10-26 20:48:51 +08009113 descriptor_write.descriptorCount = 1;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06009114 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9115 descriptor_write.pBufferInfo = &buff_info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009116
9117 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9118
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009119 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009120
Chia-I Wuf7458c52015-10-26 21:10:41 +08009121 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9122 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009123}
9124
Karl Schultz6addd812016-02-02 17:17:23 -07009125TEST_F(VkLayerTest, InvalidDSUpdateIndex) {
Tobin Ehlisc8d352d2016-11-21 10:33:40 -07009126 // Create layout w/ count of 1 and attempt update to that layout w/ binding index 2
Karl Schultz6addd812016-02-02 17:17:23 -07009127 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009128
Tobin Ehlisc8d352d2016-11-21 10:33:40 -07009129 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00936);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009130
Tobin Ehlis3b780662015-05-28 12:11:26 -06009131 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07009132 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009133 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009134 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9135 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009136
9137 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009138 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9139 ds_pool_ci.pNext = NULL;
9140 ds_pool_ci.maxSets = 1;
9141 ds_pool_ci.poolSizeCount = 1;
9142 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06009143
Tobin Ehlis3b780662015-05-28 12:11:26 -06009144 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009145 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009146 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009147
Tony Barboureb254902015-07-15 12:50:33 -06009148 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009149 dsl_binding.binding = 0;
9150 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9151 dsl_binding.descriptorCount = 1;
9152 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9153 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -06009154
9155 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009156 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9157 ds_layout_ci.pNext = NULL;
9158 ds_layout_ci.bindingCount = 1;
9159 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009160 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009161 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009162 ASSERT_VK_SUCCESS(err);
9163
9164 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009165 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009166 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009167 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009168 alloc_info.descriptorPool = ds_pool;
9169 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009170 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009171 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009172
Tony Barboureb254902015-07-15 12:50:33 -06009173 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009174 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9175 sampler_ci.pNext = NULL;
9176 sampler_ci.magFilter = VK_FILTER_NEAREST;
9177 sampler_ci.minFilter = VK_FILTER_NEAREST;
9178 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9179 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9180 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9181 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9182 sampler_ci.mipLodBias = 1.0;
9183 sampler_ci.anisotropyEnable = VK_FALSE;
9184 sampler_ci.maxAnisotropy = 1;
9185 sampler_ci.compareEnable = VK_FALSE;
9186 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9187 sampler_ci.minLod = 1.0;
9188 sampler_ci.maxLod = 1.0;
9189 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9190 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tony Barboureb254902015-07-15 12:50:33 -06009191
Tobin Ehlis3b780662015-05-28 12:11:26 -06009192 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009193 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009194 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009195
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06009196 VkDescriptorImageInfo info = {};
9197 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009198
9199 VkWriteDescriptorSet descriptor_write;
9200 memset(&descriptor_write, 0, sizeof(descriptor_write));
9201 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009202 descriptor_write.dstSet = descriptorSet;
9203 descriptor_write.dstBinding = 2;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009204 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009205 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009206 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06009207 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009208
9209 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9210
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009211 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009212
Chia-I Wuf7458c52015-10-26 21:10:41 +08009213 vkDestroySampler(m_device->device(), sampler, NULL);
9214 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9215 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009216}
9217
Tobin Ehlise202b2d2016-11-21 10:36:16 -07009218TEST_F(VkLayerTest, DSUpdateEmptyBinding) {
9219 // Create layout w/ empty binding and attempt to update it
9220 VkResult err;
9221
9222 ASSERT_NO_FATAL_FAILURE(InitState());
9223
9224 VkDescriptorPoolSize ds_type_count = {};
9225 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
9226 ds_type_count.descriptorCount = 1;
9227
9228 VkDescriptorPoolCreateInfo ds_pool_ci = {};
9229 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9230 ds_pool_ci.pNext = NULL;
9231 ds_pool_ci.maxSets = 1;
9232 ds_pool_ci.poolSizeCount = 1;
9233 ds_pool_ci.pPoolSizes = &ds_type_count;
9234
9235 VkDescriptorPool ds_pool;
9236 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
9237 ASSERT_VK_SUCCESS(err);
9238
9239 VkDescriptorSetLayoutBinding dsl_binding = {};
9240 dsl_binding.binding = 0;
9241 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9242 dsl_binding.descriptorCount = 0;
9243 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9244 dsl_binding.pImmutableSamplers = NULL;
9245
9246 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9247 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9248 ds_layout_ci.pNext = NULL;
9249 ds_layout_ci.bindingCount = 1;
9250 ds_layout_ci.pBindings = &dsl_binding;
9251 VkDescriptorSetLayout ds_layout;
9252 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
9253 ASSERT_VK_SUCCESS(err);
9254
9255 VkDescriptorSet descriptor_set;
9256 VkDescriptorSetAllocateInfo alloc_info = {};
9257 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
9258 alloc_info.descriptorSetCount = 1;
9259 alloc_info.descriptorPool = ds_pool;
9260 alloc_info.pSetLayouts = &ds_layout;
9261 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
9262 ASSERT_VK_SUCCESS(err);
9263
9264 VkSamplerCreateInfo sampler_ci = {};
9265 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9266 sampler_ci.magFilter = VK_FILTER_NEAREST;
9267 sampler_ci.minFilter = VK_FILTER_NEAREST;
9268 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9269 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9270 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9271 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9272 sampler_ci.mipLodBias = 1.0;
9273 sampler_ci.maxAnisotropy = 1;
9274 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9275 sampler_ci.minLod = 1.0;
9276 sampler_ci.maxLod = 1.0;
9277 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9278
9279 VkSampler sampler;
9280 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
9281 ASSERT_VK_SUCCESS(err);
9282
9283 VkDescriptorImageInfo info = {};
9284 info.sampler = sampler;
9285
9286 VkWriteDescriptorSet descriptor_write;
9287 memset(&descriptor_write, 0, sizeof(descriptor_write));
9288 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
9289 descriptor_write.dstSet = descriptor_set;
9290 descriptor_write.dstBinding = 0;
9291 descriptor_write.descriptorCount = 1; // Lie here to avoid parameter_validation error
9292 // This is the wrong type, but empty binding error will be flagged first
9293 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9294 descriptor_write.pImageInfo = &info;
9295
9296 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02348);
9297 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9298 m_errorMonitor->VerifyFound();
9299
9300 vkDestroySampler(m_device->device(), sampler, NULL);
9301 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9302 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9303}
9304
Karl Schultz6addd812016-02-02 17:17:23 -07009305TEST_F(VkLayerTest, InvalidDSUpdateStruct) {
9306 // Call UpdateDS w/ struct type other than valid VK_STRUCTUR_TYPE_UPDATE_*
9307 // types
9308 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009309
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009310 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 -06009311
Tobin Ehlis3b780662015-05-28 12:11:26 -06009312 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski209b5292015-09-17 09:44:05 -06009313
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009314 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009315 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9316 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009317
9318 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009319 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9320 ds_pool_ci.pNext = NULL;
9321 ds_pool_ci.maxSets = 1;
9322 ds_pool_ci.poolSizeCount = 1;
9323 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06009324
Tobin Ehlis3b780662015-05-28 12:11:26 -06009325 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009326 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009327 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -06009328 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009329 dsl_binding.binding = 0;
9330 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9331 dsl_binding.descriptorCount = 1;
9332 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9333 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009334
Tony Barboureb254902015-07-15 12:50:33 -06009335 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009336 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9337 ds_layout_ci.pNext = NULL;
9338 ds_layout_ci.bindingCount = 1;
9339 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06009340
Tobin Ehlis3b780662015-05-28 12:11:26 -06009341 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009342 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009343 ASSERT_VK_SUCCESS(err);
9344
9345 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009346 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009347 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009348 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009349 alloc_info.descriptorPool = ds_pool;
9350 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009351 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009352 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009353
Tony Barboureb254902015-07-15 12:50:33 -06009354 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009355 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9356 sampler_ci.pNext = NULL;
9357 sampler_ci.magFilter = VK_FILTER_NEAREST;
9358 sampler_ci.minFilter = VK_FILTER_NEAREST;
9359 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9360 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9361 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9362 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9363 sampler_ci.mipLodBias = 1.0;
9364 sampler_ci.anisotropyEnable = VK_FALSE;
9365 sampler_ci.maxAnisotropy = 1;
9366 sampler_ci.compareEnable = VK_FALSE;
9367 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9368 sampler_ci.minLod = 1.0;
9369 sampler_ci.maxLod = 1.0;
9370 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9371 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009372 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009373 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009374 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009375
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06009376 VkDescriptorImageInfo info = {};
9377 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009378
9379 VkWriteDescriptorSet descriptor_write;
9380 memset(&descriptor_write, 0, sizeof(descriptor_write));
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009381 descriptor_write.sType = (VkStructureType)0x99999999; /* Intentionally broken struct type */
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009382 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009383 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009384 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009385 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06009386 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009387
9388 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9389
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009390 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009391
Chia-I Wuf7458c52015-10-26 21:10:41 +08009392 vkDestroySampler(m_device->device(), sampler, NULL);
9393 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9394 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009395}
9396
Karl Schultz6addd812016-02-02 17:17:23 -07009397TEST_F(VkLayerTest, SampleDescriptorUpdateError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009398 // Create a single Sampler descriptor and send it an invalid Sampler
Karl Schultz6addd812016-02-02 17:17:23 -07009399 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009400
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009401 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9402 "Attempted write update to sampler descriptor with invalid sampler");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009403
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009404 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07009405 // TODO : Farm Descriptor setup code to helper function(s) to reduce copied
9406 // code
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009407 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009408 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
9409 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009410
9411 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009412 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;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009417
9418 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009419 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009420 ASSERT_VK_SUCCESS(err);
9421
9422 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009423 dsl_binding.binding = 0;
9424 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9425 dsl_binding.descriptorCount = 1;
9426 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9427 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009428
9429 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009430 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;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009434 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009435 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009436 ASSERT_VK_SUCCESS(err);
9437
9438 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009439 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009440 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009441 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009442 alloc_info.descriptorPool = ds_pool;
9443 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009444 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009445 ASSERT_VK_SUCCESS(err);
9446
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009447 VkSampler sampler = (VkSampler)((size_t)0xbaadbeef); // Sampler with invalid handle
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009448
9449 VkDescriptorImageInfo descriptor_info;
9450 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
9451 descriptor_info.sampler = sampler;
9452
9453 VkWriteDescriptorSet descriptor_write;
9454 memset(&descriptor_write, 0, sizeof(descriptor_write));
9455 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009456 descriptor_write.dstSet = descriptorSet;
9457 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009458 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009459 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9460 descriptor_write.pImageInfo = &descriptor_info;
9461
9462 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9463
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009464 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009465
Chia-I Wuf7458c52015-10-26 21:10:41 +08009466 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9467 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009468}
9469
Karl Schultz6addd812016-02-02 17:17:23 -07009470TEST_F(VkLayerTest, ImageViewDescriptorUpdateError) {
9471 // Create a single combined Image/Sampler descriptor and send it an invalid
9472 // imageView
9473 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009474
Karl Schultzf78bcdd2016-11-30 12:36:01 -07009475 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00943);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009476
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009477 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009478 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009479 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
9480 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009481
9482 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009483 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9484 ds_pool_ci.pNext = NULL;
9485 ds_pool_ci.maxSets = 1;
9486 ds_pool_ci.poolSizeCount = 1;
9487 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009488
9489 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009490 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009491 ASSERT_VK_SUCCESS(err);
9492
9493 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009494 dsl_binding.binding = 0;
9495 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
9496 dsl_binding.descriptorCount = 1;
9497 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9498 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009499
9500 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009501 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9502 ds_layout_ci.pNext = NULL;
9503 ds_layout_ci.bindingCount = 1;
9504 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009505 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009506 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009507 ASSERT_VK_SUCCESS(err);
9508
9509 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009510 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009511 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009512 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009513 alloc_info.descriptorPool = ds_pool;
9514 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009515 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009516 ASSERT_VK_SUCCESS(err);
9517
9518 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009519 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9520 sampler_ci.pNext = NULL;
9521 sampler_ci.magFilter = VK_FILTER_NEAREST;
9522 sampler_ci.minFilter = VK_FILTER_NEAREST;
9523 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9524 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9525 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9526 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9527 sampler_ci.mipLodBias = 1.0;
9528 sampler_ci.anisotropyEnable = VK_FALSE;
9529 sampler_ci.maxAnisotropy = 1;
9530 sampler_ci.compareEnable = VK_FALSE;
9531 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9532 sampler_ci.minLod = 1.0;
9533 sampler_ci.maxLod = 1.0;
9534 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9535 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009536
9537 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009538 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009539 ASSERT_VK_SUCCESS(err);
9540
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009541 VkImageView view = (VkImageView)((size_t)0xbaadbeef); // invalid imageView object
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009542
9543 VkDescriptorImageInfo descriptor_info;
9544 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
9545 descriptor_info.sampler = sampler;
9546 descriptor_info.imageView = view;
9547
9548 VkWriteDescriptorSet descriptor_write;
9549 memset(&descriptor_write, 0, sizeof(descriptor_write));
9550 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009551 descriptor_write.dstSet = descriptorSet;
9552 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009553 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009554 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
9555 descriptor_write.pImageInfo = &descriptor_info;
9556
9557 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9558
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009559 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009560
Chia-I Wuf7458c52015-10-26 21:10:41 +08009561 vkDestroySampler(m_device->device(), sampler, NULL);
9562 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9563 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009564}
9565
Karl Schultz6addd812016-02-02 17:17:23 -07009566TEST_F(VkLayerTest, CopyDescriptorUpdateErrors) {
9567 // Create DS w/ layout of 2 types, write update 1 and attempt to copy-update
9568 // into the other
9569 VkResult err;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009570
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009571 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " binding #1 with type "
9572 "VK_DESCRIPTOR_TYPE_SAMPLER. Types do "
9573 "not match.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009574
Tobin Ehlis04356f92015-10-27 16:35:27 -06009575 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07009576 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009577 VkDescriptorPoolSize ds_type_count[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009578 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9579 ds_type_count[0].descriptorCount = 1;
9580 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLER;
9581 ds_type_count[1].descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009582
9583 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009584 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9585 ds_pool_ci.pNext = NULL;
9586 ds_pool_ci.maxSets = 1;
9587 ds_pool_ci.poolSizeCount = 2;
9588 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009589
9590 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009591 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis04356f92015-10-27 16:35:27 -06009592 ASSERT_VK_SUCCESS(err);
9593 VkDescriptorSetLayoutBinding dsl_binding[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009594 dsl_binding[0].binding = 0;
9595 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9596 dsl_binding[0].descriptorCount = 1;
9597 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
9598 dsl_binding[0].pImmutableSamplers = NULL;
9599 dsl_binding[1].binding = 1;
9600 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9601 dsl_binding[1].descriptorCount = 1;
9602 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
9603 dsl_binding[1].pImmutableSamplers = NULL;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009604
9605 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009606 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9607 ds_layout_ci.pNext = NULL;
9608 ds_layout_ci.bindingCount = 2;
9609 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009610
9611 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009612 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis04356f92015-10-27 16:35:27 -06009613 ASSERT_VK_SUCCESS(err);
9614
9615 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009616 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009617 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009618 alloc_info.descriptorSetCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009619 alloc_info.descriptorPool = ds_pool;
9620 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009621 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis04356f92015-10-27 16:35:27 -06009622 ASSERT_VK_SUCCESS(err);
9623
9624 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009625 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9626 sampler_ci.pNext = NULL;
9627 sampler_ci.magFilter = VK_FILTER_NEAREST;
9628 sampler_ci.minFilter = VK_FILTER_NEAREST;
9629 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9630 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9631 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9632 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9633 sampler_ci.mipLodBias = 1.0;
9634 sampler_ci.anisotropyEnable = VK_FALSE;
9635 sampler_ci.maxAnisotropy = 1;
9636 sampler_ci.compareEnable = VK_FALSE;
9637 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9638 sampler_ci.minLod = 1.0;
9639 sampler_ci.maxLod = 1.0;
9640 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9641 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009642
9643 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009644 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis04356f92015-10-27 16:35:27 -06009645 ASSERT_VK_SUCCESS(err);
9646
9647 VkDescriptorImageInfo info = {};
9648 info.sampler = sampler;
9649
9650 VkWriteDescriptorSet descriptor_write;
9651 memset(&descriptor_write, 0, sizeof(VkWriteDescriptorSet));
9652 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009653 descriptor_write.dstSet = descriptorSet;
9654 descriptor_write.dstBinding = 1; // SAMPLER binding from layout above
Chia-I Wud50a7d72015-10-26 20:48:51 +08009655 descriptor_write.descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009656 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9657 descriptor_write.pImageInfo = &info;
9658 // This write update should succeed
9659 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9660 // Now perform a copy update that fails due to type mismatch
9661 VkCopyDescriptorSet copy_ds_update;
9662 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
9663 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
9664 copy_ds_update.srcSet = descriptorSet;
Mark Young29927482016-05-04 14:38:51 -06009665 copy_ds_update.srcBinding = 1; // Copy from SAMPLER binding
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009666 copy_ds_update.dstSet = descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -07009667 copy_ds_update.dstBinding = 0; // ERROR : copy to UNIFORM binding
Chia-I Wud50a7d72015-10-26 20:48:51 +08009668 copy_ds_update.descriptorCount = 1; // copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -06009669 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
9670
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009671 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -06009672 // Now perform a copy update that fails due to binding out of bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009673 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 -06009674 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
9675 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
9676 copy_ds_update.srcSet = descriptorSet;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009677 copy_ds_update.srcBinding = 3; // ERROR : Invalid binding for matching layout
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009678 copy_ds_update.dstSet = descriptorSet;
9679 copy_ds_update.dstBinding = 0;
Mark Young29927482016-05-04 14:38:51 -06009680 copy_ds_update.descriptorCount = 1; // Copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -06009681 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
9682
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009683 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009684
Tobin Ehlis04356f92015-10-27 16:35:27 -06009685 // Now perform a copy update that fails due to binding out of bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009686 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " binding#1 with offset index of 1 plus "
9687 "update array offset of 0 and update of "
9688 "5 descriptors oversteps total number "
9689 "of descriptors in set: 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009690
Tobin Ehlis04356f92015-10-27 16:35:27 -06009691 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
9692 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
9693 copy_ds_update.srcSet = descriptorSet;
9694 copy_ds_update.srcBinding = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009695 copy_ds_update.dstSet = descriptorSet;
9696 copy_ds_update.dstBinding = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009697 copy_ds_update.descriptorCount = 5; // ERROR copy 5 descriptors (out of bounds for layout)
Tobin Ehlis04356f92015-10-27 16:35:27 -06009698 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
9699
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009700 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -06009701
Chia-I Wuf7458c52015-10-26 21:10:41 +08009702 vkDestroySampler(m_device->device(), sampler, NULL);
9703 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9704 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis04356f92015-10-27 16:35:27 -06009705}
9706
Karl Schultz6addd812016-02-02 17:17:23 -07009707TEST_F(VkLayerTest, NumSamplesMismatch) {
9708 // Create CommandBuffer where MSAA samples doesn't match RenderPass
9709 // sampleCount
9710 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009711
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009712 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Num samples mismatch! ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009713
Tobin Ehlis3b780662015-05-28 12:11:26 -06009714 ASSERT_NO_FATAL_FAILURE(InitState());
9715 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009716 VkDescriptorPoolSize ds_type_count = {};
Tony Barboureb254902015-07-15 12:50:33 -06009717 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009718 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009719
9720 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009721 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9722 ds_pool_ci.pNext = NULL;
9723 ds_pool_ci.maxSets = 1;
9724 ds_pool_ci.poolSizeCount = 1;
9725 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06009726
Tobin Ehlis3b780662015-05-28 12:11:26 -06009727 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009728 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009729 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009730
Tony Barboureb254902015-07-15 12:50:33 -06009731 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08009732 dsl_binding.binding = 0;
Tony Barboureb254902015-07-15 12:50:33 -06009733 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08009734 dsl_binding.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009735 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9736 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009737
Tony Barboureb254902015-07-15 12:50:33 -06009738 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9739 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9740 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009741 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07009742 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06009743
Tobin Ehlis3b780662015-05-28 12:11:26 -06009744 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009745 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009746 ASSERT_VK_SUCCESS(err);
9747
9748 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009749 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009750 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009751 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009752 alloc_info.descriptorPool = ds_pool;
9753 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009754 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009755 ASSERT_VK_SUCCESS(err);
9756
Tony Barboureb254902015-07-15 12:50:33 -06009757 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009758 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07009759 pipe_ms_state_ci.pNext = NULL;
9760 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
9761 pipe_ms_state_ci.sampleShadingEnable = 0;
9762 pipe_ms_state_ci.minSampleShading = 1.0;
9763 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009764
Tony Barboureb254902015-07-15 12:50:33 -06009765 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009766 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9767 pipeline_layout_ci.pNext = NULL;
9768 pipeline_layout_ci.setLayoutCount = 1;
9769 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009770
9771 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009772 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009773 ASSERT_VK_SUCCESS(err);
9774
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009775 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
9776 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
9777 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -06009778 VkPipelineObj pipe(m_device);
9779 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06009780 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -06009781 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -06009782 pipe.SetMSAA(&pipe_ms_state_ci);
9783 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tobin Ehlis3b780662015-05-28 12:11:26 -06009784
Tony Barbourfe3351b2015-07-28 10:17:20 -06009785 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009786 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis3b780662015-05-28 12:11:26 -06009787
Mark Young29927482016-05-04 14:38:51 -06009788 // Render triangle (the error should trigger on the attempt to draw).
9789 Draw(3, 1, 0, 0);
9790
9791 // Finalize recording of the command buffer
9792 EndCommandBuffer();
9793
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009794 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009795
Chia-I Wuf7458c52015-10-26 21:10:41 +08009796 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9797 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9798 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009799}
Mark Young29927482016-05-04 14:38:51 -06009800
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009801TEST_F(VkLayerTest, RenderPassIncompatible) {
9802 TEST_DESCRIPTION("Hit RenderPass incompatible cases. "
9803 "Initial case is drawing with an active renderpass that's "
Mike Weiblencce7ec72016-10-17 19:33:05 -06009804 "not compatible with the bound pipeline state object's creation renderpass");
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009805 VkResult err;
9806
9807 ASSERT_NO_FATAL_FAILURE(InitState());
9808 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9809
9810 VkDescriptorSetLayoutBinding dsl_binding = {};
9811 dsl_binding.binding = 0;
9812 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9813 dsl_binding.descriptorCount = 1;
9814 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9815 dsl_binding.pImmutableSamplers = NULL;
9816
9817 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9818 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9819 ds_layout_ci.pNext = NULL;
9820 ds_layout_ci.bindingCount = 1;
9821 ds_layout_ci.pBindings = &dsl_binding;
9822
9823 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009824 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009825 ASSERT_VK_SUCCESS(err);
9826
9827 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
9828 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9829 pipeline_layout_ci.pNext = NULL;
9830 pipeline_layout_ci.setLayoutCount = 1;
9831 pipeline_layout_ci.pSetLayouts = &ds_layout;
9832
9833 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009834 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009835 ASSERT_VK_SUCCESS(err);
9836
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009837 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
9838 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
9839 // but add it to be able to run on more devices
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009840 // Create a renderpass that will be incompatible with default renderpass
9841 VkAttachmentReference attach = {};
9842 attach.layout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
9843 VkAttachmentReference color_att = {};
9844 color_att.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
9845 VkSubpassDescription subpass = {};
9846 subpass.inputAttachmentCount = 1;
9847 subpass.pInputAttachments = &attach;
9848 subpass.colorAttachmentCount = 1;
9849 subpass.pColorAttachments = &color_att;
9850 VkRenderPassCreateInfo rpci = {};
9851 rpci.subpassCount = 1;
9852 rpci.pSubpasses = &subpass;
9853 rpci.attachmentCount = 1;
9854 VkAttachmentDescription attach_desc = {};
9855 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
Cody Northropbd16af12016-06-21 09:25:48 -06009856 // Format incompatible with PSO RP color attach format B8G8R8A8_UNORM
9857 attach_desc.format = VK_FORMAT_R8G8B8A8_UNORM;
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009858 rpci.pAttachments = &attach_desc;
9859 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
9860 VkRenderPass rp;
9861 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
9862 VkPipelineObj pipe(m_device);
9863 pipe.AddShader(&vs);
9864 pipe.AddShader(&fs);
9865 pipe.AddColorAttachment();
9866 VkViewport view_port = {};
9867 m_viewports.push_back(view_port);
9868 pipe.SetViewport(m_viewports);
9869 VkRect2D rect = {};
9870 m_scissors.push_back(rect);
9871 pipe.SetScissor(m_scissors);
9872 pipe.CreateVKPipeline(pipeline_layout, renderPass());
9873
9874 VkCommandBufferInheritanceInfo cbii = {};
9875 cbii.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
9876 cbii.renderPass = rp;
9877 cbii.subpass = 0;
9878 VkCommandBufferBeginInfo cbbi = {};
9879 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
9880 cbbi.pInheritanceInfo = &cbii;
9881 vkBeginCommandBuffer(m_commandBuffer->handle(), &cbbi);
9882 VkRenderPassBeginInfo rpbi = {};
9883 rpbi.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
9884 rpbi.framebuffer = m_framebuffer;
9885 rpbi.renderPass = rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009886 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
9887 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009888
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009889 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is incompatible w/ gfx pipeline ");
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009890 // Render triangle (the error should trigger on the attempt to draw).
9891 Draw(3, 1, 0, 0);
9892
9893 // Finalize recording of the command buffer
9894 EndCommandBuffer();
9895
9896 m_errorMonitor->VerifyFound();
9897
9898 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9899 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9900 vkDestroyRenderPass(m_device->device(), rp, NULL);
9901}
9902
Mark Youngc89c6312016-03-31 16:03:20 -06009903TEST_F(VkLayerTest, NumBlendAttachMismatch) {
9904 // Create Pipeline where the number of blend attachments doesn't match the
9905 // number of color attachments. In this case, we don't add any color
9906 // blend attachments even though we have a color attachment.
9907 VkResult err;
9908
9909 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009910 "Render pass subpass 0 mismatch with blending state defined and blend state attachment");
Mark Youngc89c6312016-03-31 16:03:20 -06009911
9912 ASSERT_NO_FATAL_FAILURE(InitState());
9913 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9914 VkDescriptorPoolSize ds_type_count = {};
9915 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9916 ds_type_count.descriptorCount = 1;
9917
9918 VkDescriptorPoolCreateInfo ds_pool_ci = {};
9919 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9920 ds_pool_ci.pNext = NULL;
9921 ds_pool_ci.maxSets = 1;
9922 ds_pool_ci.poolSizeCount = 1;
9923 ds_pool_ci.pPoolSizes = &ds_type_count;
9924
9925 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009926 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Mark Youngc89c6312016-03-31 16:03:20 -06009927 ASSERT_VK_SUCCESS(err);
9928
9929 VkDescriptorSetLayoutBinding dsl_binding = {};
9930 dsl_binding.binding = 0;
9931 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9932 dsl_binding.descriptorCount = 1;
9933 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9934 dsl_binding.pImmutableSamplers = NULL;
9935
9936 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9937 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9938 ds_layout_ci.pNext = NULL;
9939 ds_layout_ci.bindingCount = 1;
9940 ds_layout_ci.pBindings = &dsl_binding;
9941
9942 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009943 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Youngc89c6312016-03-31 16:03:20 -06009944 ASSERT_VK_SUCCESS(err);
9945
9946 VkDescriptorSet descriptorSet;
9947 VkDescriptorSetAllocateInfo alloc_info = {};
9948 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
9949 alloc_info.descriptorSetCount = 1;
9950 alloc_info.descriptorPool = ds_pool;
9951 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009952 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Youngc89c6312016-03-31 16:03:20 -06009953 ASSERT_VK_SUCCESS(err);
9954
9955 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009956 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Mark Youngc89c6312016-03-31 16:03:20 -06009957 pipe_ms_state_ci.pNext = NULL;
9958 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
9959 pipe_ms_state_ci.sampleShadingEnable = 0;
9960 pipe_ms_state_ci.minSampleShading = 1.0;
9961 pipe_ms_state_ci.pSampleMask = NULL;
9962
9963 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
9964 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9965 pipeline_layout_ci.pNext = NULL;
9966 pipeline_layout_ci.setLayoutCount = 1;
9967 pipeline_layout_ci.pSetLayouts = &ds_layout;
9968
9969 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009970 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Mark Youngc89c6312016-03-31 16:03:20 -06009971 ASSERT_VK_SUCCESS(err);
9972
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009973 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
9974 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
9975 // but add it to be able to run on more devices
Mark Youngc89c6312016-03-31 16:03:20 -06009976 VkPipelineObj pipe(m_device);
9977 pipe.AddShader(&vs);
9978 pipe.AddShader(&fs);
9979 pipe.SetMSAA(&pipe_ms_state_ci);
9980 pipe.CreateVKPipeline(pipeline_layout, renderPass());
9981
9982 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009983 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Mark Youngc89c6312016-03-31 16:03:20 -06009984
Mark Young29927482016-05-04 14:38:51 -06009985 // Render triangle (the error should trigger on the attempt to draw).
9986 Draw(3, 1, 0, 0);
9987
9988 // Finalize recording of the command buffer
9989 EndCommandBuffer();
9990
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009991 m_errorMonitor->VerifyFound();
Mark Youngc89c6312016-03-31 16:03:20 -06009992
9993 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9994 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9995 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9996}
Mark Young29927482016-05-04 14:38:51 -06009997
Mark Muellerd4914412016-06-13 17:52:06 -06009998TEST_F(VkLayerTest, MissingClearAttachment) {
9999 TEST_DESCRIPTION("Points to a wrong colorAttachment index in a VkClearAttachment "
10000 "structure passed to vkCmdClearAttachments");
Cody Northropc31a84f2016-08-22 10:41:47 -060010001 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesda6ae6f2016-09-09 14:36:33 +120010002 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbesfa79fc72016-11-01 10:18:12 +130010003 "vkCmdClearAttachments() color attachment index 1 out of range for active subpass 0");
Mark Muellerd4914412016-06-13 17:52:06 -060010004
10005 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailCmdClearAttachments);
10006 m_errorMonitor->VerifyFound();
10007}
10008
Karl Schultz6addd812016-02-02 17:17:23 -070010009TEST_F(VkLayerTest, ClearCmdNoDraw) {
10010 // Create CommandBuffer where we add ClearCmd for FB Color attachment prior
10011 // to issuing a Draw
10012 VkResult err;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010013
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010014 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Mike Weiblencce7ec72016-10-17 19:33:05 -060010015 "vkCmdClearAttachments() issued on command buffer object ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010016
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010017 ASSERT_NO_FATAL_FAILURE(InitState());
10018 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -060010019
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010020 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010021 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10022 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010023
10024 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010025 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10026 ds_pool_ci.pNext = NULL;
10027 ds_pool_ci.maxSets = 1;
10028 ds_pool_ci.poolSizeCount = 1;
10029 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060010030
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010031 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010032 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010033 ASSERT_VK_SUCCESS(err);
10034
Tony Barboureb254902015-07-15 12:50:33 -060010035 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010036 dsl_binding.binding = 0;
10037 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10038 dsl_binding.descriptorCount = 1;
10039 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10040 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010041
Tony Barboureb254902015-07-15 12:50:33 -060010042 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010043 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10044 ds_layout_ci.pNext = NULL;
10045 ds_layout_ci.bindingCount = 1;
10046 ds_layout_ci.pBindings = &dsl_binding;
Mark Lobodzinski209b5292015-09-17 09:44:05 -060010047
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010048 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010049 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010050 ASSERT_VK_SUCCESS(err);
10051
10052 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010053 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010054 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010055 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060010056 alloc_info.descriptorPool = ds_pool;
10057 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010058 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010059 ASSERT_VK_SUCCESS(err);
10060
Tony Barboureb254902015-07-15 12:50:33 -060010061 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010062 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070010063 pipe_ms_state_ci.pNext = NULL;
10064 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
10065 pipe_ms_state_ci.sampleShadingEnable = 0;
10066 pipe_ms_state_ci.minSampleShading = 1.0;
10067 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010068
Tony Barboureb254902015-07-15 12:50:33 -060010069 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010070 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10071 pipeline_layout_ci.pNext = NULL;
10072 pipeline_layout_ci.setLayoutCount = 1;
10073 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010074
10075 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010076 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010077 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski209b5292015-09-17 09:44:05 -060010078
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010079 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -060010080 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -070010081 // on more devices
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010082 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010083
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010084 VkPipelineObj pipe(m_device);
10085 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -060010086 pipe.AddShader(&fs);
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010087 pipe.SetMSAA(&pipe_ms_state_ci);
10088 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -060010089
10090 BeginCommandBuffer();
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010091
Karl Schultz6addd812016-02-02 17:17:23 -070010092 // Main thing we care about for this test is that the VkImage obj we're
10093 // clearing matches Color Attachment of FB
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010094 // Also pass down other dummy params to keep driver and paramchecker happy
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -060010095 VkClearAttachment color_attachment;
10096 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10097 color_attachment.clearValue.color.float32[0] = 1.0;
10098 color_attachment.clearValue.color.float32[1] = 1.0;
10099 color_attachment.clearValue.color.float32[2] = 1.0;
10100 color_attachment.clearValue.color.float32[3] = 1.0;
10101 color_attachment.colorAttachment = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010102 VkClearRect clear_rect = {{{0, 0}, {(uint32_t)m_width, (uint32_t)m_height}}};
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010103
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010104 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010105
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010106 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010107
Chia-I Wuf7458c52015-10-26 21:10:41 +080010108 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10109 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10110 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010111}
10112
Karl Schultz6addd812016-02-02 17:17:23 -070010113TEST_F(VkLayerTest, VtxBufferBadIndex) {
10114 VkResult err;
Tobin Ehlis502480b2015-06-24 15:53:07 -060010115
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010116 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10117 "but no vertex buffers are attached to this Pipeline State Object");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010118
Tobin Ehlis502480b2015-06-24 15:53:07 -060010119 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisd332f282015-10-02 11:00:56 -060010120 ASSERT_NO_FATAL_FAILURE(InitViewport());
Tobin Ehlis502480b2015-06-24 15:53:07 -060010121 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -060010122
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010123 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010124 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10125 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010126
10127 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010128 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10129 ds_pool_ci.pNext = NULL;
10130 ds_pool_ci.maxSets = 1;
10131 ds_pool_ci.poolSizeCount = 1;
10132 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060010133
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -060010134 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010135 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis502480b2015-06-24 15:53:07 -060010136 ASSERT_VK_SUCCESS(err);
10137
Tony Barboureb254902015-07-15 12:50:33 -060010138 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010139 dsl_binding.binding = 0;
10140 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10141 dsl_binding.descriptorCount = 1;
10142 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10143 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -060010144
Tony Barboureb254902015-07-15 12:50:33 -060010145 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010146 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10147 ds_layout_ci.pNext = NULL;
10148 ds_layout_ci.bindingCount = 1;
10149 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060010150
Tobin Ehlis502480b2015-06-24 15:53:07 -060010151 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010152 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -060010153 ASSERT_VK_SUCCESS(err);
10154
10155 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010156 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010157 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010158 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060010159 alloc_info.descriptorPool = ds_pool;
10160 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010161 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis502480b2015-06-24 15:53:07 -060010162 ASSERT_VK_SUCCESS(err);
10163
Tony Barboureb254902015-07-15 12:50:33 -060010164 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010165 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070010166 pipe_ms_state_ci.pNext = NULL;
10167 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
10168 pipe_ms_state_ci.sampleShadingEnable = 0;
10169 pipe_ms_state_ci.minSampleShading = 1.0;
10170 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -060010171
Tony Barboureb254902015-07-15 12:50:33 -060010172 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010173 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10174 pipeline_layout_ci.pNext = NULL;
10175 pipeline_layout_ci.setLayoutCount = 1;
10176 pipeline_layout_ci.pSetLayouts = &ds_layout;
10177 VkPipelineLayout pipeline_layout;
Tobin Ehlis502480b2015-06-24 15:53:07 -060010178
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010179 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -060010180 ASSERT_VK_SUCCESS(err);
10181
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010182 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
10183 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
10184 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010185 VkPipelineObj pipe(m_device);
10186 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -060010187 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -060010188 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010189 pipe.SetMSAA(&pipe_ms_state_ci);
Tobin Ehlisd332f282015-10-02 11:00:56 -060010190 pipe.SetViewport(m_viewports);
10191 pipe.SetScissor(m_scissors);
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010192 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -060010193
10194 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010195 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisf7bf4502015-09-09 15:12:35 -060010196 // Don't care about actual data, just need to get to draw to flag error
10197 static const float vbo_data[3] = {1.f, 0.f, 1.f};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010198 VkConstantBufferObj vbo(m_device, sizeof(vbo_data), sizeof(float), (const void *)&vbo_data);
Tobin Ehlisf7bf4502015-09-09 15:12:35 -060010199 BindVertexBuffer(&vbo, (VkDeviceSize)0, 1); // VBO idx 1, but no VBO in PSO
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -060010200 Draw(1, 0, 0, 0);
Tobin Ehlis502480b2015-06-24 15:53:07 -060010201
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010202 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010203
Chia-I Wuf7458c52015-10-26 21:10:41 +080010204 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10205 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10206 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis502480b2015-06-24 15:53:07 -060010207}
Mark Muellerdfe37552016-07-07 14:47:42 -060010208
Mark Mueller2ee294f2016-08-04 12:59:48 -060010209TEST_F(VkLayerTest, MismatchCountQueueCreateRequestedFeature) {
10210 TEST_DESCRIPTION("Use an invalid count in a vkEnumeratePhysicalDevices call."
10211 "Use invalid Queue Family Index in vkCreateDevice");
Cody Northropc31a84f2016-08-22 10:41:47 -060010212 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Mueller2ee294f2016-08-04 12:59:48 -060010213
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010214 const char *mismatch_count_message = "Call to vkEnumeratePhysicalDevices() "
10215 "w/ pPhysicalDeviceCount value ";
Mark Mueller2ee294f2016-08-04 12:59:48 -060010216
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010217 const char *invalid_queueFamilyIndex_message = "Invalid queue create request in vkCreateDevice(). Invalid "
10218 "queueFamilyIndex ";
Mark Mueller2ee294f2016-08-04 12:59:48 -060010219
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010220 const char *unavailable_feature_message = "While calling vkCreateDevice(), requesting feature #";
Mark Mueller2ee294f2016-08-04 12:59:48 -060010221
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010222 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, mismatch_count_message);
Mark Mueller880fce52016-08-17 15:23:23 -060010223 // The following test fails with recent NVidia drivers.
10224 // By the time core_validation is reached, the NVidia
10225 // driver has sanitized the invalid condition and core_validation
10226 // is not introduced to the failure condition. This is not the case
10227 // with AMD and Mesa drivers. Futher investigation is required
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010228 // uint32_t count = static_cast<uint32_t>(~0);
10229 // VkPhysicalDevice physical_device;
10230 // vkEnumeratePhysicalDevices(instance(), &count, &physical_device);
10231 // m_errorMonitor->VerifyFound();
Mark Mueller2ee294f2016-08-04 12:59:48 -060010232
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010233 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_queueFamilyIndex_message);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010234 float queue_priority = 0.0;
10235
10236 VkDeviceQueueCreateInfo queue_create_info = {};
10237 queue_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
10238 queue_create_info.queueCount = 1;
10239 queue_create_info.pQueuePriorities = &queue_priority;
10240 queue_create_info.queueFamilyIndex = static_cast<uint32_t>(~0);
10241
10242 VkPhysicalDeviceFeatures features = m_device->phy().features();
10243 VkDevice testDevice;
10244 VkDeviceCreateInfo device_create_info = {};
10245 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
10246 device_create_info.queueCreateInfoCount = 1;
10247 device_create_info.pQueueCreateInfos = &queue_create_info;
10248 device_create_info.pEnabledFeatures = &features;
10249 vkCreateDevice(gpu(), &device_create_info, nullptr, &testDevice);
10250 m_errorMonitor->VerifyFound();
10251
10252 queue_create_info.queueFamilyIndex = 1;
10253
10254 unsigned feature_count = sizeof(VkPhysicalDeviceFeatures) / sizeof(VkBool32);
10255 VkBool32 *feature_array = reinterpret_cast<VkBool32 *>(&features);
10256 for (unsigned i = 0; i < feature_count; i++) {
10257 if (VK_FALSE == feature_array[i]) {
10258 feature_array[i] = VK_TRUE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010259 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, unavailable_feature_message);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010260 device_create_info.pEnabledFeatures = &features;
10261 vkCreateDevice(gpu(), &device_create_info, nullptr, &testDevice);
10262 m_errorMonitor->VerifyFound();
10263 break;
10264 }
10265 }
10266}
10267
Tobin Ehlis16edf082016-11-21 12:33:49 -070010268TEST_F(VkLayerTest, InvalidQueryPoolCreate) {
10269 TEST_DESCRIPTION("Attempt to create a query pool for PIPELINE_STATISTICS without enabling pipeline stats for the device.");
10270
10271 ASSERT_NO_FATAL_FAILURE(InitState());
10272
10273 const std::vector<VkQueueFamilyProperties> queue_props = m_device->queue_props;
10274 std::vector<VkDeviceQueueCreateInfo> queue_info;
10275 queue_info.reserve(queue_props.size());
10276 std::vector<std::vector<float>> queue_priorities;
10277 for (uint32_t i = 0; i < (uint32_t)queue_props.size(); i++) {
10278 VkDeviceQueueCreateInfo qi{};
10279 qi.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
10280 qi.queueFamilyIndex = i;
10281 qi.queueCount = queue_props[i].queueCount;
10282 queue_priorities.emplace_back(qi.queueCount, 0.0f);
10283 qi.pQueuePriorities = queue_priorities[i].data();
10284 queue_info.push_back(qi);
10285 }
10286
10287 std::vector<const char *> device_extension_names;
10288
10289 VkDevice local_device;
10290 VkDeviceCreateInfo device_create_info = {};
10291 auto features = m_device->phy().features();
10292 // Intentionally disable pipeline stats
10293 features.pipelineStatisticsQuery = VK_FALSE;
10294 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
10295 device_create_info.pNext = NULL;
10296 device_create_info.queueCreateInfoCount = queue_info.size();
10297 device_create_info.pQueueCreateInfos = queue_info.data();
10298 device_create_info.enabledLayerCount = 0;
10299 device_create_info.ppEnabledLayerNames = NULL;
10300 device_create_info.pEnabledFeatures = &features;
10301 VkResult err = vkCreateDevice(gpu(), &device_create_info, nullptr, &local_device);
10302 ASSERT_VK_SUCCESS(err);
10303
10304 VkQueryPoolCreateInfo qpci{};
10305 qpci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
10306 qpci.queryType = VK_QUERY_TYPE_PIPELINE_STATISTICS;
10307 qpci.queryCount = 1;
10308 VkQueryPool query_pool;
10309
10310 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01006);
10311 vkCreateQueryPool(local_device, &qpci, nullptr, &query_pool);
10312 m_errorMonitor->VerifyFound();
10313
10314 vkDestroyDevice(local_device, nullptr);
10315}
10316
Mark Mueller2ee294f2016-08-04 12:59:48 -060010317TEST_F(VkLayerTest, InvalidQueueIndexInvalidQuery) {
10318 TEST_DESCRIPTION("Use an invalid queue index in a vkCmdWaitEvents call."
10319 "End a command buffer with a query still in progress.");
10320
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010321 const char *invalid_queue_index = "was created with sharingMode of VK_SHARING_MODE_EXCLUSIVE. If one "
10322 "of src- or dstQueueFamilyIndex is VK_QUEUE_FAMILY_IGNORED, both "
10323 "must be.";
Mark Mueller2ee294f2016-08-04 12:59:48 -060010324
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010325 const char *invalid_query = "Ending command buffer with in progress query: queryPool 0x";
Mark Mueller2ee294f2016-08-04 12:59:48 -060010326
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010327 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_queue_index);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010328
10329 ASSERT_NO_FATAL_FAILURE(InitState());
10330
10331 VkEvent event;
10332 VkEventCreateInfo event_create_info{};
10333 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
10334 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
10335
Mark Mueller2ee294f2016-08-04 12:59:48 -060010336 VkQueue queue = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010337 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010338
10339 BeginCommandBuffer();
10340
10341 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010342 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 -060010343 ASSERT_TRUE(image.initialized());
10344 VkImageMemoryBarrier img_barrier = {};
10345 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
10346 img_barrier.pNext = NULL;
10347 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
10348 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
10349 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
10350 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
10351 img_barrier.image = image.handle();
10352 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
Mark Lobodzinski2a74c5c2016-08-17 13:26:28 -060010353
10354 // QueueFamilyIndex must be VK_QUEUE_FAMILY_IGNORED, this verifies
10355 // that layer validation catches the case when it is not.
10356 img_barrier.dstQueueFamilyIndex = 0;
Mark Mueller2ee294f2016-08-04 12:59:48 -060010357 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10358 img_barrier.subresourceRange.baseArrayLayer = 0;
10359 img_barrier.subresourceRange.baseMipLevel = 0;
10360 img_barrier.subresourceRange.layerCount = 1;
10361 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010362 vkCmdWaitEvents(m_commandBuffer->handle(), 1, &event, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0,
10363 nullptr, 0, nullptr, 1, &img_barrier);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010364 m_errorMonitor->VerifyFound();
10365
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010366 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_query);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010367
10368 VkQueryPool query_pool;
10369 VkQueryPoolCreateInfo query_pool_create_info = {};
10370 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
10371 query_pool_create_info.queryType = VK_QUERY_TYPE_OCCLUSION;
10372 query_pool_create_info.queryCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010373 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010374
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010375 vkCmdResetQueryPool(m_commandBuffer->handle(), query_pool, 0 /*startQuery*/, 1 /*queryCount*/);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010376 vkCmdBeginQuery(m_commandBuffer->handle(), query_pool, 0, 0);
10377
10378 vkEndCommandBuffer(m_commandBuffer->handle());
10379 m_errorMonitor->VerifyFound();
10380
10381 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
10382 vkDestroyEvent(m_device->device(), event, nullptr);
10383}
10384
Mark Muellerdfe37552016-07-07 14:47:42 -060010385TEST_F(VkLayerTest, VertexBufferInvalid) {
10386 TEST_DESCRIPTION("Submit a command buffer using deleted vertex buffer, "
10387 "delete a buffer twice, use an invalid offset for each "
10388 "buffer type, and attempt to bind a null buffer");
10389
10390 const char *deleted_buffer_in_command_buffer = "Cannot submit cmd buffer "
10391 "using deleted buffer ";
Mark Muellerdfe37552016-07-07 14:47:42 -060010392 const char *invalid_offset_message = "vkBindBufferMemory(): "
10393 "memoryOffset is 0x";
10394 const char *invalid_storage_buffer_offset_message = "vkBindBufferMemory(): "
10395 "storage memoryOffset "
10396 "is 0x";
10397 const char *invalid_texel_buffer_offset_message = "vkBindBufferMemory(): "
10398 "texel memoryOffset "
10399 "is 0x";
10400 const char *invalid_uniform_buffer_offset_message = "vkBindBufferMemory(): "
10401 "uniform memoryOffset "
10402 "is 0x";
Mark Muellerdfe37552016-07-07 14:47:42 -060010403
10404 ASSERT_NO_FATAL_FAILURE(InitState());
10405 ASSERT_NO_FATAL_FAILURE(InitViewport());
10406 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10407
10408 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010409 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Mark Muellerdfe37552016-07-07 14:47:42 -060010410 pipe_ms_state_ci.pNext = NULL;
10411 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
10412 pipe_ms_state_ci.sampleShadingEnable = 0;
10413 pipe_ms_state_ci.minSampleShading = 1.0;
10414 pipe_ms_state_ci.pSampleMask = nullptr;
10415
10416 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
10417 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10418 VkPipelineLayout pipeline_layout;
10419
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010420 VkResult err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, nullptr, &pipeline_layout);
Mark Muellerdfe37552016-07-07 14:47:42 -060010421 ASSERT_VK_SUCCESS(err);
10422
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010423 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
10424 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Muellerdfe37552016-07-07 14:47:42 -060010425 VkPipelineObj pipe(m_device);
10426 pipe.AddShader(&vs);
10427 pipe.AddShader(&fs);
10428 pipe.AddColorAttachment();
10429 pipe.SetMSAA(&pipe_ms_state_ci);
10430 pipe.SetViewport(m_viewports);
10431 pipe.SetScissor(m_scissors);
10432 pipe.CreateVKPipeline(pipeline_layout, renderPass());
10433
10434 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010435 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Mark Muellerdfe37552016-07-07 14:47:42 -060010436
10437 {
10438 // Create and bind a vertex buffer in a reduced scope, which will cause
10439 // it to be deleted upon leaving this scope
10440 const float vbo_data[3] = {1.f, 0.f, 1.f};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010441 VkVerticesObj draw_verticies(m_device, 1, 1, sizeof(vbo_data), 3, vbo_data);
Mark Muellerdfe37552016-07-07 14:47:42 -060010442 draw_verticies.BindVertexBuffers(m_commandBuffer->handle());
10443 draw_verticies.AddVertexInputToPipe(pipe);
10444 }
10445
10446 Draw(1, 0, 0, 0);
10447
10448 EndCommandBuffer();
10449
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010450 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, deleted_buffer_in_command_buffer);
Mark Muellerdfe37552016-07-07 14:47:42 -060010451 QueueCommandBuffer(false);
10452 m_errorMonitor->VerifyFound();
10453
10454 {
10455 // Create and bind a vertex buffer in a reduced scope, and delete it
10456 // twice, the second through the destructor
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010457 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eDoubleDelete);
Karl Schultzf78bcdd2016-11-30 12:36:01 -070010458 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00680);
Mark Muellerdfe37552016-07-07 14:47:42 -060010459 buffer_test.TestDoubleDestroy();
10460 }
10461 m_errorMonitor->VerifyFound();
10462
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010463 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidMemoryOffset)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060010464 // Create and bind a memory buffer with an invalid offset.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010465 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_offset_message);
10466 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT, VkBufferTest::eInvalidMemoryOffset);
10467 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010468 m_errorMonitor->VerifyFound();
10469 }
10470
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010471 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset,
10472 VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060010473 // Create and bind a memory buffer with an invalid offset again,
10474 // but look for a texel buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010475 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_texel_buffer_offset_message);
10476 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
10477 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010478 m_errorMonitor->VerifyFound();
10479 }
10480
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010481 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060010482 // Create and bind a memory buffer with an invalid offset again, but
10483 // look for a uniform buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010484 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_uniform_buffer_offset_message);
10485 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
10486 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010487 m_errorMonitor->VerifyFound();
10488 }
10489
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010490 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060010491 // Create and bind a memory buffer with an invalid offset again, but
10492 // look for a storage buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010493 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_storage_buffer_offset_message);
10494 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
10495 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010496 m_errorMonitor->VerifyFound();
10497 }
10498
10499 {
10500 // Attempt to bind a null buffer.
Karl Schultzf78bcdd2016-11-30 12:36:01 -070010501 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00799);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010502 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eBindNullBuffer);
10503 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010504 m_errorMonitor->VerifyFound();
10505 }
10506
10507 {
10508 // Attempt to use an invalid handle to delete a buffer.
Karl Schultzf78bcdd2016-11-30 12:36:01 -070010509 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00622);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010510 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eFreeInvalidHandle);
10511 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010512 }
10513 m_errorMonitor->VerifyFound();
10514
10515 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10516}
10517
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010518// INVALID_IMAGE_LAYOUT tests (one other case is hit by MapMemWithoutHostVisibleBit and not here)
10519TEST_F(VkLayerTest, InvalidImageLayout) {
10520 TEST_DESCRIPTION("Hit all possible validation checks associated with the "
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010521 "DRAWSTATE_INVALID_IMAGE_LAYOUT enum. Generally these involve having"
10522 "images in the wrong layout when they're copied or transitioned.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010523 // 3 in ValidateCmdBufImageLayouts
10524 // * -1 Attempt to submit cmd buf w/ deleted image
10525 // * -2 Cmd buf submit of image w/ layout not matching first use w/ subresource
10526 // * -3 Cmd buf submit of image w/ layout not matching first use w/o subresource
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010527
10528 ASSERT_NO_FATAL_FAILURE(InitState());
10529 // Create src & dst images to use for copy operations
10530 VkImage src_image;
10531 VkImage dst_image;
Cort3b021012016-12-07 12:00:57 -080010532 VkImage depth_image;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010533
10534 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
10535 const int32_t tex_width = 32;
10536 const int32_t tex_height = 32;
10537
10538 VkImageCreateInfo image_create_info = {};
10539 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
10540 image_create_info.pNext = NULL;
10541 image_create_info.imageType = VK_IMAGE_TYPE_2D;
10542 image_create_info.format = tex_format;
10543 image_create_info.extent.width = tex_width;
10544 image_create_info.extent.height = tex_height;
10545 image_create_info.extent.depth = 1;
10546 image_create_info.mipLevels = 1;
10547 image_create_info.arrayLayers = 4;
10548 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
10549 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
10550 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Cort3b021012016-12-07 12:00:57 -080010551 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010552 image_create_info.flags = 0;
10553
10554 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &src_image);
10555 ASSERT_VK_SUCCESS(err);
Cort3b021012016-12-07 12:00:57 -080010556 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010557 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dst_image);
10558 ASSERT_VK_SUCCESS(err);
Cort3b021012016-12-07 12:00:57 -080010559 image_create_info.format = VK_FORMAT_D32_SFLOAT;
10560 image_create_info.usage |= VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
10561 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &depth_image);
10562 ASSERT_VK_SUCCESS(err);
10563
10564 // Allocate memory
10565 VkMemoryRequirements img_mem_reqs = {};
Cort530cf382016-12-08 09:59:47 -080010566 VkMemoryAllocateInfo mem_alloc = {};
Cort3b021012016-12-07 12:00:57 -080010567 VkDeviceMemory src_image_mem, dst_image_mem, depth_image_mem;
Cort530cf382016-12-08 09:59:47 -080010568 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
10569 mem_alloc.pNext = NULL;
10570 mem_alloc.allocationSize = 0;
10571 mem_alloc.memoryTypeIndex = 0;
Cort3b021012016-12-07 12:00:57 -080010572
10573 vkGetImageMemoryRequirements(m_device->device(), src_image, &img_mem_reqs);
Cort530cf382016-12-08 09:59:47 -080010574 mem_alloc.allocationSize = img_mem_reqs.size;
10575 bool pass = m_device->phy().set_memory_type(img_mem_reqs.memoryTypeBits, &mem_alloc, 0);
Cort3b021012016-12-07 12:00:57 -080010576 ASSERT_TRUE(pass);
Cort530cf382016-12-08 09:59:47 -080010577 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &src_image_mem);
Cort3b021012016-12-07 12:00:57 -080010578 ASSERT_VK_SUCCESS(err);
10579
10580 vkGetImageMemoryRequirements(m_device->device(), dst_image, &img_mem_reqs);
Cort530cf382016-12-08 09:59:47 -080010581 mem_alloc.allocationSize = img_mem_reqs.size;
10582 pass = m_device->phy().set_memory_type(img_mem_reqs.memoryTypeBits, &mem_alloc, 0);
Cort3b021012016-12-07 12:00:57 -080010583 ASSERT_VK_SUCCESS(err);
Cort530cf382016-12-08 09:59:47 -080010584 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &dst_image_mem);
Cort3b021012016-12-07 12:00:57 -080010585 ASSERT_VK_SUCCESS(err);
10586
10587 vkGetImageMemoryRequirements(m_device->device(), depth_image, &img_mem_reqs);
Cort530cf382016-12-08 09:59:47 -080010588 mem_alloc.allocationSize = img_mem_reqs.size;
10589 pass = m_device->phy().set_memory_type(img_mem_reqs.memoryTypeBits, &mem_alloc, 0);
Cort3b021012016-12-07 12:00:57 -080010590 ASSERT_VK_SUCCESS(err);
Cort530cf382016-12-08 09:59:47 -080010591 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &depth_image_mem);
Cort3b021012016-12-07 12:00:57 -080010592 ASSERT_VK_SUCCESS(err);
10593
10594 err = vkBindImageMemory(m_device->device(), src_image, src_image_mem, 0);
10595 ASSERT_VK_SUCCESS(err);
10596 err = vkBindImageMemory(m_device->device(), dst_image, dst_image_mem, 0);
10597 ASSERT_VK_SUCCESS(err);
10598 err = vkBindImageMemory(m_device->device(), depth_image, depth_image_mem, 0);
10599 ASSERT_VK_SUCCESS(err);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010600
10601 BeginCommandBuffer();
Cort530cf382016-12-08 09:59:47 -080010602 VkImageCopy copy_region;
10603 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10604 copy_region.srcSubresource.mipLevel = 0;
10605 copy_region.srcSubresource.baseArrayLayer = 0;
10606 copy_region.srcSubresource.layerCount = 1;
10607 copy_region.srcOffset.x = 0;
10608 copy_region.srcOffset.y = 0;
10609 copy_region.srcOffset.z = 0;
10610 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10611 copy_region.dstSubresource.mipLevel = 0;
10612 copy_region.dstSubresource.baseArrayLayer = 0;
10613 copy_region.dstSubresource.layerCount = 1;
10614 copy_region.dstOffset.x = 0;
10615 copy_region.dstOffset.y = 0;
10616 copy_region.dstOffset.z = 0;
10617 copy_region.extent.width = 1;
10618 copy_region.extent.height = 1;
10619 copy_region.extent.depth = 1;
10620
10621 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10622 "Layout for input image should be TRANSFER_SRC_OPTIMAL instead of GENERAL.");
10623 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 -060010624 m_errorMonitor->VerifyFound();
10625 // Now cause error due to src image layout changing
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010626 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot copy from an image whose source layout is "
10627 "VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current "
10628 "layout VK_IMAGE_LAYOUT_GENERAL.");
Cort530cf382016-12-08 09:59:47 -080010629 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 -060010630 m_errorMonitor->VerifyFound();
10631 // Final src error is due to bad layout type
10632 m_errorMonitor->SetDesiredFailureMsg(
10633 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10634 "Layout for input image is VK_IMAGE_LAYOUT_UNDEFINED but can only be TRANSFER_SRC_OPTIMAL or GENERAL.");
Cort530cf382016-12-08 09:59:47 -080010635 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 -060010636 m_errorMonitor->VerifyFound();
10637 // Now verify same checks for dst
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010638 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10639 "Layout for output image should be TRANSFER_DST_OPTIMAL instead of GENERAL.");
Cort530cf382016-12-08 09:59:47 -080010640 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 -060010641 m_errorMonitor->VerifyFound();
10642 // Now cause error due to src image layout changing
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010643 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot copy from an image whose dest layout is "
10644 "VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current "
10645 "layout VK_IMAGE_LAYOUT_GENERAL.");
Cort530cf382016-12-08 09:59:47 -080010646 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 -060010647 m_errorMonitor->VerifyFound();
10648 m_errorMonitor->SetDesiredFailureMsg(
10649 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10650 "Layout for output image is VK_IMAGE_LAYOUT_UNDEFINED but can only be TRANSFER_DST_OPTIMAL or GENERAL.");
Cort530cf382016-12-08 09:59:47 -080010651 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 -060010652 m_errorMonitor->VerifyFound();
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010010653
Cort3b021012016-12-07 12:00:57 -080010654 // Convert dst and depth images to TRANSFER_DST for subsequent tests
10655 VkImageMemoryBarrier transfer_dst_image_barrier[1] = {};
10656 transfer_dst_image_barrier[0].sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
10657 transfer_dst_image_barrier[0].oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
10658 transfer_dst_image_barrier[0].newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
10659 transfer_dst_image_barrier[0].srcAccessMask = 0;
10660 transfer_dst_image_barrier[0].dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
10661 transfer_dst_image_barrier[0].image = dst_image;
10662 transfer_dst_image_barrier[0].subresourceRange.layerCount = image_create_info.arrayLayers;
10663 transfer_dst_image_barrier[0].subresourceRange.levelCount = image_create_info.mipLevels;
10664 transfer_dst_image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10665 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
10666 NULL, 0, NULL, 1, transfer_dst_image_barrier);
10667 transfer_dst_image_barrier[0].image = depth_image;
10668 transfer_dst_image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
10669 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
10670 NULL, 0, NULL, 1, transfer_dst_image_barrier);
10671
10672 // Cause errors due to clearing with invalid image layouts
Cort530cf382016-12-08 09:59:47 -080010673 VkClearColorValue color_clear_value = {};
10674 VkImageSubresourceRange clear_range;
10675 clear_range.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10676 clear_range.baseMipLevel = 0;
10677 clear_range.baseArrayLayer = 0;
10678 clear_range.layerCount = 1;
10679 clear_range.levelCount = 1;
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010010680
Cort3b021012016-12-07 12:00:57 -080010681 // Fail due to explicitly prohibited layout for color clear (only GENERAL and TRANSFER_DST are permitted).
10682 // Since the image is currently not in UNDEFINED layout, this will emit two errors.
10683 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01086);
10684 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01085);
Cort530cf382016-12-08 09:59:47 -080010685 m_commandBuffer->ClearColorImage(dst_image, VK_IMAGE_LAYOUT_UNDEFINED, &color_clear_value, 1, &clear_range);
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010010686 m_errorMonitor->VerifyFound();
Cort3b021012016-12-07 12:00:57 -080010687 // Fail due to provided layout not matching actual current layout for color clear.
10688 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01085);
Cort530cf382016-12-08 09:59:47 -080010689 m_commandBuffer->ClearColorImage(dst_image, VK_IMAGE_LAYOUT_GENERAL, &color_clear_value, 1, &clear_range);
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010010690 m_errorMonitor->VerifyFound();
Cort3b021012016-12-07 12:00:57 -080010691
Cort530cf382016-12-08 09:59:47 -080010692 VkClearDepthStencilValue depth_clear_value = {};
10693 clear_range.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
Cort3b021012016-12-07 12:00:57 -080010694
10695 // Fail due to explicitly prohibited layout for depth clear (only GENERAL and TRANSFER_DST are permitted).
10696 // Since the image is currently not in UNDEFINED layout, this will emit two errors.
10697 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01101);
10698 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01100);
Cort530cf382016-12-08 09:59:47 -080010699 m_commandBuffer->ClearDepthStencilImage(depth_image, VK_IMAGE_LAYOUT_UNDEFINED, &depth_clear_value, 1, &clear_range);
Cort3b021012016-12-07 12:00:57 -080010700 m_errorMonitor->VerifyFound();
10701 // Fail due to provided layout not matching actual current layout for depth clear.
10702 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01100);
Cort530cf382016-12-08 09:59:47 -080010703 m_commandBuffer->ClearDepthStencilImage(depth_image, VK_IMAGE_LAYOUT_GENERAL, &depth_clear_value, 1, &clear_range);
Cort3b021012016-12-07 12:00:57 -080010704 m_errorMonitor->VerifyFound();
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010010705
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010706 // Now cause error due to bad image layout transition in PipelineBarrier
10707 VkImageMemoryBarrier image_barrier[1] = {};
Cort3b021012016-12-07 12:00:57 -080010708 image_barrier[0].sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010709 image_barrier[0].oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
Cort3b021012016-12-07 12:00:57 -080010710 image_barrier[0].newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010711 image_barrier[0].image = src_image;
Cort3b021012016-12-07 12:00:57 -080010712 image_barrier[0].subresourceRange.layerCount = image_create_info.arrayLayers;
10713 image_barrier[0].subresourceRange.levelCount = image_create_info.mipLevels;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010714 image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010715 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "You cannot transition the layout from "
10716 "VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL when "
10717 "current layout is VK_IMAGE_LAYOUT_GENERAL.");
10718 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
10719 NULL, 0, NULL, 1, image_barrier);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010720 m_errorMonitor->VerifyFound();
10721
10722 // Finally some layout errors at RenderPass create time
10723 // Just hacking in specific state to get to the errors we want so don't copy this unless you know what you're doing.
10724 VkAttachmentReference attach = {};
10725 // perf warning for GENERAL layout w/ non-DS input attachment
10726 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
10727 VkSubpassDescription subpass = {};
10728 subpass.inputAttachmentCount = 1;
10729 subpass.pInputAttachments = &attach;
10730 VkRenderPassCreateInfo rpci = {};
10731 rpci.subpassCount = 1;
10732 rpci.pSubpasses = &subpass;
10733 rpci.attachmentCount = 1;
10734 VkAttachmentDescription attach_desc = {};
10735 attach_desc.format = VK_FORMAT_UNDEFINED;
10736 rpci.pAttachments = &attach_desc;
Tobin Ehlis1efce022016-05-11 10:40:34 -060010737 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010738 VkRenderPass rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010739 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10740 "Layout for input attachment is GENERAL but should be READ_ONLY_OPTIMAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010741 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10742 m_errorMonitor->VerifyFound();
10743 // error w/ non-general layout
10744 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
10745
10746 m_errorMonitor->SetDesiredFailureMsg(
10747 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10748 "Layout for input attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be READ_ONLY_OPTIMAL or GENERAL.");
10749 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10750 m_errorMonitor->VerifyFound();
10751 subpass.inputAttachmentCount = 0;
10752 subpass.colorAttachmentCount = 1;
10753 subpass.pColorAttachments = &attach;
10754 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
10755 // perf warning for GENERAL layout on color attachment
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010756 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10757 "Layout for color attachment is GENERAL but should be COLOR_ATTACHMENT_OPTIMAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010758 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10759 m_errorMonitor->VerifyFound();
10760 // error w/ non-color opt or GENERAL layout for color attachment
10761 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
10762 m_errorMonitor->SetDesiredFailureMsg(
10763 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10764 "Layout for color attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be COLOR_ATTACHMENT_OPTIMAL or GENERAL.");
10765 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10766 m_errorMonitor->VerifyFound();
10767 subpass.colorAttachmentCount = 0;
10768 subpass.pDepthStencilAttachment = &attach;
10769 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
10770 // perf warning for GENERAL layout on DS attachment
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010771 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10772 "GENERAL layout for depth attachment may not give optimal performance.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010773 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10774 m_errorMonitor->VerifyFound();
10775 // error w/ non-ds opt or GENERAL layout for color attachment
10776 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010777 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10778 "Layout for depth attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be "
10779 "DEPTH_STENCIL_ATTACHMENT_OPTIMAL, DEPTH_STENCIL_READ_ONLY_OPTIMAL or GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010780 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10781 m_errorMonitor->VerifyFound();
Tobin Ehlis1efce022016-05-11 10:40:34 -060010782 // For this error we need a valid renderpass so create default one
10783 attach.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
10784 attach.attachment = 0;
10785 attach_desc.format = VK_FORMAT_D24_UNORM_S8_UINT;
10786 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
10787 attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
10788 attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
10789 attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
10790 // Can't do a CLEAR load on READ_ONLY initialLayout
10791 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
10792 attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
10793 attach_desc.finalLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010794 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " with invalid first layout "
10795 "VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_"
10796 "ONLY_OPTIMAL");
Tobin Ehlis1efce022016-05-11 10:40:34 -060010797 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10798 m_errorMonitor->VerifyFound();
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010799
Cort3b021012016-12-07 12:00:57 -080010800 vkFreeMemory(m_device->device(), src_image_mem, NULL);
10801 vkFreeMemory(m_device->device(), dst_image_mem, NULL);
10802 vkFreeMemory(m_device->device(), depth_image_mem, NULL);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010803 vkDestroyImage(m_device->device(), src_image, NULL);
10804 vkDestroyImage(m_device->device(), dst_image, NULL);
Cort3b021012016-12-07 12:00:57 -080010805 vkDestroyImage(m_device->device(), depth_image, NULL);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010806}
Tobin Ehlisd8d89182016-07-18 20:13:11 -060010807
Tobin Ehlise0936662016-10-11 08:10:51 -060010808TEST_F(VkLayerTest, InvalidStorageImageLayout) {
10809 TEST_DESCRIPTION("Attempt to update a STORAGE_IMAGE descriptor w/o GENERAL layout.");
10810 VkResult err;
10811
10812 ASSERT_NO_FATAL_FAILURE(InitState());
10813
10814 const VkFormat tex_format = VK_FORMAT_R8G8B8A8_UNORM;
10815 VkImageTiling tiling;
10816 VkFormatProperties format_properties;
10817 vkGetPhysicalDeviceFormatProperties(gpu(), tex_format, &format_properties);
10818 if (format_properties.linearTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
10819 tiling = VK_IMAGE_TILING_LINEAR;
10820 } else if (format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
10821 tiling = VK_IMAGE_TILING_OPTIMAL;
10822 } else {
10823 printf("Device does not support VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT; "
10824 "skipped.\n");
10825 return;
10826 }
10827
10828 VkDescriptorPoolSize ds_type = {};
10829 ds_type.type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
10830 ds_type.descriptorCount = 1;
10831
10832 VkDescriptorPoolCreateInfo ds_pool_ci = {};
10833 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10834 ds_pool_ci.maxSets = 1;
10835 ds_pool_ci.poolSizeCount = 1;
10836 ds_pool_ci.pPoolSizes = &ds_type;
10837 ds_pool_ci.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
10838
10839 VkDescriptorPool ds_pool;
10840 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
10841 ASSERT_VK_SUCCESS(err);
10842
10843 VkDescriptorSetLayoutBinding dsl_binding = {};
10844 dsl_binding.binding = 0;
10845 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
10846 dsl_binding.descriptorCount = 1;
10847 dsl_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
10848 dsl_binding.pImmutableSamplers = NULL;
10849
10850 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10851 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10852 ds_layout_ci.pNext = NULL;
10853 ds_layout_ci.bindingCount = 1;
10854 ds_layout_ci.pBindings = &dsl_binding;
10855
10856 VkDescriptorSetLayout ds_layout;
10857 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
10858 ASSERT_VK_SUCCESS(err);
10859
10860 VkDescriptorSetAllocateInfo alloc_info = {};
10861 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
10862 alloc_info.descriptorSetCount = 1;
10863 alloc_info.descriptorPool = ds_pool;
10864 alloc_info.pSetLayouts = &ds_layout;
10865 VkDescriptorSet descriptor_set;
10866 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
10867 ASSERT_VK_SUCCESS(err);
10868
10869 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
10870 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10871 pipeline_layout_ci.pNext = NULL;
10872 pipeline_layout_ci.setLayoutCount = 1;
10873 pipeline_layout_ci.pSetLayouts = &ds_layout;
10874 VkPipelineLayout pipeline_layout;
10875 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
10876 ASSERT_VK_SUCCESS(err);
10877
10878 VkImageObj image(m_device);
10879 image.init(32, 32, tex_format, VK_IMAGE_USAGE_STORAGE_BIT, tiling, 0);
10880 ASSERT_TRUE(image.initialized());
10881 VkImageView view = image.targetView(tex_format);
10882
10883 VkDescriptorImageInfo image_info = {};
10884 image_info.imageView = view;
10885 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
10886
10887 VkWriteDescriptorSet descriptor_write = {};
10888 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
10889 descriptor_write.dstSet = descriptor_set;
10890 descriptor_write.dstBinding = 0;
10891 descriptor_write.descriptorCount = 1;
10892 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
10893 descriptor_write.pImageInfo = &image_info;
10894
10895 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10896 " of VK_DESCRIPTOR_TYPE_STORAGE_IMAGE type is being updated with layout "
10897 "VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL but according to spec ");
10898 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10899 m_errorMonitor->VerifyFound();
10900
10901 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10902 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10903 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
10904 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
10905}
10906
Mark Mueller93b938f2016-08-18 10:27:40 -060010907TEST_F(VkLayerTest, SimultaneousUse) {
10908 TEST_DESCRIPTION("Use vkCmdExecuteCommands with invalid state "
10909 "in primary and secondary command buffers.");
10910
10911 ASSERT_NO_FATAL_FAILURE(InitState());
10912 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10913
Mike Weiblen95dd0f92016-10-19 12:28:27 -060010914 const char *simultaneous_use_message1 = "without VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set!";
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010915 const char *simultaneous_use_message2 = "does not have VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set and "
10916 "will cause primary command buffer";
Mark Mueller93b938f2016-08-18 10:27:40 -060010917
10918 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010919 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Mueller93b938f2016-08-18 10:27:40 -060010920 command_buffer_allocate_info.commandPool = m_commandPool;
10921 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
10922 command_buffer_allocate_info.commandBufferCount = 1;
10923
10924 VkCommandBuffer secondary_command_buffer;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010925 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer));
Mark Mueller93b938f2016-08-18 10:27:40 -060010926 VkCommandBufferBeginInfo command_buffer_begin_info = {};
10927 VkCommandBufferInheritanceInfo command_buffer_inheritance_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010928 command_buffer_inheritance_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
Mark Mueller93b938f2016-08-18 10:27:40 -060010929 command_buffer_inheritance_info.renderPass = m_renderPass;
10930 command_buffer_inheritance_info.framebuffer = m_framebuffer;
10931 command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010932 command_buffer_begin_info.flags =
10933 VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT | VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT;
Mark Mueller93b938f2016-08-18 10:27:40 -060010934 command_buffer_begin_info.pInheritanceInfo = &command_buffer_inheritance_info;
10935
10936 vkBeginCommandBuffer(secondary_command_buffer, &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010937 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
10938 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller4042b652016-09-05 22:52:21 -060010939 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
Mark Mueller93b938f2016-08-18 10:27:40 -060010940 vkEndCommandBuffer(secondary_command_buffer);
10941
Mark Mueller93b938f2016-08-18 10:27:40 -060010942 VkSubmitInfo submit_info = {};
10943 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
10944 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010945 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Mueller4042b652016-09-05 22:52:21 -060010946 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Mueller93b938f2016-08-18 10:27:40 -060010947
Mark Mueller4042b652016-09-05 22:52:21 -060010948 vkBeginCommandBuffer(m_commandBuffer->handle(), &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010949 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
10950 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, simultaneous_use_message1);
10951 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller93b938f2016-08-18 10:27:40 -060010952 m_errorMonitor->VerifyFound();
Mark Mueller4042b652016-09-05 22:52:21 -060010953 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
10954 vkEndCommandBuffer(m_commandBuffer->handle());
Mark Mueller93b938f2016-08-18 10:27:40 -060010955
10956 m_errorMonitor->SetDesiredFailureMsg(0, "");
Mark Mueller93b938f2016-08-18 10:27:40 -060010957 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
10958
Mark Mueller4042b652016-09-05 22:52:21 -060010959 command_buffer_begin_info.flags = VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT;
Mark Mueller93b938f2016-08-18 10:27:40 -060010960 vkBeginCommandBuffer(m_commandBuffer->handle(), &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010961 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
Mark Mueller4042b652016-09-05 22:52:21 -060010962
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010963 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, simultaneous_use_message2);
10964 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller93b938f2016-08-18 10:27:40 -060010965 m_errorMonitor->VerifyFound();
Mark Mueller4042b652016-09-05 22:52:21 -060010966 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
10967 vkEndCommandBuffer(m_commandBuffer->handle());
Mark Mueller93b938f2016-08-18 10:27:40 -060010968}
10969
Mark Mueller917f6bc2016-08-30 10:57:19 -060010970TEST_F(VkLayerTest, InUseDestroyedSignaled) {
10971 TEST_DESCRIPTION("Use vkCmdExecuteCommands with invalid state "
10972 "in primary and secondary command buffers. "
Mark Muellerc8d441e2016-08-23 17:36:00 -060010973 "Delete objects that are inuse. Call VkQueueSubmit "
10974 "with an event that has been deleted.");
Mark Mueller917f6bc2016-08-30 10:57:19 -060010975
10976 ASSERT_NO_FATAL_FAILURE(InitState());
10977 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10978
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010979 const char *submit_with_deleted_event_message = "Cannot submit cmd buffer using deleted event 0x";
10980 const char *cannot_delete_event_message = "Cannot delete event 0x";
10981 const char *cannot_delete_semaphore_message = "Cannot delete semaphore 0x";
10982 const char *cannot_destroy_fence_message = "Fence 0x";
Mark Mueller917f6bc2016-08-30 10:57:19 -060010983
10984 BeginCommandBuffer();
10985
10986 VkEvent event;
10987 VkEventCreateInfo event_create_info = {};
10988 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
10989 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010990 vkCmdSetEvent(m_commandBuffer->handle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Mark Mueller917f6bc2016-08-30 10:57:19 -060010991
Mark Muellerc8d441e2016-08-23 17:36:00 -060010992 EndCommandBuffer();
10993 vkDestroyEvent(m_device->device(), event, nullptr);
10994
10995 VkSubmitInfo submit_info = {};
10996 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
10997 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010998 submit_info.pCommandBuffers = &m_commandBuffer->handle();
10999 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, submit_with_deleted_event_message);
Mark Muellerc8d441e2016-08-23 17:36:00 -060011000 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11001 m_errorMonitor->VerifyFound();
11002
11003 m_errorMonitor->SetDesiredFailureMsg(0, "");
11004 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
11005
11006 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
11007
Mark Mueller917f6bc2016-08-30 10:57:19 -060011008 VkSemaphoreCreateInfo semaphore_create_info = {};
11009 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
11010 VkSemaphore semaphore;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011011 ASSERT_VK_SUCCESS(vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore));
Mark Mueller917f6bc2016-08-30 10:57:19 -060011012 VkFenceCreateInfo fence_create_info = {};
11013 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
11014 VkFence fence;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011015 ASSERT_VK_SUCCESS(vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence));
Mark Mueller917f6bc2016-08-30 10:57:19 -060011016
11017 VkDescriptorPoolSize descriptor_pool_type_count = {};
Mark Mueller4042b652016-09-05 22:52:21 -060011018 descriptor_pool_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Mark Mueller917f6bc2016-08-30 10:57:19 -060011019 descriptor_pool_type_count.descriptorCount = 1;
11020
11021 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
11022 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11023 descriptor_pool_create_info.maxSets = 1;
11024 descriptor_pool_create_info.poolSizeCount = 1;
11025 descriptor_pool_create_info.pPoolSizes = &descriptor_pool_type_count;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011026 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
Mark Mueller917f6bc2016-08-30 10:57:19 -060011027
11028 VkDescriptorPool descriptorset_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011029 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
Mark Mueller917f6bc2016-08-30 10:57:19 -060011030
11031 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
Mark Mueller4042b652016-09-05 22:52:21 -060011032 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Mark Mueller917f6bc2016-08-30 10:57:19 -060011033 descriptorset_layout_binding.descriptorCount = 1;
11034 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_ALL;
11035
11036 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011037 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060011038 descriptorset_layout_create_info.bindingCount = 1;
11039 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
11040
11041 VkDescriptorSetLayout descriptorset_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011042 ASSERT_VK_SUCCESS(
11043 vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
Mark Mueller917f6bc2016-08-30 10:57:19 -060011044
11045 VkDescriptorSet descriptorset;
11046 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011047 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060011048 descriptorset_allocate_info.descriptorSetCount = 1;
11049 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
11050 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011051 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
Mark Mueller917f6bc2016-08-30 10:57:19 -060011052
Mark Mueller4042b652016-09-05 22:52:21 -060011053 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
11054
11055 VkDescriptorBufferInfo buffer_info = {};
11056 buffer_info.buffer = buffer_test.GetBuffer();
11057 buffer_info.offset = 0;
11058 buffer_info.range = 1024;
11059
11060 VkWriteDescriptorSet write_descriptor_set = {};
11061 write_descriptor_set.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
11062 write_descriptor_set.dstSet = descriptorset;
11063 write_descriptor_set.descriptorCount = 1;
11064 write_descriptor_set.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11065 write_descriptor_set.pBufferInfo = &buffer_info;
11066
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011067 vkUpdateDescriptorSets(m_device->device(), 1, &write_descriptor_set, 0, nullptr);
Mark Mueller4042b652016-09-05 22:52:21 -060011068
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011069 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
11070 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Mueller917f6bc2016-08-30 10:57:19 -060011071
11072 VkPipelineObj pipe(m_device);
11073 pipe.AddColorAttachment();
11074 pipe.AddShader(&vs);
11075 pipe.AddShader(&fs);
11076
11077 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011078 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060011079 pipeline_layout_create_info.setLayoutCount = 1;
11080 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
11081
11082 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011083 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
Mark Mueller917f6bc2016-08-30 10:57:19 -060011084
11085 pipe.CreateVKPipeline(pipeline_layout, m_renderPass);
11086
Mark Muellerc8d441e2016-08-23 17:36:00 -060011087 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011088 vkCmdSetEvent(m_commandBuffer->handle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Mark Muellerc8d441e2016-08-23 17:36:00 -060011089
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011090 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
11091 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
11092 &descriptorset, 0, NULL);
Mark Mueller917f6bc2016-08-30 10:57:19 -060011093
Mark Muellerc8d441e2016-08-23 17:36:00 -060011094 EndCommandBuffer();
Mark Mueller917f6bc2016-08-30 10:57:19 -060011095
Mark Mueller917f6bc2016-08-30 10:57:19 -060011096 submit_info.signalSemaphoreCount = 1;
11097 submit_info.pSignalSemaphores = &semaphore;
11098 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
Mark Muellerc8d441e2016-08-23 17:36:00 -060011099
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011100 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, cannot_delete_event_message);
Mark Mueller917f6bc2016-08-30 10:57:19 -060011101 vkDestroyEvent(m_device->device(), event, nullptr);
11102 m_errorMonitor->VerifyFound();
11103
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011104 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, cannot_delete_semaphore_message);
Mark Mueller917f6bc2016-08-30 10:57:19 -060011105 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
11106 m_errorMonitor->VerifyFound();
11107
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011108 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, cannot_destroy_fence_message);
Mark Mueller917f6bc2016-08-30 10:57:19 -060011109 vkDestroyFence(m_device->device(), fence, nullptr);
11110 m_errorMonitor->VerifyFound();
11111
Tobin Ehlis122207b2016-09-01 08:50:06 -070011112 vkQueueWaitIdle(m_device->m_queue);
Mark Mueller917f6bc2016-08-30 10:57:19 -060011113 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
11114 vkDestroyFence(m_device->device(), fence, nullptr);
11115 vkDestroyEvent(m_device->device(), event, nullptr);
11116 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011117 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
Mark Mueller917f6bc2016-08-30 10:57:19 -060011118 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
11119}
11120
Tobin Ehlis2adda372016-09-01 08:51:06 -070011121TEST_F(VkLayerTest, QueryPoolInUseDestroyedSignaled) {
11122 TEST_DESCRIPTION("Delete in-use query pool.");
11123
11124 ASSERT_NO_FATAL_FAILURE(InitState());
11125 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11126
11127 VkQueryPool query_pool;
11128 VkQueryPoolCreateInfo query_pool_ci{};
11129 query_pool_ci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
11130 query_pool_ci.queryType = VK_QUERY_TYPE_TIMESTAMP;
11131 query_pool_ci.queryCount = 1;
11132 vkCreateQueryPool(m_device->device(), &query_pool_ci, nullptr, &query_pool);
11133 BeginCommandBuffer();
11134 // Reset query pool to create binding with cmd buffer
11135 vkCmdResetQueryPool(m_commandBuffer->handle(), query_pool, 0, 1);
11136
11137 EndCommandBuffer();
11138
11139 VkSubmitInfo submit_info = {};
11140 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11141 submit_info.commandBufferCount = 1;
11142 submit_info.pCommandBuffers = &m_commandBuffer->handle();
11143 // Submit cmd buffer and then destroy query pool while in-flight
11144 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11145
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011146 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete query pool 0x");
Tobin Ehlis2adda372016-09-01 08:51:06 -070011147 vkDestroyQueryPool(m_device->handle(), query_pool, NULL);
11148 m_errorMonitor->VerifyFound();
11149
11150 vkQueueWaitIdle(m_device->m_queue);
11151 // Now that cmd buffer done we can safely destroy query_pool
11152 vkDestroyQueryPool(m_device->handle(), query_pool, NULL);
11153}
11154
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060011155TEST_F(VkLayerTest, PipelineInUseDestroyedSignaled) {
11156 TEST_DESCRIPTION("Delete in-use pipeline.");
11157
11158 ASSERT_NO_FATAL_FAILURE(InitState());
11159 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11160
11161 // Empty pipeline layout used for binding PSO
11162 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11163 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11164 pipeline_layout_ci.setLayoutCount = 0;
11165 pipeline_layout_ci.pSetLayouts = NULL;
11166
11167 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011168 VkResult err = vkCreatePipelineLayout(m_device->handle(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060011169 ASSERT_VK_SUCCESS(err);
11170
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011171 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete pipeline 0x");
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060011172 // Create PSO to be used for draw-time errors below
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011173 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
11174 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060011175 // Store pipeline handle so we can actually delete it before test finishes
11176 VkPipeline delete_this_pipeline;
11177 { // Scope pipeline so it will be auto-deleted
11178 VkPipelineObj pipe(m_device);
11179 pipe.AddShader(&vs);
11180 pipe.AddShader(&fs);
11181 pipe.AddColorAttachment();
11182 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11183 delete_this_pipeline = pipe.handle();
11184
11185 BeginCommandBuffer();
11186 // Bind pipeline to cmd buffer
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011187 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060011188
11189 EndCommandBuffer();
11190
11191 VkSubmitInfo submit_info = {};
11192 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11193 submit_info.commandBufferCount = 1;
11194 submit_info.pCommandBuffers = &m_commandBuffer->handle();
11195 // Submit cmd buffer and then pipeline destroyed while in-flight
11196 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11197 } // Pipeline deletion triggered here
11198 m_errorMonitor->VerifyFound();
11199 // Make sure queue finished and then actually delete pipeline
11200 vkQueueWaitIdle(m_device->m_queue);
11201 vkDestroyPipeline(m_device->handle(), delete_this_pipeline, nullptr);
11202 vkDestroyPipelineLayout(m_device->handle(), pipeline_layout, nullptr);
11203}
11204
Tobin Ehlis7d965da2016-09-19 16:15:45 -060011205TEST_F(VkLayerTest, ImageViewInUseDestroyedSignaled) {
11206 TEST_DESCRIPTION("Delete in-use imageView.");
11207
11208 ASSERT_NO_FATAL_FAILURE(InitState());
11209 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11210
11211 VkDescriptorPoolSize ds_type_count;
11212 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11213 ds_type_count.descriptorCount = 1;
11214
11215 VkDescriptorPoolCreateInfo ds_pool_ci = {};
11216 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11217 ds_pool_ci.maxSets = 1;
11218 ds_pool_ci.poolSizeCount = 1;
11219 ds_pool_ci.pPoolSizes = &ds_type_count;
11220
11221 VkDescriptorPool ds_pool;
11222 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
11223 ASSERT_VK_SUCCESS(err);
11224
11225 VkSamplerCreateInfo sampler_ci = {};
11226 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
11227 sampler_ci.pNext = NULL;
11228 sampler_ci.magFilter = VK_FILTER_NEAREST;
11229 sampler_ci.minFilter = VK_FILTER_NEAREST;
11230 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
11231 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11232 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11233 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11234 sampler_ci.mipLodBias = 1.0;
11235 sampler_ci.anisotropyEnable = VK_FALSE;
11236 sampler_ci.maxAnisotropy = 1;
11237 sampler_ci.compareEnable = VK_FALSE;
11238 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
11239 sampler_ci.minLod = 1.0;
11240 sampler_ci.maxLod = 1.0;
11241 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
11242 sampler_ci.unnormalizedCoordinates = VK_FALSE;
11243 VkSampler sampler;
11244
11245 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
11246 ASSERT_VK_SUCCESS(err);
11247
11248 VkDescriptorSetLayoutBinding layout_binding;
11249 layout_binding.binding = 0;
11250 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11251 layout_binding.descriptorCount = 1;
11252 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
11253 layout_binding.pImmutableSamplers = NULL;
11254
11255 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11256 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11257 ds_layout_ci.bindingCount = 1;
11258 ds_layout_ci.pBindings = &layout_binding;
11259 VkDescriptorSetLayout ds_layout;
11260 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
11261 ASSERT_VK_SUCCESS(err);
11262
11263 VkDescriptorSetAllocateInfo alloc_info = {};
11264 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11265 alloc_info.descriptorSetCount = 1;
11266 alloc_info.descriptorPool = ds_pool;
11267 alloc_info.pSetLayouts = &ds_layout;
11268 VkDescriptorSet descriptor_set;
11269 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
11270 ASSERT_VK_SUCCESS(err);
11271
11272 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11273 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11274 pipeline_layout_ci.pNext = NULL;
11275 pipeline_layout_ci.setLayoutCount = 1;
11276 pipeline_layout_ci.pSetLayouts = &ds_layout;
11277
11278 VkPipelineLayout pipeline_layout;
11279 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
11280 ASSERT_VK_SUCCESS(err);
11281
11282 VkImageObj image(m_device);
11283 image.init(128, 128, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
11284 ASSERT_TRUE(image.initialized());
11285
11286 VkImageView view;
11287 VkImageViewCreateInfo ivci = {};
11288 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
11289 ivci.image = image.handle();
11290 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
11291 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
11292 ivci.subresourceRange.layerCount = 1;
11293 ivci.subresourceRange.baseMipLevel = 0;
11294 ivci.subresourceRange.levelCount = 1;
11295 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11296
11297 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
11298 ASSERT_VK_SUCCESS(err);
11299
11300 VkDescriptorImageInfo image_info{};
11301 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
11302 image_info.imageView = view;
11303 image_info.sampler = sampler;
11304
11305 VkWriteDescriptorSet descriptor_write = {};
11306 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
11307 descriptor_write.dstSet = descriptor_set;
11308 descriptor_write.dstBinding = 0;
11309 descriptor_write.descriptorCount = 1;
11310 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11311 descriptor_write.pImageInfo = &image_info;
11312
11313 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11314
11315 // Create PSO to use the sampler
11316 char const *vsSource = "#version 450\n"
11317 "\n"
11318 "out gl_PerVertex { \n"
11319 " vec4 gl_Position;\n"
11320 "};\n"
11321 "void main(){\n"
11322 " gl_Position = vec4(1);\n"
11323 "}\n";
11324 char const *fsSource = "#version 450\n"
11325 "\n"
11326 "layout(set=0, binding=0) uniform sampler2D s;\n"
11327 "layout(location=0) out vec4 x;\n"
11328 "void main(){\n"
11329 " x = texture(s, vec2(1));\n"
11330 "}\n";
11331 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
11332 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
11333 VkPipelineObj pipe(m_device);
11334 pipe.AddShader(&vs);
11335 pipe.AddShader(&fs);
11336 pipe.AddColorAttachment();
11337 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11338
11339 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete image view 0x");
11340
11341 BeginCommandBuffer();
11342 // Bind pipeline to cmd buffer
11343 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
11344 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
11345 &descriptor_set, 0, nullptr);
11346 Draw(1, 0, 0, 0);
11347 EndCommandBuffer();
11348 // Submit cmd buffer then destroy sampler
11349 VkSubmitInfo submit_info = {};
11350 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11351 submit_info.commandBufferCount = 1;
11352 submit_info.pCommandBuffers = &m_commandBuffer->handle();
11353 // Submit cmd buffer and then destroy imageView while in-flight
11354 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11355
11356 vkDestroyImageView(m_device->device(), view, nullptr);
11357 m_errorMonitor->VerifyFound();
11358 vkQueueWaitIdle(m_device->m_queue);
11359 // Now we can actually destroy imageView
11360 vkDestroyImageView(m_device->device(), view, NULL);
11361 vkDestroySampler(m_device->device(), sampler, nullptr);
11362 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11363 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11364 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
11365}
11366
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060011367TEST_F(VkLayerTest, BufferViewInUseDestroyedSignaled) {
11368 TEST_DESCRIPTION("Delete in-use bufferView.");
11369
11370 ASSERT_NO_FATAL_FAILURE(InitState());
11371 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11372
11373 VkDescriptorPoolSize ds_type_count;
11374 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
11375 ds_type_count.descriptorCount = 1;
11376
11377 VkDescriptorPoolCreateInfo ds_pool_ci = {};
11378 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11379 ds_pool_ci.maxSets = 1;
11380 ds_pool_ci.poolSizeCount = 1;
11381 ds_pool_ci.pPoolSizes = &ds_type_count;
11382
11383 VkDescriptorPool ds_pool;
11384 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
11385 ASSERT_VK_SUCCESS(err);
11386
11387 VkDescriptorSetLayoutBinding layout_binding;
11388 layout_binding.binding = 0;
11389 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
11390 layout_binding.descriptorCount = 1;
11391 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
11392 layout_binding.pImmutableSamplers = NULL;
11393
11394 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11395 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11396 ds_layout_ci.bindingCount = 1;
11397 ds_layout_ci.pBindings = &layout_binding;
11398 VkDescriptorSetLayout ds_layout;
11399 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
11400 ASSERT_VK_SUCCESS(err);
11401
11402 VkDescriptorSetAllocateInfo alloc_info = {};
11403 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11404 alloc_info.descriptorSetCount = 1;
11405 alloc_info.descriptorPool = ds_pool;
11406 alloc_info.pSetLayouts = &ds_layout;
11407 VkDescriptorSet descriptor_set;
11408 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
11409 ASSERT_VK_SUCCESS(err);
11410
11411 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11412 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11413 pipeline_layout_ci.pNext = NULL;
11414 pipeline_layout_ci.setLayoutCount = 1;
11415 pipeline_layout_ci.pSetLayouts = &ds_layout;
11416
11417 VkPipelineLayout pipeline_layout;
11418 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
11419 ASSERT_VK_SUCCESS(err);
11420
11421 VkBuffer buffer;
11422 uint32_t queue_family_index = 0;
11423 VkBufferCreateInfo buffer_create_info = {};
11424 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
11425 buffer_create_info.size = 1024;
11426 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
11427 buffer_create_info.queueFamilyIndexCount = 1;
11428 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
11429
11430 err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
11431 ASSERT_VK_SUCCESS(err);
11432
11433 VkMemoryRequirements memory_reqs;
11434 VkDeviceMemory buffer_memory;
11435
11436 VkMemoryAllocateInfo memory_info = {};
11437 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
11438 memory_info.allocationSize = 0;
11439 memory_info.memoryTypeIndex = 0;
11440
11441 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
11442 memory_info.allocationSize = memory_reqs.size;
11443 bool pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
11444 ASSERT_TRUE(pass);
11445
11446 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
11447 ASSERT_VK_SUCCESS(err);
11448 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
11449 ASSERT_VK_SUCCESS(err);
11450
11451 VkBufferView view;
11452 VkBufferViewCreateInfo bvci = {};
11453 bvci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
11454 bvci.buffer = buffer;
11455 bvci.format = VK_FORMAT_R8_UNORM;
11456 bvci.range = VK_WHOLE_SIZE;
11457
11458 err = vkCreateBufferView(m_device->device(), &bvci, NULL, &view);
11459 ASSERT_VK_SUCCESS(err);
11460
11461 VkWriteDescriptorSet descriptor_write = {};
11462 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
11463 descriptor_write.dstSet = descriptor_set;
11464 descriptor_write.dstBinding = 0;
11465 descriptor_write.descriptorCount = 1;
11466 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
11467 descriptor_write.pTexelBufferView = &view;
11468
11469 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11470
11471 char const *vsSource = "#version 450\n"
11472 "\n"
11473 "out gl_PerVertex { \n"
11474 " vec4 gl_Position;\n"
11475 "};\n"
11476 "void main(){\n"
11477 " gl_Position = vec4(1);\n"
11478 "}\n";
11479 char const *fsSource = "#version 450\n"
11480 "\n"
11481 "layout(set=0, binding=0, r8) uniform imageBuffer s;\n"
11482 "layout(location=0) out vec4 x;\n"
11483 "void main(){\n"
11484 " x = imageLoad(s, 0);\n"
11485 "}\n";
11486 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
11487 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
11488 VkPipelineObj pipe(m_device);
11489 pipe.AddShader(&vs);
11490 pipe.AddShader(&fs);
11491 pipe.AddColorAttachment();
11492 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11493
11494 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete buffer view 0x");
11495
11496 BeginCommandBuffer();
11497 VkViewport viewport = {0, 0, 16, 16, 0, 1};
11498 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
11499 VkRect2D scissor = {{0, 0}, {16, 16}};
11500 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
11501 // Bind pipeline to cmd buffer
11502 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
11503 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
11504 &descriptor_set, 0, nullptr);
11505 Draw(1, 0, 0, 0);
11506 EndCommandBuffer();
11507
11508 VkSubmitInfo submit_info = {};
11509 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11510 submit_info.commandBufferCount = 1;
11511 submit_info.pCommandBuffers = &m_commandBuffer->handle();
11512 // Submit cmd buffer and then destroy bufferView while in-flight
11513 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11514
11515 vkDestroyBufferView(m_device->device(), view, nullptr);
11516 m_errorMonitor->VerifyFound();
11517 vkQueueWaitIdle(m_device->m_queue);
11518 // Now we can actually destroy bufferView
11519 vkDestroyBufferView(m_device->device(), view, NULL);
11520 vkDestroyBuffer(m_device->device(), buffer, NULL);
11521 vkFreeMemory(m_device->device(), buffer_memory, NULL);
11522 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11523 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11524 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
11525}
11526
Tobin Ehlis209532e2016-09-07 13:52:18 -060011527TEST_F(VkLayerTest, SamplerInUseDestroyedSignaled) {
11528 TEST_DESCRIPTION("Delete in-use sampler.");
11529
11530 ASSERT_NO_FATAL_FAILURE(InitState());
11531 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11532
11533 VkDescriptorPoolSize ds_type_count;
11534 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11535 ds_type_count.descriptorCount = 1;
11536
11537 VkDescriptorPoolCreateInfo ds_pool_ci = {};
11538 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11539 ds_pool_ci.maxSets = 1;
11540 ds_pool_ci.poolSizeCount = 1;
11541 ds_pool_ci.pPoolSizes = &ds_type_count;
11542
11543 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011544 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis209532e2016-09-07 13:52:18 -060011545 ASSERT_VK_SUCCESS(err);
11546
11547 VkSamplerCreateInfo sampler_ci = {};
11548 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
11549 sampler_ci.pNext = NULL;
11550 sampler_ci.magFilter = VK_FILTER_NEAREST;
11551 sampler_ci.minFilter = VK_FILTER_NEAREST;
11552 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
11553 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11554 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11555 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11556 sampler_ci.mipLodBias = 1.0;
11557 sampler_ci.anisotropyEnable = VK_FALSE;
11558 sampler_ci.maxAnisotropy = 1;
11559 sampler_ci.compareEnable = VK_FALSE;
11560 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
11561 sampler_ci.minLod = 1.0;
11562 sampler_ci.maxLod = 1.0;
11563 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
11564 sampler_ci.unnormalizedCoordinates = VK_FALSE;
11565 VkSampler sampler;
11566
11567 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
11568 ASSERT_VK_SUCCESS(err);
11569
11570 VkDescriptorSetLayoutBinding layout_binding;
11571 layout_binding.binding = 0;
Tobin Ehlis94fc0ad2016-09-19 16:23:01 -060011572 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
Tobin Ehlis209532e2016-09-07 13:52:18 -060011573 layout_binding.descriptorCount = 1;
11574 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
11575 layout_binding.pImmutableSamplers = NULL;
11576
11577 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11578 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11579 ds_layout_ci.bindingCount = 1;
11580 ds_layout_ci.pBindings = &layout_binding;
11581 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011582 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis209532e2016-09-07 13:52:18 -060011583 ASSERT_VK_SUCCESS(err);
11584
11585 VkDescriptorSetAllocateInfo alloc_info = {};
11586 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11587 alloc_info.descriptorSetCount = 1;
11588 alloc_info.descriptorPool = ds_pool;
11589 alloc_info.pSetLayouts = &ds_layout;
11590 VkDescriptorSet descriptor_set;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011591 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis209532e2016-09-07 13:52:18 -060011592 ASSERT_VK_SUCCESS(err);
11593
11594 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11595 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11596 pipeline_layout_ci.pNext = NULL;
11597 pipeline_layout_ci.setLayoutCount = 1;
11598 pipeline_layout_ci.pSetLayouts = &ds_layout;
11599
11600 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011601 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis209532e2016-09-07 13:52:18 -060011602 ASSERT_VK_SUCCESS(err);
11603
11604 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011605 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 -060011606 ASSERT_TRUE(image.initialized());
11607
11608 VkImageView view;
11609 VkImageViewCreateInfo ivci = {};
11610 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
11611 ivci.image = image.handle();
11612 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
11613 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
11614 ivci.subresourceRange.layerCount = 1;
11615 ivci.subresourceRange.baseMipLevel = 0;
11616 ivci.subresourceRange.levelCount = 1;
11617 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11618
11619 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
11620 ASSERT_VK_SUCCESS(err);
11621
11622 VkDescriptorImageInfo image_info{};
11623 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
11624 image_info.imageView = view;
11625 image_info.sampler = sampler;
11626
11627 VkWriteDescriptorSet descriptor_write = {};
11628 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
11629 descriptor_write.dstSet = descriptor_set;
11630 descriptor_write.dstBinding = 0;
11631 descriptor_write.descriptorCount = 1;
11632 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11633 descriptor_write.pImageInfo = &image_info;
11634
11635 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11636
11637 // Create PSO to use the sampler
11638 char const *vsSource = "#version 450\n"
11639 "\n"
11640 "out gl_PerVertex { \n"
11641 " vec4 gl_Position;\n"
11642 "};\n"
11643 "void main(){\n"
11644 " gl_Position = vec4(1);\n"
11645 "}\n";
11646 char const *fsSource = "#version 450\n"
11647 "\n"
11648 "layout(set=0, binding=0) uniform sampler2D s;\n"
11649 "layout(location=0) out vec4 x;\n"
11650 "void main(){\n"
11651 " x = texture(s, vec2(1));\n"
11652 "}\n";
11653 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
11654 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
11655 VkPipelineObj pipe(m_device);
11656 pipe.AddShader(&vs);
11657 pipe.AddShader(&fs);
11658 pipe.AddColorAttachment();
11659 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11660
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011661 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete sampler 0x");
Tobin Ehlis209532e2016-09-07 13:52:18 -060011662
11663 BeginCommandBuffer();
11664 // Bind pipeline to cmd buffer
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011665 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
11666 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
11667 &descriptor_set, 0, nullptr);
Tobin Ehlis209532e2016-09-07 13:52:18 -060011668 Draw(1, 0, 0, 0);
11669 EndCommandBuffer();
11670 // Submit cmd buffer then destroy sampler
11671 VkSubmitInfo submit_info = {};
11672 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11673 submit_info.commandBufferCount = 1;
11674 submit_info.pCommandBuffers = &m_commandBuffer->handle();
11675 // Submit cmd buffer and then destroy sampler while in-flight
11676 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11677
11678 vkDestroySampler(m_device->device(), sampler, nullptr);
11679 m_errorMonitor->VerifyFound();
11680 vkQueueWaitIdle(m_device->m_queue);
11681 // Now we can actually destroy sampler
11682 vkDestroySampler(m_device->device(), sampler, nullptr);
11683 vkDestroyImageView(m_device->device(), view, NULL);
11684 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11685 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11686 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
11687}
11688
Mark Mueller1cd9f412016-08-25 13:23:52 -060011689TEST_F(VkLayerTest, QueueForwardProgressFenceWait) {
Mark Mueller96a56d52016-08-24 10:28:05 -060011690 TEST_DESCRIPTION("Call VkQueueSubmit with a semaphore that is already "
Mark Mueller1cd9f412016-08-25 13:23:52 -060011691 "signaled but not waited on by the queue. Wait on a "
11692 "fence that has not yet been submitted to a queue.");
Mark Mueller96a56d52016-08-24 10:28:05 -060011693
11694 ASSERT_NO_FATAL_FAILURE(InitState());
11695 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11696
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011697 const char *queue_forward_progress_message = " that has already been signaled but not waited on by queue 0x";
11698 const char *invalid_fence_wait_message = " which has not been submitted on a Queue or during "
11699 "acquire next image.";
Mark Mueller96a56d52016-08-24 10:28:05 -060011700
11701 BeginCommandBuffer();
11702 EndCommandBuffer();
11703
11704 VkSemaphoreCreateInfo semaphore_create_info = {};
11705 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
11706 VkSemaphore semaphore;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011707 ASSERT_VK_SUCCESS(vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore));
Mark Mueller96a56d52016-08-24 10:28:05 -060011708 VkSubmitInfo submit_info = {};
11709 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11710 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011711 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Mueller96a56d52016-08-24 10:28:05 -060011712 submit_info.signalSemaphoreCount = 1;
11713 submit_info.pSignalSemaphores = &semaphore;
11714 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11715 m_errorMonitor->SetDesiredFailureMsg(0, "");
11716 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
11717 BeginCommandBuffer();
11718 EndCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011719 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, queue_forward_progress_message);
Mark Mueller96a56d52016-08-24 10:28:05 -060011720 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11721 m_errorMonitor->VerifyFound();
11722
Mark Mueller1cd9f412016-08-25 13:23:52 -060011723 VkFenceCreateInfo fence_create_info = {};
11724 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
11725 VkFence fence;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011726 ASSERT_VK_SUCCESS(vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence));
Mark Mueller1cd9f412016-08-25 13:23:52 -060011727
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011728 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, invalid_fence_wait_message);
Mark Mueller1cd9f412016-08-25 13:23:52 -060011729 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
11730 m_errorMonitor->VerifyFound();
11731
Mark Mueller4042b652016-09-05 22:52:21 -060011732 vkDeviceWaitIdle(m_device->device());
Mark Mueller1cd9f412016-08-25 13:23:52 -060011733 vkDestroyFence(m_device->device(), fence, nullptr);
Mark Mueller96a56d52016-08-24 10:28:05 -060011734 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
11735}
11736
Tobin Ehlis4af23302016-07-19 10:50:30 -060011737TEST_F(VkLayerTest, FramebufferIncompatible) {
11738 TEST_DESCRIPTION("Bind a secondary command buffer with with a framebuffer "
11739 "that does not match the framebuffer for the active "
11740 "renderpass.");
11741 ASSERT_NO_FATAL_FAILURE(InitState());
11742 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11743
11744 // A renderpass with one color attachment.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011745 VkAttachmentDescription attachment = {0,
11746 VK_FORMAT_B8G8R8A8_UNORM,
11747 VK_SAMPLE_COUNT_1_BIT,
11748 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
11749 VK_ATTACHMENT_STORE_OP_STORE,
11750 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
11751 VK_ATTACHMENT_STORE_OP_DONT_CARE,
11752 VK_IMAGE_LAYOUT_UNDEFINED,
11753 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis4af23302016-07-19 10:50:30 -060011754
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011755 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis4af23302016-07-19 10:50:30 -060011756
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011757 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Tobin Ehlis4af23302016-07-19 10:50:30 -060011758
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011759 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
Tobin Ehlis4af23302016-07-19 10:50:30 -060011760
11761 VkRenderPass rp;
11762 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
11763 ASSERT_VK_SUCCESS(err);
11764
11765 // A compatible framebuffer.
11766 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011767 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 -060011768 ASSERT_TRUE(image.initialized());
11769
11770 VkImageViewCreateInfo ivci = {
11771 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
11772 nullptr,
11773 0,
11774 image.handle(),
11775 VK_IMAGE_VIEW_TYPE_2D,
11776 VK_FORMAT_B8G8R8A8_UNORM,
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011777 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
11778 VK_COMPONENT_SWIZZLE_IDENTITY},
Tobin Ehlis4af23302016-07-19 10:50:30 -060011779 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
11780 };
11781 VkImageView view;
11782 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
11783 ASSERT_VK_SUCCESS(err);
11784
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011785 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Tobin Ehlis4af23302016-07-19 10:50:30 -060011786 VkFramebuffer fb;
11787 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
11788 ASSERT_VK_SUCCESS(err);
11789
11790 VkCommandBufferAllocateInfo cbai = {};
11791 cbai.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
11792 cbai.commandPool = m_commandPool;
11793 cbai.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
11794 cbai.commandBufferCount = 1;
11795
11796 VkCommandBuffer sec_cb;
11797 err = vkAllocateCommandBuffers(m_device->device(), &cbai, &sec_cb);
11798 ASSERT_VK_SUCCESS(err);
11799 VkCommandBufferBeginInfo cbbi = {};
11800 VkCommandBufferInheritanceInfo cbii = {};
Chris Forbes98420382016-11-28 17:56:51 +130011801 cbii.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
Tobin Ehlis4af23302016-07-19 10:50:30 -060011802 cbii.renderPass = renderPass();
11803 cbii.framebuffer = fb;
11804 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
11805 cbbi.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011806 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 -060011807 cbbi.pInheritanceInfo = &cbii;
11808 vkBeginCommandBuffer(sec_cb, &cbbi);
11809 vkEndCommandBuffer(sec_cb);
11810
Chris Forbes3400bc52016-09-13 18:10:34 +120011811 VkCommandBufferBeginInfo cbbi2 = {
11812 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr,
11813 0, nullptr
11814 };
11815 vkBeginCommandBuffer(m_commandBuffer->GetBufferHandle(), &cbbi2);
11816 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
Tobin Ehlis4af23302016-07-19 10:50:30 -060011817
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011818 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mike Weiblencce7ec72016-10-17 19:33:05 -060011819 " that is not the same as the primary command buffer's current active framebuffer ");
Tobin Ehlis4af23302016-07-19 10:50:30 -060011820 vkCmdExecuteCommands(m_commandBuffer->GetBufferHandle(), 1, &sec_cb);
11821 m_errorMonitor->VerifyFound();
11822 // Cleanup
11823 vkDestroyImageView(m_device->device(), view, NULL);
11824 vkDestroyRenderPass(m_device->device(), rp, NULL);
11825 vkDestroyFramebuffer(m_device->device(), fb, NULL);
11826}
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011827
11828TEST_F(VkLayerTest, ColorBlendLogicOpTests) {
11829 TEST_DESCRIPTION("If logicOp is available on the device, set it to an "
11830 "invalid value. If logicOp is not available, attempt to "
11831 "use it and verify that we see the correct error.");
11832 ASSERT_NO_FATAL_FAILURE(InitState());
11833 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11834
11835 auto features = m_device->phy().features();
11836 // Set the expected error depending on whether or not logicOp available
11837 if (VK_FALSE == features.logicOp) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011838 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "If logic operations feature not "
11839 "enabled, logicOpEnable must be "
11840 "VK_FALSE");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011841 } else {
Chris Forbes34797bc2016-10-03 15:28:49 +130011842 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "pColorBlendState->logicOp (16)");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011843 }
11844 // Create a pipeline using logicOp
11845 VkResult err;
11846
11847 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11848 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11849
11850 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011851 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011852 ASSERT_VK_SUCCESS(err);
11853
11854 VkPipelineViewportStateCreateInfo vp_state_ci = {};
11855 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
11856 vp_state_ci.viewportCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011857 VkViewport vp = {}; // Just need dummy vp to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011858 vp_state_ci.pViewports = &vp;
11859 vp_state_ci.scissorCount = 1;
11860 VkRect2D scissors = {}; // Dummy scissors to point to
11861 vp_state_ci.pScissors = &scissors;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011862
11863 VkPipelineShaderStageCreateInfo shaderStages[2];
11864 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
11865
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011866 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
11867 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011868 shaderStages[0] = vs.GetStageCreateInfo();
11869 shaderStages[1] = fs.GetStageCreateInfo();
11870
11871 VkPipelineVertexInputStateCreateInfo vi_ci = {};
11872 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
11873
11874 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
11875 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
11876 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
11877
11878 VkPipelineRasterizationStateCreateInfo rs_ci = {};
11879 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Chris Forbes14088512016-10-03 14:28:00 +130011880 rs_ci.lineWidth = 1.0f;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011881
11882 VkPipelineColorBlendAttachmentState att = {};
11883 att.blendEnable = VK_FALSE;
11884 att.colorWriteMask = 0xf;
11885
11886 VkPipelineColorBlendStateCreateInfo cb_ci = {};
11887 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
11888 // Enable logicOp & set logicOp to value 1 beyond allowed entries
11889 cb_ci.logicOpEnable = VK_TRUE;
11890 cb_ci.logicOp = VK_LOGIC_OP_RANGE_SIZE; // This should cause an error
11891 cb_ci.attachmentCount = 1;
11892 cb_ci.pAttachments = &att;
11893
Chris Forbes8aeacbf2016-10-03 14:25:08 +130011894 VkPipelineMultisampleStateCreateInfo ms_ci = {};
11895 ms_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
11896 ms_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
11897
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011898 VkGraphicsPipelineCreateInfo gp_ci = {};
11899 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
11900 gp_ci.stageCount = 2;
11901 gp_ci.pStages = shaderStages;
11902 gp_ci.pVertexInputState = &vi_ci;
11903 gp_ci.pInputAssemblyState = &ia_ci;
11904 gp_ci.pViewportState = &vp_state_ci;
11905 gp_ci.pRasterizationState = &rs_ci;
11906 gp_ci.pColorBlendState = &cb_ci;
Chris Forbes8aeacbf2016-10-03 14:25:08 +130011907 gp_ci.pMultisampleState = &ms_ci;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011908 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
11909 gp_ci.layout = pipeline_layout;
11910 gp_ci.renderPass = renderPass();
11911
11912 VkPipelineCacheCreateInfo pc_ci = {};
11913 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
11914
11915 VkPipeline pipeline;
11916 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011917 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011918 ASSERT_VK_SUCCESS(err);
11919
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011920 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011921 m_errorMonitor->VerifyFound();
11922 if (VK_SUCCESS == err) {
11923 vkDestroyPipeline(m_device->device(), pipeline, NULL);
11924 }
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011925 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
11926 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11927}
Mark Lobodzinski209b5292015-09-17 09:44:05 -060011928#endif // DRAW_STATE_TESTS
11929
Tobin Ehlis0788f522015-05-26 16:11:58 -060011930#if THREADING_TESTS
Mike Stroyanaccf7692015-05-12 16:00:45 -060011931#if GTEST_IS_THREADSAFE
11932struct thread_data_struct {
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011933 VkCommandBuffer commandBuffer;
Mike Stroyanaccf7692015-05-12 16:00:45 -060011934 VkEvent event;
11935 bool bailout;
11936};
11937
Karl Schultz6addd812016-02-02 17:17:23 -070011938extern "C" void *AddToCommandBuffer(void *arg) {
11939 struct thread_data_struct *data = (struct thread_data_struct *)arg;
Mike Stroyanaccf7692015-05-12 16:00:45 -060011940
Mike Stroyana6d14942016-07-13 15:10:05 -060011941 for (int i = 0; i < 80000; i++) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011942 vkCmdSetEvent(data->commandBuffer, data->event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Mike Stroyanaccf7692015-05-12 16:00:45 -060011943 if (data->bailout) {
11944 break;
11945 }
11946 }
11947 return NULL;
11948}
11949
Karl Schultz6addd812016-02-02 17:17:23 -070011950TEST_F(VkLayerTest, ThreadCommandBufferCollision) {
Mike Stroyan4268d1f2015-07-13 14:45:35 -060011951 test_platform_thread thread;
Mike Stroyanaccf7692015-05-12 16:00:45 -060011952
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011953 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "THREADING ERROR");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011954
Mike Stroyanaccf7692015-05-12 16:00:45 -060011955 ASSERT_NO_FATAL_FAILURE(InitState());
11956 ASSERT_NO_FATAL_FAILURE(InitViewport());
11957 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11958
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011959 // Calls AllocateCommandBuffers
11960 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Mark Lobodzinski5495d132015-09-30 16:19:16 -060011961
11962 // Avoid creating RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011963 commandBuffer.BeginCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -060011964
11965 VkEventCreateInfo event_info;
11966 VkEvent event;
Mike Stroyanaccf7692015-05-12 16:00:45 -060011967 VkResult err;
11968
11969 memset(&event_info, 0, sizeof(event_info));
11970 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
11971
Chia-I Wuf7458c52015-10-26 21:10:41 +080011972 err = vkCreateEvent(device(), &event_info, NULL, &event);
Mike Stroyanaccf7692015-05-12 16:00:45 -060011973 ASSERT_VK_SUCCESS(err);
11974
Mike Stroyanaccf7692015-05-12 16:00:45 -060011975 err = vkResetEvent(device(), event);
11976 ASSERT_VK_SUCCESS(err);
11977
11978 struct thread_data_struct data;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011979 data.commandBuffer = commandBuffer.GetBufferHandle();
Mike Stroyanaccf7692015-05-12 16:00:45 -060011980 data.event = event;
11981 data.bailout = false;
11982 m_errorMonitor->SetBailout(&data.bailout);
Mike Stroyana6d14942016-07-13 15:10:05 -060011983
11984 // First do some correct operations using multiple threads.
11985 // Add many entries to command buffer from another thread.
11986 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
11987 // Make non-conflicting calls from this thread at the same time.
11988 for (int i = 0; i < 80000; i++) {
Mike Stroyand6343902016-07-14 08:56:16 -060011989 uint32_t count;
11990 vkEnumeratePhysicalDevices(instance(), &count, NULL);
Mike Stroyana6d14942016-07-13 15:10:05 -060011991 }
11992 test_platform_thread_join(thread, NULL);
11993
11994 // Then do some incorrect operations using multiple threads.
Mike Stroyanaccf7692015-05-12 16:00:45 -060011995 // Add many entries to command buffer from another thread.
Mike Stroyan4268d1f2015-07-13 14:45:35 -060011996 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
Mike Stroyanaccf7692015-05-12 16:00:45 -060011997 // Add many entries to command buffer from this thread at the same time.
11998 AddToCommandBuffer(&data);
Mark Lobodzinski5495d132015-09-30 16:19:16 -060011999
Mike Stroyan4268d1f2015-07-13 14:45:35 -060012000 test_platform_thread_join(thread, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012001 commandBuffer.EndCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -060012002
Mike Stroyan10b8cb72016-01-22 15:22:03 -070012003 m_errorMonitor->SetBailout(NULL);
12004
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012005 m_errorMonitor->VerifyFound();
Mike Stroyanaccf7692015-05-12 16:00:45 -060012006
Chia-I Wuf7458c52015-10-26 21:10:41 +080012007 vkDestroyEvent(device(), event, NULL);
Mike Stroyanaccf7692015-05-12 16:00:45 -060012008}
Mark Lobodzinski209b5292015-09-17 09:44:05 -060012009#endif // GTEST_IS_THREADSAFE
12010#endif // THREADING_TESTS
12011
Chris Forbes9f7ff632015-05-25 11:13:08 +120012012#if SHADER_CHECKER_TESTS
Karl Schultz6addd812016-02-02 17:17:23 -070012013TEST_F(VkLayerTest, InvalidSPIRVCodeSize) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012014 TEST_DESCRIPTION("Test that an error is produced for a spirv module "
12015 "with an impossible code size");
12016
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012017 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012018
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012019 ASSERT_NO_FATAL_FAILURE(InitState());
12020 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12021
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012022 VkShaderModule module;
12023 VkShaderModuleCreateInfo moduleCreateInfo;
12024 struct icd_spv_header spv;
12025
12026 spv.magic = ICD_SPV_MAGIC;
12027 spv.version = ICD_SPV_VERSION;
12028 spv.gen_magic = 0;
12029
12030 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
12031 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -070012032 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012033 moduleCreateInfo.codeSize = 4;
12034 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080012035 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012036
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012037 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012038}
12039
Karl Schultz6addd812016-02-02 17:17:23 -070012040TEST_F(VkLayerTest, InvalidSPIRVMagic) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012041 TEST_DESCRIPTION("Test that an error is produced for a spirv module "
12042 "with a bad magic number");
12043
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012044 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid SPIR-V magic number");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012045
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012046 ASSERT_NO_FATAL_FAILURE(InitState());
12047 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12048
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012049 VkShaderModule module;
12050 VkShaderModuleCreateInfo moduleCreateInfo;
12051 struct icd_spv_header spv;
12052
12053 spv.magic = ~ICD_SPV_MAGIC;
12054 spv.version = ICD_SPV_VERSION;
12055 spv.gen_magic = 0;
12056
12057 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
12058 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -070012059 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012060 moduleCreateInfo.codeSize = sizeof(spv) + 10;
12061 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080012062 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012063
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012064 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012065}
12066
Chris Forbesb4afd0f2016-04-04 10:48:35 +120012067#if 0
12068// Not currently covered by SPIRV-Tools validator
Karl Schultz6addd812016-02-02 17:17:23 -070012069TEST_F(VkLayerTest, InvalidSPIRVVersion) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -070012070 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbesb4afd0f2016-04-04 10:48:35 +120012071 "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012072
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012073 ASSERT_NO_FATAL_FAILURE(InitState());
12074 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12075
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012076 VkShaderModule module;
12077 VkShaderModuleCreateInfo moduleCreateInfo;
12078 struct icd_spv_header spv;
12079
12080 spv.magic = ICD_SPV_MAGIC;
12081 spv.version = ~ICD_SPV_VERSION;
12082 spv.gen_magic = 0;
12083
12084 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
12085 moduleCreateInfo.pNext = NULL;
12086
Karl Schultz6addd812016-02-02 17:17:23 -070012087 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012088 moduleCreateInfo.codeSize = sizeof(spv) + 10;
12089 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080012090 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012091
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012092 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012093}
Chris Forbesb4afd0f2016-04-04 10:48:35 +120012094#endif
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012095
Karl Schultz6addd812016-02-02 17:17:23 -070012096TEST_F(VkLayerTest, CreatePipelineVertexOutputNotConsumed) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012097 TEST_DESCRIPTION("Test that a warning is produced for a vertex output that "
12098 "is not consumed by the fragment stage");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012099 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "not consumed by fragment shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012100
Chris Forbes9f7ff632015-05-25 11:13:08 +120012101 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060012102 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes9f7ff632015-05-25 11:13:08 +120012103
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012104 char const *vsSource = "#version 450\n"
12105 "\n"
12106 "layout(location=0) out float x;\n"
12107 "out gl_PerVertex {\n"
12108 " vec4 gl_Position;\n"
12109 "};\n"
12110 "void main(){\n"
12111 " gl_Position = vec4(1);\n"
12112 " x = 0;\n"
12113 "}\n";
12114 char const *fsSource = "#version 450\n"
12115 "\n"
12116 "layout(location=0) out vec4 color;\n"
12117 "void main(){\n"
12118 " color = vec4(1);\n"
12119 "}\n";
Chris Forbes9f7ff632015-05-25 11:13:08 +120012120
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012121 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12122 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes9f7ff632015-05-25 11:13:08 +120012123
12124 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080012125 pipe.AddColorAttachment();
Chris Forbes9f7ff632015-05-25 11:13:08 +120012126 pipe.AddShader(&vs);
12127 pipe.AddShader(&fs);
12128
Chris Forbes9f7ff632015-05-25 11:13:08 +120012129 VkDescriptorSetObj descriptorSet(m_device);
12130 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012131 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes9f7ff632015-05-25 11:13:08 +120012132
Tony Barbour5781e8f2015-08-04 16:23:11 -060012133 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes9f7ff632015-05-25 11:13:08 +120012134
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012135 m_errorMonitor->VerifyFound();
Chris Forbes9f7ff632015-05-25 11:13:08 +120012136}
Chris Forbes9f7ff632015-05-25 11:13:08 +120012137
Mark Mueller098c9cb2016-09-08 09:01:57 -060012138TEST_F(VkLayerTest, CreatePipelineCheckShaderBadSpecialization) {
12139 TEST_DESCRIPTION("Challenge core_validation with shader validation issues related to vkCreateGraphicsPipelines.");
12140
12141 ASSERT_NO_FATAL_FAILURE(InitState());
12142 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12143
12144 const char *bad_specialization_message =
12145 "Specialization entry 0 (for constant id 0) references memory outside provided specialization data ";
12146
12147 char const *vsSource =
12148 "#version 450\n"
12149 "\n"
12150 "out gl_PerVertex {\n"
12151 " vec4 gl_Position;\n"
12152 "};\n"
12153 "void main(){\n"
12154 " gl_Position = vec4(1);\n"
12155 "}\n";
12156
12157 char const *fsSource =
12158 "#version 450\n"
12159 "\n"
12160 "layout (constant_id = 0) const float r = 0.0f;\n"
12161 "layout(location = 0) out vec4 uFragColor;\n"
12162 "void main(){\n"
12163 " uFragColor = vec4(r,1,0,1);\n"
12164 "}\n";
12165
12166 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12167 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12168
12169 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
12170 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12171
12172 VkPipelineLayout pipeline_layout;
12173 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
12174
12175 VkPipelineViewportStateCreateInfo vp_state_create_info = {};
12176 vp_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
12177 vp_state_create_info.viewportCount = 1;
12178 VkViewport viewport = {};
12179 vp_state_create_info.pViewports = &viewport;
12180 vp_state_create_info.scissorCount = 1;
12181 VkRect2D scissors = {};
12182 vp_state_create_info.pScissors = &scissors;
12183
12184 VkDynamicState scissor_state = VK_DYNAMIC_STATE_SCISSOR;
12185
12186 VkPipelineDynamicStateCreateInfo pipeline_dynamic_state_create_info = {};
12187 pipeline_dynamic_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
12188 pipeline_dynamic_state_create_info.dynamicStateCount = 1;
12189 pipeline_dynamic_state_create_info.pDynamicStates = &scissor_state;
12190
12191 VkPipelineShaderStageCreateInfo shader_stage_create_info[2] = {
12192 vs.GetStageCreateInfo(),
12193 fs.GetStageCreateInfo()
12194 };
12195
12196 VkPipelineVertexInputStateCreateInfo vertex_input_create_info = {};
12197 vertex_input_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
12198
12199 VkPipelineInputAssemblyStateCreateInfo input_assembly_create_info = {};
12200 input_assembly_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
12201 input_assembly_create_info.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
12202
12203 VkPipelineRasterizationStateCreateInfo rasterization_state_create_info = {};
12204 rasterization_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
12205 rasterization_state_create_info.pNext = nullptr;
12206 rasterization_state_create_info.lineWidth = 1.0f;
12207 rasterization_state_create_info.rasterizerDiscardEnable = true;
12208
12209 VkPipelineColorBlendAttachmentState color_blend_attachment_state = {};
12210 color_blend_attachment_state.blendEnable = VK_FALSE;
12211 color_blend_attachment_state.colorWriteMask = 0xf;
12212
12213 VkPipelineColorBlendStateCreateInfo color_blend_state_create_info = {};
12214 color_blend_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
12215 color_blend_state_create_info.attachmentCount = 1;
12216 color_blend_state_create_info.pAttachments = &color_blend_attachment_state;
12217
12218 VkGraphicsPipelineCreateInfo graphicspipe_create_info = {};
12219 graphicspipe_create_info.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
12220 graphicspipe_create_info.stageCount = 2;
12221 graphicspipe_create_info.pStages = shader_stage_create_info;
12222 graphicspipe_create_info.pVertexInputState = &vertex_input_create_info;
12223 graphicspipe_create_info.pInputAssemblyState = &input_assembly_create_info;
12224 graphicspipe_create_info.pViewportState = &vp_state_create_info;
12225 graphicspipe_create_info.pRasterizationState = &rasterization_state_create_info;
12226 graphicspipe_create_info.pColorBlendState = &color_blend_state_create_info;
12227 graphicspipe_create_info.pDynamicState = &pipeline_dynamic_state_create_info;
12228 graphicspipe_create_info.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
12229 graphicspipe_create_info.layout = pipeline_layout;
12230 graphicspipe_create_info.renderPass = renderPass();
12231
12232 VkPipelineCacheCreateInfo pipeline_cache_create_info = {};
12233 pipeline_cache_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
12234
12235 VkPipelineCache pipelineCache;
12236 ASSERT_VK_SUCCESS(vkCreatePipelineCache(m_device->device(), &pipeline_cache_create_info, nullptr, &pipelineCache));
12237
12238 // This structure maps constant ids to data locations.
12239 const VkSpecializationMapEntry entry =
12240 // id, offset, size
12241 {0, 4, sizeof(uint32_t)}; // Challenge core validation by using a bogus offset.
12242
12243 uint32_t data = 1;
12244
12245 // Set up the info describing spec map and data
12246 const VkSpecializationInfo specialization_info = {
12247 1,
12248 &entry,
12249 1 * sizeof(float),
12250 &data,
12251 };
12252 shader_stage_create_info[0].pSpecializationInfo = &specialization_info;
12253
12254 VkPipeline pipeline;
12255 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bad_specialization_message);
12256 vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &graphicspipe_create_info, nullptr, &pipeline);
12257 m_errorMonitor->VerifyFound();
12258
12259 vkDestroyPipelineCache(m_device->device(), pipelineCache, nullptr);
12260 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
12261}
12262
12263TEST_F(VkLayerTest, CreatePipelineCheckShaderDescriptorTypeMismatch) {
12264 TEST_DESCRIPTION("Challenge core_validation with shader validation issues related to vkCreateGraphicsPipelines.");
12265
12266 ASSERT_NO_FATAL_FAILURE(InitState());
12267 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12268
12269 const char *descriptor_type_mismatch_message = "Type mismatch on descriptor slot 0.0 (used as type ";
12270
12271 VkDescriptorPoolSize descriptor_pool_type_count[2] = {};
12272 descriptor_pool_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
12273 descriptor_pool_type_count[0].descriptorCount = 1;
12274 descriptor_pool_type_count[1].type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
12275 descriptor_pool_type_count[1].descriptorCount = 1;
12276
12277 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
12278 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12279 descriptor_pool_create_info.maxSets = 1;
12280 descriptor_pool_create_info.poolSizeCount = 2;
12281 descriptor_pool_create_info.pPoolSizes = descriptor_pool_type_count;
12282 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
12283
12284 VkDescriptorPool descriptorset_pool;
12285 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
12286
12287 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
12288 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
12289 descriptorset_layout_binding.descriptorCount = 1;
12290 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_ALL;
12291
12292 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
12293 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
12294 descriptorset_layout_create_info.bindingCount = 1;
12295 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
12296
12297 VkDescriptorSetLayout descriptorset_layout;
12298 ASSERT_VK_SUCCESS(vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
12299
12300 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
12301 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
12302 descriptorset_allocate_info.descriptorSetCount = 1;
12303 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
12304 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
12305 VkDescriptorSet descriptorset;
12306 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
12307
12308 // Challenge core_validation with a non uniform buffer type.
12309 VkBufferTest storage_buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT);
12310
Mark Mueller098c9cb2016-09-08 09:01:57 -060012311 char const *vsSource =
12312 "#version 450\n"
12313 "\n"
12314 "layout (std140, set = 0, binding = 0) uniform buf {\n"
12315 " mat4 mvp;\n"
12316 "} ubuf;\n"
12317 "out gl_PerVertex {\n"
12318 " vec4 gl_Position;\n"
12319 "};\n"
12320 "void main(){\n"
12321 " gl_Position = ubuf.mvp * vec4(1);\n"
12322 "}\n";
12323
12324 char const *fsSource =
12325 "#version 450\n"
12326 "\n"
12327 "layout(location = 0) out vec4 uFragColor;\n"
12328 "void main(){\n"
12329 " uFragColor = vec4(0,1,0,1);\n"
12330 "}\n";
12331
12332 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12333 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12334
12335 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
12336 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12337 pipeline_layout_create_info.setLayoutCount = 1;
12338 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
12339
12340 VkPipelineLayout pipeline_layout;
12341 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
12342
12343 VkPipelineObj pipe(m_device);
12344 pipe.AddColorAttachment();
12345 pipe.AddShader(&vs);
12346 pipe.AddShader(&fs);
12347
12348 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, descriptor_type_mismatch_message);
12349 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12350 m_errorMonitor->VerifyFound();
12351
12352 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
12353 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
12354 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
12355}
12356
12357TEST_F(VkLayerTest, CreatePipelineCheckShaderDescriptorNotAccessible) {
12358 TEST_DESCRIPTION(
12359 "Create a pipeline in which a descriptor used by a shader stage does not include that stage in its stageFlags.");
12360
12361 ASSERT_NO_FATAL_FAILURE(InitState());
12362 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12363
12364 const char *descriptor_not_accessible_message = "Shader uses descriptor slot 0.0 (used as type ";
12365
12366 VkDescriptorPoolSize descriptor_pool_type_count = {};
12367 descriptor_pool_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
12368 descriptor_pool_type_count.descriptorCount = 1;
12369
12370 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
12371 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12372 descriptor_pool_create_info.maxSets = 1;
12373 descriptor_pool_create_info.poolSizeCount = 1;
12374 descriptor_pool_create_info.pPoolSizes = &descriptor_pool_type_count;
12375 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
12376
12377 VkDescriptorPool descriptorset_pool;
12378 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
12379
12380 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
12381 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
12382 descriptorset_layout_binding.descriptorCount = 1;
12383 // Intentionally make the uniform buffer inaccessible to the vertex shader to challenge core_validation
12384 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
12385
12386 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
12387 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
12388 descriptorset_layout_create_info.bindingCount = 1;
12389 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
12390
12391 VkDescriptorSetLayout descriptorset_layout;
12392 ASSERT_VK_SUCCESS(vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info,
12393 nullptr, &descriptorset_layout));
12394
12395 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
12396 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
12397 descriptorset_allocate_info.descriptorSetCount = 1;
12398 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
12399 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
12400 VkDescriptorSet descriptorset;
12401 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
12402
12403 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
12404
Mark Mueller098c9cb2016-09-08 09:01:57 -060012405 char const *vsSource =
12406 "#version 450\n"
12407 "\n"
12408 "layout (std140, set = 0, binding = 0) uniform buf {\n"
12409 " mat4 mvp;\n"
12410 "} ubuf;\n"
12411 "out gl_PerVertex {\n"
12412 " vec4 gl_Position;\n"
12413 "};\n"
12414 "void main(){\n"
12415 " gl_Position = ubuf.mvp * vec4(1);\n"
12416 "}\n";
12417
12418 char const *fsSource =
12419 "#version 450\n"
12420 "\n"
12421 "layout(location = 0) out vec4 uFragColor;\n"
12422 "void main(){\n"
12423 " uFragColor = vec4(0,1,0,1);\n"
12424 "}\n";
12425
12426 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12427 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12428
12429 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
12430 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12431 pipeline_layout_create_info.setLayoutCount = 1;
12432 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
12433
12434 VkPipelineLayout pipeline_layout;
12435 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
12436
12437 VkPipelineObj pipe(m_device);
12438 pipe.AddColorAttachment();
12439 pipe.AddShader(&vs);
12440 pipe.AddShader(&fs);
12441
12442 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, descriptor_not_accessible_message);
12443 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12444 m_errorMonitor->VerifyFound();
12445
12446 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
12447 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
12448 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
12449}
12450
12451TEST_F(VkLayerTest, CreatePipelineCheckShaderPushConstantNotAccessible) {
12452 TEST_DESCRIPTION("Create a graphics pipleine in which a push constant range containing a push constant block member is not "
12453 "accessible from the current shader stage.");
12454
12455 ASSERT_NO_FATAL_FAILURE(InitState());
12456 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12457
12458 const char *push_constant_not_accessible_message =
12459 "Push constant range covering variable starting at offset 0 not accessible from stage VK_SHADER_STAGE_VERTEX_BIT";
12460
12461 char const *vsSource =
12462 "#version 450\n"
12463 "\n"
12464 "layout(push_constant, std430) uniform foo { float x; } consts;\n"
12465 "out gl_PerVertex {\n"
12466 " vec4 gl_Position;\n"
12467 "};\n"
12468 "void main(){\n"
12469 " gl_Position = vec4(consts.x);\n"
12470 "}\n";
12471
12472 char const *fsSource =
12473 "#version 450\n"
12474 "\n"
12475 "layout(location = 0) out vec4 uFragColor;\n"
12476 "void main(){\n"
12477 " uFragColor = vec4(0,1,0,1);\n"
12478 "}\n";
12479
12480 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12481 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12482
12483 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
12484 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12485
12486 // Set up a push constant range
12487 VkPushConstantRange push_constant_ranges = {};
12488 // Set to the wrong stage to challenge core_validation
12489 push_constant_ranges.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
12490 push_constant_ranges.size = 4;
12491
12492 pipeline_layout_create_info.pPushConstantRanges = &push_constant_ranges;
12493 pipeline_layout_create_info.pushConstantRangeCount = 1;
12494
12495 VkPipelineLayout pipeline_layout;
12496 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
12497
12498 VkPipelineObj pipe(m_device);
12499 pipe.AddColorAttachment();
12500 pipe.AddShader(&vs);
12501 pipe.AddShader(&fs);
12502
12503 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, push_constant_not_accessible_message);
12504 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12505 m_errorMonitor->VerifyFound();
12506
12507 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
12508}
12509
12510TEST_F(VkLayerTest, CreatePipelineCheckShaderNotEnabled) {
12511 TEST_DESCRIPTION(
12512 "Create a graphics pipeline in which a capability declared by the shader requires a feature not enabled on the device.");
12513
12514 ASSERT_NO_FATAL_FAILURE(InitState());
12515 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12516
12517 const char *feature_not_enabled_message =
12518 "Shader requires VkPhysicalDeviceFeatures::shaderFloat64 but is not enabled on the device";
12519
12520 // Some awkward steps are required to test with custom device features.
12521 std::vector<const char *> device_extension_names;
12522 auto features = m_device->phy().features();
12523 // Disable support for 64 bit floats
12524 features.shaderFloat64 = false;
12525 // The sacrificial device object
12526 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
12527
12528 char const *vsSource = "#version 450\n"
12529 "\n"
12530 "out gl_PerVertex {\n"
12531 " vec4 gl_Position;\n"
12532 "};\n"
12533 "void main(){\n"
12534 " gl_Position = vec4(1);\n"
12535 "}\n";
12536 char const *fsSource = "#version 450\n"
12537 "\n"
12538 "layout(location=0) out vec4 color;\n"
12539 "void main(){\n"
12540 " dvec4 green = vec4(0.0, 1.0, 0.0, 1.0);\n"
12541 " color = vec4(green);\n"
12542 "}\n";
12543
12544 VkShaderObj vs(&test_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12545 VkShaderObj fs(&test_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12546
12547 VkRenderpassObj render_pass(&test_device);
Mark Mueller098c9cb2016-09-08 09:01:57 -060012548
12549 VkPipelineObj pipe(&test_device);
12550 pipe.AddColorAttachment();
12551 pipe.AddShader(&vs);
12552 pipe.AddShader(&fs);
12553
12554 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
12555 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12556 VkPipelineLayout pipeline_layout;
12557 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(test_device.device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
12558
12559 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, feature_not_enabled_message);
12560 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
12561 m_errorMonitor->VerifyFound();
12562
12563 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, nullptr);
12564}
12565
12566TEST_F(VkLayerTest, CreatePipelineCheckShaderBadCapability) {
12567 TEST_DESCRIPTION("Create a graphics pipeline in which a capability declared by the shader is not supported by Vulkan shaders.");
12568
12569 ASSERT_NO_FATAL_FAILURE(InitState());
12570 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12571
12572 const char *bad_capability_message = "Shader declares capability 53, not supported in Vulkan.";
12573
12574 char const *vsSource = "#version 450\n"
12575 "\n"
12576 "out gl_PerVertex {\n"
12577 " vec4 gl_Position;\n"
12578 "};\n"
12579 "layout(xfb_buffer = 1) out;"
12580 "void main(){\n"
12581 " gl_Position = vec4(1);\n"
12582 "}\n";
12583 char const *fsSource = "#version 450\n"
12584 "\n"
12585 "layout(location=0) out vec4 color;\n"
12586 "void main(){\n"
12587 " dvec4 green = vec4(0.0, 1.0, 0.0, 1.0);\n"
12588 " color = vec4(green);\n"
12589 "}\n";
12590
12591 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12592 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12593
12594 VkPipelineObj pipe(m_device);
12595 pipe.AddColorAttachment();
12596 pipe.AddShader(&vs);
12597 pipe.AddShader(&fs);
12598
12599 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
12600 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12601 VkPipelineLayout pipeline_layout;
12602 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
12603
12604 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bad_capability_message);
12605 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12606 m_errorMonitor->VerifyFound();
12607
12608 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
12609}
12610
Karl Schultz6addd812016-02-02 17:17:23 -070012611TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvided) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012612 TEST_DESCRIPTION("Test that an error is produced for a fragment shader input "
12613 "which is not present in the outputs of the previous stage");
12614
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012615 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not written by vertex shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012616
Chris Forbes59cb88d2015-05-25 11:13:13 +120012617 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060012618 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes59cb88d2015-05-25 11:13:13 +120012619
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012620 char const *vsSource = "#version 450\n"
12621 "\n"
12622 "out gl_PerVertex {\n"
12623 " vec4 gl_Position;\n"
12624 "};\n"
12625 "void main(){\n"
12626 " gl_Position = vec4(1);\n"
12627 "}\n";
12628 char const *fsSource = "#version 450\n"
12629 "\n"
12630 "layout(location=0) in float x;\n"
12631 "layout(location=0) out vec4 color;\n"
12632 "void main(){\n"
12633 " color = vec4(x);\n"
12634 "}\n";
Chris Forbes59cb88d2015-05-25 11:13:13 +120012635
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012636 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12637 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes59cb88d2015-05-25 11:13:13 +120012638
12639 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080012640 pipe.AddColorAttachment();
Chris Forbes59cb88d2015-05-25 11:13:13 +120012641 pipe.AddShader(&vs);
12642 pipe.AddShader(&fs);
12643
Chris Forbes59cb88d2015-05-25 11:13:13 +120012644 VkDescriptorSetObj descriptorSet(m_device);
12645 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012646 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes59cb88d2015-05-25 11:13:13 +120012647
Tony Barbour5781e8f2015-08-04 16:23:11 -060012648 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes59cb88d2015-05-25 11:13:13 +120012649
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012650 m_errorMonitor->VerifyFound();
Chris Forbes59cb88d2015-05-25 11:13:13 +120012651}
12652
Karl Schultz6addd812016-02-02 17:17:23 -070012653TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvidedInBlock) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012654 TEST_DESCRIPTION("Test that an error is produced for a fragment shader input "
12655 "within an interace block, which is not present in the outputs "
12656 "of the previous stage.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012657 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not written by vertex shader");
Chris Forbesa3e85f62016-01-15 14:53:11 +130012658
12659 ASSERT_NO_FATAL_FAILURE(InitState());
12660 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12661
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012662 char const *vsSource = "#version 450\n"
12663 "\n"
12664 "out gl_PerVertex {\n"
12665 " vec4 gl_Position;\n"
12666 "};\n"
12667 "void main(){\n"
12668 " gl_Position = vec4(1);\n"
12669 "}\n";
12670 char const *fsSource = "#version 450\n"
12671 "\n"
12672 "in block { layout(location=0) float x; } ins;\n"
12673 "layout(location=0) out vec4 color;\n"
12674 "void main(){\n"
12675 " color = vec4(ins.x);\n"
12676 "}\n";
Chris Forbesa3e85f62016-01-15 14:53:11 +130012677
12678 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12679 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12680
12681 VkPipelineObj pipe(m_device);
12682 pipe.AddColorAttachment();
12683 pipe.AddShader(&vs);
12684 pipe.AddShader(&fs);
12685
12686 VkDescriptorSetObj descriptorSet(m_device);
12687 descriptorSet.AppendDummy();
12688 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12689
12690 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12691
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012692 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +130012693}
12694
Karl Schultz6addd812016-02-02 17:17:23 -070012695TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchArraySize) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012696 TEST_DESCRIPTION("Test that an error is produced for mismatched array sizes "
Mike Weiblencce7ec72016-10-17 19:33:05 -060012697 "across the vertex->fragment shader interface");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012698 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0.0: 'ptr to "
12699 "output arr[2] of float32' vs 'ptr to "
12700 "input arr[3] of float32'");
Chris Forbes0036fd12016-01-26 14:19:49 +130012701
12702 ASSERT_NO_FATAL_FAILURE(InitState());
12703 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12704
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012705 char const *vsSource = "#version 450\n"
12706 "\n"
12707 "layout(location=0) out float x[2];\n"
12708 "out gl_PerVertex {\n"
12709 " vec4 gl_Position;\n"
12710 "};\n"
12711 "void main(){\n"
12712 " x[0] = 0; x[1] = 0;\n"
12713 " gl_Position = vec4(1);\n"
12714 "}\n";
12715 char const *fsSource = "#version 450\n"
12716 "\n"
12717 "layout(location=0) in float x[3];\n"
12718 "layout(location=0) out vec4 color;\n"
12719 "void main(){\n"
12720 " color = vec4(x[0] + x[1] + x[2]);\n"
12721 "}\n";
Chris Forbes0036fd12016-01-26 14:19:49 +130012722
12723 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12724 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12725
12726 VkPipelineObj pipe(m_device);
12727 pipe.AddColorAttachment();
12728 pipe.AddShader(&vs);
12729 pipe.AddShader(&fs);
12730
12731 VkDescriptorSetObj descriptorSet(m_device);
12732 descriptorSet.AppendDummy();
12733 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12734
12735 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12736
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012737 m_errorMonitor->VerifyFound();
Chris Forbes0036fd12016-01-26 14:19:49 +130012738}
12739
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060012740
Karl Schultz6addd812016-02-02 17:17:23 -070012741TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012742 TEST_DESCRIPTION("Test that an error is produced for mismatched types across "
Mike Weiblencce7ec72016-10-17 19:33:05 -060012743 "the vertex->fragment shader interface");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012744 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012745
Chris Forbesb56af562015-05-25 11:13:17 +120012746 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060012747 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesb56af562015-05-25 11:13:17 +120012748
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012749 char const *vsSource = "#version 450\n"
12750 "\n"
12751 "layout(location=0) out int x;\n"
12752 "out gl_PerVertex {\n"
12753 " vec4 gl_Position;\n"
12754 "};\n"
12755 "void main(){\n"
12756 " x = 0;\n"
12757 " gl_Position = vec4(1);\n"
12758 "}\n";
12759 char const *fsSource = "#version 450\n"
12760 "\n"
12761 "layout(location=0) in float x;\n" /* VS writes int */
12762 "layout(location=0) out vec4 color;\n"
12763 "void main(){\n"
12764 " color = vec4(x);\n"
12765 "}\n";
Chris Forbesb56af562015-05-25 11:13:17 +120012766
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012767 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12768 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesb56af562015-05-25 11:13:17 +120012769
12770 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080012771 pipe.AddColorAttachment();
Chris Forbesb56af562015-05-25 11:13:17 +120012772 pipe.AddShader(&vs);
12773 pipe.AddShader(&fs);
12774
Chris Forbesb56af562015-05-25 11:13:17 +120012775 VkDescriptorSetObj descriptorSet(m_device);
12776 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012777 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesb56af562015-05-25 11:13:17 +120012778
Tony Barbour5781e8f2015-08-04 16:23:11 -060012779 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesb56af562015-05-25 11:13:17 +120012780
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012781 m_errorMonitor->VerifyFound();
Chris Forbesb56af562015-05-25 11:13:17 +120012782}
12783
Karl Schultz6addd812016-02-02 17:17:23 -070012784TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchInBlock) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012785 TEST_DESCRIPTION("Test that an error is produced for mismatched types across "
Mike Weiblencce7ec72016-10-17 19:33:05 -060012786 "the vertex->fragment shader interface, when the variable is contained within "
Chris Forbes1cc79542016-07-20 11:13:44 +120012787 "an interface block");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012788 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0");
Chris Forbesa3e85f62016-01-15 14:53:11 +130012789
12790 ASSERT_NO_FATAL_FAILURE(InitState());
12791 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12792
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012793 char const *vsSource = "#version 450\n"
12794 "\n"
12795 "out block { layout(location=0) int x; } outs;\n"
12796 "out gl_PerVertex {\n"
12797 " vec4 gl_Position;\n"
12798 "};\n"
12799 "void main(){\n"
12800 " outs.x = 0;\n"
12801 " gl_Position = vec4(1);\n"
12802 "}\n";
12803 char const *fsSource = "#version 450\n"
12804 "\n"
12805 "in block { layout(location=0) float x; } ins;\n" /* VS writes int */
12806 "layout(location=0) out vec4 color;\n"
12807 "void main(){\n"
12808 " color = vec4(ins.x);\n"
12809 "}\n";
Chris Forbesa3e85f62016-01-15 14:53:11 +130012810
12811 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12812 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12813
12814 VkPipelineObj pipe(m_device);
12815 pipe.AddColorAttachment();
12816 pipe.AddShader(&vs);
12817 pipe.AddShader(&fs);
12818
12819 VkDescriptorSetObj descriptorSet(m_device);
12820 descriptorSet.AppendDummy();
12821 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12822
12823 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12824
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012825 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +130012826}
12827
12828TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByLocation) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012829 TEST_DESCRIPTION("Test that an error is produced for location mismatches across "
Mike Weiblencce7ec72016-10-17 19:33:05 -060012830 "the vertex->fragment shader interface; This should manifest as a not-written/not-consumed "
Chris Forbes1cc79542016-07-20 11:13:44 +120012831 "pair, but flushes out broken walking of the interfaces");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012832 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 +130012833
12834 ASSERT_NO_FATAL_FAILURE(InitState());
12835 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12836
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012837 char const *vsSource = "#version 450\n"
12838 "\n"
12839 "out block { layout(location=1) float x; } outs;\n"
12840 "out gl_PerVertex {\n"
12841 " vec4 gl_Position;\n"
12842 "};\n"
12843 "void main(){\n"
12844 " outs.x = 0;\n"
12845 " gl_Position = vec4(1);\n"
12846 "}\n";
12847 char const *fsSource = "#version 450\n"
12848 "\n"
12849 "in block { layout(location=0) float x; } ins;\n"
12850 "layout(location=0) out vec4 color;\n"
12851 "void main(){\n"
12852 " color = vec4(ins.x);\n"
12853 "}\n";
Chris Forbese9928822016-02-17 14:44:52 +130012854
12855 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12856 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12857
12858 VkPipelineObj pipe(m_device);
12859 pipe.AddColorAttachment();
12860 pipe.AddShader(&vs);
12861 pipe.AddShader(&fs);
12862
12863 VkDescriptorSetObj descriptorSet(m_device);
12864 descriptorSet.AppendDummy();
12865 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12866
12867 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12868
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012869 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +130012870}
12871
12872TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByComponent) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012873 TEST_DESCRIPTION("Test that an error is produced for component mismatches across the "
Mike Weiblencce7ec72016-10-17 19:33:05 -060012874 "vertex->fragment shader interface. It's not enough to have the same set of locations in "
Chris Forbes1cc79542016-07-20 11:13:44 +120012875 "use; matching is defined in terms of spirv variables.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012876 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 +130012877
12878 ASSERT_NO_FATAL_FAILURE(InitState());
12879 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12880
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012881 char const *vsSource = "#version 450\n"
12882 "\n"
12883 "out block { layout(location=0, component=0) float x; } outs;\n"
12884 "out gl_PerVertex {\n"
12885 " vec4 gl_Position;\n"
12886 "};\n"
12887 "void main(){\n"
12888 " outs.x = 0;\n"
12889 " gl_Position = vec4(1);\n"
12890 "}\n";
12891 char const *fsSource = "#version 450\n"
12892 "\n"
12893 "in block { layout(location=0, component=1) float x; } ins;\n"
12894 "layout(location=0) out vec4 color;\n"
12895 "void main(){\n"
12896 " color = vec4(ins.x);\n"
12897 "}\n";
Chris Forbese9928822016-02-17 14:44:52 +130012898
12899 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12900 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12901
12902 VkPipelineObj pipe(m_device);
12903 pipe.AddColorAttachment();
12904 pipe.AddShader(&vs);
12905 pipe.AddShader(&fs);
12906
12907 VkDescriptorSetObj descriptorSet(m_device);
12908 descriptorSet.AppendDummy();
12909 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12910
12911 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12912
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012913 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +130012914}
12915
Chris Forbes1f3b0152016-11-30 12:48:40 +130012916TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByPrecision) {
12917 TEST_DESCRIPTION("Test that the RelaxedPrecision decoration is validated to match");
12918
12919 ASSERT_NO_FATAL_FAILURE(InitState());
12920 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12921
12922 char const *vsSource = "#version 450\n"
12923 "layout(location=0) out mediump float x;\n"
12924 "void main() { gl_Position = vec4(0); x = 1.0; }\n";
12925 char const *fsSource = "#version 450\n"
12926 "layout(location=0) in highp float x;\n"
12927 "layout(location=0) out vec4 color;\n"
12928 "void main() { color = vec4(x); }\n";
12929
12930 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12931 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12932
12933 VkPipelineObj pipe(m_device);
12934 pipe.AddColorAttachment();
12935 pipe.AddShader(&vs);
12936 pipe.AddShader(&fs);
12937
12938 VkDescriptorSetObj descriptorSet(m_device);
12939 descriptorSet.AppendDummy();
12940 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12941
12942 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "differ in precision");
12943
12944 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12945
12946 m_errorMonitor->VerifyFound();
12947}
12948
Chris Forbes870a39e2016-11-30 12:55:56 +130012949TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByPrecisionBlock) {
12950 TEST_DESCRIPTION("Test that the RelaxedPrecision decoration is validated to match");
12951
12952 ASSERT_NO_FATAL_FAILURE(InitState());
12953 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12954
12955 char const *vsSource = "#version 450\n"
12956 "out block { layout(location=0) mediump float x; };\n"
12957 "void main() { gl_Position = vec4(0); x = 1.0; }\n";
12958 char const *fsSource = "#version 450\n"
12959 "in block { layout(location=0) highp float x; };\n"
12960 "layout(location=0) out vec4 color;\n"
12961 "void main() { color = vec4(x); }\n";
12962
12963 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12964 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12965
12966 VkPipelineObj pipe(m_device);
12967 pipe.AddColorAttachment();
12968 pipe.AddShader(&vs);
12969 pipe.AddShader(&fs);
12970
12971 VkDescriptorSetObj descriptorSet(m_device);
12972 descriptorSet.AppendDummy();
12973 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12974
12975 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "differ in precision");
12976
12977 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12978
12979 m_errorMonitor->VerifyFound();
12980}
12981
Karl Schultz6addd812016-02-02 17:17:23 -070012982TEST_F(VkLayerTest, CreatePipelineAttribNotConsumed) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012983 TEST_DESCRIPTION("Test that a warning is produced for a vertex attribute which is "
12984 "not consumed by the vertex shader");
Mike Weiblencce7ec72016-10-17 19:33:05 -060012985 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "location 0 not consumed by vertex shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012986
Chris Forbesde136e02015-05-25 11:13:28 +120012987 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060012988 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesde136e02015-05-25 11:13:28 +120012989
12990 VkVertexInputBindingDescription input_binding;
12991 memset(&input_binding, 0, sizeof(input_binding));
12992
12993 VkVertexInputAttributeDescription input_attrib;
12994 memset(&input_attrib, 0, sizeof(input_attrib));
12995 input_attrib.format = VK_FORMAT_R32_SFLOAT;
12996
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012997 char const *vsSource = "#version 450\n"
12998 "\n"
12999 "out gl_PerVertex {\n"
13000 " vec4 gl_Position;\n"
13001 "};\n"
13002 "void main(){\n"
13003 " gl_Position = vec4(1);\n"
13004 "}\n";
13005 char const *fsSource = "#version 450\n"
13006 "\n"
13007 "layout(location=0) out vec4 color;\n"
13008 "void main(){\n"
13009 " color = vec4(1);\n"
13010 "}\n";
Chris Forbesde136e02015-05-25 11:13:28 +120013011
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013012 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13013 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesde136e02015-05-25 11:13:28 +120013014
13015 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013016 pipe.AddColorAttachment();
Chris Forbesde136e02015-05-25 11:13:28 +120013017 pipe.AddShader(&vs);
13018 pipe.AddShader(&fs);
13019
13020 pipe.AddVertexInputBindings(&input_binding, 1);
13021 pipe.AddVertexInputAttribs(&input_attrib, 1);
13022
Chris Forbesde136e02015-05-25 11:13:28 +120013023 VkDescriptorSetObj descriptorSet(m_device);
13024 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013025 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesde136e02015-05-25 11:13:28 +120013026
Tony Barbour5781e8f2015-08-04 16:23:11 -060013027 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesde136e02015-05-25 11:13:28 +120013028
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013029 m_errorMonitor->VerifyFound();
Chris Forbesde136e02015-05-25 11:13:28 +120013030}
13031
Karl Schultz6addd812016-02-02 17:17:23 -070013032TEST_F(VkLayerTest, CreatePipelineAttribLocationMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013033 TEST_DESCRIPTION("Test that a warning is produced for a location mismatch on "
13034 "vertex attributes. This flushes out bad behavior in the interface walker");
Mike Weiblencce7ec72016-10-17 19:33:05 -060013035 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "location 0 not consumed by vertex shader");
Chris Forbes7d83cd52016-01-15 11:32:03 +130013036
13037 ASSERT_NO_FATAL_FAILURE(InitState());
13038 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13039
13040 VkVertexInputBindingDescription input_binding;
13041 memset(&input_binding, 0, sizeof(input_binding));
13042
13043 VkVertexInputAttributeDescription input_attrib;
13044 memset(&input_attrib, 0, sizeof(input_attrib));
13045 input_attrib.format = VK_FORMAT_R32_SFLOAT;
13046
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013047 char const *vsSource = "#version 450\n"
13048 "\n"
13049 "layout(location=1) in float x;\n"
13050 "out gl_PerVertex {\n"
13051 " vec4 gl_Position;\n"
13052 "};\n"
13053 "void main(){\n"
13054 " gl_Position = vec4(x);\n"
13055 "}\n";
13056 char const *fsSource = "#version 450\n"
13057 "\n"
13058 "layout(location=0) out vec4 color;\n"
13059 "void main(){\n"
13060 " color = vec4(1);\n"
13061 "}\n";
Chris Forbes7d83cd52016-01-15 11:32:03 +130013062
13063 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13064 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13065
13066 VkPipelineObj pipe(m_device);
13067 pipe.AddColorAttachment();
13068 pipe.AddShader(&vs);
13069 pipe.AddShader(&fs);
13070
13071 pipe.AddVertexInputBindings(&input_binding, 1);
13072 pipe.AddVertexInputAttribs(&input_attrib, 1);
13073
13074 VkDescriptorSetObj descriptorSet(m_device);
13075 descriptorSet.AppendDummy();
13076 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13077
13078 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13079
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013080 m_errorMonitor->VerifyFound();
Chris Forbes7d83cd52016-01-15 11:32:03 +130013081}
13082
Karl Schultz6addd812016-02-02 17:17:23 -070013083TEST_F(VkLayerTest, CreatePipelineAttribNotProvided) {
Mike Weiblen15bd38e2016-10-03 19:19:41 -060013084 TEST_DESCRIPTION("Test that an error is produced for a vertex shader input which is not "
Chris Forbes1cc79542016-07-20 11:13:44 +120013085 "provided by a vertex attribute");
Mike Weiblen15bd38e2016-10-03 19:19:41 -060013086 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 -060013087
Chris Forbes62e8e502015-05-25 11:13:29 +120013088 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013089 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes62e8e502015-05-25 11:13:29 +120013090
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013091 char const *vsSource = "#version 450\n"
13092 "\n"
13093 "layout(location=0) in vec4 x;\n" /* not provided */
13094 "out gl_PerVertex {\n"
13095 " vec4 gl_Position;\n"
13096 "};\n"
13097 "void main(){\n"
13098 " gl_Position = x;\n"
13099 "}\n";
13100 char const *fsSource = "#version 450\n"
13101 "\n"
13102 "layout(location=0) out vec4 color;\n"
13103 "void main(){\n"
13104 " color = vec4(1);\n"
13105 "}\n";
Chris Forbes62e8e502015-05-25 11:13:29 +120013106
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013107 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13108 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes62e8e502015-05-25 11:13:29 +120013109
13110 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013111 pipe.AddColorAttachment();
Chris Forbes62e8e502015-05-25 11:13:29 +120013112 pipe.AddShader(&vs);
13113 pipe.AddShader(&fs);
13114
Chris Forbes62e8e502015-05-25 11:13:29 +120013115 VkDescriptorSetObj descriptorSet(m_device);
13116 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013117 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes62e8e502015-05-25 11:13:29 +120013118
Tony Barbour5781e8f2015-08-04 16:23:11 -060013119 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes62e8e502015-05-25 11:13:29 +120013120
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013121 m_errorMonitor->VerifyFound();
Chris Forbes62e8e502015-05-25 11:13:29 +120013122}
13123
Karl Schultz6addd812016-02-02 17:17:23 -070013124TEST_F(VkLayerTest, CreatePipelineAttribTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013125 TEST_DESCRIPTION("Test that an error is produced for a mismatch between the "
13126 "fundamental type (float/int/uint) of an attribute and the "
Mike Weiblen15bd38e2016-10-03 19:19:41 -060013127 "vertex shader input that consumes it");
13128 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 -060013129
Chris Forbesc97d98e2015-05-25 11:13:31 +120013130 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013131 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesc97d98e2015-05-25 11:13:31 +120013132
13133 VkVertexInputBindingDescription input_binding;
13134 memset(&input_binding, 0, sizeof(input_binding));
13135
13136 VkVertexInputAttributeDescription input_attrib;
13137 memset(&input_attrib, 0, sizeof(input_attrib));
13138 input_attrib.format = VK_FORMAT_R32_SFLOAT;
13139
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013140 char const *vsSource = "#version 450\n"
13141 "\n"
13142 "layout(location=0) in int x;\n" /* attrib provided float */
13143 "out gl_PerVertex {\n"
13144 " vec4 gl_Position;\n"
13145 "};\n"
13146 "void main(){\n"
13147 " gl_Position = vec4(x);\n"
13148 "}\n";
13149 char const *fsSource = "#version 450\n"
13150 "\n"
13151 "layout(location=0) out vec4 color;\n"
13152 "void main(){\n"
13153 " color = vec4(1);\n"
13154 "}\n";
Chris Forbesc97d98e2015-05-25 11:13:31 +120013155
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013156 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13157 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesc97d98e2015-05-25 11:13:31 +120013158
13159 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013160 pipe.AddColorAttachment();
Chris Forbesc97d98e2015-05-25 11:13:31 +120013161 pipe.AddShader(&vs);
13162 pipe.AddShader(&fs);
13163
13164 pipe.AddVertexInputBindings(&input_binding, 1);
13165 pipe.AddVertexInputAttribs(&input_attrib, 1);
13166
Chris Forbesc97d98e2015-05-25 11:13:31 +120013167 VkDescriptorSetObj descriptorSet(m_device);
13168 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013169 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesc97d98e2015-05-25 11:13:31 +120013170
Tony Barbour5781e8f2015-08-04 16:23:11 -060013171 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesc97d98e2015-05-25 11:13:31 +120013172
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013173 m_errorMonitor->VerifyFound();
Chris Forbesc97d98e2015-05-25 11:13:31 +120013174}
13175
Chris Forbesc68b43c2016-04-06 11:18:47 +120013176TEST_F(VkLayerTest, CreatePipelineDuplicateStage) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013177 TEST_DESCRIPTION("Test that an error is produced for a pipeline containing multiple "
13178 "shaders for the same stage");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013179 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13180 "Multiple shaders provided for stage VK_SHADER_STAGE_VERTEX_BIT");
Chris Forbesc68b43c2016-04-06 11:18:47 +120013181
13182 ASSERT_NO_FATAL_FAILURE(InitState());
13183 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13184
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013185 char const *vsSource = "#version 450\n"
13186 "\n"
13187 "out gl_PerVertex {\n"
13188 " vec4 gl_Position;\n"
13189 "};\n"
13190 "void main(){\n"
13191 " gl_Position = vec4(1);\n"
13192 "}\n";
13193 char const *fsSource = "#version 450\n"
13194 "\n"
13195 "layout(location=0) out vec4 color;\n"
13196 "void main(){\n"
13197 " color = vec4(1);\n"
13198 "}\n";
Chris Forbesc68b43c2016-04-06 11:18:47 +120013199
13200 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13201 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13202
13203 VkPipelineObj pipe(m_device);
13204 pipe.AddColorAttachment();
13205 pipe.AddShader(&vs);
Mike Weiblencce7ec72016-10-17 19:33:05 -060013206 pipe.AddShader(&vs); // intentionally duplicate vertex shader attachment
Chris Forbesc68b43c2016-04-06 11:18:47 +120013207 pipe.AddShader(&fs);
13208
13209 VkDescriptorSetObj descriptorSet(m_device);
13210 descriptorSet.AppendDummy();
13211 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13212
13213 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13214
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013215 m_errorMonitor->VerifyFound();
Chris Forbesc68b43c2016-04-06 11:18:47 +120013216}
13217
Chris Forbes82ff92a2016-09-09 10:50:24 +120013218TEST_F(VkLayerTest, CreatePipelineMissingEntrypoint) {
13219 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13220 "No entrypoint found named `foo`");
13221
13222 ASSERT_NO_FATAL_FAILURE(InitState());
13223 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13224
13225 char const *vsSource = "#version 450\n"
13226 "out gl_PerVertex {\n"
13227 " vec4 gl_Position;\n"
13228 "};\n"
13229 "void main(){\n"
13230 " gl_Position = vec4(0);\n"
13231 "}\n";
13232 char const *fsSource = "#version 450\n"
13233 "\n"
13234 "layout(location=0) out vec4 color;\n"
13235 "void main(){\n"
13236 " color = vec4(1);\n"
13237 "}\n";
13238
13239 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13240 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this, "foo");
13241
13242 VkPipelineObj pipe(m_device);
13243 pipe.AddColorAttachment();
13244 pipe.AddShader(&vs);
13245 pipe.AddShader(&fs);
13246
13247 VkDescriptorSetObj descriptorSet(m_device);
13248 descriptorSet.AppendDummy();
13249 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13250
13251 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13252
13253 m_errorMonitor->VerifyFound();
13254}
13255
Chris Forbesae9d8cd2016-09-13 16:32:57 +120013256TEST_F(VkLayerTest, CreatePipelineDepthStencilRequired) {
13257 m_errorMonitor->SetDesiredFailureMsg(
13258 VK_DEBUG_REPORT_ERROR_BIT_EXT,
13259 "pDepthStencilState is NULL when rasterization is enabled and subpass "
13260 "uses a depth/stencil attachment");
13261
13262 ASSERT_NO_FATAL_FAILURE(InitState());
13263 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13264
13265 char const *vsSource = "#version 450\n"
13266 "void main(){ gl_Position = vec4(0); }\n";
13267 char const *fsSource = "#version 450\n"
13268 "\n"
13269 "layout(location=0) out vec4 color;\n"
13270 "void main(){\n"
13271 " color = vec4(1);\n"
13272 "}\n";
13273
13274 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13275 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13276
13277 VkPipelineObj pipe(m_device);
13278 pipe.AddColorAttachment();
13279 pipe.AddShader(&vs);
13280 pipe.AddShader(&fs);
13281
13282 VkDescriptorSetObj descriptorSet(m_device);
13283 descriptorSet.AppendDummy();
13284 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13285
13286 VkAttachmentDescription attachments[] = {
13287 { 0, VK_FORMAT_B8G8R8A8_UNORM, VK_SAMPLE_COUNT_1_BIT,
13288 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
13289 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
13290 VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
13291 },
13292 { 0, VK_FORMAT_D16_UNORM, VK_SAMPLE_COUNT_1_BIT,
13293 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
13294 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
13295 VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
13296 },
13297 };
13298 VkAttachmentReference refs[] = {
13299 { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL },
13300 { 1, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL },
13301 };
13302 VkSubpassDescription subpass = {
13303 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr,
13304 1, &refs[0], nullptr, &refs[1],
13305 0, nullptr
13306 };
13307 VkRenderPassCreateInfo rpci = {
13308 VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr,
13309 0, 2, attachments, 1, &subpass, 0, nullptr
13310 };
13311 VkRenderPass rp;
13312 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
13313 ASSERT_VK_SUCCESS(err);
13314
13315 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), rp);
13316
13317 m_errorMonitor->VerifyFound();
13318
13319 vkDestroyRenderPass(m_device->device(), rp, nullptr);
13320}
13321
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013322TEST_F(VkLayerTest, CreatePipelineTessPatchDecorationMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013323 TEST_DESCRIPTION("Test that an error is produced for a variable output from "
13324 "the TCS without the patch decoration, but consumed in the TES "
13325 "with the decoration.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013326 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is per-vertex in tessellation control shader stage "
13327 "but per-patch in tessellation evaluation shader stage");
Chris Forbesa0193bc2016-04-04 19:19:47 +120013328
13329 ASSERT_NO_FATAL_FAILURE(InitState());
13330 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13331
Chris Forbesc1e852d2016-04-04 19:26:42 +120013332 if (!m_device->phy().features().tessellationShader) {
13333 printf("Device does not support tessellation shaders; skipped.\n");
13334 return;
13335 }
13336
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013337 char const *vsSource = "#version 450\n"
13338 "void main(){}\n";
13339 char const *tcsSource = "#version 450\n"
13340 "layout(location=0) out int x[];\n"
13341 "layout(vertices=3) out;\n"
13342 "void main(){\n"
13343 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
13344 " gl_TessLevelInner[0] = 1;\n"
13345 " x[gl_InvocationID] = gl_InvocationID;\n"
13346 "}\n";
13347 char const *tesSource = "#version 450\n"
13348 "layout(triangles, equal_spacing, cw) in;\n"
13349 "layout(location=0) patch in int x;\n"
13350 "out gl_PerVertex { vec4 gl_Position; };\n"
13351 "void main(){\n"
13352 " gl_Position.xyz = gl_TessCoord;\n"
13353 " gl_Position.w = x;\n"
13354 "}\n";
13355 char const *fsSource = "#version 450\n"
13356 "layout(location=0) out vec4 color;\n"
13357 "void main(){\n"
13358 " color = vec4(1);\n"
13359 "}\n";
Chris Forbesa0193bc2016-04-04 19:19:47 +120013360
13361 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13362 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
13363 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
13364 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13365
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013366 VkPipelineInputAssemblyStateCreateInfo iasci{VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, nullptr, 0,
13367 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, VK_FALSE};
Chris Forbesa0193bc2016-04-04 19:19:47 +120013368
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013369 VkPipelineTessellationStateCreateInfo tsci{VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, nullptr, 0, 3};
Chris Forbesa0193bc2016-04-04 19:19:47 +120013370
13371 VkPipelineObj pipe(m_device);
13372 pipe.SetInputAssembly(&iasci);
13373 pipe.SetTessellation(&tsci);
13374 pipe.AddColorAttachment();
13375 pipe.AddShader(&vs);
13376 pipe.AddShader(&tcs);
13377 pipe.AddShader(&tes);
13378 pipe.AddShader(&fs);
13379
13380 VkDescriptorSetObj descriptorSet(m_device);
13381 descriptorSet.AppendDummy();
13382 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13383
13384 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13385
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013386 m_errorMonitor->VerifyFound();
Chris Forbesa0193bc2016-04-04 19:19:47 +120013387}
13388
Karl Schultz6addd812016-02-02 17:17:23 -070013389TEST_F(VkLayerTest, CreatePipelineAttribBindingConflict) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013390 TEST_DESCRIPTION("Test that an error is produced for a vertex attribute setup where multiple "
13391 "bindings provide the same location");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013392 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13393 "Duplicate vertex input binding descriptions for binding 0");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013394
Chris Forbes280ba2c2015-06-12 11:16:41 +120013395 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013396 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes280ba2c2015-06-12 11:16:41 +120013397
13398 /* Two binding descriptions for binding 0 */
13399 VkVertexInputBindingDescription input_bindings[2];
13400 memset(input_bindings, 0, sizeof(input_bindings));
13401
13402 VkVertexInputAttributeDescription input_attrib;
13403 memset(&input_attrib, 0, sizeof(input_attrib));
13404 input_attrib.format = VK_FORMAT_R32_SFLOAT;
13405
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013406 char const *vsSource = "#version 450\n"
13407 "\n"
13408 "layout(location=0) in float x;\n" /* attrib provided float */
13409 "out gl_PerVertex {\n"
13410 " vec4 gl_Position;\n"
13411 "};\n"
13412 "void main(){\n"
13413 " gl_Position = vec4(x);\n"
13414 "}\n";
13415 char const *fsSource = "#version 450\n"
13416 "\n"
13417 "layout(location=0) out vec4 color;\n"
13418 "void main(){\n"
13419 " color = vec4(1);\n"
13420 "}\n";
Chris Forbes280ba2c2015-06-12 11:16:41 +120013421
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013422 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13423 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes280ba2c2015-06-12 11:16:41 +120013424
13425 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013426 pipe.AddColorAttachment();
Chris Forbes280ba2c2015-06-12 11:16:41 +120013427 pipe.AddShader(&vs);
13428 pipe.AddShader(&fs);
13429
13430 pipe.AddVertexInputBindings(input_bindings, 2);
13431 pipe.AddVertexInputAttribs(&input_attrib, 1);
13432
Chris Forbes280ba2c2015-06-12 11:16:41 +120013433 VkDescriptorSetObj descriptorSet(m_device);
13434 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013435 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes280ba2c2015-06-12 11:16:41 +120013436
Tony Barbour5781e8f2015-08-04 16:23:11 -060013437 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes280ba2c2015-06-12 11:16:41 +120013438
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013439 m_errorMonitor->VerifyFound();
Chris Forbes280ba2c2015-06-12 11:16:41 +120013440}
Chris Forbes8f68b562015-05-25 11:13:32 +120013441
Karl Schultz6addd812016-02-02 17:17:23 -070013442TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotWritten) {
Mike Weiblencce7ec72016-10-17 19:33:05 -060013443 TEST_DESCRIPTION("Test that an error is produced for a fragment shader which does not "
Chris Forbes1cc79542016-07-20 11:13:44 +120013444 "provide an output for one of the pipeline's color attachments");
Mike Weiblencce7ec72016-10-17 19:33:05 -060013445 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attachment 0 not written by fragment shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013446
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013447 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013448
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013449 char const *vsSource = "#version 450\n"
13450 "\n"
13451 "out gl_PerVertex {\n"
13452 " vec4 gl_Position;\n"
13453 "};\n"
13454 "void main(){\n"
13455 " gl_Position = vec4(1);\n"
13456 "}\n";
13457 char const *fsSource = "#version 450\n"
13458 "\n"
13459 "void main(){\n"
13460 "}\n";
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013461
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013462 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13463 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013464
13465 VkPipelineObj pipe(m_device);
13466 pipe.AddShader(&vs);
13467 pipe.AddShader(&fs);
13468
Chia-I Wu08accc62015-07-07 11:50:03 +080013469 /* set up CB 0, not written */
13470 pipe.AddColorAttachment();
13471 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013472
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013473 VkDescriptorSetObj descriptorSet(m_device);
13474 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013475 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013476
Tony Barbour5781e8f2015-08-04 16:23:11 -060013477 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013478
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013479 m_errorMonitor->VerifyFound();
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013480}
13481
Karl Schultz6addd812016-02-02 17:17:23 -070013482TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotConsumed) {
Mike Weiblencce7ec72016-10-17 19:33:05 -060013483 TEST_DESCRIPTION("Test that a warning is produced for a fragment shader which provides a spurious "
Chris Forbes1cc79542016-07-20 11:13:44 +120013484 "output with no matching attachment");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013485 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
Mike Weiblencce7ec72016-10-17 19:33:05 -060013486 "fragment shader writes to output location 1 with no matching attachment");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013487
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013488 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013489
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013490 char const *vsSource = "#version 450\n"
13491 "\n"
13492 "out gl_PerVertex {\n"
13493 " vec4 gl_Position;\n"
13494 "};\n"
13495 "void main(){\n"
13496 " gl_Position = vec4(1);\n"
13497 "}\n";
13498 char const *fsSource = "#version 450\n"
13499 "\n"
13500 "layout(location=0) out vec4 x;\n"
13501 "layout(location=1) out vec4 y;\n" /* no matching attachment for this */
13502 "void main(){\n"
13503 " x = vec4(1);\n"
13504 " y = vec4(1);\n"
13505 "}\n";
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013506
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013507 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13508 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013509
13510 VkPipelineObj pipe(m_device);
13511 pipe.AddShader(&vs);
13512 pipe.AddShader(&fs);
13513
Chia-I Wu08accc62015-07-07 11:50:03 +080013514 /* set up CB 0, not written */
13515 pipe.AddColorAttachment();
13516 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013517 /* FS writes CB 1, but we don't configure it */
13518
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013519 VkDescriptorSetObj descriptorSet(m_device);
13520 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013521 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013522
Tony Barbour5781e8f2015-08-04 16:23:11 -060013523 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013524
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013525 m_errorMonitor->VerifyFound();
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013526}
13527
Karl Schultz6addd812016-02-02 17:17:23 -070013528TEST_F(VkLayerTest, CreatePipelineFragmentOutputTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013529 TEST_DESCRIPTION("Test that an error is produced for a mismatch between the fundamental "
Mike Weiblencce7ec72016-10-17 19:33:05 -060013530 "type of an fragment shader output variable, and the format of the corresponding attachment");
13531 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "does not match fragment shader output type");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013532
Chris Forbesa36d69e2015-05-25 11:13:44 +120013533 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesa36d69e2015-05-25 11:13:44 +120013534
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013535 char const *vsSource = "#version 450\n"
13536 "\n"
13537 "out gl_PerVertex {\n"
13538 " vec4 gl_Position;\n"
13539 "};\n"
13540 "void main(){\n"
13541 " gl_Position = vec4(1);\n"
13542 "}\n";
13543 char const *fsSource = "#version 450\n"
13544 "\n"
13545 "layout(location=0) out ivec4 x;\n" /* not UNORM */
13546 "void main(){\n"
13547 " x = ivec4(1);\n"
13548 "}\n";
Chris Forbesa36d69e2015-05-25 11:13:44 +120013549
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013550 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13551 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesa36d69e2015-05-25 11:13:44 +120013552
13553 VkPipelineObj pipe(m_device);
13554 pipe.AddShader(&vs);
13555 pipe.AddShader(&fs);
13556
Chia-I Wu08accc62015-07-07 11:50:03 +080013557 /* set up CB 0; type is UNORM by default */
13558 pipe.AddColorAttachment();
13559 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesa36d69e2015-05-25 11:13:44 +120013560
Chris Forbesa36d69e2015-05-25 11:13:44 +120013561 VkDescriptorSetObj descriptorSet(m_device);
13562 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013563 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesa36d69e2015-05-25 11:13:44 +120013564
Tony Barbour5781e8f2015-08-04 16:23:11 -060013565 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesa36d69e2015-05-25 11:13:44 +120013566
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013567 m_errorMonitor->VerifyFound();
Chris Forbesa36d69e2015-05-25 11:13:44 +120013568}
Chris Forbes7b1b8932015-06-05 14:43:36 +120013569
Karl Schultz6addd812016-02-02 17:17:23 -070013570TEST_F(VkLayerTest, CreatePipelineUniformBlockNotProvided) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013571 TEST_DESCRIPTION("Test that an error is produced for a shader consuming a uniform "
13572 "block which has no corresponding binding in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013573 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not declared in pipeline layout");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013574
Chris Forbes556c76c2015-08-14 12:04:59 +120013575 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes556c76c2015-08-14 12:04:59 +120013576
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013577 char const *vsSource = "#version 450\n"
13578 "\n"
13579 "out gl_PerVertex {\n"
13580 " vec4 gl_Position;\n"
13581 "};\n"
13582 "void main(){\n"
13583 " gl_Position = vec4(1);\n"
13584 "}\n";
13585 char const *fsSource = "#version 450\n"
13586 "\n"
13587 "layout(location=0) out vec4 x;\n"
13588 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
13589 "void main(){\n"
13590 " x = vec4(bar.y);\n"
13591 "}\n";
Chris Forbes556c76c2015-08-14 12:04:59 +120013592
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013593 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13594 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes556c76c2015-08-14 12:04:59 +120013595
Chris Forbes556c76c2015-08-14 12:04:59 +120013596 VkPipelineObj pipe(m_device);
13597 pipe.AddShader(&vs);
13598 pipe.AddShader(&fs);
13599
13600 /* set up CB 0; type is UNORM by default */
13601 pipe.AddColorAttachment();
13602 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13603
13604 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013605 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes556c76c2015-08-14 12:04:59 +120013606
13607 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13608
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013609 m_errorMonitor->VerifyFound();
Chris Forbes556c76c2015-08-14 12:04:59 +120013610}
13611
Chris Forbes5c59e902016-02-26 16:56:09 +130013612TEST_F(VkLayerTest, CreatePipelinePushConstantsNotInLayout) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013613 TEST_DESCRIPTION("Test that an error is produced for a shader consuming push constants "
13614 "which are not provided in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013615 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not declared in layout");
Chris Forbes5c59e902016-02-26 16:56:09 +130013616
13617 ASSERT_NO_FATAL_FAILURE(InitState());
13618
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013619 char const *vsSource = "#version 450\n"
13620 "\n"
13621 "layout(push_constant, std430) uniform foo { float x; } consts;\n"
13622 "out gl_PerVertex {\n"
13623 " vec4 gl_Position;\n"
13624 "};\n"
13625 "void main(){\n"
13626 " gl_Position = vec4(consts.x);\n"
13627 "}\n";
13628 char const *fsSource = "#version 450\n"
13629 "\n"
13630 "layout(location=0) out vec4 x;\n"
13631 "void main(){\n"
13632 " x = vec4(1);\n"
13633 "}\n";
Chris Forbes5c59e902016-02-26 16:56:09 +130013634
13635 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13636 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13637
13638 VkPipelineObj pipe(m_device);
13639 pipe.AddShader(&vs);
13640 pipe.AddShader(&fs);
13641
13642 /* set up CB 0; type is UNORM by default */
13643 pipe.AddColorAttachment();
13644 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13645
13646 VkDescriptorSetObj descriptorSet(m_device);
13647 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13648
13649 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13650
13651 /* should have generated an error -- no push constant ranges provided! */
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013652 m_errorMonitor->VerifyFound();
Chris Forbes5c59e902016-02-26 16:56:09 +130013653}
13654
Chris Forbes3fb17902016-08-22 14:57:55 +120013655TEST_F(VkLayerTest, CreatePipelineInputAttachmentMissing) {
13656 TEST_DESCRIPTION("Test that an error is produced for a shader consuming an input attachment "
13657 "which is not included in the subpass description");
13658 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13659 "consumes input attachment index 0 but not provided in subpass");
13660
13661 ASSERT_NO_FATAL_FAILURE(InitState());
13662
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013663 char const *vsSource = "#version 450\n"
13664 "\n"
13665 "out gl_PerVertex {\n"
13666 " vec4 gl_Position;\n"
13667 "};\n"
13668 "void main(){\n"
13669 " gl_Position = vec4(1);\n"
13670 "}\n";
13671 char const *fsSource = "#version 450\n"
13672 "\n"
13673 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
13674 "layout(location=0) out vec4 color;\n"
13675 "void main() {\n"
13676 " color = subpassLoad(x);\n"
13677 "}\n";
Chris Forbes3fb17902016-08-22 14:57:55 +120013678
13679 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13680 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13681
13682 VkPipelineObj pipe(m_device);
13683 pipe.AddShader(&vs);
13684 pipe.AddShader(&fs);
13685 pipe.AddColorAttachment();
13686 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13687
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013688 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
13689 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes3fb17902016-08-22 14:57:55 +120013690 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013691 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes3fb17902016-08-22 14:57:55 +120013692 ASSERT_VK_SUCCESS(err);
13693
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013694 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes3fb17902016-08-22 14:57:55 +120013695 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013696 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes3fb17902016-08-22 14:57:55 +120013697 ASSERT_VK_SUCCESS(err);
13698
13699 // error here.
13700 pipe.CreateVKPipeline(pl, renderPass());
13701
13702 m_errorMonitor->VerifyFound();
13703
13704 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
13705 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
13706}
13707
Chris Forbes5a9a0472016-08-22 16:02:09 +120013708TEST_F(VkLayerTest, CreatePipelineInputAttachmentTypeMismatch) {
13709 TEST_DESCRIPTION("Test that an error is produced for a shader consuming an input attachment "
13710 "with a format having a different fundamental type");
13711 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13712 "input attachment 0 format of VK_FORMAT_R8G8B8A8_UINT does not match");
13713
13714 ASSERT_NO_FATAL_FAILURE(InitState());
13715
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013716 char const *vsSource = "#version 450\n"
13717 "\n"
13718 "out gl_PerVertex {\n"
13719 " vec4 gl_Position;\n"
13720 "};\n"
13721 "void main(){\n"
13722 " gl_Position = vec4(1);\n"
13723 "}\n";
13724 char const *fsSource = "#version 450\n"
13725 "\n"
13726 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
13727 "layout(location=0) out vec4 color;\n"
13728 "void main() {\n"
13729 " color = subpassLoad(x);\n"
13730 "}\n";
Chris Forbes5a9a0472016-08-22 16:02:09 +120013731
13732 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13733 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13734
13735 VkPipelineObj pipe(m_device);
13736 pipe.AddShader(&vs);
13737 pipe.AddShader(&fs);
13738 pipe.AddColorAttachment();
13739 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13740
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013741 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
13742 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes5a9a0472016-08-22 16:02:09 +120013743 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013744 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes5a9a0472016-08-22 16:02:09 +120013745 ASSERT_VK_SUCCESS(err);
13746
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013747 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120013748 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013749 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes5a9a0472016-08-22 16:02:09 +120013750 ASSERT_VK_SUCCESS(err);
13751
13752 VkAttachmentDescription descs[2] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013753 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
13754 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
13755 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
13756 {0, VK_FORMAT_R8G8B8A8_UINT, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
13757 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 +120013758 };
13759 VkAttachmentReference color = {
13760 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
13761 };
13762 VkAttachmentReference input = {
13763 1, VK_IMAGE_LAYOUT_GENERAL,
13764 };
13765
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013766 VkSubpassDescription sd = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 1, &input, 1, &color, nullptr, nullptr, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120013767
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013768 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, descs, 1, &sd, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120013769 VkRenderPass rp;
13770 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
13771 ASSERT_VK_SUCCESS(err);
13772
13773 // error here.
13774 pipe.CreateVKPipeline(pl, rp);
13775
13776 m_errorMonitor->VerifyFound();
13777
13778 vkDestroyRenderPass(m_device->device(), rp, nullptr);
13779 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
13780 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
13781}
13782
Chris Forbes541f7b02016-08-22 15:30:27 +120013783TEST_F(VkLayerTest, CreatePipelineInputAttachmentMissingArray) {
13784 TEST_DESCRIPTION("Test that an error is produced for a shader consuming an input attachment "
13785 "which is not included in the subpass description -- array case");
13786 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13787 "consumes input attachment index 1 but not provided in subpass");
13788
13789 ASSERT_NO_FATAL_FAILURE(InitState());
13790
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013791 char const *vsSource = "#version 450\n"
13792 "\n"
13793 "out gl_PerVertex {\n"
13794 " vec4 gl_Position;\n"
13795 "};\n"
13796 "void main(){\n"
13797 " gl_Position = vec4(1);\n"
13798 "}\n";
13799 char const *fsSource = "#version 450\n"
13800 "\n"
13801 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput xs[2];\n"
13802 "layout(location=0) out vec4 color;\n"
13803 "void main() {\n"
13804 " color = subpassLoad(xs[1]);\n"
13805 "}\n";
Chris Forbes541f7b02016-08-22 15:30:27 +120013806
13807 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13808 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13809
13810 VkPipelineObj pipe(m_device);
13811 pipe.AddShader(&vs);
13812 pipe.AddShader(&fs);
13813 pipe.AddColorAttachment();
13814 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13815
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013816 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 2, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
13817 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes541f7b02016-08-22 15:30:27 +120013818 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013819 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes541f7b02016-08-22 15:30:27 +120013820 ASSERT_VK_SUCCESS(err);
13821
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013822 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes541f7b02016-08-22 15:30:27 +120013823 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013824 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes541f7b02016-08-22 15:30:27 +120013825 ASSERT_VK_SUCCESS(err);
13826
13827 // error here.
13828 pipe.CreateVKPipeline(pl, renderPass());
13829
13830 m_errorMonitor->VerifyFound();
13831
13832 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
13833 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
13834}
13835
Chris Forbes10eb9ae2016-05-31 16:09:42 +120013836TEST_F(VkLayerTest, CreateComputePipelineMissingDescriptor) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013837 TEST_DESCRIPTION("Test that an error is produced for a compute pipeline consuming a "
13838 "descriptor which is not provided in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013839 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Shader uses descriptor slot 0.0");
Chris Forbes10eb9ae2016-05-31 16:09:42 +120013840
13841 ASSERT_NO_FATAL_FAILURE(InitState());
13842
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013843 char const *csSource = "#version 450\n"
13844 "\n"
13845 "layout(local_size_x=1) in;\n"
13846 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
13847 "void main(){\n"
13848 " x = vec4(1);\n"
13849 "}\n";
Chris Forbes10eb9ae2016-05-31 16:09:42 +120013850
13851 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
13852
13853 VkDescriptorSetObj descriptorSet(m_device);
13854 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13855
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013856 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
13857 nullptr,
13858 0,
13859 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
13860 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
13861 descriptorSet.GetPipelineLayout(),
13862 VK_NULL_HANDLE,
13863 -1};
Chris Forbes10eb9ae2016-05-31 16:09:42 +120013864
13865 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013866 VkResult err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes10eb9ae2016-05-31 16:09:42 +120013867
13868 m_errorMonitor->VerifyFound();
13869
13870 if (err == VK_SUCCESS) {
13871 vkDestroyPipeline(m_device->device(), pipe, nullptr);
13872 }
13873}
13874
Chris Forbes22a9b092016-07-19 14:34:05 +120013875TEST_F(VkLayerTest, CreateComputePipelineDescriptorTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013876 TEST_DESCRIPTION("Test that an error is produced for a pipeline consuming a "
13877 "descriptor-backed resource of a mismatched type");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013878 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13879 "but descriptor of type VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER");
Chris Forbes22a9b092016-07-19 14:34:05 +120013880
13881 ASSERT_NO_FATAL_FAILURE(InitState());
13882
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013883 VkDescriptorSetLayoutBinding binding = {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr};
13884 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &binding};
Chris Forbes22a9b092016-07-19 14:34:05 +120013885 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013886 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes22a9b092016-07-19 14:34:05 +120013887 ASSERT_VK_SUCCESS(err);
13888
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013889 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes22a9b092016-07-19 14:34:05 +120013890 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013891 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes22a9b092016-07-19 14:34:05 +120013892 ASSERT_VK_SUCCESS(err);
13893
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013894 char const *csSource = "#version 450\n"
13895 "\n"
13896 "layout(local_size_x=1) in;\n"
13897 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
13898 "void main() {\n"
13899 " x.x = 1.0f;\n"
13900 "}\n";
Chris Forbes22a9b092016-07-19 14:34:05 +120013901 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
13902
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013903 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
13904 nullptr,
13905 0,
13906 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
13907 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
13908 pl,
13909 VK_NULL_HANDLE,
13910 -1};
Chris Forbes22a9b092016-07-19 14:34:05 +120013911
13912 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013913 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes22a9b092016-07-19 14:34:05 +120013914
13915 m_errorMonitor->VerifyFound();
13916
13917 if (err == VK_SUCCESS) {
13918 vkDestroyPipeline(m_device->device(), pipe, nullptr);
13919 }
13920
13921 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
13922 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
13923}
13924
Chris Forbes50020592016-07-27 13:52:41 +120013925TEST_F(VkLayerTest, DrawTimeImageViewTypeMismatchWithPipeline) {
13926 TEST_DESCRIPTION("Test that an error is produced when an image view type "
13927 "does not match the dimensionality declared in the shader");
13928
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013929 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 +120013930
13931 ASSERT_NO_FATAL_FAILURE(InitState());
13932 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13933
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013934 char const *vsSource = "#version 450\n"
13935 "\n"
13936 "out gl_PerVertex { vec4 gl_Position; };\n"
13937 "void main() { gl_Position = vec4(0); }\n";
13938 char const *fsSource = "#version 450\n"
13939 "\n"
13940 "layout(set=0, binding=0) uniform sampler3D s;\n"
13941 "layout(location=0) out vec4 color;\n"
13942 "void main() {\n"
13943 " color = texture(s, vec3(0));\n"
13944 "}\n";
Chris Forbes50020592016-07-27 13:52:41 +120013945 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13946 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13947
13948 VkPipelineObj pipe(m_device);
13949 pipe.AddShader(&vs);
13950 pipe.AddShader(&fs);
13951 pipe.AddColorAttachment();
13952
13953 VkTextureObj texture(m_device, nullptr);
13954 VkSamplerObj sampler(m_device);
13955
13956 VkDescriptorSetObj descriptorSet(m_device);
13957 descriptorSet.AppendSamplerTexture(&sampler, &texture);
13958 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13959
13960 VkResult err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13961 ASSERT_VK_SUCCESS(err);
13962
13963 BeginCommandBuffer();
13964
13965 m_commandBuffer->BindPipeline(pipe);
13966 m_commandBuffer->BindDescriptorSet(descriptorSet);
13967
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013968 VkViewport viewport = {0, 0, 16, 16, 0, 1};
Chris Forbes50020592016-07-27 13:52:41 +120013969 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013970 VkRect2D scissor = {{0, 0}, {16, 16}};
Chris Forbes50020592016-07-27 13:52:41 +120013971 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
13972
13973 // error produced here.
13974 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
13975
13976 m_errorMonitor->VerifyFound();
13977
13978 EndCommandBuffer();
13979}
13980
Chris Forbes5533bfc2016-07-27 14:12:34 +120013981TEST_F(VkLayerTest, DrawTimeImageMultisampleMismatchWithPipeline) {
13982 TEST_DESCRIPTION("Test that an error is produced when a multisampled images "
13983 "are consumed via singlesample images types in the shader, or vice versa.");
13984
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013985 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "requires bound image to have multiple samples");
Chris Forbes5533bfc2016-07-27 14:12:34 +120013986
13987 ASSERT_NO_FATAL_FAILURE(InitState());
13988 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13989
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013990 char const *vsSource = "#version 450\n"
13991 "\n"
13992 "out gl_PerVertex { vec4 gl_Position; };\n"
13993 "void main() { gl_Position = vec4(0); }\n";
13994 char const *fsSource = "#version 450\n"
13995 "\n"
13996 "layout(set=0, binding=0) uniform sampler2DMS s;\n"
13997 "layout(location=0) out vec4 color;\n"
13998 "void main() {\n"
13999 " color = texelFetch(s, ivec2(0), 0);\n"
14000 "}\n";
Chris Forbes5533bfc2016-07-27 14:12:34 +120014001 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
14009 VkTextureObj texture(m_device, nullptr);
14010 VkSamplerObj sampler(m_device);
14011
14012 VkDescriptorSetObj descriptorSet(m_device);
14013 descriptorSet.AppendSamplerTexture(&sampler, &texture);
14014 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14015
14016 VkResult err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14017 ASSERT_VK_SUCCESS(err);
14018
14019 BeginCommandBuffer();
14020
14021 m_commandBuffer->BindPipeline(pipe);
14022 m_commandBuffer->BindDescriptorSet(descriptorSet);
14023
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014024 VkViewport viewport = {0, 0, 16, 16, 0, 1};
Chris Forbes5533bfc2016-07-27 14:12:34 +120014025 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014026 VkRect2D scissor = {{0, 0}, {16, 16}};
Chris Forbes5533bfc2016-07-27 14:12:34 +120014027 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
14028
14029 // error produced here.
14030 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
14031
14032 m_errorMonitor->VerifyFound();
14033
14034 EndCommandBuffer();
14035}
14036
Mark Lobodzinski209b5292015-09-17 09:44:05 -060014037#endif // SHADER_CHECKER_TESTS
14038
14039#if DEVICE_LIMITS_TESTS
Mark Youngc48c4c12016-04-11 14:26:49 -060014040TEST_F(VkLayerTest, CreateImageLimitsViolationMaxWidth) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014041 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "CreateImage extents exceed allowable limits for format");
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060014042
14043 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060014044
14045 // Create an image
14046 VkImage image;
14047
Karl Schultz6addd812016-02-02 17:17:23 -070014048 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
14049 const int32_t tex_width = 32;
14050 const int32_t tex_height = 32;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060014051
14052 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014053 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14054 image_create_info.pNext = NULL;
14055 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14056 image_create_info.format = tex_format;
14057 image_create_info.extent.width = tex_width;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060014058 image_create_info.extent.height = tex_height;
Karl Schultz6addd812016-02-02 17:17:23 -070014059 image_create_info.extent.depth = 1;
14060 image_create_info.mipLevels = 1;
14061 image_create_info.arrayLayers = 1;
14062 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14063 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
14064 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
14065 image_create_info.flags = 0;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060014066
14067 // Introduce error by sending down a bogus width extent
14068 image_create_info.extent.width = 65536;
Chia-I Wuf7458c52015-10-26 21:10:41 +080014069 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060014070
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014071 m_errorMonitor->VerifyFound();
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060014072}
14073
Mark Youngc48c4c12016-04-11 14:26:49 -060014074TEST_F(VkLayerTest, CreateImageLimitsViolationMinWidth) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014075 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14076 "CreateImage extents is 0 for at least one required dimension");
Mark Youngc48c4c12016-04-11 14:26:49 -060014077
14078 ASSERT_NO_FATAL_FAILURE(InitState());
14079
14080 // Create an image
14081 VkImage image;
14082
14083 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
14084 const int32_t tex_width = 32;
14085 const int32_t tex_height = 32;
14086
14087 VkImageCreateInfo image_create_info = {};
14088 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14089 image_create_info.pNext = NULL;
14090 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14091 image_create_info.format = tex_format;
14092 image_create_info.extent.width = tex_width;
14093 image_create_info.extent.height = tex_height;
14094 image_create_info.extent.depth = 1;
14095 image_create_info.mipLevels = 1;
14096 image_create_info.arrayLayers = 1;
14097 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14098 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
14099 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
14100 image_create_info.flags = 0;
14101
14102 // Introduce error by sending down a bogus width extent
14103 image_create_info.extent.width = 0;
14104 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
14105
14106 m_errorMonitor->VerifyFound();
14107}
Mark Lobodzinski209b5292015-09-17 09:44:05 -060014108#endif // DEVICE_LIMITS_TESTS
Chris Forbesa36d69e2015-05-25 11:13:44 +120014109
Tobin Ehliscde08892015-09-22 10:11:37 -060014110#if IMAGE_TESTS
Mark Lobodzinski66e5eab2016-11-15 13:30:38 -070014111
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060014112TEST_F(VkLayerTest, AttachmentDescriptionUndefinedFormat) {
14113 TEST_DESCRIPTION("Create a render pass with an attachment description "
14114 "format set to VK_FORMAT_UNDEFINED");
14115
14116 ASSERT_NO_FATAL_FAILURE(InitState());
14117 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14118
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014119 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "format is VK_FORMAT_UNDEFINED");
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060014120
14121 VkAttachmentReference color_attach = {};
14122 color_attach.layout = VK_IMAGE_LAYOUT_GENERAL;
14123 color_attach.attachment = 0;
14124 VkSubpassDescription subpass = {};
14125 subpass.colorAttachmentCount = 1;
14126 subpass.pColorAttachments = &color_attach;
14127
14128 VkRenderPassCreateInfo rpci = {};
14129 rpci.subpassCount = 1;
14130 rpci.pSubpasses = &subpass;
14131 rpci.attachmentCount = 1;
14132 VkAttachmentDescription attach_desc = {};
14133 attach_desc.format = VK_FORMAT_UNDEFINED;
14134 rpci.pAttachments = &attach_desc;
14135 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
14136 VkRenderPass rp;
14137 VkResult result = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
14138
14139 m_errorMonitor->VerifyFound();
14140
14141 if (result == VK_SUCCESS) {
14142 vkDestroyRenderPass(m_device->device(), rp, NULL);
14143 }
14144}
14145
Karl Schultz6addd812016-02-02 17:17:23 -070014146TEST_F(VkLayerTest, InvalidImageView) {
14147 VkResult err;
Tobin Ehliscde08892015-09-22 10:11:37 -060014148
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014149 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with baseMipLevel 10 ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014150
Tobin Ehliscde08892015-09-22 10:11:37 -060014151 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehliscde08892015-09-22 10:11:37 -060014152
Mike Stroyana3082432015-09-25 13:39:21 -060014153 // Create an image and try to create a view with bad baseMipLevel
Karl Schultz6addd812016-02-02 17:17:23 -070014154 VkImage image;
Tobin Ehliscde08892015-09-22 10:11:37 -060014155
Karl Schultz6addd812016-02-02 17:17:23 -070014156 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
14157 const int32_t tex_width = 32;
14158 const int32_t tex_height = 32;
Tobin Ehliscde08892015-09-22 10:11:37 -060014159
14160 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014161 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14162 image_create_info.pNext = NULL;
14163 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14164 image_create_info.format = tex_format;
14165 image_create_info.extent.width = tex_width;
14166 image_create_info.extent.height = tex_height;
14167 image_create_info.extent.depth = 1;
14168 image_create_info.mipLevels = 1;
14169 image_create_info.arrayLayers = 1;
14170 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14171 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
14172 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
14173 image_create_info.flags = 0;
Tobin Ehliscde08892015-09-22 10:11:37 -060014174
Chia-I Wuf7458c52015-10-26 21:10:41 +080014175 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehliscde08892015-09-22 10:11:37 -060014176 ASSERT_VK_SUCCESS(err);
14177
14178 VkImageViewCreateInfo image_view_create_info = {};
Chris Forbes53bef902016-11-28 17:53:04 +130014179 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070014180 image_view_create_info.image = image;
14181 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
14182 image_view_create_info.format = tex_format;
14183 image_view_create_info.subresourceRange.layerCount = 1;
14184 image_view_create_info.subresourceRange.baseMipLevel = 10; // cause an error
14185 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014186 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehliscde08892015-09-22 10:11:37 -060014187
14188 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014189 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehliscde08892015-09-22 10:11:37 -060014190
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014191 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -060014192 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehliscde08892015-09-22 10:11:37 -060014193}
Mike Stroyana3082432015-09-25 13:39:21 -060014194
Mark Youngd339ba32016-05-30 13:28:35 -060014195TEST_F(VkLayerTest, CreateImageViewNoMemoryBoundToImage) {
14196 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -060014197 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -060014198 " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Mark Youngd339ba32016-05-30 13:28:35 -060014199
14200 ASSERT_NO_FATAL_FAILURE(InitState());
14201
14202 // Create an image and try to create a view with no memory backing the image
14203 VkImage image;
14204
14205 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
14206 const int32_t tex_width = 32;
14207 const int32_t tex_height = 32;
14208
14209 VkImageCreateInfo image_create_info = {};
14210 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14211 image_create_info.pNext = NULL;
14212 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14213 image_create_info.format = tex_format;
14214 image_create_info.extent.width = tex_width;
14215 image_create_info.extent.height = tex_height;
14216 image_create_info.extent.depth = 1;
14217 image_create_info.mipLevels = 1;
14218 image_create_info.arrayLayers = 1;
14219 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14220 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
14221 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
14222 image_create_info.flags = 0;
14223
14224 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
14225 ASSERT_VK_SUCCESS(err);
14226
14227 VkImageViewCreateInfo image_view_create_info = {};
Chris Forbes53bef902016-11-28 17:53:04 +130014228 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Mark Youngd339ba32016-05-30 13:28:35 -060014229 image_view_create_info.image = image;
14230 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
14231 image_view_create_info.format = tex_format;
14232 image_view_create_info.subresourceRange.layerCount = 1;
14233 image_view_create_info.subresourceRange.baseMipLevel = 0;
14234 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014235 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Youngd339ba32016-05-30 13:28:35 -060014236
14237 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014238 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Youngd339ba32016-05-30 13:28:35 -060014239
14240 m_errorMonitor->VerifyFound();
14241 vkDestroyImage(m_device->device(), image, NULL);
14242 // If last error is success, it still created the view, so delete it.
14243 if (err == VK_SUCCESS) {
14244 vkDestroyImageView(m_device->device(), view, NULL);
14245 }
Mark Youngd339ba32016-05-30 13:28:35 -060014246}
14247
Karl Schultz6addd812016-02-02 17:17:23 -070014248TEST_F(VkLayerTest, InvalidImageViewAspect) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014249 TEST_DESCRIPTION("Create an image and try to create a view with an invalid aspectMask");
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060014250 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView(): Color image "
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014251 "formats must have ONLY the "
14252 "VK_IMAGE_ASPECT_COLOR_BIT set");
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060014253 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14254 "Color image formats must have the VK_IMAGE_ASPECT_COLOR_BIT set.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014255
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060014256 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060014257
Karl Schultz6addd812016-02-02 17:17:23 -070014258 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060014259 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014260 image.init(32, 32, tex_format, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_LINEAR, 0);
Tobin Ehlis1f567a22016-05-25 16:15:18 -060014261 ASSERT_TRUE(image.initialized());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060014262
14263 VkImageViewCreateInfo image_view_create_info = {};
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060014264 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060014265 image_view_create_info.image = image.handle();
Karl Schultz6addd812016-02-02 17:17:23 -070014266 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
14267 image_view_create_info.format = tex_format;
14268 image_view_create_info.subresourceRange.baseMipLevel = 0;
14269 image_view_create_info.subresourceRange.levelCount = 1;
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060014270 image_view_create_info.subresourceRange.layerCount = 1;
Karl Schultz6addd812016-02-02 17:17:23 -070014271 // Cause an error by setting an invalid image aspect
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014272 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060014273
14274 VkImageView view;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060014275 vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060014276
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014277 m_errorMonitor->VerifyFound();
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060014278}
14279
Mark Lobodzinskidb117632016-03-31 10:45:56 -060014280TEST_F(VkLayerTest, CopyImageLayerCountMismatch) {
Karl Schultz6addd812016-02-02 17:17:23 -070014281 VkResult err;
14282 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060014283
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014284 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14285 "vkCmdCopyImage: number of layers in source and destination subresources for pRegions");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014286
Mike Stroyana3082432015-09-25 13:39:21 -060014287 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060014288
14289 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070014290 VkImage srcImage;
14291 VkImage dstImage;
14292 VkDeviceMemory srcMem;
14293 VkDeviceMemory destMem;
14294 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060014295
14296 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014297 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14298 image_create_info.pNext = NULL;
14299 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14300 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
14301 image_create_info.extent.width = 32;
14302 image_create_info.extent.height = 32;
14303 image_create_info.extent.depth = 1;
14304 image_create_info.mipLevels = 1;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060014305 image_create_info.arrayLayers = 4;
Karl Schultz6addd812016-02-02 17:17:23 -070014306 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14307 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
14308 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
14309 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014310
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014311 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014312 ASSERT_VK_SUCCESS(err);
14313
Mark Lobodzinski867787a2016-10-14 11:49:55 -060014314 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014315 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014316 ASSERT_VK_SUCCESS(err);
14317
14318 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014319 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014320 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
14321 memAlloc.pNext = NULL;
14322 memAlloc.allocationSize = 0;
14323 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014324
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060014325 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014326 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014327 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014328 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014329 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014330 ASSERT_VK_SUCCESS(err);
14331
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014332 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014333 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014334 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060014335 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014336 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014337 ASSERT_VK_SUCCESS(err);
14338
14339 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
14340 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014341 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060014342 ASSERT_VK_SUCCESS(err);
14343
14344 BeginCommandBuffer();
14345 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014346 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014347 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060014348 copyRegion.srcSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060014349 copyRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060014350 copyRegion.srcOffset.x = 0;
14351 copyRegion.srcOffset.y = 0;
14352 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014353 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014354 copyRegion.dstSubresource.mipLevel = 0;
14355 copyRegion.dstSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060014356 // Introduce failure by forcing the dst layerCount to differ from src
14357 copyRegion.dstSubresource.layerCount = 3;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014358 copyRegion.dstOffset.x = 0;
14359 copyRegion.dstOffset.y = 0;
14360 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014361 copyRegion.extent.width = 1;
14362 copyRegion.extent.height = 1;
14363 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014364 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060014365 EndCommandBuffer();
14366
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014367 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060014368
Chia-I Wuf7458c52015-10-26 21:10:41 +080014369 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014370 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080014371 vkFreeMemory(m_device->device(), srcMem, NULL);
14372 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060014373}
14374
Tony Barbourd6673642016-05-05 14:46:39 -060014375TEST_F(VkLayerTest, ImageLayerUnsupportedFormat) {
14376
14377 TEST_DESCRIPTION("Creating images with unsuported formats ");
14378
14379 ASSERT_NO_FATAL_FAILURE(InitState());
14380 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14381 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014382 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 -060014383 VK_IMAGE_TILING_OPTIMAL, 0);
14384 ASSERT_TRUE(image.initialized());
14385
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014386 // Create image with unsupported format - Expect FORMAT_UNSUPPORTED
Chris Forbesf4d8e332016-11-28 17:51:10 +130014387 VkImageCreateInfo image_create_info = {};
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014388 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014389 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14390 image_create_info.format = VK_FORMAT_UNDEFINED;
14391 image_create_info.extent.width = 32;
14392 image_create_info.extent.height = 32;
14393 image_create_info.extent.depth = 1;
14394 image_create_info.mipLevels = 1;
14395 image_create_info.arrayLayers = 1;
14396 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14397 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
14398 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014399
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014400 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14401 "vkCreateImage: VkFormat for image must not be VK_FORMAT_UNDEFINED");
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014402
14403 VkImage localImage;
14404 vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage);
14405 m_errorMonitor->VerifyFound();
14406
Tony Barbourd6673642016-05-05 14:46:39 -060014407 VkFormat unsupported = VK_FORMAT_UNDEFINED;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014408 // Look for a format that is COMPLETELY unsupported with this hardware
Tony Barbourd6673642016-05-05 14:46:39 -060014409 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
14410 VkFormat format = static_cast<VkFormat>(f);
14411 VkFormatProperties fProps = m_device->format_properties(format);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014412 if (format != VK_FORMAT_UNDEFINED && fProps.linearTilingFeatures == 0 && fProps.optimalTilingFeatures == 0) {
Tony Barbourd6673642016-05-05 14:46:39 -060014413 unsupported = format;
14414 break;
14415 }
14416 }
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014417
Tony Barbourd6673642016-05-05 14:46:39 -060014418 if (unsupported != VK_FORMAT_UNDEFINED) {
Tony Barbourd6673642016-05-05 14:46:39 -060014419 image_create_info.format = unsupported;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014420 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is an unsupported format");
Tony Barbourd6673642016-05-05 14:46:39 -060014421
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014422 vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage);
Tony Barbourd6673642016-05-05 14:46:39 -060014423 m_errorMonitor->VerifyFound();
14424 }
14425}
14426
14427TEST_F(VkLayerTest, ImageLayerViewTests) {
14428 VkResult ret;
14429 TEST_DESCRIPTION("Passing bad parameters to CreateImageView");
14430
14431 ASSERT_NO_FATAL_FAILURE(InitState());
14432
14433 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014434 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 -060014435 VK_IMAGE_TILING_OPTIMAL, 0);
14436 ASSERT_TRUE(image.initialized());
14437
14438 VkImageView imgView;
14439 VkImageViewCreateInfo imgViewInfo = {};
14440 imgViewInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
14441 imgViewInfo.image = image.handle();
14442 imgViewInfo.viewType = VK_IMAGE_VIEW_TYPE_2D;
14443 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
14444 imgViewInfo.subresourceRange.layerCount = 1;
14445 imgViewInfo.subresourceRange.baseMipLevel = 0;
14446 imgViewInfo.subresourceRange.levelCount = 1;
14447 imgViewInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14448
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014449 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with baseMipLevel");
Tony Barbourd6673642016-05-05 14:46:39 -060014450 // View can't have baseMipLevel >= image's mipLevels - Expect
14451 // VIEW_CREATE_ERROR
14452 imgViewInfo.subresourceRange.baseMipLevel = 1;
14453 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14454 m_errorMonitor->VerifyFound();
14455 imgViewInfo.subresourceRange.baseMipLevel = 0;
14456
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014457 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with baseArrayLayer");
Tony Barbourd6673642016-05-05 14:46:39 -060014458 // View can't have baseArrayLayer >= image's arraySize - Expect
14459 // VIEW_CREATE_ERROR
14460 imgViewInfo.subresourceRange.baseArrayLayer = 1;
14461 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14462 m_errorMonitor->VerifyFound();
14463 imgViewInfo.subresourceRange.baseArrayLayer = 0;
14464
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014465 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with 0 in "
14466 "pCreateInfo->subresourceRange."
14467 "levelCount");
Tony Barbourd6673642016-05-05 14:46:39 -060014468 // View's levelCount can't be 0 - Expect VIEW_CREATE_ERROR
14469 imgViewInfo.subresourceRange.levelCount = 0;
14470 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14471 m_errorMonitor->VerifyFound();
14472 imgViewInfo.subresourceRange.levelCount = 1;
14473
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014474 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with 0 in "
14475 "pCreateInfo->subresourceRange."
14476 "layerCount");
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060014477 m_errorMonitor->SetDesiredFailureMsg(
14478 VK_DEBUG_REPORT_ERROR_BIT_EXT,
14479 "if pCreateInfo->viewType is VK_IMAGE_TYPE_2D, pCreateInfo->subresourceRange.layerCount must be 1");
Tony Barbourd6673642016-05-05 14:46:39 -060014480 // View's layerCount can't be 0 - Expect VIEW_CREATE_ERROR
14481 imgViewInfo.subresourceRange.layerCount = 0;
14482 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14483 m_errorMonitor->VerifyFound();
14484 imgViewInfo.subresourceRange.layerCount = 1;
14485
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014486 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "but both must be color formats");
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060014487 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Formats MUST be IDENTICAL unless "
14488 "VK_IMAGE_CREATE_MUTABLE_FORMAT BIT "
14489 "was set on image creation.");
Tony Barbourd6673642016-05-05 14:46:39 -060014490 // Can't use depth format for view into color image - Expect INVALID_FORMAT
14491 imgViewInfo.format = VK_FORMAT_D24_UNORM_S8_UINT;
14492 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14493 m_errorMonitor->VerifyFound();
14494 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
14495
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014496 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Formats MUST be IDENTICAL unless "
14497 "VK_IMAGE_CREATE_MUTABLE_FORMAT BIT "
14498 "was set on image creation.");
Tony Barbourd6673642016-05-05 14:46:39 -060014499 // Same compatibility class but no MUTABLE_FORMAT bit - Expect
14500 // VIEW_CREATE_ERROR
14501 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UINT;
14502 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14503 m_errorMonitor->VerifyFound();
14504 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
14505
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014506 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "can support ImageViews with "
14507 "differing formats but they must be "
14508 "in the same compatibility class.");
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060014509 // TODO: Update framework to easily passing mutable flag into ImageObj init
14510 // For now just allowing image for this one test to not have memory bound
14511 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14512 " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Tony Barbourd6673642016-05-05 14:46:39 -060014513 // Have MUTABLE_FORMAT bit but not in same compatibility class - Expect
14514 // VIEW_CREATE_ERROR
14515 VkImageCreateInfo mutImgInfo = image.create_info();
14516 VkImage mutImage;
14517 mutImgInfo.format = VK_FORMAT_R8_UINT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014518 assert(m_device->format_properties(VK_FORMAT_R8_UINT).optimalTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT);
Tony Barbourd6673642016-05-05 14:46:39 -060014519 mutImgInfo.flags = VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT;
14520 mutImgInfo.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
14521 ret = vkCreateImage(m_device->handle(), &mutImgInfo, NULL, &mutImage);
14522 ASSERT_VK_SUCCESS(ret);
14523 imgViewInfo.image = mutImage;
14524 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14525 m_errorMonitor->VerifyFound();
14526 imgViewInfo.image = image.handle();
14527 vkDestroyImage(m_device->handle(), mutImage, NULL);
14528}
14529
14530TEST_F(VkLayerTest, MiscImageLayerTests) {
14531
14532 TEST_DESCRIPTION("Image layer tests that don't belong elsewhare");
14533
14534 ASSERT_NO_FATAL_FAILURE(InitState());
14535
14536 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014537 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 -060014538 VK_IMAGE_TILING_OPTIMAL, 0);
14539 ASSERT_TRUE(image.initialized());
14540
Tony Barbourd6673642016-05-05 14:46:39 -060014541 vk_testing::Buffer buffer;
14542 VkMemoryPropertyFlags reqs = 0;
14543 buffer.init_as_src(*m_device, 128 * 128 * 4, reqs);
14544 VkBufferImageCopy region = {};
14545 region.bufferRowLength = 128;
14546 region.bufferImageHeight = 128;
14547 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14548 // layerCount can't be 0 - Expect MISMATCHED_IMAGE_ASPECT
Mark Lobodzinski3702e932016-11-22 11:40:48 -070014549 region.imageSubresource.layerCount = 1;
Tony Barbourd6673642016-05-05 14:46:39 -060014550 region.imageExtent.height = 4;
14551 region.imageExtent.width = 4;
14552 region.imageExtent.depth = 1;
14553 m_commandBuffer->BeginCommandBuffer();
Tony Barbourd6673642016-05-05 14:46:39 -060014554
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070014555 // Image must have offset.z of 0 and extent.depth of 1
14556 // Introduce failure by setting imageExtent.depth to 0
14557 region.imageExtent.depth = 0;
14558 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01269);
14559 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
14560 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
14561 m_errorMonitor->VerifyFound();
14562
14563 region.imageExtent.depth = 1;
14564
14565 // Image must have offset.z of 0 and extent.depth of 1
14566 // Introduce failure by setting imageOffset.z to 4
14567 region.imageOffset.z = 4;
14568 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01269);
14569 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
14570 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
14571 m_errorMonitor->VerifyFound();
14572
14573 region.imageOffset.z = 0;
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060014574 // BufferOffset must be a multiple of the calling command's VkImage parameter's texel size
14575 // Introduce failure by setting bufferOffset to 1 and 1/2 texels
14576 region.bufferOffset = 6;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070014577 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01263);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014578 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
14579 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060014580 m_errorMonitor->VerifyFound();
14581
14582 // BufferOffset must be a multiple of 4
14583 // Introduce failure by setting bufferOffset to a value not divisible by 4
14584 region.bufferOffset = 6;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070014585 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01264);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014586 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
14587 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060014588 m_errorMonitor->VerifyFound();
14589
14590 // BufferRowLength must be 0, or greater than or equal to the width member of imageExtent
14591 region.bufferOffset = 0;
14592 region.imageExtent.height = 128;
14593 region.imageExtent.width = 128;
14594 // Introduce failure by setting bufferRowLength > 0 but less than width
14595 region.bufferRowLength = 64;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070014596 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01265);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014597 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
14598 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060014599 m_errorMonitor->VerifyFound();
14600
14601 // BufferImageHeight must be 0, or greater than or equal to the height member of imageExtent
14602 region.bufferRowLength = 128;
14603 // Introduce failure by setting bufferRowHeight > 0 but less than height
14604 region.bufferImageHeight = 64;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070014605 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01266);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014606 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
14607 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060014608 m_errorMonitor->VerifyFound();
14609
14610 region.bufferImageHeight = 128;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014611 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14612 "If the format of srcImage is a depth, stencil, depth stencil or "
14613 "integer-based format then filter must be VK_FILTER_NEAREST");
Tony Barbourd6673642016-05-05 14:46:39 -060014614 // Expect INVALID_FILTER
14615 VkImageObj intImage1(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014616 intImage1.init(128, 128, VK_FORMAT_R8_UINT, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
Tony Barbourd6673642016-05-05 14:46:39 -060014617 VkImageObj intImage2(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014618 intImage2.init(128, 128, VK_FORMAT_R8_UINT, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
Tony Barbourd6673642016-05-05 14:46:39 -060014619 VkImageBlit blitRegion = {};
14620 blitRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14621 blitRegion.srcSubresource.baseArrayLayer = 0;
14622 blitRegion.srcSubresource.layerCount = 1;
14623 blitRegion.srcSubresource.mipLevel = 0;
14624 blitRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14625 blitRegion.dstSubresource.baseArrayLayer = 0;
14626 blitRegion.dstSubresource.layerCount = 1;
14627 blitRegion.dstSubresource.mipLevel = 0;
14628
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014629 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), intImage1.handle(), intImage1.layout(), intImage2.handle(),
14630 intImage2.layout(), 16, &blitRegion, VK_FILTER_LINEAR);
Tony Barbourd6673642016-05-05 14:46:39 -060014631 m_errorMonitor->VerifyFound();
14632
Mark Lobodzinskib02ea642016-08-17 13:03:57 -060014633 // Look for NULL-blit warning
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014634 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "Offsets specify a zero-volume area.");
14635 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), intImage1.handle(), intImage1.layout(), intImage2.handle(),
14636 intImage2.layout(), 1, &blitRegion, VK_FILTER_LINEAR);
Mark Lobodzinskib02ea642016-08-17 13:03:57 -060014637 m_errorMonitor->VerifyFound();
14638
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014639 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with 0 in ppMemoryBarriers");
Tony Barbourd6673642016-05-05 14:46:39 -060014640 VkImageMemoryBarrier img_barrier;
14641 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
14642 img_barrier.pNext = NULL;
14643 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
14644 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
14645 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
14646 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
14647 img_barrier.image = image.handle();
14648 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
14649 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
14650 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14651 img_barrier.subresourceRange.baseArrayLayer = 0;
14652 img_barrier.subresourceRange.baseMipLevel = 0;
14653 // layerCount should not be 0 - Expect INVALID_IMAGE_RESOURCE
14654 img_barrier.subresourceRange.layerCount = 0;
14655 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014656 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
14657 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbourd6673642016-05-05 14:46:39 -060014658 m_errorMonitor->VerifyFound();
14659 img_barrier.subresourceRange.layerCount = 1;
14660}
14661
14662TEST_F(VkLayerTest, ImageFormatLimits) {
14663
14664 TEST_DESCRIPTION("Exceed the limits of image format ");
14665
Cody Northropc31a84f2016-08-22 10:41:47 -060014666 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014667 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "CreateImage extents exceed allowable limits for format");
Tony Barbourd6673642016-05-05 14:46:39 -060014668 VkImageCreateInfo image_create_info = {};
14669 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14670 image_create_info.pNext = NULL;
14671 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14672 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
14673 image_create_info.extent.width = 32;
14674 image_create_info.extent.height = 32;
14675 image_create_info.extent.depth = 1;
14676 image_create_info.mipLevels = 1;
14677 image_create_info.arrayLayers = 1;
14678 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14679 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
14680 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
14681 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
14682 image_create_info.flags = 0;
14683
14684 VkImage nullImg;
14685 VkImageFormatProperties imgFmtProps;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014686 vkGetPhysicalDeviceImageFormatProperties(gpu(), image_create_info.format, image_create_info.imageType, image_create_info.tiling,
14687 image_create_info.usage, image_create_info.flags, &imgFmtProps);
Tony Barbourd6673642016-05-05 14:46:39 -060014688 image_create_info.extent.depth = imgFmtProps.maxExtent.depth + 1;
14689 // Expect INVALID_FORMAT_LIMITS_VIOLATION
14690 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
14691 m_errorMonitor->VerifyFound();
14692 image_create_info.extent.depth = 1;
14693
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014694 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "exceeds allowable maximum supported by format of");
Tony Barbourd6673642016-05-05 14:46:39 -060014695 image_create_info.mipLevels = imgFmtProps.maxMipLevels + 1;
14696 // Expect INVALID_FORMAT_LIMITS_VIOLATION
14697 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
14698 m_errorMonitor->VerifyFound();
14699 image_create_info.mipLevels = 1;
14700
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014701 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "exceeds allowable maximum supported by format of");
Tony Barbourd6673642016-05-05 14:46:39 -060014702 image_create_info.arrayLayers = imgFmtProps.maxArrayLayers + 1;
14703 // Expect INVALID_FORMAT_LIMITS_VIOLATION
14704 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
14705 m_errorMonitor->VerifyFound();
14706 image_create_info.arrayLayers = 1;
14707
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014708 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is not supported by format");
Tony Barbourd6673642016-05-05 14:46:39 -060014709 int samples = imgFmtProps.sampleCounts >> 1;
14710 image_create_info.samples = (VkSampleCountFlagBits)samples;
14711 // Expect INVALID_FORMAT_LIMITS_VIOLATION
14712 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
14713 m_errorMonitor->VerifyFound();
14714 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14715
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014716 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "pCreateInfo->initialLayout, must be "
14717 "VK_IMAGE_LAYOUT_UNDEFINED or "
14718 "VK_IMAGE_LAYOUT_PREINITIALIZED");
Tony Barbourd6673642016-05-05 14:46:39 -060014719 image_create_info.initialLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
14720 // Expect INVALID_LAYOUT
14721 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
14722 m_errorMonitor->VerifyFound();
14723 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
14724}
14725
Mark Lobodzinskicea14992016-10-14 10:59:42 -060014726TEST_F(VkLayerTest, CopyImageSrcSizeExceeded) {
14727
14728 // Image copy with source region specified greater than src image size
Mark Lobodzinski629d47b2016-10-18 13:34:58 -060014729 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01175);
Mark Lobodzinskicea14992016-10-14 10:59:42 -060014730
14731 ASSERT_NO_FATAL_FAILURE(InitState());
14732
14733 VkImageObj src_image(m_device);
14734 src_image.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_LINEAR, 0);
14735 VkImageObj dst_image(m_device);
14736 dst_image.init(64, 64, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
14737
14738 BeginCommandBuffer();
14739 VkImageCopy copy_region;
14740 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14741 copy_region.srcSubresource.mipLevel = 0;
14742 copy_region.srcSubresource.baseArrayLayer = 0;
14743 copy_region.srcSubresource.layerCount = 0;
14744 copy_region.srcOffset.x = 0;
14745 copy_region.srcOffset.y = 0;
14746 copy_region.srcOffset.z = 0;
14747 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14748 copy_region.dstSubresource.mipLevel = 0;
14749 copy_region.dstSubresource.baseArrayLayer = 0;
14750 copy_region.dstSubresource.layerCount = 0;
14751 copy_region.dstOffset.x = 0;
14752 copy_region.dstOffset.y = 0;
14753 copy_region.dstOffset.z = 0;
14754 copy_region.extent.width = 64;
14755 copy_region.extent.height = 64;
14756 copy_region.extent.depth = 1;
14757 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
14758 &copy_region);
14759 EndCommandBuffer();
14760
14761 m_errorMonitor->VerifyFound();
14762}
14763
14764TEST_F(VkLayerTest, CopyImageDstSizeExceeded) {
14765
14766 // Image copy with dest region specified greater than dest image size
Mark Lobodzinski629d47b2016-10-18 13:34:58 -060014767 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01176);
Mark Lobodzinskicea14992016-10-14 10:59:42 -060014768
14769 ASSERT_NO_FATAL_FAILURE(InitState());
14770
14771 VkImageObj src_image(m_device);
14772 src_image.init(64, 64, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_LINEAR, 0);
14773 VkImageObj dst_image(m_device);
14774 dst_image.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
14775
14776 BeginCommandBuffer();
14777 VkImageCopy copy_region;
14778 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14779 copy_region.srcSubresource.mipLevel = 0;
14780 copy_region.srcSubresource.baseArrayLayer = 0;
14781 copy_region.srcSubresource.layerCount = 0;
14782 copy_region.srcOffset.x = 0;
14783 copy_region.srcOffset.y = 0;
14784 copy_region.srcOffset.z = 0;
14785 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14786 copy_region.dstSubresource.mipLevel = 0;
14787 copy_region.dstSubresource.baseArrayLayer = 0;
14788 copy_region.dstSubresource.layerCount = 0;
14789 copy_region.dstOffset.x = 0;
14790 copy_region.dstOffset.y = 0;
14791 copy_region.dstOffset.z = 0;
14792 copy_region.extent.width = 64;
14793 copy_region.extent.height = 64;
14794 copy_region.extent.depth = 1;
14795 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
14796 &copy_region);
14797 EndCommandBuffer();
14798
14799 m_errorMonitor->VerifyFound();
14800}
14801
Karl Schultz6addd812016-02-02 17:17:23 -070014802TEST_F(VkLayerTest, CopyImageFormatSizeMismatch) {
Karl Schultzbdb75952016-04-19 11:36:49 -060014803 VkResult err;
14804 bool pass;
14805
14806 // Create color images with different format sizes and try to copy between them
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014807 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14808 "vkCmdCopyImage called with unmatched source and dest image format sizes");
Karl Schultzbdb75952016-04-19 11:36:49 -060014809
14810 ASSERT_NO_FATAL_FAILURE(InitState());
14811
14812 // Create two images of different types and try to copy between them
14813 VkImage srcImage;
14814 VkImage dstImage;
14815 VkDeviceMemory srcMem;
14816 VkDeviceMemory destMem;
14817 VkMemoryRequirements memReqs;
14818
14819 VkImageCreateInfo image_create_info = {};
14820 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14821 image_create_info.pNext = NULL;
14822 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14823 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
14824 image_create_info.extent.width = 32;
14825 image_create_info.extent.height = 32;
14826 image_create_info.extent.depth = 1;
14827 image_create_info.mipLevels = 1;
14828 image_create_info.arrayLayers = 1;
14829 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14830 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
14831 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
14832 image_create_info.flags = 0;
14833
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014834 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Karl Schultzbdb75952016-04-19 11:36:49 -060014835 ASSERT_VK_SUCCESS(err);
14836
14837 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
14838 // Introduce failure by creating second image with a different-sized format.
14839 image_create_info.format = VK_FORMAT_R5G5B5A1_UNORM_PACK16;
14840
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014841 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Karl Schultzbdb75952016-04-19 11:36:49 -060014842 ASSERT_VK_SUCCESS(err);
14843
14844 // Allocate memory
14845 VkMemoryAllocateInfo memAlloc = {};
14846 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
14847 memAlloc.pNext = NULL;
14848 memAlloc.allocationSize = 0;
14849 memAlloc.memoryTypeIndex = 0;
14850
14851 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
14852 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014853 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -060014854 ASSERT_TRUE(pass);
14855 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
14856 ASSERT_VK_SUCCESS(err);
14857
14858 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
14859 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014860 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -060014861 ASSERT_TRUE(pass);
14862 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
14863 ASSERT_VK_SUCCESS(err);
14864
14865 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
14866 ASSERT_VK_SUCCESS(err);
14867 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
14868 ASSERT_VK_SUCCESS(err);
14869
14870 BeginCommandBuffer();
14871 VkImageCopy copyRegion;
14872 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14873 copyRegion.srcSubresource.mipLevel = 0;
14874 copyRegion.srcSubresource.baseArrayLayer = 0;
14875 copyRegion.srcSubresource.layerCount = 0;
14876 copyRegion.srcOffset.x = 0;
14877 copyRegion.srcOffset.y = 0;
14878 copyRegion.srcOffset.z = 0;
14879 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14880 copyRegion.dstSubresource.mipLevel = 0;
14881 copyRegion.dstSubresource.baseArrayLayer = 0;
14882 copyRegion.dstSubresource.layerCount = 0;
14883 copyRegion.dstOffset.x = 0;
14884 copyRegion.dstOffset.y = 0;
14885 copyRegion.dstOffset.z = 0;
14886 copyRegion.extent.width = 1;
14887 copyRegion.extent.height = 1;
14888 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014889 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Karl Schultzbdb75952016-04-19 11:36:49 -060014890 EndCommandBuffer();
14891
14892 m_errorMonitor->VerifyFound();
14893
14894 vkDestroyImage(m_device->device(), srcImage, NULL);
14895 vkDestroyImage(m_device->device(), dstImage, NULL);
14896 vkFreeMemory(m_device->device(), srcMem, NULL);
14897 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060014898}
14899
Karl Schultz6addd812016-02-02 17:17:23 -070014900TEST_F(VkLayerTest, CopyImageDepthStencilFormatMismatch) {
14901 VkResult err;
14902 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060014903
Mark Lobodzinskidb117632016-03-31 10:45:56 -060014904 // Create a color image and a depth/stencil image and try to copy between them
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014905 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14906 "vkCmdCopyImage called with unmatched source and dest image depth");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014907
Mike Stroyana3082432015-09-25 13:39:21 -060014908 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060014909
14910 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070014911 VkImage srcImage;
14912 VkImage dstImage;
14913 VkDeviceMemory srcMem;
14914 VkDeviceMemory destMem;
14915 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060014916
14917 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014918 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14919 image_create_info.pNext = NULL;
14920 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14921 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
14922 image_create_info.extent.width = 32;
14923 image_create_info.extent.height = 32;
14924 image_create_info.extent.depth = 1;
14925 image_create_info.mipLevels = 1;
14926 image_create_info.arrayLayers = 1;
14927 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14928 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
14929 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
14930 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014931
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014932 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014933 ASSERT_VK_SUCCESS(err);
14934
Karl Schultzbdb75952016-04-19 11:36:49 -060014935 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
14936
Mark Lobodzinskidb117632016-03-31 10:45:56 -060014937 // Introduce failure by creating second image with a depth/stencil format
Karl Schultz6addd812016-02-02 17:17:23 -070014938 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060014939 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
Mark Lobodzinski867787a2016-10-14 11:49:55 -060014940 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014941
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014942 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014943 ASSERT_VK_SUCCESS(err);
14944
14945 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014946 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014947 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
14948 memAlloc.pNext = NULL;
14949 memAlloc.allocationSize = 0;
14950 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014951
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060014952 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014953 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014954 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014955 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014956 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014957 ASSERT_VK_SUCCESS(err);
14958
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014959 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014960 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014961 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014962 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014963 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014964 ASSERT_VK_SUCCESS(err);
14965
14966 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
14967 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014968 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060014969 ASSERT_VK_SUCCESS(err);
14970
14971 BeginCommandBuffer();
14972 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014973 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014974 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060014975 copyRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014976 copyRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014977 copyRegion.srcOffset.x = 0;
14978 copyRegion.srcOffset.y = 0;
14979 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014980 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014981 copyRegion.dstSubresource.mipLevel = 0;
14982 copyRegion.dstSubresource.baseArrayLayer = 0;
14983 copyRegion.dstSubresource.layerCount = 0;
14984 copyRegion.dstOffset.x = 0;
14985 copyRegion.dstOffset.y = 0;
14986 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014987 copyRegion.extent.width = 1;
14988 copyRegion.extent.height = 1;
14989 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014990 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060014991 EndCommandBuffer();
14992
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014993 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060014994
Chia-I Wuf7458c52015-10-26 21:10:41 +080014995 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014996 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080014997 vkFreeMemory(m_device->device(), srcMem, NULL);
14998 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060014999}
15000
Karl Schultz6addd812016-02-02 17:17:23 -070015001TEST_F(VkLayerTest, ResolveImageLowSampleCount) {
15002 VkResult err;
15003 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060015004
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015005 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15006 "vkCmdResolveImage called with source sample count less than 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015007
Mike Stroyana3082432015-09-25 13:39:21 -060015008 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060015009
15010 // Create two images of sample count 1 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070015011 VkImage srcImage;
15012 VkImage dstImage;
15013 VkDeviceMemory srcMem;
15014 VkDeviceMemory destMem;
15015 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060015016
15017 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015018 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15019 image_create_info.pNext = NULL;
15020 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15021 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
15022 image_create_info.extent.width = 32;
15023 image_create_info.extent.height = 1;
15024 image_create_info.extent.depth = 1;
15025 image_create_info.mipLevels = 1;
15026 image_create_info.arrayLayers = 1;
15027 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15028 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15029 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
15030 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015031
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015032 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015033 ASSERT_VK_SUCCESS(err);
15034
Karl Schultz6addd812016-02-02 17:17:23 -070015035 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015036
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015037 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015038 ASSERT_VK_SUCCESS(err);
15039
15040 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015041 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015042 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15043 memAlloc.pNext = NULL;
15044 memAlloc.allocationSize = 0;
15045 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015046
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060015047 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015048 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015049 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015050 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015051 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015052 ASSERT_VK_SUCCESS(err);
15053
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015054 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015055 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015056 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015057 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015058 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015059 ASSERT_VK_SUCCESS(err);
15060
15061 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
15062 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015063 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060015064 ASSERT_VK_SUCCESS(err);
15065
15066 BeginCommandBuffer();
15067 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070015068 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
15069 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060015070 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015071 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015072 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060015073 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130015074 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060015075 resolveRegion.srcOffset.x = 0;
15076 resolveRegion.srcOffset.y = 0;
15077 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015078 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015079 resolveRegion.dstSubresource.mipLevel = 0;
15080 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130015081 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015082 resolveRegion.dstOffset.x = 0;
15083 resolveRegion.dstOffset.y = 0;
15084 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015085 resolveRegion.extent.width = 1;
15086 resolveRegion.extent.height = 1;
15087 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015088 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060015089 EndCommandBuffer();
15090
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015091 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060015092
Chia-I Wuf7458c52015-10-26 21:10:41 +080015093 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015094 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080015095 vkFreeMemory(m_device->device(), srcMem, NULL);
15096 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060015097}
15098
Karl Schultz6addd812016-02-02 17:17:23 -070015099TEST_F(VkLayerTest, ResolveImageHighSampleCount) {
15100 VkResult err;
15101 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060015102
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015103 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15104 "vkCmdResolveImage called with dest sample count greater than 1.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015105
Mike Stroyana3082432015-09-25 13:39:21 -060015106 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060015107
Chris Forbesa7530692016-05-08 12:35:39 +120015108 // Create two images of sample count 4 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070015109 VkImage srcImage;
15110 VkImage dstImage;
15111 VkDeviceMemory srcMem;
15112 VkDeviceMemory destMem;
15113 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060015114
15115 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015116 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15117 image_create_info.pNext = NULL;
15118 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15119 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
15120 image_create_info.extent.width = 32;
15121 image_create_info.extent.height = 1;
15122 image_create_info.extent.depth = 1;
15123 image_create_info.mipLevels = 1;
15124 image_create_info.arrayLayers = 1;
Chris Forbesa7530692016-05-08 12:35:39 +120015125 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070015126 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15127 // Note: Some implementations expect color attachment usage for any
15128 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015129 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070015130 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015131
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015132 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015133 ASSERT_VK_SUCCESS(err);
15134
Karl Schultz6addd812016-02-02 17:17:23 -070015135 // Note: Some implementations expect color attachment usage for any
15136 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015137 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015138
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015139 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015140 ASSERT_VK_SUCCESS(err);
15141
15142 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015143 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015144 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15145 memAlloc.pNext = NULL;
15146 memAlloc.allocationSize = 0;
15147 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015148
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060015149 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015150 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015151 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015152 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015153 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015154 ASSERT_VK_SUCCESS(err);
15155
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015156 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015157 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015158 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015159 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015160 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015161 ASSERT_VK_SUCCESS(err);
15162
15163 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
15164 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015165 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060015166 ASSERT_VK_SUCCESS(err);
15167
15168 BeginCommandBuffer();
15169 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070015170 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
15171 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060015172 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015173 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015174 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060015175 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130015176 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060015177 resolveRegion.srcOffset.x = 0;
15178 resolveRegion.srcOffset.y = 0;
15179 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015180 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015181 resolveRegion.dstSubresource.mipLevel = 0;
15182 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130015183 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015184 resolveRegion.dstOffset.x = 0;
15185 resolveRegion.dstOffset.y = 0;
15186 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015187 resolveRegion.extent.width = 1;
15188 resolveRegion.extent.height = 1;
15189 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015190 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060015191 EndCommandBuffer();
15192
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015193 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060015194
Chia-I Wuf7458c52015-10-26 21:10:41 +080015195 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015196 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080015197 vkFreeMemory(m_device->device(), srcMem, NULL);
15198 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060015199}
15200
Karl Schultz6addd812016-02-02 17:17:23 -070015201TEST_F(VkLayerTest, ResolveImageFormatMismatch) {
15202 VkResult err;
15203 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060015204
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015205 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15206 "vkCmdResolveImage called with unmatched source and dest formats.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015207
Mike Stroyana3082432015-09-25 13:39:21 -060015208 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060015209
15210 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070015211 VkImage srcImage;
15212 VkImage dstImage;
15213 VkDeviceMemory srcMem;
15214 VkDeviceMemory destMem;
15215 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060015216
15217 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015218 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15219 image_create_info.pNext = NULL;
15220 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15221 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
15222 image_create_info.extent.width = 32;
15223 image_create_info.extent.height = 1;
15224 image_create_info.extent.depth = 1;
15225 image_create_info.mipLevels = 1;
15226 image_create_info.arrayLayers = 1;
15227 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
15228 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15229 // Note: Some implementations expect color attachment usage for any
15230 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015231 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070015232 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015233
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015234 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015235 ASSERT_VK_SUCCESS(err);
15236
Karl Schultz6addd812016-02-02 17:17:23 -070015237 // Set format to something other than source image
15238 image_create_info.format = VK_FORMAT_R32_SFLOAT;
15239 // Note: Some implementations expect color attachment usage for any
15240 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015241 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070015242 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015243
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015244 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015245 ASSERT_VK_SUCCESS(err);
15246
15247 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015248 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015249 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15250 memAlloc.pNext = NULL;
15251 memAlloc.allocationSize = 0;
15252 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015253
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060015254 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015255 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015256 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015257 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015258 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015259 ASSERT_VK_SUCCESS(err);
15260
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015261 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015262 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015263 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015264 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015265 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015266 ASSERT_VK_SUCCESS(err);
15267
15268 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
15269 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015270 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060015271 ASSERT_VK_SUCCESS(err);
15272
15273 BeginCommandBuffer();
15274 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070015275 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
15276 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060015277 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015278 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015279 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060015280 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130015281 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060015282 resolveRegion.srcOffset.x = 0;
15283 resolveRegion.srcOffset.y = 0;
15284 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015285 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015286 resolveRegion.dstSubresource.mipLevel = 0;
15287 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130015288 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015289 resolveRegion.dstOffset.x = 0;
15290 resolveRegion.dstOffset.y = 0;
15291 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015292 resolveRegion.extent.width = 1;
15293 resolveRegion.extent.height = 1;
15294 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015295 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060015296 EndCommandBuffer();
15297
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015298 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060015299
Chia-I Wuf7458c52015-10-26 21:10:41 +080015300 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015301 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080015302 vkFreeMemory(m_device->device(), srcMem, NULL);
15303 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060015304}
15305
Karl Schultz6addd812016-02-02 17:17:23 -070015306TEST_F(VkLayerTest, ResolveImageTypeMismatch) {
15307 VkResult err;
15308 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060015309
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015310 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15311 "vkCmdResolveImage called with unmatched source and dest image types.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015312
Mike Stroyana3082432015-09-25 13:39:21 -060015313 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060015314
15315 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070015316 VkImage srcImage;
15317 VkImage dstImage;
15318 VkDeviceMemory srcMem;
15319 VkDeviceMemory destMem;
15320 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060015321
15322 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015323 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15324 image_create_info.pNext = NULL;
15325 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15326 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
15327 image_create_info.extent.width = 32;
15328 image_create_info.extent.height = 1;
15329 image_create_info.extent.depth = 1;
15330 image_create_info.mipLevels = 1;
15331 image_create_info.arrayLayers = 1;
15332 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
15333 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15334 // Note: Some implementations expect color attachment usage for any
15335 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015336 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070015337 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015338
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015339 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015340 ASSERT_VK_SUCCESS(err);
15341
Karl Schultz6addd812016-02-02 17:17:23 -070015342 image_create_info.imageType = VK_IMAGE_TYPE_1D;
15343 // Note: Some implementations expect color attachment usage for any
15344 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015345 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070015346 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015347
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015348 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015349 ASSERT_VK_SUCCESS(err);
15350
15351 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015352 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015353 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15354 memAlloc.pNext = NULL;
15355 memAlloc.allocationSize = 0;
15356 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015357
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060015358 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015359 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015360 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015361 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015362 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015363 ASSERT_VK_SUCCESS(err);
15364
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015365 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015366 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015367 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015368 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015369 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015370 ASSERT_VK_SUCCESS(err);
15371
15372 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
15373 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015374 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060015375 ASSERT_VK_SUCCESS(err);
15376
15377 BeginCommandBuffer();
15378 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070015379 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
15380 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060015381 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015382 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015383 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060015384 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130015385 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060015386 resolveRegion.srcOffset.x = 0;
15387 resolveRegion.srcOffset.y = 0;
15388 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015389 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015390 resolveRegion.dstSubresource.mipLevel = 0;
15391 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130015392 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015393 resolveRegion.dstOffset.x = 0;
15394 resolveRegion.dstOffset.y = 0;
15395 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015396 resolveRegion.extent.width = 1;
15397 resolveRegion.extent.height = 1;
15398 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015399 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060015400 EndCommandBuffer();
15401
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015402 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060015403
Chia-I Wuf7458c52015-10-26 21:10:41 +080015404 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015405 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080015406 vkFreeMemory(m_device->device(), srcMem, NULL);
15407 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060015408}
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015409
Karl Schultz6addd812016-02-02 17:17:23 -070015410TEST_F(VkLayerTest, DepthStencilImageViewWithColorAspectBitError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015411 // Create a single Image descriptor and cause it to first hit an error due
Karl Schultz6addd812016-02-02 17:17:23 -070015412 // to using a DS format, then cause it to hit error due to COLOR_BIT not
15413 // set in aspect
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015414 // The image format check comes 2nd in validation so we trigger it first,
15415 // then when we cause aspect fail next, bad format check will be preempted
Karl Schultz6addd812016-02-02 17:17:23 -070015416 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015417
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015418 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15419 "Combination depth/stencil image formats can have only the ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015420
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015421 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015422
Chia-I Wu1b99bb22015-10-27 19:25:11 +080015423 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015424 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
15425 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015426
15427 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015428 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
15429 ds_pool_ci.pNext = NULL;
15430 ds_pool_ci.maxSets = 1;
15431 ds_pool_ci.poolSizeCount = 1;
15432 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015433
15434 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015435 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015436 ASSERT_VK_SUCCESS(err);
15437
15438 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015439 dsl_binding.binding = 0;
15440 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
15441 dsl_binding.descriptorCount = 1;
15442 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
15443 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015444
15445 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015446 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
15447 ds_layout_ci.pNext = NULL;
15448 ds_layout_ci.bindingCount = 1;
15449 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015450 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015451 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015452 ASSERT_VK_SUCCESS(err);
15453
15454 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015455 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080015456 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070015457 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015458 alloc_info.descriptorPool = ds_pool;
15459 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015460 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015461 ASSERT_VK_SUCCESS(err);
15462
Karl Schultz6addd812016-02-02 17:17:23 -070015463 VkImage image_bad;
15464 VkImage image_good;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015465 // One bad format and one good format for Color attachment
Tobin Ehlis269f0322016-05-25 16:24:21 -060015466 const VkFormat tex_format_bad = VK_FORMAT_D24_UNORM_S8_UINT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015467 const VkFormat tex_format_good = VK_FORMAT_B8G8R8A8_UNORM;
Karl Schultz6addd812016-02-02 17:17:23 -070015468 const int32_t tex_width = 32;
15469 const int32_t tex_height = 32;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015470
15471 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015472 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15473 image_create_info.pNext = NULL;
15474 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15475 image_create_info.format = tex_format_bad;
15476 image_create_info.extent.width = tex_width;
15477 image_create_info.extent.height = tex_height;
15478 image_create_info.extent.depth = 1;
15479 image_create_info.mipLevels = 1;
15480 image_create_info.arrayLayers = 1;
15481 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15482 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015483 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070015484 image_create_info.flags = 0;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015485
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015486 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_bad);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015487 ASSERT_VK_SUCCESS(err);
15488 image_create_info.format = tex_format_good;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015489 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
15490 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_good);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015491 ASSERT_VK_SUCCESS(err);
15492
15493 VkImageViewCreateInfo image_view_create_info = {};
Chris Forbes53bef902016-11-28 17:53:04 +130015494 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070015495 image_view_create_info.image = image_bad;
15496 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
15497 image_view_create_info.format = tex_format_bad;
15498 image_view_create_info.subresourceRange.baseArrayLayer = 0;
15499 image_view_create_info.subresourceRange.baseMipLevel = 0;
15500 image_view_create_info.subresourceRange.layerCount = 1;
15501 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015502 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015503
15504 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015505 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015506
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015507 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015508
Chia-I Wuf7458c52015-10-26 21:10:41 +080015509 vkDestroyImage(m_device->device(), image_bad, NULL);
15510 vkDestroyImage(m_device->device(), image_good, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080015511 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
15512 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015513}
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015514
15515TEST_F(VkLayerTest, ClearImageErrors) {
15516 TEST_DESCRIPTION("Call ClearColorImage w/ a depth|stencil image and "
15517 "ClearDepthStencilImage with a color image.");
15518
15519 ASSERT_NO_FATAL_FAILURE(InitState());
15520 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15521
15522 // Renderpass is started here so end it as Clear cmds can't be in renderpass
15523 BeginCommandBuffer();
15524 m_commandBuffer->EndRenderPass();
15525
15526 // Color image
15527 VkClearColorValue clear_color;
15528 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
15529 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
15530 const VkFormat color_format = VK_FORMAT_B8G8R8A8_UNORM;
15531 const int32_t img_width = 32;
15532 const int32_t img_height = 32;
15533 VkImageCreateInfo image_create_info = {};
15534 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15535 image_create_info.pNext = NULL;
15536 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15537 image_create_info.format = color_format;
15538 image_create_info.extent.width = img_width;
15539 image_create_info.extent.height = img_height;
15540 image_create_info.extent.depth = 1;
15541 image_create_info.mipLevels = 1;
15542 image_create_info.arrayLayers = 1;
15543 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15544 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15545 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
15546
15547 vk_testing::Image color_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015548 color_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015549
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015550 const VkImageSubresourceRange color_range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015551
15552 // Depth/Stencil image
15553 VkClearDepthStencilValue clear_value = {0};
15554 reqs = 0; // don't need HOST_VISIBLE DS image
15555 VkImageCreateInfo ds_image_create_info = vk_testing::Image::create_info();
15556 ds_image_create_info.imageType = VK_IMAGE_TYPE_2D;
15557 ds_image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
15558 ds_image_create_info.extent.width = 64;
15559 ds_image_create_info.extent.height = 64;
15560 ds_image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15561 ds_image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
15562
15563 vk_testing::Image ds_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015564 ds_image.init(*m_device, (const VkImageCreateInfo &)ds_image_create_info, reqs);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015565
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015566 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 -060015567
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015568 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdClearColorImage called with depth/stencil image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015569
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015570 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), ds_image.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015571 &color_range);
15572
15573 m_errorMonitor->VerifyFound();
15574
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015575 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdClearColorImage called with "
15576 "image created without "
15577 "VK_IMAGE_USAGE_TRANSFER_DST_BIT");
Tony Barbour26434b92016-06-02 09:43:50 -060015578
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015579 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), ds_image.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
Tony Barbour26434b92016-06-02 09:43:50 -060015580 &color_range);
15581
15582 m_errorMonitor->VerifyFound();
15583
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015584 // Call CmdClearDepthStencilImage with color image
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015585 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15586 "vkCmdClearDepthStencilImage called without a depth/stencil image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015587
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015588 vkCmdClearDepthStencilImage(m_commandBuffer->GetBufferHandle(), color_image.handle(),
15589 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, &clear_value, 1, &ds_range);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015590
15591 m_errorMonitor->VerifyFound();
15592}
Tobin Ehliscde08892015-09-22 10:11:37 -060015593#endif // IMAGE_TESTS
15594
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060015595
15596// WSI Enabled Tests
15597//
Chris Forbes09368e42016-10-13 11:59:22 +130015598#if 0
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060015599TEST_F(VkWsiEnabledLayerTest, TestEnabledWsi) {
15600
15601#if defined(VK_USE_PLATFORM_XCB_KHR)
15602 VkSurfaceKHR surface = VK_NULL_HANDLE;
15603
15604 VkResult err;
15605 bool pass;
15606 VkSwapchainKHR swapchain = VK_NULL_HANDLE;
15607 VkSwapchainCreateInfoKHR swapchain_create_info = {};
15608 // uint32_t swapchain_image_count = 0;
15609 // VkImage swapchain_images[1] = {VK_NULL_HANDLE};
15610 // uint32_t image_index = 0;
15611 // VkPresentInfoKHR present_info = {};
15612
15613 ASSERT_NO_FATAL_FAILURE(InitState());
15614
15615 // Use the create function from one of the VK_KHR_*_surface extension in
15616 // order to create a surface, testing all known errors in the process,
15617 // before successfully creating a surface:
15618 // First, try to create a surface without a VkXcbSurfaceCreateInfoKHR:
15619 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pCreateInfo specified as NULL");
15620 err = vkCreateXcbSurfaceKHR(instance(), NULL, NULL, &surface);
15621 pass = (err != VK_SUCCESS);
15622 ASSERT_TRUE(pass);
15623 m_errorMonitor->VerifyFound();
15624
15625 // Next, try to create a surface with the wrong
15626 // VkXcbSurfaceCreateInfoKHR::sType:
15627 VkXcbSurfaceCreateInfoKHR xcb_create_info = {};
15628 xcb_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
15629 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pCreateInfo->sType must be");
15630 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
15631 pass = (err != VK_SUCCESS);
15632 ASSERT_TRUE(pass);
15633 m_errorMonitor->VerifyFound();
15634
15635 // Create a native window, and then correctly create a surface:
15636 xcb_connection_t *connection;
15637 xcb_screen_t *screen;
15638 xcb_window_t xcb_window;
15639 xcb_intern_atom_reply_t *atom_wm_delete_window;
15640
15641 const xcb_setup_t *setup;
15642 xcb_screen_iterator_t iter;
15643 int scr;
15644 uint32_t value_mask, value_list[32];
15645 int width = 1;
15646 int height = 1;
15647
15648 connection = xcb_connect(NULL, &scr);
15649 ASSERT_TRUE(connection != NULL);
15650 setup = xcb_get_setup(connection);
15651 iter = xcb_setup_roots_iterator(setup);
15652 while (scr-- > 0)
15653 xcb_screen_next(&iter);
15654 screen = iter.data;
15655
15656 xcb_window = xcb_generate_id(connection);
15657
15658 value_mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK;
15659 value_list[0] = screen->black_pixel;
15660 value_list[1] = XCB_EVENT_MASK_KEY_RELEASE | XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_STRUCTURE_NOTIFY;
15661
15662 xcb_create_window(connection, XCB_COPY_FROM_PARENT, xcb_window, screen->root, 0, 0, width, height, 0,
15663 XCB_WINDOW_CLASS_INPUT_OUTPUT, screen->root_visual, value_mask, value_list);
15664
15665 /* Magic code that will send notification when window is destroyed */
15666 xcb_intern_atom_cookie_t cookie = xcb_intern_atom(connection, 1, 12, "WM_PROTOCOLS");
15667 xcb_intern_atom_reply_t *reply = xcb_intern_atom_reply(connection, cookie, 0);
15668
15669 xcb_intern_atom_cookie_t cookie2 = xcb_intern_atom(connection, 0, 16, "WM_DELETE_WINDOW");
15670 atom_wm_delete_window = xcb_intern_atom_reply(connection, cookie2, 0);
15671 xcb_change_property(connection, XCB_PROP_MODE_REPLACE, xcb_window, (*reply).atom, 4, 32, 1, &(*atom_wm_delete_window).atom);
15672 free(reply);
15673
15674 xcb_map_window(connection, xcb_window);
15675
15676 // Force the x/y coordinates to 100,100 results are identical in consecutive
15677 // runs
15678 const uint32_t coords[] = { 100, 100 };
15679 xcb_configure_window(connection, xcb_window, XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y, coords);
15680
15681 // Finally, try to correctly create a surface:
15682 xcb_create_info.sType = VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR;
15683 xcb_create_info.pNext = NULL;
15684 xcb_create_info.flags = 0;
15685 xcb_create_info.connection = connection;
15686 xcb_create_info.window = xcb_window;
15687 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
15688 pass = (err == VK_SUCCESS);
15689 ASSERT_TRUE(pass);
15690
15691 // Check if surface supports presentation:
15692
15693 // 1st, do so without having queried the queue families:
15694 VkBool32 supported = false;
15695 // TODO: Get the following error to come out:
15696 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15697 "called before calling the vkGetPhysicalDeviceQueueFamilyProperties "
15698 "function");
15699 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
15700 pass = (err != VK_SUCCESS);
15701 // ASSERT_TRUE(pass);
15702 // m_errorMonitor->VerifyFound();
15703
15704 // Next, query a queue family index that's too large:
15705 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with a queueFamilyIndex that is too large");
15706 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 100000, surface, &supported);
15707 pass = (err != VK_SUCCESS);
15708 ASSERT_TRUE(pass);
15709 m_errorMonitor->VerifyFound();
15710
15711 // Finally, do so correctly:
15712 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
15713 // SUPPORTED
15714 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
15715 pass = (err == VK_SUCCESS);
15716 ASSERT_TRUE(pass);
15717
15718 // Before proceeding, try to create a swapchain without having called
15719 // vkGetPhysicalDeviceSurfaceCapabilitiesKHR():
15720 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
15721 swapchain_create_info.pNext = NULL;
15722 swapchain_create_info.flags = 0;
15723 swapchain_create_info.imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
15724 swapchain_create_info.surface = surface;
15725 swapchain_create_info.imageArrayLayers = 1;
15726 swapchain_create_info.preTransform = VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR;
15727 swapchain_create_info.compositeAlpha = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR;
15728 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15729 "called before calling vkGetPhysicalDeviceSurfaceCapabilitiesKHR().");
15730 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
15731 pass = (err != VK_SUCCESS);
15732 ASSERT_TRUE(pass);
15733 m_errorMonitor->VerifyFound();
15734
15735 // Get the surface capabilities:
15736 VkSurfaceCapabilitiesKHR surface_capabilities;
15737
15738 // Do so correctly (only error logged by this entrypoint is if the
15739 // extension isn't enabled):
15740 err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), surface, &surface_capabilities);
15741 pass = (err == VK_SUCCESS);
15742 ASSERT_TRUE(pass);
15743
15744 // Get the surface formats:
15745 uint32_t surface_format_count;
15746
15747 // First, try without a pointer to surface_format_count:
15748 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pSurfaceFormatCount "
15749 "specified as NULL");
15750 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, NULL, NULL);
15751 pass = (err == VK_SUCCESS);
15752 ASSERT_TRUE(pass);
15753 m_errorMonitor->VerifyFound();
15754
15755 // Next, call with a non-NULL pSurfaceFormats, even though we haven't
15756 // correctly done a 1st try (to get the count):
15757 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "but no prior positive value has been seen for");
15758 surface_format_count = 0;
15759 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, (VkSurfaceFormatKHR *)&surface_format_count);
15760 pass = (err == VK_SUCCESS);
15761 ASSERT_TRUE(pass);
15762 m_errorMonitor->VerifyFound();
15763
15764 // Next, correctly do a 1st try (with a NULL pointer to surface_formats):
15765 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, NULL);
15766 pass = (err == VK_SUCCESS);
15767 ASSERT_TRUE(pass);
15768
15769 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
15770 VkSurfaceFormatKHR *surface_formats = (VkSurfaceFormatKHR *)malloc(surface_format_count * sizeof(VkSurfaceFormatKHR));
15771
15772 // Next, do a 2nd try with surface_format_count being set too high:
15773 surface_format_count += 5;
15774 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is greater than the value");
15775 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, surface_formats);
15776 pass = (err == VK_SUCCESS);
15777 ASSERT_TRUE(pass);
15778 m_errorMonitor->VerifyFound();
15779
15780 // Finally, do a correct 1st and 2nd try:
15781 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, NULL);
15782 pass = (err == VK_SUCCESS);
15783 ASSERT_TRUE(pass);
15784 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, surface_formats);
15785 pass = (err == VK_SUCCESS);
15786 ASSERT_TRUE(pass);
15787
15788 // Get the surface present modes:
15789 uint32_t surface_present_mode_count;
15790
15791 // First, try without a pointer to surface_format_count:
15792 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pPresentModeCount "
15793 "specified as NULL");
15794
15795 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, NULL, NULL);
15796 pass = (err == VK_SUCCESS);
15797 ASSERT_TRUE(pass);
15798 m_errorMonitor->VerifyFound();
15799
15800 // Next, call with a non-NULL VkPresentModeKHR, even though we haven't
15801 // correctly done a 1st try (to get the count):
15802 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "but no prior positive value has been seen for");
15803 surface_present_mode_count = 0;
15804 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count,
15805 (VkPresentModeKHR *)&surface_present_mode_count);
15806 pass = (err == VK_SUCCESS);
15807 ASSERT_TRUE(pass);
15808 m_errorMonitor->VerifyFound();
15809
15810 // Next, correctly do a 1st try (with a NULL pointer to surface_formats):
15811 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, NULL);
15812 pass = (err == VK_SUCCESS);
15813 ASSERT_TRUE(pass);
15814
15815 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
15816 VkPresentModeKHR *surface_present_modes = (VkPresentModeKHR *)malloc(surface_present_mode_count * sizeof(VkPresentModeKHR));
15817
15818 // Next, do a 2nd try with surface_format_count being set too high:
15819 surface_present_mode_count += 5;
15820 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is greater than the value");
15821 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, surface_present_modes);
15822 pass = (err == VK_SUCCESS);
15823 ASSERT_TRUE(pass);
15824 m_errorMonitor->VerifyFound();
15825
15826 // Finally, do a correct 1st and 2nd try:
15827 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, NULL);
15828 pass = (err == VK_SUCCESS);
15829 ASSERT_TRUE(pass);
15830 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, surface_present_modes);
15831 pass = (err == VK_SUCCESS);
15832 ASSERT_TRUE(pass);
15833
15834 // Create a swapchain:
15835
15836 // First, try without a pointer to swapchain_create_info:
15837 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pCreateInfo "
15838 "specified as NULL");
15839
15840 err = vkCreateSwapchainKHR(m_device->device(), NULL, NULL, &swapchain);
15841 pass = (err != VK_SUCCESS);
15842 ASSERT_TRUE(pass);
15843 m_errorMonitor->VerifyFound();
15844
15845 // Next, call with a non-NULL swapchain_create_info, that has the wrong
15846 // sType:
15847 swapchain_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
15848 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pCreateInfo->sType must be");
15849
15850 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
15851 pass = (err != VK_SUCCESS);
15852 ASSERT_TRUE(pass);
15853 m_errorMonitor->VerifyFound();
15854
15855 // Next, call with a NULL swapchain pointer:
15856 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
15857 swapchain_create_info.pNext = NULL;
15858 swapchain_create_info.flags = 0;
15859 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pSwapchain "
15860 "specified as NULL");
15861
15862 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, NULL);
15863 pass = (err != VK_SUCCESS);
15864 ASSERT_TRUE(pass);
15865 m_errorMonitor->VerifyFound();
15866
15867 // TODO: Enhance swapchain layer so that
15868 // swapchain_create_info.queueFamilyIndexCount is checked against something?
15869
15870 // Next, call with a queue family index that's too large:
15871 uint32_t queueFamilyIndex[2] = { 100000, 0 };
15872 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
15873 swapchain_create_info.queueFamilyIndexCount = 2;
15874 swapchain_create_info.pQueueFamilyIndices = queueFamilyIndex;
15875 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with a queueFamilyIndex that is too large");
15876 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
15877 pass = (err != VK_SUCCESS);
15878 ASSERT_TRUE(pass);
15879 m_errorMonitor->VerifyFound();
15880
15881 // Next, call a queueFamilyIndexCount that's too small for CONCURRENT:
15882 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
15883 swapchain_create_info.queueFamilyIndexCount = 1;
15884 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15885 "but with a bad value(s) for pCreateInfo->queueFamilyIndexCount or "
15886 "pCreateInfo->pQueueFamilyIndices).");
15887 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
15888 pass = (err != VK_SUCCESS);
15889 ASSERT_TRUE(pass);
15890 m_errorMonitor->VerifyFound();
15891
15892 // Next, call with an invalid imageSharingMode:
15893 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_MAX_ENUM;
15894 swapchain_create_info.queueFamilyIndexCount = 1;
15895 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15896 "called with a non-supported pCreateInfo->imageSharingMode (i.e.");
15897 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
15898 pass = (err != VK_SUCCESS);
15899 ASSERT_TRUE(pass);
15900 m_errorMonitor->VerifyFound();
15901 // Fix for the future:
15902 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
15903 // SUPPORTED
15904 swapchain_create_info.queueFamilyIndexCount = 0;
15905 queueFamilyIndex[0] = 0;
15906 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE;
15907
15908 // TODO: CONTINUE TESTING VALIDATION OF vkCreateSwapchainKHR() ...
15909 // Get the images from a swapchain:
15910 // Acquire an image from a swapchain:
15911 // Present an image to a swapchain:
15912 // Destroy the swapchain:
15913
15914 // TODOs:
15915 //
15916 // - Try destroying the device without first destroying the swapchain
15917 //
15918 // - Try destroying the device without first destroying the surface
15919 //
15920 // - Try destroying the surface without first destroying the swapchain
15921
15922 // Destroy the surface:
15923 vkDestroySurfaceKHR(instance(), surface, NULL);
15924
15925 // Tear down the window:
15926 xcb_destroy_window(connection, xcb_window);
15927 xcb_disconnect(connection);
15928
15929#else // VK_USE_PLATFORM_XCB_KHR
15930 return;
15931#endif // VK_USE_PLATFORM_XCB_KHR
15932}
Chris Forbes09368e42016-10-13 11:59:22 +130015933#endif
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060015934
15935//
15936// POSITIVE VALIDATION TESTS
15937//
15938// These tests do not expect to encounter ANY validation errors pass only if this is true
15939
Tobin Ehlise0006882016-11-03 10:14:28 -060015940TEST_F(VkPositiveLayerTest, SecondaryCommandBufferImageLayoutTransitions) {
15941 TEST_DESCRIPTION("Perform an image layout transition in a secondary command buffer followed "
15942 "by a transition in the primary.");
15943 VkResult err;
15944 m_errorMonitor->ExpectSuccess();
15945 ASSERT_NO_FATAL_FAILURE(InitState());
15946 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15947 // Allocate a secondary and primary cmd buffer
15948 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
15949 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
15950 command_buffer_allocate_info.commandPool = m_commandPool;
15951 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
15952 command_buffer_allocate_info.commandBufferCount = 1;
15953
15954 VkCommandBuffer secondary_command_buffer;
15955 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer));
15956 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
15957 VkCommandBuffer primary_command_buffer;
15958 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &primary_command_buffer));
15959 VkCommandBufferBeginInfo command_buffer_begin_info = {};
15960 VkCommandBufferInheritanceInfo command_buffer_inheritance_info = {};
15961 command_buffer_inheritance_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
15962 command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
15963 command_buffer_begin_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
15964 command_buffer_begin_info.pInheritanceInfo = &command_buffer_inheritance_info;
15965
15966 err = vkBeginCommandBuffer(secondary_command_buffer, &command_buffer_begin_info);
15967 ASSERT_VK_SUCCESS(err);
15968 VkImageObj image(m_device);
15969 image.init(128, 128, VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
15970 ASSERT_TRUE(image.initialized());
15971 VkImageMemoryBarrier img_barrier = {};
15972 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
15973 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
15974 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
15975 img_barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
15976 img_barrier.newLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
15977 img_barrier.image = image.handle();
15978 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
15979 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
15980 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
15981 img_barrier.subresourceRange.baseArrayLayer = 0;
15982 img_barrier.subresourceRange.baseMipLevel = 0;
15983 img_barrier.subresourceRange.layerCount = 1;
15984 img_barrier.subresourceRange.levelCount = 1;
15985 vkCmdPipelineBarrier(secondary_command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr,
15986 0, nullptr, 1, &img_barrier);
15987 err = vkEndCommandBuffer(secondary_command_buffer);
15988 ASSERT_VK_SUCCESS(err);
15989
15990 // Now update primary cmd buffer to execute secondary and transitions image
15991 command_buffer_begin_info.pInheritanceInfo = nullptr;
15992 err = vkBeginCommandBuffer(primary_command_buffer, &command_buffer_begin_info);
15993 ASSERT_VK_SUCCESS(err);
15994 vkCmdExecuteCommands(primary_command_buffer, 1, &secondary_command_buffer);
15995 VkImageMemoryBarrier img_barrier2 = {};
15996 img_barrier2.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
15997 img_barrier2.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
15998 img_barrier2.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
15999 img_barrier2.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
16000 img_barrier2.newLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
16001 img_barrier2.image = image.handle();
16002 img_barrier2.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
16003 img_barrier2.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
16004 img_barrier2.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
16005 img_barrier2.subresourceRange.baseArrayLayer = 0;
16006 img_barrier2.subresourceRange.baseMipLevel = 0;
16007 img_barrier2.subresourceRange.layerCount = 1;
16008 img_barrier2.subresourceRange.levelCount = 1;
16009 vkCmdPipelineBarrier(primary_command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0,
16010 nullptr, 1, &img_barrier2);
16011 err = vkEndCommandBuffer(primary_command_buffer);
16012 ASSERT_VK_SUCCESS(err);
16013 VkSubmitInfo submit_info = {};
16014 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
16015 submit_info.commandBufferCount = 1;
16016 submit_info.pCommandBuffers = &primary_command_buffer;
16017 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
16018 ASSERT_VK_SUCCESS(err);
16019 m_errorMonitor->VerifyNotFound();
16020 err = vkDeviceWaitIdle(m_device->device());
16021 ASSERT_VK_SUCCESS(err);
16022 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &secondary_command_buffer);
16023 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &primary_command_buffer);
16024}
16025
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016026// This is a positive test. No failures are expected.
16027TEST_F(VkPositiveLayerTest, IgnoreUnrelatedDescriptor) {
16028 TEST_DESCRIPTION("Ensure that the vkUpdateDescriptorSets validation code "
16029 "is ignoring VkWriteDescriptorSet members that are not "
16030 "related to the descriptor type specified by "
16031 "VkWriteDescriptorSet::descriptorType. Correct "
16032 "validation behavior will result in the test running to "
16033 "completion without validation errors.");
16034
16035 const uintptr_t invalid_ptr = 0xcdcdcdcd;
16036
16037 ASSERT_NO_FATAL_FAILURE(InitState());
16038
16039 // Image Case
16040 {
16041 m_errorMonitor->ExpectSuccess();
16042
16043 VkImage image;
16044 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
16045 const int32_t tex_width = 32;
16046 const int32_t tex_height = 32;
16047 VkImageCreateInfo image_create_info = {};
16048 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16049 image_create_info.pNext = NULL;
16050 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16051 image_create_info.format = tex_format;
16052 image_create_info.extent.width = tex_width;
16053 image_create_info.extent.height = tex_height;
16054 image_create_info.extent.depth = 1;
16055 image_create_info.mipLevels = 1;
16056 image_create_info.arrayLayers = 1;
16057 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16058 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
16059 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
16060 image_create_info.flags = 0;
16061 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
16062 ASSERT_VK_SUCCESS(err);
16063
16064 VkMemoryRequirements memory_reqs;
16065 VkDeviceMemory image_memory;
16066 bool pass;
16067 VkMemoryAllocateInfo memory_info = {};
16068 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16069 memory_info.pNext = NULL;
16070 memory_info.allocationSize = 0;
16071 memory_info.memoryTypeIndex = 0;
16072 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
16073 memory_info.allocationSize = memory_reqs.size;
16074 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
16075 ASSERT_TRUE(pass);
16076 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
16077 ASSERT_VK_SUCCESS(err);
16078 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
16079 ASSERT_VK_SUCCESS(err);
16080
16081 VkImageViewCreateInfo image_view_create_info = {};
16082 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
16083 image_view_create_info.image = image;
16084 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
16085 image_view_create_info.format = tex_format;
16086 image_view_create_info.subresourceRange.layerCount = 1;
16087 image_view_create_info.subresourceRange.baseMipLevel = 0;
16088 image_view_create_info.subresourceRange.levelCount = 1;
16089 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16090
16091 VkImageView view;
16092 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
16093 ASSERT_VK_SUCCESS(err);
16094
16095 VkDescriptorPoolSize ds_type_count = {};
16096 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
16097 ds_type_count.descriptorCount = 1;
16098
16099 VkDescriptorPoolCreateInfo ds_pool_ci = {};
16100 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
16101 ds_pool_ci.pNext = NULL;
16102 ds_pool_ci.maxSets = 1;
16103 ds_pool_ci.poolSizeCount = 1;
16104 ds_pool_ci.pPoolSizes = &ds_type_count;
16105
16106 VkDescriptorPool ds_pool;
16107 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
16108 ASSERT_VK_SUCCESS(err);
16109
16110 VkDescriptorSetLayoutBinding dsl_binding = {};
16111 dsl_binding.binding = 0;
16112 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
16113 dsl_binding.descriptorCount = 1;
16114 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
16115 dsl_binding.pImmutableSamplers = NULL;
16116
16117 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
16118 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
16119 ds_layout_ci.pNext = NULL;
16120 ds_layout_ci.bindingCount = 1;
16121 ds_layout_ci.pBindings = &dsl_binding;
16122 VkDescriptorSetLayout ds_layout;
16123 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
16124 ASSERT_VK_SUCCESS(err);
16125
16126 VkDescriptorSet descriptor_set;
16127 VkDescriptorSetAllocateInfo alloc_info = {};
16128 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
16129 alloc_info.descriptorSetCount = 1;
16130 alloc_info.descriptorPool = ds_pool;
16131 alloc_info.pSetLayouts = &ds_layout;
16132 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
16133 ASSERT_VK_SUCCESS(err);
16134
16135 VkDescriptorImageInfo image_info = {};
16136 image_info.imageView = view;
16137 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
16138
16139 VkWriteDescriptorSet descriptor_write;
16140 memset(&descriptor_write, 0, sizeof(descriptor_write));
16141 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
16142 descriptor_write.dstSet = descriptor_set;
16143 descriptor_write.dstBinding = 0;
16144 descriptor_write.descriptorCount = 1;
16145 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
16146 descriptor_write.pImageInfo = &image_info;
16147
16148 // Set pBufferInfo and pTexelBufferView to invalid values, which should
16149 // be
16150 // ignored for descriptorType == VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE.
16151 // This will most likely produce a crash if the parameter_validation
16152 // layer
16153 // does not correctly ignore pBufferInfo.
16154 descriptor_write.pBufferInfo = reinterpret_cast<const VkDescriptorBufferInfo *>(invalid_ptr);
16155 descriptor_write.pTexelBufferView = reinterpret_cast<const VkBufferView *>(invalid_ptr);
16156
16157 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
16158
16159 m_errorMonitor->VerifyNotFound();
16160
16161 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
16162 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
16163 vkDestroyImageView(m_device->device(), view, NULL);
16164 vkDestroyImage(m_device->device(), image, NULL);
16165 vkFreeMemory(m_device->device(), image_memory, NULL);
16166 }
16167
16168 // Buffer Case
16169 {
16170 m_errorMonitor->ExpectSuccess();
16171
16172 VkBuffer buffer;
16173 uint32_t queue_family_index = 0;
16174 VkBufferCreateInfo buffer_create_info = {};
16175 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
16176 buffer_create_info.size = 1024;
16177 buffer_create_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
16178 buffer_create_info.queueFamilyIndexCount = 1;
16179 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
16180
16181 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
16182 ASSERT_VK_SUCCESS(err);
16183
16184 VkMemoryRequirements memory_reqs;
16185 VkDeviceMemory buffer_memory;
16186 bool pass;
16187 VkMemoryAllocateInfo memory_info = {};
16188 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16189 memory_info.pNext = NULL;
16190 memory_info.allocationSize = 0;
16191 memory_info.memoryTypeIndex = 0;
16192
16193 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
16194 memory_info.allocationSize = memory_reqs.size;
16195 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
16196 ASSERT_TRUE(pass);
16197
16198 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
16199 ASSERT_VK_SUCCESS(err);
16200 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
16201 ASSERT_VK_SUCCESS(err);
16202
16203 VkDescriptorPoolSize ds_type_count = {};
16204 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16205 ds_type_count.descriptorCount = 1;
16206
16207 VkDescriptorPoolCreateInfo ds_pool_ci = {};
16208 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
16209 ds_pool_ci.pNext = NULL;
16210 ds_pool_ci.maxSets = 1;
16211 ds_pool_ci.poolSizeCount = 1;
16212 ds_pool_ci.pPoolSizes = &ds_type_count;
16213
16214 VkDescriptorPool ds_pool;
16215 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
16216 ASSERT_VK_SUCCESS(err);
16217
16218 VkDescriptorSetLayoutBinding dsl_binding = {};
16219 dsl_binding.binding = 0;
16220 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16221 dsl_binding.descriptorCount = 1;
16222 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
16223 dsl_binding.pImmutableSamplers = NULL;
16224
16225 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
16226 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
16227 ds_layout_ci.pNext = NULL;
16228 ds_layout_ci.bindingCount = 1;
16229 ds_layout_ci.pBindings = &dsl_binding;
16230 VkDescriptorSetLayout ds_layout;
16231 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
16232 ASSERT_VK_SUCCESS(err);
16233
16234 VkDescriptorSet descriptor_set;
16235 VkDescriptorSetAllocateInfo alloc_info = {};
16236 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
16237 alloc_info.descriptorSetCount = 1;
16238 alloc_info.descriptorPool = ds_pool;
16239 alloc_info.pSetLayouts = &ds_layout;
16240 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
16241 ASSERT_VK_SUCCESS(err);
16242
16243 VkDescriptorBufferInfo buffer_info = {};
16244 buffer_info.buffer = buffer;
16245 buffer_info.offset = 0;
16246 buffer_info.range = 1024;
16247
16248 VkWriteDescriptorSet descriptor_write;
16249 memset(&descriptor_write, 0, sizeof(descriptor_write));
16250 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
16251 descriptor_write.dstSet = descriptor_set;
16252 descriptor_write.dstBinding = 0;
16253 descriptor_write.descriptorCount = 1;
16254 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16255 descriptor_write.pBufferInfo = &buffer_info;
16256
16257 // Set pImageInfo and pTexelBufferView to invalid values, which should
16258 // be
16259 // ignored for descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER.
16260 // This will most likely produce a crash if the parameter_validation
16261 // layer
16262 // does not correctly ignore pImageInfo.
16263 descriptor_write.pImageInfo = reinterpret_cast<const VkDescriptorImageInfo *>(invalid_ptr);
16264 descriptor_write.pTexelBufferView = reinterpret_cast<const VkBufferView *>(invalid_ptr);
16265
16266 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
16267
16268 m_errorMonitor->VerifyNotFound();
16269
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016270 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
16271 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
16272 vkDestroyBuffer(m_device->device(), buffer, NULL);
16273 vkFreeMemory(m_device->device(), buffer_memory, NULL);
16274 }
16275
16276 // Texel Buffer Case
16277 {
16278 m_errorMonitor->ExpectSuccess();
16279
16280 VkBuffer buffer;
16281 uint32_t queue_family_index = 0;
16282 VkBufferCreateInfo buffer_create_info = {};
16283 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
16284 buffer_create_info.size = 1024;
16285 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
16286 buffer_create_info.queueFamilyIndexCount = 1;
16287 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
16288
16289 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
16290 ASSERT_VK_SUCCESS(err);
16291
16292 VkMemoryRequirements memory_reqs;
16293 VkDeviceMemory buffer_memory;
16294 bool pass;
16295 VkMemoryAllocateInfo memory_info = {};
16296 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16297 memory_info.pNext = NULL;
16298 memory_info.allocationSize = 0;
16299 memory_info.memoryTypeIndex = 0;
16300
16301 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
16302 memory_info.allocationSize = memory_reqs.size;
16303 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
16304 ASSERT_TRUE(pass);
16305
16306 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
16307 ASSERT_VK_SUCCESS(err);
16308 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
16309 ASSERT_VK_SUCCESS(err);
16310
16311 VkBufferViewCreateInfo buff_view_ci = {};
16312 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
16313 buff_view_ci.buffer = buffer;
16314 buff_view_ci.format = VK_FORMAT_R8_UNORM;
16315 buff_view_ci.range = VK_WHOLE_SIZE;
16316 VkBufferView buffer_view;
16317 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buffer_view);
16318
16319 VkDescriptorPoolSize ds_type_count = {};
16320 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
16321 ds_type_count.descriptorCount = 1;
16322
16323 VkDescriptorPoolCreateInfo ds_pool_ci = {};
16324 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
16325 ds_pool_ci.pNext = NULL;
16326 ds_pool_ci.maxSets = 1;
16327 ds_pool_ci.poolSizeCount = 1;
16328 ds_pool_ci.pPoolSizes = &ds_type_count;
16329
16330 VkDescriptorPool ds_pool;
16331 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
16332 ASSERT_VK_SUCCESS(err);
16333
16334 VkDescriptorSetLayoutBinding dsl_binding = {};
16335 dsl_binding.binding = 0;
16336 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
16337 dsl_binding.descriptorCount = 1;
16338 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
16339 dsl_binding.pImmutableSamplers = NULL;
16340
16341 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
16342 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
16343 ds_layout_ci.pNext = NULL;
16344 ds_layout_ci.bindingCount = 1;
16345 ds_layout_ci.pBindings = &dsl_binding;
16346 VkDescriptorSetLayout ds_layout;
16347 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
16348 ASSERT_VK_SUCCESS(err);
16349
16350 VkDescriptorSet descriptor_set;
16351 VkDescriptorSetAllocateInfo alloc_info = {};
16352 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
16353 alloc_info.descriptorSetCount = 1;
16354 alloc_info.descriptorPool = ds_pool;
16355 alloc_info.pSetLayouts = &ds_layout;
16356 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
16357 ASSERT_VK_SUCCESS(err);
16358
16359 VkWriteDescriptorSet descriptor_write;
16360 memset(&descriptor_write, 0, sizeof(descriptor_write));
16361 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
16362 descriptor_write.dstSet = descriptor_set;
16363 descriptor_write.dstBinding = 0;
16364 descriptor_write.descriptorCount = 1;
16365 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
16366 descriptor_write.pTexelBufferView = &buffer_view;
16367
16368 // Set pImageInfo and pBufferInfo to invalid values, which should be
16369 // ignored for descriptorType ==
16370 // VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER.
16371 // This will most likely produce a crash if the parameter_validation
16372 // layer
16373 // does not correctly ignore pImageInfo and pBufferInfo.
16374 descriptor_write.pImageInfo = reinterpret_cast<const VkDescriptorImageInfo *>(invalid_ptr);
16375 descriptor_write.pBufferInfo = reinterpret_cast<const VkDescriptorBufferInfo *>(invalid_ptr);
16376
16377 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
16378
16379 m_errorMonitor->VerifyNotFound();
16380
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016381 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
16382 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
16383 vkDestroyBufferView(m_device->device(), buffer_view, NULL);
16384 vkDestroyBuffer(m_device->device(), buffer, NULL);
16385 vkFreeMemory(m_device->device(), buffer_memory, NULL);
16386 }
16387}
16388
Tobin Ehlisf7428442016-10-25 07:58:24 -060016389TEST_F(VkLayerTest, DuplicateDescriptorBinding) {
16390 TEST_DESCRIPTION("Create a descriptor set layout with a duplicate binding number.");
16391
16392 ASSERT_NO_FATAL_FAILURE(InitState());
16393 // Create layout where two binding #s are "1"
16394 static const uint32_t NUM_BINDINGS = 3;
16395 VkDescriptorSetLayoutBinding dsl_binding[NUM_BINDINGS] = {};
16396 dsl_binding[0].binding = 1;
16397 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16398 dsl_binding[0].descriptorCount = 1;
16399 dsl_binding[0].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
16400 dsl_binding[0].pImmutableSamplers = NULL;
16401 dsl_binding[1].binding = 0;
16402 dsl_binding[1].descriptorCount = 1;
16403 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16404 dsl_binding[1].descriptorCount = 1;
16405 dsl_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
16406 dsl_binding[1].pImmutableSamplers = NULL;
16407 dsl_binding[2].binding = 1; // Duplicate binding should cause error
16408 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16409 dsl_binding[2].descriptorCount = 1;
16410 dsl_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
16411 dsl_binding[2].pImmutableSamplers = NULL;
16412
16413 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
16414 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
16415 ds_layout_ci.pNext = NULL;
16416 ds_layout_ci.bindingCount = NUM_BINDINGS;
16417 ds_layout_ci.pBindings = dsl_binding;
16418 VkDescriptorSetLayout ds_layout;
16419 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02345);
16420 vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
16421 m_errorMonitor->VerifyFound();
16422}
16423
Mike Weiblen9a0f55d2016-10-31 22:35:00 -060016424TEST_F(VkLayerTest, ViewportAndScissorBoundsChecking) {
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060016425 TEST_DESCRIPTION("Verify errors are detected on misuse of SetViewport and SetScissor.");
16426
16427 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060016428
16429 BeginCommandBuffer();
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060016430
Mike Weiblen9a0f55d2016-10-31 22:35:00 -060016431 const VkPhysicalDeviceLimits &limits = m_device->props.limits;
16432
16433 {
16434 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01448);
16435 VkViewport viewport = {0, 0, static_cast<float>(limits.maxViewportDimensions[0] + 1), 16, 0, 1};
16436 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
16437 m_errorMonitor->VerifyFound();
16438 }
16439
16440 {
16441 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01449);
16442 VkViewport viewport = {0, 0, 16, static_cast<float>(limits.maxViewportDimensions[1] + 1), 0, 1};
16443 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
16444 m_errorMonitor->VerifyFound();
16445 }
16446
16447 {
16448 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01450);
16449 VkViewport viewport = {limits.viewportBoundsRange[0] - 1, 0, 16, 16, 0, 1};
16450 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
16451 m_errorMonitor->VerifyFound();
16452 }
16453
16454 {
16455 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01450);
16456 VkViewport viewport = {0, limits.viewportBoundsRange[0] - 1, 16, 16, 0, 1};
16457 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
16458 m_errorMonitor->VerifyFound();
16459 }
16460
16461 {
16462 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01451);
16463 VkViewport viewport = {limits.viewportBoundsRange[1], 0, 16, 16, 0, 1};
16464 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
16465 m_errorMonitor->VerifyFound();
16466 }
16467
16468 {
16469 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01452);
16470 VkViewport viewport = {0, limits.viewportBoundsRange[1], 16, 16, 0, 1};
16471 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
16472 m_errorMonitor->VerifyFound();
16473 }
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060016474
16475 {
16476 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01489);
16477 VkRect2D scissor = {{-1, 0}, {16, 16}};
16478 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
16479 m_errorMonitor->VerifyFound();
16480 }
16481
16482 {
16483 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01489);
16484 VkRect2D scissor = {{0, -2}, {16, 16}};
16485 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
16486 m_errorMonitor->VerifyFound();
16487 }
16488
16489 {
16490 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01490);
16491 VkRect2D scissor = {{100, 100}, {INT_MAX, 16}};
16492 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
16493 m_errorMonitor->VerifyFound();
16494 }
16495
16496 {
16497 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01491);
16498 VkRect2D scissor = {{100, 100}, {16, INT_MAX}};
16499 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
16500 m_errorMonitor->VerifyFound();
16501 }
16502
16503 EndCommandBuffer();
16504}
16505
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016506// This is a positive test. No failures are expected.
16507TEST_F(VkPositiveLayerTest, EmptyDescriptorUpdateTest) {
16508 TEST_DESCRIPTION("Update last descriptor in a set that includes an empty binding");
16509 VkResult err;
16510
16511 ASSERT_NO_FATAL_FAILURE(InitState());
16512 m_errorMonitor->ExpectSuccess();
16513 VkDescriptorPoolSize ds_type_count = {};
16514 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16515 ds_type_count.descriptorCount = 2;
16516
16517 VkDescriptorPoolCreateInfo ds_pool_ci = {};
16518 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
16519 ds_pool_ci.pNext = NULL;
16520 ds_pool_ci.maxSets = 1;
16521 ds_pool_ci.poolSizeCount = 1;
16522 ds_pool_ci.pPoolSizes = &ds_type_count;
16523
16524 VkDescriptorPool ds_pool;
16525 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
16526 ASSERT_VK_SUCCESS(err);
16527
16528 // Create layout with two uniform buffer descriptors w/ empty binding between them
16529 static const uint32_t NUM_BINDINGS = 3;
16530 VkDescriptorSetLayoutBinding dsl_binding[NUM_BINDINGS] = {};
16531 dsl_binding[0].binding = 0;
16532 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16533 dsl_binding[0].descriptorCount = 1;
16534 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
16535 dsl_binding[0].pImmutableSamplers = NULL;
16536 dsl_binding[1].binding = 1;
16537 dsl_binding[1].descriptorCount = 0; // empty binding
16538 dsl_binding[2].binding = 2;
16539 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16540 dsl_binding[2].descriptorCount = 1;
16541 dsl_binding[2].stageFlags = VK_SHADER_STAGE_ALL;
16542 dsl_binding[2].pImmutableSamplers = NULL;
16543
16544 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
16545 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
16546 ds_layout_ci.pNext = NULL;
16547 ds_layout_ci.bindingCount = NUM_BINDINGS;
16548 ds_layout_ci.pBindings = dsl_binding;
16549 VkDescriptorSetLayout ds_layout;
16550 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
16551 ASSERT_VK_SUCCESS(err);
16552
16553 VkDescriptorSet descriptor_set = {};
16554 VkDescriptorSetAllocateInfo alloc_info = {};
16555 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
16556 alloc_info.descriptorSetCount = 1;
16557 alloc_info.descriptorPool = ds_pool;
16558 alloc_info.pSetLayouts = &ds_layout;
16559 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
16560 ASSERT_VK_SUCCESS(err);
16561
16562 // Create a buffer to be used for update
16563 VkBufferCreateInfo buff_ci = {};
16564 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
16565 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
16566 buff_ci.size = 256;
16567 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
16568 VkBuffer buffer;
16569 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
16570 ASSERT_VK_SUCCESS(err);
16571 // Have to bind memory to buffer before descriptor update
16572 VkMemoryAllocateInfo mem_alloc = {};
16573 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16574 mem_alloc.pNext = NULL;
16575 mem_alloc.allocationSize = 512; // one allocation for both buffers
16576 mem_alloc.memoryTypeIndex = 0;
16577
16578 VkMemoryRequirements mem_reqs;
16579 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
16580 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
16581 if (!pass) {
16582 vkDestroyBuffer(m_device->device(), buffer, NULL);
16583 return;
16584 }
16585
16586 VkDeviceMemory mem;
16587 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
16588 ASSERT_VK_SUCCESS(err);
16589 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
16590 ASSERT_VK_SUCCESS(err);
16591
16592 // Only update the descriptor at binding 2
16593 VkDescriptorBufferInfo buff_info = {};
16594 buff_info.buffer = buffer;
16595 buff_info.offset = 0;
16596 buff_info.range = VK_WHOLE_SIZE;
16597 VkWriteDescriptorSet descriptor_write = {};
16598 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
16599 descriptor_write.dstBinding = 2;
16600 descriptor_write.descriptorCount = 1;
16601 descriptor_write.pTexelBufferView = nullptr;
16602 descriptor_write.pBufferInfo = &buff_info;
16603 descriptor_write.pImageInfo = nullptr;
16604 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16605 descriptor_write.dstSet = descriptor_set;
16606
16607 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
16608
16609 m_errorMonitor->VerifyNotFound();
16610 // Cleanup
16611 vkFreeMemory(m_device->device(), mem, NULL);
16612 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
16613 vkDestroyBuffer(m_device->device(), buffer, NULL);
16614 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
16615}
16616
16617// This is a positive test. No failures are expected.
16618TEST_F(VkPositiveLayerTest, TestAliasedMemoryTracking) {
16619 VkResult err;
16620 bool pass;
16621
16622 TEST_DESCRIPTION("Create a buffer, allocate memory, bind memory, destroy "
16623 "the buffer, create an image, and bind the same memory to "
16624 "it");
16625
16626 m_errorMonitor->ExpectSuccess();
16627
16628 ASSERT_NO_FATAL_FAILURE(InitState());
16629
16630 VkBuffer buffer;
16631 VkImage image;
16632 VkDeviceMemory mem;
16633 VkMemoryRequirements mem_reqs;
16634
16635 VkBufferCreateInfo buf_info = {};
16636 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
16637 buf_info.pNext = NULL;
16638 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
16639 buf_info.size = 256;
16640 buf_info.queueFamilyIndexCount = 0;
16641 buf_info.pQueueFamilyIndices = NULL;
16642 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
16643 buf_info.flags = 0;
16644 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
16645 ASSERT_VK_SUCCESS(err);
16646
16647 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
16648
16649 VkMemoryAllocateInfo alloc_info = {};
16650 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16651 alloc_info.pNext = NULL;
16652 alloc_info.memoryTypeIndex = 0;
16653
16654 // Ensure memory is big enough for both bindings
16655 alloc_info.allocationSize = 0x10000;
16656
16657 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
16658 if (!pass) {
16659 vkDestroyBuffer(m_device->device(), buffer, NULL);
16660 return;
16661 }
16662
16663 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
16664 ASSERT_VK_SUCCESS(err);
16665
16666 uint8_t *pData;
16667 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
16668 ASSERT_VK_SUCCESS(err);
16669
16670 memset(pData, 0xCADECADE, static_cast<size_t>(mem_reqs.size));
16671
16672 vkUnmapMemory(m_device->device(), mem);
16673
16674 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
16675 ASSERT_VK_SUCCESS(err);
16676
16677 // NOW, destroy the buffer. Obviously, the resource no longer occupies this
16678 // memory. In fact, it was never used by the GPU.
16679 // Just be be sure, wait for idle.
16680 vkDestroyBuffer(m_device->device(), buffer, NULL);
16681 vkDeviceWaitIdle(m_device->device());
16682
16683 VkImageCreateInfo image_create_info = {};
16684 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16685 image_create_info.pNext = NULL;
16686 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16687 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
16688 image_create_info.extent.width = 64;
16689 image_create_info.extent.height = 64;
16690 image_create_info.extent.depth = 1;
16691 image_create_info.mipLevels = 1;
16692 image_create_info.arrayLayers = 1;
16693 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16694 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
16695 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
16696 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
16697 image_create_info.queueFamilyIndexCount = 0;
16698 image_create_info.pQueueFamilyIndices = NULL;
16699 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
16700 image_create_info.flags = 0;
16701
16702 VkMemoryAllocateInfo mem_alloc = {};
16703 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16704 mem_alloc.pNext = NULL;
16705 mem_alloc.allocationSize = 0;
16706 mem_alloc.memoryTypeIndex = 0;
16707
16708 /* Create a mappable image. It will be the texture if linear images are ok
16709 * to be textures or it will be the staging image if they are not.
16710 */
16711 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
16712 ASSERT_VK_SUCCESS(err);
16713
16714 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
16715
16716 mem_alloc.allocationSize = mem_reqs.size;
16717
16718 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
16719 if (!pass) {
16720 vkDestroyImage(m_device->device(), image, NULL);
16721 return;
16722 }
16723
16724 // VALIDATION FAILURE:
16725 err = vkBindImageMemory(m_device->device(), image, mem, 0);
16726 ASSERT_VK_SUCCESS(err);
16727
16728 m_errorMonitor->VerifyNotFound();
16729
16730 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016731 vkDestroyImage(m_device->device(), image, NULL);
16732}
16733
Tobin Ehlis953e8392016-11-17 10:54:13 -070016734TEST_F(VkPositiveLayerTest, DynamicOffsetWithInactiveBinding) {
16735 // Create a descriptorSet w/ dynamic descriptors where 1 binding is inactive
16736 // We previously had a bug where dynamic offset of inactive bindings was still being used
16737 VkResult err;
16738 m_errorMonitor->ExpectSuccess();
16739
16740 ASSERT_NO_FATAL_FAILURE(InitState());
16741 ASSERT_NO_FATAL_FAILURE(InitViewport());
16742 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
16743
16744 VkDescriptorPoolSize ds_type_count = {};
16745 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
16746 ds_type_count.descriptorCount = 3;
16747
16748 VkDescriptorPoolCreateInfo ds_pool_ci = {};
16749 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
16750 ds_pool_ci.pNext = NULL;
16751 ds_pool_ci.maxSets = 1;
16752 ds_pool_ci.poolSizeCount = 1;
16753 ds_pool_ci.pPoolSizes = &ds_type_count;
16754
16755 VkDescriptorPool ds_pool;
16756 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
16757 ASSERT_VK_SUCCESS(err);
16758
16759 const uint32_t BINDING_COUNT = 3;
16760 VkDescriptorSetLayoutBinding dsl_binding[BINDING_COUNT] = {};
Tobin Ehlis0050fba2016-11-30 10:22:02 -070016761 dsl_binding[0].binding = 2;
Tobin Ehlis953e8392016-11-17 10:54:13 -070016762 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
16763 dsl_binding[0].descriptorCount = 1;
16764 dsl_binding[0].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
16765 dsl_binding[0].pImmutableSamplers = NULL;
Tobin Ehlis0050fba2016-11-30 10:22:02 -070016766 dsl_binding[1].binding = 0;
Tobin Ehlis953e8392016-11-17 10:54:13 -070016767 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
16768 dsl_binding[1].descriptorCount = 1;
16769 dsl_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
16770 dsl_binding[1].pImmutableSamplers = NULL;
Tobin Ehlis0050fba2016-11-30 10:22:02 -070016771 dsl_binding[2].binding = 1;
Tobin Ehlis953e8392016-11-17 10:54:13 -070016772 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
16773 dsl_binding[2].descriptorCount = 1;
16774 dsl_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
16775 dsl_binding[2].pImmutableSamplers = NULL;
16776
16777 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
16778 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
16779 ds_layout_ci.pNext = NULL;
16780 ds_layout_ci.bindingCount = BINDING_COUNT;
16781 ds_layout_ci.pBindings = dsl_binding;
16782 VkDescriptorSetLayout ds_layout;
16783 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
16784 ASSERT_VK_SUCCESS(err);
16785
16786 VkDescriptorSet descriptor_set;
16787 VkDescriptorSetAllocateInfo alloc_info = {};
16788 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
16789 alloc_info.descriptorSetCount = 1;
16790 alloc_info.descriptorPool = ds_pool;
16791 alloc_info.pSetLayouts = &ds_layout;
16792 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
16793 ASSERT_VK_SUCCESS(err);
16794
16795 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
16796 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
16797 pipeline_layout_ci.pNext = NULL;
16798 pipeline_layout_ci.setLayoutCount = 1;
16799 pipeline_layout_ci.pSetLayouts = &ds_layout;
16800
16801 VkPipelineLayout pipeline_layout;
16802 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
16803 ASSERT_VK_SUCCESS(err);
16804
16805 // Create two buffers to update the descriptors with
16806 // The first will be 2k and used for bindings 0 & 1, the second is 1k for binding 2
16807 uint32_t qfi = 0;
16808 VkBufferCreateInfo buffCI = {};
16809 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
16810 buffCI.size = 2048;
16811 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
16812 buffCI.queueFamilyIndexCount = 1;
16813 buffCI.pQueueFamilyIndices = &qfi;
16814
16815 VkBuffer dyub1;
16816 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub1);
16817 ASSERT_VK_SUCCESS(err);
16818 // buffer2
16819 buffCI.size = 1024;
16820 VkBuffer dyub2;
16821 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub2);
16822 ASSERT_VK_SUCCESS(err);
16823 // Allocate memory and bind to buffers
16824 VkMemoryAllocateInfo mem_alloc[2] = {};
16825 mem_alloc[0].sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16826 mem_alloc[0].pNext = NULL;
16827 mem_alloc[0].memoryTypeIndex = 0;
16828 mem_alloc[1].sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16829 mem_alloc[1].pNext = NULL;
16830 mem_alloc[1].memoryTypeIndex = 0;
16831
16832 VkMemoryRequirements mem_reqs1;
16833 vkGetBufferMemoryRequirements(m_device->device(), dyub1, &mem_reqs1);
16834 VkMemoryRequirements mem_reqs2;
16835 vkGetBufferMemoryRequirements(m_device->device(), dyub2, &mem_reqs2);
16836 mem_alloc[0].allocationSize = mem_reqs1.size;
16837 bool pass = m_device->phy().set_memory_type(mem_reqs1.memoryTypeBits, &mem_alloc[0], 0);
16838 mem_alloc[1].allocationSize = mem_reqs2.size;
16839 pass &= m_device->phy().set_memory_type(mem_reqs2.memoryTypeBits, &mem_alloc[1], 0);
16840 if (!pass) {
16841 vkDestroyBuffer(m_device->device(), dyub1, NULL);
16842 vkDestroyBuffer(m_device->device(), dyub2, NULL);
16843 return;
16844 }
16845
16846 VkDeviceMemory mem1;
16847 err = vkAllocateMemory(m_device->device(), &mem_alloc[0], NULL, &mem1);
16848 ASSERT_VK_SUCCESS(err);
16849 err = vkBindBufferMemory(m_device->device(), dyub1, mem1, 0);
16850 ASSERT_VK_SUCCESS(err);
16851 VkDeviceMemory mem2;
16852 err = vkAllocateMemory(m_device->device(), &mem_alloc[1], NULL, &mem2);
16853 ASSERT_VK_SUCCESS(err);
16854 err = vkBindBufferMemory(m_device->device(), dyub2, mem2, 0);
16855 ASSERT_VK_SUCCESS(err);
16856 // Update descriptors
16857 VkDescriptorBufferInfo buff_info[BINDING_COUNT] = {};
16858 buff_info[0].buffer = dyub1;
16859 buff_info[0].offset = 0;
16860 buff_info[0].range = 256;
16861 buff_info[1].buffer = dyub1;
16862 buff_info[1].offset = 256;
16863 buff_info[1].range = 512;
16864 buff_info[2].buffer = dyub2;
16865 buff_info[2].offset = 0;
16866 buff_info[2].range = 512;
16867
16868 VkWriteDescriptorSet descriptor_write;
16869 memset(&descriptor_write, 0, sizeof(descriptor_write));
16870 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
16871 descriptor_write.dstSet = descriptor_set;
16872 descriptor_write.dstBinding = 0;
16873 descriptor_write.descriptorCount = BINDING_COUNT;
16874 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
16875 descriptor_write.pBufferInfo = buff_info;
16876
16877 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
16878
16879 BeginCommandBuffer();
16880
16881 // Create PSO to be used for draw-time errors below
16882 char const *vsSource = "#version 450\n"
16883 "\n"
16884 "out gl_PerVertex { \n"
16885 " vec4 gl_Position;\n"
16886 "};\n"
16887 "void main(){\n"
16888 " gl_Position = vec4(1);\n"
16889 "}\n";
16890 char const *fsSource = "#version 450\n"
16891 "\n"
16892 "layout(location=0) out vec4 x;\n"
16893 "layout(set=0) layout(binding=0) uniform foo1 { int x; int y; } bar1;\n"
16894 "layout(set=0) layout(binding=2) uniform foo2 { int x; int y; } bar2;\n"
16895 "void main(){\n"
16896 " x = vec4(bar1.y) + vec4(bar2.y);\n"
16897 "}\n";
16898 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
16899 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
16900 VkPipelineObj pipe(m_device);
16901 pipe.SetViewport(m_viewports);
16902 pipe.SetScissor(m_scissors);
16903 pipe.AddShader(&vs);
16904 pipe.AddShader(&fs);
16905 pipe.AddColorAttachment();
16906 pipe.CreateVKPipeline(pipeline_layout, renderPass());
16907
16908 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
16909 // This update should succeed, but offset of inactive binding 1 oversteps binding 2 buffer size
16910 // we used to have a bug in this case.
16911 uint32_t dyn_off[BINDING_COUNT] = {0, 1024, 256};
16912 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
16913 &descriptor_set, BINDING_COUNT, dyn_off);
16914 Draw(1, 0, 0, 0);
16915 m_errorMonitor->VerifyNotFound();
16916
16917 vkDestroyBuffer(m_device->device(), dyub1, NULL);
16918 vkDestroyBuffer(m_device->device(), dyub2, NULL);
16919 vkFreeMemory(m_device->device(), mem1, NULL);
16920 vkFreeMemory(m_device->device(), mem2, NULL);
16921
16922 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
16923 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
16924 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
16925}
16926
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016927TEST_F(VkPositiveLayerTest, NonCoherentMemoryMapping) {
16928
16929 TEST_DESCRIPTION("Ensure that validations handling of non-coherent memory "
16930 "mapping while using VK_WHOLE_SIZE does not cause access "
16931 "violations");
16932 VkResult err;
16933 uint8_t *pData;
16934 ASSERT_NO_FATAL_FAILURE(InitState());
16935
16936 VkDeviceMemory mem;
16937 VkMemoryRequirements mem_reqs;
16938 mem_reqs.memoryTypeBits = 0xFFFFFFFF;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070016939 const VkDeviceSize atom_size = m_device->props.limits.nonCoherentAtomSize;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016940 VkMemoryAllocateInfo alloc_info = {};
16941 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16942 alloc_info.pNext = NULL;
16943 alloc_info.memoryTypeIndex = 0;
16944
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070016945 static const VkDeviceSize allocation_size = 32 * atom_size;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016946 alloc_info.allocationSize = allocation_size;
16947
16948 // Find a memory configurations WITHOUT a COHERENT bit, otherwise exit
16949 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT,
16950 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
16951 if (!pass) {
16952 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info,
16953 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT,
16954 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
16955 if (!pass) {
16956 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info,
16957 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT |
16958 VK_MEMORY_PROPERTY_HOST_CACHED_BIT,
16959 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
16960 if (!pass) {
16961 return;
16962 }
16963 }
16964 }
16965
16966 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
16967 ASSERT_VK_SUCCESS(err);
16968
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070016969 // Map/Flush/Invalidate using WHOLE_SIZE and zero offsets and entire mapped range
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016970 m_errorMonitor->ExpectSuccess();
16971 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, (void **)&pData);
16972 ASSERT_VK_SUCCESS(err);
16973 VkMappedMemoryRange mmr = {};
16974 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
16975 mmr.memory = mem;
16976 mmr.offset = 0;
16977 mmr.size = VK_WHOLE_SIZE;
16978 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
16979 ASSERT_VK_SUCCESS(err);
16980 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
16981 ASSERT_VK_SUCCESS(err);
16982 m_errorMonitor->VerifyNotFound();
16983 vkUnmapMemory(m_device->device(), mem);
16984
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070016985 // Map/Flush/Invalidate using WHOLE_SIZE and an offset and entire mapped range
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016986 m_errorMonitor->ExpectSuccess();
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070016987 err = vkMapMemory(m_device->device(), mem, 5 * atom_size, VK_WHOLE_SIZE, 0, (void **)&pData);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016988 ASSERT_VK_SUCCESS(err);
16989 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
16990 mmr.memory = mem;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070016991 mmr.offset = 6 * atom_size;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016992 mmr.size = VK_WHOLE_SIZE;
16993 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
16994 ASSERT_VK_SUCCESS(err);
16995 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
16996 ASSERT_VK_SUCCESS(err);
16997 m_errorMonitor->VerifyNotFound();
16998 vkUnmapMemory(m_device->device(), mem);
16999
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017000 // Map with offset and size
17001 // Flush/Invalidate subrange of mapped area with offset and size
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017002 m_errorMonitor->ExpectSuccess();
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017003 err = vkMapMemory(m_device->device(), mem, 3 * atom_size, 9 * atom_size, 0, (void **)&pData);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017004 ASSERT_VK_SUCCESS(err);
17005 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
17006 mmr.memory = mem;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017007 mmr.offset = 4 * atom_size;
17008 mmr.size = 2 * atom_size;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017009 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
17010 ASSERT_VK_SUCCESS(err);
17011 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
17012 ASSERT_VK_SUCCESS(err);
17013 m_errorMonitor->VerifyNotFound();
17014 vkUnmapMemory(m_device->device(), mem);
17015
17016 // Map without offset and flush WHOLE_SIZE with two separate offsets
17017 m_errorMonitor->ExpectSuccess();
17018 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, (void **)&pData);
17019 ASSERT_VK_SUCCESS(err);
17020 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
17021 mmr.memory = mem;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017022 mmr.offset = allocation_size - (4 * atom_size);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017023 mmr.size = VK_WHOLE_SIZE;
17024 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
17025 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017026 mmr.offset = allocation_size - (6 * atom_size);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017027 mmr.size = VK_WHOLE_SIZE;
17028 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
17029 ASSERT_VK_SUCCESS(err);
17030 m_errorMonitor->VerifyNotFound();
17031 vkUnmapMemory(m_device->device(), mem);
17032
17033 vkFreeMemory(m_device->device(), mem, NULL);
17034}
17035
17036// This is a positive test. We used to expect error in this case but spec now allows it
17037TEST_F(VkPositiveLayerTest, ResetUnsignaledFence) {
17038 m_errorMonitor->ExpectSuccess();
17039 vk_testing::Fence testFence;
17040 VkFenceCreateInfo fenceInfo = {};
17041 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
17042 fenceInfo.pNext = NULL;
17043
17044 ASSERT_NO_FATAL_FAILURE(InitState());
17045 testFence.init(*m_device, fenceInfo);
17046 VkFence fences[1] = { testFence.handle() };
17047 VkResult result = vkResetFences(m_device->device(), 1, fences);
17048 ASSERT_VK_SUCCESS(result);
17049
17050 m_errorMonitor->VerifyNotFound();
17051}
17052
17053TEST_F(VkPositiveLayerTest, CommandBufferSimultaneousUseSync) {
17054 m_errorMonitor->ExpectSuccess();
17055
17056 ASSERT_NO_FATAL_FAILURE(InitState());
17057 VkResult err;
17058
17059 // Record (empty!) command buffer that can be submitted multiple times
17060 // simultaneously.
17061 VkCommandBufferBeginInfo cbbi = { VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr,
17062 VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT, nullptr };
17063 m_commandBuffer->BeginCommandBuffer(&cbbi);
17064 m_commandBuffer->EndCommandBuffer();
17065
17066 VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
17067 VkFence fence;
17068 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
17069 ASSERT_VK_SUCCESS(err);
17070
17071 VkSemaphoreCreateInfo sci = { VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0 };
17072 VkSemaphore s1, s2;
17073 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s1);
17074 ASSERT_VK_SUCCESS(err);
17075 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s2);
17076 ASSERT_VK_SUCCESS(err);
17077
17078 // Submit CB once signaling s1, with fence so we can roll forward to its retirement.
17079 VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 1, &m_commandBuffer->handle(), 1, &s1 };
17080 err = vkQueueSubmit(m_device->m_queue, 1, &si, fence);
17081 ASSERT_VK_SUCCESS(err);
17082
17083 // Submit CB again, signaling s2.
17084 si.pSignalSemaphores = &s2;
17085 err = vkQueueSubmit(m_device->m_queue, 1, &si, VK_NULL_HANDLE);
17086 ASSERT_VK_SUCCESS(err);
17087
17088 // Wait for fence.
17089 err = vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
17090 ASSERT_VK_SUCCESS(err);
17091
17092 // CB is still in flight from second submission, but semaphore s1 is no
17093 // longer in flight. delete it.
17094 vkDestroySemaphore(m_device->device(), s1, nullptr);
17095
17096 m_errorMonitor->VerifyNotFound();
17097
17098 // Force device idle and clean up remaining objects
17099 vkDeviceWaitIdle(m_device->device());
17100 vkDestroySemaphore(m_device->device(), s2, nullptr);
17101 vkDestroyFence(m_device->device(), fence, nullptr);
17102}
17103
17104TEST_F(VkPositiveLayerTest, FenceCreateSignaledWaitHandling) {
17105 m_errorMonitor->ExpectSuccess();
17106
17107 ASSERT_NO_FATAL_FAILURE(InitState());
17108 VkResult err;
17109
17110 // A fence created signaled
17111 VkFenceCreateInfo fci1 = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, VK_FENCE_CREATE_SIGNALED_BIT };
17112 VkFence f1;
17113 err = vkCreateFence(m_device->device(), &fci1, nullptr, &f1);
17114 ASSERT_VK_SUCCESS(err);
17115
17116 // A fence created not
17117 VkFenceCreateInfo fci2 = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
17118 VkFence f2;
17119 err = vkCreateFence(m_device->device(), &fci2, nullptr, &f2);
17120 ASSERT_VK_SUCCESS(err);
17121
17122 // Submit the unsignaled fence
17123 VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 0, nullptr, 0, nullptr };
17124 err = vkQueueSubmit(m_device->m_queue, 1, &si, f2);
17125
17126 // Wait on both fences, with signaled first.
17127 VkFence fences[] = { f1, f2 };
17128 vkWaitForFences(m_device->device(), 2, fences, VK_TRUE, UINT64_MAX);
17129
17130 // Should have both retired!
17131 vkDestroyFence(m_device->device(), f1, nullptr);
17132 vkDestroyFence(m_device->device(), f2, nullptr);
17133
17134 m_errorMonitor->VerifyNotFound();
17135}
17136
17137TEST_F(VkPositiveLayerTest, ValidUsage) {
17138 TEST_DESCRIPTION("Verify that creating an image view from an image with valid usage "
17139 "doesn't generate validation errors");
17140
17141 ASSERT_NO_FATAL_FAILURE(InitState());
17142
17143 m_errorMonitor->ExpectSuccess();
17144 // Verify that we can create a view with usage INPUT_ATTACHMENT
17145 VkImageObj image(m_device);
17146 image.init(128, 128, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
17147 ASSERT_TRUE(image.initialized());
17148 VkImageView imageView;
17149 VkImageViewCreateInfo ivci = {};
17150 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
17151 ivci.image = image.handle();
17152 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
17153 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
17154 ivci.subresourceRange.layerCount = 1;
17155 ivci.subresourceRange.baseMipLevel = 0;
17156 ivci.subresourceRange.levelCount = 1;
17157 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
17158
17159 vkCreateImageView(m_device->device(), &ivci, NULL, &imageView);
17160 m_errorMonitor->VerifyNotFound();
17161 vkDestroyImageView(m_device->device(), imageView, NULL);
17162}
17163
17164// This is a positive test. No failures are expected.
17165TEST_F(VkPositiveLayerTest, BindSparse) {
17166 TEST_DESCRIPTION("Bind 2 memory ranges to one image using vkQueueBindSparse, destroy the image"
17167 "and then free the memory");
17168
17169 ASSERT_NO_FATAL_FAILURE(InitState());
17170
17171 auto index = m_device->graphics_queue_node_index_;
17172 if (!(m_device->queue_props[index].queueFlags & VK_QUEUE_SPARSE_BINDING_BIT))
17173 return;
17174
17175 m_errorMonitor->ExpectSuccess();
17176
17177 VkImage image;
17178 VkImageCreateInfo image_create_info = {};
17179 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
17180 image_create_info.pNext = NULL;
17181 image_create_info.imageType = VK_IMAGE_TYPE_2D;
17182 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
17183 image_create_info.extent.width = 64;
17184 image_create_info.extent.height = 64;
17185 image_create_info.extent.depth = 1;
17186 image_create_info.mipLevels = 1;
17187 image_create_info.arrayLayers = 1;
17188 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
17189 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
17190 image_create_info.usage = VK_IMAGE_USAGE_STORAGE_BIT;
17191 image_create_info.flags = VK_IMAGE_CREATE_SPARSE_BINDING_BIT;
17192 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
17193 ASSERT_VK_SUCCESS(err);
17194
17195 VkMemoryRequirements memory_reqs;
17196 VkDeviceMemory memory_one, memory_two;
17197 bool pass;
17198 VkMemoryAllocateInfo memory_info = {};
17199 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17200 memory_info.pNext = NULL;
17201 memory_info.allocationSize = 0;
17202 memory_info.memoryTypeIndex = 0;
17203 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
17204 // Find an image big enough to allow sparse mapping of 2 memory regions
17205 // Increase the image size until it is at least twice the
17206 // size of the required alignment, to ensure we can bind both
17207 // allocated memory blocks to the image on aligned offsets.
17208 while (memory_reqs.size < (memory_reqs.alignment * 2)) {
17209 vkDestroyImage(m_device->device(), image, nullptr);
17210 image_create_info.extent.width *= 2;
17211 image_create_info.extent.height *= 2;
17212 err = vkCreateImage(m_device->device(), &image_create_info, nullptr, &image);
17213 ASSERT_VK_SUCCESS(err);
17214 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
17215 }
17216 // Allocate 2 memory regions of minimum alignment size, bind one at 0, the other
17217 // at the end of the first
17218 memory_info.allocationSize = memory_reqs.alignment;
17219 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
17220 ASSERT_TRUE(pass);
17221 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &memory_one);
17222 ASSERT_VK_SUCCESS(err);
17223 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &memory_two);
17224 ASSERT_VK_SUCCESS(err);
17225 VkSparseMemoryBind binds[2];
17226 binds[0].flags = 0;
17227 binds[0].memory = memory_one;
17228 binds[0].memoryOffset = 0;
17229 binds[0].resourceOffset = 0;
17230 binds[0].size = memory_info.allocationSize;
17231 binds[1].flags = 0;
17232 binds[1].memory = memory_two;
17233 binds[1].memoryOffset = 0;
17234 binds[1].resourceOffset = memory_info.allocationSize;
17235 binds[1].size = memory_info.allocationSize;
17236
17237 VkSparseImageOpaqueMemoryBindInfo opaqueBindInfo;
17238 opaqueBindInfo.image = image;
17239 opaqueBindInfo.bindCount = 2;
17240 opaqueBindInfo.pBinds = binds;
17241
17242 VkFence fence = VK_NULL_HANDLE;
17243 VkBindSparseInfo bindSparseInfo = {};
17244 bindSparseInfo.sType = VK_STRUCTURE_TYPE_BIND_SPARSE_INFO;
17245 bindSparseInfo.imageOpaqueBindCount = 1;
17246 bindSparseInfo.pImageOpaqueBinds = &opaqueBindInfo;
17247
17248 vkQueueBindSparse(m_device->m_queue, 1, &bindSparseInfo, fence);
17249 vkQueueWaitIdle(m_device->m_queue);
17250 vkDestroyImage(m_device->device(), image, NULL);
17251 vkFreeMemory(m_device->device(), memory_one, NULL);
17252 vkFreeMemory(m_device->device(), memory_two, NULL);
17253 m_errorMonitor->VerifyNotFound();
17254}
17255
17256TEST_F(VkPositiveLayerTest, RenderPassInitialLayoutUndefined) {
17257 TEST_DESCRIPTION("Ensure that CmdBeginRenderPass with an attachment's "
17258 "initialLayout of VK_IMAGE_LAYOUT_UNDEFINED works when "
17259 "the command buffer has prior knowledge of that "
17260 "attachment's layout.");
17261
17262 m_errorMonitor->ExpectSuccess();
17263
17264 ASSERT_NO_FATAL_FAILURE(InitState());
17265
17266 // A renderpass with one color attachment.
17267 VkAttachmentDescription attachment = { 0,
17268 VK_FORMAT_R8G8B8A8_UNORM,
17269 VK_SAMPLE_COUNT_1_BIT,
17270 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
17271 VK_ATTACHMENT_STORE_OP_STORE,
17272 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
17273 VK_ATTACHMENT_STORE_OP_DONT_CARE,
17274 VK_IMAGE_LAYOUT_UNDEFINED,
17275 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
17276
17277 VkAttachmentReference att_ref = { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
17278
17279 VkSubpassDescription subpass = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr };
17280
17281 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr };
17282
17283 VkRenderPass rp;
17284 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
17285 ASSERT_VK_SUCCESS(err);
17286
17287 // A compatible framebuffer.
17288 VkImageObj image(m_device);
17289 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
17290 ASSERT_TRUE(image.initialized());
17291
17292 VkImageViewCreateInfo ivci = {
17293 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
17294 nullptr,
17295 0,
17296 image.handle(),
17297 VK_IMAGE_VIEW_TYPE_2D,
17298 VK_FORMAT_R8G8B8A8_UNORM,
17299 { VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
17300 VK_COMPONENT_SWIZZLE_IDENTITY },
17301 { VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 },
17302 };
17303 VkImageView view;
17304 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
17305 ASSERT_VK_SUCCESS(err);
17306
17307 VkFramebufferCreateInfo fci = { VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1 };
17308 VkFramebuffer fb;
17309 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
17310 ASSERT_VK_SUCCESS(err);
17311
17312 // Record a single command buffer which uses this renderpass twice. The
17313 // bug is triggered at the beginning of the second renderpass, when the
17314 // command buffer already has a layout recorded for the attachment.
17315 VkRenderPassBeginInfo rpbi = { VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb,{ { 0, 0 },{ 32, 32 } }, 0, nullptr };
17316 BeginCommandBuffer();
17317 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
17318 vkCmdEndRenderPass(m_commandBuffer->handle());
17319 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
17320
17321 m_errorMonitor->VerifyNotFound();
17322
17323 vkCmdEndRenderPass(m_commandBuffer->handle());
17324 EndCommandBuffer();
17325
17326 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
17327 vkDestroyRenderPass(m_device->device(), rp, nullptr);
17328 vkDestroyImageView(m_device->device(), view, nullptr);
17329}
17330
17331TEST_F(VkPositiveLayerTest, FramebufferBindingDestroyCommandPool) {
17332 TEST_DESCRIPTION("This test should pass. Create a Framebuffer and "
17333 "command buffer, bind them together, then destroy "
17334 "command pool and framebuffer and verify there are no "
17335 "errors.");
17336
17337 m_errorMonitor->ExpectSuccess();
17338
17339 ASSERT_NO_FATAL_FAILURE(InitState());
17340
17341 // A renderpass with one color attachment.
17342 VkAttachmentDescription attachment = { 0,
17343 VK_FORMAT_R8G8B8A8_UNORM,
17344 VK_SAMPLE_COUNT_1_BIT,
17345 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
17346 VK_ATTACHMENT_STORE_OP_STORE,
17347 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
17348 VK_ATTACHMENT_STORE_OP_DONT_CARE,
17349 VK_IMAGE_LAYOUT_UNDEFINED,
17350 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
17351
17352 VkAttachmentReference att_ref = { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
17353
17354 VkSubpassDescription subpass = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr };
17355
17356 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr };
17357
17358 VkRenderPass rp;
17359 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
17360 ASSERT_VK_SUCCESS(err);
17361
17362 // A compatible framebuffer.
17363 VkImageObj image(m_device);
17364 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
17365 ASSERT_TRUE(image.initialized());
17366
17367 VkImageViewCreateInfo ivci = {
17368 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
17369 nullptr,
17370 0,
17371 image.handle(),
17372 VK_IMAGE_VIEW_TYPE_2D,
17373 VK_FORMAT_R8G8B8A8_UNORM,
17374 { VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
17375 VK_COMPONENT_SWIZZLE_IDENTITY },
17376 { VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 },
17377 };
17378 VkImageView view;
17379 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
17380 ASSERT_VK_SUCCESS(err);
17381
17382 VkFramebufferCreateInfo fci = { VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1 };
17383 VkFramebuffer fb;
17384 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
17385 ASSERT_VK_SUCCESS(err);
17386
17387 // Explicitly create a command buffer to bind the FB to so that we can then
17388 // destroy the command pool in order to implicitly free command buffer
17389 VkCommandPool command_pool;
17390 VkCommandPoolCreateInfo pool_create_info{};
17391 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17392 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
17393 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17394 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
17395
17396 VkCommandBuffer command_buffer;
17397 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
17398 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17399 command_buffer_allocate_info.commandPool = command_pool;
17400 command_buffer_allocate_info.commandBufferCount = 1;
17401 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17402 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
17403
17404 // Begin our cmd buffer with renderpass using our framebuffer
17405 VkRenderPassBeginInfo rpbi = { VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb,{ { 0, 0 },{ 32, 32 } }, 0, nullptr };
17406 VkCommandBufferBeginInfo begin_info{};
17407 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17408 vkBeginCommandBuffer(command_buffer, &begin_info);
17409
17410 vkCmdBeginRenderPass(command_buffer, &rpbi, VK_SUBPASS_CONTENTS_INLINE);
17411 vkCmdEndRenderPass(command_buffer);
17412 vkEndCommandBuffer(command_buffer);
17413 vkDestroyImageView(m_device->device(), view, nullptr);
17414 // Destroy command pool to implicitly free command buffer
17415 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
17416 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
17417 vkDestroyRenderPass(m_device->device(), rp, nullptr);
17418 m_errorMonitor->VerifyNotFound();
17419}
17420
17421TEST_F(VkPositiveLayerTest, RenderPassSubpassZeroTransitionsApplied) {
17422 TEST_DESCRIPTION("Ensure that CmdBeginRenderPass applies the layout "
17423 "transitions for the first subpass");
17424
17425 m_errorMonitor->ExpectSuccess();
17426
17427 ASSERT_NO_FATAL_FAILURE(InitState());
17428
17429 // A renderpass with one color attachment.
17430 VkAttachmentDescription attachment = { 0,
17431 VK_FORMAT_R8G8B8A8_UNORM,
17432 VK_SAMPLE_COUNT_1_BIT,
17433 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
17434 VK_ATTACHMENT_STORE_OP_STORE,
17435 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
17436 VK_ATTACHMENT_STORE_OP_DONT_CARE,
17437 VK_IMAGE_LAYOUT_UNDEFINED,
17438 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
17439
17440 VkAttachmentReference att_ref = { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
17441
17442 VkSubpassDescription subpass = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr };
17443
17444 VkSubpassDependency dep = { 0,
17445 0,
17446 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
17447 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
17448 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
17449 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
17450 VK_DEPENDENCY_BY_REGION_BIT };
17451
17452 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 1, &dep };
17453
17454 VkResult err;
17455 VkRenderPass rp;
17456 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
17457 ASSERT_VK_SUCCESS(err);
17458
17459 // A compatible framebuffer.
17460 VkImageObj image(m_device);
17461 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
17462 ASSERT_TRUE(image.initialized());
17463
17464 VkImageViewCreateInfo ivci = {
17465 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
17466 nullptr,
17467 0,
17468 image.handle(),
17469 VK_IMAGE_VIEW_TYPE_2D,
17470 VK_FORMAT_R8G8B8A8_UNORM,
17471 { VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
17472 VK_COMPONENT_SWIZZLE_IDENTITY },
17473 { VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 },
17474 };
17475 VkImageView view;
17476 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
17477 ASSERT_VK_SUCCESS(err);
17478
17479 VkFramebufferCreateInfo fci = { VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1 };
17480 VkFramebuffer fb;
17481 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
17482 ASSERT_VK_SUCCESS(err);
17483
17484 // Record a single command buffer which issues a pipeline barrier w/
17485 // image memory barrier for the attachment. This detects the previously
17486 // missing tracking of the subpass layout by throwing a validation error
17487 // if it doesn't occur.
17488 VkRenderPassBeginInfo rpbi = { VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb,{ { 0, 0 },{ 32, 32 } }, 0, nullptr };
17489 BeginCommandBuffer();
17490 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
17491
17492 VkImageMemoryBarrier imb = { VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,
17493 nullptr,
17494 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
17495 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
17496 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
17497 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
17498 VK_QUEUE_FAMILY_IGNORED,
17499 VK_QUEUE_FAMILY_IGNORED,
17500 image.handle(),
17501 { VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 } };
17502 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
17503 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_DEPENDENCY_BY_REGION_BIT, 0, nullptr, 0, nullptr, 1,
17504 &imb);
17505
17506 vkCmdEndRenderPass(m_commandBuffer->handle());
17507 m_errorMonitor->VerifyNotFound();
17508 EndCommandBuffer();
17509
17510 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
17511 vkDestroyRenderPass(m_device->device(), rp, nullptr);
17512 vkDestroyImageView(m_device->device(), view, nullptr);
17513}
17514
17515TEST_F(VkPositiveLayerTest, DepthStencilLayoutTransitionForDepthOnlyImageview) {
17516 TEST_DESCRIPTION("Validate that when an imageView of a depth/stencil image "
17517 "is used as a depth/stencil framebuffer attachment, the "
17518 "aspectMask is ignored and both depth and stencil image "
17519 "subresources are used.");
17520
17521 VkFormatProperties format_properties;
17522 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_D32_SFLOAT_S8_UINT, &format_properties);
17523 if (!(format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)) {
17524 return;
17525 }
17526
17527 m_errorMonitor->ExpectSuccess();
17528
17529 ASSERT_NO_FATAL_FAILURE(InitState());
17530
17531 VkAttachmentDescription attachment = { 0,
17532 VK_FORMAT_D32_SFLOAT_S8_UINT,
17533 VK_SAMPLE_COUNT_1_BIT,
17534 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
17535 VK_ATTACHMENT_STORE_OP_STORE,
17536 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
17537 VK_ATTACHMENT_STORE_OP_DONT_CARE,
17538 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
17539 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL };
17540
17541 VkAttachmentReference att_ref = { 0, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL };
17542
17543 VkSubpassDescription subpass = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, &att_ref, 0, nullptr };
17544
17545 VkSubpassDependency dep = { 0,
17546 0,
17547 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
17548 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
17549 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
17550 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
17551 VK_DEPENDENCY_BY_REGION_BIT};
17552
17553 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 1, &dep };
17554
17555 VkResult err;
17556 VkRenderPass rp;
17557 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
17558 ASSERT_VK_SUCCESS(err);
17559
17560 VkImageObj image(m_device);
17561 image.init_no_layout(32, 32, VK_FORMAT_D32_SFLOAT_S8_UINT,
17562 0x26, // usage
17563 VK_IMAGE_TILING_OPTIMAL, 0);
17564 ASSERT_TRUE(image.initialized());
17565 image.SetLayout(0x6, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL);
17566
17567 VkImageViewCreateInfo ivci = {
17568 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
17569 nullptr,
17570 0,
17571 image.handle(),
17572 VK_IMAGE_VIEW_TYPE_2D,
17573 VK_FORMAT_D32_SFLOAT_S8_UINT,
17574 { VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A },
17575 { 0x2, 0, 1, 0, 1 },
17576 };
17577 VkImageView view;
17578 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
17579 ASSERT_VK_SUCCESS(err);
17580
17581 VkFramebufferCreateInfo fci = { VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1 };
17582 VkFramebuffer fb;
17583 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
17584 ASSERT_VK_SUCCESS(err);
17585
17586 VkRenderPassBeginInfo rpbi = { VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb,{ { 0, 0 },{ 32, 32 } }, 0, nullptr };
17587 BeginCommandBuffer();
17588 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
17589
17590 VkImageMemoryBarrier imb = {};
17591 imb.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
17592 imb.pNext = nullptr;
17593 imb.srcAccessMask = VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
17594 imb.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
17595 imb.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
17596 imb.newLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
17597 imb.srcQueueFamilyIndex = 0;
17598 imb.dstQueueFamilyIndex = 0;
17599 imb.image = image.handle();
17600 imb.subresourceRange.aspectMask = 0x6;
17601 imb.subresourceRange.baseMipLevel = 0;
17602 imb.subresourceRange.levelCount = 0x1;
17603 imb.subresourceRange.baseArrayLayer = 0;
17604 imb.subresourceRange.layerCount = 0x1;
17605
17606 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
17607 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_DEPENDENCY_BY_REGION_BIT, 0, nullptr, 0, nullptr, 1,
17608 &imb);
17609
17610 vkCmdEndRenderPass(m_commandBuffer->handle());
17611 EndCommandBuffer();
17612 QueueCommandBuffer(false);
17613 m_errorMonitor->VerifyNotFound();
17614
17615 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
17616 vkDestroyRenderPass(m_device->device(), rp, nullptr);
17617 vkDestroyImageView(m_device->device(), view, nullptr);
17618}
17619
17620TEST_F(VkPositiveLayerTest, RenderPassTransitionsAttachmentUnused) {
17621 TEST_DESCRIPTION("Ensure that layout transitions work correctly without "
17622 "errors, when an attachment reference is "
17623 "VK_ATTACHMENT_UNUSED");
17624
17625 m_errorMonitor->ExpectSuccess();
17626
17627 ASSERT_NO_FATAL_FAILURE(InitState());
17628
17629 // A renderpass with no attachments
17630 VkAttachmentReference att_ref = { VK_ATTACHMENT_UNUSED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
17631
17632 VkSubpassDescription subpass = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr };
17633
17634 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 1, &subpass, 0, nullptr };
17635
17636 VkRenderPass rp;
17637 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
17638 ASSERT_VK_SUCCESS(err);
17639
17640 // A compatible framebuffer.
17641 VkFramebufferCreateInfo fci = { VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 0, nullptr, 32, 32, 1 };
17642 VkFramebuffer fb;
17643 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
17644 ASSERT_VK_SUCCESS(err);
17645
17646 // Record a command buffer which just begins and ends the renderpass. The
17647 // bug manifests in BeginRenderPass.
17648 VkRenderPassBeginInfo rpbi = { VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb,{ { 0, 0 },{ 32, 32 } }, 0, nullptr };
17649 BeginCommandBuffer();
17650 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
17651 vkCmdEndRenderPass(m_commandBuffer->handle());
17652 m_errorMonitor->VerifyNotFound();
17653 EndCommandBuffer();
17654
17655 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
17656 vkDestroyRenderPass(m_device->device(), rp, nullptr);
17657}
17658
17659// This is a positive test. No errors are expected.
17660TEST_F(VkPositiveLayerTest, StencilLoadOp) {
17661 TEST_DESCRIPTION("Create a stencil-only attachment with a LOAD_OP set to "
17662 "CLEAR. stencil[Load|Store]Op used to be ignored.");
17663 VkResult result = VK_SUCCESS;
17664 VkImageFormatProperties formatProps;
17665 vkGetPhysicalDeviceImageFormatProperties(gpu(), VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
17666 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT, 0,
17667 &formatProps);
17668 if (formatProps.maxExtent.width < 100 || formatProps.maxExtent.height < 100) {
17669 return;
17670 }
17671
17672 ASSERT_NO_FATAL_FAILURE(InitState());
17673 VkFormat depth_stencil_fmt = VK_FORMAT_D24_UNORM_S8_UINT;
17674 m_depthStencil->Init(m_device, 100, 100, depth_stencil_fmt,
17675 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT);
17676 VkAttachmentDescription att = {};
17677 VkAttachmentReference ref = {};
17678 att.format = depth_stencil_fmt;
17679 att.samples = VK_SAMPLE_COUNT_1_BIT;
17680 att.loadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
17681 att.storeOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
17682 att.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
17683 att.stencilStoreOp = VK_ATTACHMENT_STORE_OP_STORE;
17684 att.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
17685 att.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
17686
17687 VkClearValue clear;
17688 clear.depthStencil.depth = 1.0;
17689 clear.depthStencil.stencil = 0;
17690 ref.attachment = 0;
17691 ref.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
17692
17693 VkSubpassDescription subpass = {};
17694 subpass.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;
17695 subpass.flags = 0;
17696 subpass.inputAttachmentCount = 0;
17697 subpass.pInputAttachments = NULL;
17698 subpass.colorAttachmentCount = 0;
17699 subpass.pColorAttachments = NULL;
17700 subpass.pResolveAttachments = NULL;
17701 subpass.pDepthStencilAttachment = &ref;
17702 subpass.preserveAttachmentCount = 0;
17703 subpass.pPreserveAttachments = NULL;
17704
17705 VkRenderPass rp;
17706 VkRenderPassCreateInfo rp_info = {};
17707 rp_info.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
17708 rp_info.attachmentCount = 1;
17709 rp_info.pAttachments = &att;
17710 rp_info.subpassCount = 1;
17711 rp_info.pSubpasses = &subpass;
17712 result = vkCreateRenderPass(device(), &rp_info, NULL, &rp);
17713 ASSERT_VK_SUCCESS(result);
17714
17715 VkImageView *depthView = m_depthStencil->BindInfo();
17716 VkFramebufferCreateInfo fb_info = {};
17717 fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
17718 fb_info.pNext = NULL;
17719 fb_info.renderPass = rp;
17720 fb_info.attachmentCount = 1;
17721 fb_info.pAttachments = depthView;
17722 fb_info.width = 100;
17723 fb_info.height = 100;
17724 fb_info.layers = 1;
17725 VkFramebuffer fb;
17726 result = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
17727 ASSERT_VK_SUCCESS(result);
17728
17729 VkRenderPassBeginInfo rpbinfo = {};
17730 rpbinfo.clearValueCount = 1;
17731 rpbinfo.pClearValues = &clear;
17732 rpbinfo.pNext = NULL;
17733 rpbinfo.renderPass = rp;
17734 rpbinfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
17735 rpbinfo.renderArea.extent.width = 100;
17736 rpbinfo.renderArea.extent.height = 100;
17737 rpbinfo.renderArea.offset.x = 0;
17738 rpbinfo.renderArea.offset.y = 0;
17739 rpbinfo.framebuffer = fb;
17740
17741 VkFence fence = {};
17742 VkFenceCreateInfo fence_ci = {};
17743 fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
17744 fence_ci.pNext = nullptr;
17745 fence_ci.flags = 0;
17746 result = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fence);
17747 ASSERT_VK_SUCCESS(result);
17748
17749 m_commandBuffer->BeginCommandBuffer();
17750 m_commandBuffer->BeginRenderPass(rpbinfo);
17751 m_commandBuffer->EndRenderPass();
17752 m_commandBuffer->EndCommandBuffer();
17753 m_commandBuffer->QueueCommandBuffer(fence);
17754
17755 VkImageObj destImage(m_device);
17756 destImage.init(100, 100, depth_stencil_fmt, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
17757 VK_IMAGE_TILING_OPTIMAL, 0);
17758 VkImageMemoryBarrier barrier = {};
17759 VkImageSubresourceRange range;
17760 barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
17761 barrier.srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
17762 barrier.dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT;
17763 barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
17764 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
17765 barrier.image = m_depthStencil->handle();
17766 range.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
17767 range.baseMipLevel = 0;
17768 range.levelCount = 1;
17769 range.baseArrayLayer = 0;
17770 range.layerCount = 1;
17771 barrier.subresourceRange = range;
17772 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
17773 VkCommandBufferObj cmdbuf(m_device, m_commandPool);
17774 cmdbuf.BeginCommandBuffer();
17775 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
17776 &barrier);
17777 barrier.srcAccessMask = 0;
17778 barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
17779 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
17780 barrier.image = destImage.handle();
17781 barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
17782 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
17783 &barrier);
17784 VkImageCopy cregion;
17785 cregion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
17786 cregion.srcSubresource.mipLevel = 0;
17787 cregion.srcSubresource.baseArrayLayer = 0;
17788 cregion.srcSubresource.layerCount = 1;
17789 cregion.srcOffset.x = 0;
17790 cregion.srcOffset.y = 0;
17791 cregion.srcOffset.z = 0;
17792 cregion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
17793 cregion.dstSubresource.mipLevel = 0;
17794 cregion.dstSubresource.baseArrayLayer = 0;
17795 cregion.dstSubresource.layerCount = 1;
17796 cregion.dstOffset.x = 0;
17797 cregion.dstOffset.y = 0;
17798 cregion.dstOffset.z = 0;
17799 cregion.extent.width = 100;
17800 cregion.extent.height = 100;
17801 cregion.extent.depth = 1;
17802 cmdbuf.CopyImage(m_depthStencil->handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, destImage.handle(),
17803 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &cregion);
17804 cmdbuf.EndCommandBuffer();
17805
17806 VkSubmitInfo submit_info;
17807 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17808 submit_info.pNext = NULL;
17809 submit_info.waitSemaphoreCount = 0;
17810 submit_info.pWaitSemaphores = NULL;
17811 submit_info.pWaitDstStageMask = NULL;
17812 submit_info.commandBufferCount = 1;
17813 submit_info.pCommandBuffers = &cmdbuf.handle();
17814 submit_info.signalSemaphoreCount = 0;
17815 submit_info.pSignalSemaphores = NULL;
17816
17817 m_errorMonitor->ExpectSuccess();
17818 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
17819 m_errorMonitor->VerifyNotFound();
17820
17821 vkQueueWaitIdle(m_device->m_queue);
17822 vkDestroyFence(m_device->device(), fence, nullptr);
17823 vkDestroyRenderPass(m_device->device(), rp, nullptr);
17824 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
17825}
17826
17827// This is a positive test. No errors should be generated.
17828TEST_F(VkPositiveLayerTest, WaitEventThenSet) {
17829 TEST_DESCRIPTION("Wait on a event then set it after the wait has been submitted.");
17830
17831 m_errorMonitor->ExpectSuccess();
17832 ASSERT_NO_FATAL_FAILURE(InitState());
17833
17834 VkEvent event;
17835 VkEventCreateInfo event_create_info{};
17836 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
17837 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
17838
17839 VkCommandPool command_pool;
17840 VkCommandPoolCreateInfo pool_create_info{};
17841 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17842 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
17843 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17844 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
17845
17846 VkCommandBuffer command_buffer;
17847 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
17848 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17849 command_buffer_allocate_info.commandPool = command_pool;
17850 command_buffer_allocate_info.commandBufferCount = 1;
17851 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17852 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
17853
17854 VkQueue queue = VK_NULL_HANDLE;
17855 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
17856
17857 {
17858 VkCommandBufferBeginInfo begin_info{};
17859 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17860 vkBeginCommandBuffer(command_buffer, &begin_info);
17861
17862 vkCmdWaitEvents(command_buffer, 1, &event, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, nullptr, 0,
17863 nullptr, 0, nullptr);
17864 vkCmdResetEvent(command_buffer, event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
17865 vkEndCommandBuffer(command_buffer);
17866 }
17867 {
17868 VkSubmitInfo submit_info{};
17869 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17870 submit_info.commandBufferCount = 1;
17871 submit_info.pCommandBuffers = &command_buffer;
17872 submit_info.signalSemaphoreCount = 0;
17873 submit_info.pSignalSemaphores = nullptr;
17874 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
17875 }
17876 { vkSetEvent(m_device->device(), event); }
17877
17878 vkQueueWaitIdle(queue);
17879
17880 vkDestroyEvent(m_device->device(), event, nullptr);
17881 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
17882 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
17883
17884 m_errorMonitor->VerifyNotFound();
17885}
17886// This is a positive test. No errors should be generated.
17887TEST_F(VkPositiveLayerTest, QueryAndCopySecondaryCommandBuffers) {
17888 TEST_DESCRIPTION("Issue a query on a secondary command buffery and copy it on a primary.");
17889
17890 ASSERT_NO_FATAL_FAILURE(InitState());
17891 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
17892 return;
17893
17894 m_errorMonitor->ExpectSuccess();
17895
17896 VkQueryPool query_pool;
17897 VkQueryPoolCreateInfo query_pool_create_info{};
17898 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
17899 query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP;
17900 query_pool_create_info.queryCount = 1;
17901 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
17902
17903 VkCommandPool command_pool;
17904 VkCommandPoolCreateInfo pool_create_info{};
17905 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17906 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
17907 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17908 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
17909
17910 VkCommandBuffer command_buffer;
17911 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
17912 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17913 command_buffer_allocate_info.commandPool = command_pool;
17914 command_buffer_allocate_info.commandBufferCount = 1;
17915 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17916 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
17917
17918 VkCommandBuffer secondary_command_buffer;
17919 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
17920 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer);
17921
17922 VkQueue queue = VK_NULL_HANDLE;
17923 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
17924
17925 uint32_t qfi = 0;
17926 VkBufferCreateInfo buff_create_info = {};
17927 buff_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
17928 buff_create_info.size = 1024;
17929 buff_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
17930 buff_create_info.queueFamilyIndexCount = 1;
17931 buff_create_info.pQueueFamilyIndices = &qfi;
17932
17933 VkResult err;
17934 VkBuffer buffer;
17935 err = vkCreateBuffer(m_device->device(), &buff_create_info, NULL, &buffer);
17936 ASSERT_VK_SUCCESS(err);
17937 VkMemoryAllocateInfo mem_alloc = {};
17938 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17939 mem_alloc.pNext = NULL;
17940 mem_alloc.allocationSize = 1024;
17941 mem_alloc.memoryTypeIndex = 0;
17942
17943 VkMemoryRequirements memReqs;
17944 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
17945 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
17946 if (!pass) {
17947 vkDestroyBuffer(m_device->device(), buffer, NULL);
17948 return;
17949 }
17950
17951 VkDeviceMemory mem;
17952 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
17953 ASSERT_VK_SUCCESS(err);
17954 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
17955 ASSERT_VK_SUCCESS(err);
17956
17957 VkCommandBufferInheritanceInfo hinfo = {};
17958 hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
17959 hinfo.renderPass = VK_NULL_HANDLE;
17960 hinfo.subpass = 0;
17961 hinfo.framebuffer = VK_NULL_HANDLE;
17962 hinfo.occlusionQueryEnable = VK_FALSE;
17963 hinfo.queryFlags = 0;
17964 hinfo.pipelineStatistics = 0;
17965
17966 {
17967 VkCommandBufferBeginInfo begin_info{};
17968 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17969 begin_info.pInheritanceInfo = &hinfo;
17970 vkBeginCommandBuffer(secondary_command_buffer, &begin_info);
17971
17972 vkCmdResetQueryPool(secondary_command_buffer, query_pool, 0, 1);
17973 vkCmdWriteTimestamp(secondary_command_buffer, VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0);
17974
17975 vkEndCommandBuffer(secondary_command_buffer);
17976
17977 begin_info.pInheritanceInfo = nullptr;
17978 vkBeginCommandBuffer(command_buffer, &begin_info);
17979
17980 vkCmdExecuteCommands(command_buffer, 1, &secondary_command_buffer);
17981 vkCmdCopyQueryPoolResults(command_buffer, query_pool, 0, 1, buffer, 0, 0, 0);
17982
17983 vkEndCommandBuffer(command_buffer);
17984 }
17985 {
17986 VkSubmitInfo submit_info{};
17987 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17988 submit_info.commandBufferCount = 1;
17989 submit_info.pCommandBuffers = &command_buffer;
17990 submit_info.signalSemaphoreCount = 0;
17991 submit_info.pSignalSemaphores = nullptr;
17992 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
17993 }
17994
17995 vkQueueWaitIdle(queue);
17996
17997 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
17998 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
17999 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &secondary_command_buffer);
18000 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18001 vkDestroyBuffer(m_device->device(), buffer, NULL);
18002 vkFreeMemory(m_device->device(), mem, NULL);
18003
18004 m_errorMonitor->VerifyNotFound();
18005}
18006
18007// This is a positive test. No errors should be generated.
18008TEST_F(VkPositiveLayerTest, QueryAndCopyMultipleCommandBuffers) {
18009 TEST_DESCRIPTION("Issue a query and copy from it on a second command buffer.");
18010
18011 ASSERT_NO_FATAL_FAILURE(InitState());
18012 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
18013 return;
18014
18015 m_errorMonitor->ExpectSuccess();
18016
18017 VkQueryPool query_pool;
18018 VkQueryPoolCreateInfo query_pool_create_info{};
18019 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
18020 query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP;
18021 query_pool_create_info.queryCount = 1;
18022 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
18023
18024 VkCommandPool command_pool;
18025 VkCommandPoolCreateInfo pool_create_info{};
18026 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18027 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18028 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18029 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18030
18031 VkCommandBuffer command_buffer[2];
18032 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18033 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18034 command_buffer_allocate_info.commandPool = command_pool;
18035 command_buffer_allocate_info.commandBufferCount = 2;
18036 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18037 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18038
18039 VkQueue queue = VK_NULL_HANDLE;
18040 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
18041
18042 uint32_t qfi = 0;
18043 VkBufferCreateInfo buff_create_info = {};
18044 buff_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
18045 buff_create_info.size = 1024;
18046 buff_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
18047 buff_create_info.queueFamilyIndexCount = 1;
18048 buff_create_info.pQueueFamilyIndices = &qfi;
18049
18050 VkResult err;
18051 VkBuffer buffer;
18052 err = vkCreateBuffer(m_device->device(), &buff_create_info, NULL, &buffer);
18053 ASSERT_VK_SUCCESS(err);
18054 VkMemoryAllocateInfo mem_alloc = {};
18055 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18056 mem_alloc.pNext = NULL;
18057 mem_alloc.allocationSize = 1024;
18058 mem_alloc.memoryTypeIndex = 0;
18059
18060 VkMemoryRequirements memReqs;
18061 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
18062 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
18063 if (!pass) {
18064 vkDestroyBuffer(m_device->device(), buffer, NULL);
18065 return;
18066 }
18067
18068 VkDeviceMemory mem;
18069 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
18070 ASSERT_VK_SUCCESS(err);
18071 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
18072 ASSERT_VK_SUCCESS(err);
18073
18074 {
18075 VkCommandBufferBeginInfo begin_info{};
18076 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18077 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18078
18079 vkCmdResetQueryPool(command_buffer[0], query_pool, 0, 1);
18080 vkCmdWriteTimestamp(command_buffer[0], VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0);
18081
18082 vkEndCommandBuffer(command_buffer[0]);
18083
18084 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18085
18086 vkCmdCopyQueryPoolResults(command_buffer[1], query_pool, 0, 1, buffer, 0, 0, 0);
18087
18088 vkEndCommandBuffer(command_buffer[1]);
18089 }
18090 {
18091 VkSubmitInfo submit_info{};
18092 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18093 submit_info.commandBufferCount = 2;
18094 submit_info.pCommandBuffers = command_buffer;
18095 submit_info.signalSemaphoreCount = 0;
18096 submit_info.pSignalSemaphores = nullptr;
18097 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
18098 }
18099
18100 vkQueueWaitIdle(queue);
18101
18102 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
18103 vkFreeCommandBuffers(m_device->device(), command_pool, 2, command_buffer);
18104 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18105 vkDestroyBuffer(m_device->device(), buffer, NULL);
18106 vkFreeMemory(m_device->device(), mem, NULL);
18107
18108 m_errorMonitor->VerifyNotFound();
18109}
18110
Tony Barbourc46924f2016-11-04 11:49:52 -060018111TEST_F(VkLayerTest, ResetEventThenSet) {
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018112 TEST_DESCRIPTION("Reset an event then set it after the reset has been submitted.");
18113
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018114 ASSERT_NO_FATAL_FAILURE(InitState());
18115 VkEvent event;
18116 VkEventCreateInfo event_create_info{};
18117 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
18118 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
18119
18120 VkCommandPool command_pool;
18121 VkCommandPoolCreateInfo pool_create_info{};
18122 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18123 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18124 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18125 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18126
18127 VkCommandBuffer command_buffer;
18128 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18129 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18130 command_buffer_allocate_info.commandPool = command_pool;
18131 command_buffer_allocate_info.commandBufferCount = 1;
18132 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18133 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
18134
18135 VkQueue queue = VK_NULL_HANDLE;
18136 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
18137
18138 {
18139 VkCommandBufferBeginInfo begin_info{};
18140 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18141 vkBeginCommandBuffer(command_buffer, &begin_info);
18142
18143 vkCmdResetEvent(command_buffer, event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018144 vkEndCommandBuffer(command_buffer);
18145 }
18146 {
18147 VkSubmitInfo submit_info{};
18148 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18149 submit_info.commandBufferCount = 1;
18150 submit_info.pCommandBuffers = &command_buffer;
18151 submit_info.signalSemaphoreCount = 0;
18152 submit_info.pSignalSemaphores = nullptr;
18153 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
18154 }
18155 {
18156 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is already in use by a "
18157 "command buffer.");
18158 vkSetEvent(m_device->device(), event);
18159 m_errorMonitor->VerifyFound();
18160 }
18161
18162 vkQueueWaitIdle(queue);
18163
18164 vkDestroyEvent(m_device->device(), event, nullptr);
18165 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
18166 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18167}
18168
18169// This is a positive test. No errors should be generated.
18170TEST_F(VkPositiveLayerTest, TwoFencesThreeFrames) {
18171 TEST_DESCRIPTION("Two command buffers with two separate fences are each "
18172 "run through a Submit & WaitForFences cycle 3 times. This "
18173 "previously revealed a bug so running this positive test "
18174 "to prevent a regression.");
18175 m_errorMonitor->ExpectSuccess();
18176
18177 ASSERT_NO_FATAL_FAILURE(InitState());
18178 VkQueue queue = VK_NULL_HANDLE;
18179 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
18180
18181 static const uint32_t NUM_OBJECTS = 2;
18182 static const uint32_t NUM_FRAMES = 3;
18183 VkCommandBuffer cmd_buffers[NUM_OBJECTS] = {};
18184 VkFence fences[NUM_OBJECTS] = {};
18185
18186 VkCommandPool cmd_pool;
18187 VkCommandPoolCreateInfo cmd_pool_ci = {};
18188 cmd_pool_ci.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18189 cmd_pool_ci.queueFamilyIndex = m_device->graphics_queue_node_index_;
18190 cmd_pool_ci.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18191 VkResult err = vkCreateCommandPool(m_device->device(), &cmd_pool_ci, nullptr, &cmd_pool);
18192 ASSERT_VK_SUCCESS(err);
18193
18194 VkCommandBufferAllocateInfo cmd_buf_info = {};
18195 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18196 cmd_buf_info.commandPool = cmd_pool;
18197 cmd_buf_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18198 cmd_buf_info.commandBufferCount = 1;
18199
18200 VkFenceCreateInfo fence_ci = {};
18201 fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18202 fence_ci.pNext = nullptr;
18203 fence_ci.flags = 0;
18204
18205 for (uint32_t i = 0; i < NUM_OBJECTS; ++i) {
18206 err = vkAllocateCommandBuffers(m_device->device(), &cmd_buf_info, &cmd_buffers[i]);
18207 ASSERT_VK_SUCCESS(err);
18208 err = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fences[i]);
18209 ASSERT_VK_SUCCESS(err);
18210 }
18211
18212 for (uint32_t frame = 0; frame < NUM_FRAMES; ++frame) {
18213 for (uint32_t obj = 0; obj < NUM_OBJECTS; ++obj) {
18214 // Create empty cmd buffer
18215 VkCommandBufferBeginInfo cmdBufBeginDesc = {};
18216 cmdBufBeginDesc.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18217
18218 err = vkBeginCommandBuffer(cmd_buffers[obj], &cmdBufBeginDesc);
18219 ASSERT_VK_SUCCESS(err);
18220 err = vkEndCommandBuffer(cmd_buffers[obj]);
18221 ASSERT_VK_SUCCESS(err);
18222
18223 VkSubmitInfo submit_info = {};
18224 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18225 submit_info.commandBufferCount = 1;
18226 submit_info.pCommandBuffers = &cmd_buffers[obj];
18227 // Submit cmd buffer and wait for fence
18228 err = vkQueueSubmit(queue, 1, &submit_info, fences[obj]);
18229 ASSERT_VK_SUCCESS(err);
18230 err = vkWaitForFences(m_device->device(), 1, &fences[obj], VK_TRUE, UINT64_MAX);
18231 ASSERT_VK_SUCCESS(err);
18232 err = vkResetFences(m_device->device(), 1, &fences[obj]);
18233 ASSERT_VK_SUCCESS(err);
18234 }
18235 }
18236 m_errorMonitor->VerifyNotFound();
18237 vkDestroyCommandPool(m_device->device(), cmd_pool, NULL);
18238 for (uint32_t i = 0; i < NUM_OBJECTS; ++i) {
18239 vkDestroyFence(m_device->device(), fences[i], nullptr);
18240 }
18241}
18242// This is a positive test. No errors should be generated.
18243TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWI) {
18244
18245 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
18246 "submitted on separate queues followed by a QueueWaitIdle.");
18247
18248 ASSERT_NO_FATAL_FAILURE(InitState());
18249 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
18250 return;
18251
18252 m_errorMonitor->ExpectSuccess();
18253
18254 VkSemaphore semaphore;
18255 VkSemaphoreCreateInfo semaphore_create_info{};
18256 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
18257 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
18258
18259 VkCommandPool command_pool;
18260 VkCommandPoolCreateInfo pool_create_info{};
18261 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18262 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18263 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18264 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18265
18266 VkCommandBuffer command_buffer[2];
18267 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18268 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18269 command_buffer_allocate_info.commandPool = command_pool;
18270 command_buffer_allocate_info.commandBufferCount = 2;
18271 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18272 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18273
18274 VkQueue queue = VK_NULL_HANDLE;
18275 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
18276
18277 {
18278 VkCommandBufferBeginInfo begin_info{};
18279 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18280 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18281
18282 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
18283 nullptr, 0, nullptr, 0, nullptr);
18284
18285 VkViewport viewport{};
18286 viewport.maxDepth = 1.0f;
18287 viewport.minDepth = 0.0f;
18288 viewport.width = 512;
18289 viewport.height = 512;
18290 viewport.x = 0;
18291 viewport.y = 0;
18292 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
18293 vkEndCommandBuffer(command_buffer[0]);
18294 }
18295 {
18296 VkCommandBufferBeginInfo begin_info{};
18297 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18298 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18299
18300 VkViewport viewport{};
18301 viewport.maxDepth = 1.0f;
18302 viewport.minDepth = 0.0f;
18303 viewport.width = 512;
18304 viewport.height = 512;
18305 viewport.x = 0;
18306 viewport.y = 0;
18307 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
18308 vkEndCommandBuffer(command_buffer[1]);
18309 }
18310 {
18311 VkSubmitInfo submit_info{};
18312 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18313 submit_info.commandBufferCount = 1;
18314 submit_info.pCommandBuffers = &command_buffer[0];
18315 submit_info.signalSemaphoreCount = 1;
18316 submit_info.pSignalSemaphores = &semaphore;
18317 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
18318 }
18319 {
18320 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
18321 VkSubmitInfo submit_info{};
18322 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18323 submit_info.commandBufferCount = 1;
18324 submit_info.pCommandBuffers = &command_buffer[1];
18325 submit_info.waitSemaphoreCount = 1;
18326 submit_info.pWaitSemaphores = &semaphore;
18327 submit_info.pWaitDstStageMask = flags;
18328 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
18329 }
18330
18331 vkQueueWaitIdle(m_device->m_queue);
18332
18333 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
18334 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
18335 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18336
18337 m_errorMonitor->VerifyNotFound();
18338}
18339
18340// This is a positive test. No errors should be generated.
18341TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWIFence) {
18342
18343 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
18344 "submitted on separate queues, the second having a fence"
18345 "followed by a QueueWaitIdle.");
18346
18347 ASSERT_NO_FATAL_FAILURE(InitState());
18348 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
18349 return;
18350
18351 m_errorMonitor->ExpectSuccess();
18352
18353 VkFence fence;
18354 VkFenceCreateInfo fence_create_info{};
18355 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18356 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
18357
18358 VkSemaphore semaphore;
18359 VkSemaphoreCreateInfo semaphore_create_info{};
18360 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
18361 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
18362
18363 VkCommandPool command_pool;
18364 VkCommandPoolCreateInfo pool_create_info{};
18365 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18366 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18367 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18368 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18369
18370 VkCommandBuffer command_buffer[2];
18371 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18372 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18373 command_buffer_allocate_info.commandPool = command_pool;
18374 command_buffer_allocate_info.commandBufferCount = 2;
18375 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18376 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18377
18378 VkQueue queue = VK_NULL_HANDLE;
18379 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
18380
18381 {
18382 VkCommandBufferBeginInfo begin_info{};
18383 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18384 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18385
18386 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
18387 nullptr, 0, nullptr, 0, nullptr);
18388
18389 VkViewport viewport{};
18390 viewport.maxDepth = 1.0f;
18391 viewport.minDepth = 0.0f;
18392 viewport.width = 512;
18393 viewport.height = 512;
18394 viewport.x = 0;
18395 viewport.y = 0;
18396 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
18397 vkEndCommandBuffer(command_buffer[0]);
18398 }
18399 {
18400 VkCommandBufferBeginInfo begin_info{};
18401 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18402 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18403
18404 VkViewport viewport{};
18405 viewport.maxDepth = 1.0f;
18406 viewport.minDepth = 0.0f;
18407 viewport.width = 512;
18408 viewport.height = 512;
18409 viewport.x = 0;
18410 viewport.y = 0;
18411 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
18412 vkEndCommandBuffer(command_buffer[1]);
18413 }
18414 {
18415 VkSubmitInfo submit_info{};
18416 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18417 submit_info.commandBufferCount = 1;
18418 submit_info.pCommandBuffers = &command_buffer[0];
18419 submit_info.signalSemaphoreCount = 1;
18420 submit_info.pSignalSemaphores = &semaphore;
18421 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
18422 }
18423 {
18424 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
18425 VkSubmitInfo submit_info{};
18426 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18427 submit_info.commandBufferCount = 1;
18428 submit_info.pCommandBuffers = &command_buffer[1];
18429 submit_info.waitSemaphoreCount = 1;
18430 submit_info.pWaitSemaphores = &semaphore;
18431 submit_info.pWaitDstStageMask = flags;
18432 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
18433 }
18434
18435 vkQueueWaitIdle(m_device->m_queue);
18436
18437 vkDestroyFence(m_device->device(), fence, nullptr);
18438 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
18439 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
18440 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18441
18442 m_errorMonitor->VerifyNotFound();
18443}
18444
18445// This is a positive test. No errors should be generated.
18446TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceTwoWFF) {
18447
18448 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
18449 "submitted on separate queues, the second having a fence"
18450 "followed by two consecutive WaitForFences calls on the same fence.");
18451
18452 ASSERT_NO_FATAL_FAILURE(InitState());
18453 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
18454 return;
18455
18456 m_errorMonitor->ExpectSuccess();
18457
18458 VkFence fence;
18459 VkFenceCreateInfo fence_create_info{};
18460 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18461 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
18462
18463 VkSemaphore semaphore;
18464 VkSemaphoreCreateInfo semaphore_create_info{};
18465 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
18466 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
18467
18468 VkCommandPool command_pool;
18469 VkCommandPoolCreateInfo pool_create_info{};
18470 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18471 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18472 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18473 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18474
18475 VkCommandBuffer command_buffer[2];
18476 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18477 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18478 command_buffer_allocate_info.commandPool = command_pool;
18479 command_buffer_allocate_info.commandBufferCount = 2;
18480 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18481 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18482
18483 VkQueue queue = VK_NULL_HANDLE;
18484 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
18485
18486 {
18487 VkCommandBufferBeginInfo begin_info{};
18488 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18489 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18490
18491 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
18492 nullptr, 0, nullptr, 0, nullptr);
18493
18494 VkViewport viewport{};
18495 viewport.maxDepth = 1.0f;
18496 viewport.minDepth = 0.0f;
18497 viewport.width = 512;
18498 viewport.height = 512;
18499 viewport.x = 0;
18500 viewport.y = 0;
18501 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
18502 vkEndCommandBuffer(command_buffer[0]);
18503 }
18504 {
18505 VkCommandBufferBeginInfo begin_info{};
18506 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18507 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18508
18509 VkViewport viewport{};
18510 viewport.maxDepth = 1.0f;
18511 viewport.minDepth = 0.0f;
18512 viewport.width = 512;
18513 viewport.height = 512;
18514 viewport.x = 0;
18515 viewport.y = 0;
18516 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
18517 vkEndCommandBuffer(command_buffer[1]);
18518 }
18519 {
18520 VkSubmitInfo submit_info{};
18521 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18522 submit_info.commandBufferCount = 1;
18523 submit_info.pCommandBuffers = &command_buffer[0];
18524 submit_info.signalSemaphoreCount = 1;
18525 submit_info.pSignalSemaphores = &semaphore;
18526 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
18527 }
18528 {
18529 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
18530 VkSubmitInfo submit_info{};
18531 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18532 submit_info.commandBufferCount = 1;
18533 submit_info.pCommandBuffers = &command_buffer[1];
18534 submit_info.waitSemaphoreCount = 1;
18535 submit_info.pWaitSemaphores = &semaphore;
18536 submit_info.pWaitDstStageMask = flags;
18537 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
18538 }
18539
18540 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
18541 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
18542
18543 vkDestroyFence(m_device->device(), fence, nullptr);
18544 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
18545 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
18546 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18547
18548 m_errorMonitor->VerifyNotFound();
18549}
18550
18551TEST_F(VkPositiveLayerTest, TwoQueuesEnsureCorrectRetirementWithWorkStolen) {
18552
18553 ASSERT_NO_FATAL_FAILURE(InitState());
18554 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) {
18555 printf("Test requires two queues, skipping\n");
18556 return;
18557 }
18558
18559 VkResult err;
18560
18561 m_errorMonitor->ExpectSuccess();
18562
18563 VkQueue q0 = m_device->m_queue;
18564 VkQueue q1 = nullptr;
18565 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &q1);
18566 ASSERT_NE(q1, nullptr);
18567
18568 // An (empty) command buffer. We must have work in the first submission --
18569 // the layer treats unfenced work differently from fenced work.
18570 VkCommandPoolCreateInfo cpci = { VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, nullptr, 0, 0 };
18571 VkCommandPool pool;
18572 err = vkCreateCommandPool(m_device->device(), &cpci, nullptr, &pool);
18573 ASSERT_VK_SUCCESS(err);
18574 VkCommandBufferAllocateInfo cbai = { VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, nullptr, pool,
18575 VK_COMMAND_BUFFER_LEVEL_PRIMARY, 1 };
18576 VkCommandBuffer cb;
18577 err = vkAllocateCommandBuffers(m_device->device(), &cbai, &cb);
18578 ASSERT_VK_SUCCESS(err);
18579 VkCommandBufferBeginInfo cbbi = { VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr, 0, nullptr };
18580 err = vkBeginCommandBuffer(cb, &cbbi);
18581 ASSERT_VK_SUCCESS(err);
18582 err = vkEndCommandBuffer(cb);
18583 ASSERT_VK_SUCCESS(err);
18584
18585 // A semaphore
18586 VkSemaphoreCreateInfo sci = { VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0 };
18587 VkSemaphore s;
18588 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s);
18589 ASSERT_VK_SUCCESS(err);
18590
18591 // First submission, to q0
18592 VkSubmitInfo s0 = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 1, &cb, 1, &s };
18593
18594 err = vkQueueSubmit(q0, 1, &s0, VK_NULL_HANDLE);
18595 ASSERT_VK_SUCCESS(err);
18596
18597 // Second submission, to q1, waiting on s
18598 VkFlags waitmask = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT; // doesn't really matter what this value is.
18599 VkSubmitInfo s1 = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 1, &s, &waitmask, 0, nullptr, 0, nullptr };
18600
18601 err = vkQueueSubmit(q1, 1, &s1, VK_NULL_HANDLE);
18602 ASSERT_VK_SUCCESS(err);
18603
18604 // Wait for q0 idle
18605 err = vkQueueWaitIdle(q0);
18606 ASSERT_VK_SUCCESS(err);
18607
18608 // Command buffer should have been completed (it was on q0); reset the pool.
18609 vkFreeCommandBuffers(m_device->device(), pool, 1, &cb);
18610
18611 m_errorMonitor->VerifyNotFound();
18612
18613 // Force device completely idle and clean up resources
18614 vkDeviceWaitIdle(m_device->device());
18615 vkDestroyCommandPool(m_device->device(), pool, nullptr);
18616 vkDestroySemaphore(m_device->device(), s, nullptr);
18617}
18618
18619// This is a positive test. No errors should be generated.
18620TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFence) {
18621
18622 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
18623 "submitted on separate queues, the second having a fence, "
18624 "followed by a WaitForFences call.");
18625
18626 ASSERT_NO_FATAL_FAILURE(InitState());
18627 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
18628 return;
18629
18630 m_errorMonitor->ExpectSuccess();
18631
18632 ASSERT_NO_FATAL_FAILURE(InitState());
18633 VkFence fence;
18634 VkFenceCreateInfo fence_create_info{};
18635 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18636 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
18637
18638 VkSemaphore semaphore;
18639 VkSemaphoreCreateInfo semaphore_create_info{};
18640 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
18641 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
18642
18643 VkCommandPool command_pool;
18644 VkCommandPoolCreateInfo pool_create_info{};
18645 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18646 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18647 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18648 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18649
18650 VkCommandBuffer command_buffer[2];
18651 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18652 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18653 command_buffer_allocate_info.commandPool = command_pool;
18654 command_buffer_allocate_info.commandBufferCount = 2;
18655 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18656 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18657
18658 VkQueue queue = VK_NULL_HANDLE;
18659 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
18660
18661 {
18662 VkCommandBufferBeginInfo begin_info{};
18663 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18664 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18665
18666 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
18667 nullptr, 0, nullptr, 0, nullptr);
18668
18669 VkViewport viewport{};
18670 viewport.maxDepth = 1.0f;
18671 viewport.minDepth = 0.0f;
18672 viewport.width = 512;
18673 viewport.height = 512;
18674 viewport.x = 0;
18675 viewport.y = 0;
18676 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
18677 vkEndCommandBuffer(command_buffer[0]);
18678 }
18679 {
18680 VkCommandBufferBeginInfo begin_info{};
18681 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18682 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18683
18684 VkViewport viewport{};
18685 viewport.maxDepth = 1.0f;
18686 viewport.minDepth = 0.0f;
18687 viewport.width = 512;
18688 viewport.height = 512;
18689 viewport.x = 0;
18690 viewport.y = 0;
18691 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
18692 vkEndCommandBuffer(command_buffer[1]);
18693 }
18694 {
18695 VkSubmitInfo submit_info{};
18696 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18697 submit_info.commandBufferCount = 1;
18698 submit_info.pCommandBuffers = &command_buffer[0];
18699 submit_info.signalSemaphoreCount = 1;
18700 submit_info.pSignalSemaphores = &semaphore;
18701 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
18702 }
18703 {
18704 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
18705 VkSubmitInfo submit_info{};
18706 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18707 submit_info.commandBufferCount = 1;
18708 submit_info.pCommandBuffers = &command_buffer[1];
18709 submit_info.waitSemaphoreCount = 1;
18710 submit_info.pWaitSemaphores = &semaphore;
18711 submit_info.pWaitDstStageMask = flags;
18712 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
18713 }
18714
18715 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
18716
18717 vkDestroyFence(m_device->device(), fence, nullptr);
18718 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
18719 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
18720 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18721
18722 m_errorMonitor->VerifyNotFound();
18723}
18724
18725// This is a positive test. No errors should be generated.
18726TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueWithSemaphoreAndOneFence) {
18727
18728 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
18729 "on the same queue, sharing a signal/wait semaphore, the "
18730 "second having a fence, "
18731 "followed by a WaitForFences call.");
18732
18733 m_errorMonitor->ExpectSuccess();
18734
18735 ASSERT_NO_FATAL_FAILURE(InitState());
18736 VkFence fence;
18737 VkFenceCreateInfo fence_create_info{};
18738 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18739 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
18740
18741 VkSemaphore semaphore;
18742 VkSemaphoreCreateInfo semaphore_create_info{};
18743 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
18744 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
18745
18746 VkCommandPool command_pool;
18747 VkCommandPoolCreateInfo pool_create_info{};
18748 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18749 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18750 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18751 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18752
18753 VkCommandBuffer command_buffer[2];
18754 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18755 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18756 command_buffer_allocate_info.commandPool = command_pool;
18757 command_buffer_allocate_info.commandBufferCount = 2;
18758 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18759 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18760
18761 {
18762 VkCommandBufferBeginInfo begin_info{};
18763 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18764 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18765
18766 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
18767 nullptr, 0, nullptr, 0, nullptr);
18768
18769 VkViewport viewport{};
18770 viewport.maxDepth = 1.0f;
18771 viewport.minDepth = 0.0f;
18772 viewport.width = 512;
18773 viewport.height = 512;
18774 viewport.x = 0;
18775 viewport.y = 0;
18776 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
18777 vkEndCommandBuffer(command_buffer[0]);
18778 }
18779 {
18780 VkCommandBufferBeginInfo begin_info{};
18781 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18782 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18783
18784 VkViewport viewport{};
18785 viewport.maxDepth = 1.0f;
18786 viewport.minDepth = 0.0f;
18787 viewport.width = 512;
18788 viewport.height = 512;
18789 viewport.x = 0;
18790 viewport.y = 0;
18791 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
18792 vkEndCommandBuffer(command_buffer[1]);
18793 }
18794 {
18795 VkSubmitInfo submit_info{};
18796 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18797 submit_info.commandBufferCount = 1;
18798 submit_info.pCommandBuffers = &command_buffer[0];
18799 submit_info.signalSemaphoreCount = 1;
18800 submit_info.pSignalSemaphores = &semaphore;
18801 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
18802 }
18803 {
18804 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
18805 VkSubmitInfo submit_info{};
18806 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18807 submit_info.commandBufferCount = 1;
18808 submit_info.pCommandBuffers = &command_buffer[1];
18809 submit_info.waitSemaphoreCount = 1;
18810 submit_info.pWaitSemaphores = &semaphore;
18811 submit_info.pWaitDstStageMask = flags;
18812 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
18813 }
18814
18815 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
18816
18817 vkDestroyFence(m_device->device(), fence, nullptr);
18818 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
18819 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
18820 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18821
18822 m_errorMonitor->VerifyNotFound();
18823}
18824
18825// This is a positive test. No errors should be generated.
18826TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueNullQueueSubmitWithFence) {
18827
18828 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
18829 "on the same queue, no fences, followed by a third QueueSubmit with NO "
18830 "SubmitInfos but with a fence, followed by a WaitForFences call.");
18831
18832 m_errorMonitor->ExpectSuccess();
18833
18834 ASSERT_NO_FATAL_FAILURE(InitState());
18835 VkFence fence;
18836 VkFenceCreateInfo fence_create_info{};
18837 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18838 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
18839
18840 VkCommandPool command_pool;
18841 VkCommandPoolCreateInfo pool_create_info{};
18842 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18843 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18844 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18845 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18846
18847 VkCommandBuffer command_buffer[2];
18848 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18849 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18850 command_buffer_allocate_info.commandPool = command_pool;
18851 command_buffer_allocate_info.commandBufferCount = 2;
18852 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18853 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18854
18855 {
18856 VkCommandBufferBeginInfo begin_info{};
18857 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18858 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18859
18860 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
18861 nullptr, 0, nullptr, 0, nullptr);
18862
18863 VkViewport viewport{};
18864 viewport.maxDepth = 1.0f;
18865 viewport.minDepth = 0.0f;
18866 viewport.width = 512;
18867 viewport.height = 512;
18868 viewport.x = 0;
18869 viewport.y = 0;
18870 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
18871 vkEndCommandBuffer(command_buffer[0]);
18872 }
18873 {
18874 VkCommandBufferBeginInfo begin_info{};
18875 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18876 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18877
18878 VkViewport viewport{};
18879 viewport.maxDepth = 1.0f;
18880 viewport.minDepth = 0.0f;
18881 viewport.width = 512;
18882 viewport.height = 512;
18883 viewport.x = 0;
18884 viewport.y = 0;
18885 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
18886 vkEndCommandBuffer(command_buffer[1]);
18887 }
18888 {
18889 VkSubmitInfo submit_info{};
18890 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18891 submit_info.commandBufferCount = 1;
18892 submit_info.pCommandBuffers = &command_buffer[0];
18893 submit_info.signalSemaphoreCount = 0;
18894 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
18895 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
18896 }
18897 {
18898 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
18899 VkSubmitInfo submit_info{};
18900 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18901 submit_info.commandBufferCount = 1;
18902 submit_info.pCommandBuffers = &command_buffer[1];
18903 submit_info.waitSemaphoreCount = 0;
18904 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
18905 submit_info.pWaitDstStageMask = flags;
18906 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
18907 }
18908
18909 vkQueueSubmit(m_device->m_queue, 0, NULL, fence);
18910
18911 VkResult err = vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
18912 ASSERT_VK_SUCCESS(err);
18913
18914 vkDestroyFence(m_device->device(), fence, nullptr);
18915 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
18916 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18917
18918 m_errorMonitor->VerifyNotFound();
18919}
18920
18921// This is a positive test. No errors should be generated.
18922TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueOneFence) {
18923
18924 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
18925 "on the same queue, the second having a fence, followed "
18926 "by a WaitForFences call.");
18927
18928 m_errorMonitor->ExpectSuccess();
18929
18930 ASSERT_NO_FATAL_FAILURE(InitState());
18931 VkFence fence;
18932 VkFenceCreateInfo fence_create_info{};
18933 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18934 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
18935
18936 VkCommandPool command_pool;
18937 VkCommandPoolCreateInfo pool_create_info{};
18938 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18939 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18940 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18941 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18942
18943 VkCommandBuffer command_buffer[2];
18944 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18945 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18946 command_buffer_allocate_info.commandPool = command_pool;
18947 command_buffer_allocate_info.commandBufferCount = 2;
18948 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18949 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18950
18951 {
18952 VkCommandBufferBeginInfo begin_info{};
18953 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18954 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18955
18956 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
18957 nullptr, 0, nullptr, 0, nullptr);
18958
18959 VkViewport viewport{};
18960 viewport.maxDepth = 1.0f;
18961 viewport.minDepth = 0.0f;
18962 viewport.width = 512;
18963 viewport.height = 512;
18964 viewport.x = 0;
18965 viewport.y = 0;
18966 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
18967 vkEndCommandBuffer(command_buffer[0]);
18968 }
18969 {
18970 VkCommandBufferBeginInfo begin_info{};
18971 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18972 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18973
18974 VkViewport viewport{};
18975 viewport.maxDepth = 1.0f;
18976 viewport.minDepth = 0.0f;
18977 viewport.width = 512;
18978 viewport.height = 512;
18979 viewport.x = 0;
18980 viewport.y = 0;
18981 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
18982 vkEndCommandBuffer(command_buffer[1]);
18983 }
18984 {
18985 VkSubmitInfo submit_info{};
18986 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18987 submit_info.commandBufferCount = 1;
18988 submit_info.pCommandBuffers = &command_buffer[0];
18989 submit_info.signalSemaphoreCount = 0;
18990 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
18991 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
18992 }
18993 {
18994 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
18995 VkSubmitInfo submit_info{};
18996 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18997 submit_info.commandBufferCount = 1;
18998 submit_info.pCommandBuffers = &command_buffer[1];
18999 submit_info.waitSemaphoreCount = 0;
19000 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
19001 submit_info.pWaitDstStageMask = flags;
19002 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
19003 }
19004
19005 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
19006
19007 vkDestroyFence(m_device->device(), fence, nullptr);
19008 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
19009 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
19010
19011 m_errorMonitor->VerifyNotFound();
19012}
19013
19014// This is a positive test. No errors should be generated.
19015TEST_F(VkPositiveLayerTest, TwoSubmitInfosWithSemaphoreOneQueueSubmitsOneFence) {
19016
19017 TEST_DESCRIPTION("Two command buffers each in a separate SubmitInfo sent in a single "
19018 "QueueSubmit call followed by a WaitForFences call.");
19019 ASSERT_NO_FATAL_FAILURE(InitState());
19020
19021 m_errorMonitor->ExpectSuccess();
19022
19023 VkFence fence;
19024 VkFenceCreateInfo fence_create_info{};
19025 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
19026 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
19027
19028 VkSemaphore semaphore;
19029 VkSemaphoreCreateInfo semaphore_create_info{};
19030 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
19031 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
19032
19033 VkCommandPool command_pool;
19034 VkCommandPoolCreateInfo pool_create_info{};
19035 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
19036 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
19037 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
19038 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
19039
19040 VkCommandBuffer command_buffer[2];
19041 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
19042 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
19043 command_buffer_allocate_info.commandPool = command_pool;
19044 command_buffer_allocate_info.commandBufferCount = 2;
19045 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
19046 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
19047
19048 {
19049 VkCommandBufferBeginInfo begin_info{};
19050 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19051 vkBeginCommandBuffer(command_buffer[0], &begin_info);
19052
19053 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
19054 nullptr, 0, nullptr, 0, nullptr);
19055
19056 VkViewport viewport{};
19057 viewport.maxDepth = 1.0f;
19058 viewport.minDepth = 0.0f;
19059 viewport.width = 512;
19060 viewport.height = 512;
19061 viewport.x = 0;
19062 viewport.y = 0;
19063 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
19064 vkEndCommandBuffer(command_buffer[0]);
19065 }
19066 {
19067 VkCommandBufferBeginInfo begin_info{};
19068 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19069 vkBeginCommandBuffer(command_buffer[1], &begin_info);
19070
19071 VkViewport viewport{};
19072 viewport.maxDepth = 1.0f;
19073 viewport.minDepth = 0.0f;
19074 viewport.width = 512;
19075 viewport.height = 512;
19076 viewport.x = 0;
19077 viewport.y = 0;
19078 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
19079 vkEndCommandBuffer(command_buffer[1]);
19080 }
19081 {
19082 VkSubmitInfo submit_info[2];
19083 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
19084
19085 submit_info[0].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19086 submit_info[0].pNext = NULL;
19087 submit_info[0].commandBufferCount = 1;
19088 submit_info[0].pCommandBuffers = &command_buffer[0];
19089 submit_info[0].signalSemaphoreCount = 1;
19090 submit_info[0].pSignalSemaphores = &semaphore;
19091 submit_info[0].waitSemaphoreCount = 0;
19092 submit_info[0].pWaitSemaphores = NULL;
19093 submit_info[0].pWaitDstStageMask = 0;
19094
19095 submit_info[1].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19096 submit_info[1].pNext = NULL;
19097 submit_info[1].commandBufferCount = 1;
19098 submit_info[1].pCommandBuffers = &command_buffer[1];
19099 submit_info[1].waitSemaphoreCount = 1;
19100 submit_info[1].pWaitSemaphores = &semaphore;
19101 submit_info[1].pWaitDstStageMask = flags;
19102 submit_info[1].signalSemaphoreCount = 0;
19103 submit_info[1].pSignalSemaphores = NULL;
19104 vkQueueSubmit(m_device->m_queue, 2, &submit_info[0], fence);
19105 }
19106
19107 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
19108
19109 vkDestroyFence(m_device->device(), fence, nullptr);
19110 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
19111 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
19112 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
19113
19114 m_errorMonitor->VerifyNotFound();
19115}
19116
19117TEST_F(VkPositiveLayerTest, RenderPassSecondaryCommandBuffersMultipleTimes) {
19118 m_errorMonitor->ExpectSuccess();
19119
19120 ASSERT_NO_FATAL_FAILURE(InitState());
19121 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19122
19123 BeginCommandBuffer(); // Framework implicitly begins the renderpass.
19124 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle()); // End implicit.
19125
19126 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
19127 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
19128 m_errorMonitor->VerifyNotFound();
19129 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
19130 m_errorMonitor->VerifyNotFound();
19131 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
19132 m_errorMonitor->VerifyNotFound();
19133
19134 m_commandBuffer->EndCommandBuffer();
19135 m_errorMonitor->VerifyNotFound();
19136}
19137
19138TEST_F(VkPositiveLayerTest, ValidRenderPassAttachmentLayoutWithLoadOp) {
19139 TEST_DESCRIPTION("Positive test where we create a renderpass with an "
19140 "attachment that uses LOAD_OP_CLEAR, the first subpass "
19141 "has a valid layout, and a second subpass then uses a "
19142 "valid *READ_ONLY* layout.");
19143 m_errorMonitor->ExpectSuccess();
19144 ASSERT_NO_FATAL_FAILURE(InitState());
19145
19146 VkAttachmentReference attach[2] = {};
19147 attach[0].attachment = 0;
19148 attach[0].layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
19149 attach[1].attachment = 0;
19150 attach[1].layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
19151 VkSubpassDescription subpasses[2] = {};
19152 // First subpass clears DS attach on load
19153 subpasses[0].pDepthStencilAttachment = &attach[0];
19154 // 2nd subpass reads in DS as input attachment
19155 subpasses[1].inputAttachmentCount = 1;
19156 subpasses[1].pInputAttachments = &attach[1];
19157 VkAttachmentDescription attach_desc = {};
19158 attach_desc.format = VK_FORMAT_D24_UNORM_S8_UINT;
19159 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
19160 attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
19161 attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
19162 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
19163 attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
19164 attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
19165 attach_desc.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
19166 VkRenderPassCreateInfo rpci = {};
19167 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
19168 rpci.attachmentCount = 1;
19169 rpci.pAttachments = &attach_desc;
19170 rpci.subpassCount = 2;
19171 rpci.pSubpasses = subpasses;
19172
19173 // Now create RenderPass and verify no errors
19174 VkRenderPass rp;
19175 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
19176 m_errorMonitor->VerifyNotFound();
19177
19178 vkDestroyRenderPass(m_device->device(), rp, NULL);
19179}
19180
19181TEST_F(VkPositiveLayerTest, CreatePipelineAttribMatrixType) {
19182 TEST_DESCRIPTION("Test that pipeline validation accepts matrices passed "
19183 "as vertex attributes");
19184 m_errorMonitor->ExpectSuccess();
19185
19186 ASSERT_NO_FATAL_FAILURE(InitState());
19187 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19188
19189 VkVertexInputBindingDescription input_binding;
19190 memset(&input_binding, 0, sizeof(input_binding));
19191
19192 VkVertexInputAttributeDescription input_attribs[2];
19193 memset(input_attribs, 0, sizeof(input_attribs));
19194
19195 for (int i = 0; i < 2; i++) {
19196 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
19197 input_attribs[i].location = i;
19198 }
19199
19200 char const *vsSource = "#version 450\n"
19201 "\n"
19202 "layout(location=0) in mat2x4 x;\n"
19203 "out gl_PerVertex {\n"
19204 " vec4 gl_Position;\n"
19205 "};\n"
19206 "void main(){\n"
19207 " gl_Position = x[0] + x[1];\n"
19208 "}\n";
19209 char const *fsSource = "#version 450\n"
19210 "\n"
19211 "layout(location=0) out vec4 color;\n"
19212 "void main(){\n"
19213 " color = vec4(1);\n"
19214 "}\n";
19215
19216 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19217 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19218
19219 VkPipelineObj pipe(m_device);
19220 pipe.AddColorAttachment();
19221 pipe.AddShader(&vs);
19222 pipe.AddShader(&fs);
19223
19224 pipe.AddVertexInputBindings(&input_binding, 1);
19225 pipe.AddVertexInputAttribs(input_attribs, 2);
19226
19227 VkDescriptorSetObj descriptorSet(m_device);
19228 descriptorSet.AppendDummy();
19229 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19230
19231 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
19232
19233 /* expect success */
19234 m_errorMonitor->VerifyNotFound();
19235}
19236
19237TEST_F(VkPositiveLayerTest, CreatePipelineAttribArrayType) {
19238 m_errorMonitor->ExpectSuccess();
19239
19240 ASSERT_NO_FATAL_FAILURE(InitState());
19241 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19242
19243 VkVertexInputBindingDescription input_binding;
19244 memset(&input_binding, 0, sizeof(input_binding));
19245
19246 VkVertexInputAttributeDescription input_attribs[2];
19247 memset(input_attribs, 0, sizeof(input_attribs));
19248
19249 for (int i = 0; i < 2; i++) {
19250 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
19251 input_attribs[i].location = i;
19252 }
19253
19254 char const *vsSource = "#version 450\n"
19255 "\n"
19256 "layout(location=0) in vec4 x[2];\n"
19257 "out gl_PerVertex {\n"
19258 " vec4 gl_Position;\n"
19259 "};\n"
19260 "void main(){\n"
19261 " gl_Position = x[0] + x[1];\n"
19262 "}\n";
19263 char const *fsSource = "#version 450\n"
19264 "\n"
19265 "layout(location=0) out vec4 color;\n"
19266 "void main(){\n"
19267 " color = vec4(1);\n"
19268 "}\n";
19269
19270 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19271 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19272
19273 VkPipelineObj pipe(m_device);
19274 pipe.AddColorAttachment();
19275 pipe.AddShader(&vs);
19276 pipe.AddShader(&fs);
19277
19278 pipe.AddVertexInputBindings(&input_binding, 1);
19279 pipe.AddVertexInputAttribs(input_attribs, 2);
19280
19281 VkDescriptorSetObj descriptorSet(m_device);
19282 descriptorSet.AppendDummy();
19283 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19284
19285 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
19286
19287 m_errorMonitor->VerifyNotFound();
19288}
19289
19290TEST_F(VkPositiveLayerTest, CreatePipelineAttribComponents) {
19291 TEST_DESCRIPTION("Test that pipeline validation accepts consuming a vertex attribute "
19292 "through multiple vertex shader inputs, each consuming a different "
19293 "subset of the components.");
19294 m_errorMonitor->ExpectSuccess();
19295
19296 ASSERT_NO_FATAL_FAILURE(InitState());
19297 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19298
19299 VkVertexInputBindingDescription input_binding;
19300 memset(&input_binding, 0, sizeof(input_binding));
19301
19302 VkVertexInputAttributeDescription input_attribs[3];
19303 memset(input_attribs, 0, sizeof(input_attribs));
19304
19305 for (int i = 0; i < 3; i++) {
19306 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
19307 input_attribs[i].location = i;
19308 }
19309
19310 char const *vsSource = "#version 450\n"
19311 "\n"
19312 "layout(location=0) in vec4 x;\n"
19313 "layout(location=1) in vec3 y1;\n"
19314 "layout(location=1, component=3) in float y2;\n"
19315 "layout(location=2) in vec4 z;\n"
19316 "out gl_PerVertex {\n"
19317 " vec4 gl_Position;\n"
19318 "};\n"
19319 "void main(){\n"
19320 " gl_Position = x + vec4(y1, y2) + z;\n"
19321 "}\n";
19322 char const *fsSource = "#version 450\n"
19323 "\n"
19324 "layout(location=0) out vec4 color;\n"
19325 "void main(){\n"
19326 " color = vec4(1);\n"
19327 "}\n";
19328
19329 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19330 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19331
19332 VkPipelineObj pipe(m_device);
19333 pipe.AddColorAttachment();
19334 pipe.AddShader(&vs);
19335 pipe.AddShader(&fs);
19336
19337 pipe.AddVertexInputBindings(&input_binding, 1);
19338 pipe.AddVertexInputAttribs(input_attribs, 3);
19339
19340 VkDescriptorSetObj descriptorSet(m_device);
19341 descriptorSet.AppendDummy();
19342 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19343
19344 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
19345
19346 m_errorMonitor->VerifyNotFound();
19347}
19348
19349TEST_F(VkPositiveLayerTest, CreatePipelineSimplePositive) {
19350 m_errorMonitor->ExpectSuccess();
19351
19352 ASSERT_NO_FATAL_FAILURE(InitState());
19353 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19354
19355 char const *vsSource = "#version 450\n"
19356 "out gl_PerVertex {\n"
19357 " vec4 gl_Position;\n"
19358 "};\n"
19359 "void main(){\n"
19360 " gl_Position = vec4(0);\n"
19361 "}\n";
19362 char const *fsSource = "#version 450\n"
19363 "\n"
19364 "layout(location=0) out vec4 color;\n"
19365 "void main(){\n"
19366 " color = vec4(1);\n"
19367 "}\n";
19368
19369 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19370 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19371
19372 VkPipelineObj pipe(m_device);
19373 pipe.AddColorAttachment();
19374 pipe.AddShader(&vs);
19375 pipe.AddShader(&fs);
19376
19377 VkDescriptorSetObj descriptorSet(m_device);
19378 descriptorSet.AppendDummy();
19379 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19380
19381 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
19382
19383 m_errorMonitor->VerifyNotFound();
19384}
19385
19386TEST_F(VkPositiveLayerTest, CreatePipelineRelaxedTypeMatch) {
19387 TEST_DESCRIPTION("Test that pipeline validation accepts the relaxed type matching rules "
19388 "set out in 14.1.3: fundamental type must match, and producer side must "
19389 "have at least as many components");
19390 m_errorMonitor->ExpectSuccess();
19391
19392 // VK 1.0.8 Specification, 14.1.3 "Additionally,..." block
19393
19394 ASSERT_NO_FATAL_FAILURE(InitState());
19395 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19396
19397 char const *vsSource = "#version 450\n"
19398 "out gl_PerVertex {\n"
19399 " vec4 gl_Position;\n"
19400 "};\n"
19401 "layout(location=0) out vec3 x;\n"
19402 "layout(location=1) out ivec3 y;\n"
19403 "layout(location=2) out vec3 z;\n"
19404 "void main(){\n"
19405 " gl_Position = vec4(0);\n"
19406 " x = vec3(0); y = ivec3(0); z = vec3(0);\n"
19407 "}\n";
19408 char const *fsSource = "#version 450\n"
19409 "\n"
19410 "layout(location=0) out vec4 color;\n"
19411 "layout(location=0) in float x;\n"
19412 "layout(location=1) flat in int y;\n"
19413 "layout(location=2) in vec2 z;\n"
19414 "void main(){\n"
19415 " color = vec4(1 + x + y + z.x);\n"
19416 "}\n";
19417
19418 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19419 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19420
19421 VkPipelineObj pipe(m_device);
19422 pipe.AddColorAttachment();
19423 pipe.AddShader(&vs);
19424 pipe.AddShader(&fs);
19425
19426 VkDescriptorSetObj descriptorSet(m_device);
19427 descriptorSet.AppendDummy();
19428 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19429
19430 VkResult err = VK_SUCCESS;
19431 err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
19432 ASSERT_VK_SUCCESS(err);
19433
19434 m_errorMonitor->VerifyNotFound();
19435}
19436
19437TEST_F(VkPositiveLayerTest, CreatePipelineTessPerVertex) {
19438 TEST_DESCRIPTION("Test that pipeline validation accepts per-vertex variables "
19439 "passed between the TCS and TES stages");
19440 m_errorMonitor->ExpectSuccess();
19441
19442 ASSERT_NO_FATAL_FAILURE(InitState());
19443 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19444
19445 if (!m_device->phy().features().tessellationShader) {
19446 printf("Device does not support tessellation shaders; skipped.\n");
19447 return;
19448 }
19449
19450 char const *vsSource = "#version 450\n"
19451 "void main(){}\n";
19452 char const *tcsSource = "#version 450\n"
19453 "layout(location=0) out int x[];\n"
19454 "layout(vertices=3) out;\n"
19455 "void main(){\n"
19456 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
19457 " gl_TessLevelInner[0] = 1;\n"
19458 " x[gl_InvocationID] = gl_InvocationID;\n"
19459 "}\n";
19460 char const *tesSource = "#version 450\n"
19461 "layout(triangles, equal_spacing, cw) in;\n"
19462 "layout(location=0) in int x[];\n"
19463 "out gl_PerVertex { vec4 gl_Position; };\n"
19464 "void main(){\n"
19465 " gl_Position.xyz = gl_TessCoord;\n"
19466 " gl_Position.w = x[0] + x[1] + x[2];\n"
19467 "}\n";
19468 char const *fsSource = "#version 450\n"
19469 "layout(location=0) out vec4 color;\n"
19470 "void main(){\n"
19471 " color = vec4(1);\n"
19472 "}\n";
19473
19474 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19475 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
19476 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
19477 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19478
19479 VkPipelineInputAssemblyStateCreateInfo iasci{ VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, nullptr, 0,
19480 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, VK_FALSE };
19481
19482 VkPipelineTessellationStateCreateInfo tsci{ VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, nullptr, 0, 3 };
19483
19484 VkPipelineObj pipe(m_device);
19485 pipe.SetInputAssembly(&iasci);
19486 pipe.SetTessellation(&tsci);
19487 pipe.AddColorAttachment();
19488 pipe.AddShader(&vs);
19489 pipe.AddShader(&tcs);
19490 pipe.AddShader(&tes);
19491 pipe.AddShader(&fs);
19492
19493 VkDescriptorSetObj descriptorSet(m_device);
19494 descriptorSet.AppendDummy();
19495 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19496
19497 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
19498
19499 m_errorMonitor->VerifyNotFound();
19500}
19501
19502TEST_F(VkPositiveLayerTest, CreatePipelineGeometryInputBlockPositive) {
19503 TEST_DESCRIPTION("Test that pipeline validation accepts a user-defined "
19504 "interface block passed into the geometry shader. This "
19505 "is interesting because the 'extra' array level is not "
19506 "present on the member type, but on the block instance.");
19507 m_errorMonitor->ExpectSuccess();
19508
19509 ASSERT_NO_FATAL_FAILURE(InitState());
19510 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19511
19512 if (!m_device->phy().features().geometryShader) {
19513 printf("Device does not support geometry shaders; skipped.\n");
19514 return;
19515 }
19516
19517 char const *vsSource = "#version 450\n"
19518 "layout(location=0) out VertexData { vec4 x; } vs_out;\n"
19519 "void main(){\n"
19520 " vs_out.x = vec4(1);\n"
19521 "}\n";
19522 char const *gsSource = "#version 450\n"
19523 "layout(triangles) in;\n"
19524 "layout(triangle_strip, max_vertices=3) out;\n"
19525 "layout(location=0) in VertexData { vec4 x; } gs_in[];\n"
19526 "out gl_PerVertex { vec4 gl_Position; };\n"
19527 "void main() {\n"
19528 " gl_Position = gs_in[0].x;\n"
19529 " EmitVertex();\n"
19530 "}\n";
19531 char const *fsSource = "#version 450\n"
19532 "layout(location=0) out vec4 color;\n"
19533 "void main(){\n"
19534 " color = vec4(1);\n"
19535 "}\n";
19536
19537 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19538 VkShaderObj gs(m_device, gsSource, VK_SHADER_STAGE_GEOMETRY_BIT, this);
19539 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19540
19541 VkPipelineObj pipe(m_device);
19542 pipe.AddColorAttachment();
19543 pipe.AddShader(&vs);
19544 pipe.AddShader(&gs);
19545 pipe.AddShader(&fs);
19546
19547 VkDescriptorSetObj descriptorSet(m_device);
19548 descriptorSet.AppendDummy();
19549 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19550
19551 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
19552
19553 m_errorMonitor->VerifyNotFound();
19554}
19555
19556TEST_F(VkPositiveLayerTest, CreatePipeline64BitAttributesPositive) {
19557 TEST_DESCRIPTION("Test that pipeline validation accepts basic use of 64bit vertex "
19558 "attributes. This is interesting because they consume multiple "
19559 "locations.");
19560 m_errorMonitor->ExpectSuccess();
19561
19562 ASSERT_NO_FATAL_FAILURE(InitState());
19563 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19564
19565 if (!m_device->phy().features().shaderFloat64) {
19566 printf("Device does not support 64bit vertex attributes; skipped.\n");
19567 return;
19568 }
19569
19570 VkVertexInputBindingDescription input_bindings[1];
19571 memset(input_bindings, 0, sizeof(input_bindings));
19572
19573 VkVertexInputAttributeDescription input_attribs[4];
19574 memset(input_attribs, 0, sizeof(input_attribs));
19575 input_attribs[0].location = 0;
19576 input_attribs[0].offset = 0;
19577 input_attribs[0].format = VK_FORMAT_R64G64B64A64_SFLOAT;
19578 input_attribs[1].location = 2;
19579 input_attribs[1].offset = 32;
19580 input_attribs[1].format = VK_FORMAT_R64G64B64A64_SFLOAT;
19581 input_attribs[2].location = 4;
19582 input_attribs[2].offset = 64;
19583 input_attribs[2].format = VK_FORMAT_R64G64B64A64_SFLOAT;
19584 input_attribs[3].location = 6;
19585 input_attribs[3].offset = 96;
19586 input_attribs[3].format = VK_FORMAT_R64G64B64A64_SFLOAT;
19587
19588 char const *vsSource = "#version 450\n"
19589 "\n"
19590 "layout(location=0) in dmat4 x;\n"
19591 "out gl_PerVertex {\n"
19592 " vec4 gl_Position;\n"
19593 "};\n"
19594 "void main(){\n"
19595 " gl_Position = vec4(x[0][0]);\n"
19596 "}\n";
19597 char const *fsSource = "#version 450\n"
19598 "\n"
19599 "layout(location=0) out vec4 color;\n"
19600 "void main(){\n"
19601 " color = vec4(1);\n"
19602 "}\n";
19603
19604 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19605 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19606
19607 VkPipelineObj pipe(m_device);
19608 pipe.AddColorAttachment();
19609 pipe.AddShader(&vs);
19610 pipe.AddShader(&fs);
19611
19612 pipe.AddVertexInputBindings(input_bindings, 1);
19613 pipe.AddVertexInputAttribs(input_attribs, 4);
19614
19615 VkDescriptorSetObj descriptorSet(m_device);
19616 descriptorSet.AppendDummy();
19617 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19618
19619 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
19620
19621 m_errorMonitor->VerifyNotFound();
19622}
19623
19624TEST_F(VkPositiveLayerTest, CreatePipelineInputAttachmentPositive) {
19625 TEST_DESCRIPTION("Positive test for a correctly matched input attachment");
19626 m_errorMonitor->ExpectSuccess();
19627
19628 ASSERT_NO_FATAL_FAILURE(InitState());
19629
19630 char const *vsSource = "#version 450\n"
19631 "\n"
19632 "out gl_PerVertex {\n"
19633 " vec4 gl_Position;\n"
19634 "};\n"
19635 "void main(){\n"
19636 " gl_Position = vec4(1);\n"
19637 "}\n";
19638 char const *fsSource = "#version 450\n"
19639 "\n"
19640 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
19641 "layout(location=0) out vec4 color;\n"
19642 "void main() {\n"
19643 " color = subpassLoad(x);\n"
19644 "}\n";
19645
19646 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19647 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19648
19649 VkPipelineObj pipe(m_device);
19650 pipe.AddShader(&vs);
19651 pipe.AddShader(&fs);
19652 pipe.AddColorAttachment();
19653 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19654
19655 VkDescriptorSetLayoutBinding dslb = { 0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr };
19656 VkDescriptorSetLayoutCreateInfo dslci = { VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb };
19657 VkDescriptorSetLayout dsl;
19658 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
19659 ASSERT_VK_SUCCESS(err);
19660
19661 VkPipelineLayoutCreateInfo plci = { VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr };
19662 VkPipelineLayout pl;
19663 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
19664 ASSERT_VK_SUCCESS(err);
19665
19666 VkAttachmentDescription descs[2] = {
19667 { 0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
19668 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
19669 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL },
19670 { 0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
19671 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_GENERAL, VK_IMAGE_LAYOUT_GENERAL },
19672 };
19673 VkAttachmentReference color = {
19674 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
19675 };
19676 VkAttachmentReference input = {
19677 1, VK_IMAGE_LAYOUT_GENERAL,
19678 };
19679
19680 VkSubpassDescription sd = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 1, &input, 1, &color, nullptr, nullptr, 0, nullptr };
19681
19682 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, descs, 1, &sd, 0, nullptr };
19683 VkRenderPass rp;
19684 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
19685 ASSERT_VK_SUCCESS(err);
19686
19687 // should be OK. would go wrong here if it's going to...
19688 pipe.CreateVKPipeline(pl, rp);
19689
19690 m_errorMonitor->VerifyNotFound();
19691
19692 vkDestroyRenderPass(m_device->device(), rp, nullptr);
19693 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
19694 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
19695}
19696
19697TEST_F(VkPositiveLayerTest, CreateComputePipelineMissingDescriptorUnusedPositive) {
19698 TEST_DESCRIPTION("Test that pipeline validation accepts a compute pipeline which declares a "
19699 "descriptor-backed resource which is not provided, but the shader does not "
19700 "statically use it. This is interesting because it requires compute pipelines "
19701 "to have a proper descriptor use walk, which they didn't for some time.");
19702 m_errorMonitor->ExpectSuccess();
19703
19704 ASSERT_NO_FATAL_FAILURE(InitState());
19705
19706 char const *csSource = "#version 450\n"
19707 "\n"
19708 "layout(local_size_x=1) in;\n"
19709 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
19710 "void main(){\n"
19711 " // x is not used.\n"
19712 "}\n";
19713
19714 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
19715
19716 VkDescriptorSetObj descriptorSet(m_device);
19717 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19718
19719 VkComputePipelineCreateInfo cpci = { VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
19720 nullptr,
19721 0,
19722 { VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
19723 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr },
19724 descriptorSet.GetPipelineLayout(),
19725 VK_NULL_HANDLE,
19726 -1 };
19727
19728 VkPipeline pipe;
19729 VkResult err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
19730
19731 m_errorMonitor->VerifyNotFound();
19732
19733 if (err == VK_SUCCESS) {
19734 vkDestroyPipeline(m_device->device(), pipe, nullptr);
19735 }
19736}
19737
19738TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsSampler) {
19739 TEST_DESCRIPTION("Test that pipeline validation accepts a shader consuming only the "
19740 "sampler portion of a combined image + sampler");
19741 m_errorMonitor->ExpectSuccess();
19742
19743 ASSERT_NO_FATAL_FAILURE(InitState());
19744
19745 VkDescriptorSetLayoutBinding bindings[] = {
19746 { 0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
19747 { 1, VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
19748 { 2, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
19749 };
19750 VkDescriptorSetLayoutCreateInfo dslci = { VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 3, bindings };
19751 VkDescriptorSetLayout dsl;
19752 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
19753 ASSERT_VK_SUCCESS(err);
19754
19755 VkPipelineLayoutCreateInfo plci = { VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr };
19756 VkPipelineLayout pl;
19757 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
19758 ASSERT_VK_SUCCESS(err);
19759
19760 char const *csSource = "#version 450\n"
19761 "\n"
19762 "layout(local_size_x=1) in;\n"
19763 "layout(set=0, binding=0) uniform sampler s;\n"
19764 "layout(set=0, binding=1) uniform texture2D t;\n"
19765 "layout(set=0, binding=2) buffer block { vec4 x; };\n"
19766 "void main() {\n"
19767 " x = texture(sampler2D(t, s), vec2(0));\n"
19768 "}\n";
19769 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
19770
19771 VkComputePipelineCreateInfo cpci = { VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
19772 nullptr,
19773 0,
19774 { VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
19775 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr },
19776 pl,
19777 VK_NULL_HANDLE,
19778 -1 };
19779
19780 VkPipeline pipe;
19781 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
19782
19783 m_errorMonitor->VerifyNotFound();
19784
19785 if (err == VK_SUCCESS) {
19786 vkDestroyPipeline(m_device->device(), pipe, nullptr);
19787 }
19788
19789 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
19790 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
19791}
19792
19793TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsImage) {
19794 TEST_DESCRIPTION("Test that pipeline validation accepts a shader consuming only the "
19795 "image portion of a combined image + sampler");
19796 m_errorMonitor->ExpectSuccess();
19797
19798 ASSERT_NO_FATAL_FAILURE(InitState());
19799
19800 VkDescriptorSetLayoutBinding bindings[] = {
19801 { 0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
19802 { 1, VK_DESCRIPTOR_TYPE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
19803 { 2, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
19804 };
19805 VkDescriptorSetLayoutCreateInfo dslci = { VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 3, bindings };
19806 VkDescriptorSetLayout dsl;
19807 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
19808 ASSERT_VK_SUCCESS(err);
19809
19810 VkPipelineLayoutCreateInfo plci = { VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr };
19811 VkPipelineLayout pl;
19812 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
19813 ASSERT_VK_SUCCESS(err);
19814
19815 char const *csSource = "#version 450\n"
19816 "\n"
19817 "layout(local_size_x=1) in;\n"
19818 "layout(set=0, binding=0) uniform texture2D t;\n"
19819 "layout(set=0, binding=1) uniform sampler s;\n"
19820 "layout(set=0, binding=2) buffer block { vec4 x; };\n"
19821 "void main() {\n"
19822 " x = texture(sampler2D(t, s), vec2(0));\n"
19823 "}\n";
19824 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
19825
19826 VkComputePipelineCreateInfo cpci = { VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
19827 nullptr,
19828 0,
19829 { VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
19830 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr },
19831 pl,
19832 VK_NULL_HANDLE,
19833 -1 };
19834
19835 VkPipeline pipe;
19836 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
19837
19838 m_errorMonitor->VerifyNotFound();
19839
19840 if (err == VK_SUCCESS) {
19841 vkDestroyPipeline(m_device->device(), pipe, nullptr);
19842 }
19843
19844 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
19845 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
19846}
19847
19848TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsBoth) {
19849 TEST_DESCRIPTION("Test that pipeline validation accepts a shader consuming "
19850 "both the sampler and the image of a combined image+sampler "
19851 "but via separate variables");
19852 m_errorMonitor->ExpectSuccess();
19853
19854 ASSERT_NO_FATAL_FAILURE(InitState());
19855
19856 VkDescriptorSetLayoutBinding bindings[] = {
19857 { 0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
19858 { 1, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
19859 };
19860 VkDescriptorSetLayoutCreateInfo dslci = { VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 2, bindings };
19861 VkDescriptorSetLayout dsl;
19862 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
19863 ASSERT_VK_SUCCESS(err);
19864
19865 VkPipelineLayoutCreateInfo plci = { VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr };
19866 VkPipelineLayout pl;
19867 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
19868 ASSERT_VK_SUCCESS(err);
19869
19870 char const *csSource = "#version 450\n"
19871 "\n"
19872 "layout(local_size_x=1) in;\n"
19873 "layout(set=0, binding=0) uniform texture2D t;\n"
19874 "layout(set=0, binding=0) uniform sampler s; // both binding 0!\n"
19875 "layout(set=0, binding=1) buffer block { vec4 x; };\n"
19876 "void main() {\n"
19877 " x = texture(sampler2D(t, s), vec2(0));\n"
19878 "}\n";
19879 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
19880
19881 VkComputePipelineCreateInfo cpci = { VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
19882 nullptr,
19883 0,
19884 { VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
19885 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr },
19886 pl,
19887 VK_NULL_HANDLE,
19888 -1 };
19889
19890 VkPipeline pipe;
19891 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
19892
19893 m_errorMonitor->VerifyNotFound();
19894
19895 if (err == VK_SUCCESS) {
19896 vkDestroyPipeline(m_device->device(), pipe, nullptr);
19897 }
19898
19899 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
19900 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
19901}
19902
19903TEST_F(VkPositiveLayerTest, ValidStructPNext) {
19904 TEST_DESCRIPTION("Verify that a valid pNext value is handled correctly");
19905
19906 ASSERT_NO_FATAL_FAILURE(InitState());
19907
19908 // Positive test to check parameter_validation and unique_objects support
19909 // for NV_dedicated_allocation
19910 uint32_t extension_count = 0;
19911 bool supports_nv_dedicated_allocation = false;
19912 VkResult err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, nullptr);
19913 ASSERT_VK_SUCCESS(err);
19914
19915 if (extension_count > 0) {
19916 std::vector<VkExtensionProperties> available_extensions(extension_count);
19917
19918 err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, &available_extensions[0]);
19919 ASSERT_VK_SUCCESS(err);
19920
19921 for (const auto &extension_props : available_extensions) {
19922 if (strcmp(extension_props.extensionName, VK_NV_DEDICATED_ALLOCATION_EXTENSION_NAME) == 0) {
19923 supports_nv_dedicated_allocation = true;
19924 }
19925 }
19926 }
19927
19928 if (supports_nv_dedicated_allocation) {
19929 m_errorMonitor->ExpectSuccess();
19930
19931 VkDedicatedAllocationBufferCreateInfoNV dedicated_buffer_create_info = {};
19932 dedicated_buffer_create_info.sType = VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_BUFFER_CREATE_INFO_NV;
19933 dedicated_buffer_create_info.pNext = nullptr;
19934 dedicated_buffer_create_info.dedicatedAllocation = VK_TRUE;
19935
19936 uint32_t queue_family_index = 0;
19937 VkBufferCreateInfo buffer_create_info = {};
19938 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
19939 buffer_create_info.pNext = &dedicated_buffer_create_info;
19940 buffer_create_info.size = 1024;
19941 buffer_create_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
19942 buffer_create_info.queueFamilyIndexCount = 1;
19943 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
19944
19945 VkBuffer buffer;
19946 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
19947 ASSERT_VK_SUCCESS(err);
19948
19949 VkMemoryRequirements memory_reqs;
19950 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
19951
19952 VkDedicatedAllocationMemoryAllocateInfoNV dedicated_memory_info = {};
19953 dedicated_memory_info.sType = VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_MEMORY_ALLOCATE_INFO_NV;
19954 dedicated_memory_info.pNext = nullptr;
19955 dedicated_memory_info.buffer = buffer;
19956 dedicated_memory_info.image = VK_NULL_HANDLE;
19957
19958 VkMemoryAllocateInfo memory_info = {};
19959 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
19960 memory_info.pNext = &dedicated_memory_info;
19961 memory_info.allocationSize = memory_reqs.size;
19962
19963 bool pass;
19964 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
19965 ASSERT_TRUE(pass);
19966
19967 VkDeviceMemory buffer_memory;
19968 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
19969 ASSERT_VK_SUCCESS(err);
19970
19971 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
19972 ASSERT_VK_SUCCESS(err);
19973
19974 vkDestroyBuffer(m_device->device(), buffer, NULL);
19975 vkFreeMemory(m_device->device(), buffer_memory, NULL);
19976
19977 m_errorMonitor->VerifyNotFound();
19978 }
19979}
19980
19981TEST_F(VkPositiveLayerTest, PSOPolygonModeValid) {
19982 VkResult err;
19983
19984 TEST_DESCRIPTION("Verify that using a solid polygon fill mode works correctly.");
19985
19986 ASSERT_NO_FATAL_FAILURE(InitState());
19987 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19988
19989 std::vector<const char *> device_extension_names;
19990 auto features = m_device->phy().features();
19991 // Artificially disable support for non-solid fill modes
19992 features.fillModeNonSolid = false;
19993 // The sacrificial device object
19994 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
19995
19996 VkRenderpassObj render_pass(&test_device);
19997
19998 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
19999 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
20000 pipeline_layout_ci.setLayoutCount = 0;
20001 pipeline_layout_ci.pSetLayouts = NULL;
20002
20003 VkPipelineLayout pipeline_layout;
20004 err = vkCreatePipelineLayout(test_device.device(), &pipeline_layout_ci, NULL, &pipeline_layout);
20005 ASSERT_VK_SUCCESS(err);
20006
20007 VkPipelineRasterizationStateCreateInfo rs_ci = {};
20008 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
20009 rs_ci.pNext = nullptr;
20010 rs_ci.lineWidth = 1.0f;
20011 rs_ci.rasterizerDiscardEnable = true;
20012
20013 VkShaderObj vs(&test_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
20014 VkShaderObj fs(&test_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
20015
20016 // Set polygonMode=FILL. No error is expected
20017 m_errorMonitor->ExpectSuccess();
20018 {
20019 VkPipelineObj pipe(&test_device);
20020 pipe.AddShader(&vs);
20021 pipe.AddShader(&fs);
20022 pipe.AddColorAttachment();
20023 // Set polygonMode to a good value
20024 rs_ci.polygonMode = VK_POLYGON_MODE_FILL;
20025 pipe.SetRasterization(&rs_ci);
20026 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
20027 }
20028 m_errorMonitor->VerifyNotFound();
20029
20030 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, NULL);
20031}
20032
20033TEST_F(VkPositiveLayerTest, ValidPushConstants) {
20034 VkResult err;
20035 ASSERT_NO_FATAL_FAILURE(InitState());
20036 ASSERT_NO_FATAL_FAILURE(InitViewport());
20037 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
20038
20039 VkPipelineLayout pipeline_layout;
20040 VkPushConstantRange pc_range = {};
20041 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
20042 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
20043 pipeline_layout_ci.pushConstantRangeCount = 1;
20044 pipeline_layout_ci.pPushConstantRanges = &pc_range;
20045
20046 //
20047 // Check for invalid push constant ranges in pipeline layouts.
20048 //
20049 struct PipelineLayoutTestCase {
20050 VkPushConstantRange const range;
20051 char const *msg;
20052 };
20053
20054 // Check for overlapping ranges
20055 const uint32_t ranges_per_test = 5;
20056 struct OverlappingRangeTestCase {
20057 VkPushConstantRange const ranges[ranges_per_test];
20058 char const *msg;
20059 };
20060
20061 // Run some positive tests to make sure overlap checking in the layer is OK
20062 const std::array<OverlappingRangeTestCase, 2> overlapping_range_tests_pos = { { { { { VK_SHADER_STAGE_VERTEX_BIT, 0, 4 },
20063 { VK_SHADER_STAGE_VERTEX_BIT, 4, 4 },
20064 { VK_SHADER_STAGE_VERTEX_BIT, 8, 4 },
20065 { VK_SHADER_STAGE_VERTEX_BIT, 12, 4 },
20066 { VK_SHADER_STAGE_VERTEX_BIT, 16, 4 } },
20067 "" },
20068 { { { VK_SHADER_STAGE_VERTEX_BIT, 92, 24 },
20069 { VK_SHADER_STAGE_VERTEX_BIT, 80, 4 },
20070 { VK_SHADER_STAGE_VERTEX_BIT, 64, 8 },
20071 { VK_SHADER_STAGE_VERTEX_BIT, 4, 16 },
20072 { VK_SHADER_STAGE_VERTEX_BIT, 0, 4 } },
20073 "" } } };
20074 for (const auto &iter : overlapping_range_tests_pos) {
20075 pipeline_layout_ci.pPushConstantRanges = iter.ranges;
20076 m_errorMonitor->ExpectSuccess();
20077 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
20078 m_errorMonitor->VerifyNotFound();
20079 if (VK_SUCCESS == err) {
20080 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
20081 }
20082 }
20083
20084 //
20085 // CmdPushConstants tests
20086 //
20087 const uint8_t dummy_values[100] = {};
20088
20089 BeginCommandBuffer();
20090
20091 // positive overlapping range tests with cmd
20092 const std::array<PipelineLayoutTestCase, 4> cmd_overlap_tests_pos = { {
20093 { { VK_SHADER_STAGE_VERTEX_BIT, 0, 16 }, "" },
20094 { { VK_SHADER_STAGE_VERTEX_BIT, 0, 4 }, "" },
20095 { { VK_SHADER_STAGE_VERTEX_BIT, 20, 12 }, "" },
20096 { { VK_SHADER_STAGE_VERTEX_BIT, 56, 36 }, "" },
20097 } };
20098
20099 // Setup ranges: [0,16) [20,36) [36,44) [44,52) [56,80) [80,92)
20100 const VkPushConstantRange pc_range4[] = {
20101 { VK_SHADER_STAGE_VERTEX_BIT, 20, 16 },{ VK_SHADER_STAGE_VERTEX_BIT, 0, 16 },{ VK_SHADER_STAGE_VERTEX_BIT, 44, 8 },
20102 { VK_SHADER_STAGE_VERTEX_BIT, 80, 12 },{ VK_SHADER_STAGE_VERTEX_BIT, 36, 8 },{ VK_SHADER_STAGE_VERTEX_BIT, 56, 24 },
20103 };
20104
20105 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range4) / sizeof(VkPushConstantRange);
20106 pipeline_layout_ci.pPushConstantRanges = pc_range4;
20107 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
20108 ASSERT_VK_SUCCESS(err);
20109 for (const auto &iter : cmd_overlap_tests_pos) {
20110 m_errorMonitor->ExpectSuccess();
20111 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.range.stageFlags, iter.range.offset,
20112 iter.range.size, dummy_values);
20113 m_errorMonitor->VerifyNotFound();
20114 }
20115 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
20116
20117 EndCommandBuffer();
20118}
20119
20120
20121
20122
20123
20124
20125
20126#if 0 // A few devices have issues with this test so disabling for now
20127TEST_F(VkPositiveLayerTest, LongFenceChain)
20128{
20129 m_errorMonitor->ExpectSuccess();
20130
20131 ASSERT_NO_FATAL_FAILURE(InitState());
20132 VkResult err;
20133
20134 std::vector<VkFence> fences;
20135
20136 const int chainLength = 32768;
20137
20138 for (int i = 0; i < chainLength; i++) {
20139 VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
20140 VkFence fence;
20141 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
20142 ASSERT_VK_SUCCESS(err);
20143
20144 fences.push_back(fence);
20145
20146 VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr,
20147 0, nullptr, 0, nullptr };
20148 err = vkQueueSubmit(m_device->m_queue, 1, &si, fence);
20149 ASSERT_VK_SUCCESS(err);
20150
20151 }
20152
20153 // BOOM, stack overflow.
20154 vkWaitForFences(m_device->device(), 1, &fences.back(), VK_TRUE, UINT64_MAX);
20155
20156 for (auto fence : fences)
20157 vkDestroyFence(m_device->device(), fence, nullptr);
20158
20159 m_errorMonitor->VerifyNotFound();
20160}
20161#endif
20162
20163
Cody Northrop1242dfd2016-07-13 17:24:59 -060020164#if defined(ANDROID) && defined(VALIDATION_APK)
20165static bool initialized = false;
20166static bool active = false;
20167
20168// Convert Intents to argv
20169// Ported from Hologram sample, only difference is flexible key
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020170std::vector<std::string> get_args(android_app &app, const char *intent_extra_data_key) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060020171 std::vector<std::string> args;
20172 JavaVM &vm = *app.activity->vm;
20173 JNIEnv *p_env;
20174 if (vm.AttachCurrentThread(&p_env, nullptr) != JNI_OK)
20175 return args;
20176
20177 JNIEnv &env = *p_env;
20178 jobject activity = app.activity->clazz;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020179 jmethodID get_intent_method = env.GetMethodID(env.GetObjectClass(activity), "getIntent", "()Landroid/content/Intent;");
Cody Northrop1242dfd2016-07-13 17:24:59 -060020180 jobject intent = env.CallObjectMethod(activity, get_intent_method);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020181 jmethodID get_string_extra_method =
20182 env.GetMethodID(env.GetObjectClass(intent), "getStringExtra", "(Ljava/lang/String;)Ljava/lang/String;");
Cody Northrop1242dfd2016-07-13 17:24:59 -060020183 jvalue get_string_extra_args;
20184 get_string_extra_args.l = env.NewStringUTF(intent_extra_data_key);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020185 jstring extra_str = static_cast<jstring>(env.CallObjectMethodA(intent, get_string_extra_method, &get_string_extra_args));
Cody Northrop1242dfd2016-07-13 17:24:59 -060020186
20187 std::string args_str;
20188 if (extra_str) {
20189 const char *extra_utf = env.GetStringUTFChars(extra_str, nullptr);
20190 args_str = extra_utf;
20191 env.ReleaseStringUTFChars(extra_str, extra_utf);
20192 env.DeleteLocalRef(extra_str);
20193 }
20194
20195 env.DeleteLocalRef(get_string_extra_args.l);
20196 env.DeleteLocalRef(intent);
20197 vm.DetachCurrentThread();
20198
20199 // split args_str
20200 std::stringstream ss(args_str);
20201 std::string arg;
20202 while (std::getline(ss, arg, ' ')) {
20203 if (!arg.empty())
20204 args.push_back(arg);
20205 }
20206
20207 return args;
20208}
20209
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020210static int32_t processInput(struct android_app *app, AInputEvent *event) { return 0; }
Cody Northrop1242dfd2016-07-13 17:24:59 -060020211
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020212static void processCommand(struct android_app *app, int32_t cmd) {
20213 switch (cmd) {
20214 case APP_CMD_INIT_WINDOW: {
20215 if (app->window) {
20216 initialized = true;
Cody Northrop1242dfd2016-07-13 17:24:59 -060020217 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020218 break;
20219 }
20220 case APP_CMD_GAINED_FOCUS: {
20221 active = true;
20222 break;
20223 }
20224 case APP_CMD_LOST_FOCUS: {
20225 active = false;
20226 break;
20227 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060020228 }
20229}
20230
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020231void android_main(struct android_app *app) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060020232 app_dummy();
20233
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020234 const char *appTag = "VulkanLayerValidationTests";
Cody Northrop1242dfd2016-07-13 17:24:59 -060020235
20236 int vulkanSupport = InitVulkan();
20237 if (vulkanSupport == 0) {
20238 __android_log_print(ANDROID_LOG_INFO, appTag, "==== FAILED ==== No Vulkan support found");
20239 return;
20240 }
20241
20242 app->onAppCmd = processCommand;
20243 app->onInputEvent = processInput;
20244
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020245 while (1) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060020246 int events;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020247 struct android_poll_source *source;
20248 while (ALooper_pollAll(active ? 0 : -1, NULL, &events, (void **)&source) >= 0) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060020249 if (source) {
20250 source->process(app, source);
20251 }
20252
20253 if (app->destroyRequested != 0) {
20254 VkTestFramework::Finish();
20255 return;
20256 }
20257 }
20258
20259 if (initialized && active) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020260 // Use the following key to send arguments to gtest, i.e.
20261 // --es args "--gtest_filter=-VkLayerTest.foo"
20262 const char key[] = "args";
20263 std::vector<std::string> args = get_args(*app, key);
Cody Northrop1242dfd2016-07-13 17:24:59 -060020264
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020265 std::string filter = "";
20266 if (args.size() > 0) {
20267 __android_log_print(ANDROID_LOG_INFO, appTag, "Intent args = %s", args[0].c_str());
20268 filter += args[0];
20269 } else {
20270 __android_log_print(ANDROID_LOG_INFO, appTag, "No Intent args detected");
20271 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060020272
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020273 int argc = 2;
20274 char *argv[] = {(char *)"foo", (char *)filter.c_str()};
20275 __android_log_print(ANDROID_LOG_DEBUG, appTag, "filter = %s", argv[1]);
Cody Northrop1242dfd2016-07-13 17:24:59 -060020276
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020277 // Route output to files until we can override the gtest output
20278 freopen("/sdcard/Android/data/com.example.VulkanLayerValidationTests/files/out.txt", "w", stdout);
20279 freopen("/sdcard/Android/data/com.example.VulkanLayerValidationTests/files/err.txt", "w", stderr);
Cody Northrop1242dfd2016-07-13 17:24:59 -060020280
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020281 ::testing::InitGoogleTest(&argc, argv);
20282 VkTestFramework::InitArgs(&argc, argv);
20283 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
Cody Northrop1242dfd2016-07-13 17:24:59 -060020284
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020285 int result = RUN_ALL_TESTS();
Cody Northrop1242dfd2016-07-13 17:24:59 -060020286
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020287 if (result != 0) {
20288 __android_log_print(ANDROID_LOG_INFO, appTag, "==== Tests FAILED ====");
20289 } else {
20290 __android_log_print(ANDROID_LOG_INFO, appTag, "==== Tests PASSED ====");
20291 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060020292
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020293 VkTestFramework::Finish();
Cody Northrop1242dfd2016-07-13 17:24:59 -060020294
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020295 fclose(stdout);
20296 fclose(stderr);
Cody Northrop1242dfd2016-07-13 17:24:59 -060020297
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020298 ANativeActivity_finish(app->activity);
Cody Northrop1242dfd2016-07-13 17:24:59 -060020299
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020300 return;
Cody Northrop1242dfd2016-07-13 17:24:59 -060020301 }
20302 }
20303}
20304#endif
20305
Tony Barbour300a6082015-04-07 13:44:53 -060020306int main(int argc, char **argv) {
20307 int result;
20308
Cody Northrop8e54a402016-03-08 22:25:52 -070020309#ifdef ANDROID
20310 int vulkanSupport = InitVulkan();
20311 if (vulkanSupport == 0)
20312 return 1;
20313#endif
20314
Tony Barbour300a6082015-04-07 13:44:53 -060020315 ::testing::InitGoogleTest(&argc, argv);
Tony Barbour6918cd52015-04-09 12:58:51 -060020316 VkTestFramework::InitArgs(&argc, argv);
Tony Barbour300a6082015-04-07 13:44:53 -060020317
20318 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
20319
20320 result = RUN_ALL_TESTS();
20321
Tony Barbour6918cd52015-04-09 12:58:51 -060020322 VkTestFramework::Finish();
Tony Barbour300a6082015-04-07 13:44:53 -060020323 return result;
20324}