blob: f628d8ef810633bae56b6199f700035eb5a8f4a1 [file] [log] [blame]
Karl Schultz6addd812016-02-02 17:17:23 -07001/*
2 * Copyright (c) 2015-2016 The Khronos Group Inc.
3 * Copyright (c) 2015-2016 Valve Corporation
4 * Copyright (c) 2015-2016 LunarG, Inc.
Michael Lentine0a369f62016-02-03 16:51:46 -06005 * Copyright (c) 2015-2016 Google, Inc.
Karl Schultz6addd812016-02-02 17:17:23 -07006 *
Jon Ashburn3ebf1252016-04-19 11:30:31 -06007 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
Karl Schultz6addd812016-02-02 17:17:23 -070010 *
Jon Ashburn3ebf1252016-04-19 11:30:31 -060011 * http://www.apache.org/licenses/LICENSE-2.0
Karl Schultz6addd812016-02-02 17:17:23 -070012 *
13 * Author: Chia-I Wu <olvaffe@gmail.com>
14 * Author: Chris Forbes <chrisf@ijw.co.nz>
15 * Author: Courtney Goeltzenleuchter <courtney@LunarG.com>
16 * Author: Mark Lobodzinski <mark@lunarg.com>
17 * Author: Mike Stroyan <mike@LunarG.com>
18 * Author: Tobin Ehlis <tobine@google.com>
19 * Author: Tony Barbour <tony@LunarG.com>
Cody Northrop1242dfd2016-07-13 17:24:59 -060020 * Author: Cody Northrop <cnorthrop@google.com>
Karl Schultz6addd812016-02-02 17:17:23 -070021 */
Tony Barbour65c48b32015-11-17 10:02:56 -070022
Cody Northrop8e54a402016-03-08 22:25:52 -070023#ifdef ANDROID
24#include "vulkan_wrapper.h"
25#else
David Pinedo9316d3b2015-11-06 12:54:48 -070026#include <vulkan/vulkan.h>
Cody Northrop8e54a402016-03-08 22:25:52 -070027#endif
Cody Northrop1242dfd2016-07-13 17:24:59 -060028
29#if defined(ANDROID) && defined(VALIDATION_APK)
30#include <android/log.h>
31#include <android_native_app_glue.h>
32#endif
33
Jon Ashburn7fa7e222016-02-02 12:08:10 -070034#include "icd-spv.h"
Mark Lobodzinskice751c62016-09-08 10:45:35 -060035#include "test_common.h"
36#include "vk_layer_config.h"
Mark Lobodzinski629d47b2016-10-18 13:34:58 -060037#include "vk_validation_error_messages.h"
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060038#include "vkrenderframework.h"
39#include <limits.h>
40#include <unordered_set>
Tony Barbour300a6082015-04-07 13:44:53 -060041
Mark Lobodzinski3780e142015-05-14 15:08:13 -050042#define GLM_FORCE_RADIANS
43#include "glm/glm.hpp"
44#include <glm/gtc/matrix_transform.hpp>
45
Dustin Gravesffa90fa2016-05-06 11:20:38 -060046#define PARAMETER_VALIDATION_TESTS 1
Tobin Ehlis0788f522015-05-26 16:11:58 -060047#define MEM_TRACKER_TESTS 1
48#define OBJ_TRACKER_TESTS 1
49#define DRAW_STATE_TESTS 1
50#define THREADING_TESTS 1
Chris Forbes9f7ff632015-05-25 11:13:08 +120051#define SHADER_CHECKER_TESTS 1
Mark Lobodzinski209b5292015-09-17 09:44:05 -060052#define DEVICE_LIMITS_TESTS 1
Tobin Ehliscde08892015-09-22 10:11:37 -060053#define IMAGE_TESTS 1
Tobin Ehlis0788f522015-05-26 16:11:58 -060054
Mark Lobodzinski3780e142015-05-14 15:08:13 -050055//--------------------------------------------------------------------------------------
56// Mesh and VertexFormat Data
57//--------------------------------------------------------------------------------------
Karl Schultz6addd812016-02-02 17:17:23 -070058struct Vertex {
59 float posX, posY, posZ, posW; // Position data
60 float r, g, b, a; // Color
Mark Lobodzinski3780e142015-05-14 15:08:13 -050061};
62
Karl Schultz6addd812016-02-02 17:17:23 -070063#define XYZ1(_x_, _y_, _z_) (_x_), (_y_), (_z_), 1.f
Mark Lobodzinski3780e142015-05-14 15:08:13 -050064
65typedef enum _BsoFailSelect {
Karl Schultz6addd812016-02-02 17:17:23 -070066 BsoFailNone = 0x00000000,
67 BsoFailLineWidth = 0x00000001,
68 BsoFailDepthBias = 0x00000002,
69 BsoFailViewport = 0x00000004,
70 BsoFailScissor = 0x00000008,
71 BsoFailBlend = 0x00000010,
72 BsoFailDepthBounds = 0x00000020,
73 BsoFailStencilReadMask = 0x00000040,
74 BsoFailStencilWriteMask = 0x00000080,
75 BsoFailStencilReference = 0x00000100,
Mark Muellerd4914412016-06-13 17:52:06 -060076 BsoFailCmdClearAttachments = 0x00000200,
Tobin Ehlis379ba3b2016-07-19 11:22:29 -060077 BsoFailIndexBuffer = 0x00000400,
Mark Lobodzinski3780e142015-05-14 15:08:13 -050078} BsoFailSelect;
79
80struct vktriangle_vs_uniform {
81 // Must start with MVP
Karl Schultz6addd812016-02-02 17:17:23 -070082 float mvp[4][4];
83 float position[3][4];
84 float color[3][4];
Mark Lobodzinski3780e142015-05-14 15:08:13 -050085};
86
Mark Lobodzinskice751c62016-09-08 10:45:35 -060087static const char bindStateVertShaderText[] = "#version 450\n"
88 "vec2 vertices[3];\n"
89 "out gl_PerVertex {\n"
90 " vec4 gl_Position;\n"
91 "};\n"
92 "void main() {\n"
93 " vertices[0] = vec2(-1.0, -1.0);\n"
94 " vertices[1] = vec2( 1.0, -1.0);\n"
95 " vertices[2] = vec2( 0.0, 1.0);\n"
96 " gl_Position = vec4(vertices[gl_VertexIndex % 3], 0.0, 1.0);\n"
97 "}\n";
Mark Lobodzinski3780e142015-05-14 15:08:13 -050098
Mark Lobodzinskice751c62016-09-08 10:45:35 -060099static const char bindStateFragShaderText[] = "#version 450\n"
100 "\n"
101 "layout(location = 0) out vec4 uFragColor;\n"
102 "void main(){\n"
103 " uFragColor = vec4(0,1,0,1);\n"
104 "}\n";
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500105
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600106static VKAPI_ATTR VkBool32 VKAPI_CALL myDbgFunc(VkFlags msgFlags, VkDebugReportObjectTypeEXT objType, uint64_t srcObject,
107 size_t location, int32_t msgCode, const char *pLayerPrefix, const char *pMsg,
108 void *pUserData);
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600109
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600110// ErrorMonitor Usage:
111//
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600112// Call SetDesiredFailureMsg with: a string to be compared against all
113// encountered log messages, or a validation error enum identifying
114// desired error message. Passing NULL or VALIDATION_ERROR_MAX_ENUM
115// will match all log messages. logMsg will return true for skipCall
116// only if msg is matched or NULL.
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600117//
118// Call DesiredMsgFound to determine if the desired failure message
119// was encountered.
Tony Barbour300a6082015-04-07 13:44:53 -0600120class ErrorMonitor {
Karl Schultz6addd812016-02-02 17:17:23 -0700121 public:
122 ErrorMonitor() {
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600123 test_platform_thread_create_mutex(&m_mutex);
124 test_platform_thread_lock_mutex(&m_mutex);
Chris Forbes17756132016-09-16 14:36:39 +1200125 m_msgFlags = VK_DEBUG_REPORT_ERROR_BIT_EXT;
Karl Schultz6addd812016-02-02 17:17:23 -0700126 m_bailout = NULL;
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600127 test_platform_thread_unlock_mutex(&m_mutex);
Tony Barbour300a6082015-04-07 13:44:53 -0600128 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600129
Dustin Graves48458142016-04-29 16:11:55 -0600130 ~ErrorMonitor() { test_platform_thread_delete_mutex(&m_mutex); }
131
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600132 // ErrorMonitor will look for an error message containing the specified string
Karl Schultz6addd812016-02-02 17:17:23 -0700133 void SetDesiredFailureMsg(VkFlags msgFlags, const char *msgString) {
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600134 // Also discard all collected messages to this point
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600135 test_platform_thread_lock_mutex(&m_mutex);
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600136 m_failure_message_strings.clear();
137 // If we are looking for a matching string, ignore any IDs
138 m_desired_message_ids.clear();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600139 m_otherMsgs.clear();
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600140 m_desired_message_strings.insert(msgString);
Karl Schultz6addd812016-02-02 17:17:23 -0700141 m_msgFound = VK_FALSE;
142 m_msgFlags = msgFlags;
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600143 test_platform_thread_unlock_mutex(&m_mutex);
Tony Barbour300a6082015-04-07 13:44:53 -0600144 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600145
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600146 // ErrorMonitor will look for a message ID matching the specified one
147 void SetDesiredFailureMsg(VkFlags msgFlags, UNIQUE_VALIDATION_ERROR_CODE msg_id) {
148 // Also discard all collected messages to this point
149 test_platform_thread_lock_mutex(&m_mutex);
150 m_failure_message_strings.clear();
151 // If we are looking for IDs don't look for strings
152 m_desired_message_strings.clear();
153 m_otherMsgs.clear();
154 m_desired_message_ids.insert(msg_id);
155 m_msgFound = VK_FALSE;
156 m_msgFlags = msgFlags;
157 test_platform_thread_unlock_mutex(&m_mutex);
158 }
159
160 VkBool32 CheckForDesiredMsg(uint32_t message_code, const char *msgString) {
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600161 VkBool32 result = VK_FALSE;
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600162 test_platform_thread_lock_mutex(&m_mutex);
Mike Stroyanaccf7692015-05-12 16:00:45 -0600163 if (m_bailout != NULL) {
164 *m_bailout = true;
165 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600166 string errorString(msgString);
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600167 bool found_expected = false;
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600168
169 for (auto desired_msg : m_desired_message_strings) {
Karl Schultz05cc4e32016-10-12 13:25:23 -0600170 if (desired_msg.length() == 0) {
171 // An empty desired_msg string "" indicates a positive test - not expecting an error.
172 // Return true to avoid calling layers/driver with this error.
173 // And don't erase the "" string, so it remains if another error is found.
174 result = VK_TRUE;
Tony Barbourae58dba2016-12-13 16:30:36 -0700175 found_expected = true;
176 m_msgFound = VK_TRUE;
177 m_failure_message_strings.insert(errorString);
Karl Schultz05cc4e32016-10-12 13:25:23 -0600178 } else if (errorString.find(desired_msg) != string::npos) {
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600179 found_expected = true;
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600180 m_failure_message_strings.insert(errorString);
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600181 m_msgFound = VK_TRUE;
182 result = VK_TRUE;
183 // We only want one match for each expected error so remove from set here
184 // Since we're about the break the loop it's ok to remove from set we're iterating over
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600185 m_desired_message_strings.erase(desired_msg);
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600186 break;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600187 }
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600188 }
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600189 for (auto desired_id : m_desired_message_ids) {
190 if (desired_id == VALIDATION_ERROR_MAX_ENUM) {
191 // A message ID set to MAX_ENUM indicates a positive test - not expecting an error.
192 // Return true to avoid calling layers/driver with this error.
193 result = VK_TRUE;
194 } else if (desired_id == message_code) {
195 // Double-check that the string matches the error enum
196 if (errorString.find(validation_error_map[desired_id]) != string::npos) {
197 found_expected = true;
198 result = VK_TRUE;
199 m_msgFound = VK_TRUE;
200 m_desired_message_ids.erase(desired_id);
201 break;
202 } else {
203 // Treat this message as a regular unexpected error, but print a warning jic
204 printf("Message (%s) from MessageID %d does not correspond to expected message from error Database (%s)\n",
205 errorString.c_str(), desired_id, validation_error_map[desired_id]);
206 }
207 }
208 }
209
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600210 if (!found_expected) {
Chris Forbes5b9442b2016-09-13 16:49:57 +1200211 printf("Unexpected: %s\n", msgString);
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600212 m_otherMsgs.push_back(errorString);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600213 }
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600214 test_platform_thread_unlock_mutex(&m_mutex);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600215 return result;
Mike Stroyanaccf7692015-05-12 16:00:45 -0600216 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600217
Karl Schultz6addd812016-02-02 17:17:23 -0700218 vector<string> GetOtherFailureMsgs(void) { return m_otherMsgs; }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600219
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600220 VkDebugReportFlagsEXT GetMessageFlags(void) { return m_msgFlags; }
221
Karl Schultz6addd812016-02-02 17:17:23 -0700222 VkBool32 DesiredMsgFound(void) { return m_msgFound; }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600223
Karl Schultz6addd812016-02-02 17:17:23 -0700224 void SetBailout(bool *bailout) { m_bailout = bailout; }
Tony Barbour300a6082015-04-07 13:44:53 -0600225
Karl Schultz6addd812016-02-02 17:17:23 -0700226 void DumpFailureMsgs(void) {
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600227 vector<string> otherMsgs = GetOtherFailureMsgs();
Tony Barbour59b42282016-11-03 13:31:28 -0600228 if (otherMsgs.size()) {
229 cout << "Other error messages logged for this test were:" << endl;
230 for (auto iter = otherMsgs.begin(); iter != otherMsgs.end(); iter++) {
231 cout << " " << *iter << endl;
232 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600233 }
234 }
235
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600236 // Helpers
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200237
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600238 // ExpectSuccess now takes an optional argument allowing a custom combination of debug flags
239 void ExpectSuccess(VkDebugReportFlagsEXT message_flag_mask = VK_DEBUG_REPORT_ERROR_BIT_EXT) {
240 m_msgFlags = message_flag_mask;
241 // Match ANY message matching specified type
242 SetDesiredFailureMsg(message_flag_mask, "");
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200243 }
244
245 void VerifyFound() {
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600246 // Not seeing the desired message is a failure. /Before/ throwing, dump any other messages.
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200247 if (!DesiredMsgFound()) {
248 DumpFailureMsgs();
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600249 for (auto desired_msg : m_desired_message_strings) {
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600250 FAIL() << "Did not receive expected error '" << desired_msg << "'";
251 }
Tony Barbour59b42282016-11-03 13:31:28 -0600252 for (auto desired_id : m_desired_message_ids) {
253 FAIL() << "Did not receive expected error '" << desired_id << "'";
254 }
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200255 }
256 }
257
258 void VerifyNotFound() {
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600259 // ExpectSuccess() configured us to match anything. Any error is a failure.
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200260 if (DesiredMsgFound()) {
261 DumpFailureMsgs();
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600262 for (auto msg : m_failure_message_strings) {
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600263 FAIL() << "Expected to succeed but got error: " << msg;
264 }
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200265 }
266 }
267
Karl Schultz6addd812016-02-02 17:17:23 -0700268 private:
269 VkFlags m_msgFlags;
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600270 std::unordered_set<uint32_t>m_desired_message_ids;
271 std::unordered_set<string> m_desired_message_strings;
272 std::unordered_set<string> m_failure_message_strings;
Karl Schultz6addd812016-02-02 17:17:23 -0700273 vector<string> m_otherMsgs;
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600274 test_platform_thread_mutex m_mutex;
Karl Schultz6addd812016-02-02 17:17:23 -0700275 bool *m_bailout;
276 VkBool32 m_msgFound;
Tony Barbour300a6082015-04-07 13:44:53 -0600277};
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500278
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600279static VKAPI_ATTR VkBool32 VKAPI_CALL myDbgFunc(VkFlags msgFlags, VkDebugReportObjectTypeEXT objType, uint64_t srcObject,
280 size_t location, int32_t msgCode, const char *pLayerPrefix, const char *pMsg,
281 void *pUserData) {
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600282 ErrorMonitor *errMonitor = (ErrorMonitor *)pUserData;
283 if (msgFlags & errMonitor->GetMessageFlags()) {
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600284 return errMonitor->CheckForDesiredMsg(msgCode, pMsg);
Tony Barbour0b4d9562015-04-09 10:48:04 -0600285 }
Courtney Goeltzenleuchter06640832015-09-04 13:52:24 -0600286 return false;
Tony Barbour300a6082015-04-07 13:44:53 -0600287}
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500288
Karl Schultz6addd812016-02-02 17:17:23 -0700289class VkLayerTest : public VkRenderFramework {
290 public:
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800291 VkResult BeginCommandBuffer(VkCommandBufferObj &commandBuffer);
292 VkResult EndCommandBuffer(VkCommandBufferObj &commandBuffer);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600293 void VKTriangleTest(const char *vertShaderText, const char *fragShaderText, BsoFailSelect failMask);
294 void GenericDrawPreparation(VkCommandBufferObj *commandBuffer, VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet,
Karl Schultz6addd812016-02-02 17:17:23 -0700295 BsoFailSelect failMask);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600296 void GenericDrawPreparation(VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet, BsoFailSelect failMask) {
297 GenericDrawPreparation(m_commandBuffer, pipelineobj, descriptorSet, failMask);
Karl Schultz6addd812016-02-02 17:17:23 -0700298 }
Tony Barbour300a6082015-04-07 13:44:53 -0600299
Tony Barbourfe3351b2015-07-28 10:17:20 -0600300 /* Convenience functions that use built-in command buffer */
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600301 VkResult BeginCommandBuffer() { return BeginCommandBuffer(*m_commandBuffer); }
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800302 VkResult EndCommandBuffer() { return EndCommandBuffer(*m_commandBuffer); }
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600303 void Draw(uint32_t vertexCount, uint32_t instanceCount, uint32_t firstVertex, uint32_t firstInstance) {
304 m_commandBuffer->Draw(vertexCount, instanceCount, firstVertex, firstInstance);
Karl Schultz6addd812016-02-02 17:17:23 -0700305 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600306 void DrawIndexed(uint32_t indexCount, uint32_t instanceCount, uint32_t firstIndex, int32_t vertexOffset,
Karl Schultz6addd812016-02-02 17:17:23 -0700307 uint32_t firstInstance) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600308 m_commandBuffer->DrawIndexed(indexCount, instanceCount, firstIndex, vertexOffset, firstInstance);
Karl Schultz6addd812016-02-02 17:17:23 -0700309 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600310 void QueueCommandBuffer(bool checkSuccess = true) { m_commandBuffer->QueueCommandBuffer(checkSuccess); }
311 void QueueCommandBuffer(const VkFence &fence) { m_commandBuffer->QueueCommandBuffer(fence); }
312 void BindVertexBuffer(VkConstantBufferObj *vertexBuffer, VkDeviceSize offset, uint32_t binding) {
Karl Schultz6addd812016-02-02 17:17:23 -0700313 m_commandBuffer->BindVertexBuffer(vertexBuffer, offset, binding);
314 }
315 void BindIndexBuffer(VkIndexBufferObj *indexBuffer, VkDeviceSize offset) {
316 m_commandBuffer->BindIndexBuffer(indexBuffer, offset);
317 }
318
319 protected:
320 ErrorMonitor *m_errorMonitor;
Ian Elliott2c1daf52016-05-12 09:41:46 -0600321 bool m_enableWSI;
Tony Barbour300a6082015-04-07 13:44:53 -0600322
323 virtual void SetUp() {
Courtney Goeltzenleuchtercd69eee2015-07-06 09:10:47 -0600324 std::vector<const char *> instance_layer_names;
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600325 std::vector<const char *> instance_extension_names;
326 std::vector<const char *> device_extension_names;
Tony Barbour3fdff9e2015-04-23 12:55:36 -0600327
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700328 instance_extension_names.push_back(VK_EXT_DEBUG_REPORT_EXTENSION_NAME);
Courtney Goeltzenleuchterc2b06fe2015-06-16 15:59:11 -0600329 /*
330 * Since CreateDbgMsgCallback is an instance level extension call
331 * any extension / layer that utilizes that feature also needs
332 * to be enabled at create instance time.
333 */
Karl Schultz6addd812016-02-02 17:17:23 -0700334 // Use Threading layer first to protect others from
335 // ThreadCommandBufferCollision test
Courtney Goeltzenleuchter76885322016-02-06 17:11:22 -0700336 instance_layer_names.push_back("VK_LAYER_GOOGLE_threading");
Tobin Ehlis24aab042016-03-24 10:54:18 -0600337 instance_layer_names.push_back("VK_LAYER_LUNARG_parameter_validation");
Michael Lentine03107b42015-12-11 10:49:51 -0800338 instance_layer_names.push_back("VK_LAYER_LUNARG_object_tracker");
Tobin Ehlisc96f8062016-03-09 16:12:48 -0700339 instance_layer_names.push_back("VK_LAYER_LUNARG_core_validation");
Michael Lentine03107b42015-12-11 10:49:51 -0800340 instance_layer_names.push_back("VK_LAYER_LUNARG_image");
Ian Elliotte48a1382016-04-28 14:22:58 -0600341 instance_layer_names.push_back("VK_LAYER_LUNARG_swapchain");
Dustin Graveseaa78cd2016-01-26 16:30:22 -0700342 instance_layer_names.push_back("VK_LAYER_GOOGLE_unique_objects");
Courtney Goeltzenleuchterd971b612015-06-17 20:51:59 -0600343
Ian Elliott2c1daf52016-05-12 09:41:46 -0600344 if (m_enableWSI) {
345 instance_extension_names.push_back(VK_KHR_SURFACE_EXTENSION_NAME);
346 device_extension_names.push_back(VK_KHR_SWAPCHAIN_EXTENSION_NAME);
347#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
348#if defined(VK_USE_PLATFORM_ANDROID_KHR)
349 instance_extension_names.push_back(VK_KHR_ANDROID_SURFACE_EXTENSION_NAME);
350#endif // VK_USE_PLATFORM_ANDROID_KHR
351#if defined(VK_USE_PLATFORM_MIR_KHR)
352 instance_extension_names.push_back(VK_KHR_MIR_SURFACE_EXTENSION_NAME);
353#endif // VK_USE_PLATFORM_MIR_KHR
354#if defined(VK_USE_PLATFORM_WAYLAND_KHR)
355 instance_extension_names.push_back(VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME);
356#endif // VK_USE_PLATFORM_WAYLAND_KHR
357#if defined(VK_USE_PLATFORM_WIN32_KHR)
358 instance_extension_names.push_back(VK_KHR_WIN32_SURFACE_EXTENSION_NAME);
359#endif // VK_USE_PLATFORM_WIN32_KHR
360#endif // NEED_TO_TEST_THIS_ON_PLATFORM
361#if defined(VK_USE_PLATFORM_XCB_KHR)
362 instance_extension_names.push_back(VK_KHR_XCB_SURFACE_EXTENSION_NAME);
363#elif defined(VK_USE_PLATFORM_XLIB_KHR)
364 instance_extension_names.push_back(VK_KHR_XLIB_SURFACE_EXTENSION_NAME);
365#endif // VK_USE_PLATFORM_XLIB_KHR
366 }
367
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600368 this->app_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
Tony Barbour300a6082015-04-07 13:44:53 -0600369 this->app_info.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800370 this->app_info.pApplicationName = "layer_tests";
371 this->app_info.applicationVersion = 1;
Tony Barbour300a6082015-04-07 13:44:53 -0600372 this->app_info.pEngineName = "unittest";
373 this->app_info.engineVersion = 1;
Jon Ashburnc5012ff2016-03-22 13:57:46 -0600374 this->app_info.apiVersion = VK_API_VERSION_1_0;
Tony Barbour300a6082015-04-07 13:44:53 -0600375
Tony Barbour15524c32015-04-29 17:34:29 -0600376 m_errorMonitor = new ErrorMonitor;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600377 InitFramework(instance_layer_names, instance_extension_names, device_extension_names, myDbgFunc, m_errorMonitor);
Tony Barbour300a6082015-04-07 13:44:53 -0600378 }
379
380 virtual void TearDown() {
381 // Clean up resources before we reset
Tony Barbour300a6082015-04-07 13:44:53 -0600382 ShutdownFramework();
Tony Barbour0b4d9562015-04-09 10:48:04 -0600383 delete m_errorMonitor;
Tony Barbour300a6082015-04-07 13:44:53 -0600384 }
Ian Elliott2c1daf52016-05-12 09:41:46 -0600385
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600386 VkLayerTest() { m_enableWSI = false; }
Tony Barbour300a6082015-04-07 13:44:53 -0600387};
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500388
Karl Schultz6addd812016-02-02 17:17:23 -0700389VkResult VkLayerTest::BeginCommandBuffer(VkCommandBufferObj &commandBuffer) {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600390 VkResult result;
Tony Barbour300a6082015-04-07 13:44:53 -0600391
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800392 result = commandBuffer.BeginCommandBuffer();
Tony Barbour300a6082015-04-07 13:44:53 -0600393
394 /*
395 * For render test all drawing happens in a single render pass
396 * on a single command buffer.
397 */
Chris Forbes76a5eeb2015-06-16 14:05:59 +1200398 if (VK_SUCCESS == result && renderPass()) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800399 commandBuffer.BeginRenderPass(renderPassBeginInfo());
Tony Barbour300a6082015-04-07 13:44:53 -0600400 }
401
402 return result;
403}
404
Karl Schultz6addd812016-02-02 17:17:23 -0700405VkResult VkLayerTest::EndCommandBuffer(VkCommandBufferObj &commandBuffer) {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600406 VkResult result;
Tony Barbour300a6082015-04-07 13:44:53 -0600407
Chris Forbes76a5eeb2015-06-16 14:05:59 +1200408 if (renderPass()) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800409 commandBuffer.EndRenderPass();
Chris Forbes76a5eeb2015-06-16 14:05:59 +1200410 }
Tony Barbour300a6082015-04-07 13:44:53 -0600411
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800412 result = commandBuffer.EndCommandBuffer();
Tony Barbour300a6082015-04-07 13:44:53 -0600413
414 return result;
415}
416
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600417void VkLayerTest::VKTriangleTest(const char *vertShaderText, const char *fragShaderText, BsoFailSelect failMask) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500418 // Create identity matrix
419 int i;
420 struct vktriangle_vs_uniform data;
421
422 glm::mat4 Projection = glm::mat4(1.0f);
Karl Schultz6addd812016-02-02 17:17:23 -0700423 glm::mat4 View = glm::mat4(1.0f);
424 glm::mat4 Model = glm::mat4(1.0f);
425 glm::mat4 MVP = Projection * View * Model;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500426 const int matrixSize = sizeof(MVP);
Karl Schultz6addd812016-02-02 17:17:23 -0700427 const int bufSize = sizeof(vktriangle_vs_uniform) / sizeof(float);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500428
429 memcpy(&data.mvp, &MVP[0][0], matrixSize);
430
Karl Schultz6addd812016-02-02 17:17:23 -0700431 static const Vertex tri_data[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600432 {XYZ1(-1, -1, 0), XYZ1(1.f, 0.f, 0.f)}, {XYZ1(1, -1, 0), XYZ1(0.f, 1.f, 0.f)}, {XYZ1(0, 1, 0), XYZ1(0.f, 0.f, 1.f)},
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500433 };
434
Karl Schultz6addd812016-02-02 17:17:23 -0700435 for (i = 0; i < 3; i++) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500436 data.position[i][0] = tri_data[i].posX;
437 data.position[i][1] = tri_data[i].posY;
438 data.position[i][2] = tri_data[i].posZ;
439 data.position[i][3] = tri_data[i].posW;
Karl Schultz6addd812016-02-02 17:17:23 -0700440 data.color[i][0] = tri_data[i].r;
441 data.color[i][1] = tri_data[i].g;
442 data.color[i][2] = tri_data[i].b;
443 data.color[i][3] = tri_data[i].a;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500444 }
445
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500446 ASSERT_NO_FATAL_FAILURE(InitViewport());
447
Chris Forbesbcfaadd2016-09-16 14:13:53 +1200448 VkConstantBufferObj constantBuffer(m_device, bufSize * 2, sizeof(float), (const void *)&data,
449 VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500450
Karl Schultz6addd812016-02-02 17:17:23 -0700451 VkShaderObj vs(m_device, vertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600452 VkShaderObj ps(m_device, fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500453
454 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +0800455 pipelineobj.AddColorAttachment();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500456 pipelineobj.AddShader(&vs);
457 pipelineobj.AddShader(&ps);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600458 if (failMask & BsoFailLineWidth) {
459 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_LINE_WIDTH);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600460 VkPipelineInputAssemblyStateCreateInfo ia_state = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600461 ia_state.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600462 ia_state.topology = VK_PRIMITIVE_TOPOLOGY_LINE_LIST;
463 pipelineobj.SetInputAssembly(&ia_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600464 }
465 if (failMask & BsoFailDepthBias) {
466 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_DEPTH_BIAS);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600467 VkPipelineRasterizationStateCreateInfo rs_state = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600468 rs_state.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600469 rs_state.depthBiasEnable = VK_TRUE;
Mark Young7394fdd2016-03-31 14:56:43 -0600470 rs_state.lineWidth = 1.0f;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600471 pipelineobj.SetRasterization(&rs_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600472 }
Rene Lindsayacbf5e62016-12-15 18:47:11 -0700473 // Viewport and scissors must stay in sync or other errors will occur than
Karl Schultz6addd812016-02-02 17:17:23 -0700474 // the ones we want
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600475 if (failMask & BsoFailViewport) {
476 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_VIEWPORT);
477 }
478 if (failMask & BsoFailScissor) {
479 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_SCISSOR);
480 }
481 if (failMask & BsoFailBlend) {
482 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_BLEND_CONSTANTS);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600483 VkPipelineColorBlendAttachmentState att_state = {};
484 att_state.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
485 att_state.blendEnable = VK_TRUE;
486 pipelineobj.AddColorAttachment(0, &att_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600487 }
488 if (failMask & BsoFailDepthBounds) {
489 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_DEPTH_BOUNDS);
490 }
491 if (failMask & BsoFailStencilReadMask) {
492 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK);
493 }
494 if (failMask & BsoFailStencilWriteMask) {
495 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_WRITE_MASK);
496 }
497 if (failMask & BsoFailStencilReference) {
498 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_REFERENCE);
499 }
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500500
501 VkDescriptorSetObj descriptorSet(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600502 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, constantBuffer);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500503
504 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -0600505 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500506
Tony Barbourfe3351b2015-07-28 10:17:20 -0600507 GenericDrawPreparation(pipelineobj, descriptorSet, failMask);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500508
509 // render triangle
Tobin Ehlis379ba3b2016-07-19 11:22:29 -0600510 if (failMask & BsoFailIndexBuffer) {
511 // Use DrawIndexed w/o an index buffer bound
512 DrawIndexed(3, 1, 0, 0, 0);
513 } else {
514 Draw(3, 1, 0, 0);
515 }
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500516
Mark Muellerd4914412016-06-13 17:52:06 -0600517 if (failMask & BsoFailCmdClearAttachments) {
518 VkClearAttachment color_attachment = {};
519 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
520 color_attachment.colorAttachment = 1; // Someone who knew what they were doing would use 0 for the index;
521 VkClearRect clear_rect = {{{0, 0}, {static_cast<uint32_t>(m_width), static_cast<uint32_t>(m_height)}}, 0, 0};
522
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600523 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Muellerd4914412016-06-13 17:52:06 -0600524 }
525
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500526 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -0600527 EndCommandBuffer();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500528
Tony Barbourfe3351b2015-07-28 10:17:20 -0600529 QueueCommandBuffer();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500530}
531
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600532void VkLayerTest::GenericDrawPreparation(VkCommandBufferObj *commandBuffer, VkPipelineObj &pipelineobj,
533 VkDescriptorSetObj &descriptorSet, BsoFailSelect failMask) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500534 if (m_depthStencil->Initialized()) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600535 commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, m_depthStencil);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500536 } else {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600537 commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500538 }
539
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800540 commandBuffer->PrepareAttachments();
Karl Schultz6addd812016-02-02 17:17:23 -0700541 // Make sure depthWriteEnable is set so that Depth fail test will work
542 // correctly
543 // Make sure stencilTestEnable is set so that Stencil fail test will work
544 // correctly
Tony Barboureb254902015-07-15 12:50:33 -0600545 VkStencilOpState stencil = {};
Chia-I Wu1b99bb22015-10-27 19:25:11 +0800546 stencil.failOp = VK_STENCIL_OP_KEEP;
547 stencil.passOp = VK_STENCIL_OP_KEEP;
548 stencil.depthFailOp = VK_STENCIL_OP_KEEP;
549 stencil.compareOp = VK_COMPARE_OP_NEVER;
Tony Barboureb254902015-07-15 12:50:33 -0600550
551 VkPipelineDepthStencilStateCreateInfo ds_ci = {};
552 ds_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO;
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600553 ds_ci.pNext = NULL;
554 ds_ci.depthTestEnable = VK_FALSE;
555 ds_ci.depthWriteEnable = VK_TRUE;
556 ds_ci.depthCompareOp = VK_COMPARE_OP_NEVER;
557 ds_ci.depthBoundsTestEnable = VK_FALSE;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600558 if (failMask & BsoFailDepthBounds) {
559 ds_ci.depthBoundsTestEnable = VK_TRUE;
Tobin Ehlis21c88352016-05-26 06:15:45 -0600560 ds_ci.maxDepthBounds = 0.0f;
561 ds_ci.minDepthBounds = 0.0f;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600562 }
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600563 ds_ci.stencilTestEnable = VK_TRUE;
564 ds_ci.front = stencil;
565 ds_ci.back = stencil;
Tony Barboureb254902015-07-15 12:50:33 -0600566
Tobin Ehlis4bf96d12015-06-25 11:58:41 -0600567 pipelineobj.SetDepthStencil(&ds_ci);
Tobin Ehlisd332f282015-10-02 11:00:56 -0600568 pipelineobj.SetViewport(m_viewports);
569 pipelineobj.SetScissor(m_scissors);
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800570 descriptorSet.CreateVKDescriptorSet(commandBuffer);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600571 VkResult err = pipelineobj.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Cody Northrop29a08f22015-08-27 10:20:35 -0600572 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800573 commandBuffer->BindPipeline(pipelineobj);
574 commandBuffer->BindDescriptorSet(descriptorSet);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500575}
576
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600577class VkPositiveLayerTest : public VkLayerTest {
578 public:
579 protected:
580};
581
Ian Elliott2c1daf52016-05-12 09:41:46 -0600582class VkWsiEnabledLayerTest : public VkLayerTest {
583 public:
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600584 protected:
585 VkWsiEnabledLayerTest() { m_enableWSI = true; }
Ian Elliott2c1daf52016-05-12 09:41:46 -0600586};
587
Mark Muellerdfe37552016-07-07 14:47:42 -0600588class VkBufferTest {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600589 public:
Mark Muellerdfe37552016-07-07 14:47:42 -0600590 enum eTestEnFlags {
591 eDoubleDelete,
592 eInvalidDeviceOffset,
593 eInvalidMemoryOffset,
594 eBindNullBuffer,
595 eFreeInvalidHandle,
Mark Mueller4042b652016-09-05 22:52:21 -0600596 eNone,
Mark Muellerdfe37552016-07-07 14:47:42 -0600597 };
598
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600599 enum eTestConditions { eOffsetAlignment = 1 };
Mark Muellerdfe37552016-07-07 14:47:42 -0600600
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600601 static bool GetTestConditionValid(VkDeviceObj *aVulkanDevice, eTestEnFlags aTestFlag, VkBufferUsageFlags aBufferUsage = 0) {
602 if (eInvalidDeviceOffset != aTestFlag && eInvalidMemoryOffset != aTestFlag) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600603 return true;
604 }
605 VkDeviceSize offset_limit = 0;
606 if (eInvalidMemoryOffset == aTestFlag) {
607 VkBuffer vulkanBuffer;
608 VkBufferCreateInfo buffer_create_info = {};
609 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
610 buffer_create_info.size = 32;
611 buffer_create_info.usage = aBufferUsage;
612
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600613 vkCreateBuffer(aVulkanDevice->device(), &buffer_create_info, nullptr, &vulkanBuffer);
Mark Mueller4042b652016-09-05 22:52:21 -0600614 VkMemoryRequirements memory_reqs = {};
Mark Muellerdfe37552016-07-07 14:47:42 -0600615
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600616 vkGetBufferMemoryRequirements(aVulkanDevice->device(), vulkanBuffer, &memory_reqs);
Mark Muellerdfe37552016-07-07 14:47:42 -0600617 vkDestroyBuffer(aVulkanDevice->device(), vulkanBuffer, nullptr);
618 offset_limit = memory_reqs.alignment;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600619 } else if ((VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT | VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT) & aBufferUsage) {
620 offset_limit = aVulkanDevice->props.limits.minTexelBufferOffsetAlignment;
Mark Muellerdfe37552016-07-07 14:47:42 -0600621 } else if (VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT & aBufferUsage) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600622 offset_limit = aVulkanDevice->props.limits.minUniformBufferOffsetAlignment;
Mark Muellerdfe37552016-07-07 14:47:42 -0600623 } else if (VK_BUFFER_USAGE_STORAGE_BUFFER_BIT & aBufferUsage) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600624 offset_limit = aVulkanDevice->props.limits.minStorageBufferOffsetAlignment;
Mark Muellerdfe37552016-07-07 14:47:42 -0600625 }
626 if (eOffsetAlignment < offset_limit) {
627 return true;
628 }
629 return false;
630 }
631
632 // A constructor which performs validation tests within construction.
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600633 VkBufferTest(VkDeviceObj *aVulkanDevice, VkBufferUsageFlags aBufferUsage, eTestEnFlags aTestFlag = eNone)
634 : AllocateCurrent(false), BoundCurrent(false), CreateCurrent(false), VulkanDevice(aVulkanDevice->device()) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600635
636 if (eBindNullBuffer == aTestFlag) {
637 VulkanMemory = 0;
638 vkBindBufferMemory(VulkanDevice, VulkanBuffer, VulkanMemory, 0);
639 } else {
640 VkBufferCreateInfo buffer_create_info = {};
641 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
642 buffer_create_info.size = 32;
643 buffer_create_info.usage = aBufferUsage;
644
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600645 vkCreateBuffer(VulkanDevice, &buffer_create_info, nullptr, &VulkanBuffer);
Mark Muellerdfe37552016-07-07 14:47:42 -0600646
647 CreateCurrent = true;
648
649 VkMemoryRequirements memory_requirements;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600650 vkGetBufferMemoryRequirements(VulkanDevice, VulkanBuffer, &memory_requirements);
Mark Muellerdfe37552016-07-07 14:47:42 -0600651
652 VkMemoryAllocateInfo memory_allocate_info = {};
653 memory_allocate_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
654 memory_allocate_info.allocationSize = memory_requirements.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600655 bool pass = aVulkanDevice->phy().set_memory_type(memory_requirements.memoryTypeBits, &memory_allocate_info,
656 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
Mark Muellerdfe37552016-07-07 14:47:42 -0600657 if (!pass) {
658 vkDestroyBuffer(VulkanDevice, VulkanBuffer, nullptr);
659 return;
660 }
661
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600662 vkAllocateMemory(VulkanDevice, &memory_allocate_info, NULL, &VulkanMemory);
Mark Muellerdfe37552016-07-07 14:47:42 -0600663 AllocateCurrent = true;
664 // NB: 1 is intentionally an invalid offset value
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600665 const bool offset_en = eInvalidDeviceOffset == aTestFlag || eInvalidMemoryOffset == aTestFlag;
666 vkBindBufferMemory(VulkanDevice, VulkanBuffer, VulkanMemory, offset_en ? eOffsetAlignment : 0);
Mark Muellerdfe37552016-07-07 14:47:42 -0600667 BoundCurrent = true;
668
669 InvalidDeleteEn = (eFreeInvalidHandle == aTestFlag);
670 }
671 }
672
673 ~VkBufferTest() {
674 if (CreateCurrent) {
675 vkDestroyBuffer(VulkanDevice, VulkanBuffer, nullptr);
676 }
677 if (AllocateCurrent) {
678 if (InvalidDeleteEn) {
679 union {
680 VkDeviceMemory device_memory;
681 unsigned long long index_access;
682 } bad_index;
683
684 bad_index.device_memory = VulkanMemory;
685 bad_index.index_access++;
686
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600687 vkFreeMemory(VulkanDevice, bad_index.device_memory, nullptr);
Mark Muellerdfe37552016-07-07 14:47:42 -0600688 }
689 vkFreeMemory(VulkanDevice, VulkanMemory, nullptr);
690 }
691 }
692
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600693 bool GetBufferCurrent() { return AllocateCurrent && BoundCurrent && CreateCurrent; }
Mark Muellerdfe37552016-07-07 14:47:42 -0600694
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600695 const VkBuffer &GetBuffer() { return VulkanBuffer; }
Mark Muellerdfe37552016-07-07 14:47:42 -0600696
697 void TestDoubleDestroy() {
698 // Destroy the buffer but leave the flag set, which will cause
699 // the buffer to be destroyed again in the destructor.
700 vkDestroyBuffer(VulkanDevice, VulkanBuffer, nullptr);
701 }
702
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600703 protected:
Mark Muellerdfe37552016-07-07 14:47:42 -0600704 bool AllocateCurrent;
705 bool BoundCurrent;
706 bool CreateCurrent;
707 bool InvalidDeleteEn;
708
709 VkBuffer VulkanBuffer;
710 VkDevice VulkanDevice;
711 VkDeviceMemory VulkanMemory;
Mark Muellerdfe37552016-07-07 14:47:42 -0600712};
713
714class VkVerticesObj {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600715 public:
716 VkVerticesObj(VkDeviceObj *aVulkanDevice, unsigned aAttributeCount, unsigned aBindingCount, unsigned aByteStride,
Mark Muellerdfe37552016-07-07 14:47:42 -0600717 VkDeviceSize aVertexCount, const float *aVerticies)
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600718 : BoundCurrent(false), AttributeCount(aAttributeCount), BindingCount(aBindingCount), BindId(BindIdGenerator),
Mark Muellerdfe37552016-07-07 14:47:42 -0600719 PipelineVertexInputStateCreateInfo(),
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600720 VulkanMemoryBuffer(aVulkanDevice, 1, static_cast<int>(aByteStride * aVertexCount),
721 reinterpret_cast<const void *>(aVerticies), VK_BUFFER_USAGE_VERTEX_BUFFER_BIT) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600722 BindIdGenerator++; // NB: This can wrap w/misuse
723
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600724 VertexInputAttributeDescription = new VkVertexInputAttributeDescription[AttributeCount];
725 VertexInputBindingDescription = new VkVertexInputBindingDescription[BindingCount];
Mark Muellerdfe37552016-07-07 14:47:42 -0600726
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600727 PipelineVertexInputStateCreateInfo.pVertexAttributeDescriptions = VertexInputAttributeDescription;
728 PipelineVertexInputStateCreateInfo.vertexAttributeDescriptionCount = AttributeCount;
729 PipelineVertexInputStateCreateInfo.pVertexBindingDescriptions = VertexInputBindingDescription;
730 PipelineVertexInputStateCreateInfo.vertexBindingDescriptionCount = BindingCount;
731 PipelineVertexInputStateCreateInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
Mark Muellerdfe37552016-07-07 14:47:42 -0600732
733 unsigned i = 0;
734 do {
735 VertexInputAttributeDescription[i].binding = BindId;
736 VertexInputAttributeDescription[i].location = i;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600737 VertexInputAttributeDescription[i].format = VK_FORMAT_R32G32B32_SFLOAT;
738 VertexInputAttributeDescription[i].offset = sizeof(float) * aByteStride;
Mark Muellerdfe37552016-07-07 14:47:42 -0600739 i++;
740 } while (AttributeCount < i);
741
742 i = 0;
743 do {
744 VertexInputBindingDescription[i].binding = BindId;
745 VertexInputBindingDescription[i].stride = aByteStride;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600746 VertexInputBindingDescription[i].inputRate = VK_VERTEX_INPUT_RATE_VERTEX;
Mark Muellerdfe37552016-07-07 14:47:42 -0600747 i++;
748 } while (BindingCount < i);
749 }
750
751 ~VkVerticesObj() {
752 if (VertexInputAttributeDescription) {
753 delete[] VertexInputAttributeDescription;
754 }
755 if (VertexInputBindingDescription) {
756 delete[] VertexInputBindingDescription;
757 }
758 }
759
760 bool AddVertexInputToPipe(VkPipelineObj &aPipelineObj) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600761 aPipelineObj.AddVertexInputAttribs(VertexInputAttributeDescription, AttributeCount);
762 aPipelineObj.AddVertexInputBindings(VertexInputBindingDescription, BindingCount);
Mark Muellerdfe37552016-07-07 14:47:42 -0600763 return true;
764 }
765
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600766 void BindVertexBuffers(VkCommandBuffer aCommandBuffer, unsigned aOffsetCount = 0, VkDeviceSize *aOffsetList = nullptr) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600767 VkDeviceSize *offsetList;
768 unsigned offsetCount;
769
770 if (aOffsetCount) {
771 offsetList = aOffsetList;
772 offsetCount = aOffsetCount;
773 } else {
774 offsetList = new VkDeviceSize[1]();
775 offsetCount = 1;
776 }
777
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600778 vkCmdBindVertexBuffers(aCommandBuffer, BindId, offsetCount, &VulkanMemoryBuffer.handle(), offsetList);
Mark Muellerdfe37552016-07-07 14:47:42 -0600779 BoundCurrent = true;
780
781 if (!aOffsetCount) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600782 delete[] offsetList;
Mark Muellerdfe37552016-07-07 14:47:42 -0600783 }
784 }
785
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600786 protected:
Mark Muellerdfe37552016-07-07 14:47:42 -0600787 static uint32_t BindIdGenerator;
788
789 bool BoundCurrent;
790 unsigned AttributeCount;
791 unsigned BindingCount;
792 uint32_t BindId;
793
794 VkPipelineVertexInputStateCreateInfo PipelineVertexInputStateCreateInfo;
795 VkVertexInputAttributeDescription *VertexInputAttributeDescription;
796 VkVertexInputBindingDescription *VertexInputBindingDescription;
797 VkConstantBufferObj VulkanMemoryBuffer;
798};
799
800uint32_t VkVerticesObj::BindIdGenerator;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500801// ********************************************************************************************************************
802// ********************************************************************************************************************
803// ********************************************************************************************************************
804// ********************************************************************************************************************
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600805#if PARAMETER_VALIDATION_TESTS
806TEST_F(VkLayerTest, RequiredParameter) {
807 TEST_DESCRIPTION("Specify VK_NULL_HANDLE, NULL, and 0 for required handle, "
808 "pointer, array, and array count parameters");
809
810 ASSERT_NO_FATAL_FAILURE(InitState());
811
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600812 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pFeatures specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600813 // Specify NULL for a pointer to a handle
814 // Expected to trigger an error with
815 // parameter_validation::validate_required_pointer
816 vkGetPhysicalDeviceFeatures(gpu(), NULL);
817 m_errorMonitor->VerifyFound();
818
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600819 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
820 "required parameter pQueueFamilyPropertyCount specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600821 // Specify NULL for pointer to array count
822 // Expected to trigger an error with parameter_validation::validate_array
Dustin Gravesa4bb8c12016-05-16 17:22:51 -0600823 vkGetPhysicalDeviceQueueFamilyProperties(gpu(), NULL, NULL);
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600824 m_errorMonitor->VerifyFound();
825
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600826 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter viewportCount must be greater than 0");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600827 // Specify 0 for a required array count
828 // Expected to trigger an error with parameter_validation::validate_array
829 VkViewport view_port = {};
830 m_commandBuffer->SetViewport(0, 0, &view_port);
831 m_errorMonitor->VerifyFound();
832
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600833 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pViewports specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600834 // Specify NULL for a required array
835 // Expected to trigger an error with parameter_validation::validate_array
836 m_commandBuffer->SetViewport(0, 1, NULL);
837 m_errorMonitor->VerifyFound();
838
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600839 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter memory specified as VK_NULL_HANDLE");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600840 // Specify VK_NULL_HANDLE for a required handle
841 // Expected to trigger an error with
842 // parameter_validation::validate_required_handle
843 vkUnmapMemory(device(), VK_NULL_HANDLE);
844 m_errorMonitor->VerifyFound();
845
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600846 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
847 "required parameter pFences[0] specified as VK_NULL_HANDLE");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600848 // Specify VK_NULL_HANDLE for a required handle array entry
849 // Expected to trigger an error with
850 // parameter_validation::validate_required_handle_array
851 VkFence fence = VK_NULL_HANDLE;
852 vkResetFences(device(), 1, &fence);
853 m_errorMonitor->VerifyFound();
854
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600855 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pAllocateInfo specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600856 // Specify NULL for a required struct pointer
857 // Expected to trigger an error with
858 // parameter_validation::validate_struct_type
859 VkDeviceMemory memory = VK_NULL_HANDLE;
860 vkAllocateMemory(device(), NULL, NULL, &memory);
861 m_errorMonitor->VerifyFound();
862
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600863 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "value of faceMask must not be 0");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600864 // Specify 0 for a required VkFlags parameter
865 // Expected to trigger an error with parameter_validation::validate_flags
866 m_commandBuffer->SetStencilReference(0, 0);
867 m_errorMonitor->VerifyFound();
868
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600869 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "value of pSubmits[0].pWaitDstStageMask[0] must not be 0");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600870 // Specify 0 for a required VkFlags array entry
871 // Expected to trigger an error with
872 // parameter_validation::validate_flags_array
873 VkSemaphore semaphore = VK_NULL_HANDLE;
874 VkPipelineStageFlags stageFlags = 0;
875 VkSubmitInfo submitInfo = {};
876 submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
877 submitInfo.waitSemaphoreCount = 1;
878 submitInfo.pWaitSemaphores = &semaphore;
879 submitInfo.pWaitDstStageMask = &stageFlags;
880 vkQueueSubmit(m_device->m_queue, 1, &submitInfo, VK_NULL_HANDLE);
881 m_errorMonitor->VerifyFound();
882}
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600883
Dustin Gravesfce74c02016-05-10 11:42:58 -0600884TEST_F(VkLayerTest, ReservedParameter) {
885 TEST_DESCRIPTION("Specify a non-zero value for a reserved parameter");
886
887 ASSERT_NO_FATAL_FAILURE(InitState());
888
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600889 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " must be 0");
Dustin Gravesfce74c02016-05-10 11:42:58 -0600890 // Specify 0 for a reserved VkFlags parameter
891 // Expected to trigger an error with
892 // parameter_validation::validate_reserved_flags
893 VkEvent event_handle = VK_NULL_HANDLE;
894 VkEventCreateInfo event_info = {};
895 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
896 event_info.flags = 1;
897 vkCreateEvent(device(), &event_info, NULL, &event_handle);
898 m_errorMonitor->VerifyFound();
899}
900
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600901TEST_F(VkLayerTest, InvalidStructSType) {
902 TEST_DESCRIPTION("Specify an invalid VkStructureType for a Vulkan "
903 "structure's sType field");
904
905 ASSERT_NO_FATAL_FAILURE(InitState());
906
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600907 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pAllocateInfo->sType must be");
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600908 // Zero struct memory, effectively setting sType to
909 // VK_STRUCTURE_TYPE_APPLICATION_INFO
910 // Expected to trigger an error with
911 // parameter_validation::validate_struct_type
912 VkMemoryAllocateInfo alloc_info = {};
913 VkDeviceMemory memory = VK_NULL_HANDLE;
914 vkAllocateMemory(device(), &alloc_info, NULL, &memory);
915 m_errorMonitor->VerifyFound();
916
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600917 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pSubmits[0].sType must be");
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600918 // Zero struct memory, effectively setting sType to
919 // VK_STRUCTURE_TYPE_APPLICATION_INFO
920 // Expected to trigger an error with
921 // parameter_validation::validate_struct_type_array
922 VkSubmitInfo submit_info = {};
923 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
924 m_errorMonitor->VerifyFound();
925}
926
927TEST_F(VkLayerTest, InvalidStructPNext) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600928 TEST_DESCRIPTION("Specify an invalid value for a Vulkan structure's pNext field");
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600929
930 ASSERT_NO_FATAL_FAILURE(InitState());
931
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600932 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "value of pCreateInfo->pNext must be NULL");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600933 // Set VkMemoryAllocateInfo::pNext to a non-NULL value, when pNext must be NULL.
Karl Schultz38b50992016-07-11 16:09:09 -0600934 // Need to pick a function that has no allowed pNext structure types.
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600935 // Expected to trigger an error with parameter_validation::validate_struct_pnext
Karl Schultz38b50992016-07-11 16:09:09 -0600936 VkEvent event = VK_NULL_HANDLE;
Karl Schultz70db3902016-07-11 16:22:10 -0600937 VkEventCreateInfo event_alloc_info = {};
Karl Schultz38b50992016-07-11 16:09:09 -0600938 // Zero-initialization will provide the correct sType
939 VkApplicationInfo app_info = {};
940 event_alloc_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
941 event_alloc_info.pNext = &app_info;
942 vkCreateEvent(device(), &event_alloc_info, NULL, &event);
943 m_errorMonitor->VerifyFound();
944
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600945 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
946 " chain includes a structure with unexpected VkStructureType ");
Karl Schultz38b50992016-07-11 16:09:09 -0600947 // Set VkMemoryAllocateInfo::pNext to a non-NULL value, but use
948 // a function that has allowed pNext structure types and specify
949 // a structure type that is not allowed.
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600950 // Expected to trigger an error with parameter_validation::validate_struct_pnext
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600951 VkDeviceMemory memory = VK_NULL_HANDLE;
Dustin Graves47b6cba2016-05-10 17:34:38 -0600952 VkMemoryAllocateInfo memory_alloc_info = {};
953 memory_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
954 memory_alloc_info.pNext = &app_info;
955 vkAllocateMemory(device(), &memory_alloc_info, NULL, &memory);
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600956 m_errorMonitor->VerifyFound();
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600957}
Dustin Graves5d33d532016-05-09 16:21:12 -0600958
959TEST_F(VkLayerTest, UnrecognizedValue) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600960 TEST_DESCRIPTION("Specify unrecognized Vulkan enumeration, flags, and VkBool32 values");
Dustin Graves5d33d532016-05-09 16:21:12 -0600961
962 ASSERT_NO_FATAL_FAILURE(InitState());
963
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600964 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "does not fall within the begin..end "
965 "range of the core VkFormat "
966 "enumeration tokens");
Dustin Graves5d33d532016-05-09 16:21:12 -0600967 // Specify an invalid VkFormat value
968 // Expected to trigger an error with
969 // parameter_validation::validate_ranged_enum
970 VkFormatProperties format_properties;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600971 vkGetPhysicalDeviceFormatProperties(gpu(), static_cast<VkFormat>(8000), &format_properties);
Dustin Graves5d33d532016-05-09 16:21:12 -0600972 m_errorMonitor->VerifyFound();
973
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600974 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "contains flag bits that are not recognized members of");
Dustin Graves5d33d532016-05-09 16:21:12 -0600975 // Specify an invalid VkFlags bitmask value
976 // Expected to trigger an error with parameter_validation::validate_flags
977 VkImageFormatProperties image_format_properties;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600978 vkGetPhysicalDeviceImageFormatProperties(gpu(), VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
979 static_cast<VkImageUsageFlags>(1 << 25), 0, &image_format_properties);
Dustin Graves5d33d532016-05-09 16:21:12 -0600980 m_errorMonitor->VerifyFound();
981
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600982 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "contains flag bits that are not recognized members of");
Dustin Graves5d33d532016-05-09 16:21:12 -0600983 // Specify an invalid VkFlags array entry
984 // Expected to trigger an error with
985 // parameter_validation::validate_flags_array
986 VkSemaphore semaphore = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600987 VkPipelineStageFlags stage_flags = static_cast<VkPipelineStageFlags>(1 << 25);
Dustin Graves5d33d532016-05-09 16:21:12 -0600988 VkSubmitInfo submit_info = {};
989 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
990 submit_info.waitSemaphoreCount = 1;
991 submit_info.pWaitSemaphores = &semaphore;
992 submit_info.pWaitDstStageMask = &stage_flags;
993 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
994 m_errorMonitor->VerifyFound();
995
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600996 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "is neither VK_TRUE nor VK_FALSE");
Dustin Graves5d33d532016-05-09 16:21:12 -0600997 // Specify an invalid VkBool32 value
998 // Expected to trigger a warning with
999 // parameter_validation::validate_bool32
1000 VkSampler sampler = VK_NULL_HANDLE;
1001 VkSamplerCreateInfo sampler_info = {};
1002 sampler_info.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
1003 sampler_info.pNext = NULL;
1004 sampler_info.magFilter = VK_FILTER_NEAREST;
1005 sampler_info.minFilter = VK_FILTER_NEAREST;
1006 sampler_info.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
1007 sampler_info.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
1008 sampler_info.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
1009 sampler_info.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
1010 sampler_info.mipLodBias = 1.0;
1011 sampler_info.maxAnisotropy = 1;
1012 sampler_info.compareEnable = VK_FALSE;
1013 sampler_info.compareOp = VK_COMPARE_OP_NEVER;
1014 sampler_info.minLod = 1.0;
1015 sampler_info.maxLod = 1.0;
1016 sampler_info.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
1017 sampler_info.unnormalizedCoordinates = VK_FALSE;
1018 // Not VK_TRUE or VK_FALSE
1019 sampler_info.anisotropyEnable = 3;
1020 vkCreateSampler(m_device->device(), &sampler_info, NULL, &sampler);
1021 m_errorMonitor->VerifyFound();
1022}
Dustin Gravesfce74c02016-05-10 11:42:58 -06001023
1024TEST_F(VkLayerTest, FailedReturnValue) {
1025 TEST_DESCRIPTION("Check for a message describing a VkResult failure code");
1026
1027 ASSERT_NO_FATAL_FAILURE(InitState());
1028
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001029 // Find an unsupported image format
1030 VkFormat unsupported = VK_FORMAT_UNDEFINED;
1031 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
1032 VkFormat format = static_cast<VkFormat>(f);
1033 VkFormatProperties fProps = m_device->format_properties(format);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001034 if (format != VK_FORMAT_UNDEFINED && fProps.linearTilingFeatures == 0 && fProps.optimalTilingFeatures == 0) {
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001035 unsupported = format;
1036 break;
1037 }
1038 }
1039
1040 if (unsupported != VK_FORMAT_UNDEFINED) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001041 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
1042 "the requested format is not supported on this device");
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001043 // Specify an unsupported VkFormat value to generate a
1044 // VK_ERROR_FORMAT_NOT_SUPPORTED return code
1045 // Expected to trigger a warning from
1046 // parameter_validation::validate_result
1047 VkImageFormatProperties image_format_properties;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001048 VkResult err = vkGetPhysicalDeviceImageFormatProperties(gpu(), unsupported, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
1049 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, 0, &image_format_properties);
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001050 ASSERT_TRUE(err == VK_ERROR_FORMAT_NOT_SUPPORTED);
1051 m_errorMonitor->VerifyFound();
1052 }
Dustin Gravesfce74c02016-05-10 11:42:58 -06001053}
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001054
1055TEST_F(VkLayerTest, UpdateBufferAlignment) {
1056 TEST_DESCRIPTION("Check alignment parameters for vkCmdUpdateBuffer");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001057 uint32_t updateData[] = {1, 2, 3, 4, 5, 6, 7, 8};
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001058
1059 ASSERT_NO_FATAL_FAILURE(InitState());
1060
1061 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
1062 vk_testing::Buffer buffer;
1063 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
1064
1065 BeginCommandBuffer();
1066 // Introduce failure by using dstOffset that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001067 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001068 m_commandBuffer->UpdateBuffer(buffer.handle(), 1, 4, updateData);
1069 m_errorMonitor->VerifyFound();
1070
1071 // Introduce failure by using dataSize that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001072 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001073 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, 6, updateData);
1074 m_errorMonitor->VerifyFound();
1075
1076 // Introduce failure by using dataSize that is < 0
1077 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001078 "must be greater than zero and less than or equal to 65536");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001079 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, -44, updateData);
1080 m_errorMonitor->VerifyFound();
1081
1082 // Introduce failure by using dataSize that is > 65536
1083 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001084 "must be greater than zero and less than or equal to 65536");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001085 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, 80000, updateData);
1086 m_errorMonitor->VerifyFound();
1087
1088 EndCommandBuffer();
1089}
1090
1091TEST_F(VkLayerTest, FillBufferAlignment) {
1092 TEST_DESCRIPTION("Check alignment parameters for vkCmdFillBuffer");
1093
1094 ASSERT_NO_FATAL_FAILURE(InitState());
1095
1096 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
1097 vk_testing::Buffer buffer;
1098 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
1099
1100 BeginCommandBuffer();
1101
1102 // Introduce failure by using dstOffset that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001103 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001104 m_commandBuffer->FillBuffer(buffer.handle(), 1, 4, 0x11111111);
1105 m_errorMonitor->VerifyFound();
1106
1107 // Introduce failure by using size that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001108 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001109 m_commandBuffer->FillBuffer(buffer.handle(), 0, 6, 0x11111111);
1110 m_errorMonitor->VerifyFound();
1111
1112 // Introduce failure by using size that is zero
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001113 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "must be greater than zero");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001114 m_commandBuffer->FillBuffer(buffer.handle(), 0, 0, 0x11111111);
1115 m_errorMonitor->VerifyFound();
1116
1117 EndCommandBuffer();
1118}
Dustin Graves40f35822016-06-23 11:12:53 -06001119
Cortd889ff92016-07-27 09:51:27 -07001120TEST_F(VkLayerTest, PSOPolygonModeInvalid) {
1121 VkResult err;
1122
1123 TEST_DESCRIPTION("Attempt to use a non-solid polygon fill mode in a "
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001124 "pipeline when this feature is not enabled.");
Cortd889ff92016-07-27 09:51:27 -07001125
1126 ASSERT_NO_FATAL_FAILURE(InitState());
1127 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1128
1129 std::vector<const char *> device_extension_names;
1130 auto features = m_device->phy().features();
1131 // Artificially disable support for non-solid fill modes
1132 features.fillModeNonSolid = false;
1133 // The sacrificial device object
1134 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
1135
1136 VkRenderpassObj render_pass(&test_device);
1137
1138 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1139 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1140 pipeline_layout_ci.setLayoutCount = 0;
1141 pipeline_layout_ci.pSetLayouts = NULL;
1142
1143 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001144 err = vkCreatePipelineLayout(test_device.device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Cortd889ff92016-07-27 09:51:27 -07001145 ASSERT_VK_SUCCESS(err);
1146
1147 VkPipelineRasterizationStateCreateInfo rs_ci = {};
1148 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
1149 rs_ci.pNext = nullptr;
1150 rs_ci.lineWidth = 1.0f;
1151 rs_ci.rasterizerDiscardEnable = true;
1152
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001153 VkShaderObj vs(&test_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
1154 VkShaderObj fs(&test_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Cortd889ff92016-07-27 09:51:27 -07001155
Mark Lobodzinski5e644732016-08-15 16:51:19 -06001156 // Set polygonMode to unsupported value POINT, should fail
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001157 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1158 "polygonMode cannot be VK_POLYGON_MODE_POINT or VK_POLYGON_MODE_LINE");
Cortd889ff92016-07-27 09:51:27 -07001159 {
1160 VkPipelineObj pipe(&test_device);
1161 pipe.AddShader(&vs);
1162 pipe.AddShader(&fs);
1163 pipe.AddColorAttachment();
1164 // Introduce failure by setting unsupported polygon mode
1165 rs_ci.polygonMode = VK_POLYGON_MODE_POINT;
1166 pipe.SetRasterization(&rs_ci);
1167 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
1168 }
1169 m_errorMonitor->VerifyFound();
1170
1171 // Try again with polygonMode=LINE, should fail
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001172 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1173 "polygonMode cannot be VK_POLYGON_MODE_POINT or VK_POLYGON_MODE_LINE");
Cortd889ff92016-07-27 09:51:27 -07001174 {
1175 VkPipelineObj pipe(&test_device);
1176 pipe.AddShader(&vs);
1177 pipe.AddShader(&fs);
1178 pipe.AddColorAttachment();
1179 // Introduce failure by setting unsupported polygon mode
1180 rs_ci.polygonMode = VK_POLYGON_MODE_LINE;
1181 pipe.SetRasterization(&rs_ci);
1182 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
1183 }
1184 m_errorMonitor->VerifyFound();
1185
Cortd889ff92016-07-27 09:51:27 -07001186 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, NULL);
1187}
1188
Dustin Gravesffa90fa2016-05-06 11:20:38 -06001189#endif // PARAMETER_VALIDATION_TESTS
1190
Tobin Ehlis0788f522015-05-26 16:11:58 -06001191#if MEM_TRACKER_TESTS
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001192#if 0
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001193TEST_F(VkLayerTest, CallResetCommandBufferBeforeCompletion)
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001194{
1195 vk_testing::Fence testFence;
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001196 VkFenceCreateInfo fenceInfo = {};
1197 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1198 fenceInfo.pNext = NULL;
1199 fenceInfo.flags = 0;
1200
Mike Weiblencce7ec72016-10-17 19:33:05 -06001201 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Resetting command buffer");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001202
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001203 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbourc1eb1a52015-07-20 13:00:10 -06001204
1205 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
1206 vk_testing::Buffer buffer;
1207 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001208
Tony Barbourfe3351b2015-07-28 10:17:20 -06001209 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001210 m_commandBuffer->FillBuffer(buffer.handle(), 0, 4, 0x11111111);
Tony Barbourfe3351b2015-07-28 10:17:20 -06001211 EndCommandBuffer();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001212
1213 testFence.init(*m_device, fenceInfo);
1214
1215 // Bypass framework since it does the waits automatically
1216 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001217 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08001218 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1219 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001220 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001221 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07001222 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001223 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001224 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08001225 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001226 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06001227
1228 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001229 ASSERT_VK_SUCCESS( err );
1230
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001231 // Introduce failure by calling begin again before checking fence
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001232 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001233
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001234 m_errorMonitor->VerifyFound();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001235}
1236
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001237TEST_F(VkLayerTest, CallBeginCommandBufferBeforeCompletion)
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001238{
1239 vk_testing::Fence testFence;
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001240 VkFenceCreateInfo fenceInfo = {};
1241 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1242 fenceInfo.pNext = NULL;
1243 fenceInfo.flags = 0;
1244
Mike Weiblencce7ec72016-10-17 19:33:05 -06001245 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Calling vkBeginCommandBuffer() on active command buffer");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001246
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001247 ASSERT_NO_FATAL_FAILURE(InitState());
1248 ASSERT_NO_FATAL_FAILURE(InitViewport());
1249 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1250
Tony Barbourfe3351b2015-07-28 10:17:20 -06001251 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001252 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbourfe3351b2015-07-28 10:17:20 -06001253 EndCommandBuffer();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001254
1255 testFence.init(*m_device, fenceInfo);
1256
1257 // Bypass framework since it does the waits automatically
1258 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001259 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08001260 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1261 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001262 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001263 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07001264 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001265 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001266 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08001267 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001268 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06001269
1270 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001271 ASSERT_VK_SUCCESS( err );
1272
Jon Ashburnf19916e2016-01-11 13:12:43 -07001273 VkCommandBufferInheritanceInfo hinfo = {};
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001274 VkCommandBufferBeginInfo info = {};
1275 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
1276 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001277 info.renderPass = VK_NULL_HANDLE;
1278 info.subpass = 0;
1279 info.framebuffer = VK_NULL_HANDLE;
Chia-I Wub8d47ae2015-11-11 10:18:12 +08001280 info.occlusionQueryEnable = VK_FALSE;
1281 info.queryFlags = 0;
1282 info.pipelineStatistics = 0;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001283
1284 // Introduce failure by calling BCB again before checking fence
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001285 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001286
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001287 m_errorMonitor->VerifyFound();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001288}
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001289#endif
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001290
Mark Lobodzinski833bb552016-12-15 07:41:13 -07001291TEST_F(VkLayerTest, SparseBindingImageBufferCreate) {
1292 TEST_DESCRIPTION("Create buffer/image with sparse attributes but without the sparse_binding bit set");
1293
1294 ASSERT_NO_FATAL_FAILURE(InitState());
1295
1296 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00669);
1297 VkBuffer buffer;
1298 VkBufferCreateInfo buf_info = {};
1299 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1300 buf_info.pNext = NULL;
1301 buf_info.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
1302 buf_info.size = 2048;
1303 buf_info.queueFamilyIndexCount = 0;
1304 buf_info.pQueueFamilyIndices = NULL;
1305 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1306 buf_info.flags = VK_BUFFER_CREATE_SPARSE_RESIDENCY_BIT;
1307 vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1308 m_errorMonitor->VerifyFound();
1309
1310 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02160);
1311 VkImage image;
1312 VkImageCreateInfo image_create_info = {};
1313 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1314 image_create_info.pNext = NULL;
1315 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1316 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
1317 image_create_info.extent.width = 512;
1318 image_create_info.extent.height = 64;
1319 image_create_info.extent.depth = 1;
1320 image_create_info.mipLevels = 1;
1321 image_create_info.arrayLayers = 1;
1322 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
1323 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
1324 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
1325 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
1326 image_create_info.queueFamilyIndexCount = 0;
1327 image_create_info.pQueueFamilyIndices = NULL;
1328 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1329 image_create_info.flags = VK_BUFFER_CREATE_SPARSE_ALIASED_BIT;
1330 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1331 m_errorMonitor->VerifyFound();
1332}
1333
Tobin Ehlisf11be982016-05-11 13:52:53 -06001334TEST_F(VkLayerTest, InvalidMemoryAliasing) {
1335 TEST_DESCRIPTION("Create a buffer and image, allocate memory, and bind the "
1336 "buffer and image to memory such that they will alias.");
1337 VkResult err;
1338 bool pass;
1339 ASSERT_NO_FATAL_FAILURE(InitState());
1340
Tobin Ehlis077ded32016-05-12 17:39:13 -06001341 VkBuffer buffer, buffer2;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001342 VkImage image;
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001343 VkImage image2;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001344 VkDeviceMemory mem; // buffer will be bound first
1345 VkDeviceMemory mem_img; // image bound first
Tobin Ehlis077ded32016-05-12 17:39:13 -06001346 VkMemoryRequirements buff_mem_reqs, img_mem_reqs;
Rene Lindsayd14f5572016-12-16 14:57:18 -07001347 VkMemoryRequirements buff_mem_reqs2, img_mem_reqs2;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001348
1349 VkBufferCreateInfo buf_info = {};
1350 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1351 buf_info.pNext = NULL;
1352 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
1353 buf_info.size = 256;
1354 buf_info.queueFamilyIndexCount = 0;
1355 buf_info.pQueueFamilyIndices = NULL;
1356 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1357 buf_info.flags = 0;
1358 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1359 ASSERT_VK_SUCCESS(err);
1360
Tobin Ehlis077ded32016-05-12 17:39:13 -06001361 vkGetBufferMemoryRequirements(m_device->device(), buffer, &buff_mem_reqs);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001362
1363 VkImageCreateInfo image_create_info = {};
1364 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1365 image_create_info.pNext = NULL;
1366 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1367 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
1368 image_create_info.extent.width = 64;
1369 image_create_info.extent.height = 64;
1370 image_create_info.extent.depth = 1;
1371 image_create_info.mipLevels = 1;
1372 image_create_info.arrayLayers = 1;
1373 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehlis12a4b5e2016-08-08 12:33:11 -06001374 // Image tiling must be optimal to trigger error when aliasing linear buffer
1375 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001376 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
1377 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
1378 image_create_info.queueFamilyIndexCount = 0;
1379 image_create_info.pQueueFamilyIndices = NULL;
1380 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1381 image_create_info.flags = 0;
1382
Tobin Ehlisf11be982016-05-11 13:52:53 -06001383 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1384 ASSERT_VK_SUCCESS(err);
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001385 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image2);
1386 ASSERT_VK_SUCCESS(err);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001387
Tobin Ehlis077ded32016-05-12 17:39:13 -06001388 vkGetImageMemoryRequirements(m_device->device(), image, &img_mem_reqs);
1389
1390 VkMemoryAllocateInfo alloc_info = {};
1391 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1392 alloc_info.pNext = NULL;
1393 alloc_info.memoryTypeIndex = 0;
1394 // Ensure memory is big enough for both bindings
1395 alloc_info.allocationSize = buff_mem_reqs.size + img_mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001396 pass = m_device->phy().set_memory_type(buff_mem_reqs.memoryTypeBits & img_mem_reqs.memoryTypeBits, &alloc_info,
1397 VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001398 if (!pass) {
Tobin Ehlis077ded32016-05-12 17:39:13 -06001399 vkDestroyBuffer(m_device->device(), buffer, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001400 vkDestroyImage(m_device->device(), image, NULL);
1401 return;
1402 }
Tobin Ehlis077ded32016-05-12 17:39:13 -06001403 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
1404 ASSERT_VK_SUCCESS(err);
1405 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
1406 ASSERT_VK_SUCCESS(err);
1407
Rene Lindsayd14f5572016-12-16 14:57:18 -07001408 vkGetImageMemoryRequirements(m_device->device(), image2, &img_mem_reqs2);
1409
Tobin Ehlis32b2bbc2016-12-13 17:33:41 -07001410 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, " is aliased with linear buffer 0x");
Tobin Ehlis077ded32016-05-12 17:39:13 -06001411 // VALIDATION FAILURE due to image mapping overlapping buffer mapping
Tobin Ehlisf11be982016-05-11 13:52:53 -06001412 err = vkBindImageMemory(m_device->device(), image, mem, 0);
1413 m_errorMonitor->VerifyFound();
1414
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001415 // Now correctly bind image2 to second mem allocation before incorrectly
Tobin Ehlis077ded32016-05-12 17:39:13 -06001416 // aliasing buffer2
1417 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer2);
1418 ASSERT_VK_SUCCESS(err);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001419 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem_img);
1420 ASSERT_VK_SUCCESS(err);
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001421 err = vkBindImageMemory(m_device->device(), image2, mem_img, 0);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001422 ASSERT_VK_SUCCESS(err);
Tobin Ehlis32b2bbc2016-12-13 17:33:41 -07001423 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "is aliased with non-linear image 0x");
Rene Lindsayd14f5572016-12-16 14:57:18 -07001424 vkGetBufferMemoryRequirements(m_device->device(), buffer2, &buff_mem_reqs2);
Tobin Ehlis077ded32016-05-12 17:39:13 -06001425 err = vkBindBufferMemory(m_device->device(), buffer2, mem_img, 0);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001426 m_errorMonitor->VerifyFound();
1427
1428 vkDestroyBuffer(m_device->device(), buffer, NULL);
Tobin Ehlis077ded32016-05-12 17:39:13 -06001429 vkDestroyBuffer(m_device->device(), buffer2, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001430 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001431 vkDestroyImage(m_device->device(), image2, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001432 vkFreeMemory(m_device->device(), mem, NULL);
1433 vkFreeMemory(m_device->device(), mem_img, NULL);
1434}
1435
Tobin Ehlis35372522016-05-12 08:32:31 -06001436TEST_F(VkLayerTest, InvalidMemoryMapping) {
1437 TEST_DESCRIPTION("Attempt to map memory in a number of incorrect ways");
1438 VkResult err;
1439 bool pass;
1440 ASSERT_NO_FATAL_FAILURE(InitState());
1441
1442 VkBuffer buffer;
1443 VkDeviceMemory mem;
1444 VkMemoryRequirements mem_reqs;
1445
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001446 const VkDeviceSize atom_size = m_device->props.limits.nonCoherentAtomSize;
1447
Tobin Ehlis35372522016-05-12 08:32:31 -06001448 VkBufferCreateInfo buf_info = {};
1449 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1450 buf_info.pNext = NULL;
1451 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
1452 buf_info.size = 256;
1453 buf_info.queueFamilyIndexCount = 0;
1454 buf_info.pQueueFamilyIndices = NULL;
1455 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1456 buf_info.flags = 0;
1457 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1458 ASSERT_VK_SUCCESS(err);
1459
1460 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
1461 VkMemoryAllocateInfo alloc_info = {};
1462 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1463 alloc_info.pNext = NULL;
1464 alloc_info.memoryTypeIndex = 0;
1465
1466 // Ensure memory is big enough for both bindings
1467 static const VkDeviceSize allocation_size = 0x10000;
1468 alloc_info.allocationSize = allocation_size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001469 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
Tobin Ehlis35372522016-05-12 08:32:31 -06001470 if (!pass) {
1471 vkDestroyBuffer(m_device->device(), buffer, NULL);
1472 return;
1473 }
1474 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
1475 ASSERT_VK_SUCCESS(err);
1476
1477 uint8_t *pData;
1478 // Attempt to map memory size 0 is invalid
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001479 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VkMapMemory: Attempting to map memory range of size zero");
Tobin Ehlis35372522016-05-12 08:32:31 -06001480 err = vkMapMemory(m_device->device(), mem, 0, 0, 0, (void **)&pData);
1481 m_errorMonitor->VerifyFound();
1482 // Map memory twice
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001483 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001484 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001485 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1486 "VkMapMemory: Attempting to map memory on an already-mapped object ");
1487 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001488 m_errorMonitor->VerifyFound();
1489
1490 // Unmap the memory to avoid re-map error
1491 vkUnmapMemory(m_device->device(), mem);
1492 // overstep allocation with VK_WHOLE_SIZE
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001493 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1494 " with size of VK_WHOLE_SIZE oversteps total array size 0x");
1495 err = vkMapMemory(m_device->device(), mem, allocation_size + 1, VK_WHOLE_SIZE, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001496 m_errorMonitor->VerifyFound();
1497 // overstep allocation w/o VK_WHOLE_SIZE
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001498 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " oversteps total array size 0x");
1499 err = vkMapMemory(m_device->device(), mem, 1, allocation_size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001500 m_errorMonitor->VerifyFound();
1501 // Now error due to unmapping memory that's not mapped
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001502 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Unmapping Memory without memory being mapped: ");
Tobin Ehlis35372522016-05-12 08:32:31 -06001503 vkUnmapMemory(m_device->device(), mem);
1504 m_errorMonitor->VerifyFound();
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001505
Tobin Ehlis35372522016-05-12 08:32:31 -06001506 // Now map memory and cause errors due to flushing invalid ranges
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001507 err = vkMapMemory(m_device->device(), mem, 4 * atom_size, VK_WHOLE_SIZE, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001508 ASSERT_VK_SUCCESS(err);
1509 VkMappedMemoryRange mmr = {};
Chris Forbes3aec0892016-06-13 10:29:26 +12001510 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
Tobin Ehlis35372522016-05-12 08:32:31 -06001511 mmr.memory = mem;
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001512 mmr.offset = atom_size; // Error b/c offset less than offset of mapped mem
Mark Lobodzinskib3c675e2016-11-15 08:56:03 -07001513 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00642);
Tobin Ehlis35372522016-05-12 08:32:31 -06001514 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1515 m_errorMonitor->VerifyFound();
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001516
Tobin Ehlis35372522016-05-12 08:32:31 -06001517 // Now flush range that oversteps mapped range
1518 vkUnmapMemory(m_device->device(), mem);
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001519 err = vkMapMemory(m_device->device(), mem, 0, 4 * atom_size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001520 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001521 mmr.offset = atom_size;
1522 mmr.size = 4 * atom_size; // Flushing bounds exceed mapped bounds
Mark Lobodzinskib3c675e2016-11-15 08:56:03 -07001523 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00642);
1524 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1525 m_errorMonitor->VerifyFound();
1526
1527 // Now flush range with VK_WHOLE_SIZE that oversteps offset
1528 vkUnmapMemory(m_device->device(), mem);
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001529 err = vkMapMemory(m_device->device(), mem, 2 * atom_size, 4 * atom_size, 0, (void **)&pData);
Mark Lobodzinskib3c675e2016-11-15 08:56:03 -07001530 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001531 mmr.offset = atom_size;
Mark Lobodzinskib3c675e2016-11-15 08:56:03 -07001532 mmr.size = VK_WHOLE_SIZE;
1533 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00643);
Tobin Ehlis35372522016-05-12 08:32:31 -06001534 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1535 m_errorMonitor->VerifyFound();
1536
Tony Barboure3975eb2016-12-15 14:52:44 -07001537#if 0 // Planning discussion with working group on this validation check.
Mark Lobodzinski3826a4f2016-11-15 09:38:51 -07001538 // Some platforms have an atomsize of 1 which makes the test meaningless
1539 if (atom_size > 3) {
1540 // Now with an offset NOT a multiple of the device limit
1541 vkUnmapMemory(m_device->device(), mem);
1542 err = vkMapMemory(m_device->device(), mem, 0, 4 * atom_size, 0, (void **)&pData);
1543 ASSERT_VK_SUCCESS(err);
1544 mmr.offset = 3; // Not a multiple of atom_size
1545 mmr.size = VK_WHOLE_SIZE;
1546 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00644);
1547 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1548 m_errorMonitor->VerifyFound();
1549
1550 // Now with a size NOT a multiple of the device limit
1551 vkUnmapMemory(m_device->device(), mem);
1552 err = vkMapMemory(m_device->device(), mem, 0, 4 * atom_size, 0, (void **)&pData);
1553 ASSERT_VK_SUCCESS(err);
1554 mmr.offset = atom_size;
1555 mmr.size = 2 * atom_size + 1; // Not a multiple of atom_size
1556 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00645);
1557 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1558 m_errorMonitor->VerifyFound();
1559 }
Tony Barboure3975eb2016-12-15 14:52:44 -07001560#endif
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001561 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT,
1562 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Tobin Ehlis35372522016-05-12 08:32:31 -06001563 if (!pass) {
1564 vkFreeMemory(m_device->device(), mem, NULL);
1565 vkDestroyBuffer(m_device->device(), buffer, NULL);
1566 return;
1567 }
1568 // TODO : If we can get HOST_VISIBLE w/o HOST_COHERENT we can test cases of
1569 // MEMTRACK_INVALID_MAP in validateAndCopyNoncoherentMemoryToDriver()
1570
1571 vkDestroyBuffer(m_device->device(), buffer, NULL);
1572 vkFreeMemory(m_device->device(), mem, NULL);
1573}
1574
Chris Forbes09368e42016-10-13 11:59:22 +13001575#if 0 // disabled until PV gets real extension enable checks
Ian Elliott1c32c772016-04-28 14:47:13 -06001576TEST_F(VkLayerTest, EnableWsiBeforeUse) {
1577 VkResult err;
1578 bool pass;
1579
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001580 // FIXME: After we turn on this code for non-Linux platforms, uncomment the
1581 // following declaration (which is temporarily being moved below):
1582 // VkSurfaceKHR surface = VK_NULL_HANDLE;
Ian Elliott1c32c772016-04-28 14:47:13 -06001583 VkSwapchainKHR swapchain = VK_NULL_HANDLE;
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001584 VkSwapchainCreateInfoKHR swapchain_create_info = {VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR};
Ian Elliott1c32c772016-04-28 14:47:13 -06001585 uint32_t swapchain_image_count = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001586 // VkImage swapchain_images[1] = {VK_NULL_HANDLE};
Ian Elliott1c32c772016-04-28 14:47:13 -06001587 uint32_t image_index = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001588 // VkPresentInfoKHR present_info = {};
Ian Elliott1c32c772016-04-28 14:47:13 -06001589
1590 ASSERT_NO_FATAL_FAILURE(InitState());
1591
Ian Elliott3f06ce52016-04-29 14:46:21 -06001592#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
1593#if defined(VK_USE_PLATFORM_ANDROID_KHR)
1594 // Use the functions from the VK_KHR_android_surface extension without
1595 // enabling that extension:
1596
1597 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001598 VkAndroidSurfaceCreateInfoKHR android_create_info = {VK_STRUCTURE_TYPE_ANDROID_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001599 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1600 err = vkCreateAndroidSurfaceKHR(instance(), &android_create_info, NULL, &surface);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001601 pass = (err != VK_SUCCESS);
1602 ASSERT_TRUE(pass);
1603 m_errorMonitor->VerifyFound();
1604#endif // VK_USE_PLATFORM_ANDROID_KHR
1605
Ian Elliott3f06ce52016-04-29 14:46:21 -06001606#if defined(VK_USE_PLATFORM_MIR_KHR)
1607 // Use the functions from the VK_KHR_mir_surface extension without enabling
1608 // that extension:
1609
1610 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001611 VkMirSurfaceCreateInfoKHR mir_create_info = {VK_STRUCTURE_TYPE_MIR_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001612 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott3f06ce52016-04-29 14:46:21 -06001613 err = vkCreateMirSurfaceKHR(instance(), &mir_create_info, NULL, &surface);
1614 pass = (err != VK_SUCCESS);
1615 ASSERT_TRUE(pass);
1616 m_errorMonitor->VerifyFound();
1617
1618 // Tell whether an mir_connection supports presentation:
1619 MirConnection *mir_connection = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001620 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1621 vkGetPhysicalDeviceMirPresentationSupportKHR(gpu(), 0, mir_connection, visual_id);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001622 m_errorMonitor->VerifyFound();
1623#endif // VK_USE_PLATFORM_MIR_KHR
1624
Ian Elliott3f06ce52016-04-29 14:46:21 -06001625#if defined(VK_USE_PLATFORM_WAYLAND_KHR)
1626 // Use the functions from the VK_KHR_wayland_surface extension without
1627 // enabling that extension:
1628
1629 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001630 VkWaylandSurfaceCreateInfoKHR wayland_create_info = {VK_STRUCTURE_TYPE_WAYLAND_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001631 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1632 err = vkCreateWaylandSurfaceKHR(instance(), &wayland_create_info, NULL, &surface);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001633 pass = (err != VK_SUCCESS);
1634 ASSERT_TRUE(pass);
1635 m_errorMonitor->VerifyFound();
1636
1637 // Tell whether an wayland_display supports presentation:
1638 struct wl_display wayland_display = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001639 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1640 vkGetPhysicalDeviceWaylandPresentationSupportKHR(gpu(), 0, &wayland_display);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001641 m_errorMonitor->VerifyFound();
1642#endif // VK_USE_PLATFORM_WAYLAND_KHR
Ian Elliott489eec02016-05-05 14:12:44 -06001643#endif // NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott3f06ce52016-04-29 14:46:21 -06001644
Ian Elliott3f06ce52016-04-29 14:46:21 -06001645#if defined(VK_USE_PLATFORM_WIN32_KHR)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001646 // FIXME: REMOVE THIS HERE, AND UNCOMMENT ABOVE, WHEN THIS TEST HAS BEEN PORTED
1647 // TO NON-LINUX PLATFORMS:
1648 VkSurfaceKHR surface = VK_NULL_HANDLE;
Ian Elliott3f06ce52016-04-29 14:46:21 -06001649 // Use the functions from the VK_KHR_win32_surface extension without
1650 // enabling that extension:
1651
1652 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001653 VkWin32SurfaceCreateInfoKHR win32_create_info = {VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001654 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1655 err = vkCreateWin32SurfaceKHR(instance(), &win32_create_info, NULL, &surface);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001656 pass = (err != VK_SUCCESS);
1657 ASSERT_TRUE(pass);
1658 m_errorMonitor->VerifyFound();
1659
1660 // Tell whether win32 supports presentation:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001661 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott489eec02016-05-05 14:12:44 -06001662 vkGetPhysicalDeviceWin32PresentationSupportKHR(gpu(), 0);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001663 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001664// Set this (for now, until all platforms are supported and tested):
1665#define NEED_TO_TEST_THIS_ON_PLATFORM
1666#endif // VK_USE_PLATFORM_WIN32_KHR
Tony Barbour2e7bd402016-11-14 14:46:33 -07001667#if defined(VK_USE_PLATFORM_XCB_KHR) || defined (VK_USE_PLATFORM_XLIB_KHR)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001668 // FIXME: REMOVE THIS HERE, AND UNCOMMENT ABOVE, WHEN THIS TEST HAS BEEN PORTED
1669 // TO NON-LINUX PLATFORMS:
1670 VkSurfaceKHR surface = VK_NULL_HANDLE;
Tony Barbour2e7bd402016-11-14 14:46:33 -07001671#endif
1672#if defined(VK_USE_PLATFORM_XCB_KHR)
Ian Elliott1c32c772016-04-28 14:47:13 -06001673 // Use the functions from the VK_KHR_xcb_surface extension without enabling
1674 // that extension:
1675
1676 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001677 VkXcbSurfaceCreateInfoKHR xcb_create_info = {VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001678 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001679 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
1680 pass = (err != VK_SUCCESS);
1681 ASSERT_TRUE(pass);
1682 m_errorMonitor->VerifyFound();
1683
1684 // Tell whether an xcb_visualid_t supports presentation:
Ian Elliott3f06ce52016-04-29 14:46:21 -06001685 xcb_connection_t *xcb_connection = NULL;
Ian Elliott1c32c772016-04-28 14:47:13 -06001686 xcb_visualid_t visual_id = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001687 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1688 vkGetPhysicalDeviceXcbPresentationSupportKHR(gpu(), 0, xcb_connection, visual_id);
Ian Elliott1c32c772016-04-28 14:47:13 -06001689 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001690// Set this (for now, until all platforms are supported and tested):
1691#define NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06001692#endif // VK_USE_PLATFORM_XCB_KHR
1693
Ian Elliott12630812016-04-29 14:35:43 -06001694#if defined(VK_USE_PLATFORM_XLIB_KHR)
1695 // Use the functions from the VK_KHR_xlib_surface extension without enabling
1696 // that extension:
1697
1698 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001699 VkXlibSurfaceCreateInfoKHR xlib_create_info = {VK_STRUCTURE_TYPE_XLIB_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001700 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott12630812016-04-29 14:35:43 -06001701 err = vkCreateXlibSurfaceKHR(instance(), &xlib_create_info, NULL, &surface);
1702 pass = (err != VK_SUCCESS);
1703 ASSERT_TRUE(pass);
1704 m_errorMonitor->VerifyFound();
1705
1706 // Tell whether an Xlib VisualID supports presentation:
1707 Display *dpy = NULL;
1708 VisualID visual = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001709 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott12630812016-04-29 14:35:43 -06001710 vkGetPhysicalDeviceXlibPresentationSupportKHR(gpu(), 0, dpy, visual);
1711 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001712// Set this (for now, until all platforms are supported and tested):
1713#define NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott12630812016-04-29 14:35:43 -06001714#endif // VK_USE_PLATFORM_XLIB_KHR
1715
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001716// Use the functions from the VK_KHR_surface extension without enabling
1717// that extension:
Ian Elliott1c32c772016-04-28 14:47:13 -06001718
Ian Elliott489eec02016-05-05 14:12:44 -06001719#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06001720 // Destroy a surface:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001721 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001722 vkDestroySurfaceKHR(instance(), surface, NULL);
1723 m_errorMonitor->VerifyFound();
1724
1725 // Check if surface supports presentation:
1726 VkBool32 supported = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001727 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001728 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
1729 pass = (err != VK_SUCCESS);
1730 ASSERT_TRUE(pass);
1731 m_errorMonitor->VerifyFound();
1732
1733 // Check surface capabilities:
1734 VkSurfaceCapabilitiesKHR capabilities = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001735 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1736 err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), surface, &capabilities);
Ian Elliott1c32c772016-04-28 14:47:13 -06001737 pass = (err != VK_SUCCESS);
1738 ASSERT_TRUE(pass);
1739 m_errorMonitor->VerifyFound();
1740
1741 // Check surface formats:
1742 uint32_t format_count = 0;
1743 VkSurfaceFormatKHR *formats = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001744 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1745 err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &format_count, formats);
Ian Elliott1c32c772016-04-28 14:47:13 -06001746 pass = (err != VK_SUCCESS);
1747 ASSERT_TRUE(pass);
1748 m_errorMonitor->VerifyFound();
1749
1750 // Check surface present modes:
1751 uint32_t present_mode_count = 0;
1752 VkSurfaceFormatKHR *present_modes = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001753 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1754 err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &present_mode_count, present_modes);
Ian Elliott1c32c772016-04-28 14:47:13 -06001755 pass = (err != VK_SUCCESS);
1756 ASSERT_TRUE(pass);
1757 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001758#endif // NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06001759
Ian Elliott1c32c772016-04-28 14:47:13 -06001760 // Use the functions from the VK_KHR_swapchain extension without enabling
1761 // that extension:
1762
1763 // Create a swapchain:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001764 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001765 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
1766 swapchain_create_info.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001767 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
Ian Elliott1c32c772016-04-28 14:47:13 -06001768 pass = (err != VK_SUCCESS);
1769 ASSERT_TRUE(pass);
1770 m_errorMonitor->VerifyFound();
1771
1772 // Get the images from the swapchain:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001773 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1774 err = vkGetSwapchainImagesKHR(m_device->device(), swapchain, &swapchain_image_count, NULL);
Ian Elliott1c32c772016-04-28 14:47:13 -06001775 pass = (err != VK_SUCCESS);
1776 ASSERT_TRUE(pass);
1777 m_errorMonitor->VerifyFound();
1778
Chris Forbeseb7d5502016-09-13 18:19:21 +12001779 // Add a fence to avoid (justifiable) error about not providing fence OR semaphore
1780 VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
1781 VkFence fence;
1782 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
1783
Ian Elliott1c32c772016-04-28 14:47:13 -06001784 // Try to acquire an image:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001785 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Chris Forbeseb7d5502016-09-13 18:19:21 +12001786 err = vkAcquireNextImageKHR(m_device->device(), swapchain, 0, VK_NULL_HANDLE, fence, &image_index);
Ian Elliott1c32c772016-04-28 14:47:13 -06001787 pass = (err != VK_SUCCESS);
1788 ASSERT_TRUE(pass);
1789 m_errorMonitor->VerifyFound();
1790
Chris Forbeseb7d5502016-09-13 18:19:21 +12001791 vkDestroyFence(m_device->device(), fence, nullptr);
1792
Ian Elliott1c32c772016-04-28 14:47:13 -06001793 // Try to present an image:
Ian Elliott2c1daf52016-05-12 09:41:46 -06001794 //
1795 // NOTE: Currently can't test this because a real swapchain is needed (as
1796 // opposed to the fake one we created) in order for the layer to lookup the
1797 // VkDevice used to enable the extension:
Ian Elliott1c32c772016-04-28 14:47:13 -06001798
1799 // Destroy the swapchain:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001800 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001801 vkDestroySwapchainKHR(m_device->device(), swapchain, NULL);
1802 m_errorMonitor->VerifyFound();
1803}
Chris Forbes09368e42016-10-13 11:59:22 +13001804#endif
Ian Elliott1c32c772016-04-28 14:47:13 -06001805
Karl Schultz6addd812016-02-02 17:17:23 -07001806TEST_F(VkLayerTest, MapMemWithoutHostVisibleBit) {
1807 VkResult err;
1808 bool pass;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001809
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001810 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1811 "Mapping Memory without VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001812
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001813 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001814
1815 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07001816 VkImage image;
1817 VkDeviceMemory mem;
1818 VkMemoryRequirements mem_reqs;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001819
Karl Schultz6addd812016-02-02 17:17:23 -07001820 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
1821 const int32_t tex_width = 32;
1822 const int32_t tex_height = 32;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001823
Tony Barboureb254902015-07-15 12:50:33 -06001824 VkImageCreateInfo image_create_info = {};
1825 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07001826 image_create_info.pNext = NULL;
1827 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1828 image_create_info.format = tex_format;
1829 image_create_info.extent.width = tex_width;
1830 image_create_info.extent.height = tex_height;
1831 image_create_info.extent.depth = 1;
1832 image_create_info.mipLevels = 1;
1833 image_create_info.arrayLayers = 1;
1834 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
1835 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
1836 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
1837 image_create_info.flags = 0;
Chris Forbese65e4d02016-09-13 17:39:18 +12001838 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001839
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001840 VkMemoryAllocateInfo mem_alloc = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08001841 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07001842 mem_alloc.pNext = NULL;
1843 mem_alloc.allocationSize = 0;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001844
Chia-I Wuf7458c52015-10-26 21:10:41 +08001845 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001846 ASSERT_VK_SUCCESS(err);
1847
Karl Schultz6addd812016-02-02 17:17:23 -07001848 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001849
Mark Lobodzinski23065352015-05-29 09:32:35 -05001850 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001851
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001852 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
Karl Schultz6addd812016-02-02 17:17:23 -07001853 if (!pass) { // If we can't find any unmappable memory this test doesn't
1854 // make sense
Chia-I Wuf7458c52015-10-26 21:10:41 +08001855 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbour02fdc7d2015-08-04 16:13:01 -06001856 return;
Mike Stroyand1c84a52015-08-18 14:40:24 -06001857 }
Mike Stroyan713b2d72015-08-04 10:49:29 -06001858
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001859 // allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001860 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001861 ASSERT_VK_SUCCESS(err);
1862
1863 // Try to bind free memory that has been freed
Tony Barbour67e99152015-07-10 14:10:27 -06001864 err = vkBindImageMemory(m_device->device(), image, mem, 0);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001865 ASSERT_VK_SUCCESS(err);
1866
1867 // Map memory as if to initialize the image
1868 void *mappedAddress = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001869 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, &mappedAddress);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001870
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001871 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06001872
Chia-I Wuf7458c52015-10-26 21:10:41 +08001873 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06001874 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001875}
1876
Karl Schultz6addd812016-02-02 17:17:23 -07001877TEST_F(VkLayerTest, RebindMemory) {
1878 VkResult err;
1879 bool pass;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001880
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001881 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "which has already been bound to mem object");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001882
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001883 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001884
1885 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07001886 VkImage image;
1887 VkDeviceMemory mem1;
1888 VkDeviceMemory mem2;
1889 VkMemoryRequirements mem_reqs;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001890
Karl Schultz6addd812016-02-02 17:17:23 -07001891 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
1892 const int32_t tex_width = 32;
1893 const int32_t tex_height = 32;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001894
Tony Barboureb254902015-07-15 12:50:33 -06001895 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07001896 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1897 image_create_info.pNext = NULL;
1898 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1899 image_create_info.format = tex_format;
1900 image_create_info.extent.width = tex_width;
1901 image_create_info.extent.height = tex_height;
1902 image_create_info.extent.depth = 1;
1903 image_create_info.mipLevels = 1;
1904 image_create_info.arrayLayers = 1;
1905 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
1906 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
1907 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
1908 image_create_info.flags = 0;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001909
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001910 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07001911 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1912 mem_alloc.pNext = NULL;
1913 mem_alloc.allocationSize = 0;
1914 mem_alloc.memoryTypeIndex = 0;
Tony Barboureb254902015-07-15 12:50:33 -06001915
Karl Schultz6addd812016-02-02 17:17:23 -07001916 // Introduce failure, do NOT set memProps to
1917 // VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
Tony Barboureb254902015-07-15 12:50:33 -06001918 mem_alloc.memoryTypeIndex = 1;
Chia-I Wuf7458c52015-10-26 21:10:41 +08001919 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001920 ASSERT_VK_SUCCESS(err);
1921
Karl Schultz6addd812016-02-02 17:17:23 -07001922 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001923
1924 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001925 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06001926 ASSERT_TRUE(pass);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001927
1928 // allocate 2 memory objects
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001929 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem1);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001930 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001931 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem2);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001932 ASSERT_VK_SUCCESS(err);
1933
1934 // Bind first memory object to Image object
Tony Barbour67e99152015-07-10 14:10:27 -06001935 err = vkBindImageMemory(m_device->device(), image, mem1, 0);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001936 ASSERT_VK_SUCCESS(err);
1937
Karl Schultz6addd812016-02-02 17:17:23 -07001938 // Introduce validation failure, try to bind a different memory object to
1939 // the same image object
Tony Barbour67e99152015-07-10 14:10:27 -06001940 err = vkBindImageMemory(m_device->device(), image, mem2, 0);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001941
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001942 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06001943
Chia-I Wuf7458c52015-10-26 21:10:41 +08001944 vkDestroyImage(m_device->device(), image, NULL);
1945 vkFreeMemory(m_device->device(), mem1, NULL);
1946 vkFreeMemory(m_device->device(), mem2, NULL);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001947}
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001948
Karl Schultz6addd812016-02-02 17:17:23 -07001949TEST_F(VkLayerTest, SubmitSignaledFence) {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001950 vk_testing::Fence testFence;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001951
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001952 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "submitted in SIGNALED state. Fences "
1953 "must be reset before being submitted");
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001954
1955 VkFenceCreateInfo fenceInfo = {};
Tony Barbour0b4d9562015-04-09 10:48:04 -06001956 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1957 fenceInfo.pNext = NULL;
1958 fenceInfo.flags = VK_FENCE_CREATE_SIGNALED_BIT;
Tony Barbour300a6082015-04-07 13:44:53 -06001959
Tony Barbour300a6082015-04-07 13:44:53 -06001960 ASSERT_NO_FATAL_FAILURE(InitState());
1961 ASSERT_NO_FATAL_FAILURE(InitViewport());
1962 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1963
Tony Barbourfe3351b2015-07-28 10:17:20 -06001964 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001965 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbourfe3351b2015-07-28 10:17:20 -06001966 EndCommandBuffer();
Tony Barbour300a6082015-04-07 13:44:53 -06001967
1968 testFence.init(*m_device, fenceInfo);
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001969
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001970 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08001971 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1972 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001973 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001974 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07001975 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001976 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001977 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08001978 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001979 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06001980
1981 vkQueueSubmit(m_device->m_queue, 1, &submit_info, testFence.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07001982 vkQueueWaitIdle(m_device->m_queue);
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001983
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001984 m_errorMonitor->VerifyFound();
Tony Barbour0b4d9562015-04-09 10:48:04 -06001985}
Chris Forbes4e44c912016-06-16 10:20:00 +12001986
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001987TEST_F(VkLayerTest, InvalidUsageBits) {
1988 TEST_DESCRIPTION("Specify wrong usage for image then create conflicting view of image "
1989 "Initialize buffer with wrong usage then perform copy expecting errors "
1990 "from both the image and the buffer (2 calls)");
1991 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid usage flag for image ");
Tobin Ehlis41376e12015-07-03 08:45:14 -06001992
1993 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesd2b5fe42016-11-28 18:00:00 +13001994
1995 auto format = VK_FORMAT_D24_UNORM_S8_UINT;
1996
Tony Barbourf92621a2016-05-02 14:28:12 -06001997 VkImageObj image(m_device);
Tony Barbour75d79f02016-08-30 09:39:07 -06001998 // Initialize image with USAGE_TRANSIENT_ATTACHMENT
Chris Forbesd2b5fe42016-11-28 18:00:00 +13001999 image.init(128, 128, format, VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
Karl Schultzb5bc11e2016-05-04 08:36:08 -06002000 ASSERT_TRUE(image.initialized());
Tobin Ehlis41376e12015-07-03 08:45:14 -06002001
Tony Barbourf92621a2016-05-02 14:28:12 -06002002 VkImageView dsv;
2003 VkImageViewCreateInfo dsvci = {};
2004 dsvci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
2005 dsvci.image = image.handle();
2006 dsvci.viewType = VK_IMAGE_VIEW_TYPE_2D;
Chris Forbesd2b5fe42016-11-28 18:00:00 +13002007 dsvci.format = format;
Tony Barbourf92621a2016-05-02 14:28:12 -06002008 dsvci.subresourceRange.layerCount = 1;
2009 dsvci.subresourceRange.baseMipLevel = 0;
2010 dsvci.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002011 dsvci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
Tobin Ehlis41376e12015-07-03 08:45:14 -06002012
Tony Barbourf92621a2016-05-02 14:28:12 -06002013 // Create a view with depth / stencil aspect for image with different usage
2014 vkCreateImageView(m_device->device(), &dsvci, NULL, &dsv);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002015
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002016 m_errorMonitor->VerifyFound();
Tony Barbourf92621a2016-05-02 14:28:12 -06002017
2018 // Initialize buffer with TRANSFER_DST usage
2019 vk_testing::Buffer buffer;
2020 VkMemoryPropertyFlags reqs = 0;
2021 buffer.init_as_dst(*m_device, 128 * 128, reqs);
2022 VkBufferImageCopy region = {};
2023 region.bufferRowLength = 128;
2024 region.bufferImageHeight = 128;
2025 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2026 region.imageSubresource.layerCount = 1;
2027 region.imageExtent.height = 16;
2028 region.imageExtent.width = 16;
2029 region.imageExtent.depth = 1;
2030
Tony Barbourf92621a2016-05-02 14:28:12 -06002031 // Buffer usage not set to TRANSFER_SRC and image usage not set to
2032 // TRANSFER_DST
2033 BeginCommandBuffer();
Tony Barbourf92621a2016-05-02 14:28:12 -06002034
Chris Forbesda581202016-10-06 18:25:26 +13002035 // two separate errors from this call:
2036 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "image should have VK_IMAGE_USAGE_TRANSFER_DST_BIT");
2037 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "buffer should have VK_BUFFER_USAGE_TRANSFER_SRC_BIT");
2038
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002039 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
2040 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Tony Barbourf92621a2016-05-02 14:28:12 -06002041 m_errorMonitor->VerifyFound();
Tobin Ehlis41376e12015-07-03 08:45:14 -06002042}
Tony Barbour75d79f02016-08-30 09:39:07 -06002043
Tony Barbour75d79f02016-08-30 09:39:07 -06002044
Mark Lobodzinski209b5292015-09-17 09:44:05 -06002045#endif // MEM_TRACKER_TESTS
2046
Tobin Ehlis4bf96d12015-06-25 11:58:41 -06002047#if OBJ_TRACKER_TESTS
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002048
2049TEST_F(VkLayerTest, LeakAnObject) {
2050 VkResult err;
2051
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002052 TEST_DESCRIPTION("Create a fence and destroy its device without first destroying the fence.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002053
2054 // Note that we have to create a new device since destroying the
2055 // framework's device causes Teardown() to fail and just calling Teardown
2056 // will destroy the errorMonitor.
2057
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002058 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "has not been destroyed.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002059
2060 ASSERT_NO_FATAL_FAILURE(InitState());
2061
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002062 const std::vector<VkQueueFamilyProperties> queue_props = m_device->queue_props;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002063 std::vector<VkDeviceQueueCreateInfo> queue_info;
2064 queue_info.reserve(queue_props.size());
2065 std::vector<std::vector<float>> queue_priorities;
2066 for (uint32_t i = 0; i < (uint32_t)queue_props.size(); i++) {
2067 VkDeviceQueueCreateInfo qi = {};
2068 qi.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
2069 qi.pNext = NULL;
2070 qi.queueFamilyIndex = i;
2071 qi.queueCount = queue_props[i].queueCount;
2072 queue_priorities.emplace_back(qi.queueCount, 0.0f);
2073 qi.pQueuePriorities = queue_priorities[i].data();
2074 queue_info.push_back(qi);
2075 }
2076
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002077 std::vector<const char *> device_extension_names;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002078
2079 // The sacrificial device object
2080 VkDevice testDevice;
2081 VkDeviceCreateInfo device_create_info = {};
2082 auto features = m_device->phy().features();
2083 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
2084 device_create_info.pNext = NULL;
2085 device_create_info.queueCreateInfoCount = queue_info.size();
2086 device_create_info.pQueueCreateInfos = queue_info.data();
Tony Barbour4c70d102016-08-08 16:06:56 -06002087 device_create_info.enabledLayerCount = 0;
2088 device_create_info.ppEnabledLayerNames = NULL;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002089 device_create_info.pEnabledFeatures = &features;
2090 err = vkCreateDevice(gpu(), &device_create_info, NULL, &testDevice);
2091 ASSERT_VK_SUCCESS(err);
2092
2093 VkFence fence;
2094 VkFenceCreateInfo fence_create_info = {};
2095 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
2096 fence_create_info.pNext = NULL;
2097 fence_create_info.flags = 0;
2098 err = vkCreateFence(testDevice, &fence_create_info, NULL, &fence);
2099 ASSERT_VK_SUCCESS(err);
2100
2101 // Induce failure by not calling vkDestroyFence
2102 vkDestroyDevice(testDevice, NULL);
2103 m_errorMonitor->VerifyFound();
2104}
2105
2106TEST_F(VkLayerTest, InvalidCommandPoolConsistency) {
2107
2108 TEST_DESCRIPTION("Allocate command buffers from one command pool and "
2109 "attempt to delete them from another.");
2110
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002111 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "FreeCommandBuffers is attempting to free Command Buffer");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002112
Cody Northropc31a84f2016-08-22 10:41:47 -06002113 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002114 VkCommandPool command_pool_one;
2115 VkCommandPool command_pool_two;
2116
2117 VkCommandPoolCreateInfo pool_create_info{};
2118 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
2119 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
2120 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
2121
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002122 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool_one);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002123
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002124 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool_two);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002125
Chris Forbes5ab04ec2016-11-28 18:03:11 +13002126 VkCommandBuffer cb;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002127 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002128 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002129 command_buffer_allocate_info.commandPool = command_pool_one;
Chris Forbes5ab04ec2016-11-28 18:03:11 +13002130 command_buffer_allocate_info.commandBufferCount = 1;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002131 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Chris Forbes5ab04ec2016-11-28 18:03:11 +13002132 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &cb);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002133
Chris Forbes5ab04ec2016-11-28 18:03:11 +13002134 vkFreeCommandBuffers(m_device->device(), command_pool_two, 1, &cb);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002135
2136 m_errorMonitor->VerifyFound();
2137
2138 vkDestroyCommandPool(m_device->device(), command_pool_one, NULL);
2139 vkDestroyCommandPool(m_device->device(), command_pool_two, NULL);
2140}
2141
2142TEST_F(VkLayerTest, InvalidDescriptorPoolConsistency) {
2143 VkResult err;
2144
2145 TEST_DESCRIPTION("Allocate descriptor sets from one DS pool and "
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002146 "attempt to delete them from another.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002147
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002148 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "FreeDescriptorSets is attempting to free descriptorSet");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002149
2150 ASSERT_NO_FATAL_FAILURE(InitState());
2151 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2152
2153 VkDescriptorPoolSize ds_type_count = {};
2154 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
2155 ds_type_count.descriptorCount = 1;
2156
2157 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2158 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2159 ds_pool_ci.pNext = NULL;
2160 ds_pool_ci.flags = 0;
2161 ds_pool_ci.maxSets = 1;
2162 ds_pool_ci.poolSizeCount = 1;
2163 ds_pool_ci.pPoolSizes = &ds_type_count;
2164
2165 VkDescriptorPool ds_pool_one;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002166 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool_one);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002167 ASSERT_VK_SUCCESS(err);
2168
2169 // Create a second descriptor pool
2170 VkDescriptorPool ds_pool_two;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002171 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool_two);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002172 ASSERT_VK_SUCCESS(err);
2173
2174 VkDescriptorSetLayoutBinding dsl_binding = {};
2175 dsl_binding.binding = 0;
2176 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
2177 dsl_binding.descriptorCount = 1;
2178 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2179 dsl_binding.pImmutableSamplers = NULL;
2180
2181 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2182 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2183 ds_layout_ci.pNext = NULL;
2184 ds_layout_ci.bindingCount = 1;
2185 ds_layout_ci.pBindings = &dsl_binding;
2186
2187 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002188 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002189 ASSERT_VK_SUCCESS(err);
2190
2191 VkDescriptorSet descriptorSet;
2192 VkDescriptorSetAllocateInfo alloc_info = {};
2193 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
2194 alloc_info.descriptorSetCount = 1;
2195 alloc_info.descriptorPool = ds_pool_one;
2196 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002197 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002198 ASSERT_VK_SUCCESS(err);
2199
2200 err = vkFreeDescriptorSets(m_device->device(), ds_pool_two, 1, &descriptorSet);
2201
2202 m_errorMonitor->VerifyFound();
2203
2204 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2205 vkDestroyDescriptorPool(m_device->device(), ds_pool_one, NULL);
2206 vkDestroyDescriptorPool(m_device->device(), ds_pool_two, NULL);
2207}
2208
2209TEST_F(VkLayerTest, CreateUnknownObject) {
Karl Schultzf78bcdd2016-11-30 12:36:01 -07002210 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00788);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002211
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002212 TEST_DESCRIPTION("Pass an invalid image object handle into a Vulkan API call.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002213
2214 ASSERT_NO_FATAL_FAILURE(InitState());
2215
2216 // Pass bogus handle into GetImageMemoryRequirements
2217 VkMemoryRequirements mem_reqs;
2218 uint64_t fakeImageHandle = 0xCADECADE;
2219 VkImage fauxImage = reinterpret_cast<VkImage &>(fakeImageHandle);
2220
2221 vkGetImageMemoryRequirements(m_device->device(), fauxImage, &mem_reqs);
2222
2223 m_errorMonitor->VerifyFound();
2224}
2225
Karl Schultz6addd812016-02-02 17:17:23 -07002226TEST_F(VkLayerTest, PipelineNotBound) {
2227 VkResult err;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002228
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002229 TEST_DESCRIPTION("Pass in an invalid pipeline object handle into a Vulkan API call.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002230
Karl Schultzf78bcdd2016-11-30 12:36:01 -07002231 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00601);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002232
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002233 ASSERT_NO_FATAL_FAILURE(InitState());
2234 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002235
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002236 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002237 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2238 ds_type_count.descriptorCount = 1;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002239
2240 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002241 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2242 ds_pool_ci.pNext = NULL;
2243 ds_pool_ci.maxSets = 1;
2244 ds_pool_ci.poolSizeCount = 1;
2245 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002246
2247 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002248 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002249 ASSERT_VK_SUCCESS(err);
2250
2251 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002252 dsl_binding.binding = 0;
2253 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2254 dsl_binding.descriptorCount = 1;
2255 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2256 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002257
2258 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002259 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2260 ds_layout_ci.pNext = NULL;
2261 ds_layout_ci.bindingCount = 1;
2262 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002263
2264 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002265 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002266 ASSERT_VK_SUCCESS(err);
2267
2268 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002269 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08002270 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07002271 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06002272 alloc_info.descriptorPool = ds_pool;
2273 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002274 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002275 ASSERT_VK_SUCCESS(err);
2276
2277 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002278 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
2279 pipeline_layout_ci.pNext = NULL;
2280 pipeline_layout_ci.setLayoutCount = 1;
2281 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002282
2283 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002284 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002285 ASSERT_VK_SUCCESS(err);
2286
Mark Youngad779052016-01-06 14:26:04 -07002287 VkPipeline badPipeline = (VkPipeline)((size_t)0xbaadb1be);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002288
2289 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002290 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, badPipeline);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002291
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002292 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002293
Chia-I Wuf7458c52015-10-26 21:10:41 +08002294 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
2295 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2296 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002297}
Mike Stroyan80fc6c32016-06-20 15:42:29 -06002298
Mark Lobodzinskibc185762016-06-15 16:28:53 -06002299TEST_F(VkLayerTest, BindImageInvalidMemoryType) {
2300 VkResult err;
2301
2302 TEST_DESCRIPTION("Test validation check for an invalid memory type index "
2303 "during bind[Buffer|Image]Memory time");
2304
Mark Lobodzinskibc185762016-06-15 16:28:53 -06002305 ASSERT_NO_FATAL_FAILURE(InitState());
2306
2307 // Create an image, allocate memory, set a bad typeIndex and then try to
2308 // bind it
2309 VkImage image;
2310 VkDeviceMemory mem;
2311 VkMemoryRequirements mem_reqs;
2312 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2313 const int32_t tex_width = 32;
2314 const int32_t tex_height = 32;
2315
2316 VkImageCreateInfo image_create_info = {};
2317 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2318 image_create_info.pNext = NULL;
2319 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2320 image_create_info.format = tex_format;
2321 image_create_info.extent.width = tex_width;
2322 image_create_info.extent.height = tex_height;
2323 image_create_info.extent.depth = 1;
2324 image_create_info.mipLevels = 1;
2325 image_create_info.arrayLayers = 1;
2326 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2327 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
2328 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2329 image_create_info.flags = 0;
2330
2331 VkMemoryAllocateInfo mem_alloc = {};
2332 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2333 mem_alloc.pNext = NULL;
2334 mem_alloc.allocationSize = 0;
2335 mem_alloc.memoryTypeIndex = 0;
2336
2337 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
2338 ASSERT_VK_SUCCESS(err);
2339
2340 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
2341 mem_alloc.allocationSize = mem_reqs.size;
Mike Stroyan80fc6c32016-06-20 15:42:29 -06002342
2343 // Introduce Failure, select invalid TypeIndex
2344 VkPhysicalDeviceMemoryProperties memory_info;
2345
2346 vkGetPhysicalDeviceMemoryProperties(gpu(), &memory_info);
2347 unsigned int i;
2348 for (i = 0; i < memory_info.memoryTypeCount; i++) {
2349 if ((mem_reqs.memoryTypeBits & (1 << i)) == 0) {
2350 mem_alloc.memoryTypeIndex = i;
2351 break;
2352 }
2353 }
2354 if (i >= memory_info.memoryTypeCount) {
2355 printf("No invalid memory type index could be found; skipped.\n");
2356 vkDestroyImage(m_device->device(), image, NULL);
2357 return;
2358 }
2359
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002360 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "for this object type are not compatible with the memory");
Mark Lobodzinskibc185762016-06-15 16:28:53 -06002361
2362 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
2363 ASSERT_VK_SUCCESS(err);
2364
2365 err = vkBindImageMemory(m_device->device(), image, mem, 0);
2366 (void)err;
2367
2368 m_errorMonitor->VerifyFound();
2369
2370 vkDestroyImage(m_device->device(), image, NULL);
2371 vkFreeMemory(m_device->device(), mem, NULL);
2372}
Mike Stroyan80fc6c32016-06-20 15:42:29 -06002373
Karl Schultz6addd812016-02-02 17:17:23 -07002374TEST_F(VkLayerTest, BindInvalidMemory) {
2375 VkResult err;
2376 bool pass;
Tobin Ehlisec598302015-09-15 15:02:17 -06002377
Karl Schultzf78bcdd2016-11-30 12:36:01 -07002378 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00809);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002379
Tobin Ehlisec598302015-09-15 15:02:17 -06002380 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisec598302015-09-15 15:02:17 -06002381
2382 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07002383 VkImage image;
2384 VkDeviceMemory mem;
2385 VkMemoryRequirements mem_reqs;
Tobin Ehlisec598302015-09-15 15:02:17 -06002386
Karl Schultz6addd812016-02-02 17:17:23 -07002387 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2388 const int32_t tex_width = 32;
2389 const int32_t tex_height = 32;
Tobin Ehlisec598302015-09-15 15:02:17 -06002390
2391 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002392 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2393 image_create_info.pNext = NULL;
2394 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2395 image_create_info.format = tex_format;
2396 image_create_info.extent.width = tex_width;
2397 image_create_info.extent.height = tex_height;
2398 image_create_info.extent.depth = 1;
2399 image_create_info.mipLevels = 1;
2400 image_create_info.arrayLayers = 1;
2401 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2402 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2403 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2404 image_create_info.flags = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002405
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002406 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002407 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2408 mem_alloc.pNext = NULL;
2409 mem_alloc.allocationSize = 0;
2410 mem_alloc.memoryTypeIndex = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002411
Chia-I Wuf7458c52015-10-26 21:10:41 +08002412 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlisec598302015-09-15 15:02:17 -06002413 ASSERT_VK_SUCCESS(err);
2414
Karl Schultz6addd812016-02-02 17:17:23 -07002415 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Tobin Ehlisec598302015-09-15 15:02:17 -06002416
2417 mem_alloc.allocationSize = mem_reqs.size;
2418
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002419 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06002420 ASSERT_TRUE(pass);
Tobin Ehlisec598302015-09-15 15:02:17 -06002421
2422 // allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002423 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlisec598302015-09-15 15:02:17 -06002424 ASSERT_VK_SUCCESS(err);
2425
2426 // Introduce validation failure, free memory before binding
Chia-I Wuf7458c52015-10-26 21:10:41 +08002427 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002428
2429 // Try to bind free memory that has been freed
2430 err = vkBindImageMemory(m_device->device(), image, mem, 0);
2431 // This may very well return an error.
2432 (void)err;
2433
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002434 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002435
Chia-I Wuf7458c52015-10-26 21:10:41 +08002436 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002437}
2438
Karl Schultz6addd812016-02-02 17:17:23 -07002439TEST_F(VkLayerTest, BindMemoryToDestroyedObject) {
2440 VkResult err;
2441 bool pass;
Tobin Ehlisec598302015-09-15 15:02:17 -06002442
Karl Schultzf78bcdd2016-11-30 12:36:01 -07002443 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00808);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002444
Tobin Ehlisec598302015-09-15 15:02:17 -06002445 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisec598302015-09-15 15:02:17 -06002446
Karl Schultz6addd812016-02-02 17:17:23 -07002447 // Create an image object, allocate memory, destroy the object and then try
2448 // to bind it
2449 VkImage image;
2450 VkDeviceMemory mem;
2451 VkMemoryRequirements mem_reqs;
Tobin Ehlisec598302015-09-15 15:02:17 -06002452
Karl Schultz6addd812016-02-02 17:17:23 -07002453 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2454 const int32_t tex_width = 32;
2455 const int32_t tex_height = 32;
Tobin Ehlisec598302015-09-15 15:02:17 -06002456
2457 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002458 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2459 image_create_info.pNext = NULL;
2460 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2461 image_create_info.format = tex_format;
2462 image_create_info.extent.width = tex_width;
2463 image_create_info.extent.height = tex_height;
2464 image_create_info.extent.depth = 1;
2465 image_create_info.mipLevels = 1;
2466 image_create_info.arrayLayers = 1;
2467 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2468 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2469 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2470 image_create_info.flags = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002471
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002472 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002473 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2474 mem_alloc.pNext = NULL;
2475 mem_alloc.allocationSize = 0;
2476 mem_alloc.memoryTypeIndex = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002477
Chia-I Wuf7458c52015-10-26 21:10:41 +08002478 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlisec598302015-09-15 15:02:17 -06002479 ASSERT_VK_SUCCESS(err);
2480
Karl Schultz6addd812016-02-02 17:17:23 -07002481 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Tobin Ehlisec598302015-09-15 15:02:17 -06002482
2483 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002484 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06002485 ASSERT_TRUE(pass);
Tobin Ehlisec598302015-09-15 15:02:17 -06002486
2487 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002488 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlisec598302015-09-15 15:02:17 -06002489 ASSERT_VK_SUCCESS(err);
2490
2491 // Introduce validation failure, destroy Image object before binding
Chia-I Wuf7458c52015-10-26 21:10:41 +08002492 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002493 ASSERT_VK_SUCCESS(err);
2494
2495 // Now Try to bind memory to this destroyed object
2496 err = vkBindImageMemory(m_device->device(), image, mem, 0);
2497 // This may very well return an error.
Karl Schultz6addd812016-02-02 17:17:23 -07002498 (void)err;
Tobin Ehlisec598302015-09-15 15:02:17 -06002499
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002500 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002501
Chia-I Wuf7458c52015-10-26 21:10:41 +08002502 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002503}
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002504
Mark Lobodzinski209b5292015-09-17 09:44:05 -06002505#endif // OBJ_TRACKER_TESTS
2506
Tobin Ehlis0788f522015-05-26 16:11:58 -06002507#if DRAW_STATE_TESTS
Mark Lobodzinskic808d442016-04-14 10:57:23 -06002508
Mark Lobodzinski66e5eab2016-11-15 13:30:38 -07002509TEST_F(VkLayerTest, CreatePipelineBadVertexAttributeFormat) {
2510 TEST_DESCRIPTION("Test that pipeline validation catches invalid vertex attribute formats");
2511
2512 ASSERT_NO_FATAL_FAILURE(InitState());
2513 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2514
2515 VkVertexInputBindingDescription input_binding;
2516 memset(&input_binding, 0, sizeof(input_binding));
2517
2518 VkVertexInputAttributeDescription input_attribs;
2519 memset(&input_attribs, 0, sizeof(input_attribs));
2520
2521 // Pick a really bad format for this purpose and make sure it should fail
2522 input_attribs.format = VK_FORMAT_BC2_UNORM_BLOCK;
2523 VkFormatProperties format_props = m_device->format_properties(input_attribs.format);
2524 if ((format_props.bufferFeatures & VK_FORMAT_FEATURE_VERTEX_BUFFER_BIT) != 0) {
2525 printf("Format unsuitable for test; skipped.\n");
2526 return;
2527 }
2528
2529 input_attribs.location = 0;
2530 char const *vsSource = "#version 450\n"
2531 "\n"
2532 "out gl_PerVertex {\n"
2533 " vec4 gl_Position;\n"
2534 "};\n"
2535 "void main(){\n"
2536 " gl_Position = vec4(1);\n"
2537 "}\n";
2538 char const *fsSource = "#version 450\n"
2539 "\n"
2540 "layout(location=0) out vec4 color;\n"
2541 "void main(){\n"
2542 " color = vec4(1);\n"
2543 "}\n";
2544
2545 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01413);
2546 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
2547 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
2548
2549 VkPipelineObj pipe(m_device);
2550 pipe.AddColorAttachment();
2551 pipe.AddShader(&vs);
2552 pipe.AddShader(&fs);
2553
2554 pipe.AddVertexInputBindings(&input_binding, 1);
2555 pipe.AddVertexInputAttribs(&input_attribs, 1);
2556
2557 VkDescriptorSetObj descriptorSet(m_device);
2558 descriptorSet.AppendDummy();
2559 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
2560
2561 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
2562
2563 m_errorMonitor->VerifyFound();
2564}
2565
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002566TEST_F(VkLayerTest, ImageSampleCounts) {
2567
2568 TEST_DESCRIPTION("Use bad sample counts in image transfer calls to trigger "
2569 "validation errors.");
2570 ASSERT_NO_FATAL_FAILURE(InitState());
2571
2572 VkMemoryPropertyFlags reqs = 0;
2573 VkImageCreateInfo image_create_info = {};
2574 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2575 image_create_info.pNext = NULL;
2576 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2577 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
2578 image_create_info.extent.width = 256;
2579 image_create_info.extent.height = 256;
2580 image_create_info.extent.depth = 1;
2581 image_create_info.mipLevels = 1;
2582 image_create_info.arrayLayers = 1;
2583 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
2584 image_create_info.flags = 0;
2585
2586 VkImageBlit blit_region = {};
2587 blit_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2588 blit_region.srcSubresource.baseArrayLayer = 0;
2589 blit_region.srcSubresource.layerCount = 1;
2590 blit_region.srcSubresource.mipLevel = 0;
2591 blit_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2592 blit_region.dstSubresource.baseArrayLayer = 0;
2593 blit_region.dstSubresource.layerCount = 1;
2594 blit_region.dstSubresource.mipLevel = 0;
2595
2596 // Create two images, the source with sampleCount = 2, and attempt to blit
2597 // between them
2598 {
2599 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002600 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002601 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002602 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002603 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002604 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002605 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002606 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002607 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002608 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "was created with a sample count "
2609 "of VK_SAMPLE_COUNT_2_BIT but "
2610 "must be VK_SAMPLE_COUNT_1_BIT");
2611 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
2612 dst_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, 1, &blit_region, VK_FILTER_NEAREST);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002613 m_errorMonitor->VerifyFound();
2614 m_commandBuffer->EndCommandBuffer();
2615 }
2616
2617 // Create two images, the dest with sampleCount = 4, and attempt to blit
2618 // between them
2619 {
2620 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002621 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002622 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002623 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002624 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002625 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002626 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002627 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002628 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002629 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "was created with a sample count "
2630 "of VK_SAMPLE_COUNT_4_BIT but "
2631 "must be VK_SAMPLE_COUNT_1_BIT");
2632 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
2633 dst_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, 1, &blit_region, VK_FILTER_NEAREST);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002634 m_errorMonitor->VerifyFound();
2635 m_commandBuffer->EndCommandBuffer();
2636 }
2637
2638 VkBufferImageCopy copy_region = {};
2639 copy_region.bufferRowLength = 128;
2640 copy_region.bufferImageHeight = 128;
2641 copy_region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2642 copy_region.imageSubresource.layerCount = 1;
2643 copy_region.imageExtent.height = 64;
2644 copy_region.imageExtent.width = 64;
2645 copy_region.imageExtent.depth = 1;
2646
2647 // Create src buffer and dst image with sampleCount = 4 and attempt to copy
2648 // buffer to image
2649 {
2650 vk_testing::Buffer src_buffer;
2651 VkMemoryPropertyFlags reqs = 0;
2652 src_buffer.init_as_src(*m_device, 128 * 128 * 4, reqs);
2653 image_create_info.samples = VK_SAMPLE_COUNT_8_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002654 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002655 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002656 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002657 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002658 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "was created with a sample count "
2659 "of VK_SAMPLE_COUNT_8_BIT but "
2660 "must be VK_SAMPLE_COUNT_1_BIT");
2661 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), src_buffer.handle(), dst_image.handle(),
2662 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &copy_region);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002663 m_errorMonitor->VerifyFound();
2664 m_commandBuffer->EndCommandBuffer();
2665 }
2666
2667 // Create dst buffer and src image with sampleCount = 2 and attempt to copy
2668 // image to buffer
2669 {
2670 vk_testing::Buffer dst_buffer;
2671 dst_buffer.init_as_dst(*m_device, 128 * 128 * 4, reqs);
2672 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002673 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002674 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002675 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002676 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002677 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "was created with a sample count "
2678 "of VK_SAMPLE_COUNT_2_BIT but "
2679 "must be VK_SAMPLE_COUNT_1_BIT");
2680 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002681 dst_buffer.handle(), 1, &copy_region);
2682 m_errorMonitor->VerifyFound();
2683 m_commandBuffer->EndCommandBuffer();
2684 }
2685}
2686
Mike Stroyanac5afeb2016-10-17 13:58:10 -06002687TEST_F(VkLayerTest, BlitImageFormats) {
2688
2689 // Image blit with mismatched formats
2690 const char * expected_message =
2691 "vkCmdBlitImage: If one of srcImage and dstImage images has signed/unsigned integer format,"
2692 " the other one must also have signed/unsigned integer format";
2693
2694 ASSERT_NO_FATAL_FAILURE(InitState());
2695
2696 VkImageObj src_image(m_device);
2697 src_image.init(64, 64, VK_FORMAT_A2B10G10R10_UINT_PACK32, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_LINEAR, 0);
2698 VkImageObj dst_image(m_device);
2699 dst_image.init(64, 64, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
2700 VkImageObj dst_image2(m_device);
Mike Stroyan131f3e72016-10-18 11:10:23 -06002701 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 -06002702
2703 VkImageBlit blitRegion = {};
2704 blitRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2705 blitRegion.srcSubresource.baseArrayLayer = 0;
2706 blitRegion.srcSubresource.layerCount = 1;
2707 blitRegion.srcSubresource.mipLevel = 0;
2708 blitRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2709 blitRegion.dstSubresource.baseArrayLayer = 0;
2710 blitRegion.dstSubresource.layerCount = 1;
2711 blitRegion.dstSubresource.mipLevel = 0;
2712
2713 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, expected_message);
2714
2715 // Unsigned int vs not an int
2716 BeginCommandBuffer();
2717 vkCmdBlitImage(m_commandBuffer->handle(), src_image.image(), src_image.layout(), dst_image.image(),
2718 dst_image.layout(), 1, &blitRegion, VK_FILTER_NEAREST);
2719
2720 m_errorMonitor->VerifyFound();
2721
2722 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, expected_message);
2723
2724 // Unsigned int vs signed int
2725 vkCmdBlitImage(m_commandBuffer->handle(), src_image.image(), src_image.layout(), dst_image2.image(),
2726 dst_image2.layout(), 1, &blitRegion, VK_FILTER_NEAREST);
2727
2728 m_errorMonitor->VerifyFound();
2729
2730 EndCommandBuffer();
2731}
2732
2733
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002734TEST_F(VkLayerTest, DSImageTransferGranularityTests) {
2735 VkResult err;
2736 bool pass;
2737
2738 TEST_DESCRIPTION("Tests for validaiton of Queue Family property minImageTransferGranularity.");
2739 ASSERT_NO_FATAL_FAILURE(InitState());
2740
2741 // If w/d/h granularity is 1, test is not meaningful
2742 // TODO: When virtual device limits are available, create a set of limits for this test that
2743 // will always have a granularity of > 1 for w, h, and d
2744 auto index = m_device->graphics_queue_node_index_;
2745 auto queue_family_properties = m_device->phy().queue_properties();
2746
2747 if ((queue_family_properties[index].minImageTransferGranularity.depth < 4) ||
2748 (queue_family_properties[index].minImageTransferGranularity.width < 4) ||
2749 (queue_family_properties[index].minImageTransferGranularity.height < 4)) {
2750 return;
2751 }
2752
2753 // Create two images of different types and try to copy between them
2754 VkImage srcImage;
2755 VkImage dstImage;
2756 VkDeviceMemory srcMem;
2757 VkDeviceMemory destMem;
2758 VkMemoryRequirements memReqs;
2759
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002760 VkImageCreateInfo image_create_info = {};
2761 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2762 image_create_info.pNext = NULL;
2763 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2764 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
2765 image_create_info.extent.width = 32;
2766 image_create_info.extent.height = 32;
2767 image_create_info.extent.depth = 1;
2768 image_create_info.mipLevels = 1;
2769 image_create_info.arrayLayers = 4;
2770 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2771 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
2772 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
2773 image_create_info.flags = 0;
2774
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002775 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002776 ASSERT_VK_SUCCESS(err);
2777
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002778 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002779 ASSERT_VK_SUCCESS(err);
2780
2781 // Allocate memory
2782 VkMemoryAllocateInfo memAlloc = {};
2783 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2784 memAlloc.pNext = NULL;
2785 memAlloc.allocationSize = 0;
2786 memAlloc.memoryTypeIndex = 0;
2787
2788 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
2789 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002790 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002791 ASSERT_TRUE(pass);
2792 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
2793 ASSERT_VK_SUCCESS(err);
2794
2795 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
2796 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002797 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002798 ASSERT_VK_SUCCESS(err);
2799 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
2800 ASSERT_VK_SUCCESS(err);
2801
2802 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
2803 ASSERT_VK_SUCCESS(err);
2804 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
2805 ASSERT_VK_SUCCESS(err);
2806
2807 BeginCommandBuffer();
2808 VkImageCopy copyRegion;
2809 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2810 copyRegion.srcSubresource.mipLevel = 0;
2811 copyRegion.srcSubresource.baseArrayLayer = 0;
2812 copyRegion.srcSubresource.layerCount = 1;
2813 copyRegion.srcOffset.x = 0;
2814 copyRegion.srcOffset.y = 0;
2815 copyRegion.srcOffset.z = 0;
2816 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2817 copyRegion.dstSubresource.mipLevel = 0;
2818 copyRegion.dstSubresource.baseArrayLayer = 0;
2819 copyRegion.dstSubresource.layerCount = 1;
2820 copyRegion.dstOffset.x = 0;
2821 copyRegion.dstOffset.y = 0;
2822 copyRegion.dstOffset.z = 0;
2823 copyRegion.extent.width = 1;
2824 copyRegion.extent.height = 1;
2825 copyRegion.extent.depth = 1;
2826
2827 // Introduce failure by setting srcOffset to a bad granularity value
2828 copyRegion.srcOffset.y = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002829 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2830 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002831 m_errorMonitor->VerifyFound();
2832
2833 // Introduce failure by setting extent to a bad granularity value
2834 copyRegion.srcOffset.y = 0;
2835 copyRegion.extent.width = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002836 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2837 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002838 m_errorMonitor->VerifyFound();
2839
2840 // Now do some buffer/image copies
2841 vk_testing::Buffer buffer;
2842 VkMemoryPropertyFlags reqs = 0;
2843 buffer.init_as_dst(*m_device, 128 * 128, reqs);
2844 VkBufferImageCopy region = {};
2845 region.bufferOffset = 0;
2846 region.bufferRowLength = 3;
2847 region.bufferImageHeight = 128;
2848 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2849 region.imageSubresource.layerCount = 1;
2850 region.imageExtent.height = 16;
2851 region.imageExtent.width = 16;
2852 region.imageExtent.depth = 1;
2853 region.imageOffset.x = 0;
2854 region.imageOffset.y = 0;
2855 region.imageOffset.z = 0;
2856
2857 // Introduce failure by setting bufferRowLength to a bad granularity value
2858 region.bufferRowLength = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002859 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2860 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
2861 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002862 m_errorMonitor->VerifyFound();
2863 region.bufferRowLength = 128;
2864
2865 // Introduce failure by setting bufferOffset to a bad granularity value
2866 region.bufferOffset = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002867 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2868 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
2869 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002870 m_errorMonitor->VerifyFound();
2871 region.bufferOffset = 0;
2872
2873 // Introduce failure by setting bufferImageHeight to a bad granularity value
2874 region.bufferImageHeight = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002875 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2876 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
2877 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002878 m_errorMonitor->VerifyFound();
2879 region.bufferImageHeight = 128;
2880
2881 // Introduce failure by setting imageExtent to a bad granularity value
2882 region.imageExtent.width = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002883 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2884 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
2885 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002886 m_errorMonitor->VerifyFound();
2887 region.imageExtent.width = 16;
2888
2889 // Introduce failure by setting imageOffset to a bad granularity value
2890 region.imageOffset.z = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002891 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2892 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
2893 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002894 m_errorMonitor->VerifyFound();
2895
2896 EndCommandBuffer();
2897
2898 vkDestroyImage(m_device->device(), srcImage, NULL);
2899 vkDestroyImage(m_device->device(), dstImage, NULL);
2900 vkFreeMemory(m_device->device(), srcMem, NULL);
2901 vkFreeMemory(m_device->device(), destMem, NULL);
2902}
2903
Mark Lobodzinski570efc62016-08-09 16:43:19 -06002904TEST_F(VkLayerTest, MismatchedQueueFamiliesOnSubmit) {
Mark Lobodzinski570efc62016-08-09 16:43:19 -06002905 TEST_DESCRIPTION("Submit command buffer created using one queue family and "
2906 "attempt to submit them on a queue created in a different "
2907 "queue family.");
2908
Cody Northropc31a84f2016-08-22 10:41:47 -06002909 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski570efc62016-08-09 16:43:19 -06002910 // This test is meaningless unless we have multiple queue families
2911 auto queue_family_properties = m_device->phy().queue_properties();
2912 if (queue_family_properties.size() < 2) {
2913 return;
2914 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002915 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is being submitted on queue ");
Mark Lobodzinski570efc62016-08-09 16:43:19 -06002916 // Get safe index of another queue family
2917 uint32_t other_queue_family = (m_device->graphics_queue_node_index_ == 0) ? 1 : 0;
2918 ASSERT_NO_FATAL_FAILURE(InitState());
2919 // Create a second queue using a different queue family
2920 VkQueue other_queue;
2921 vkGetDeviceQueue(m_device->device(), other_queue_family, 0, &other_queue);
2922
2923 // Record an empty cmd buffer
2924 VkCommandBufferBeginInfo cmdBufBeginDesc = {};
2925 cmdBufBeginDesc.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
2926 vkBeginCommandBuffer(m_commandBuffer->handle(), &cmdBufBeginDesc);
2927 vkEndCommandBuffer(m_commandBuffer->handle());
2928
2929 // And submit on the wrong queue
2930 VkSubmitInfo submit_info = {};
2931 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
2932 submit_info.commandBufferCount = 1;
2933 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Tobin Ehlisfd213ea2016-08-10 17:10:46 -06002934 vkQueueSubmit(other_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Lobodzinski570efc62016-08-09 16:43:19 -06002935
2936 m_errorMonitor->VerifyFound();
Mark Lobodzinski570efc62016-08-09 16:43:19 -06002937}
2938
Chris Forbes4c24a922016-11-16 08:59:10 +13002939TEST_F(VkLayerTest, RenderPassAttachmentIndexOutOfRange) {
2940 ASSERT_NO_FATAL_FAILURE(InitState());
2941
Chris Forbes2d9b2a82016-11-21 10:45:39 +13002942 // There are no attachments, but refer to attachment 0.
2943 VkAttachmentReference ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Chris Forbes4c24a922016-11-16 08:59:10 +13002944 VkSubpassDescription subpasses[] = {
Chris Forbes2d9b2a82016-11-21 10:45:39 +13002945 {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &ref, nullptr,
2946 nullptr, 0, nullptr},
Chris Forbes4c24a922016-11-16 08:59:10 +13002947 };
2948
Chris Forbes2d9b2a82016-11-21 10:45:39 +13002949 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO,
2950 nullptr,
2951 0,
2952 0,
2953 nullptr,
2954 1,
2955 subpasses,
2956 0,
2957 nullptr};
Chris Forbes4c24a922016-11-16 08:59:10 +13002958 VkRenderPass rp;
2959
Chris Forbes2d9b2a82016-11-21 10:45:39 +13002960 // "... must be less than the total number of attachments ..."
Chris Forbes4c24a922016-11-16 08:59:10 +13002961 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbes2d9b2a82016-11-21 10:45:39 +13002962 VALIDATION_ERROR_00325);
Chris Forbes4c24a922016-11-16 08:59:10 +13002963 vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
2964 m_errorMonitor->VerifyFound();
2965}
2966
Chris Forbesa58c4522016-09-28 15:19:39 +13002967TEST_F(VkLayerTest, RenderPassPipelineSubpassMismatch) {
2968 TEST_DESCRIPTION("Use a pipeline for the wrong subpass in a render pass instance");
2969 ASSERT_NO_FATAL_FAILURE(InitState());
2970
2971 // A renderpass with two subpasses, both writing the same attachment.
2972 VkAttachmentDescription attach[] = {
2973 { 0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT,
2974 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
2975 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
2976 VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL
2977 },
2978 };
2979 VkAttachmentReference ref = { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
2980 VkSubpassDescription subpasses[] = {
2981 { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr,
2982 1, &ref, nullptr, nullptr, 0, nullptr },
2983 { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr,
2984 1, &ref, nullptr, nullptr, 0, nullptr },
2985 };
2986 VkSubpassDependency dep = {
2987 0, 1,
2988 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
2989 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
2990 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
2991 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
2992 VK_DEPENDENCY_BY_REGION_BIT
2993 };
2994 VkRenderPassCreateInfo rpci = {
2995 VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr,
2996 0, 1, attach, 2, subpasses, 1, &dep
2997 };
2998 VkRenderPass rp;
2999 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3000 ASSERT_VK_SUCCESS(err);
3001
3002 VkImageObj image(m_device);
3003 image.init_no_layout(32, 32, VK_FORMAT_R8G8B8A8_UNORM,
3004 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT,
3005 VK_IMAGE_TILING_OPTIMAL, 0);
3006 VkImageView imageView = image.targetView(VK_FORMAT_R8G8B8A8_UNORM);
3007
3008 VkFramebufferCreateInfo fbci = {
3009 VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr,
3010 0, rp, 1, &imageView, 32, 32, 1
3011 };
3012 VkFramebuffer fb;
3013 err = vkCreateFramebuffer(m_device->device(), &fbci, nullptr, &fb);
3014 ASSERT_VK_SUCCESS(err);
3015
3016 char const *vsSource =
3017 "#version 450\n"
3018 "void main() { gl_Position = vec4(1); }\n";
3019 char const *fsSource =
3020 "#version 450\n"
3021 "layout(location=0) out vec4 color;\n"
3022 "void main() { color = vec4(1); }\n";
3023
3024 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
3025 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
3026 VkPipelineObj pipe(m_device);
3027 pipe.AddColorAttachment();
3028 pipe.AddShader(&vs);
3029 pipe.AddShader(&fs);
3030 VkViewport view_port = {};
3031 m_viewports.push_back(view_port);
3032 pipe.SetViewport(m_viewports);
3033 VkRect2D rect = {};
3034 m_scissors.push_back(rect);
3035 pipe.SetScissor(m_scissors);
3036
3037 VkPipelineLayoutCreateInfo plci = {
3038 VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr,
3039 0, 0, nullptr, 0, nullptr
3040 };
3041 VkPipelineLayout pl;
3042 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
3043 ASSERT_VK_SUCCESS(err);
3044 pipe.CreateVKPipeline(pl, rp);
3045
3046 BeginCommandBuffer();
3047
3048 VkRenderPassBeginInfo rpbi = {
3049 VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr,
3050 rp, fb, { { 0, 0, }, { 32, 32 } }, 0, nullptr
3051 };
3052
3053 // subtest 1: bind in the wrong subpass
3054 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
3055 vkCmdNextSubpass(m_commandBuffer->handle(), VK_SUBPASS_CONTENTS_INLINE);
3056 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3057 "built for subpass 0 but used in subpass 1");
3058 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
3059 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
3060 m_errorMonitor->VerifyFound();
3061
3062 vkCmdEndRenderPass(m_commandBuffer->handle());
3063
3064 // subtest 2: bind in correct subpass, then transition to next subpass
3065 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
3066 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
3067 vkCmdNextSubpass(m_commandBuffer->handle(), VK_SUBPASS_CONTENTS_INLINE);
3068 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3069 "built for subpass 0 but used in subpass 1");
3070 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
3071 m_errorMonitor->VerifyFound();
3072
3073 vkCmdEndRenderPass(m_commandBuffer->handle());
3074
3075 EndCommandBuffer();
3076
3077 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
3078 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
3079 vkDestroyRenderPass(m_device->device(), rp, nullptr);
3080}
3081
Tony Barbour4e919972016-08-09 13:27:40 -06003082TEST_F(VkLayerTest, RenderPassInvalidRenderArea) {
3083 TEST_DESCRIPTION("Generate INVALID_RENDER_AREA error by beginning renderpass"
3084 "with extent outside of framebuffer");
3085 ASSERT_NO_FATAL_FAILURE(InitState());
3086 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3087
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003088 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot execute a render pass with renderArea "
3089 "not within the bound of the framebuffer.");
Tony Barbour4e919972016-08-09 13:27:40 -06003090
3091 // Framebuffer for render target is 256x256, exceed that for INVALID_RENDER_AREA
3092 m_renderPassBeginInfo.renderArea.extent.width = 257;
3093 m_renderPassBeginInfo.renderArea.extent.height = 257;
3094 BeginCommandBuffer();
3095 m_errorMonitor->VerifyFound();
3096}
3097
3098TEST_F(VkLayerTest, DisabledIndependentBlend) {
3099 TEST_DESCRIPTION("Generate INDEPENDENT_BLEND by disabling independent "
3100 "blend and then specifying different blend states for two "
3101 "attachements");
Cody Northrop5703cc72016-08-19 09:57:10 -06003102 VkPhysicalDeviceFeatures features = {};
3103 features.independentBlend = VK_FALSE;
Cody Northropc31a84f2016-08-22 10:41:47 -06003104 ASSERT_NO_FATAL_FAILURE(InitState(&features));
Tony Barbour4e919972016-08-09 13:27:40 -06003105
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003106 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3107 "Invalid Pipeline CreateInfo: If independent blend feature not "
3108 "enabled, all elements of pAttachments must be identical");
Tony Barbour4e919972016-08-09 13:27:40 -06003109
Cody Northropc31a84f2016-08-22 10:41:47 -06003110 VkDescriptorSetObj descriptorSet(m_device);
3111 descriptorSet.AppendDummy();
3112 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Tony Barbour4e919972016-08-09 13:27:40 -06003113
Cody Northropc31a84f2016-08-22 10:41:47 -06003114 VkPipelineObj pipeline(m_device);
3115 VkRenderpassObj renderpass(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003116 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Cody Northropc31a84f2016-08-22 10:41:47 -06003117 pipeline.AddShader(&vs);
Cody Northrop5703cc72016-08-19 09:57:10 -06003118
Cody Northropc31a84f2016-08-22 10:41:47 -06003119 VkPipelineColorBlendAttachmentState att_state1 = {}, att_state2 = {};
3120 att_state1.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
3121 att_state1.blendEnable = VK_TRUE;
3122 att_state2.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
3123 att_state2.blendEnable = VK_FALSE;
3124 pipeline.AddColorAttachment(0, &att_state1);
3125 pipeline.AddColorAttachment(1, &att_state2);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003126 pipeline.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderpass.handle());
Cody Northropc31a84f2016-08-22 10:41:47 -06003127 m_errorMonitor->VerifyFound();
Tony Barbour4e919972016-08-09 13:27:40 -06003128}
3129
Chris Forbes26ec2122016-11-29 08:58:33 +13003130#if 0
Tony Barbour4e919972016-08-09 13:27:40 -06003131TEST_F(VkLayerTest, RenderPassDepthStencilAttachmentUnused) {
3132 TEST_DESCRIPTION("Specify no depth attachement in renderpass then specify "
3133 "depth attachments in subpass");
Cody Northropc31a84f2016-08-22 10:41:47 -06003134 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbour4e919972016-08-09 13:27:40 -06003135
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003136 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3137 "vkCreateRenderPass has no depth/stencil attachment, yet subpass");
Tony Barbour4e919972016-08-09 13:27:40 -06003138
3139 // Create a renderPass with a single color attachment
3140 VkAttachmentReference attach = {};
3141 attach.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
3142 VkSubpassDescription subpass = {};
3143 VkRenderPassCreateInfo rpci = {};
3144 rpci.subpassCount = 1;
3145 rpci.pSubpasses = &subpass;
3146 rpci.attachmentCount = 1;
3147 VkAttachmentDescription attach_desc = {};
3148 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
3149 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
3150 rpci.pAttachments = &attach_desc;
3151 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3152 VkRenderPass rp;
3153 subpass.pDepthStencilAttachment = &attach;
3154 subpass.pColorAttachments = NULL;
3155 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3156 m_errorMonitor->VerifyFound();
3157}
Chris Forbes26ec2122016-11-29 08:58:33 +13003158#endif
Tony Barbour4e919972016-08-09 13:27:40 -06003159
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003160TEST_F(VkLayerTest, UnusedPreserveAttachment) {
3161 TEST_DESCRIPTION("Create a framebuffer where a subpass has a preserve "
3162 "attachment reference of VK_ATTACHMENT_UNUSED");
3163
3164 ASSERT_NO_FATAL_FAILURE(InitState());
3165 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3166
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003167 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "must not be VK_ATTACHMENT_UNUSED");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003168
3169 VkAttachmentReference color_attach = {};
3170 color_attach.layout = VK_IMAGE_LAYOUT_GENERAL;
3171 color_attach.attachment = 0;
3172 uint32_t preserve_attachment = VK_ATTACHMENT_UNUSED;
3173 VkSubpassDescription subpass = {};
3174 subpass.colorAttachmentCount = 1;
3175 subpass.pColorAttachments = &color_attach;
3176 subpass.preserveAttachmentCount = 1;
3177 subpass.pPreserveAttachments = &preserve_attachment;
3178
3179 VkRenderPassCreateInfo rpci = {};
3180 rpci.subpassCount = 1;
3181 rpci.pSubpasses = &subpass;
3182 rpci.attachmentCount = 1;
3183 VkAttachmentDescription attach_desc = {};
3184 attach_desc.format = VK_FORMAT_UNDEFINED;
3185 rpci.pAttachments = &attach_desc;
3186 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3187 VkRenderPass rp;
Mark Lobodzinskia4feeeb2016-06-17 12:00:46 -06003188 VkResult result = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003189
3190 m_errorMonitor->VerifyFound();
3191
Mark Lobodzinskia4feeeb2016-06-17 12:00:46 -06003192 if (result == VK_SUCCESS) {
3193 vkDestroyRenderPass(m_device->device(), rp, NULL);
3194 }
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003195}
3196
Chris Forbesc5389742016-06-29 11:49:23 +12003197TEST_F(VkLayerTest, CreateRenderPassResolveRequiresColorMsaa) {
Chris Forbes6655bb32016-07-01 18:27:30 +12003198 TEST_DESCRIPTION("Ensure that CreateRenderPass produces a validation error "
3199 "when the source of a subpass multisample resolve "
3200 "does not have multiple samples.");
3201
Chris Forbesc5389742016-06-29 11:49:23 +12003202 ASSERT_NO_FATAL_FAILURE(InitState());
3203
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003204 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3205 "Subpass 0 requests multisample resolve from attachment 0 which has "
3206 "VK_SAMPLE_COUNT_1_BIT");
Chris Forbesc5389742016-06-29 11:49:23 +12003207
3208 VkAttachmentDescription attachments[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003209 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3210 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3211 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3212 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3213 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3214 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbesc5389742016-06-29 11:49:23 +12003215 };
3216
3217 VkAttachmentReference color = {
3218 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3219 };
3220
3221 VkAttachmentReference resolve = {
3222 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3223 };
3224
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003225 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &color, &resolve, nullptr, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003226
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003227 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003228
3229 VkRenderPass rp;
3230 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3231
3232 m_errorMonitor->VerifyFound();
3233
3234 if (err == VK_SUCCESS)
3235 vkDestroyRenderPass(m_device->device(), rp, nullptr);
3236}
3237
3238TEST_F(VkLayerTest, CreateRenderPassResolveRequiresSingleSampleDest) {
Chris Forbes6655bb32016-07-01 18:27:30 +12003239 TEST_DESCRIPTION("Ensure CreateRenderPass produces a validation error "
3240 "when a subpass multisample resolve operation is "
3241 "requested, and the destination of that resolve has "
3242 "multiple samples.");
3243
Chris Forbesc5389742016-06-29 11:49:23 +12003244 ASSERT_NO_FATAL_FAILURE(InitState());
3245
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003246 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3247 "Subpass 0 requests multisample resolve into attachment 1, which "
3248 "must have VK_SAMPLE_COUNT_1_BIT but has VK_SAMPLE_COUNT_4_BIT");
Chris Forbesc5389742016-06-29 11:49:23 +12003249
3250 VkAttachmentDescription attachments[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003251 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3252 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3253 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3254 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3255 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3256 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbesc5389742016-06-29 11:49:23 +12003257 };
3258
3259 VkAttachmentReference color = {
3260 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3261 };
3262
3263 VkAttachmentReference resolve = {
3264 1, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3265 };
3266
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003267 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &color, &resolve, nullptr, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003268
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003269 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003270
3271 VkRenderPass rp;
3272 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3273
3274 m_errorMonitor->VerifyFound();
3275
3276 if (err == VK_SUCCESS)
3277 vkDestroyRenderPass(m_device->device(), rp, nullptr);
3278}
3279
Chris Forbes3f128ef2016-06-29 14:58:53 +12003280TEST_F(VkLayerTest, CreateRenderPassSubpassSampleCountConsistency) {
Chris Forbes6655bb32016-07-01 18:27:30 +12003281 TEST_DESCRIPTION("Ensure CreateRenderPass produces a validation error "
3282 "when the color and depth attachments used by a subpass "
3283 "have inconsistent sample counts");
3284
Chris Forbes3f128ef2016-06-29 14:58:53 +12003285 ASSERT_NO_FATAL_FAILURE(InitState());
3286
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003287 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3288 "Subpass 0 attempts to render to attachments with inconsistent sample counts");
Chris Forbes3f128ef2016-06-29 14:58:53 +12003289
3290 VkAttachmentDescription attachments[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003291 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3292 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3293 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3294 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3295 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3296 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbes3f128ef2016-06-29 14:58:53 +12003297 };
3298
3299 VkAttachmentReference color[] = {
3300 {
3301 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3302 },
3303 {
3304 1, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3305 },
3306 };
3307
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003308 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 2, color, nullptr, nullptr, 0, nullptr};
Chris Forbes3f128ef2016-06-29 14:58:53 +12003309
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003310 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbes3f128ef2016-06-29 14:58:53 +12003311
3312 VkRenderPass rp;
3313 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3314
3315 m_errorMonitor->VerifyFound();
3316
3317 if (err == VK_SUCCESS)
3318 vkDestroyRenderPass(m_device->device(), rp, nullptr);
3319}
3320
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003321TEST_F(VkLayerTest, FramebufferCreateErrors) {
3322 TEST_DESCRIPTION("Hit errors when attempting to create a framebuffer :\n"
Mike Weiblencce7ec72016-10-17 19:33:05 -06003323 " 1. Mismatch between framebuffer & renderPass attachmentCount\n"
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003324 " 2. Use a color image as depthStencil attachment\n"
Mike Weiblencce7ec72016-10-17 19:33:05 -06003325 " 3. Mismatch framebuffer & renderPass attachment formats\n"
3326 " 4. Mismatch framebuffer & renderPass attachment #samples\n"
3327 " 5. Framebuffer attachment w/ non-1 mip-levels\n"
3328 " 6. Framebuffer attachment where dimensions don't match\n"
3329 " 7. Framebuffer attachment w/o identity swizzle\n"
3330 " 8. framebuffer dimensions exceed physical device limits\n");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003331
3332 ASSERT_NO_FATAL_FAILURE(InitState());
3333 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3334
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003335 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3336 "vkCreateFramebuffer(): VkFramebufferCreateInfo attachmentCount of 2 "
3337 "does not match attachmentCount of 1 of ");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003338
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003339 // Create a renderPass with a single color attachment
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003340 VkAttachmentReference attach = {};
3341 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
3342 VkSubpassDescription subpass = {};
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003343 subpass.pColorAttachments = &attach;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003344 VkRenderPassCreateInfo rpci = {};
3345 rpci.subpassCount = 1;
3346 rpci.pSubpasses = &subpass;
3347 rpci.attachmentCount = 1;
3348 VkAttachmentDescription attach_desc = {};
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003349 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis77d717c2016-06-22 14:19:19 -06003350 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003351 rpci.pAttachments = &attach_desc;
3352 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3353 VkRenderPass rp;
3354 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3355 ASSERT_VK_SUCCESS(err);
3356
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003357 VkImageView ivs[2];
3358 ivs[0] = m_renderTargets[0]->targetView(VK_FORMAT_B8G8R8A8_UNORM);
3359 ivs[1] = m_renderTargets[0]->targetView(VK_FORMAT_B8G8R8A8_UNORM);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003360 VkFramebufferCreateInfo fb_info = {};
3361 fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
3362 fb_info.pNext = NULL;
3363 fb_info.renderPass = rp;
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003364 // Set mis-matching attachmentCount
3365 fb_info.attachmentCount = 2;
3366 fb_info.pAttachments = ivs;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003367 fb_info.width = 100;
3368 fb_info.height = 100;
3369 fb_info.layers = 1;
3370
3371 VkFramebuffer fb;
3372 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3373
3374 m_errorMonitor->VerifyFound();
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003375 if (err == VK_SUCCESS) {
3376 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3377 }
3378 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003379
3380 // Create a renderPass with a depth-stencil attachment created with
3381 // IMAGE_USAGE_COLOR_ATTACHMENT
3382 // Add our color attachment to pDepthStencilAttachment
3383 subpass.pDepthStencilAttachment = &attach;
3384 subpass.pColorAttachments = NULL;
3385 VkRenderPass rp_ds;
3386 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp_ds);
3387 ASSERT_VK_SUCCESS(err);
3388 // Set correct attachment count, but attachment has COLOR usage bit set
3389 fb_info.attachmentCount = 1;
3390 fb_info.renderPass = rp_ds;
3391
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003392 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " conflicts with the image's IMAGE_USAGE flags ");
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003393 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3394
3395 m_errorMonitor->VerifyFound();
3396 if (err == VK_SUCCESS) {
3397 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3398 }
3399 vkDestroyRenderPass(m_device->device(), rp_ds, NULL);
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003400
3401 // Create new renderpass with alternate attachment format from fb
3402 attach_desc.format = VK_FORMAT_R8G8B8A8_UNORM;
3403 subpass.pDepthStencilAttachment = NULL;
3404 subpass.pColorAttachments = &attach;
3405 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3406 ASSERT_VK_SUCCESS(err);
3407
3408 // Cause error due to mis-matched formats between rp & fb
3409 // rp attachment 0 now has RGBA8 but corresponding fb attach is BGRA8
3410 fb_info.renderPass = rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003411 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3412 " has format of VK_FORMAT_B8G8R8A8_UNORM that does not match ");
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003413 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3414
3415 m_errorMonitor->VerifyFound();
3416 if (err == VK_SUCCESS) {
3417 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3418 }
Tobin Ehlis77d717c2016-06-22 14:19:19 -06003419 vkDestroyRenderPass(m_device->device(), rp, NULL);
3420
3421 // Create new renderpass with alternate sample count from fb
3422 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
3423 attach_desc.samples = VK_SAMPLE_COUNT_4_BIT;
3424 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3425 ASSERT_VK_SUCCESS(err);
3426
3427 // Cause error due to mis-matched sample count between rp & fb
3428 fb_info.renderPass = rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003429 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has VK_SAMPLE_COUNT_1_BIT samples "
3430 "that do not match the "
3431 "VK_SAMPLE_COUNT_4_BIT ");
Tobin Ehlis77d717c2016-06-22 14:19:19 -06003432 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3433
3434 m_errorMonitor->VerifyFound();
3435 if (err == VK_SUCCESS) {
3436 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3437 }
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003438
3439 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003440
3441 // Create a custom imageView with non-1 mip levels
3442 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003443 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 -06003444 ASSERT_TRUE(image.initialized());
3445
3446 VkImageView view;
3447 VkImageViewCreateInfo ivci = {};
3448 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
3449 ivci.image = image.handle();
3450 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
3451 ivci.format = VK_FORMAT_B8G8R8A8_UNORM;
3452 ivci.subresourceRange.layerCount = 1;
3453 ivci.subresourceRange.baseMipLevel = 0;
3454 // Set level count 2 (only 1 is allowed for FB attachment)
3455 ivci.subresourceRange.levelCount = 2;
3456 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3457 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
3458 ASSERT_VK_SUCCESS(err);
3459 // Re-create renderpass to have matching sample count
3460 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
3461 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3462 ASSERT_VK_SUCCESS(err);
3463
3464 fb_info.renderPass = rp;
3465 fb_info.pAttachments = &view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003466 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has mip levelCount of 2 but only ");
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003467 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3468
3469 m_errorMonitor->VerifyFound();
3470 if (err == VK_SUCCESS) {
3471 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3472 }
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003473 vkDestroyImageView(m_device->device(), view, NULL);
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06003474 // Update view to original color buffer and grow FB dimensions too big
3475 fb_info.pAttachments = ivs;
3476 fb_info.height = 1024;
3477 fb_info.width = 1024;
3478 fb_info.layers = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003479 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " Attachment dimensions must be at "
3480 "least as large. ");
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06003481 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3482
3483 m_errorMonitor->VerifyFound();
3484 if (err == VK_SUCCESS) {
3485 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3486 }
Tobin Ehlisb1f303b2016-06-23 08:19:55 -06003487 // Create view attachment with non-identity swizzle
3488 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
3489 ivci.image = image.handle();
3490 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
3491 ivci.format = VK_FORMAT_B8G8R8A8_UNORM;
3492 ivci.subresourceRange.layerCount = 1;
3493 ivci.subresourceRange.baseMipLevel = 0;
3494 ivci.subresourceRange.levelCount = 1;
3495 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3496 ivci.components.r = VK_COMPONENT_SWIZZLE_G;
3497 ivci.components.g = VK_COMPONENT_SWIZZLE_R;
3498 ivci.components.b = VK_COMPONENT_SWIZZLE_A;
3499 ivci.components.a = VK_COMPONENT_SWIZZLE_B;
3500 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
3501 ASSERT_VK_SUCCESS(err);
3502
3503 fb_info.pAttachments = &view;
3504 fb_info.height = 100;
3505 fb_info.width = 100;
3506 fb_info.layers = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003507 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has non-identy swizzle. All "
3508 "framebuffer attachments must have "
3509 "been created with the identity "
3510 "swizzle. ");
Tobin Ehlisb1f303b2016-06-23 08:19:55 -06003511 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3512
3513 m_errorMonitor->VerifyFound();
3514 if (err == VK_SUCCESS) {
3515 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3516 }
3517 vkDestroyImageView(m_device->device(), view, NULL);
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06003518 // Request fb that exceeds max dimensions
3519 // reset attachment to color attachment
3520 fb_info.pAttachments = ivs;
3521 fb_info.width = m_device->props.limits.maxFramebufferWidth + 1;
3522 fb_info.height = m_device->props.limits.maxFramebufferHeight + 1;
3523 fb_info.layers = m_device->props.limits.maxFramebufferLayers + 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003524 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " Requested VkFramebufferCreateInfo "
3525 "dimensions exceed physical device "
3526 "limits. ");
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06003527 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3528
3529 m_errorMonitor->VerifyFound();
3530 if (err == VK_SUCCESS) {
3531 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3532 }
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06003533
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003534 vkDestroyRenderPass(m_device->device(), rp, NULL);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003535}
3536
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003537TEST_F(VkLayerTest, DynamicDepthBiasNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003538 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Depth Bias dynamic "
3539 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003540
Cody Northropc31a84f2016-08-22 10:41:47 -06003541 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003542 // Dynamic depth bias
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003543 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic depth bias state not set for this command buffer");
3544 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthBias);
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003545 m_errorMonitor->VerifyFound();
3546}
3547
3548TEST_F(VkLayerTest, DynamicLineWidthNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003549 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Line Width dynamic "
3550 "state is required but not correctly bound.");
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003551
Cody Northropc31a84f2016-08-22 10:41:47 -06003552 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003553 // Dynamic line width
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003554 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic line width state not set for this command buffer");
3555 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailLineWidth);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003556 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003557}
3558
3559TEST_F(VkLayerTest, DynamicViewportNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003560 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Viewport dynamic "
3561 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003562
Cody Northropc31a84f2016-08-22 10:41:47 -06003563 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003564 // Dynamic viewport state
Mike Weiblen95dd0f92016-10-19 12:28:27 -06003565 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 -06003566 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailViewport);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003567 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003568}
3569
3570TEST_F(VkLayerTest, DynamicScissorNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003571 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Scissor dynamic "
3572 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003573
Cody Northropc31a84f2016-08-22 10:41:47 -06003574 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003575 // Dynamic scissor state
Mike Weiblen95dd0f92016-10-19 12:28:27 -06003576 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 -06003577 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailScissor);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003578 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003579}
3580
Cortd713fe82016-07-27 09:51:27 -07003581TEST_F(VkLayerTest, DynamicBlendConstantsNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003582 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Blend Constants "
3583 "dynamic state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003584
3585 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis21c88352016-05-26 06:15:45 -06003586 // Dynamic blend constant state
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003587 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3588 "Dynamic blend constants state not set for this command buffer");
3589 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailBlend);
Tobin Ehlis21c88352016-05-26 06:15:45 -06003590 m_errorMonitor->VerifyFound();
3591}
3592
3593TEST_F(VkLayerTest, DynamicDepthBoundsNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003594 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Depth Bounds dynamic "
3595 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003596
3597 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis21c88352016-05-26 06:15:45 -06003598 if (!m_device->phy().features().depthBounds) {
3599 printf("Device does not support depthBounds test; skipped.\n");
3600 return;
3601 }
3602 // Dynamic depth bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003603 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3604 "Dynamic depth bounds state not set for this command buffer");
3605 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthBounds);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003606 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003607}
3608
3609TEST_F(VkLayerTest, DynamicStencilReadNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003610 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Stencil Read dynamic "
3611 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003612
3613 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003614 // Dynamic stencil read mask
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003615 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3616 "Dynamic stencil read mask state not set for this command buffer");
3617 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilReadMask);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003618 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003619}
3620
3621TEST_F(VkLayerTest, DynamicStencilWriteNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003622 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Stencil Write dynamic"
3623 " state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003624
3625 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003626 // Dynamic stencil write mask
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003627 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3628 "Dynamic stencil write mask state not set for this command buffer");
3629 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilWriteMask);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003630 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003631}
3632
3633TEST_F(VkLayerTest, DynamicStencilRefNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003634 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Stencil Ref dynamic "
3635 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003636
3637 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003638 // Dynamic stencil reference
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003639 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3640 "Dynamic stencil reference state not set for this command buffer");
3641 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilReference);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003642 m_errorMonitor->VerifyFound();
Tobin Ehlis963a4042015-09-29 08:18:34 -06003643}
3644
Tobin Ehlis379ba3b2016-07-19 11:22:29 -06003645TEST_F(VkLayerTest, IndexBufferNotBound) {
3646 TEST_DESCRIPTION("Run an indexed draw call without an index buffer bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003647
3648 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003649 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3650 "Index buffer object not bound to this command buffer when Indexed ");
3651 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailIndexBuffer);
Tobin Ehlis379ba3b2016-07-19 11:22:29 -06003652 m_errorMonitor->VerifyFound();
3653}
3654
Karl Schultz6addd812016-02-02 17:17:23 -07003655TEST_F(VkLayerTest, CommandBufferTwoSubmits) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003656 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3657 "was begun w/ VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set, but has "
3658 "been submitted");
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003659
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003660 ASSERT_NO_FATAL_FAILURE(InitState());
3661 ASSERT_NO_FATAL_FAILURE(InitViewport());
3662 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3663
Karl Schultz6addd812016-02-02 17:17:23 -07003664 // We luck out b/c by default the framework creates CB w/ the
3665 // VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003666 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003667 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003668 EndCommandBuffer();
3669
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003670 // Bypass framework since it does the waits automatically
3671 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06003672 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08003673 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3674 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003675 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06003676 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07003677 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003678 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003679 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08003680 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06003681 submit_info.pSignalSemaphores = NULL;
3682
Chris Forbes40028e22016-06-13 09:59:34 +12003683 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Karl Schultz6addd812016-02-02 17:17:23 -07003684 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski89cad1a2016-11-11 15:51:31 -07003685 vkQueueWaitIdle(m_device->m_queue);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003686
Karl Schultz6addd812016-02-02 17:17:23 -07003687 // Cause validation error by re-submitting cmd buffer that should only be
3688 // submitted once
Chris Forbes40028e22016-06-13 09:59:34 +12003689 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Lobodzinski89cad1a2016-11-11 15:51:31 -07003690 vkQueueWaitIdle(m_device->m_queue);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003691
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003692 m_errorMonitor->VerifyFound();
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003693}
3694
Karl Schultz6addd812016-02-02 17:17:23 -07003695TEST_F(VkLayerTest, AllocDescriptorFromEmptyPool) {
Tobin Ehlis14cd5852016-11-23 12:52:48 -07003696 TEST_DESCRIPTION("Attempt to allocate more sets and descriptors than descriptor pool has available.");
Karl Schultz6addd812016-02-02 17:17:23 -07003697 VkResult err;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003698
3699 ASSERT_NO_FATAL_FAILURE(InitState());
3700 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003701
Karl Schultz6addd812016-02-02 17:17:23 -07003702 // Create Pool w/ 1 Sampler descriptor, but try to alloc Uniform Buffer
3703 // descriptor from it
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003704 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003705 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
Tobin Ehlis14cd5852016-11-23 12:52:48 -07003706 ds_type_count.descriptorCount = 2;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003707
3708 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003709 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3710 ds_pool_ci.pNext = NULL;
3711 ds_pool_ci.flags = 0;
3712 ds_pool_ci.maxSets = 1;
3713 ds_pool_ci.poolSizeCount = 1;
3714 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003715
3716 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003717 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003718 ASSERT_VK_SUCCESS(err);
3719
Tobin Ehlis14cd5852016-11-23 12:52:48 -07003720 VkDescriptorSetLayoutBinding dsl_binding_samp = {};
3721 dsl_binding_samp.binding = 0;
3722 dsl_binding_samp.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
3723 dsl_binding_samp.descriptorCount = 1;
3724 dsl_binding_samp.stageFlags = VK_SHADER_STAGE_ALL;
3725 dsl_binding_samp.pImmutableSamplers = NULL;
3726
3727 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3728 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3729 ds_layout_ci.pNext = NULL;
3730 ds_layout_ci.bindingCount = 1;
3731 ds_layout_ci.pBindings = &dsl_binding_samp;
3732
3733 VkDescriptorSetLayout ds_layout_samp;
3734 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout_samp);
3735 ASSERT_VK_SUCCESS(err);
3736
3737 // Try to allocate 2 sets when pool only has 1 set
3738 VkDescriptorSet descriptor_sets[2];
3739 VkDescriptorSetLayout set_layouts[2] = {ds_layout_samp, ds_layout_samp};
3740 VkDescriptorSetAllocateInfo alloc_info = {};
3741 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
3742 alloc_info.descriptorSetCount = 2;
3743 alloc_info.descriptorPool = ds_pool;
3744 alloc_info.pSetLayouts = set_layouts;
3745 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00911);
3746 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptor_sets);
3747 m_errorMonitor->VerifyFound();
3748
3749 alloc_info.descriptorSetCount = 1;
3750 // Create layout w/ descriptor type not available in pool
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003751 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003752 dsl_binding.binding = 0;
3753 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3754 dsl_binding.descriptorCount = 1;
3755 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3756 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003757
Karl Schultz6addd812016-02-02 17:17:23 -07003758 ds_layout_ci.bindingCount = 1;
3759 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003760
Tobin Ehlis14cd5852016-11-23 12:52:48 -07003761 VkDescriptorSetLayout ds_layout_ub;
3762 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout_ub);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003763 ASSERT_VK_SUCCESS(err);
3764
Tobin Ehlis14cd5852016-11-23 12:52:48 -07003765 VkDescriptorSet descriptor_set;
Jon Ashburnf19916e2016-01-11 13:12:43 -07003766 alloc_info.descriptorSetCount = 1;
Tobin Ehlis14cd5852016-11-23 12:52:48 -07003767 alloc_info.pSetLayouts = &ds_layout_ub;
3768 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00912);
3769 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003770
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003771 m_errorMonitor->VerifyFound();
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003772
Karl Schultz2825ab92016-12-02 08:23:14 -07003773 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_samp, NULL);
Tobin Ehlis14cd5852016-11-23 12:52:48 -07003774 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_ub, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +08003775 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003776}
3777
Karl Schultz6addd812016-02-02 17:17:23 -07003778TEST_F(VkLayerTest, FreeDescriptorFromOneShotPool) {
3779 VkResult err;
Tobin Ehlise735c692015-10-08 13:13:50 -06003780
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003781 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3782 "It is invalid to call vkFreeDescriptorSets() with a pool created "
3783 "without setting VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003784
Tobin Ehlise735c692015-10-08 13:13:50 -06003785 ASSERT_NO_FATAL_FAILURE(InitState());
3786 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise735c692015-10-08 13:13:50 -06003787
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003788 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003789 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3790 ds_type_count.descriptorCount = 1;
Tobin Ehlise735c692015-10-08 13:13:50 -06003791
3792 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003793 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3794 ds_pool_ci.pNext = NULL;
3795 ds_pool_ci.maxSets = 1;
3796 ds_pool_ci.poolSizeCount = 1;
3797 ds_pool_ci.flags = 0;
3798 // Not specifying VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT means
3799 // app can only call vkResetDescriptorPool on this pool.;
3800 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise735c692015-10-08 13:13:50 -06003801
3802 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003803 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise735c692015-10-08 13:13:50 -06003804 ASSERT_VK_SUCCESS(err);
3805
3806 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003807 dsl_binding.binding = 0;
3808 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3809 dsl_binding.descriptorCount = 1;
3810 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3811 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlise735c692015-10-08 13:13:50 -06003812
3813 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003814 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3815 ds_layout_ci.pNext = NULL;
3816 ds_layout_ci.bindingCount = 1;
3817 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise735c692015-10-08 13:13:50 -06003818
3819 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003820 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise735c692015-10-08 13:13:50 -06003821 ASSERT_VK_SUCCESS(err);
3822
3823 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003824 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08003825 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07003826 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06003827 alloc_info.descriptorPool = ds_pool;
3828 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003829 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise735c692015-10-08 13:13:50 -06003830 ASSERT_VK_SUCCESS(err);
3831
3832 err = vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003833 m_errorMonitor->VerifyFound();
Tobin Ehlise735c692015-10-08 13:13:50 -06003834
Chia-I Wuf7458c52015-10-26 21:10:41 +08003835 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3836 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise735c692015-10-08 13:13:50 -06003837}
3838
Karl Schultz6addd812016-02-02 17:17:23 -07003839TEST_F(VkLayerTest, InvalidDescriptorPool) {
Karl Schultzbdb75952016-04-19 11:36:49 -06003840 // Attempt to clear Descriptor Pool with bad object.
3841 // ObjectTracker should catch this.
Cody Northropc31a84f2016-08-22 10:41:47 -06003842
3843 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultzf78bcdd2016-11-30 12:36:01 -07003844 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00930);
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06003845 uint64_t fake_pool_handle = 0xbaad6001;
3846 VkDescriptorPool bad_pool = reinterpret_cast<VkDescriptorPool &>(fake_pool_handle);
3847 vkResetDescriptorPool(device(), bad_pool, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -06003848 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003849}
3850
Karl Schultzf78bcdd2016-11-30 12:36:01 -07003851TEST_F(VkLayerTest, InvalidDescriptorSet) {
Karl Schultzbdb75952016-04-19 11:36:49 -06003852 // Attempt to bind an invalid Descriptor Set to a valid Command Buffer
3853 // ObjectTracker should catch this.
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003854 // Create a valid cmd buffer
Karl Schultzbdb75952016-04-19 11:36:49 -06003855 // call vkCmdBindDescriptorSets w/ false Descriptor Set
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06003856
3857 uint64_t fake_set_handle = 0xbaad6001;
3858 VkDescriptorSet bad_set = reinterpret_cast<VkDescriptorSet &>(fake_set_handle);
Karl Schultzbdb75952016-04-19 11:36:49 -06003859 VkResult err;
Karl Schultzf78bcdd2016-11-30 12:36:01 -07003860 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00982);
Karl Schultzbdb75952016-04-19 11:36:49 -06003861
3862 ASSERT_NO_FATAL_FAILURE(InitState());
3863
3864 VkDescriptorSetLayoutBinding layout_bindings[1] = {};
3865 layout_bindings[0].binding = 0;
3866 layout_bindings[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3867 layout_bindings[0].descriptorCount = 1;
3868 layout_bindings[0].stageFlags = VK_SHADER_STAGE_VERTEX_BIT;
3869 layout_bindings[0].pImmutableSamplers = NULL;
3870
3871 VkDescriptorSetLayout descriptor_set_layout;
3872 VkDescriptorSetLayoutCreateInfo dslci = {};
3873 dslci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3874 dslci.pNext = NULL;
3875 dslci.bindingCount = 1;
3876 dslci.pBindings = layout_bindings;
3877 err = vkCreateDescriptorSetLayout(device(), &dslci, NULL, &descriptor_set_layout);
Karl Schultz5cb21112016-04-21 17:17:40 -06003878 ASSERT_VK_SUCCESS(err);
Karl Schultzbdb75952016-04-19 11:36:49 -06003879
3880 VkPipelineLayout pipeline_layout;
3881 VkPipelineLayoutCreateInfo plci = {};
3882 plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
3883 plci.pNext = NULL;
3884 plci.setLayoutCount = 1;
3885 plci.pSetLayouts = &descriptor_set_layout;
3886 err = vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout);
Karl Schultz5cb21112016-04-21 17:17:40 -06003887 ASSERT_VK_SUCCESS(err);
Karl Schultzbdb75952016-04-19 11:36:49 -06003888
3889 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003890 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1, &bad_set, 0,
3891 NULL);
Karl Schultzbdb75952016-04-19 11:36:49 -06003892 m_errorMonitor->VerifyFound();
3893 EndCommandBuffer();
3894 vkDestroyPipelineLayout(device(), pipeline_layout, NULL);
3895 vkDestroyDescriptorSetLayout(device(), descriptor_set_layout, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003896}
3897
Karl Schultz6addd812016-02-02 17:17:23 -07003898TEST_F(VkLayerTest, InvalidDescriptorSetLayout) {
Karl Schultzbdb75952016-04-19 11:36:49 -06003899 // Attempt to create a Pipeline Layout with an invalid Descriptor Set Layout.
3900 // ObjectTracker should catch this.
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06003901 uint64_t fake_layout_handle = 0xbaad6001;
3902 VkDescriptorSetLayout bad_layout = reinterpret_cast<VkDescriptorSetLayout &>(fake_layout_handle);
Karl Schultzf78bcdd2016-11-30 12:36:01 -07003903 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00875);
Cody Northropc31a84f2016-08-22 10:41:47 -06003904 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultzbdb75952016-04-19 11:36:49 -06003905 VkPipelineLayout pipeline_layout;
3906 VkPipelineLayoutCreateInfo plci = {};
3907 plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
3908 plci.pNext = NULL;
3909 plci.setLayoutCount = 1;
3910 plci.pSetLayouts = &bad_layout;
3911 vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout);
3912
3913 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003914}
3915
Mark Muellerd4914412016-06-13 17:52:06 -06003916TEST_F(VkLayerTest, WriteDescriptorSetIntegrityCheck) {
3917 TEST_DESCRIPTION("This test verifies some requirements of chapter 13.2.3 of the Vulkan Spec "
3918 "1) A uniform buffer update must have a valid buffer index."
3919 "2) When using an array of descriptors in a single WriteDescriptor,"
3920 " the descriptor types and stageflags must all be the same."
3921 "3) Immutable Sampler state must match across descriptors");
3922
3923 const char *invalid_BufferInfo_ErrorMessage =
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003924 "vkUpdateDescriptorSets: if pDescriptorWrites[0].descriptorType is VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, "
3925 "VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC or "
3926 "VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC, pDescriptorWrites[0].pBufferInfo must not be NULL";
3927 const char *stateFlag_ErrorMessage = "Attempting write update to descriptor set ";
3928 const char *immutable_ErrorMessage = "Attempting write update to descriptor set ";
Mark Muellerd4914412016-06-13 17:52:06 -06003929
Mark Muellerd4914412016-06-13 17:52:06 -06003930 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_BufferInfo_ErrorMessage);
3931
3932 ASSERT_NO_FATAL_FAILURE(InitState());
3933 VkDescriptorPoolSize ds_type_count[4] = {};
3934 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3935 ds_type_count[0].descriptorCount = 1;
Tony Barboure132c5f2016-12-12 11:50:20 -07003936 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLER;
Mark Muellerd4914412016-06-13 17:52:06 -06003937 ds_type_count[1].descriptorCount = 1;
Tony Barboure132c5f2016-12-12 11:50:20 -07003938 ds_type_count[2].type = VK_DESCRIPTOR_TYPE_SAMPLER;
Mark Muellerd4914412016-06-13 17:52:06 -06003939 ds_type_count[2].descriptorCount = 1;
3940 ds_type_count[3].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
3941 ds_type_count[3].descriptorCount = 1;
3942
3943 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3944 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3945 ds_pool_ci.maxSets = 1;
3946 ds_pool_ci.poolSizeCount = sizeof(ds_type_count) / sizeof(VkDescriptorPoolSize);
3947 ds_pool_ci.pPoolSizes = ds_type_count;
3948
3949 VkDescriptorPool ds_pool;
3950 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
3951 ASSERT_VK_SUCCESS(err);
3952
Mark Muellerb9896722016-06-16 09:54:29 -06003953 VkDescriptorSetLayoutBinding layout_binding[3] = {};
Mark Muellerd4914412016-06-13 17:52:06 -06003954 layout_binding[0].binding = 0;
3955 layout_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3956 layout_binding[0].descriptorCount = 1;
3957 layout_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
3958 layout_binding[0].pImmutableSamplers = NULL;
3959
3960 layout_binding[1].binding = 1;
3961 layout_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
3962 layout_binding[1].descriptorCount = 1;
3963 layout_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
3964 layout_binding[1].pImmutableSamplers = NULL;
3965
3966 VkSamplerCreateInfo sampler_ci = {};
3967 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
3968 sampler_ci.pNext = NULL;
3969 sampler_ci.magFilter = VK_FILTER_NEAREST;
3970 sampler_ci.minFilter = VK_FILTER_NEAREST;
3971 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
3972 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3973 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3974 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3975 sampler_ci.mipLodBias = 1.0;
3976 sampler_ci.anisotropyEnable = VK_FALSE;
3977 sampler_ci.maxAnisotropy = 1;
3978 sampler_ci.compareEnable = VK_FALSE;
3979 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
3980 sampler_ci.minLod = 1.0;
3981 sampler_ci.maxLod = 1.0;
3982 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
3983 sampler_ci.unnormalizedCoordinates = VK_FALSE;
3984 VkSampler sampler;
3985
3986 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
3987 ASSERT_VK_SUCCESS(err);
3988
3989 layout_binding[2].binding = 2;
3990 layout_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
3991 layout_binding[2].descriptorCount = 1;
3992 layout_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
3993 layout_binding[2].pImmutableSamplers = static_cast<VkSampler *>(&sampler);
3994
Mark Muellerd4914412016-06-13 17:52:06 -06003995 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3996 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3997 ds_layout_ci.bindingCount = sizeof(layout_binding) / sizeof(VkDescriptorSetLayoutBinding);
3998 ds_layout_ci.pBindings = layout_binding;
3999 VkDescriptorSetLayout ds_layout;
4000 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
4001 ASSERT_VK_SUCCESS(err);
4002
4003 VkDescriptorSetAllocateInfo alloc_info = {};
4004 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
4005 alloc_info.descriptorSetCount = 1;
4006 alloc_info.descriptorPool = ds_pool;
4007 alloc_info.pSetLayouts = &ds_layout;
4008 VkDescriptorSet descriptorSet;
4009 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
4010 ASSERT_VK_SUCCESS(err);
4011
4012 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4013 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4014 pipeline_layout_ci.pNext = NULL;
4015 pipeline_layout_ci.setLayoutCount = 1;
4016 pipeline_layout_ci.pSetLayouts = &ds_layout;
4017
4018 VkPipelineLayout pipeline_layout;
4019 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
4020 ASSERT_VK_SUCCESS(err);
4021
Mark Mueller5c838ce2016-06-16 09:54:29 -06004022 VkWriteDescriptorSet descriptor_write = {};
Mark Muellerd4914412016-06-13 17:52:06 -06004023 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
4024 descriptor_write.dstSet = descriptorSet;
4025 descriptor_write.dstBinding = 0;
4026 descriptor_write.descriptorCount = 1;
4027 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4028
Mark Mueller5c838ce2016-06-16 09:54:29 -06004029 // 1) The uniform buffer is intentionally invalid here
Mark Muellerd4914412016-06-13 17:52:06 -06004030 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4031 m_errorMonitor->VerifyFound();
4032
4033 // Create a buffer to update the descriptor with
4034 uint32_t qfi = 0;
4035 VkBufferCreateInfo buffCI = {};
4036 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
4037 buffCI.size = 1024;
4038 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
4039 buffCI.queueFamilyIndexCount = 1;
4040 buffCI.pQueueFamilyIndices = &qfi;
4041
4042 VkBuffer dyub;
4043 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
4044 ASSERT_VK_SUCCESS(err);
Mark Muellerd4914412016-06-13 17:52:06 -06004045
Tony Barboure132c5f2016-12-12 11:50:20 -07004046 VkDeviceMemory mem;
4047 VkMemoryRequirements mem_reqs;
4048 vkGetBufferMemoryRequirements(m_device->device(), dyub, &mem_reqs);
4049
4050 VkMemoryAllocateInfo mem_alloc_info = {};
4051 mem_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4052 mem_alloc_info.allocationSize = mem_reqs.size;
4053 m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
4054 err = vkAllocateMemory(m_device->device(), &mem_alloc_info, NULL, &mem);
4055 ASSERT_VK_SUCCESS(err);
4056
4057 err = vkBindBufferMemory(m_device->device(), dyub, mem, 0);
4058 ASSERT_VK_SUCCESS(err);
4059
4060 VkDescriptorBufferInfo buffInfo[2] = {};
4061 buffInfo[0].buffer = dyub;
4062 buffInfo[0].offset = 0;
4063 buffInfo[0].range = 1024;
4064 buffInfo[1].buffer = dyub;
4065 buffInfo[1].offset = 0;
4066 buffInfo[1].range = 1024;
4067 descriptor_write.pBufferInfo = buffInfo;
Mark Muellerd4914412016-06-13 17:52:06 -06004068 descriptor_write.descriptorCount = 2;
4069
Mark Mueller5c838ce2016-06-16 09:54:29 -06004070 // 2) The stateFlags don't match between the first and second descriptor
Mark Muellerd4914412016-06-13 17:52:06 -06004071 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, stateFlag_ErrorMessage);
4072 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4073 m_errorMonitor->VerifyFound();
4074
Mark Mueller5c838ce2016-06-16 09:54:29 -06004075 // 3) The second descriptor has a null_ptr pImmutableSamplers and
4076 // the third descriptor contains an immutable sampler
Mark Muellerd4914412016-06-13 17:52:06 -06004077 descriptor_write.dstBinding = 1;
4078 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Mark Mueller5c838ce2016-06-16 09:54:29 -06004079
Mark Mueller5c838ce2016-06-16 09:54:29 -06004080 // Make pImageInfo index non-null to avoid complaints of it missing
4081 VkDescriptorImageInfo imageInfo = {};
4082 imageInfo.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
4083 descriptor_write.pImageInfo = &imageInfo;
Mark Muellerd4914412016-06-13 17:52:06 -06004084 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, immutable_ErrorMessage);
4085 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4086 m_errorMonitor->VerifyFound();
4087
Mark Muellerd4914412016-06-13 17:52:06 -06004088 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tony Barboure132c5f2016-12-12 11:50:20 -07004089 vkFreeMemory(m_device->device(), mem, NULL);
Mark Muellerd4914412016-06-13 17:52:06 -06004090 vkDestroySampler(m_device->device(), sampler, NULL);
4091 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4092 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4093 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
4094}
4095
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004096TEST_F(VkLayerTest, InvalidCmdBufferBufferDestroyed) {
4097 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4098 "due to a buffer dependency being destroyed.");
4099 ASSERT_NO_FATAL_FAILURE(InitState());
4100
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004101 VkBuffer buffer;
4102 VkDeviceMemory mem;
4103 VkMemoryRequirements mem_reqs;
4104
4105 VkBufferCreateInfo buf_info = {};
4106 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes3d5882f2016-09-16 17:37:17 +12004107 buf_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004108 buf_info.size = 256;
4109 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
4110 VkResult err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
4111 ASSERT_VK_SUCCESS(err);
4112
4113 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
4114
4115 VkMemoryAllocateInfo alloc_info = {};
4116 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4117 alloc_info.allocationSize = 256;
4118 bool pass = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004119 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 -06004120 if (!pass) {
4121 vkDestroyBuffer(m_device->device(), buffer, NULL);
4122 return;
4123 }
4124 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
4125 ASSERT_VK_SUCCESS(err);
4126
4127 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
4128 ASSERT_VK_SUCCESS(err);
4129
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004130 m_commandBuffer->BeginCommandBuffer();
Chris Forbes3d5882f2016-09-16 17:37:17 +12004131 vkCmdFillBuffer(m_commandBuffer->GetBufferHandle(), buffer, 0, VK_WHOLE_SIZE, 0);
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004132 m_commandBuffer->EndCommandBuffer();
4133
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004134 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound buffer ");
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004135 // Destroy buffer dependency prior to submit to cause ERROR
4136 vkDestroyBuffer(m_device->device(), buffer, NULL);
4137
4138 VkSubmitInfo submit_info = {};
4139 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4140 submit_info.commandBufferCount = 1;
4141 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4142 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4143
4144 m_errorMonitor->VerifyFound();
4145 vkFreeMemory(m_device->handle(), mem, NULL);
4146}
4147
Tobin Ehlisea413442016-09-28 10:23:59 -06004148TEST_F(VkLayerTest, InvalidCmdBufferBufferViewDestroyed) {
4149 TEST_DESCRIPTION("Delete bufferView bound to cmd buffer, then attempt to submit cmd buffer.");
4150
4151 ASSERT_NO_FATAL_FAILURE(InitState());
4152 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4153
4154 VkDescriptorPoolSize ds_type_count;
4155 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
4156 ds_type_count.descriptorCount = 1;
4157
4158 VkDescriptorPoolCreateInfo ds_pool_ci = {};
4159 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4160 ds_pool_ci.maxSets = 1;
4161 ds_pool_ci.poolSizeCount = 1;
4162 ds_pool_ci.pPoolSizes = &ds_type_count;
4163
4164 VkDescriptorPool ds_pool;
4165 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
4166 ASSERT_VK_SUCCESS(err);
4167
4168 VkDescriptorSetLayoutBinding layout_binding;
4169 layout_binding.binding = 0;
4170 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
4171 layout_binding.descriptorCount = 1;
4172 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
4173 layout_binding.pImmutableSamplers = NULL;
4174
4175 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
4176 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4177 ds_layout_ci.bindingCount = 1;
4178 ds_layout_ci.pBindings = &layout_binding;
4179 VkDescriptorSetLayout ds_layout;
4180 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
4181 ASSERT_VK_SUCCESS(err);
4182
4183 VkDescriptorSetAllocateInfo alloc_info = {};
4184 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
4185 alloc_info.descriptorSetCount = 1;
4186 alloc_info.descriptorPool = ds_pool;
4187 alloc_info.pSetLayouts = &ds_layout;
4188 VkDescriptorSet descriptor_set;
4189 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
4190 ASSERT_VK_SUCCESS(err);
4191
4192 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4193 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4194 pipeline_layout_ci.pNext = NULL;
4195 pipeline_layout_ci.setLayoutCount = 1;
4196 pipeline_layout_ci.pSetLayouts = &ds_layout;
4197
4198 VkPipelineLayout pipeline_layout;
4199 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
4200 ASSERT_VK_SUCCESS(err);
4201
4202 VkBuffer buffer;
4203 uint32_t queue_family_index = 0;
4204 VkBufferCreateInfo buffer_create_info = {};
4205 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
4206 buffer_create_info.size = 1024;
4207 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
4208 buffer_create_info.queueFamilyIndexCount = 1;
4209 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
4210
4211 err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
4212 ASSERT_VK_SUCCESS(err);
4213
4214 VkMemoryRequirements memory_reqs;
4215 VkDeviceMemory buffer_memory;
4216
4217 VkMemoryAllocateInfo memory_info = {};
4218 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4219 memory_info.allocationSize = 0;
4220 memory_info.memoryTypeIndex = 0;
4221
4222 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
4223 memory_info.allocationSize = memory_reqs.size;
4224 bool pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
4225 ASSERT_TRUE(pass);
4226
4227 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
4228 ASSERT_VK_SUCCESS(err);
4229 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
4230 ASSERT_VK_SUCCESS(err);
4231
4232 VkBufferView view;
4233 VkBufferViewCreateInfo bvci = {};
4234 bvci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
4235 bvci.buffer = buffer;
4236 bvci.format = VK_FORMAT_R8_UNORM;
4237 bvci.range = VK_WHOLE_SIZE;
4238
4239 err = vkCreateBufferView(m_device->device(), &bvci, NULL, &view);
4240 ASSERT_VK_SUCCESS(err);
4241
4242 VkWriteDescriptorSet descriptor_write = {};
4243 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
4244 descriptor_write.dstSet = descriptor_set;
4245 descriptor_write.dstBinding = 0;
4246 descriptor_write.descriptorCount = 1;
4247 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
4248 descriptor_write.pTexelBufferView = &view;
4249
4250 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4251
4252 char const *vsSource = "#version 450\n"
4253 "\n"
4254 "out gl_PerVertex { \n"
4255 " vec4 gl_Position;\n"
4256 "};\n"
4257 "void main(){\n"
4258 " gl_Position = vec4(1);\n"
4259 "}\n";
4260 char const *fsSource = "#version 450\n"
4261 "\n"
4262 "layout(set=0, binding=0, r8) uniform imageBuffer s;\n"
4263 "layout(location=0) out vec4 x;\n"
4264 "void main(){\n"
4265 " x = imageLoad(s, 0);\n"
4266 "}\n";
4267 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4268 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
4269 VkPipelineObj pipe(m_device);
4270 pipe.AddShader(&vs);
4271 pipe.AddShader(&fs);
4272 pipe.AddColorAttachment();
4273 pipe.CreateVKPipeline(pipeline_layout, renderPass());
4274
4275 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot submit cmd buffer using deleted buffer view ");
4276 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound buffer view ");
4277
4278 BeginCommandBuffer();
4279 VkViewport viewport = {0, 0, 16, 16, 0, 1};
4280 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
4281 VkRect2D scissor = {{0, 0}, {16, 16}};
4282 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
4283 // Bind pipeline to cmd buffer
4284 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
4285 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
4286 &descriptor_set, 0, nullptr);
4287 Draw(1, 0, 0, 0);
4288 EndCommandBuffer();
4289
4290 // Delete BufferView in order to invalidate cmd buffer
4291 vkDestroyBufferView(m_device->device(), view, NULL);
4292 // Now attempt submit of cmd buffer
4293 VkSubmitInfo submit_info = {};
4294 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4295 submit_info.commandBufferCount = 1;
4296 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4297 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4298 m_errorMonitor->VerifyFound();
4299
4300 // Clean-up
4301 vkDestroyBuffer(m_device->device(), buffer, NULL);
4302 vkFreeMemory(m_device->device(), buffer_memory, NULL);
4303 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4304 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4305 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
4306}
4307
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004308TEST_F(VkLayerTest, InvalidCmdBufferImageDestroyed) {
4309 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4310 "due to an image dependency being destroyed.");
4311 ASSERT_NO_FATAL_FAILURE(InitState());
4312
4313 VkImage image;
4314 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
4315 VkImageCreateInfo image_create_info = {};
4316 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4317 image_create_info.pNext = NULL;
4318 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4319 image_create_info.format = tex_format;
4320 image_create_info.extent.width = 32;
4321 image_create_info.extent.height = 32;
4322 image_create_info.extent.depth = 1;
4323 image_create_info.mipLevels = 1;
4324 image_create_info.arrayLayers = 1;
4325 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
4326 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004327 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004328 image_create_info.flags = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004329 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004330 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004331 // Have to bind memory to image before recording cmd in cmd buffer using it
4332 VkMemoryRequirements mem_reqs;
4333 VkDeviceMemory image_mem;
4334 bool pass;
4335 VkMemoryAllocateInfo mem_alloc = {};
4336 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4337 mem_alloc.pNext = NULL;
4338 mem_alloc.memoryTypeIndex = 0;
4339 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
4340 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004341 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004342 ASSERT_TRUE(pass);
4343 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
4344 ASSERT_VK_SUCCESS(err);
4345 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
4346 ASSERT_VK_SUCCESS(err);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004347
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004348 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlis764d7072016-07-01 12:54:29 -06004349 VkClearColorValue ccv;
4350 ccv.float32[0] = 1.0f;
4351 ccv.float32[1] = 1.0f;
4352 ccv.float32[2] = 1.0f;
4353 ccv.float32[3] = 1.0f;
4354 VkImageSubresourceRange isr = {};
4355 isr.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004356 isr.baseArrayLayer = 0;
4357 isr.baseMipLevel = 0;
Tobin Ehlis764d7072016-07-01 12:54:29 -06004358 isr.layerCount = 1;
4359 isr.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004360 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), image, VK_IMAGE_LAYOUT_GENERAL, &ccv, 1, &isr);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004361 m_commandBuffer->EndCommandBuffer();
4362
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004363 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004364 // Destroy image dependency prior to submit to cause ERROR
4365 vkDestroyImage(m_device->device(), image, NULL);
4366
4367 VkSubmitInfo submit_info = {};
4368 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4369 submit_info.commandBufferCount = 1;
4370 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4371 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4372
4373 m_errorMonitor->VerifyFound();
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004374 vkFreeMemory(m_device->device(), image_mem, nullptr);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004375}
4376
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004377TEST_F(VkLayerTest, InvalidCmdBufferFramebufferImageDestroyed) {
4378 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4379 "due to a framebuffer image dependency being destroyed.");
4380 VkFormatProperties format_properties;
4381 VkResult err = VK_SUCCESS;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004382 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
4383 if (!(format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)) {
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004384 return;
4385 }
4386
4387 ASSERT_NO_FATAL_FAILURE(InitState());
4388 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4389
4390 VkImageCreateInfo image_ci = {};
4391 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4392 image_ci.pNext = NULL;
4393 image_ci.imageType = VK_IMAGE_TYPE_2D;
4394 image_ci.format = VK_FORMAT_B8G8R8A8_UNORM;
4395 image_ci.extent.width = 32;
4396 image_ci.extent.height = 32;
4397 image_ci.extent.depth = 1;
4398 image_ci.mipLevels = 1;
4399 image_ci.arrayLayers = 1;
4400 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
4401 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004402 image_ci.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_SAMPLED_BIT;
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004403 image_ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
4404 image_ci.flags = 0;
4405 VkImage image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004406 ASSERT_VK_SUCCESS(vkCreateImage(m_device->handle(), &image_ci, NULL, &image));
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004407
4408 VkMemoryRequirements memory_reqs;
4409 VkDeviceMemory image_memory;
4410 bool pass;
4411 VkMemoryAllocateInfo memory_info = {};
4412 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4413 memory_info.pNext = NULL;
4414 memory_info.allocationSize = 0;
4415 memory_info.memoryTypeIndex = 0;
4416 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
4417 memory_info.allocationSize = memory_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004418 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004419 ASSERT_TRUE(pass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004420 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004421 ASSERT_VK_SUCCESS(err);
4422 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
4423 ASSERT_VK_SUCCESS(err);
4424
4425 VkImageViewCreateInfo ivci = {
4426 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
4427 nullptr,
4428 0,
4429 image,
4430 VK_IMAGE_VIEW_TYPE_2D,
4431 VK_FORMAT_B8G8R8A8_UNORM,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004432 {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A},
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004433 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
4434 };
4435 VkImageView view;
4436 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
4437 ASSERT_VK_SUCCESS(err);
4438
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004439 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 32, 32, 1};
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004440 VkFramebuffer fb;
4441 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
4442 ASSERT_VK_SUCCESS(err);
4443
4444 // Just use default renderpass with our framebuffer
4445 m_renderPassBeginInfo.framebuffer = fb;
4446 // Create Null cmd buffer for submit
4447 BeginCommandBuffer();
4448 EndCommandBuffer();
4449 // Destroy image attached to framebuffer to invalidate cmd buffer
4450 vkDestroyImage(m_device->device(), image, NULL);
4451 // Now attempt to submit cmd buffer and verify error
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004452 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004453 QueueCommandBuffer(false);
4454 m_errorMonitor->VerifyFound();
4455
4456 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
4457 vkDestroyImageView(m_device->device(), view, nullptr);
4458 vkFreeMemory(m_device->device(), image_memory, nullptr);
4459}
4460
Tobin Ehlisb329f992016-10-12 13:20:29 -06004461TEST_F(VkLayerTest, FramebufferInUseDestroyedSignaled) {
4462 TEST_DESCRIPTION("Delete in-use framebuffer.");
4463 VkFormatProperties format_properties;
4464 VkResult err = VK_SUCCESS;
4465 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
4466
4467 ASSERT_NO_FATAL_FAILURE(InitState());
4468 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4469
4470 VkImageObj image(m_device);
4471 image.init(256, 256, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
4472 ASSERT_TRUE(image.initialized());
4473 VkImageView view = image.targetView(VK_FORMAT_B8G8R8A8_UNORM);
4474
4475 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 256, 256, 1};
4476 VkFramebuffer fb;
4477 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
4478 ASSERT_VK_SUCCESS(err);
4479
4480 // Just use default renderpass with our framebuffer
4481 m_renderPassBeginInfo.framebuffer = fb;
4482 // Create Null cmd buffer for submit
4483 BeginCommandBuffer();
4484 EndCommandBuffer();
4485 // Submit cmd buffer to put it in-flight
4486 VkSubmitInfo submit_info = {};
4487 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4488 submit_info.commandBufferCount = 1;
4489 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4490 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4491 // Destroy framebuffer while in-flight
4492 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete framebuffer 0x");
4493 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4494 m_errorMonitor->VerifyFound();
4495 // Wait for queue to complete so we can safely destroy everything
4496 vkQueueWaitIdle(m_device->m_queue);
4497 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
4498}
4499
Tobin Ehlis88becd72016-09-21 14:33:41 -06004500TEST_F(VkLayerTest, FramebufferImageInUseDestroyedSignaled) {
4501 TEST_DESCRIPTION("Delete in-use image that's child of framebuffer.");
4502 VkFormatProperties format_properties;
4503 VkResult err = VK_SUCCESS;
4504 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
Tobin Ehlis88becd72016-09-21 14:33:41 -06004505
4506 ASSERT_NO_FATAL_FAILURE(InitState());
4507 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4508
4509 VkImageCreateInfo image_ci = {};
4510 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4511 image_ci.pNext = NULL;
4512 image_ci.imageType = VK_IMAGE_TYPE_2D;
4513 image_ci.format = VK_FORMAT_B8G8R8A8_UNORM;
4514 image_ci.extent.width = 256;
4515 image_ci.extent.height = 256;
4516 image_ci.extent.depth = 1;
4517 image_ci.mipLevels = 1;
4518 image_ci.arrayLayers = 1;
4519 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
4520 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
Tobin Ehlisc8ca0312016-09-22 07:30:05 -06004521 image_ci.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Tobin Ehlis88becd72016-09-21 14:33:41 -06004522 image_ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
4523 image_ci.flags = 0;
4524 VkImage image;
4525 ASSERT_VK_SUCCESS(vkCreateImage(m_device->handle(), &image_ci, NULL, &image));
4526
4527 VkMemoryRequirements memory_reqs;
4528 VkDeviceMemory image_memory;
4529 bool pass;
4530 VkMemoryAllocateInfo memory_info = {};
4531 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4532 memory_info.pNext = NULL;
4533 memory_info.allocationSize = 0;
4534 memory_info.memoryTypeIndex = 0;
4535 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
4536 memory_info.allocationSize = memory_reqs.size;
4537 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
4538 ASSERT_TRUE(pass);
4539 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
4540 ASSERT_VK_SUCCESS(err);
4541 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
4542 ASSERT_VK_SUCCESS(err);
4543
4544 VkImageViewCreateInfo ivci = {
4545 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
4546 nullptr,
4547 0,
4548 image,
4549 VK_IMAGE_VIEW_TYPE_2D,
4550 VK_FORMAT_B8G8R8A8_UNORM,
4551 {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A},
4552 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
4553 };
4554 VkImageView view;
4555 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
4556 ASSERT_VK_SUCCESS(err);
4557
4558 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 256, 256, 1};
4559 VkFramebuffer fb;
4560 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
4561 ASSERT_VK_SUCCESS(err);
4562
4563 // Just use default renderpass with our framebuffer
4564 m_renderPassBeginInfo.framebuffer = fb;
4565 // Create Null cmd buffer for submit
4566 BeginCommandBuffer();
4567 EndCommandBuffer();
4568 // Submit cmd buffer to put it (and attached imageView) in-flight
4569 VkSubmitInfo submit_info = {};
4570 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4571 submit_info.commandBufferCount = 1;
4572 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4573 // Submit cmd buffer to put framebuffer and children in-flight
4574 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4575 // Destroy image attached to framebuffer while in-flight
4576 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete image 0x");
4577 vkDestroyImage(m_device->device(), image, NULL);
4578 m_errorMonitor->VerifyFound();
4579 // Wait for queue to complete so we can safely destroy image and other objects
4580 vkQueueWaitIdle(m_device->m_queue);
4581 vkDestroyImage(m_device->device(), image, NULL);
4582 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
4583 vkDestroyImageView(m_device->device(), view, nullptr);
4584 vkFreeMemory(m_device->device(), image_memory, nullptr);
4585}
4586
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06004587TEST_F(VkLayerTest, RenderPassInUseDestroyedSignaled) {
4588 TEST_DESCRIPTION("Delete in-use renderPass.");
4589
4590 ASSERT_NO_FATAL_FAILURE(InitState());
4591 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4592
4593 // Create simple renderpass
4594 VkAttachmentReference attach = {};
4595 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
4596 VkSubpassDescription subpass = {};
4597 subpass.pColorAttachments = &attach;
4598 VkRenderPassCreateInfo rpci = {};
4599 rpci.subpassCount = 1;
4600 rpci.pSubpasses = &subpass;
4601 rpci.attachmentCount = 1;
4602 VkAttachmentDescription attach_desc = {};
4603 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
4604 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
4605 rpci.pAttachments = &attach_desc;
4606 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
4607 VkRenderPass rp;
4608 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
4609 ASSERT_VK_SUCCESS(err);
4610
4611 // Create a pipeline that uses the given renderpass
4612 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4613 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4614
4615 VkPipelineLayout pipeline_layout;
4616 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
4617 ASSERT_VK_SUCCESS(err);
4618
4619 VkPipelineViewportStateCreateInfo vp_state_ci = {};
4620 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
4621 vp_state_ci.viewportCount = 1;
4622 VkViewport vp = {}; // Just need dummy vp to point to
4623 vp_state_ci.pViewports = &vp;
4624 vp_state_ci.scissorCount = 1;
4625 VkRect2D scissors = {}; // Dummy scissors to point to
4626 vp_state_ci.pScissors = &scissors;
4627
4628 VkPipelineShaderStageCreateInfo shaderStages[2];
4629 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
4630
4631 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
4632 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
4633 // but add it to be able to run on more devices
4634 shaderStages[0] = vs.GetStageCreateInfo();
4635 shaderStages[1] = fs.GetStageCreateInfo();
4636
4637 VkPipelineVertexInputStateCreateInfo vi_ci = {};
4638 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
4639
4640 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
4641 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
4642 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
4643
4644 VkPipelineRasterizationStateCreateInfo rs_ci = {};
4645 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
4646 rs_ci.rasterizerDiscardEnable = true;
4647 rs_ci.lineWidth = 1.0f;
4648
4649 VkPipelineColorBlendAttachmentState att = {};
4650 att.blendEnable = VK_FALSE;
4651 att.colorWriteMask = 0xf;
4652
4653 VkPipelineColorBlendStateCreateInfo cb_ci = {};
4654 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
4655 cb_ci.attachmentCount = 1;
4656 cb_ci.pAttachments = &att;
4657
4658 VkGraphicsPipelineCreateInfo gp_ci = {};
4659 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
4660 gp_ci.stageCount = 2;
4661 gp_ci.pStages = shaderStages;
4662 gp_ci.pVertexInputState = &vi_ci;
4663 gp_ci.pInputAssemblyState = &ia_ci;
4664 gp_ci.pViewportState = &vp_state_ci;
4665 gp_ci.pRasterizationState = &rs_ci;
4666 gp_ci.pColorBlendState = &cb_ci;
4667 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
4668 gp_ci.layout = pipeline_layout;
4669 gp_ci.renderPass = rp;
4670
4671 VkPipelineCacheCreateInfo pc_ci = {};
4672 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
4673
4674 VkPipeline pipeline;
4675 VkPipelineCache pipe_cache;
4676 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipe_cache);
4677 ASSERT_VK_SUCCESS(err);
4678
4679 err = vkCreateGraphicsPipelines(m_device->device(), pipe_cache, 1, &gp_ci, NULL, &pipeline);
4680 ASSERT_VK_SUCCESS(err);
4681 // Bind pipeline to cmd buffer, will also bind renderpass
4682 m_commandBuffer->BeginCommandBuffer();
4683 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
4684 m_commandBuffer->EndCommandBuffer();
4685
4686 VkSubmitInfo submit_info = {};
4687 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4688 submit_info.commandBufferCount = 1;
4689 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4690 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4691
4692 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00393);
4693 vkDestroyRenderPass(m_device->device(), rp, nullptr);
4694 m_errorMonitor->VerifyFound();
4695
4696 // Wait for queue to complete so we can safely destroy everything
4697 vkQueueWaitIdle(m_device->m_queue);
4698 vkDestroyRenderPass(m_device->device(), rp, nullptr);
4699 vkDestroyPipeline(m_device->device(), pipeline, nullptr);
4700 vkDestroyPipelineCache(m_device->device(), pipe_cache, nullptr);
4701 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
4702}
4703
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004704TEST_F(VkLayerTest, ImageMemoryNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004705 TEST_DESCRIPTION("Attempt to draw with an image which has not had memory bound to it.");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004706 ASSERT_NO_FATAL_FAILURE(InitState());
4707
4708 VkImage image;
4709 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
4710 VkImageCreateInfo image_create_info = {};
4711 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4712 image_create_info.pNext = NULL;
4713 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4714 image_create_info.format = tex_format;
4715 image_create_info.extent.width = 32;
4716 image_create_info.extent.height = 32;
4717 image_create_info.extent.depth = 1;
4718 image_create_info.mipLevels = 1;
4719 image_create_info.arrayLayers = 1;
4720 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
4721 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004722 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004723 image_create_info.flags = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004724 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004725 ASSERT_VK_SUCCESS(err);
4726 // Have to bind memory to image before recording cmd in cmd buffer using it
4727 VkMemoryRequirements mem_reqs;
4728 VkDeviceMemory image_mem;
4729 bool pass;
4730 VkMemoryAllocateInfo mem_alloc = {};
4731 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4732 mem_alloc.pNext = NULL;
4733 mem_alloc.memoryTypeIndex = 0;
4734 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
4735 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004736 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004737 ASSERT_TRUE(pass);
4738 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
4739 ASSERT_VK_SUCCESS(err);
4740
Tobin Ehlisfed999f2016-09-21 15:09:45 -06004741 // Introduce error, do not call vkBindImageMemory(m_device->device(), image, image_mem, 0);
4742 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06004743 " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004744
4745 m_commandBuffer->BeginCommandBuffer();
4746 VkClearColorValue ccv;
4747 ccv.float32[0] = 1.0f;
4748 ccv.float32[1] = 1.0f;
4749 ccv.float32[2] = 1.0f;
4750 ccv.float32[3] = 1.0f;
4751 VkImageSubresourceRange isr = {};
4752 isr.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
4753 isr.baseArrayLayer = 0;
4754 isr.baseMipLevel = 0;
4755 isr.layerCount = 1;
4756 isr.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004757 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), image, VK_IMAGE_LAYOUT_GENERAL, &ccv, 1, &isr);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004758 m_commandBuffer->EndCommandBuffer();
4759
4760 m_errorMonitor->VerifyFound();
4761 vkDestroyImage(m_device->device(), image, NULL);
4762 vkFreeMemory(m_device->device(), image_mem, nullptr);
4763}
4764
4765TEST_F(VkLayerTest, BufferMemoryNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004766 TEST_DESCRIPTION("Attempt to copy from a buffer which has not had memory bound to it.");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004767 ASSERT_NO_FATAL_FAILURE(InitState());
4768
4769 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004770 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 -06004771 VK_IMAGE_TILING_OPTIMAL, 0);
4772 ASSERT_TRUE(image.initialized());
4773
4774 VkBuffer buffer;
4775 VkDeviceMemory mem;
4776 VkMemoryRequirements mem_reqs;
4777
4778 VkBufferCreateInfo buf_info = {};
4779 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes8d260dd2016-09-16 17:42:42 +12004780 buf_info.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004781 buf_info.size = 256;
4782 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
4783 VkResult err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
4784 ASSERT_VK_SUCCESS(err);
4785
4786 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
4787
4788 VkMemoryAllocateInfo alloc_info = {};
4789 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4790 alloc_info.allocationSize = 256;
4791 bool pass = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004792 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 -06004793 if (!pass) {
4794 vkDestroyBuffer(m_device->device(), buffer, NULL);
4795 return;
4796 }
4797 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
4798 ASSERT_VK_SUCCESS(err);
4799
Tobin Ehlisfed999f2016-09-21 15:09:45 -06004800 // Introduce failure by not calling vkBindBufferMemory(m_device->device(), buffer, mem, 0);
4801 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06004802 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004803 VkBufferImageCopy region = {};
4804 region.bufferRowLength = 128;
4805 region.bufferImageHeight = 128;
4806 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
4807
4808 region.imageSubresource.layerCount = 1;
4809 region.imageExtent.height = 4;
4810 region.imageExtent.width = 4;
4811 region.imageExtent.depth = 1;
4812 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004813 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer, image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
4814 &region);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004815 m_commandBuffer->EndCommandBuffer();
4816
4817 m_errorMonitor->VerifyFound();
4818
4819 vkDestroyBuffer(m_device->device(), buffer, NULL);
4820 vkFreeMemory(m_device->handle(), mem, NULL);
4821}
4822
Tobin Ehlis85940f52016-07-07 16:57:21 -06004823TEST_F(VkLayerTest, InvalidCmdBufferEventDestroyed) {
4824 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4825 "due to an event dependency being destroyed.");
4826 ASSERT_NO_FATAL_FAILURE(InitState());
4827
4828 VkEvent event;
4829 VkEventCreateInfo evci = {};
4830 evci.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
4831 VkResult result = vkCreateEvent(m_device->device(), &evci, NULL, &event);
4832 ASSERT_VK_SUCCESS(result);
4833
4834 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004835 vkCmdSetEvent(m_commandBuffer->GetBufferHandle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Tobin Ehlis85940f52016-07-07 16:57:21 -06004836 m_commandBuffer->EndCommandBuffer();
4837
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004838 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound event ");
Tobin Ehlis85940f52016-07-07 16:57:21 -06004839 // Destroy event dependency prior to submit to cause ERROR
4840 vkDestroyEvent(m_device->device(), event, NULL);
4841
4842 VkSubmitInfo submit_info = {};
4843 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4844 submit_info.commandBufferCount = 1;
4845 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4846 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4847
4848 m_errorMonitor->VerifyFound();
4849}
4850
Tobin Ehlisdbea7552016-07-08 14:33:31 -06004851TEST_F(VkLayerTest, InvalidCmdBufferQueryPoolDestroyed) {
4852 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4853 "due to a query pool dependency being destroyed.");
4854 ASSERT_NO_FATAL_FAILURE(InitState());
4855
4856 VkQueryPool query_pool;
4857 VkQueryPoolCreateInfo qpci{};
4858 qpci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
4859 qpci.queryType = VK_QUERY_TYPE_TIMESTAMP;
4860 qpci.queryCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004861 VkResult result = vkCreateQueryPool(m_device->device(), &qpci, nullptr, &query_pool);
Tobin Ehlisdbea7552016-07-08 14:33:31 -06004862 ASSERT_VK_SUCCESS(result);
4863
4864 m_commandBuffer->BeginCommandBuffer();
4865 vkCmdResetQueryPool(m_commandBuffer->GetBufferHandle(), query_pool, 0, 1);
4866 m_commandBuffer->EndCommandBuffer();
4867
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004868 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound query pool ");
Tobin Ehlisdbea7552016-07-08 14:33:31 -06004869 // Destroy query pool dependency prior to submit to cause ERROR
4870 vkDestroyQueryPool(m_device->device(), query_pool, NULL);
4871
4872 VkSubmitInfo submit_info = {};
4873 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4874 submit_info.commandBufferCount = 1;
4875 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4876 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4877
4878 m_errorMonitor->VerifyFound();
4879}
4880
Tobin Ehlis24130d92016-07-08 15:50:53 -06004881TEST_F(VkLayerTest, InvalidCmdBufferPipelineDestroyed) {
4882 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4883 "due to a pipeline dependency being destroyed.");
4884 ASSERT_NO_FATAL_FAILURE(InitState());
4885 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4886
4887 VkResult err;
4888
4889 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4890 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4891
4892 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004893 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis24130d92016-07-08 15:50:53 -06004894 ASSERT_VK_SUCCESS(err);
4895
4896 VkPipelineViewportStateCreateInfo vp_state_ci = {};
4897 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
4898 vp_state_ci.viewportCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004899 VkViewport vp = {}; // Just need dummy vp to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -06004900 vp_state_ci.pViewports = &vp;
Tobin Ehlis24130d92016-07-08 15:50:53 -06004901 vp_state_ci.scissorCount = 1;
4902 VkRect2D scissors = {}; // Dummy scissors to point to
4903 vp_state_ci.pScissors = &scissors;
Tobin Ehlis24130d92016-07-08 15:50:53 -06004904
4905 VkPipelineShaderStageCreateInfo shaderStages[2];
4906 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
4907
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004908 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
4909 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
4910 // but add it to be able to run on more devices
Tobin Ehlis24130d92016-07-08 15:50:53 -06004911 shaderStages[0] = vs.GetStageCreateInfo();
4912 shaderStages[1] = fs.GetStageCreateInfo();
4913
4914 VkPipelineVertexInputStateCreateInfo vi_ci = {};
4915 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
4916
4917 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
4918 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
4919 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
4920
4921 VkPipelineRasterizationStateCreateInfo rs_ci = {};
4922 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Chris Forbese06ba252016-09-16 17:48:53 +12004923 rs_ci.rasterizerDiscardEnable = true;
4924 rs_ci.lineWidth = 1.0f;
Tobin Ehlis24130d92016-07-08 15:50:53 -06004925
4926 VkPipelineColorBlendAttachmentState att = {};
4927 att.blendEnable = VK_FALSE;
4928 att.colorWriteMask = 0xf;
4929
4930 VkPipelineColorBlendStateCreateInfo cb_ci = {};
4931 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
4932 cb_ci.attachmentCount = 1;
4933 cb_ci.pAttachments = &att;
4934
4935 VkGraphicsPipelineCreateInfo gp_ci = {};
4936 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
4937 gp_ci.stageCount = 2;
4938 gp_ci.pStages = shaderStages;
4939 gp_ci.pVertexInputState = &vi_ci;
4940 gp_ci.pInputAssemblyState = &ia_ci;
4941 gp_ci.pViewportState = &vp_state_ci;
4942 gp_ci.pRasterizationState = &rs_ci;
4943 gp_ci.pColorBlendState = &cb_ci;
Tobin Ehlis24130d92016-07-08 15:50:53 -06004944 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
4945 gp_ci.layout = pipeline_layout;
4946 gp_ci.renderPass = renderPass();
4947
4948 VkPipelineCacheCreateInfo pc_ci = {};
4949 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
4950
4951 VkPipeline pipeline;
4952 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004953 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis24130d92016-07-08 15:50:53 -06004954 ASSERT_VK_SUCCESS(err);
4955
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004956 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis24130d92016-07-08 15:50:53 -06004957 ASSERT_VK_SUCCESS(err);
4958
4959 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004960 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Tobin Ehlis24130d92016-07-08 15:50:53 -06004961 m_commandBuffer->EndCommandBuffer();
4962 // Now destroy pipeline in order to cause error when submitting
4963 vkDestroyPipeline(m_device->device(), pipeline, nullptr);
4964
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004965 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound pipeline ");
Tobin Ehlis24130d92016-07-08 15:50:53 -06004966
4967 VkSubmitInfo submit_info = {};
4968 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4969 submit_info.commandBufferCount = 1;
4970 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4971 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4972
4973 m_errorMonitor->VerifyFound();
4974 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
4975 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4976}
4977
Tobin Ehlis31289162016-08-17 14:57:58 -06004978TEST_F(VkLayerTest, InvalidCmdBufferDescriptorSetBufferDestroyed) {
4979 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4980 "due to a bound descriptor set with a buffer dependency "
4981 "being destroyed.");
4982 ASSERT_NO_FATAL_FAILURE(InitState());
4983 ASSERT_NO_FATAL_FAILURE(InitViewport());
4984 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4985
4986 VkDescriptorPoolSize ds_type_count = {};
4987 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4988 ds_type_count.descriptorCount = 1;
4989
4990 VkDescriptorPoolCreateInfo ds_pool_ci = {};
4991 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4992 ds_pool_ci.pNext = NULL;
4993 ds_pool_ci.maxSets = 1;
4994 ds_pool_ci.poolSizeCount = 1;
4995 ds_pool_ci.pPoolSizes = &ds_type_count;
4996
4997 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004998 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis31289162016-08-17 14:57:58 -06004999 ASSERT_VK_SUCCESS(err);
5000
5001 VkDescriptorSetLayoutBinding dsl_binding = {};
5002 dsl_binding.binding = 0;
5003 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5004 dsl_binding.descriptorCount = 1;
5005 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5006 dsl_binding.pImmutableSamplers = NULL;
5007
5008 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5009 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5010 ds_layout_ci.pNext = NULL;
5011 ds_layout_ci.bindingCount = 1;
5012 ds_layout_ci.pBindings = &dsl_binding;
5013 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005014 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis31289162016-08-17 14:57:58 -06005015 ASSERT_VK_SUCCESS(err);
5016
5017 VkDescriptorSet descriptorSet;
5018 VkDescriptorSetAllocateInfo alloc_info = {};
5019 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
5020 alloc_info.descriptorSetCount = 1;
5021 alloc_info.descriptorPool = ds_pool;
5022 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005023 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis31289162016-08-17 14:57:58 -06005024 ASSERT_VK_SUCCESS(err);
5025
5026 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5027 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5028 pipeline_layout_ci.pNext = NULL;
5029 pipeline_layout_ci.setLayoutCount = 1;
5030 pipeline_layout_ci.pSetLayouts = &ds_layout;
5031
5032 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005033 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis31289162016-08-17 14:57:58 -06005034 ASSERT_VK_SUCCESS(err);
5035
5036 // Create a buffer to update the descriptor with
5037 uint32_t qfi = 0;
5038 VkBufferCreateInfo buffCI = {};
5039 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
5040 buffCI.size = 1024;
5041 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
5042 buffCI.queueFamilyIndexCount = 1;
5043 buffCI.pQueueFamilyIndices = &qfi;
5044
5045 VkBuffer buffer;
5046 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &buffer);
5047 ASSERT_VK_SUCCESS(err);
5048 // Allocate memory and bind to buffer so we can make it to the appropriate
5049 // error
5050 VkMemoryAllocateInfo mem_alloc = {};
5051 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5052 mem_alloc.pNext = NULL;
5053 mem_alloc.allocationSize = 1024;
5054 mem_alloc.memoryTypeIndex = 0;
5055
5056 VkMemoryRequirements memReqs;
5057 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005058 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis31289162016-08-17 14:57:58 -06005059 if (!pass) {
5060 vkDestroyBuffer(m_device->device(), buffer, NULL);
5061 return;
5062 }
5063
5064 VkDeviceMemory mem;
5065 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
5066 ASSERT_VK_SUCCESS(err);
5067 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
5068 ASSERT_VK_SUCCESS(err);
5069 // Correctly update descriptor to avoid "NOT_UPDATED" error
5070 VkDescriptorBufferInfo buffInfo = {};
5071 buffInfo.buffer = buffer;
5072 buffInfo.offset = 0;
5073 buffInfo.range = 1024;
5074
5075 VkWriteDescriptorSet descriptor_write;
5076 memset(&descriptor_write, 0, sizeof(descriptor_write));
5077 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5078 descriptor_write.dstSet = descriptorSet;
5079 descriptor_write.dstBinding = 0;
5080 descriptor_write.descriptorCount = 1;
5081 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5082 descriptor_write.pBufferInfo = &buffInfo;
5083
5084 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5085
5086 // Create PSO to be used for draw-time errors below
5087 char const *vsSource = "#version 450\n"
5088 "\n"
5089 "out gl_PerVertex { \n"
5090 " vec4 gl_Position;\n"
5091 "};\n"
5092 "void main(){\n"
5093 " gl_Position = vec4(1);\n"
5094 "}\n";
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005095 char const *fsSource = "#version 450\n"
5096 "\n"
5097 "layout(location=0) out vec4 x;\n"
5098 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
5099 "void main(){\n"
5100 " x = vec4(bar.y);\n"
5101 "}\n";
Tobin Ehlis31289162016-08-17 14:57:58 -06005102 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5103 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5104 VkPipelineObj pipe(m_device);
5105 pipe.AddShader(&vs);
5106 pipe.AddShader(&fs);
5107 pipe.AddColorAttachment();
5108 pipe.CreateVKPipeline(pipeline_layout, renderPass());
5109
5110 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005111 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5112 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5113 &descriptorSet, 0, NULL);
Tobin Ehlis31289162016-08-17 14:57:58 -06005114 Draw(1, 0, 0, 0);
5115 EndCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005116 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound buffer ");
Tobin Ehlis31289162016-08-17 14:57:58 -06005117 // Destroy buffer should invalidate the cmd buffer, causing error on submit
5118 vkDestroyBuffer(m_device->device(), buffer, NULL);
5119 // Attempt to submit cmd buffer
5120 VkSubmitInfo submit_info = {};
5121 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5122 submit_info.commandBufferCount = 1;
5123 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5124 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5125 m_errorMonitor->VerifyFound();
5126 // Cleanup
5127 vkFreeMemory(m_device->device(), mem, NULL);
5128
5129 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5130 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5131 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5132}
5133
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005134TEST_F(VkLayerTest, InvalidCmdBufferDescriptorSetImageSamplerDestroyed) {
5135 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
5136 "due to a bound descriptor sets with a combined image "
5137 "sampler having their image, sampler, and descriptor set "
5138 "each respectively destroyed and then attempting to "
Mark Mueller917f6bc2016-08-30 10:57:19 -06005139 "submit associated cmd buffers. Attempt to destroy a "
5140 "DescriptorSet that is in use.");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005141 ASSERT_NO_FATAL_FAILURE(InitState());
5142 ASSERT_NO_FATAL_FAILURE(InitViewport());
5143 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5144
5145 VkDescriptorPoolSize ds_type_count = {};
5146 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5147 ds_type_count.descriptorCount = 1;
5148
5149 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5150 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5151 ds_pool_ci.pNext = NULL;
5152 ds_pool_ci.maxSets = 1;
5153 ds_pool_ci.poolSizeCount = 1;
5154 ds_pool_ci.pPoolSizes = &ds_type_count;
5155
5156 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005157 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005158 ASSERT_VK_SUCCESS(err);
5159
5160 VkDescriptorSetLayoutBinding dsl_binding = {};
5161 dsl_binding.binding = 0;
5162 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5163 dsl_binding.descriptorCount = 1;
5164 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5165 dsl_binding.pImmutableSamplers = NULL;
5166
5167 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5168 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5169 ds_layout_ci.pNext = NULL;
5170 ds_layout_ci.bindingCount = 1;
5171 ds_layout_ci.pBindings = &dsl_binding;
5172 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005173 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005174 ASSERT_VK_SUCCESS(err);
5175
5176 VkDescriptorSet descriptorSet;
5177 VkDescriptorSetAllocateInfo alloc_info = {};
5178 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
5179 alloc_info.descriptorSetCount = 1;
5180 alloc_info.descriptorPool = ds_pool;
5181 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005182 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005183 ASSERT_VK_SUCCESS(err);
5184
5185 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5186 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5187 pipeline_layout_ci.pNext = NULL;
5188 pipeline_layout_ci.setLayoutCount = 1;
5189 pipeline_layout_ci.pSetLayouts = &ds_layout;
5190
5191 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005192 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005193 ASSERT_VK_SUCCESS(err);
5194
5195 // Create images to update the descriptor with
5196 VkImage image;
5197 VkImage image2;
5198 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
5199 const int32_t tex_width = 32;
5200 const int32_t tex_height = 32;
5201 VkImageCreateInfo image_create_info = {};
5202 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5203 image_create_info.pNext = NULL;
5204 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5205 image_create_info.format = tex_format;
5206 image_create_info.extent.width = tex_width;
5207 image_create_info.extent.height = tex_height;
5208 image_create_info.extent.depth = 1;
5209 image_create_info.mipLevels = 1;
5210 image_create_info.arrayLayers = 1;
5211 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
5212 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
5213 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
5214 image_create_info.flags = 0;
5215 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
5216 ASSERT_VK_SUCCESS(err);
5217 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image2);
5218 ASSERT_VK_SUCCESS(err);
5219
5220 VkMemoryRequirements memory_reqs;
5221 VkDeviceMemory image_memory;
5222 bool pass;
5223 VkMemoryAllocateInfo memory_info = {};
5224 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5225 memory_info.pNext = NULL;
5226 memory_info.allocationSize = 0;
5227 memory_info.memoryTypeIndex = 0;
5228 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
5229 // Allocate enough memory for both images
5230 memory_info.allocationSize = memory_reqs.size * 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005231 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005232 ASSERT_TRUE(pass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005233 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005234 ASSERT_VK_SUCCESS(err);
5235 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
5236 ASSERT_VK_SUCCESS(err);
5237 // Bind second image to memory right after first image
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005238 err = vkBindImageMemory(m_device->device(), image2, image_memory, memory_reqs.size);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005239 ASSERT_VK_SUCCESS(err);
5240
5241 VkImageViewCreateInfo image_view_create_info = {};
5242 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
5243 image_view_create_info.image = image;
5244 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
5245 image_view_create_info.format = tex_format;
5246 image_view_create_info.subresourceRange.layerCount = 1;
5247 image_view_create_info.subresourceRange.baseMipLevel = 0;
5248 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005249 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005250
5251 VkImageView view;
5252 VkImageView view2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005253 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005254 ASSERT_VK_SUCCESS(err);
5255 image_view_create_info.image = image2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005256 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view2);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005257 ASSERT_VK_SUCCESS(err);
5258 // Create Samplers
5259 VkSamplerCreateInfo sampler_ci = {};
5260 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
5261 sampler_ci.pNext = NULL;
5262 sampler_ci.magFilter = VK_FILTER_NEAREST;
5263 sampler_ci.minFilter = VK_FILTER_NEAREST;
5264 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
5265 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5266 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5267 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5268 sampler_ci.mipLodBias = 1.0;
5269 sampler_ci.anisotropyEnable = VK_FALSE;
5270 sampler_ci.maxAnisotropy = 1;
5271 sampler_ci.compareEnable = VK_FALSE;
5272 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
5273 sampler_ci.minLod = 1.0;
5274 sampler_ci.maxLod = 1.0;
5275 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
5276 sampler_ci.unnormalizedCoordinates = VK_FALSE;
5277 VkSampler sampler;
5278 VkSampler sampler2;
5279 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
5280 ASSERT_VK_SUCCESS(err);
5281 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler2);
5282 ASSERT_VK_SUCCESS(err);
5283 // Update descriptor with image and sampler
5284 VkDescriptorImageInfo img_info = {};
5285 img_info.sampler = sampler;
5286 img_info.imageView = view;
5287 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
5288
5289 VkWriteDescriptorSet descriptor_write;
5290 memset(&descriptor_write, 0, sizeof(descriptor_write));
5291 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5292 descriptor_write.dstSet = descriptorSet;
5293 descriptor_write.dstBinding = 0;
5294 descriptor_write.descriptorCount = 1;
5295 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5296 descriptor_write.pImageInfo = &img_info;
5297
5298 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5299
5300 // Create PSO to be used for draw-time errors below
5301 char const *vsSource = "#version 450\n"
5302 "\n"
5303 "out gl_PerVertex { \n"
5304 " vec4 gl_Position;\n"
5305 "};\n"
5306 "void main(){\n"
5307 " gl_Position = vec4(1);\n"
5308 "}\n";
5309 char const *fsSource = "#version 450\n"
5310 "\n"
5311 "layout(set=0, binding=0) uniform sampler2D s;\n"
5312 "layout(location=0) out vec4 x;\n"
5313 "void main(){\n"
5314 " x = texture(s, vec2(1));\n"
5315 "}\n";
5316 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5317 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5318 VkPipelineObj pipe(m_device);
5319 pipe.AddShader(&vs);
5320 pipe.AddShader(&fs);
5321 pipe.AddColorAttachment();
5322 pipe.CreateVKPipeline(pipeline_layout, renderPass());
5323
5324 // First error case is destroying sampler prior to cmd buffer submission
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005325 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot submit cmd buffer using deleted sampler ");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005326 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005327 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5328 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5329 &descriptorSet, 0, NULL);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005330 Draw(1, 0, 0, 0);
5331 EndCommandBuffer();
5332 // Destroy sampler invalidates the cmd buffer, causing error on submit
5333 vkDestroySampler(m_device->device(), sampler, NULL);
5334 // Attempt to submit cmd buffer
5335 VkSubmitInfo submit_info = {};
5336 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5337 submit_info.commandBufferCount = 1;
5338 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5339 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5340 m_errorMonitor->VerifyFound();
5341 // Now re-update descriptor with valid sampler and delete image
5342 img_info.sampler = sampler2;
5343 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005344 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005345 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005346 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5347 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5348 &descriptorSet, 0, NULL);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005349 Draw(1, 0, 0, 0);
5350 EndCommandBuffer();
5351 // Destroy image invalidates the cmd buffer, causing error on submit
5352 vkDestroyImage(m_device->device(), image, NULL);
5353 // Attempt to submit cmd buffer
5354 submit_info = {};
5355 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5356 submit_info.commandBufferCount = 1;
5357 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5358 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5359 m_errorMonitor->VerifyFound();
5360 // Now update descriptor to be valid, but then free descriptor
5361 img_info.imageView = view2;
5362 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005363 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound descriptor set ");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005364 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005365 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5366 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5367 &descriptorSet, 0, NULL);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005368 Draw(1, 0, 0, 0);
5369 EndCommandBuffer();
5370 // Destroy descriptor set invalidates the cb, causing error on submit
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005371 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot call vkFreeDescriptorSets() on descriptor set 0x");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005372 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
Mark Mueller917f6bc2016-08-30 10:57:19 -06005373 m_errorMonitor->VerifyFound();
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005374 // Attempt to submit cmd buffer
5375 submit_info = {};
5376 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5377 submit_info.commandBufferCount = 1;
5378 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5379 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5380 m_errorMonitor->VerifyFound();
5381 // Cleanup
5382 vkFreeMemory(m_device->device(), image_memory, NULL);
5383 vkDestroySampler(m_device->device(), sampler2, NULL);
5384 vkDestroyImage(m_device->device(), image2, NULL);
5385 vkDestroyImageView(m_device->device(), view, NULL);
5386 vkDestroyImageView(m_device->device(), view2, NULL);
5387 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5388 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5389 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5390}
5391
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06005392TEST_F(VkLayerTest, DescriptorPoolInUseDestroyedSignaled) {
5393 TEST_DESCRIPTION("Delete a DescriptorPool with a DescriptorSet that is in use.");
5394 ASSERT_NO_FATAL_FAILURE(InitState());
5395 ASSERT_NO_FATAL_FAILURE(InitViewport());
5396 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5397
5398 VkDescriptorPoolSize ds_type_count = {};
5399 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5400 ds_type_count.descriptorCount = 1;
5401
5402 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5403 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5404 ds_pool_ci.pNext = NULL;
5405 ds_pool_ci.maxSets = 1;
5406 ds_pool_ci.poolSizeCount = 1;
5407 ds_pool_ci.pPoolSizes = &ds_type_count;
5408
5409 VkDescriptorPool ds_pool;
5410 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
5411 ASSERT_VK_SUCCESS(err);
5412
5413 VkDescriptorSetLayoutBinding dsl_binding = {};
5414 dsl_binding.binding = 0;
5415 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5416 dsl_binding.descriptorCount = 1;
5417 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5418 dsl_binding.pImmutableSamplers = NULL;
5419
5420 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5421 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5422 ds_layout_ci.pNext = NULL;
5423 ds_layout_ci.bindingCount = 1;
5424 ds_layout_ci.pBindings = &dsl_binding;
5425 VkDescriptorSetLayout ds_layout;
5426 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
5427 ASSERT_VK_SUCCESS(err);
5428
5429 VkDescriptorSet descriptor_set;
5430 VkDescriptorSetAllocateInfo alloc_info = {};
5431 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
5432 alloc_info.descriptorSetCount = 1;
5433 alloc_info.descriptorPool = ds_pool;
5434 alloc_info.pSetLayouts = &ds_layout;
5435 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
5436 ASSERT_VK_SUCCESS(err);
5437
5438 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5439 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5440 pipeline_layout_ci.pNext = NULL;
5441 pipeline_layout_ci.setLayoutCount = 1;
5442 pipeline_layout_ci.pSetLayouts = &ds_layout;
5443
5444 VkPipelineLayout pipeline_layout;
5445 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
5446 ASSERT_VK_SUCCESS(err);
5447
5448 // Create image to update the descriptor with
5449 VkImageObj image(m_device);
5450 image.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
5451 ASSERT_TRUE(image.initialized());
5452
5453 VkImageView view = image.targetView(VK_FORMAT_B8G8R8A8_UNORM);
5454 // Create Sampler
5455 VkSamplerCreateInfo sampler_ci = {};
5456 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
5457 sampler_ci.pNext = NULL;
5458 sampler_ci.magFilter = VK_FILTER_NEAREST;
5459 sampler_ci.minFilter = VK_FILTER_NEAREST;
5460 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
5461 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5462 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5463 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5464 sampler_ci.mipLodBias = 1.0;
5465 sampler_ci.anisotropyEnable = VK_FALSE;
5466 sampler_ci.maxAnisotropy = 1;
5467 sampler_ci.compareEnable = VK_FALSE;
5468 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
5469 sampler_ci.minLod = 1.0;
5470 sampler_ci.maxLod = 1.0;
5471 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
5472 sampler_ci.unnormalizedCoordinates = VK_FALSE;
5473 VkSampler sampler;
5474 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
5475 ASSERT_VK_SUCCESS(err);
5476 // Update descriptor with image and sampler
5477 VkDescriptorImageInfo img_info = {};
5478 img_info.sampler = sampler;
5479 img_info.imageView = view;
5480 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
5481
5482 VkWriteDescriptorSet descriptor_write;
5483 memset(&descriptor_write, 0, sizeof(descriptor_write));
5484 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5485 descriptor_write.dstSet = descriptor_set;
5486 descriptor_write.dstBinding = 0;
5487 descriptor_write.descriptorCount = 1;
5488 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5489 descriptor_write.pImageInfo = &img_info;
5490
5491 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5492
5493 // Create PSO to be used for draw-time errors below
5494 char const *vsSource = "#version 450\n"
5495 "\n"
5496 "out gl_PerVertex { \n"
5497 " vec4 gl_Position;\n"
5498 "};\n"
5499 "void main(){\n"
5500 " gl_Position = vec4(1);\n"
5501 "}\n";
5502 char const *fsSource = "#version 450\n"
5503 "\n"
5504 "layout(set=0, binding=0) uniform sampler2D s;\n"
5505 "layout(location=0) out vec4 x;\n"
5506 "void main(){\n"
5507 " x = texture(s, vec2(1));\n"
5508 "}\n";
5509 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5510 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5511 VkPipelineObj pipe(m_device);
5512 pipe.AddShader(&vs);
5513 pipe.AddShader(&fs);
5514 pipe.AddColorAttachment();
5515 pipe.CreateVKPipeline(pipeline_layout, renderPass());
5516
5517 BeginCommandBuffer();
5518 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5519 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5520 &descriptor_set, 0, NULL);
5521 Draw(1, 0, 0, 0);
5522 EndCommandBuffer();
5523 // Submit cmd buffer to put pool in-flight
5524 VkSubmitInfo submit_info = {};
5525 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5526 submit_info.commandBufferCount = 1;
5527 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5528 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5529 // Destroy pool while in-flight, causing error
5530 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete descriptor pool ");
5531 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5532 m_errorMonitor->VerifyFound();
5533 vkQueueWaitIdle(m_device->m_queue);
5534 // Cleanup
5535 vkDestroySampler(m_device->device(), sampler, NULL);
5536 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5537 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5538 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5539}
5540
Tobin Ehlis50a095d2016-09-21 17:32:49 -06005541TEST_F(VkLayerTest, DescriptorImageUpdateNoMemoryBound) {
5542 TEST_DESCRIPTION("Attempt an image descriptor set update where image's bound memory has been freed.");
5543 ASSERT_NO_FATAL_FAILURE(InitState());
5544 ASSERT_NO_FATAL_FAILURE(InitViewport());
5545 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5546
5547 VkDescriptorPoolSize ds_type_count = {};
5548 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5549 ds_type_count.descriptorCount = 1;
5550
5551 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5552 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5553 ds_pool_ci.pNext = NULL;
5554 ds_pool_ci.maxSets = 1;
5555 ds_pool_ci.poolSizeCount = 1;
5556 ds_pool_ci.pPoolSizes = &ds_type_count;
5557
5558 VkDescriptorPool ds_pool;
5559 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
5560 ASSERT_VK_SUCCESS(err);
5561
5562 VkDescriptorSetLayoutBinding dsl_binding = {};
5563 dsl_binding.binding = 0;
5564 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5565 dsl_binding.descriptorCount = 1;
5566 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5567 dsl_binding.pImmutableSamplers = NULL;
5568
5569 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5570 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5571 ds_layout_ci.pNext = NULL;
5572 ds_layout_ci.bindingCount = 1;
5573 ds_layout_ci.pBindings = &dsl_binding;
5574 VkDescriptorSetLayout ds_layout;
5575 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
5576 ASSERT_VK_SUCCESS(err);
5577
5578 VkDescriptorSet descriptorSet;
5579 VkDescriptorSetAllocateInfo alloc_info = {};
5580 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
5581 alloc_info.descriptorSetCount = 1;
5582 alloc_info.descriptorPool = ds_pool;
5583 alloc_info.pSetLayouts = &ds_layout;
5584 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
5585 ASSERT_VK_SUCCESS(err);
5586
5587 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5588 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5589 pipeline_layout_ci.pNext = NULL;
5590 pipeline_layout_ci.setLayoutCount = 1;
5591 pipeline_layout_ci.pSetLayouts = &ds_layout;
5592
5593 VkPipelineLayout pipeline_layout;
5594 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
5595 ASSERT_VK_SUCCESS(err);
5596
5597 // Create images to update the descriptor with
5598 VkImage image;
5599 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
5600 const int32_t tex_width = 32;
5601 const int32_t tex_height = 32;
5602 VkImageCreateInfo image_create_info = {};
5603 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5604 image_create_info.pNext = NULL;
5605 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5606 image_create_info.format = tex_format;
5607 image_create_info.extent.width = tex_width;
5608 image_create_info.extent.height = tex_height;
5609 image_create_info.extent.depth = 1;
5610 image_create_info.mipLevels = 1;
5611 image_create_info.arrayLayers = 1;
5612 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
5613 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
5614 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
5615 image_create_info.flags = 0;
5616 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
5617 ASSERT_VK_SUCCESS(err);
5618 // Initially bind memory to avoid error at bind view time. We'll break binding before update.
5619 VkMemoryRequirements memory_reqs;
5620 VkDeviceMemory image_memory;
5621 bool pass;
5622 VkMemoryAllocateInfo memory_info = {};
5623 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5624 memory_info.pNext = NULL;
5625 memory_info.allocationSize = 0;
5626 memory_info.memoryTypeIndex = 0;
5627 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
5628 // Allocate enough memory for image
5629 memory_info.allocationSize = memory_reqs.size;
5630 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
5631 ASSERT_TRUE(pass);
5632 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
5633 ASSERT_VK_SUCCESS(err);
5634 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
5635 ASSERT_VK_SUCCESS(err);
5636
5637 VkImageViewCreateInfo image_view_create_info = {};
5638 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
5639 image_view_create_info.image = image;
5640 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
5641 image_view_create_info.format = tex_format;
5642 image_view_create_info.subresourceRange.layerCount = 1;
5643 image_view_create_info.subresourceRange.baseMipLevel = 0;
5644 image_view_create_info.subresourceRange.levelCount = 1;
5645 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
5646
5647 VkImageView view;
5648 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
5649 ASSERT_VK_SUCCESS(err);
5650 // Create Samplers
5651 VkSamplerCreateInfo sampler_ci = {};
5652 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
5653 sampler_ci.pNext = NULL;
5654 sampler_ci.magFilter = VK_FILTER_NEAREST;
5655 sampler_ci.minFilter = VK_FILTER_NEAREST;
5656 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
5657 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5658 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5659 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5660 sampler_ci.mipLodBias = 1.0;
5661 sampler_ci.anisotropyEnable = VK_FALSE;
5662 sampler_ci.maxAnisotropy = 1;
5663 sampler_ci.compareEnable = VK_FALSE;
5664 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
5665 sampler_ci.minLod = 1.0;
5666 sampler_ci.maxLod = 1.0;
5667 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
5668 sampler_ci.unnormalizedCoordinates = VK_FALSE;
5669 VkSampler sampler;
5670 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
5671 ASSERT_VK_SUCCESS(err);
5672 // Update descriptor with image and sampler
5673 VkDescriptorImageInfo img_info = {};
5674 img_info.sampler = sampler;
5675 img_info.imageView = view;
5676 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
5677
5678 VkWriteDescriptorSet descriptor_write;
5679 memset(&descriptor_write, 0, sizeof(descriptor_write));
5680 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5681 descriptor_write.dstSet = descriptorSet;
5682 descriptor_write.dstBinding = 0;
5683 descriptor_write.descriptorCount = 1;
5684 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5685 descriptor_write.pImageInfo = &img_info;
5686 // Break memory binding and attempt update
5687 vkFreeMemory(m_device->device(), image_memory, nullptr);
5688 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06005689 " previously bound memory was freed. Memory must not be freed prior to this operation.");
Tobin Ehlis50a095d2016-09-21 17:32:49 -06005690 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
5691 "vkUpdateDescriptorsSets() failed write update validation for Descriptor Set 0x");
5692 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5693 m_errorMonitor->VerifyFound();
5694 // Cleanup
5695 vkDestroyImage(m_device->device(), image, NULL);
5696 vkDestroySampler(m_device->device(), sampler, NULL);
5697 vkDestroyImageView(m_device->device(), view, NULL);
5698 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5699 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5700 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5701}
5702
Karl Schultz6addd812016-02-02 17:17:23 -07005703TEST_F(VkLayerTest, InvalidPipeline) {
Karl Schultzbdb75952016-04-19 11:36:49 -06005704 // Attempt to bind an invalid Pipeline to a valid Command Buffer
5705 // ObjectTracker should catch this.
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06005706 // Create a valid cmd buffer
5707 // call vkCmdBindPipeline w/ false Pipeline
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06005708 uint64_t fake_pipeline_handle = 0xbaad6001;
5709 VkPipeline bad_pipeline = reinterpret_cast<VkPipeline &>(fake_pipeline_handle);
Karl Schultzbdb75952016-04-19 11:36:49 -06005710 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes4dbf70f2016-09-16 17:58:00 +12005711 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5712
Karl Schultzf78bcdd2016-11-30 12:36:01 -07005713 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00601);
Karl Schultzbdb75952016-04-19 11:36:49 -06005714 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005715 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, bad_pipeline);
Karl Schultzbdb75952016-04-19 11:36:49 -06005716 m_errorMonitor->VerifyFound();
Chris Forbes4dbf70f2016-09-16 17:58:00 +12005717
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06005718 // Now issue a draw call with no pipeline bound
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005719 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "At Draw/Dispatch time no valid VkPipeline is bound!");
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06005720 Draw(1, 0, 0, 0);
5721 m_errorMonitor->VerifyFound();
Chris Forbes4dbf70f2016-09-16 17:58:00 +12005722
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06005723 // Finally same check once more but with Dispatch/Compute
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005724 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 +12005725 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle()); // must be outside renderpass
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06005726 vkCmdDispatch(m_commandBuffer->GetBufferHandle(), 0, 0, 0);
5727 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06005728}
5729
Karl Schultz6addd812016-02-02 17:17:23 -07005730TEST_F(VkLayerTest, DescriptorSetNotUpdated) {
Tobin Ehlis5a5f5ef2016-08-17 13:56:55 -06005731 TEST_DESCRIPTION("Bind a descriptor set that hasn't been updated.");
Karl Schultz6addd812016-02-02 17:17:23 -07005732 VkResult err;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005733
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005734 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, " bound but it was never updated. ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005735
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005736 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyan713b2d72015-08-04 10:49:29 -06005737 ASSERT_NO_FATAL_FAILURE(InitViewport());
5738 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08005739 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005740 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5741 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06005742
5743 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005744 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5745 ds_pool_ci.pNext = NULL;
5746 ds_pool_ci.maxSets = 1;
5747 ds_pool_ci.poolSizeCount = 1;
5748 ds_pool_ci.pPoolSizes = &ds_type_count;
Mike Stroyan713b2d72015-08-04 10:49:29 -06005749
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005750 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005751 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005752 ASSERT_VK_SUCCESS(err);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005753
Tony Barboureb254902015-07-15 12:50:33 -06005754 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005755 dsl_binding.binding = 0;
5756 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5757 dsl_binding.descriptorCount = 1;
5758 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5759 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005760
Tony Barboureb254902015-07-15 12:50:33 -06005761 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005762 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5763 ds_layout_ci.pNext = NULL;
5764 ds_layout_ci.bindingCount = 1;
5765 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005766 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005767 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005768 ASSERT_VK_SUCCESS(err);
5769
5770 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005771 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08005772 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07005773 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06005774 alloc_info.descriptorPool = ds_pool;
5775 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005776 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005777 ASSERT_VK_SUCCESS(err);
5778
Tony Barboureb254902015-07-15 12:50:33 -06005779 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005780 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5781 pipeline_layout_ci.pNext = NULL;
5782 pipeline_layout_ci.setLayoutCount = 1;
5783 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005784
5785 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005786 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005787 ASSERT_VK_SUCCESS(err);
5788
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005789 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -06005790 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -07005791 // on more devices
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005792 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005793
Tony Barbourc95e4ac2015-08-04 17:05:26 -06005794 VkPipelineObj pipe(m_device);
5795 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06005796 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -06005797 pipe.AddColorAttachment();
Tony Barbourc95e4ac2015-08-04 17:05:26 -06005798 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06005799
5800 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005801 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5802 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5803 &descriptorSet, 0, NULL);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005804
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005805 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06005806
Chia-I Wuf7458c52015-10-26 21:10:41 +08005807 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5808 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5809 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06005810}
5811
Karl Schultz6addd812016-02-02 17:17:23 -07005812TEST_F(VkLayerTest, InvalidBufferViewObject) {
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005813 // Create a single TEXEL_BUFFER descriptor and send it an invalid bufferView
Karl Schultz6addd812016-02-02 17:17:23 -07005814 VkResult err;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005815
Karl Schultzf78bcdd2016-11-30 12:36:01 -07005816 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00940);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005817
5818 ASSERT_NO_FATAL_FAILURE(InitState());
5819 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005820 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
5821 ds_type_count.descriptorCount = 1;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005822
5823 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005824 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5825 ds_pool_ci.pNext = NULL;
5826 ds_pool_ci.maxSets = 1;
5827 ds_pool_ci.poolSizeCount = 1;
5828 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005829
5830 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005831 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005832 ASSERT_VK_SUCCESS(err);
5833
5834 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005835 dsl_binding.binding = 0;
5836 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
5837 dsl_binding.descriptorCount = 1;
5838 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5839 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005840
5841 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005842 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5843 ds_layout_ci.pNext = NULL;
5844 ds_layout_ci.bindingCount = 1;
5845 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005846 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005847 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005848 ASSERT_VK_SUCCESS(err);
5849
5850 VkDescriptorSet descriptorSet;
5851 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08005852 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07005853 alloc_info.descriptorSetCount = 1;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005854 alloc_info.descriptorPool = ds_pool;
5855 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005856 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005857 ASSERT_VK_SUCCESS(err);
5858
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005859 VkBufferView view = (VkBufferView)((size_t)0xbaadbeef); // invalid bufferView object
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005860 VkWriteDescriptorSet descriptor_write;
5861 memset(&descriptor_write, 0, sizeof(descriptor_write));
5862 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5863 descriptor_write.dstSet = descriptorSet;
5864 descriptor_write.dstBinding = 0;
5865 descriptor_write.descriptorCount = 1;
5866 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
5867 descriptor_write.pTexelBufferView = &view;
5868
5869 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5870
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005871 m_errorMonitor->VerifyFound();
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005872
5873 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5874 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5875}
5876
Mark Youngd339ba32016-05-30 13:28:35 -06005877TEST_F(VkLayerTest, CreateBufferViewNoMemoryBoundToBuffer) {
Tobin Ehlis4ff58172016-09-22 10:52:00 -06005878 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 -06005879
5880 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -06005881 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06005882 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Mark Youngd339ba32016-05-30 13:28:35 -06005883
5884 ASSERT_NO_FATAL_FAILURE(InitState());
5885
5886 // Create a buffer with no bound memory and then attempt to create
5887 // a buffer view.
5888 VkBufferCreateInfo buff_ci = {};
5889 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes4538d242016-09-13 18:13:58 +12005890 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT;
Mark Youngd339ba32016-05-30 13:28:35 -06005891 buff_ci.size = 256;
5892 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
5893 VkBuffer buffer;
5894 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
5895 ASSERT_VK_SUCCESS(err);
5896
5897 VkBufferViewCreateInfo buff_view_ci = {};
5898 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
5899 buff_view_ci.buffer = buffer;
5900 buff_view_ci.format = VK_FORMAT_R8_UNORM;
5901 buff_view_ci.range = VK_WHOLE_SIZE;
5902 VkBufferView buff_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005903 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buff_view);
Mark Youngd339ba32016-05-30 13:28:35 -06005904
5905 m_errorMonitor->VerifyFound();
5906 vkDestroyBuffer(m_device->device(), buffer, NULL);
5907 // If last error is success, it still created the view, so delete it.
5908 if (err == VK_SUCCESS) {
5909 vkDestroyBufferView(m_device->device(), buff_view, NULL);
5910 }
5911}
5912
Karl Schultz6addd812016-02-02 17:17:23 -07005913TEST_F(VkLayerTest, InvalidDynamicOffsetCases) {
5914 // Create a descriptorSet w/ dynamic descriptor and then hit 3 offset error
5915 // cases:
Tobin Ehlisf6585052015-12-17 11:48:42 -07005916 // 1. No dynamicOffset supplied
5917 // 2. Too many dynamicOffsets supplied
5918 // 3. Dynamic offset oversteps buffer being updated
Karl Schultz6addd812016-02-02 17:17:23 -07005919 VkResult err;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005920 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " requires 1 dynamicOffsets, but only "
5921 "0 dynamicOffsets are left in "
5922 "pDynamicOffsets ");
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005923
5924 ASSERT_NO_FATAL_FAILURE(InitState());
5925 ASSERT_NO_FATAL_FAILURE(InitViewport());
5926 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5927
5928 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005929 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
5930 ds_type_count.descriptorCount = 1;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005931
5932 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005933 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5934 ds_pool_ci.pNext = NULL;
5935 ds_pool_ci.maxSets = 1;
5936 ds_pool_ci.poolSizeCount = 1;
5937 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005938
5939 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005940 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005941 ASSERT_VK_SUCCESS(err);
5942
5943 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005944 dsl_binding.binding = 0;
5945 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
5946 dsl_binding.descriptorCount = 1;
5947 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5948 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005949
5950 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005951 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5952 ds_layout_ci.pNext = NULL;
5953 ds_layout_ci.bindingCount = 1;
5954 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005955 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005956 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005957 ASSERT_VK_SUCCESS(err);
5958
5959 VkDescriptorSet descriptorSet;
5960 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08005961 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07005962 alloc_info.descriptorSetCount = 1;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005963 alloc_info.descriptorPool = ds_pool;
5964 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005965 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005966 ASSERT_VK_SUCCESS(err);
5967
5968 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005969 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5970 pipeline_layout_ci.pNext = NULL;
5971 pipeline_layout_ci.setLayoutCount = 1;
5972 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005973
5974 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005975 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005976 ASSERT_VK_SUCCESS(err);
5977
5978 // Create a buffer to update the descriptor with
5979 uint32_t qfi = 0;
5980 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005981 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
5982 buffCI.size = 1024;
5983 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
5984 buffCI.queueFamilyIndexCount = 1;
5985 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005986
5987 VkBuffer dyub;
5988 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
5989 ASSERT_VK_SUCCESS(err);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06005990 // Allocate memory and bind to buffer so we can make it to the appropriate
5991 // error
5992 VkMemoryAllocateInfo mem_alloc = {};
5993 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5994 mem_alloc.pNext = NULL;
5995 mem_alloc.allocationSize = 1024;
Chris Forbesb6116cc2016-05-08 11:39:59 +12005996 mem_alloc.memoryTypeIndex = 0;
5997
5998 VkMemoryRequirements memReqs;
5999 vkGetBufferMemoryRequirements(m_device->device(), dyub, &memReqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006000 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
Chris Forbesb6116cc2016-05-08 11:39:59 +12006001 if (!pass) {
6002 vkDestroyBuffer(m_device->device(), dyub, NULL);
6003 return;
6004 }
6005
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06006006 VkDeviceMemory mem;
6007 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
6008 ASSERT_VK_SUCCESS(err);
6009 err = vkBindBufferMemory(m_device->device(), dyub, mem, 0);
6010 ASSERT_VK_SUCCESS(err);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006011 // Correctly update descriptor to avoid "NOT_UPDATED" error
6012 VkDescriptorBufferInfo buffInfo = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006013 buffInfo.buffer = dyub;
6014 buffInfo.offset = 0;
6015 buffInfo.range = 1024;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006016
6017 VkWriteDescriptorSet descriptor_write;
6018 memset(&descriptor_write, 0, sizeof(descriptor_write));
6019 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6020 descriptor_write.dstSet = descriptorSet;
6021 descriptor_write.dstBinding = 0;
6022 descriptor_write.descriptorCount = 1;
6023 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6024 descriptor_write.pBufferInfo = &buffInfo;
6025
6026 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6027
6028 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006029 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6030 &descriptorSet, 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006031 m_errorMonitor->VerifyFound();
Tobin Ehlisf6585052015-12-17 11:48:42 -07006032 uint32_t pDynOff[2] = {512, 756};
6033 // Now cause error b/c too many dynOffsets in array for # of dyn descriptors
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006034 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6035 "Attempting to bind 1 descriptorSets with 1 dynamic descriptors, but ");
6036 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6037 &descriptorSet, 2, pDynOff);
Chris Forbes7b342802016-04-07 13:20:10 +12006038 m_errorMonitor->VerifyFound();
Tobin Ehlisf6585052015-12-17 11:48:42 -07006039 // Finally cause error due to dynamicOffset being too big
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006040 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " dynamic offset 512 combined with "
6041 "offset 0 and range 1024 that "
6042 "oversteps the buffer size of 1024");
Tobin Ehlisf6585052015-12-17 11:48:42 -07006043 // Create PSO to be used for draw-time errors below
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006044 char const *vsSource = "#version 450\n"
6045 "\n"
6046 "out gl_PerVertex { \n"
6047 " vec4 gl_Position;\n"
6048 "};\n"
6049 "void main(){\n"
6050 " gl_Position = vec4(1);\n"
6051 "}\n";
6052 char const *fsSource = "#version 450\n"
6053 "\n"
6054 "layout(location=0) out vec4 x;\n"
6055 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
6056 "void main(){\n"
6057 " x = vec4(bar.y);\n"
6058 "}\n";
Tobin Ehlisf6585052015-12-17 11:48:42 -07006059 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
6060 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
6061 VkPipelineObj pipe(m_device);
6062 pipe.AddShader(&vs);
6063 pipe.AddShader(&fs);
6064 pipe.AddColorAttachment();
6065 pipe.CreateVKPipeline(pipeline_layout, renderPass());
6066
Rene Lindsayacbf5e62016-12-15 18:47:11 -07006067 VkViewport viewport = {0, 0, 16, 16, 0, 1};
6068 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
6069 VkRect2D scissor = {{0, 0}, {16, 16}};
6070 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
6071
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006072 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07006073 // This update should succeed, but offset size of 512 will overstep buffer
6074 // /w range 1024 & size 1024
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006075 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6076 &descriptorSet, 1, pDynOff);
Tobin Ehlisf6585052015-12-17 11:48:42 -07006077 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006078 m_errorMonitor->VerifyFound();
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006079
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06006080 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tobin Ehlis512098e2016-05-05 09:06:12 -06006081 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06006082
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006083 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06006084 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006085 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6086}
6087
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006088TEST_F(VkLayerTest, DescriptorBufferUpdateNoMemoryBound) {
6089 TEST_DESCRIPTION("Attempt to update a descriptor with a non-sparse buffer "
6090 "that doesn't have memory bound");
6091 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -06006092 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06006093 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Tobin Ehlisfed999f2016-09-21 15:09:45 -06006094 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6095 "vkUpdateDescriptorsSets() failed write update validation for Descriptor Set 0x");
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006096
6097 ASSERT_NO_FATAL_FAILURE(InitState());
6098 ASSERT_NO_FATAL_FAILURE(InitViewport());
6099 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6100
6101 VkDescriptorPoolSize ds_type_count = {};
6102 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6103 ds_type_count.descriptorCount = 1;
6104
6105 VkDescriptorPoolCreateInfo ds_pool_ci = {};
6106 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6107 ds_pool_ci.pNext = NULL;
6108 ds_pool_ci.maxSets = 1;
6109 ds_pool_ci.poolSizeCount = 1;
6110 ds_pool_ci.pPoolSizes = &ds_type_count;
6111
6112 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006113 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006114 ASSERT_VK_SUCCESS(err);
6115
6116 VkDescriptorSetLayoutBinding dsl_binding = {};
6117 dsl_binding.binding = 0;
6118 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6119 dsl_binding.descriptorCount = 1;
6120 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6121 dsl_binding.pImmutableSamplers = NULL;
6122
6123 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
6124 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6125 ds_layout_ci.pNext = NULL;
6126 ds_layout_ci.bindingCount = 1;
6127 ds_layout_ci.pBindings = &dsl_binding;
6128 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006129 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006130 ASSERT_VK_SUCCESS(err);
6131
6132 VkDescriptorSet descriptorSet;
6133 VkDescriptorSetAllocateInfo alloc_info = {};
6134 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
6135 alloc_info.descriptorSetCount = 1;
6136 alloc_info.descriptorPool = ds_pool;
6137 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006138 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006139 ASSERT_VK_SUCCESS(err);
6140
6141 // Create a buffer to update the descriptor with
6142 uint32_t qfi = 0;
6143 VkBufferCreateInfo buffCI = {};
6144 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
6145 buffCI.size = 1024;
6146 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
6147 buffCI.queueFamilyIndexCount = 1;
6148 buffCI.pQueueFamilyIndices = &qfi;
6149
6150 VkBuffer dyub;
6151 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
6152 ASSERT_VK_SUCCESS(err);
6153
6154 // Attempt to update descriptor without binding memory to it
6155 VkDescriptorBufferInfo buffInfo = {};
6156 buffInfo.buffer = dyub;
6157 buffInfo.offset = 0;
6158 buffInfo.range = 1024;
6159
6160 VkWriteDescriptorSet descriptor_write;
6161 memset(&descriptor_write, 0, sizeof(descriptor_write));
6162 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6163 descriptor_write.dstSet = descriptorSet;
6164 descriptor_write.dstBinding = 0;
6165 descriptor_write.descriptorCount = 1;
6166 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6167 descriptor_write.pBufferInfo = &buffInfo;
6168
6169 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6170 m_errorMonitor->VerifyFound();
6171
6172 vkDestroyBuffer(m_device->device(), dyub, NULL);
6173 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6174 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6175}
6176
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006177TEST_F(VkLayerTest, InvalidPushConstants) {
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006178 VkResult err;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006179 ASSERT_NO_FATAL_FAILURE(InitState());
6180 ASSERT_NO_FATAL_FAILURE(InitViewport());
6181 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6182
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006183 VkPipelineLayout pipeline_layout;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006184 VkPushConstantRange pc_range = {};
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006185 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
6186 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6187 pipeline_layout_ci.pushConstantRangeCount = 1;
6188 pipeline_layout_ci.pPushConstantRanges = &pc_range;
6189
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006190 //
6191 // Check for invalid push constant ranges in pipeline layouts.
6192 //
6193 struct PipelineLayoutTestCase {
Karl Schultzc81037d2016-05-12 08:11:23 -06006194 VkPushConstantRange const range;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006195 char const *msg;
6196 };
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006197
Karl Schultzc81037d2016-05-12 08:11:23 -06006198 const uint32_t too_big = m_device->props.limits.maxPushConstantsSize + 0x4;
6199 const std::array<PipelineLayoutTestCase, 10> range_tests = {{
6200 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 0},
6201 "vkCreatePipelineLayout() call has push constants index 0 with "
6202 "size 0."},
6203 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 1},
6204 "vkCreatePipelineLayout() call has push constants index 0 with "
6205 "size 1."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006206 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 1},
Karl Schultzc81037d2016-05-12 08:11:23 -06006207 "vkCreatePipelineLayout() call has push constants index 0 with "
6208 "size 1."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006209 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 0},
Karl Schultzc81037d2016-05-12 08:11:23 -06006210 "vkCreatePipelineLayout() call has push constants index 0 with "
6211 "size 0."},
6212 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
6213 "vkCreatePipelineLayout() call has push constants index 0 with "
6214 "offset 1. Offset must"},
6215 {{VK_SHADER_STAGE_VERTEX_BIT, 0, too_big},
6216 "vkCreatePipelineLayout() call has push constants index 0 "
6217 "with offset "},
6218 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, too_big},
6219 "vkCreatePipelineLayout() call has push constants "
6220 "index 0 with offset "},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006221 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, 4},
Karl Schultzc81037d2016-05-12 08:11:23 -06006222 "vkCreatePipelineLayout() call has push constants index 0 "
6223 "with offset "},
6224 {{VK_SHADER_STAGE_VERTEX_BIT, 0xFFFFFFF0, 0x00000020},
6225 "vkCreatePipelineLayout() call has push "
6226 "constants index 0 with offset "},
6227 {{VK_SHADER_STAGE_VERTEX_BIT, 0x00000020, 0xFFFFFFF0},
6228 "vkCreatePipelineLayout() call has push "
6229 "constants index 0 with offset "},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006230 }};
6231
6232 // Check for invalid offset and size
Karl Schultzc81037d2016-05-12 08:11:23 -06006233 for (const auto &iter : range_tests) {
6234 pc_range = iter.range;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006235 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
6236 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006237 m_errorMonitor->VerifyFound();
6238 if (VK_SUCCESS == err) {
6239 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6240 }
6241 }
6242
6243 // Check for invalid stage flag
6244 pc_range.offset = 0;
6245 pc_range.size = 16;
6246 pc_range.stageFlags = 0;
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006247 m_errorMonitor->SetDesiredFailureMsg(
6248 VK_DEBUG_REPORT_ERROR_BIT_EXT,
6249 "vkCreatePipelineLayout: value of pCreateInfo->pPushConstantRanges[0].stageFlags must not be 0");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006250 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006251 m_errorMonitor->VerifyFound();
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006252 if (VK_SUCCESS == err) {
6253 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6254 }
6255
6256 // Check for overlapping ranges
Karl Schultzc81037d2016-05-12 08:11:23 -06006257 const uint32_t ranges_per_test = 5;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006258 struct OverlappingRangeTestCase {
Karl Schultzc81037d2016-05-12 08:11:23 -06006259 VkPushConstantRange const ranges[ranges_per_test];
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006260 char const *msg;
6261 };
6262
Karl Schultzc81037d2016-05-12 08:11:23 -06006263 const std::array<OverlappingRangeTestCase, 5> overlapping_range_tests = {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006264 {{{{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6265 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6266 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6267 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6268 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006269 "vkCreatePipelineLayout() call has push constants with overlapping ranges:"},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006270 {
6271 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6272 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
6273 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
6274 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
6275 {VK_SHADER_STAGE_VERTEX_BIT, 16, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006276 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 3:[12, 20), 4:[16, 20)",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006277 },
6278 {
6279 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
6280 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
6281 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
6282 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
6283 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006284 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 0:[16, 20), 1:[12, 20)",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006285 },
6286 {
6287 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
6288 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
6289 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
6290 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
6291 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006292 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 0:[16, 20), 3:[12, 20)",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006293 },
6294 {
6295 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
6296 {VK_SHADER_STAGE_VERTEX_BIT, 32, 4},
6297 {VK_SHADER_STAGE_VERTEX_BIT, 4, 96},
6298 {VK_SHADER_STAGE_VERTEX_BIT, 40, 8},
6299 {VK_SHADER_STAGE_VERTEX_BIT, 52, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006300 "vkCreatePipelineLayout() call has push constants with overlapping ranges:",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006301 }}};
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006302
Karl Schultzc81037d2016-05-12 08:11:23 -06006303 for (const auto &iter : overlapping_range_tests) {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006304 pipeline_layout_ci.pPushConstantRanges = iter.ranges;
Karl Schultzc81037d2016-05-12 08:11:23 -06006305 pipeline_layout_ci.pushConstantRangeCount = ranges_per_test;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006306 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, iter.msg);
6307 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006308 m_errorMonitor->VerifyFound();
6309 if (VK_SUCCESS == err) {
6310 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6311 }
6312 }
6313
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006314 //
6315 // CmdPushConstants tests
6316 //
Karl Schultzc81037d2016-05-12 08:11:23 -06006317 const uint8_t dummy_values[100] = {};
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006318
6319 // Check for invalid offset and size and if range is within layout range(s)
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006320 const std::array<PipelineLayoutTestCase, 11> cmd_range_tests = {{
6321 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 0}, "vkCmdPushConstants: parameter size must be greater than 0"},
Karl Schultzc81037d2016-05-12 08:11:23 -06006322 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 1},
6323 "vkCmdPushConstants() call has push constants with size 1. Size "
6324 "must be greater than zero and a multiple of 4."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006325 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 1},
Karl Schultzc81037d2016-05-12 08:11:23 -06006326 "vkCmdPushConstants() call has push constants with size 1. Size "
6327 "must be greater than zero and a multiple of 4."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006328 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
Karl Schultzc81037d2016-05-12 08:11:23 -06006329 "vkCmdPushConstants() call has push constants with offset 1. "
6330 "Offset must be a multiple of 4."},
6331 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
6332 "vkCmdPushConstants() call has push constants with offset 1. "
6333 "Offset must be a multiple of 4."},
6334 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 20},
6335 "vkCmdPushConstants() Push constant range [0, 20) with stageFlags = "
6336 "0x1 not within flag-matching ranges in pipeline layout"},
6337 {{VK_SHADER_STAGE_VERTEX_BIT, 60, 8},
6338 "vkCmdPushConstants() Push constant range [60, 68) with stageFlags = "
6339 "0x1 not within flag-matching ranges in pipeline layout"},
6340 {{VK_SHADER_STAGE_VERTEX_BIT, 76, 8},
6341 "vkCmdPushConstants() Push constant range [76, 84) with stageFlags = "
6342 "0x1 not within flag-matching ranges in pipeline layout"},
6343 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 80},
6344 "vkCmdPushConstants() Push constant range [0, 80) with stageFlags = "
6345 "0x1 not within flag-matching ranges in pipeline layout"},
6346 {{VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, 0, 4},
6347 "vkCmdPushConstants() stageFlags = 0x2 do not match the stageFlags in "
6348 "any of the ranges in pipeline layout"},
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006349 {{VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, 0, 16},
Karl Schultzc81037d2016-05-12 08:11:23 -06006350 "vkCmdPushConstants() stageFlags = 0x3 do not match the stageFlags in "
6351 "any of the ranges in pipeline layout"},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006352 }};
6353
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006354 BeginCommandBuffer();
6355
6356 // Setup ranges: [0,16) [64,80)
Karl Schultzc81037d2016-05-12 08:11:23 -06006357 const VkPushConstantRange pc_range2[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006358 {VK_SHADER_STAGE_VERTEX_BIT, 64, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 0, 16},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006359 };
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006360 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range2) / sizeof(VkPushConstantRange);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006361 pipeline_layout_ci.pPushConstantRanges = pc_range2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006362 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006363 ASSERT_VK_SUCCESS(err);
Karl Schultzc81037d2016-05-12 08:11:23 -06006364 for (const auto &iter : cmd_range_tests) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006365 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
6366 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.range.stageFlags, iter.range.offset,
Karl Schultzc81037d2016-05-12 08:11:23 -06006367 iter.range.size, dummy_values);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006368 m_errorMonitor->VerifyFound();
6369 }
6370
6371 // Check for invalid stage flag
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006372 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdPushConstants: value of stageFlags must not be 0");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006373 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, 0, 0, 16, dummy_values);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006374 m_errorMonitor->VerifyFound();
Karl Schultzc81037d2016-05-12 08:11:23 -06006375 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006376
Karl Schultzc81037d2016-05-12 08:11:23 -06006377 // overlapping range tests with cmd
6378 const std::array<PipelineLayoutTestCase, 3> cmd_overlap_tests = {{
6379 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 20},
6380 "vkCmdPushConstants() Push constant range [0, 20) with stageFlags = "
6381 "0x1 not within flag-matching ranges in pipeline layout"},
6382 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
6383 "vkCmdPushConstants() Push constant range [16, 20) with stageFlags = "
6384 "0x1 not within flag-matching ranges in pipeline layout"},
6385 {{VK_SHADER_STAGE_VERTEX_BIT, 40, 16},
6386 "vkCmdPushConstants() Push constant range [40, 56) with stageFlags = "
6387 "0x1 not within flag-matching ranges in pipeline layout"},
6388 }};
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006389 // Setup ranges: [0,16), [20,36), [36,44), [44,52), [80,92)
Karl Schultzc81037d2016-05-12 08:11:23 -06006390 const VkPushConstantRange pc_range3[] = {
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006391 {VK_SHADER_STAGE_VERTEX_BIT, 20, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 0, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 44, 8},
6392 {VK_SHADER_STAGE_VERTEX_BIT, 80, 12}, {VK_SHADER_STAGE_VERTEX_BIT, 36, 8},
Karl Schultzc81037d2016-05-12 08:11:23 -06006393 };
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006394 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range3) / sizeof(VkPushConstantRange);
Karl Schultzc81037d2016-05-12 08:11:23 -06006395 pipeline_layout_ci.pPushConstantRanges = pc_range3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006396 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzc81037d2016-05-12 08:11:23 -06006397 ASSERT_VK_SUCCESS(err);
Karl Schultzc81037d2016-05-12 08:11:23 -06006398 for (const auto &iter : cmd_overlap_tests) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006399 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
6400 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.range.stageFlags, iter.range.offset,
Karl Schultzc81037d2016-05-12 08:11:23 -06006401 iter.range.size, dummy_values);
6402 m_errorMonitor->VerifyFound();
6403 }
Karl Schultzc81037d2016-05-12 08:11:23 -06006404 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6405
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006406 EndCommandBuffer();
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006407}
6408
Karl Schultz6addd812016-02-02 17:17:23 -07006409TEST_F(VkLayerTest, DescriptorSetCompatibility) {
Tobin Ehlis559c6382015-11-05 09:52:49 -07006410 // Test various desriptorSet errors with bad binding combinations
Karl Schultz6addd812016-02-02 17:17:23 -07006411 VkResult err;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006412
6413 ASSERT_NO_FATAL_FAILURE(InitState());
6414 ASSERT_NO_FATAL_FAILURE(InitViewport());
6415 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6416
Mike Stroyanb8a61002016-06-20 16:00:28 -06006417 const VkFormat tex_format = VK_FORMAT_R8G8B8A8_UNORM;
6418 VkImageTiling tiling;
6419 VkFormatProperties format_properties;
6420 vkGetPhysicalDeviceFormatProperties(gpu(), tex_format, &format_properties);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006421 if (format_properties.linearTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
Mike Stroyanb8a61002016-06-20 16:00:28 -06006422 tiling = VK_IMAGE_TILING_LINEAR;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006423 } else if (format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
Mike Stroyanb8a61002016-06-20 16:00:28 -06006424 tiling = VK_IMAGE_TILING_OPTIMAL;
6425 } else {
6426 printf("Device does not support VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT; "
6427 "skipped.\n");
6428 return;
6429 }
6430
Tobin Ehlis559c6382015-11-05 09:52:49 -07006431 static const uint32_t NUM_DESCRIPTOR_TYPES = 5;
6432 VkDescriptorPoolSize ds_type_count[NUM_DESCRIPTOR_TYPES] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006433 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6434 ds_type_count[0].descriptorCount = 10;
6435 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
6436 ds_type_count[1].descriptorCount = 2;
6437 ds_type_count[2].type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
6438 ds_type_count[2].descriptorCount = 2;
6439 ds_type_count[3].type = VK_DESCRIPTOR_TYPE_SAMPLER;
6440 ds_type_count[3].descriptorCount = 5;
6441 // TODO : LunarG ILO driver currently asserts in desc.c w/ INPUT_ATTACHMENT
6442 // type
6443 // ds_type_count[4].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
6444 ds_type_count[4].type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
6445 ds_type_count[4].descriptorCount = 2;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006446
6447 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006448 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6449 ds_pool_ci.pNext = NULL;
6450 ds_pool_ci.maxSets = 5;
6451 ds_pool_ci.poolSizeCount = NUM_DESCRIPTOR_TYPES;
6452 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006453
6454 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006455 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006456 ASSERT_VK_SUCCESS(err);
6457
6458 static const uint32_t MAX_DS_TYPES_IN_LAYOUT = 2;
6459 VkDescriptorSetLayoutBinding dsl_binding[MAX_DS_TYPES_IN_LAYOUT] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006460 dsl_binding[0].binding = 0;
6461 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6462 dsl_binding[0].descriptorCount = 5;
6463 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
6464 dsl_binding[0].pImmutableSamplers = NULL;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006465
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006466 // Create layout identical to set0 layout but w/ different stageFlags
6467 VkDescriptorSetLayoutBinding dsl_fs_stage_only = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006468 dsl_fs_stage_only.binding = 0;
6469 dsl_fs_stage_only.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6470 dsl_fs_stage_only.descriptorCount = 5;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006471 dsl_fs_stage_only.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT; // Different stageFlags to cause error at
6472 // bind time
Karl Schultz6addd812016-02-02 17:17:23 -07006473 dsl_fs_stage_only.pImmutableSamplers = NULL;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006474 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006475 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6476 ds_layout_ci.pNext = NULL;
6477 ds_layout_ci.bindingCount = 1;
6478 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006479 static const uint32_t NUM_LAYOUTS = 4;
6480 VkDescriptorSetLayout ds_layout[NUM_LAYOUTS] = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006481 VkDescriptorSetLayout ds_layout_fs_only = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006482 // Create 4 unique layouts for full pipelineLayout, and 1 special fs-only
6483 // layout for error case
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006484 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[0]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006485 ASSERT_VK_SUCCESS(err);
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07006486 ds_layout_ci.pBindings = &dsl_fs_stage_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006487 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006488 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006489 dsl_binding[0].binding = 0;
6490 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006491 dsl_binding[0].descriptorCount = 2;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07006492 dsl_binding[1].binding = 1;
6493 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
6494 dsl_binding[1].descriptorCount = 2;
6495 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
6496 dsl_binding[1].pImmutableSamplers = NULL;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07006497 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006498 ds_layout_ci.bindingCount = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006499 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[1]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006500 ASSERT_VK_SUCCESS(err);
6501 dsl_binding[0].binding = 0;
6502 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006503 dsl_binding[0].descriptorCount = 5;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006504 ds_layout_ci.bindingCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006505 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[2]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006506 ASSERT_VK_SUCCESS(err);
6507 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006508 dsl_binding[0].descriptorCount = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006509 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[3]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006510 ASSERT_VK_SUCCESS(err);
6511
6512 static const uint32_t NUM_SETS = 4;
6513 VkDescriptorSet descriptorSet[NUM_SETS] = {};
6514 VkDescriptorSetAllocateInfo alloc_info = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006515 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006516 alloc_info.descriptorSetCount = NUM_LAYOUTS;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006517 alloc_info.descriptorPool = ds_pool;
6518 alloc_info.pSetLayouts = ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006519 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptorSet);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006520 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006521 VkDescriptorSet ds0_fs_only = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07006522 alloc_info.descriptorSetCount = 1;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006523 alloc_info.pSetLayouts = &ds_layout_fs_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006524 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &ds0_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006525 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006526
6527 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006528 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6529 pipeline_layout_ci.pNext = NULL;
6530 pipeline_layout_ci.setLayoutCount = NUM_LAYOUTS;
6531 pipeline_layout_ci.pSetLayouts = ds_layout;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006532
6533 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006534 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006535 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006536 // Create pipelineLayout with only one setLayout
6537 pipeline_layout_ci.setLayoutCount = 1;
6538 VkPipelineLayout single_pipe_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006539 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &single_pipe_layout);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006540 ASSERT_VK_SUCCESS(err);
6541 // Create pipelineLayout with 2 descriptor setLayout at index 0
6542 pipeline_layout_ci.pSetLayouts = &ds_layout[3];
6543 VkPipelineLayout pipe_layout_one_desc;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006544 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_one_desc);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006545 ASSERT_VK_SUCCESS(err);
6546 // Create pipelineLayout with 5 SAMPLER descriptor setLayout at index 0
6547 pipeline_layout_ci.pSetLayouts = &ds_layout[2];
6548 VkPipelineLayout pipe_layout_five_samp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006549 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_five_samp);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006550 ASSERT_VK_SUCCESS(err);
6551 // Create pipelineLayout with UB type, but stageFlags for FS only
6552 pipeline_layout_ci.pSetLayouts = &ds_layout_fs_only;
6553 VkPipelineLayout pipe_layout_fs_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006554 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006555 ASSERT_VK_SUCCESS(err);
6556 // Create pipelineLayout w/ incompatible set0 layout, but set1 is fine
6557 VkDescriptorSetLayout pl_bad_s0[2] = {};
6558 pl_bad_s0[0] = ds_layout_fs_only;
6559 pl_bad_s0[1] = ds_layout[1];
6560 pipeline_layout_ci.setLayoutCount = 2;
6561 pipeline_layout_ci.pSetLayouts = pl_bad_s0;
6562 VkPipelineLayout pipe_layout_bad_set0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006563 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_bad_set0);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006564 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006565
6566 // Create a buffer to update the descriptor with
6567 uint32_t qfi = 0;
6568 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006569 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
6570 buffCI.size = 1024;
6571 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
6572 buffCI.queueFamilyIndexCount = 1;
6573 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006574
6575 VkBuffer dyub;
6576 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
6577 ASSERT_VK_SUCCESS(err);
6578 // Correctly update descriptor to avoid "NOT_UPDATED" error
6579 static const uint32_t NUM_BUFFS = 5;
6580 VkDescriptorBufferInfo buffInfo[NUM_BUFFS] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006581 for (uint32_t i = 0; i < NUM_BUFFS; ++i) {
Tobin Ehlis559c6382015-11-05 09:52:49 -07006582 buffInfo[i].buffer = dyub;
6583 buffInfo[i].offset = 0;
6584 buffInfo[i].range = 1024;
6585 }
Karl Schultz6addd812016-02-02 17:17:23 -07006586 VkImage image;
Karl Schultz6addd812016-02-02 17:17:23 -07006587 const int32_t tex_width = 32;
6588 const int32_t tex_height = 32;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006589 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006590 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
6591 image_create_info.pNext = NULL;
6592 image_create_info.imageType = VK_IMAGE_TYPE_2D;
6593 image_create_info.format = tex_format;
6594 image_create_info.extent.width = tex_width;
6595 image_create_info.extent.height = tex_height;
6596 image_create_info.extent.depth = 1;
6597 image_create_info.mipLevels = 1;
6598 image_create_info.arrayLayers = 1;
6599 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyanb8a61002016-06-20 16:00:28 -06006600 image_create_info.tiling = tiling;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006601 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_STORAGE_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -07006602 image_create_info.flags = 0;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006603 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
6604 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006605
Karl Schultz6addd812016-02-02 17:17:23 -07006606 VkMemoryRequirements memReqs;
6607 VkDeviceMemory imageMem;
6608 bool pass;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07006609 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006610 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
6611 memAlloc.pNext = NULL;
6612 memAlloc.allocationSize = 0;
6613 memAlloc.memoryTypeIndex = 0;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07006614 vkGetImageMemoryRequirements(m_device->device(), image, &memReqs);
6615 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006616 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07006617 ASSERT_TRUE(pass);
6618 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &imageMem);
6619 ASSERT_VK_SUCCESS(err);
6620 err = vkBindImageMemory(m_device->device(), image, imageMem, 0);
6621 ASSERT_VK_SUCCESS(err);
6622
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006623 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006624 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
6625 image_view_create_info.image = image;
6626 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
6627 image_view_create_info.format = tex_format;
6628 image_view_create_info.subresourceRange.layerCount = 1;
6629 image_view_create_info.subresourceRange.baseMipLevel = 0;
6630 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006631 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006632
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006633 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006634 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006635 ASSERT_VK_SUCCESS(err);
Tobin Ehlis991d45a2016-01-06 08:48:41 -07006636 VkDescriptorImageInfo imageInfo[4] = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006637 imageInfo[0].imageView = view;
6638 imageInfo[0].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
6639 imageInfo[1].imageView = view;
6640 imageInfo[1].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
Tobin Ehlis991d45a2016-01-06 08:48:41 -07006641 imageInfo[2].imageView = view;
Tobin Ehlisa1fccbc2016-10-10 14:54:43 -06006642 imageInfo[2].imageLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis991d45a2016-01-06 08:48:41 -07006643 imageInfo[3].imageView = view;
Tobin Ehlisa1fccbc2016-10-10 14:54:43 -06006644 imageInfo[3].imageLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006645
6646 static const uint32_t NUM_SET_UPDATES = 3;
6647 VkWriteDescriptorSet descriptor_write[NUM_SET_UPDATES] = {};
6648 descriptor_write[0].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6649 descriptor_write[0].dstSet = descriptorSet[0];
6650 descriptor_write[0].dstBinding = 0;
6651 descriptor_write[0].descriptorCount = 5;
6652 descriptor_write[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6653 descriptor_write[0].pBufferInfo = buffInfo;
6654 descriptor_write[1].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6655 descriptor_write[1].dstSet = descriptorSet[1];
6656 descriptor_write[1].dstBinding = 0;
6657 descriptor_write[1].descriptorCount = 2;
6658 descriptor_write[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
6659 descriptor_write[1].pImageInfo = imageInfo;
6660 descriptor_write[2].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6661 descriptor_write[2].dstSet = descriptorSet[1];
6662 descriptor_write[2].dstBinding = 1;
6663 descriptor_write[2].descriptorCount = 2;
6664 descriptor_write[2].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
Tobin Ehlis991d45a2016-01-06 08:48:41 -07006665 descriptor_write[2].pImageInfo = &imageInfo[2];
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006666
6667 vkUpdateDescriptorSets(m_device->device(), 3, descriptor_write, 0, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006668
Tobin Ehlis88452832015-12-03 09:40:56 -07006669 // Create PSO to be used for draw-time errors below
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006670 char const *vsSource = "#version 450\n"
6671 "\n"
6672 "out gl_PerVertex {\n"
6673 " vec4 gl_Position;\n"
6674 "};\n"
6675 "void main(){\n"
6676 " gl_Position = vec4(1);\n"
6677 "}\n";
6678 char const *fsSource = "#version 450\n"
6679 "\n"
6680 "layout(location=0) out vec4 x;\n"
6681 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
6682 "void main(){\n"
6683 " x = vec4(bar.y);\n"
6684 "}\n";
Tobin Ehlis88452832015-12-03 09:40:56 -07006685 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
6686 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006687 VkPipelineObj pipe(m_device);
6688 pipe.AddShader(&vs);
6689 pipe.AddShader(&fs);
Tobin Ehlis88452832015-12-03 09:40:56 -07006690 pipe.AddColorAttachment();
6691 pipe.CreateVKPipeline(pipe_layout_fs_only, renderPass());
Tobin Ehlis559c6382015-11-05 09:52:49 -07006692
6693 BeginCommandBuffer();
Tobin Ehlis88452832015-12-03 09:40:56 -07006694
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006695 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07006696 // NOTE : I believe LunarG ilo driver has bug (LX#189) that requires binding
6697 // of PSO
6698 // here before binding DSs. Otherwise we assert in cmd_copy_dset_data() of
6699 // cmd_pipeline.c
6700 // due to the fact that cmd_alloc_dset_data() has not been called in
6701 // cmd_bind_graphics_pipeline()
6702 // TODO : Want to cause various binding incompatibility issues here to test
6703 // DrawState
Tobin Ehlis559c6382015-11-05 09:52:49 -07006704 // First cause various verify_layout_compatibility() fails
6705 // Second disturb early and late sets and verify INFO msgs
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006706 // verify_set_layout_compatibility fail cases:
6707 // 1. invalid VkPipelineLayout (layout) passed into vkCmdBindDescriptorSets
Karl Schultzf78bcdd2016-11-30 12:36:01 -07006708 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00981);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006709 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS,
6710 (VkPipelineLayout)((size_t)0xbaadb1be), 0, 1, &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006711 m_errorMonitor->VerifyFound();
6712
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006713 // 2. layoutIndex exceeds # of layouts in layout
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006714 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " attempting to bind set to index 1");
6715 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, single_pipe_layout, 0, 2,
6716 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006717 m_errorMonitor->VerifyFound();
6718
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006719 vkDestroyPipelineLayout(m_device->device(), single_pipe_layout, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07006720 // 3. Pipeline setLayout[0] has 2 descriptors, but set being bound has 5
6721 // descriptors
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006722 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has 2 descriptors, but DescriptorSetLayout ");
6723 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_one_desc, 0, 1,
6724 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006725 m_errorMonitor->VerifyFound();
6726
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006727 vkDestroyPipelineLayout(m_device->device(), pipe_layout_one_desc, NULL);
6728 // 4. same # of descriptors but mismatch in type
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006729 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is type 'VK_DESCRIPTOR_TYPE_SAMPLER' but binding ");
6730 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_five_samp, 0, 1,
6731 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006732 m_errorMonitor->VerifyFound();
6733
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006734 vkDestroyPipelineLayout(m_device->device(), pipe_layout_five_samp, NULL);
6735 // 5. same # of descriptors but mismatch in stageFlags
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006736 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6737 " has stageFlags 16 but binding 0 for DescriptorSetLayout ");
6738 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_fs_only, 0, 1,
6739 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006740 m_errorMonitor->VerifyFound();
6741
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006742 // Cause INFO messages due to disturbing previously bound Sets
6743 // First bind sets 0 & 1
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006744 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
6745 &descriptorSet[0], 0, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006746 // 1. Disturb bound set0 by re-binding set1 w/ updated pipelineLayout
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006747 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, " previously bound as set #0 was disturbed ");
6748 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_bad_set0, 1, 1,
6749 &descriptorSet[1], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006750 m_errorMonitor->VerifyFound();
6751
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006752 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
6753 &descriptorSet[0], 0, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006754 // 2. Disturb set after last bound set
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006755 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, " newly bound as set #0 so set #1 and "
6756 "any subsequent sets were disturbed ");
6757 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_fs_only, 0, 1,
6758 &ds0_fs_only, 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006759 m_errorMonitor->VerifyFound();
6760
Tobin Ehlis10fad692016-07-07 12:00:36 -06006761 // Now that we're done actively using the pipelineLayout that gfx pipeline
6762 // was created with, we should be able to delete it. Do that now to verify
6763 // that validation obeys pipelineLayout lifetime
6764 vkDestroyPipelineLayout(m_device->device(), pipe_layout_fs_only, NULL);
6765
Tobin Ehlis88452832015-12-03 09:40:56 -07006766 // Cause draw-time errors due to PSO incompatibilities
Karl Schultz6addd812016-02-02 17:17:23 -07006767 // 1. Error due to not binding required set (we actually use same code as
6768 // above to disturb set0)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006769 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
6770 &descriptorSet[0], 0, NULL);
6771 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_bad_set0, 1, 1,
6772 &descriptorSet[1], 0, NULL);
6773 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 -07006774 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006775 m_errorMonitor->VerifyFound();
6776
Tobin Ehlis991d45a2016-01-06 08:48:41 -07006777 vkDestroyPipelineLayout(m_device->device(), pipe_layout_bad_set0, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07006778 // 2. Error due to bound set not being compatible with PSO's
6779 // VkPipelineLayout (diff stageFlags in this case)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006780 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
6781 &descriptorSet[0], 0, NULL);
6782 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " bound as set #0 is not compatible with ");
Tobin Ehlis88452832015-12-03 09:40:56 -07006783 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006784 m_errorMonitor->VerifyFound();
6785
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006786 // Remaining clean-up
Karl Schultz6addd812016-02-02 17:17:23 -07006787 for (uint32_t i = 0; i < NUM_LAYOUTS; ++i) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006788 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout[i], NULL);
6789 }
6790 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_fs_only, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006791 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006792 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6793 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06006794 vkFreeMemory(m_device->device(), imageMem, NULL);
6795 vkDestroyImage(m_device->device(), image, NULL);
6796 vkDestroyImageView(m_device->device(), view, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006797}
Tobin Ehlis559c6382015-11-05 09:52:49 -07006798
Karl Schultz6addd812016-02-02 17:17:23 -07006799TEST_F(VkLayerTest, NoBeginCommandBuffer) {
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006800
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006801 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6802 "You must call vkBeginCommandBuffer() before this call to ");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006803
6804 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006805 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006806 // Call EndCommandBuffer() w/o calling BeginCommandBuffer()
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006807 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006808
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006809 m_errorMonitor->VerifyFound();
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006810}
6811
Karl Schultz6addd812016-02-02 17:17:23 -07006812TEST_F(VkLayerTest, SecondaryCommandBufferNullRenderpass) {
6813 VkResult err;
6814 VkCommandBuffer draw_cmd;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006815
Karl Schultzf78bcdd2016-11-30 12:36:01 -07006816 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00110);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006817
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006818 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006819
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006820 VkCommandBufferAllocateInfo cmd = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006821 cmd.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06006822 cmd.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006823 cmd.commandPool = m_commandPool;
6824 cmd.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006825 cmd.commandBufferCount = 1;
Cody Northropb4569702015-08-04 17:35:57 -06006826
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006827 err = vkAllocateCommandBuffers(m_device->device(), &cmd, &draw_cmd);
Mike Stroyand1c84a52015-08-18 14:40:24 -06006828 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006829
6830 // Force the failure by not setting the Renderpass and Framebuffer fields
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006831 VkCommandBufferBeginInfo cmd_buf_info = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07006832 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006833 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06006834 cmd_buf_info.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006835 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 -07006836 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006837
6838 // The error should be caught by validation of the BeginCommandBuffer call
6839 vkBeginCommandBuffer(draw_cmd, &cmd_buf_info);
6840
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006841 m_errorMonitor->VerifyFound();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006842 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &draw_cmd);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006843}
6844
Karl Schultz6addd812016-02-02 17:17:23 -07006845TEST_F(VkLayerTest, CommandBufferResetErrors) {
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006846 // Cause error due to Begin while recording CB
6847 // Then cause 2 errors for attempting to reset CB w/o having
6848 // VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT set for the pool from
6849 // which CBs were allocated. Note that this bit is off by default.
Mike Weiblencce7ec72016-10-17 19:33:05 -06006850 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot call Begin on command buffer");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006851
6852 ASSERT_NO_FATAL_FAILURE(InitState());
6853
6854 // Calls AllocateCommandBuffers
6855 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
6856
Karl Schultz6addd812016-02-02 17:17:23 -07006857 // Force the failure by setting the Renderpass and Framebuffer fields with
6858 // (fake) data
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006859 VkCommandBufferBeginInfo cmd_buf_info = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07006860 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006861 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
6862 cmd_buf_info.pNext = NULL;
6863 cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006864 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006865
6866 // Begin CB to transition to recording state
6867 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
6868 // Can't re-begin. This should trigger error
6869 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006870 m_errorMonitor->VerifyFound();
6871
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006872 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to reset command buffer ");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006873 VkCommandBufferResetFlags flags = 0; // Don't care about flags for this test
6874 // Reset attempt will trigger error due to incorrect CommandPool state
6875 vkResetCommandBuffer(commandBuffer.GetBufferHandle(), flags);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006876 m_errorMonitor->VerifyFound();
6877
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006878 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " attempts to implicitly reset cmdBuffer created from ");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006879 // Transition CB to RECORDED state
6880 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
6881 // Now attempting to Begin will implicitly reset, which triggers error
6882 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006883 m_errorMonitor->VerifyFound();
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006884}
6885
Karl Schultz6addd812016-02-02 17:17:23 -07006886TEST_F(VkLayerTest, InvalidPipelineCreateState) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006887 // Attempt to Create Gfx Pipeline w/o a VS
Karl Schultz6addd812016-02-02 17:17:23 -07006888 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006889
Mike Weiblencce7ec72016-10-17 19:33:05 -06006890 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Pipeline CreateInfo State: Vertex Shader required");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006891
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006892 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06006893 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinski209b5292015-09-17 09:44:05 -06006894
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006895 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006896 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6897 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06006898
6899 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006900 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6901 ds_pool_ci.pNext = NULL;
6902 ds_pool_ci.maxSets = 1;
6903 ds_pool_ci.poolSizeCount = 1;
6904 ds_pool_ci.pPoolSizes = &ds_type_count;
Mark Lobodzinski209b5292015-09-17 09:44:05 -06006905
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006906 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006907 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006908 ASSERT_VK_SUCCESS(err);
6909
Tony Barboureb254902015-07-15 12:50:33 -06006910 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006911 dsl_binding.binding = 0;
6912 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6913 dsl_binding.descriptorCount = 1;
6914 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6915 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006916
Tony Barboureb254902015-07-15 12:50:33 -06006917 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006918 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6919 ds_layout_ci.pNext = NULL;
6920 ds_layout_ci.bindingCount = 1;
6921 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06006922
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006923 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006924 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006925 ASSERT_VK_SUCCESS(err);
6926
6927 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006928 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006929 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006930 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06006931 alloc_info.descriptorPool = ds_pool;
6932 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006933 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006934 ASSERT_VK_SUCCESS(err);
6935
Tony Barboureb254902015-07-15 12:50:33 -06006936 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006937 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6938 pipeline_layout_ci.setLayoutCount = 1;
6939 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006940
6941 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006942 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006943 ASSERT_VK_SUCCESS(err);
6944
Tobin Ehlise68360f2015-10-01 11:15:13 -06006945 VkViewport vp = {}; // Just need dummy vp to point to
Karl Schultz6addd812016-02-02 17:17:23 -07006946 VkRect2D sc = {}; // dummy scissor to point to
Tobin Ehlise68360f2015-10-01 11:15:13 -06006947
6948 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006949 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
6950 vp_state_ci.scissorCount = 1;
6951 vp_state_ci.pScissors = &sc;
6952 vp_state_ci.viewportCount = 1;
6953 vp_state_ci.pViewports = &vp;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006954
Karl Schultzdfdb8d42016-03-08 10:30:21 -07006955 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
6956 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
6957 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
6958 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
6959 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
6960 rs_state_ci.depthClampEnable = VK_FALSE;
6961 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
6962 rs_state_ci.depthBiasEnable = VK_FALSE;
6963
Tony Barboureb254902015-07-15 12:50:33 -06006964 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006965 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
6966 gp_ci.pViewportState = &vp_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07006967 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07006968 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
6969 gp_ci.layout = pipeline_layout;
6970 gp_ci.renderPass = renderPass();
Tony Barboureb254902015-07-15 12:50:33 -06006971
6972 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006973 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
6974 pc_ci.initialDataSize = 0;
6975 pc_ci.pInitialData = 0;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006976
6977 VkPipeline pipeline;
Jon Ashburnc669cc62015-07-09 15:02:25 -06006978 VkPipelineCache pipelineCache;
6979
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006980 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Jon Ashburnc669cc62015-07-09 15:02:25 -06006981 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006982 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006983
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006984 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06006985
Chia-I Wuf7458c52015-10-26 21:10:41 +08006986 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
6987 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6988 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6989 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006990}
Tobin Ehlis912df022015-09-17 08:46:18 -06006991/*// TODO : This test should be good, but needs Tess support in compiler to run
6992TEST_F(VkLayerTest, InvalidPatchControlPoints)
6993{
6994 // Attempt to Create Gfx Pipeline w/o a VS
Tobin Ehlis912df022015-09-17 08:46:18 -06006995 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006996
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07006997 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07006998 "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH
6999primitive ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007000
Tobin Ehlis912df022015-09-17 08:46:18 -06007001 ASSERT_NO_FATAL_FAILURE(InitState());
7002 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis912df022015-09-17 08:46:18 -06007003
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007004 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlis912df022015-09-17 08:46:18 -06007005 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007006 ds_type_count.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06007007
7008 VkDescriptorPoolCreateInfo ds_pool_ci = {};
7009 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7010 ds_pool_ci.pNext = NULL;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007011 ds_pool_ci.poolSizeCount = 1;
7012 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis912df022015-09-17 08:46:18 -06007013
7014 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07007015 err = vkCreateDescriptorPool(m_device->device(),
7016VK_DESCRIPTOR_POOL_USAGE_NON_FREE, 1, &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis912df022015-09-17 08:46:18 -06007017 ASSERT_VK_SUCCESS(err);
7018
7019 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08007020 dsl_binding.binding = 0;
Tobin Ehlis912df022015-09-17 08:46:18 -06007021 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08007022 dsl_binding.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06007023 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7024 dsl_binding.pImmutableSamplers = NULL;
7025
7026 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007027 ds_layout_ci.sType =
7028VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06007029 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007030 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07007031 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis912df022015-09-17 08:46:18 -06007032
7033 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007034 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
7035&ds_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06007036 ASSERT_VK_SUCCESS(err);
7037
7038 VkDescriptorSet descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -07007039 err = vkAllocateDescriptorSets(m_device->device(), ds_pool,
7040VK_DESCRIPTOR_SET_USAGE_NON_FREE, 1, &ds_layout, &descriptorSet);
Tobin Ehlis912df022015-09-17 08:46:18 -06007041 ASSERT_VK_SUCCESS(err);
7042
7043 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007044 pipeline_layout_ci.sType =
7045VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06007046 pipeline_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007047 pipeline_layout_ci.setLayoutCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06007048 pipeline_layout_ci.pSetLayouts = &ds_layout;
7049
7050 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007051 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
7052&pipeline_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06007053 ASSERT_VK_SUCCESS(err);
7054
7055 VkPipelineShaderStageCreateInfo shaderStages[3];
7056 memset(&shaderStages, 0, 3 * sizeof(VkPipelineShaderStageCreateInfo));
7057
Karl Schultz6addd812016-02-02 17:17:23 -07007058 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT,
7059this);
Tobin Ehlis912df022015-09-17 08:46:18 -06007060 // Just using VS txt for Tess shaders as we don't care about functionality
Karl Schultz6addd812016-02-02 17:17:23 -07007061 VkShaderObj
7062tc(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT,
7063this);
7064 VkShaderObj
7065te(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT,
7066this);
Tobin Ehlis912df022015-09-17 08:46:18 -06007067
Karl Schultz6addd812016-02-02 17:17:23 -07007068 shaderStages[0].sType =
7069VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06007070 shaderStages[0].stage = VK_SHADER_STAGE_VERTEX_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06007071 shaderStages[0].shader = vs.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07007072 shaderStages[1].sType =
7073VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06007074 shaderStages[1].stage = VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06007075 shaderStages[1].shader = tc.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07007076 shaderStages[2].sType =
7077VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06007078 shaderStages[2].stage = VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06007079 shaderStages[2].shader = te.handle();
7080
7081 VkPipelineInputAssemblyStateCreateInfo iaCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007082 iaCI.sType =
7083VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
Chia-I Wu515eb8f2015-10-31 00:31:16 +08007084 iaCI.topology = VK_PRIMITIVE_TOPOLOGY_PATCH_LIST;
Tobin Ehlis912df022015-09-17 08:46:18 -06007085
7086 VkPipelineTessellationStateCreateInfo tsCI = {};
7087 tsCI.sType = VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO;
7088 tsCI.patchControlPoints = 0; // This will cause an error
7089
7090 VkGraphicsPipelineCreateInfo gp_ci = {};
7091 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7092 gp_ci.pNext = NULL;
7093 gp_ci.stageCount = 3;
7094 gp_ci.pStages = shaderStages;
7095 gp_ci.pVertexInputState = NULL;
7096 gp_ci.pInputAssemblyState = &iaCI;
7097 gp_ci.pTessellationState = &tsCI;
7098 gp_ci.pViewportState = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007099 gp_ci.pRasterizationState = NULL;
Tobin Ehlis912df022015-09-17 08:46:18 -06007100 gp_ci.pMultisampleState = NULL;
7101 gp_ci.pDepthStencilState = NULL;
7102 gp_ci.pColorBlendState = NULL;
7103 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7104 gp_ci.layout = pipeline_layout;
7105 gp_ci.renderPass = renderPass();
7106
7107 VkPipelineCacheCreateInfo pc_ci = {};
7108 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
7109 pc_ci.pNext = NULL;
7110 pc_ci.initialSize = 0;
7111 pc_ci.initialData = 0;
7112 pc_ci.maxSize = 0;
7113
7114 VkPipeline pipeline;
7115 VkPipelineCache pipelineCache;
7116
Karl Schultz6addd812016-02-02 17:17:23 -07007117 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL,
7118&pipelineCache);
Tobin Ehlis912df022015-09-17 08:46:18 -06007119 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07007120 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
7121&gp_ci, NULL, &pipeline);
Tobin Ehlis912df022015-09-17 08:46:18 -06007122
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007123 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06007124
Chia-I Wuf7458c52015-10-26 21:10:41 +08007125 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7126 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7127 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7128 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis912df022015-09-17 08:46:18 -06007129}
7130*/
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007131
Karl Schultz6addd812016-02-02 17:17:23 -07007132TEST_F(VkLayerTest, PSOViewportScissorCountMismatch) {
Karl Schultz6addd812016-02-02 17:17:23 -07007133 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007134
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007135 TEST_DESCRIPTION("Set scissor and viewport counts to different numbers");
7136
Mark Lobodzinski6fcae552016-12-18 08:57:03 -07007137 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01434);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007138
Tobin Ehlise68360f2015-10-01 11:15:13 -06007139 ASSERT_NO_FATAL_FAILURE(InitState());
7140 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06007141
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007142 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007143 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7144 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007145
7146 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007147 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7148 ds_pool_ci.maxSets = 1;
7149 ds_pool_ci.poolSizeCount = 1;
7150 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007151
7152 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007153 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007154 ASSERT_VK_SUCCESS(err);
7155
7156 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007157 dsl_binding.binding = 0;
7158 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7159 dsl_binding.descriptorCount = 1;
7160 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007161
7162 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007163 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7164 ds_layout_ci.bindingCount = 1;
7165 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007166
7167 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007168 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007169 ASSERT_VK_SUCCESS(err);
7170
7171 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007172 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007173 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007174 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007175 alloc_info.descriptorPool = ds_pool;
7176 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007177 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007178 ASSERT_VK_SUCCESS(err);
7179
7180 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007181 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7182 pipeline_layout_ci.setLayoutCount = 1;
7183 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007184
7185 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007186 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007187 ASSERT_VK_SUCCESS(err);
7188
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007189 VkViewport vp = {};
Tobin Ehlise68360f2015-10-01 11:15:13 -06007190
7191 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007192 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
7193 vp_state_ci.scissorCount = 0;
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007194 // Count mismatch should cause error
7195 vp_state_ci.viewportCount = 1;
Karl Schultz6addd812016-02-02 17:17:23 -07007196 vp_state_ci.pViewports = &vp;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007197
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007198 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
7199 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7200 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
7201 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
7202 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
7203 rs_state_ci.depthClampEnable = VK_FALSE;
7204 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
7205 rs_state_ci.depthBiasEnable = VK_FALSE;
7206
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007207 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7208 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7209 vi_ci.pNext = nullptr;
7210 vi_ci.vertexBindingDescriptionCount = 0;
7211 vi_ci.pVertexBindingDescriptions = nullptr;
7212 vi_ci.vertexAttributeDescriptionCount = 0;
7213 vi_ci.pVertexAttributeDescriptions = nullptr;
7214
7215 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7216 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7217 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7218
7219 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
7220 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
7221 pipe_ms_state_ci.pNext = NULL;
7222 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
7223 pipe_ms_state_ci.sampleShadingEnable = 0;
7224 pipe_ms_state_ci.minSampleShading = 1.0;
7225 pipe_ms_state_ci.pSampleMask = NULL;
7226
Cody Northropeb3a6c12015-10-05 14:44:45 -06007227 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07007228 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06007229
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007230 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinskid04c7862016-12-16 13:17:49 -07007231 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
7232 // We shouldn't need a fragment shader but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08007233 shaderStages[0] = vs.GetStageCreateInfo();
7234 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007235
7236 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007237 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7238 gp_ci.stageCount = 2;
7239 gp_ci.pStages = shaderStages;
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007240 gp_ci.pVertexInputState = &vi_ci;
7241 gp_ci.pInputAssemblyState = &ia_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007242 gp_ci.pViewportState = &vp_state_ci;
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007243 gp_ci.pMultisampleState = &pipe_ms_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007244 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007245 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7246 gp_ci.layout = pipeline_layout;
7247 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007248
7249 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007250 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007251
7252 VkPipeline pipeline;
7253 VkPipelineCache pipelineCache;
7254
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007255 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007256 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007257 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007258
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007259 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007260
Chia-I Wuf7458c52015-10-26 21:10:41 +08007261 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7262 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7263 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7264 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007265}
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007266
7267// Don't set viewport state in PSO. This is an error b/c we always need this state for the counts even if the data is going to be
7268// set dynamically.
Karl Schultz6addd812016-02-02 17:17:23 -07007269TEST_F(VkLayerTest, PSOViewportStateNotSet) {
Karl Schultz6addd812016-02-02 17:17:23 -07007270 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007271
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007272 TEST_DESCRIPTION("Create a graphics pipeline with rasterization enabled but no viewport state.");
7273
Mark Lobodzinskid04c7862016-12-16 13:17:49 -07007274 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02113);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007275
Tobin Ehlise68360f2015-10-01 11:15:13 -06007276 ASSERT_NO_FATAL_FAILURE(InitState());
7277 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06007278
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007279 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007280 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7281 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007282
7283 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007284 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7285 ds_pool_ci.maxSets = 1;
7286 ds_pool_ci.poolSizeCount = 1;
7287 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007288
7289 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007290 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007291 ASSERT_VK_SUCCESS(err);
7292
7293 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007294 dsl_binding.binding = 0;
7295 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7296 dsl_binding.descriptorCount = 1;
7297 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007298
7299 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007300 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7301 ds_layout_ci.bindingCount = 1;
7302 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007303
7304 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007305 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007306 ASSERT_VK_SUCCESS(err);
7307
7308 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007309 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007310 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007311 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007312 alloc_info.descriptorPool = ds_pool;
7313 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007314 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007315 ASSERT_VK_SUCCESS(err);
7316
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007317 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7318 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7319 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7320
7321 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7322 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7323 vi_ci.pNext = nullptr;
7324 vi_ci.vertexBindingDescriptionCount = 0;
7325 vi_ci.pVertexBindingDescriptions = nullptr;
7326 vi_ci.vertexAttributeDescriptionCount = 0;
7327 vi_ci.pVertexAttributeDescriptions = nullptr;
7328
7329 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
7330 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
7331 pipe_ms_state_ci.pNext = NULL;
7332 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
7333 pipe_ms_state_ci.sampleShadingEnable = 0;
7334 pipe_ms_state_ci.minSampleShading = 1.0;
7335 pipe_ms_state_ci.pSampleMask = NULL;
7336
Tobin Ehlise68360f2015-10-01 11:15:13 -06007337 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007338 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7339 pipeline_layout_ci.setLayoutCount = 1;
7340 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007341
7342 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007343 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007344 ASSERT_VK_SUCCESS(err);
7345
7346 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
7347 // Set scissor as dynamic to avoid second error
7348 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007349 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
7350 dyn_state_ci.dynamicStateCount = 1;
7351 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007352
Cody Northropeb3a6c12015-10-05 14:44:45 -06007353 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07007354 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06007355
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007356 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007357 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
7358 // We shouldn't need a fragment shader but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08007359 shaderStages[0] = vs.GetStageCreateInfo();
7360 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007361
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007362 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
7363 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7364 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
7365 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
7366 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
7367 rs_state_ci.depthClampEnable = VK_FALSE;
7368 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
7369 rs_state_ci.depthBiasEnable = VK_FALSE;
7370
Tobin Ehlise68360f2015-10-01 11:15:13 -06007371 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007372 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7373 gp_ci.stageCount = 2;
7374 gp_ci.pStages = shaderStages;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007375 gp_ci.pRasterizationState = &rs_state_ci;
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007376 // Not setting VP state w/o dynamic vp state should cause validation error
7377 gp_ci.pViewportState = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -07007378 gp_ci.pDynamicState = &dyn_state_ci;
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007379 gp_ci.pVertexInputState = &vi_ci;
7380 gp_ci.pInputAssemblyState = &ia_ci;
7381 gp_ci.pMultisampleState = &pipe_ms_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007382 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7383 gp_ci.layout = pipeline_layout;
7384 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007385
7386 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007387 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007388
7389 VkPipeline pipeline;
7390 VkPipelineCache pipelineCache;
7391
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007392 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007393 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007394 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007395
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007396 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007397
Chia-I Wuf7458c52015-10-26 21:10:41 +08007398 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7399 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7400 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7401 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007402}
Mark Lobodzinski73169e22016-12-16 14:01:17 -07007403
7404// Create PSO w/o non-zero viewportCount but no viewport data, then run second test where dynamic scissor count doesn't match PSO
7405// scissor count
Karl Schultz6addd812016-02-02 17:17:23 -07007406TEST_F(VkLayerTest, PSOViewportCountWithoutDataAndDynScissorMismatch) {
7407 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007408
Mark Lobodzinskid04c7862016-12-16 13:17:49 -07007409 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02110);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007410
Tobin Ehlise68360f2015-10-01 11:15:13 -06007411 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007412
7413 if (!m_device->phy().features().multiViewport) {
7414 printf("Device does not support multiple viewports/scissors; skipped.\n");
7415 return;
7416 }
7417
Tobin Ehlise68360f2015-10-01 11:15:13 -06007418 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06007419
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007420 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007421 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7422 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007423
7424 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007425 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7426 ds_pool_ci.maxSets = 1;
7427 ds_pool_ci.poolSizeCount = 1;
7428 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007429
7430 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007431 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007432 ASSERT_VK_SUCCESS(err);
7433
7434 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007435 dsl_binding.binding = 0;
7436 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7437 dsl_binding.descriptorCount = 1;
7438 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007439
7440 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007441 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7442 ds_layout_ci.bindingCount = 1;
7443 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007444
7445 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007446 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007447 ASSERT_VK_SUCCESS(err);
7448
7449 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007450 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007451 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007452 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007453 alloc_info.descriptorPool = ds_pool;
7454 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007455 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007456 ASSERT_VK_SUCCESS(err);
7457
7458 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007459 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7460 pipeline_layout_ci.setLayoutCount = 1;
7461 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007462
7463 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007464 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007465 ASSERT_VK_SUCCESS(err);
7466
7467 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007468 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
7469 vp_state_ci.viewportCount = 1;
7470 vp_state_ci.pViewports = NULL; // Null vp w/ count of 1 should cause error
7471 vp_state_ci.scissorCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007472 vp_state_ci.pScissors = NULL; // Scissor is dynamic (below) so this won't cause error
Tobin Ehlise68360f2015-10-01 11:15:13 -06007473
7474 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
7475 // Set scissor as dynamic to avoid that error
7476 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007477 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
7478 dyn_state_ci.dynamicStateCount = 1;
7479 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007480
Mark Lobodzinski73169e22016-12-16 14:01:17 -07007481 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
7482 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
7483 pipe_ms_state_ci.pNext = NULL;
7484 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
7485 pipe_ms_state_ci.sampleShadingEnable = 0;
7486 pipe_ms_state_ci.minSampleShading = 1.0;
7487 pipe_ms_state_ci.pSampleMask = NULL;
7488
Cody Northropeb3a6c12015-10-05 14:44:45 -06007489 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07007490 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06007491
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007492 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski73169e22016-12-16 14:01:17 -07007493 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
7494 // We shouldn't need a fragment shader but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08007495 shaderStages[0] = vs.GetStageCreateInfo();
7496 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007497
Cody Northropf6622dc2015-10-06 10:33:21 -06007498 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7499 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7500 vi_ci.pNext = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007501 vi_ci.vertexBindingDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06007502 vi_ci.pVertexBindingDescriptions = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007503 vi_ci.vertexAttributeDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06007504 vi_ci.pVertexAttributeDescriptions = nullptr;
7505
7506 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7507 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7508 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7509
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007510 VkPipelineRasterizationStateCreateInfo rs_ci = {};
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007511 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Mark Lobodzinski73169e22016-12-16 14:01:17 -07007512 rs_ci.lineWidth = m_device->props.limits.lineWidthRange[0];
Cody Northropf6622dc2015-10-06 10:33:21 -06007513 rs_ci.pNext = nullptr;
7514
Mark Youngc89c6312016-03-31 16:03:20 -06007515 VkPipelineColorBlendAttachmentState att = {};
7516 att.blendEnable = VK_FALSE;
7517 att.colorWriteMask = 0xf;
7518
Cody Northropf6622dc2015-10-06 10:33:21 -06007519 VkPipelineColorBlendStateCreateInfo cb_ci = {};
7520 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
7521 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06007522 cb_ci.attachmentCount = 1;
7523 cb_ci.pAttachments = &att;
Cody Northropf6622dc2015-10-06 10:33:21 -06007524
Tobin Ehlise68360f2015-10-01 11:15:13 -06007525 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007526 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7527 gp_ci.stageCount = 2;
7528 gp_ci.pStages = shaderStages;
7529 gp_ci.pVertexInputState = &vi_ci;
7530 gp_ci.pInputAssemblyState = &ia_ci;
7531 gp_ci.pViewportState = &vp_state_ci;
7532 gp_ci.pRasterizationState = &rs_ci;
7533 gp_ci.pColorBlendState = &cb_ci;
7534 gp_ci.pDynamicState = &dyn_state_ci;
Mark Lobodzinski73169e22016-12-16 14:01:17 -07007535 gp_ci.pMultisampleState = &pipe_ms_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007536 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7537 gp_ci.layout = pipeline_layout;
7538 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007539
7540 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007541 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007542
7543 VkPipeline pipeline;
7544 VkPipelineCache pipelineCache;
7545
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007546 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007547 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007548 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007549
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007550 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007551
Tobin Ehlisd332f282015-10-02 11:00:56 -06007552 // Now hit second fail case where we set scissor w/ different count than PSO
Karl Schultz6addd812016-02-02 17:17:23 -07007553 // First need to successfully create the PSO from above by setting
7554 // pViewports
Mike Weiblen95dd0f92016-10-19 12:28:27 -06007555 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 -07007556
7557 VkViewport vp = {}; // Just need dummy vp to point to
7558 vp_state_ci.pViewports = &vp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007559 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Karl Schultz6addd812016-02-02 17:17:23 -07007560 ASSERT_VK_SUCCESS(err);
7561 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007562 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007563 VkRect2D scissors[1] = {}; // don't care about data
Karl Schultz6addd812016-02-02 17:17:23 -07007564 // Count of 2 doesn't match PSO count of 1
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007565 vkCmdSetScissor(m_commandBuffer->GetBufferHandle(), 1, 1, scissors);
Karl Schultz6addd812016-02-02 17:17:23 -07007566 Draw(1, 0, 0, 0);
7567
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007568 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07007569
7570 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7571 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7572 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7573 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06007574 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07007575}
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07007576
7577// Create PSO w/o non-zero scissorCount but no scissor data, then run second test where dynamic viewportCount doesn't match PSO
Karl Schultz6addd812016-02-02 17:17:23 -07007578// viewportCount
7579TEST_F(VkLayerTest, PSOScissorCountWithoutDataAndDynViewportMismatch) {
7580 VkResult err;
7581
Mark Lobodzinskid04c7862016-12-16 13:17:49 -07007582 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02111);
Karl Schultz6addd812016-02-02 17:17:23 -07007583
7584 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007585
7586 if (!m_device->phy().features().multiViewport) {
7587 printf("Device does not support multiple viewports/scissors; skipped.\n");
7588 return;
7589 }
7590
Karl Schultz6addd812016-02-02 17:17:23 -07007591 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7592
7593 VkDescriptorPoolSize ds_type_count = {};
7594 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7595 ds_type_count.descriptorCount = 1;
7596
7597 VkDescriptorPoolCreateInfo ds_pool_ci = {};
7598 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7599 ds_pool_ci.maxSets = 1;
7600 ds_pool_ci.poolSizeCount = 1;
7601 ds_pool_ci.pPoolSizes = &ds_type_count;
7602
7603 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007604 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Karl Schultz6addd812016-02-02 17:17:23 -07007605 ASSERT_VK_SUCCESS(err);
7606
7607 VkDescriptorSetLayoutBinding dsl_binding = {};
7608 dsl_binding.binding = 0;
7609 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7610 dsl_binding.descriptorCount = 1;
7611 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7612
7613 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
7614 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7615 ds_layout_ci.bindingCount = 1;
7616 ds_layout_ci.pBindings = &dsl_binding;
7617
7618 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007619 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Karl Schultz6addd812016-02-02 17:17:23 -07007620 ASSERT_VK_SUCCESS(err);
7621
7622 VkDescriptorSet descriptorSet;
7623 VkDescriptorSetAllocateInfo alloc_info = {};
7624 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
7625 alloc_info.descriptorSetCount = 1;
7626 alloc_info.descriptorPool = ds_pool;
7627 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007628 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Karl Schultz6addd812016-02-02 17:17:23 -07007629 ASSERT_VK_SUCCESS(err);
7630
7631 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
7632 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7633 pipeline_layout_ci.setLayoutCount = 1;
7634 pipeline_layout_ci.pSetLayouts = &ds_layout;
7635
7636 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007637 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultz6addd812016-02-02 17:17:23 -07007638 ASSERT_VK_SUCCESS(err);
7639
7640 VkPipelineViewportStateCreateInfo vp_state_ci = {};
7641 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
7642 vp_state_ci.scissorCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007643 vp_state_ci.pScissors = NULL; // Null scissor w/ count of 1 should cause error
Karl Schultz6addd812016-02-02 17:17:23 -07007644 vp_state_ci.viewportCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007645 vp_state_ci.pViewports = NULL; // vp is dynamic (below) so this won't cause error
Karl Schultz6addd812016-02-02 17:17:23 -07007646
7647 VkDynamicState vp_state = VK_DYNAMIC_STATE_VIEWPORT;
7648 // Set scissor as dynamic to avoid that error
7649 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
7650 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
7651 dyn_state_ci.dynamicStateCount = 1;
7652 dyn_state_ci.pDynamicStates = &vp_state;
7653
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07007654 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
7655 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
7656 pipe_ms_state_ci.pNext = NULL;
7657 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
7658 pipe_ms_state_ci.sampleShadingEnable = 0;
7659 pipe_ms_state_ci.minSampleShading = 1.0;
7660 pipe_ms_state_ci.pSampleMask = NULL;
7661
Karl Schultz6addd812016-02-02 17:17:23 -07007662 VkPipelineShaderStageCreateInfo shaderStages[2];
7663 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
7664
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007665 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07007666 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
7667 // We shouldn't need a fragment shader but add it to be able to run on more devices
Karl Schultz6addd812016-02-02 17:17:23 -07007668 shaderStages[0] = vs.GetStageCreateInfo();
7669 shaderStages[1] = fs.GetStageCreateInfo();
7670
7671 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7672 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7673 vi_ci.pNext = nullptr;
7674 vi_ci.vertexBindingDescriptionCount = 0;
7675 vi_ci.pVertexBindingDescriptions = nullptr;
7676 vi_ci.vertexAttributeDescriptionCount = 0;
7677 vi_ci.pVertexAttributeDescriptions = nullptr;
7678
7679 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7680 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7681 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7682
7683 VkPipelineRasterizationStateCreateInfo rs_ci = {};
7684 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07007685 rs_ci.lineWidth = m_device->props.limits.lineWidthRange[0];
Karl Schultz6addd812016-02-02 17:17:23 -07007686 rs_ci.pNext = nullptr;
7687
Mark Youngc89c6312016-03-31 16:03:20 -06007688 VkPipelineColorBlendAttachmentState att = {};
7689 att.blendEnable = VK_FALSE;
7690 att.colorWriteMask = 0xf;
7691
Karl Schultz6addd812016-02-02 17:17:23 -07007692 VkPipelineColorBlendStateCreateInfo cb_ci = {};
7693 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
7694 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06007695 cb_ci.attachmentCount = 1;
7696 cb_ci.pAttachments = &att;
Karl Schultz6addd812016-02-02 17:17:23 -07007697
7698 VkGraphicsPipelineCreateInfo gp_ci = {};
7699 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7700 gp_ci.stageCount = 2;
7701 gp_ci.pStages = shaderStages;
7702 gp_ci.pVertexInputState = &vi_ci;
7703 gp_ci.pInputAssemblyState = &ia_ci;
7704 gp_ci.pViewportState = &vp_state_ci;
7705 gp_ci.pRasterizationState = &rs_ci;
7706 gp_ci.pColorBlendState = &cb_ci;
7707 gp_ci.pDynamicState = &dyn_state_ci;
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07007708 gp_ci.pMultisampleState = &pipe_ms_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007709 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7710 gp_ci.layout = pipeline_layout;
7711 gp_ci.renderPass = renderPass();
7712
7713 VkPipelineCacheCreateInfo pc_ci = {};
7714 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
7715
7716 VkPipeline pipeline;
7717 VkPipelineCache pipelineCache;
7718
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007719 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Karl Schultz6addd812016-02-02 17:17:23 -07007720 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007721 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Karl Schultz6addd812016-02-02 17:17:23 -07007722
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007723 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07007724
7725 // Now hit second fail case where we set scissor w/ different count than PSO
7726 // First need to successfully create the PSO from above by setting
7727 // pViewports
Mike Weiblen95dd0f92016-10-19 12:28:27 -06007728 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 -06007729
Tobin Ehlisd332f282015-10-02 11:00:56 -06007730 VkRect2D sc = {}; // Just need dummy vp to point to
7731 vp_state_ci.pScissors = &sc;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007732 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlisd332f282015-10-02 11:00:56 -06007733 ASSERT_VK_SUCCESS(err);
7734 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007735 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07007736 VkViewport viewports[1] = {};
7737 viewports[0].width = 8;
7738 viewports[0].height = 8;
Tobin Ehlisd332f282015-10-02 11:00:56 -06007739 // Count of 2 doesn't match PSO count of 1
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007740 vkCmdSetViewport(m_commandBuffer->GetBufferHandle(), 1, 1, viewports);
Tobin Ehlisd332f282015-10-02 11:00:56 -06007741 Draw(1, 0, 0, 0);
7742
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007743 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007744
Chia-I Wuf7458c52015-10-26 21:10:41 +08007745 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7746 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7747 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7748 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06007749 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007750}
7751
Mark Young7394fdd2016-03-31 14:56:43 -06007752TEST_F(VkLayerTest, PSOLineWidthInvalid) {
7753 VkResult err;
7754
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007755 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to -1");
Mark Young7394fdd2016-03-31 14:56:43 -06007756
7757 ASSERT_NO_FATAL_FAILURE(InitState());
7758 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7759
7760 VkDescriptorPoolSize ds_type_count = {};
7761 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7762 ds_type_count.descriptorCount = 1;
7763
7764 VkDescriptorPoolCreateInfo ds_pool_ci = {};
7765 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7766 ds_pool_ci.maxSets = 1;
7767 ds_pool_ci.poolSizeCount = 1;
7768 ds_pool_ci.pPoolSizes = &ds_type_count;
7769
7770 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007771 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Mark Young7394fdd2016-03-31 14:56:43 -06007772 ASSERT_VK_SUCCESS(err);
7773
7774 VkDescriptorSetLayoutBinding dsl_binding = {};
7775 dsl_binding.binding = 0;
7776 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7777 dsl_binding.descriptorCount = 1;
7778 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7779
7780 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
7781 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7782 ds_layout_ci.bindingCount = 1;
7783 ds_layout_ci.pBindings = &dsl_binding;
7784
7785 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007786 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Young7394fdd2016-03-31 14:56:43 -06007787 ASSERT_VK_SUCCESS(err);
7788
7789 VkDescriptorSet descriptorSet;
7790 VkDescriptorSetAllocateInfo alloc_info = {};
7791 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
7792 alloc_info.descriptorSetCount = 1;
7793 alloc_info.descriptorPool = ds_pool;
7794 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007795 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Young7394fdd2016-03-31 14:56:43 -06007796 ASSERT_VK_SUCCESS(err);
7797
7798 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
7799 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7800 pipeline_layout_ci.setLayoutCount = 1;
7801 pipeline_layout_ci.pSetLayouts = &ds_layout;
7802
7803 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007804 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Mark Young7394fdd2016-03-31 14:56:43 -06007805 ASSERT_VK_SUCCESS(err);
7806
7807 VkPipelineViewportStateCreateInfo vp_state_ci = {};
7808 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
7809 vp_state_ci.scissorCount = 1;
7810 vp_state_ci.pScissors = NULL;
7811 vp_state_ci.viewportCount = 1;
7812 vp_state_ci.pViewports = NULL;
7813
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007814 VkDynamicState dynamic_states[3] = {VK_DYNAMIC_STATE_VIEWPORT, VK_DYNAMIC_STATE_SCISSOR, VK_DYNAMIC_STATE_LINE_WIDTH};
Mark Young7394fdd2016-03-31 14:56:43 -06007815 // Set scissor as dynamic to avoid that error
7816 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
7817 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
7818 dyn_state_ci.dynamicStateCount = 2;
7819 dyn_state_ci.pDynamicStates = dynamic_states;
7820
7821 VkPipelineShaderStageCreateInfo shaderStages[2];
7822 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
7823
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007824 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
7825 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT,
Mark Young7394fdd2016-03-31 14:56:43 -06007826 this); // TODO - We shouldn't need a fragment shader
7827 // but add it to be able to run on more devices
7828 shaderStages[0] = vs.GetStageCreateInfo();
7829 shaderStages[1] = fs.GetStageCreateInfo();
7830
7831 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7832 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7833 vi_ci.pNext = nullptr;
7834 vi_ci.vertexBindingDescriptionCount = 0;
7835 vi_ci.pVertexBindingDescriptions = nullptr;
7836 vi_ci.vertexAttributeDescriptionCount = 0;
7837 vi_ci.pVertexAttributeDescriptions = nullptr;
7838
7839 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7840 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7841 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7842
7843 VkPipelineRasterizationStateCreateInfo rs_ci = {};
7844 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7845 rs_ci.pNext = nullptr;
7846
Mark Young47107952016-05-02 15:59:55 -06007847 // Check too low (line width of -1.0f).
7848 rs_ci.lineWidth = -1.0f;
Mark Young7394fdd2016-03-31 14:56:43 -06007849
7850 VkPipelineColorBlendAttachmentState att = {};
7851 att.blendEnable = VK_FALSE;
7852 att.colorWriteMask = 0xf;
7853
7854 VkPipelineColorBlendStateCreateInfo cb_ci = {};
7855 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
7856 cb_ci.pNext = nullptr;
7857 cb_ci.attachmentCount = 1;
7858 cb_ci.pAttachments = &att;
7859
7860 VkGraphicsPipelineCreateInfo gp_ci = {};
7861 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7862 gp_ci.stageCount = 2;
7863 gp_ci.pStages = shaderStages;
7864 gp_ci.pVertexInputState = &vi_ci;
7865 gp_ci.pInputAssemblyState = &ia_ci;
7866 gp_ci.pViewportState = &vp_state_ci;
7867 gp_ci.pRasterizationState = &rs_ci;
7868 gp_ci.pColorBlendState = &cb_ci;
7869 gp_ci.pDynamicState = &dyn_state_ci;
7870 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7871 gp_ci.layout = pipeline_layout;
7872 gp_ci.renderPass = renderPass();
7873
7874 VkPipelineCacheCreateInfo pc_ci = {};
7875 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
7876
7877 VkPipeline pipeline;
7878 VkPipelineCache pipelineCache;
7879
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007880 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06007881 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007882 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06007883
7884 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06007885 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06007886
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007887 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to 65536");
Mark Young7394fdd2016-03-31 14:56:43 -06007888
7889 // Check too high (line width of 65536.0f).
7890 rs_ci.lineWidth = 65536.0f;
7891
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007892 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06007893 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007894 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06007895
7896 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06007897 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06007898
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007899 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to -1");
Mark Young7394fdd2016-03-31 14:56:43 -06007900
7901 dyn_state_ci.dynamicStateCount = 3;
7902
7903 rs_ci.lineWidth = 1.0f;
7904
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007905 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06007906 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007907 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06007908 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007909 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06007910
7911 // Check too low with dynamic setting.
Mark Young47107952016-05-02 15:59:55 -06007912 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), -1.0f);
Mark Young7394fdd2016-03-31 14:56:43 -06007913 m_errorMonitor->VerifyFound();
7914
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007915 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to 65536");
Mark Young7394fdd2016-03-31 14:56:43 -06007916
7917 // Check too high with dynamic setting.
7918 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), 65536.0f);
7919 m_errorMonitor->VerifyFound();
7920 EndCommandBuffer();
7921
7922 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7923 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7924 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7925 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06007926 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06007927}
7928
Karl Schultz6addd812016-02-02 17:17:23 -07007929TEST_F(VkLayerTest, NullRenderPass) {
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007930 // Bind a NULL RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007931 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7932 "You cannot use a NULL RenderPass object in vkCmdBeginRenderPass()");
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007933
7934 ASSERT_NO_FATAL_FAILURE(InitState());
7935 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007936
Tony Barbourfe3351b2015-07-28 10:17:20 -06007937 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07007938 // Don't care about RenderPass handle b/c error should be flagged before
7939 // that
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007940 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), NULL, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007941
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007942 m_errorMonitor->VerifyFound();
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007943}
7944
Karl Schultz6addd812016-02-02 17:17:23 -07007945TEST_F(VkLayerTest, RenderPassWithinRenderPass) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007946 // Bind a BeginRenderPass within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007947 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7948 "It is invalid to issue this call inside an active render pass");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007949
7950 ASSERT_NO_FATAL_FAILURE(InitState());
7951 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007952
Tony Barbourfe3351b2015-07-28 10:17:20 -06007953 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07007954 // Just create a dummy Renderpass that's non-NULL so we can get to the
7955 // proper error
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007956 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007957
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007958 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06007959}
7960
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06007961TEST_F(VkLayerTest, RenderPassClearOpMismatch) {
7962 TEST_DESCRIPTION("Begin a renderPass where clearValueCount is less than"
7963 "the number of renderPass attachments that use loadOp"
7964 "VK_ATTACHMENT_LOAD_OP_CLEAR.");
7965
7966 ASSERT_NO_FATAL_FAILURE(InitState());
7967 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7968
7969 // Create a renderPass with a single attachment that uses loadOp CLEAR
7970 VkAttachmentReference attach = {};
7971 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
7972 VkSubpassDescription subpass = {};
7973 subpass.inputAttachmentCount = 1;
7974 subpass.pInputAttachments = &attach;
7975 VkRenderPassCreateInfo rpci = {};
7976 rpci.subpassCount = 1;
7977 rpci.pSubpasses = &subpass;
7978 rpci.attachmentCount = 1;
7979 VkAttachmentDescription attach_desc = {};
7980 attach_desc.format = VK_FORMAT_UNDEFINED;
7981 // Set loadOp to CLEAR
7982 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
7983 rpci.pAttachments = &attach_desc;
7984 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
7985 VkRenderPass rp;
7986 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
7987
7988 VkCommandBufferInheritanceInfo hinfo = {};
7989 hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
7990 hinfo.renderPass = VK_NULL_HANDLE;
7991 hinfo.subpass = 0;
7992 hinfo.framebuffer = VK_NULL_HANDLE;
7993 hinfo.occlusionQueryEnable = VK_FALSE;
7994 hinfo.queryFlags = 0;
7995 hinfo.pipelineStatistics = 0;
7996 VkCommandBufferBeginInfo info = {};
7997 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
7998 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
7999 info.pInheritanceInfo = &hinfo;
8000
8001 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
8002 VkRenderPassBeginInfo rp_begin = {};
8003 rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
8004 rp_begin.pNext = NULL;
8005 rp_begin.renderPass = renderPass();
8006 rp_begin.framebuffer = framebuffer();
8007 rp_begin.clearValueCount = 0; // Should be 1
8008
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008009 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has a clearValueCount of 0 but "
8010 "there must be at least 1 entries in "
8011 "pClearValues array to account for ");
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008012
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008013 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rp_begin, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008014
8015 m_errorMonitor->VerifyFound();
Mark Lobodzinski5c70ebd2016-06-09 13:45:00 -06008016
8017 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008018}
8019
Slawomir Cygan0808f392016-11-28 17:53:23 +01008020TEST_F(VkLayerTest, RenderPassClearOpTooManyValues) {
8021 TEST_DESCRIPTION("Begin a renderPass where clearValueCount is greater than"
8022 "the number of renderPass attachments that use loadOp"
8023 "VK_ATTACHMENT_LOAD_OP_CLEAR.");
8024
8025 ASSERT_NO_FATAL_FAILURE(InitState());
8026 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8027
8028 // Create a renderPass with a single attachment that uses loadOp CLEAR
8029 VkAttachmentReference attach = {};
8030 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
8031 VkSubpassDescription subpass = {};
8032 subpass.inputAttachmentCount = 1;
8033 subpass.pInputAttachments = &attach;
8034 VkRenderPassCreateInfo rpci = {};
8035 rpci.subpassCount = 1;
8036 rpci.pSubpasses = &subpass;
8037 rpci.attachmentCount = 1;
8038 VkAttachmentDescription attach_desc = {};
8039 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
8040 // Set loadOp to CLEAR
8041 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
8042 rpci.pAttachments = &attach_desc;
8043 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
8044 VkRenderPass rp;
8045 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
8046
8047 VkCommandBufferBeginInfo info = {};
8048 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
8049 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
8050
8051 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
8052 VkRenderPassBeginInfo rp_begin = {};
8053 rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
8054 rp_begin.pNext = NULL;
8055 rp_begin.renderPass = renderPass();
8056 rp_begin.framebuffer = framebuffer();
8057 rp_begin.clearValueCount = 2; // Should be 1
8058
8059 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, " has a clearValueCount of"
8060 " 2 but only first 1 entries in pClearValues array are used");
8061
8062 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rp_begin, VK_SUBPASS_CONTENTS_INLINE);
8063
8064 m_errorMonitor->VerifyFound();
8065
8066 vkDestroyRenderPass(m_device->device(), rp, NULL);
8067}
8068
8069
Cody Northrop3bb4d962016-05-09 16:15:57 -06008070TEST_F(VkLayerTest, EndCommandBufferWithinRenderPass) {
8071
8072 TEST_DESCRIPTION("End a command buffer with an active render pass");
8073
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008074 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8075 "It is invalid to issue this call inside an active render pass");
Cody Northrop3bb4d962016-05-09 16:15:57 -06008076
8077 ASSERT_NO_FATAL_FAILURE(InitState());
8078 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8079
8080 // The framework's BeginCommandBuffer calls CreateRenderPass
8081 BeginCommandBuffer();
8082
8083 // Call directly into vkEndCommandBuffer instead of the
8084 // the framework's EndCommandBuffer, which inserts a
8085 // vkEndRenderPass
8086 vkEndCommandBuffer(m_commandBuffer->GetBufferHandle());
8087
8088 m_errorMonitor->VerifyFound();
8089
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008090 // TODO: Add test for VK_COMMAND_BUFFER_LEVEL_SECONDARY
8091 // TODO: Add test for VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT
Cody Northrop3bb4d962016-05-09 16:15:57 -06008092}
8093
Karl Schultz6addd812016-02-02 17:17:23 -07008094TEST_F(VkLayerTest, FillBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008095 // Call CmdFillBuffer within an active renderpass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008096 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8097 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008098
8099 ASSERT_NO_FATAL_FAILURE(InitState());
8100 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008101
8102 // Renderpass is started here
8103 BeginCommandBuffer();
8104
8105 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008106 vk_testing::Buffer dstBuffer;
8107 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008108
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008109 m_commandBuffer->FillBuffer(dstBuffer.handle(), 0, 4, 0x11111111);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008110
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008111 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008112}
8113
Karl Schultz6addd812016-02-02 17:17:23 -07008114TEST_F(VkLayerTest, UpdateBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008115 // Call CmdUpdateBuffer within an active renderpass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008116 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8117 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008118
8119 ASSERT_NO_FATAL_FAILURE(InitState());
8120 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008121
8122 // Renderpass is started here
8123 BeginCommandBuffer();
8124
8125 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008126 vk_testing::Buffer dstBuffer;
8127 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008128
Karl Schultz6addd812016-02-02 17:17:23 -07008129 VkDeviceSize dstOffset = 0;
8130 VkDeviceSize dataSize = 1024;
Karl Schultzee344492016-07-11 15:09:57 -06008131 const void *pData = NULL;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008132
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008133 vkCmdUpdateBuffer(m_commandBuffer->GetBufferHandle(), dstBuffer.handle(), dstOffset, dataSize, pData);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008134
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008135 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008136}
8137
Karl Schultz6addd812016-02-02 17:17:23 -07008138TEST_F(VkLayerTest, ClearColorImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008139 // Call CmdClearColorImage within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008140 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8141 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008142
8143 ASSERT_NO_FATAL_FAILURE(InitState());
8144 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008145
8146 // Renderpass is started here
8147 BeginCommandBuffer();
8148
Michael Lentine0a369f62016-02-03 16:51:46 -06008149 VkClearColorValue clear_color;
8150 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
Karl Schultz6addd812016-02-02 17:17:23 -07008151 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
8152 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
8153 const int32_t tex_width = 32;
8154 const int32_t tex_height = 32;
8155 VkImageCreateInfo image_create_info = {};
8156 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
8157 image_create_info.pNext = NULL;
8158 image_create_info.imageType = VK_IMAGE_TYPE_2D;
8159 image_create_info.format = tex_format;
8160 image_create_info.extent.width = tex_width;
8161 image_create_info.extent.height = tex_height;
8162 image_create_info.extent.depth = 1;
8163 image_create_info.mipLevels = 1;
8164 image_create_info.arrayLayers = 1;
8165 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
8166 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
8167 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008168
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008169 vk_testing::Image dstImage;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008170 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008171
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008172 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008173
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008174 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1, &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008175
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008176 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008177}
8178
Karl Schultz6addd812016-02-02 17:17:23 -07008179TEST_F(VkLayerTest, ClearDepthStencilImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008180 // Call CmdClearDepthStencilImage within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008181 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8182 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008183
8184 ASSERT_NO_FATAL_FAILURE(InitState());
8185 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008186
8187 // Renderpass is started here
8188 BeginCommandBuffer();
8189
8190 VkClearDepthStencilValue clear_value = {0};
Dustin Gravesa2e5c942016-02-11 18:28:06 -07008191 VkMemoryPropertyFlags reqs = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07008192 VkImageCreateInfo image_create_info = vk_testing::Image::create_info();
8193 image_create_info.imageType = VK_IMAGE_TYPE_2D;
8194 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
8195 image_create_info.extent.width = 64;
8196 image_create_info.extent.height = 64;
8197 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
8198 image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008199
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008200 vk_testing::Image dstImage;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008201 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008202
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008203 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_DEPTH_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008204
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008205 vkCmdClearDepthStencilImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(),
8206 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, &clear_value, 1, &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008207
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008208 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008209}
8210
Karl Schultz6addd812016-02-02 17:17:23 -07008211TEST_F(VkLayerTest, ClearColorAttachmentsOutsideRenderPass) {
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06008212 // Call CmdClearAttachmentss outside of an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07008213 VkResult err;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008214
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008215 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdClearAttachments(): This call "
8216 "must be issued inside an active "
8217 "render pass");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008218
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008219 ASSERT_NO_FATAL_FAILURE(InitState());
8220 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008221
8222 // Start no RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008223 err = m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008224 ASSERT_VK_SUCCESS(err);
8225
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06008226 VkClearAttachment color_attachment;
8227 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8228 color_attachment.clearValue.color.float32[0] = 0;
8229 color_attachment.clearValue.color.float32[1] = 0;
8230 color_attachment.clearValue.color.float32[2] = 0;
8231 color_attachment.clearValue.color.float32[3] = 0;
8232 color_attachment.colorAttachment = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07008233 VkClearRect clear_rect = {{{0, 0}, {32, 32}}};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008234 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008235
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008236 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008237}
8238
Chris Forbes3b97e932016-09-07 11:29:24 +12008239TEST_F(VkLayerTest, RenderPassExcessiveNextSubpass) {
8240 TEST_DESCRIPTION("Test that an error is produced when CmdNextSubpass is "
8241 "called too many times in a renderpass instance");
8242
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008243 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdNextSubpass(): Attempted to advance "
8244 "beyond final subpass");
Chris Forbes3b97e932016-09-07 11:29:24 +12008245
8246 ASSERT_NO_FATAL_FAILURE(InitState());
8247 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8248
8249 BeginCommandBuffer();
8250
8251 // error here.
8252 vkCmdNextSubpass(m_commandBuffer->GetBufferHandle(), VK_SUBPASS_CONTENTS_INLINE);
8253 m_errorMonitor->VerifyFound();
8254
8255 EndCommandBuffer();
8256}
8257
Chris Forbes6d624702016-09-07 13:57:05 +12008258TEST_F(VkLayerTest, RenderPassEndedBeforeFinalSubpass) {
8259 TEST_DESCRIPTION("Test that an error is produced when CmdEndRenderPass is "
8260 "called before the final subpass has been reached");
8261
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008262 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdEndRenderPass(): Called before reaching "
8263 "final subpass");
Chris Forbes6d624702016-09-07 13:57:05 +12008264
8265 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008266 VkSubpassDescription sd[2] = {{0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr},
8267 {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr}};
Chris Forbes6d624702016-09-07 13:57:05 +12008268
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008269 VkRenderPassCreateInfo rcpi = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 2, sd, 0, nullptr};
Chris Forbes6d624702016-09-07 13:57:05 +12008270
8271 VkRenderPass rp;
8272 VkResult err = vkCreateRenderPass(m_device->device(), &rcpi, nullptr, &rp);
8273 ASSERT_VK_SUCCESS(err);
8274
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008275 VkFramebufferCreateInfo fbci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 0, nullptr, 16, 16, 1};
Chris Forbes6d624702016-09-07 13:57:05 +12008276
8277 VkFramebuffer fb;
8278 err = vkCreateFramebuffer(m_device->device(), &fbci, nullptr, &fb);
8279 ASSERT_VK_SUCCESS(err);
8280
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008281 m_commandBuffer->BeginCommandBuffer(); // no implicit RP begin
Chris Forbes6d624702016-09-07 13:57:05 +12008282
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008283 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 +12008284
8285 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
8286
8287 // Error here.
8288 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
8289 m_errorMonitor->VerifyFound();
8290
8291 // Clean up.
8292 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
8293 vkDestroyRenderPass(m_device->device(), rp, nullptr);
8294}
8295
Karl Schultz9e66a292016-04-21 15:57:51 -06008296TEST_F(VkLayerTest, BufferMemoryBarrierNoBuffer) {
8297 // Try to add a buffer memory barrier with no buffer.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008298 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8299 "required parameter pBufferMemoryBarriers[0].buffer specified as VK_NULL_HANDLE");
Karl Schultz9e66a292016-04-21 15:57:51 -06008300
8301 ASSERT_NO_FATAL_FAILURE(InitState());
8302 BeginCommandBuffer();
8303
8304 VkBufferMemoryBarrier buf_barrier = {};
8305 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
8306 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8307 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
8308 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8309 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8310 buf_barrier.buffer = VK_NULL_HANDLE;
8311 buf_barrier.offset = 0;
8312 buf_barrier.size = VK_WHOLE_SIZE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008313 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8314 nullptr, 1, &buf_barrier, 0, nullptr);
Karl Schultz9e66a292016-04-21 15:57:51 -06008315
8316 m_errorMonitor->VerifyFound();
8317}
8318
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008319TEST_F(VkLayerTest, InvalidBarriers) {
8320 TEST_DESCRIPTION("A variety of ways to get VK_INVALID_BARRIER ");
8321
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008322 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Barriers cannot be set during subpass");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008323
8324 ASSERT_NO_FATAL_FAILURE(InitState());
8325 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8326
8327 VkMemoryBarrier mem_barrier = {};
8328 mem_barrier.sType = VK_STRUCTURE_TYPE_MEMORY_BARRIER;
8329 mem_barrier.pNext = NULL;
8330 mem_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8331 mem_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
8332 BeginCommandBuffer();
8333 // BeginCommandBuffer() starts a render pass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008334 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 1,
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008335 &mem_barrier, 0, nullptr, 0, nullptr);
8336 m_errorMonitor->VerifyFound();
8337
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008338 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Image Layout cannot be transitioned to UNDEFINED");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008339 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008340 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 -06008341 ASSERT_TRUE(image.initialized());
8342 VkImageMemoryBarrier img_barrier = {};
8343 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
8344 img_barrier.pNext = NULL;
8345 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8346 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
8347 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8348 // New layout can't be UNDEFINED
8349 img_barrier.newLayout = VK_IMAGE_LAYOUT_UNDEFINED;
8350 img_barrier.image = image.handle();
8351 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8352 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8353 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8354 img_barrier.subresourceRange.baseArrayLayer = 0;
8355 img_barrier.subresourceRange.baseMipLevel = 0;
8356 img_barrier.subresourceRange.layerCount = 1;
8357 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008358 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8359 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008360 m_errorMonitor->VerifyFound();
8361 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8362
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008363 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Subresource must have the sum of the "
8364 "baseArrayLayer");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008365 // baseArrayLayer + layerCount must be <= image's arrayLayers
8366 img_barrier.subresourceRange.baseArrayLayer = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008367 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8368 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008369 m_errorMonitor->VerifyFound();
8370 img_barrier.subresourceRange.baseArrayLayer = 0;
8371
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008372 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Subresource must have the sum of the baseMipLevel");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008373 // baseMipLevel + levelCount must be <= image's mipLevels
8374 img_barrier.subresourceRange.baseMipLevel = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008375 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8376 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008377 m_errorMonitor->VerifyFound();
8378 img_barrier.subresourceRange.baseMipLevel = 0;
8379
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008380 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 -06008381 vk_testing::Buffer buffer;
Mark Lobodzinskibdf378a2016-12-12 17:11:50 -07008382 VkMemoryPropertyFlags mem_reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
8383 buffer.init_as_src_and_dst(*m_device, 256, mem_reqs);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008384 VkBufferMemoryBarrier buf_barrier = {};
8385 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
8386 buf_barrier.pNext = NULL;
8387 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8388 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
8389 buf_barrier.buffer = buffer.handle();
8390 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8391 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8392 buf_barrier.offset = 0;
8393 buf_barrier.size = VK_WHOLE_SIZE;
8394 // Can't send buffer barrier during a render pass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008395 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8396 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008397 m_errorMonitor->VerifyFound();
8398 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
8399
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008400 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "which is not less than total size");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008401 buf_barrier.offset = 257;
8402 // Offset greater than total size
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008403 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8404 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008405 m_errorMonitor->VerifyFound();
8406 buf_barrier.offset = 0;
8407
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008408 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "whose sum is greater than total size");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008409 buf_barrier.size = 257;
8410 // Size greater than total size
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008411 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8412 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008413 m_errorMonitor->VerifyFound();
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008414
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008415 // Now exercise barrier aspect bit errors, first DS
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06008416 m_errorMonitor->SetDesiredFailureMsg(
8417 VK_DEBUG_REPORT_ERROR_BIT_EXT,
8418 "Combination depth/stencil image formats can have only the VK_IMAGE_ASPECT_DEPTH_BIT and VK_IMAGE_ASPECT_STENCIL_BIT set.");
8419 m_errorMonitor->SetDesiredFailureMsg(
8420 VK_DEBUG_REPORT_ERROR_BIT_EXT,
8421 "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 -06008422 VkDepthStencilObj ds_image(m_device);
8423 ds_image.Init(m_device, 128, 128, VK_FORMAT_D24_UNORM_S8_UINT);
8424 ASSERT_TRUE(ds_image.initialized());
Tobin Ehlis15684a02016-07-21 14:55:26 -06008425 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
8426 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008427 img_barrier.image = ds_image.handle();
Tobin Ehlis15684a02016-07-21 14:55:26 -06008428 // Use of COLOR aspect on DS image is error
8429 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008430 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8431 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008432 m_errorMonitor->VerifyFound();
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008433 // Now test depth-only
8434 VkFormatProperties format_props;
8435
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008436 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_D16_UNORM, &format_props);
8437 if (format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) {
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06008438 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8439 "Depth-only image formats must have the VK_IMAGE_ASPECT_DEPTH_BIT set.");
8440 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8441 "Depth-only image formats can have only the VK_IMAGE_ASPECT_DEPTH_BIT set.");
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008442 VkDepthStencilObj d_image(m_device);
8443 d_image.Init(m_device, 128, 128, VK_FORMAT_D16_UNORM);
8444 ASSERT_TRUE(d_image.initialized());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008445 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
Tobin Ehlis15684a02016-07-21 14:55:26 -06008446 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008447 img_barrier.image = d_image.handle();
Tobin Ehlis15684a02016-07-21 14:55:26 -06008448 // Use of COLOR aspect on depth image is error
8449 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008450 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
8451 0, nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008452 m_errorMonitor->VerifyFound();
8453 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008454 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_S8_UINT, &format_props);
8455 if (format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) {
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008456 // Now test stencil-only
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06008457 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8458 "Stencil-only image formats must have the VK_IMAGE_ASPECT_STENCIL_BIT set.");
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008459 VkDepthStencilObj s_image(m_device);
8460 s_image.Init(m_device, 128, 128, VK_FORMAT_S8_UINT);
8461 ASSERT_TRUE(s_image.initialized());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008462 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
Tobin Ehlis15684a02016-07-21 14:55:26 -06008463 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008464 img_barrier.image = s_image.handle();
Tobin Ehlis15684a02016-07-21 14:55:26 -06008465 // Use of COLOR aspect on depth image is error
8466 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008467 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
8468 0, nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008469 m_errorMonitor->VerifyFound();
8470 }
8471 // Finally test color
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06008472 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8473 "Color image formats must have the VK_IMAGE_ASPECT_COLOR_BIT set.");
8474 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8475 "Color image formats must have ONLY the VK_IMAGE_ASPECT_COLOR_BIT set.");
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008476 VkImageObj c_image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008477 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 -06008478 ASSERT_TRUE(c_image.initialized());
8479 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8480 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
8481 img_barrier.image = c_image.handle();
8482 // Set aspect to depth (non-color)
8483 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008484 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8485 nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008486 m_errorMonitor->VerifyFound();
Mark Lobodzinskibdf378a2016-12-12 17:11:50 -07008487
8488 // Attempt to mismatch barriers/waitEvents calls with incompatible queues
8489
8490 // Create command pool with incompatible queueflags
8491 const std::vector<VkQueueFamilyProperties> queue_props = m_device->queue_props;
8492 uint32_t queue_family_index = UINT32_MAX;
8493 for (uint32_t i = 0; i < queue_props.size(); i++) {
8494 if ((queue_props[i].queueFlags & VK_QUEUE_COMPUTE_BIT) == 0) {
8495 queue_family_index = i;
8496 break;
8497 }
8498 }
8499 if (queue_family_index == UINT32_MAX) {
8500 printf("No non-compute queue found; skipped.\n");
8501 return;
8502 }
8503 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02513);
8504
8505 VkCommandPool command_pool;
8506 VkCommandPoolCreateInfo pool_create_info{};
8507 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
8508 pool_create_info.queueFamilyIndex = queue_family_index;
8509 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
8510 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
8511
8512 // Allocate a command buffer
8513 VkCommandBuffer bad_command_buffer;
8514 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
8515 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
8516 command_buffer_allocate_info.commandPool = command_pool;
8517 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
8518 command_buffer_allocate_info.commandBufferCount = 1;
8519 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &bad_command_buffer));
8520
8521 VkCommandBufferBeginInfo cbbi = {};
8522 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
8523 vkBeginCommandBuffer(bad_command_buffer, &cbbi);
8524 buf_barrier.offset = 0;
8525 buf_barrier.size = VK_WHOLE_SIZE;
8526 vkCmdPipelineBarrier(bad_command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 1,
8527 &buf_barrier, 0, nullptr);
8528 m_errorMonitor->VerifyFound();
8529
8530 if ((queue_props[queue_family_index].queueFlags & VK_QUEUE_GRAPHICS_BIT) == 0) {
8531 vkEndCommandBuffer(bad_command_buffer);
8532 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
8533 printf("The non-compute queue does not support graphics; skipped.\n");
8534 return;
8535 }
8536 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02510);
8537 VkEvent event;
8538 VkEventCreateInfo event_create_info{};
8539 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
8540 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
8541 vkCmdWaitEvents(bad_command_buffer, 1, &event, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, nullptr, 0,
8542 nullptr, 0, nullptr);
8543 m_errorMonitor->VerifyFound();
8544
8545 vkEndCommandBuffer(bad_command_buffer);
8546 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008547}
8548
Tony Barbour18ba25c2016-09-29 13:42:40 -06008549TEST_F(VkLayerTest, LayoutFromPresentWithoutAccessMemoryRead) {
8550 // Transition an image away from PRESENT_SRC_KHR without ACCESS_MEMORY_READ in srcAccessMask
8551
8552 m_errorMonitor->SetDesiredFailureMsg(
8553 VK_DEBUG_REPORT_WARNING_BIT_EXT,
8554 "must have required access bit");
8555 ASSERT_NO_FATAL_FAILURE(InitState());
8556 VkImageObj image(m_device);
Tony Barbour256c80a2016-10-05 13:23:46 -06008557 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 -06008558 ASSERT_TRUE(image.initialized());
8559
8560 VkImageMemoryBarrier barrier = {};
8561 VkImageSubresourceRange range;
8562 barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
8563 barrier.srcAccessMask = 0;
8564 barrier.srcAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
8565 barrier.dstAccessMask = VK_ACCESS_MEMORY_READ_BIT;
8566 barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8567 barrier.newLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
8568 barrier.image = image.handle();
8569 range.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8570 range.baseMipLevel = 0;
8571 range.levelCount = 1;
8572 range.baseArrayLayer = 0;
8573 range.layerCount = 1;
8574 barrier.subresourceRange = range;
8575 VkCommandBufferObj cmdbuf(m_device, m_commandPool);
8576 cmdbuf.BeginCommandBuffer();
8577 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
8578 &barrier);
8579 barrier.oldLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
8580 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
8581 barrier.srcAccessMask = 0;
8582 barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
8583 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
8584 &barrier);
8585
8586 m_errorMonitor->VerifyFound();
8587}
8588
Karl Schultz6addd812016-02-02 17:17:23 -07008589TEST_F(VkLayerTest, IdxBufferAlignmentError) {
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008590 // Bind a BeginRenderPass within an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07008591 VkResult err;
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008592
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008593 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdBindIndexBuffer() offset (0x7) does not fall on ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008594
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008595 ASSERT_NO_FATAL_FAILURE(InitState());
8596 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008597 uint32_t qfi = 0;
8598 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008599 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
8600 buffCI.size = 1024;
8601 buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
8602 buffCI.queueFamilyIndexCount = 1;
8603 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008604
8605 VkBuffer ib;
Chia-I Wuf7458c52015-10-26 21:10:41 +08008606 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008607 ASSERT_VK_SUCCESS(err);
8608
8609 BeginCommandBuffer();
8610 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07008611 // vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
8612 // VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008613 // Should error before calling to driver so don't care about actual data
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008614 vkCmdBindIndexBuffer(m_commandBuffer->GetBufferHandle(), ib, 7, VK_INDEX_TYPE_UINT16);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008615
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008616 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06008617
Chia-I Wuf7458c52015-10-26 21:10:41 +08008618 vkDestroyBuffer(m_device->device(), ib, NULL);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008619}
8620
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07008621TEST_F(VkLayerTest, InvalidQueueFamilyIndex) {
8622 // Create an out-of-range queueFamilyIndex
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008623 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8624 "vkCreateBuffer: pCreateInfo->pQueueFamilyIndices[0] (777) must be one "
8625 "of the indices specified when the device was created, via the "
8626 "VkDeviceQueueCreateInfo structure.");
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07008627
8628 ASSERT_NO_FATAL_FAILURE(InitState());
8629 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8630 VkBufferCreateInfo buffCI = {};
8631 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
8632 buffCI.size = 1024;
8633 buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
8634 buffCI.queueFamilyIndexCount = 1;
8635 // Introduce failure by specifying invalid queue_family_index
8636 uint32_t qfi = 777;
8637 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis24aab042016-03-24 10:54:18 -06008638 buffCI.sharingMode = VK_SHARING_MODE_CONCURRENT; // qfi only matters in CONCURRENT mode
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07008639
8640 VkBuffer ib;
8641 vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
8642
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008643 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06008644 vkDestroyBuffer(m_device->device(), ib, NULL);
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07008645}
8646
Karl Schultz6addd812016-02-02 17:17:23 -07008647TEST_F(VkLayerTest, ExecuteCommandsPrimaryCB) {
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -06008648TEST_DESCRIPTION("Attempt vkCmdExecuteCommands with a primary command buffer"
Tobin Ehlis0c94db02016-07-19 10:49:32 -06008649 " (should only be secondary)");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008650
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06008651 ASSERT_NO_FATAL_FAILURE(InitState());
8652 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06008653
Chris Forbesf29a84f2016-10-06 18:39:28 +13008654 // An empty primary command buffer
8655 VkCommandBufferObj cb(m_device, m_commandPool);
8656 cb.BeginCommandBuffer();
8657 cb.EndCommandBuffer();
Tobin Ehlis0c94db02016-07-19 10:49:32 -06008658
Chris Forbesf29a84f2016-10-06 18:39:28 +13008659 m_commandBuffer->BeginCommandBuffer();
8660 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
8661 VkCommandBuffer handle = cb.handle();
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06008662
Chris Forbesf29a84f2016-10-06 18:39:28 +13008663 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdExecuteCommands() called w/ Primary Cmd Buffer ");
8664 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &handle);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008665 m_errorMonitor->VerifyFound();
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06008666}
8667
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008668TEST_F(VkLayerTest, DSUsageBitsErrors) {
8669 TEST_DESCRIPTION("Attempt to update descriptor sets for images and buffers "
8670 "that do not have correct usage bits sets.");
8671 VkResult err;
8672
8673 ASSERT_NO_FATAL_FAILURE(InitState());
8674 VkDescriptorPoolSize ds_type_count[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
8675 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
8676 ds_type_count[i].type = VkDescriptorType(i);
8677 ds_type_count[i].descriptorCount = 1;
8678 }
8679 VkDescriptorPoolCreateInfo ds_pool_ci = {};
8680 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8681 ds_pool_ci.pNext = NULL;
8682 ds_pool_ci.maxSets = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
8683 ds_pool_ci.poolSizeCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
8684 ds_pool_ci.pPoolSizes = ds_type_count;
8685
8686 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008687 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008688 ASSERT_VK_SUCCESS(err);
8689
8690 // Create 10 layouts where each has a single descriptor of different type
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008691 VkDescriptorSetLayoutBinding dsl_binding[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008692 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
8693 dsl_binding[i].binding = 0;
8694 dsl_binding[i].descriptorType = VkDescriptorType(i);
8695 dsl_binding[i].descriptorCount = 1;
8696 dsl_binding[i].stageFlags = VK_SHADER_STAGE_ALL;
8697 dsl_binding[i].pImmutableSamplers = NULL;
8698 }
8699
8700 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
8701 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8702 ds_layout_ci.pNext = NULL;
8703 ds_layout_ci.bindingCount = 1;
8704 VkDescriptorSetLayout ds_layouts[VK_DESCRIPTOR_TYPE_RANGE_SIZE];
8705 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
8706 ds_layout_ci.pBindings = dsl_binding + i;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008707 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, ds_layouts + i);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008708 ASSERT_VK_SUCCESS(err);
8709 }
8710 VkDescriptorSet descriptor_sets[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
8711 VkDescriptorSetAllocateInfo alloc_info = {};
8712 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
8713 alloc_info.descriptorSetCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
8714 alloc_info.descriptorPool = ds_pool;
8715 alloc_info.pSetLayouts = ds_layouts;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008716 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptor_sets);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008717 ASSERT_VK_SUCCESS(err);
8718
8719 // Create a buffer & bufferView to be used for invalid updates
8720 VkBufferCreateInfo buff_ci = {};
8721 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
8722 // This usage is not valid for any descriptor type
8723 buff_ci.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
8724 buff_ci.size = 256;
8725 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
8726 VkBuffer buffer;
8727 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
8728 ASSERT_VK_SUCCESS(err);
8729
8730 VkBufferViewCreateInfo buff_view_ci = {};
8731 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
8732 buff_view_ci.buffer = buffer;
8733 buff_view_ci.format = VK_FORMAT_R8_UNORM;
8734 buff_view_ci.range = VK_WHOLE_SIZE;
8735 VkBufferView buff_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008736 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buff_view);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008737 ASSERT_VK_SUCCESS(err);
8738
8739 // Create an image to be used for invalid updates
8740 VkImageCreateInfo image_ci = {};
8741 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
8742 image_ci.imageType = VK_IMAGE_TYPE_2D;
8743 image_ci.format = VK_FORMAT_R8G8B8A8_UNORM;
8744 image_ci.extent.width = 64;
8745 image_ci.extent.height = 64;
8746 image_ci.extent.depth = 1;
8747 image_ci.mipLevels = 1;
8748 image_ci.arrayLayers = 1;
8749 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
8750 image_ci.tiling = VK_IMAGE_TILING_LINEAR;
8751 image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
8752 // This usage is not valid for any descriptor type
8753 image_ci.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
8754 image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
8755 VkImage image;
8756 err = vkCreateImage(m_device->device(), &image_ci, NULL, &image);
8757 ASSERT_VK_SUCCESS(err);
8758 // Bind memory to image
8759 VkMemoryRequirements mem_reqs;
8760 VkDeviceMemory image_mem;
8761 bool pass;
8762 VkMemoryAllocateInfo mem_alloc = {};
8763 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
8764 mem_alloc.pNext = NULL;
8765 mem_alloc.allocationSize = 0;
8766 mem_alloc.memoryTypeIndex = 0;
8767 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
8768 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008769 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008770 ASSERT_TRUE(pass);
8771 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
8772 ASSERT_VK_SUCCESS(err);
8773 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
8774 ASSERT_VK_SUCCESS(err);
8775 // Now create view for image
8776 VkImageViewCreateInfo image_view_ci = {};
8777 image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
8778 image_view_ci.image = image;
8779 image_view_ci.format = VK_FORMAT_R8G8B8A8_UNORM;
8780 image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D;
8781 image_view_ci.subresourceRange.layerCount = 1;
8782 image_view_ci.subresourceRange.baseArrayLayer = 0;
8783 image_view_ci.subresourceRange.levelCount = 1;
8784 image_view_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8785 VkImageView image_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008786 err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, &image_view);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008787 ASSERT_VK_SUCCESS(err);
8788
8789 VkDescriptorBufferInfo buff_info = {};
8790 buff_info.buffer = buffer;
8791 VkDescriptorImageInfo img_info = {};
8792 img_info.imageView = image_view;
8793 VkWriteDescriptorSet descriptor_write = {};
8794 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
8795 descriptor_write.dstBinding = 0;
8796 descriptor_write.descriptorCount = 1;
8797 descriptor_write.pTexelBufferView = &buff_view;
8798 descriptor_write.pBufferInfo = &buff_info;
8799 descriptor_write.pImageInfo = &img_info;
8800
8801 // These error messages align with VkDescriptorType struct
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008802 const char *error_msgs[] = {"", // placeholder, no error for SAMPLER descriptor
8803 " does not have VK_IMAGE_USAGE_SAMPLED_BIT set.",
8804 " does not have VK_IMAGE_USAGE_SAMPLED_BIT set.",
8805 " does not have VK_IMAGE_USAGE_STORAGE_BIT set.",
8806 " does not have VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT set.",
8807 " does not have VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT set.",
8808 " does not have VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT set.",
8809 " does not have VK_BUFFER_USAGE_STORAGE_BUFFER_BIT set.",
8810 " does not have VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT set.",
8811 " does not have VK_BUFFER_USAGE_STORAGE_BUFFER_BIT set.",
8812 " does not have VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT set."};
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008813 // Start loop at 1 as SAMPLER desc type has no usage bit error
8814 for (uint32_t i = 1; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
8815 descriptor_write.descriptorType = VkDescriptorType(i);
8816 descriptor_write.dstSet = descriptor_sets[i];
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008817 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, error_msgs[i]);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008818
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008819 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008820
8821 m_errorMonitor->VerifyFound();
8822 vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[i], NULL);
8823 }
8824 vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[0], NULL);
8825 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06008826 vkFreeMemory(m_device->device(), image_mem, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008827 vkDestroyImageView(m_device->device(), image_view, NULL);
8828 vkDestroyBuffer(m_device->device(), buffer, NULL);
8829 vkDestroyBufferView(m_device->device(), buff_view, NULL);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008830 vkFreeDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_TYPE_RANGE_SIZE, descriptor_sets);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008831 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
8832}
8833
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008834TEST_F(VkLayerTest, DSBufferInfoErrors) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008835 TEST_DESCRIPTION("Attempt to update buffer descriptor set that has incorrect "
8836 "parameters in VkDescriptorBufferInfo struct. This includes:\n"
8837 "1. offset value greater than buffer size\n"
8838 "2. range value of 0\n"
8839 "3. range value greater than buffer (size - offset)");
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008840 VkResult err;
8841
8842 ASSERT_NO_FATAL_FAILURE(InitState());
8843 VkDescriptorPoolSize ds_type_count = {};
8844 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
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 = 1;
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 Ehlis585f66d2016-07-01 18:23:58 -06008856 ASSERT_VK_SUCCESS(err);
8857
8858 // Create layout with single uniform buffer descriptor
8859 VkDescriptorSetLayoutBinding dsl_binding = {};
8860 dsl_binding.binding = 0;
8861 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8862 dsl_binding.descriptorCount = 1;
8863 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8864 dsl_binding.pImmutableSamplers = NULL;
8865
8866 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
8867 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8868 ds_layout_ci.pNext = NULL;
8869 ds_layout_ci.bindingCount = 1;
8870 ds_layout_ci.pBindings = &dsl_binding;
8871 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008872 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008873 ASSERT_VK_SUCCESS(err);
8874
8875 VkDescriptorSet descriptor_set = {};
8876 VkDescriptorSetAllocateInfo alloc_info = {};
8877 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
8878 alloc_info.descriptorSetCount = 1;
8879 alloc_info.descriptorPool = ds_pool;
8880 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008881 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008882 ASSERT_VK_SUCCESS(err);
8883
8884 // Create a buffer to be used for invalid updates
8885 VkBufferCreateInfo buff_ci = {};
8886 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
8887 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
8888 buff_ci.size = 256;
8889 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
8890 VkBuffer buffer;
8891 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
8892 ASSERT_VK_SUCCESS(err);
8893 // Have to bind memory to buffer before descriptor update
8894 VkMemoryAllocateInfo mem_alloc = {};
8895 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
8896 mem_alloc.pNext = NULL;
8897 mem_alloc.allocationSize = 256;
8898 mem_alloc.memoryTypeIndex = 0;
8899
8900 VkMemoryRequirements mem_reqs;
8901 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008902 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008903 if (!pass) {
8904 vkDestroyBuffer(m_device->device(), buffer, NULL);
8905 return;
8906 }
8907
8908 VkDeviceMemory mem;
8909 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
8910 ASSERT_VK_SUCCESS(err);
8911 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
8912 ASSERT_VK_SUCCESS(err);
8913
8914 VkDescriptorBufferInfo buff_info = {};
8915 buff_info.buffer = buffer;
8916 // First make offset 1 larger than buffer size
8917 buff_info.offset = 257;
8918 buff_info.range = VK_WHOLE_SIZE;
8919 VkWriteDescriptorSet descriptor_write = {};
8920 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
8921 descriptor_write.dstBinding = 0;
8922 descriptor_write.descriptorCount = 1;
8923 descriptor_write.pTexelBufferView = nullptr;
8924 descriptor_write.pBufferInfo = &buff_info;
8925 descriptor_write.pImageInfo = nullptr;
8926
8927 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8928 descriptor_write.dstSet = descriptor_set;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008929 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " offset of 257 is greater than buffer ");
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008930
8931 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8932
8933 m_errorMonitor->VerifyFound();
8934 // Now cause error due to range of 0
8935 buff_info.offset = 0;
8936 buff_info.range = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008937 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8938 " range is not VK_WHOLE_SIZE and is zero, which is not allowed.");
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008939
8940 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8941
8942 m_errorMonitor->VerifyFound();
8943 // Now cause error due to range exceeding buffer size - offset
8944 buff_info.offset = 128;
8945 buff_info.range = 200;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008946 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 -06008947
8948 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8949
8950 m_errorMonitor->VerifyFound();
Mark Lobodzinski4bb54092016-07-06 14:27:19 -06008951 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008952 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8953 vkDestroyBuffer(m_device->device(), buffer, NULL);
8954 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
8955 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
8956}
8957
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008958TEST_F(VkLayerTest, DSAspectBitsErrors) {
8959 // TODO : Initially only catching case where DEPTH & STENCIL aspect bits
8960 // are set, but could expand this test to hit more cases.
8961 TEST_DESCRIPTION("Attempt to update descriptor sets for images "
8962 "that do not have correct aspect bits sets.");
8963 VkResult err;
8964
8965 ASSERT_NO_FATAL_FAILURE(InitState());
8966 VkDescriptorPoolSize ds_type_count = {};
8967 ds_type_count.type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
8968 ds_type_count.descriptorCount = 1;
8969
8970 VkDescriptorPoolCreateInfo ds_pool_ci = {};
8971 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8972 ds_pool_ci.pNext = NULL;
8973 ds_pool_ci.maxSets = 5;
8974 ds_pool_ci.poolSizeCount = 1;
8975 ds_pool_ci.pPoolSizes = &ds_type_count;
8976
8977 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008978 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008979 ASSERT_VK_SUCCESS(err);
8980
8981 VkDescriptorSetLayoutBinding dsl_binding = {};
8982 dsl_binding.binding = 0;
8983 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
8984 dsl_binding.descriptorCount = 1;
8985 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8986 dsl_binding.pImmutableSamplers = NULL;
8987
8988 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
8989 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8990 ds_layout_ci.pNext = NULL;
8991 ds_layout_ci.bindingCount = 1;
8992 ds_layout_ci.pBindings = &dsl_binding;
8993 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008994 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008995 ASSERT_VK_SUCCESS(err);
8996
8997 VkDescriptorSet descriptor_set = {};
8998 VkDescriptorSetAllocateInfo alloc_info = {};
8999 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
9000 alloc_info.descriptorSetCount = 1;
9001 alloc_info.descriptorPool = ds_pool;
9002 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009003 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009004 ASSERT_VK_SUCCESS(err);
9005
9006 // Create an image to be used for invalid updates
9007 VkImageCreateInfo image_ci = {};
9008 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
9009 image_ci.imageType = VK_IMAGE_TYPE_2D;
9010 image_ci.format = VK_FORMAT_D24_UNORM_S8_UINT;
9011 image_ci.extent.width = 64;
9012 image_ci.extent.height = 64;
9013 image_ci.extent.depth = 1;
9014 image_ci.mipLevels = 1;
9015 image_ci.arrayLayers = 1;
9016 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
9017 image_ci.tiling = VK_IMAGE_TILING_LINEAR;
9018 image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
9019 image_ci.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
9020 image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
9021 VkImage image;
9022 err = vkCreateImage(m_device->device(), &image_ci, NULL, &image);
9023 ASSERT_VK_SUCCESS(err);
9024 // Bind memory to image
9025 VkMemoryRequirements mem_reqs;
9026 VkDeviceMemory image_mem;
9027 bool pass;
9028 VkMemoryAllocateInfo mem_alloc = {};
9029 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
9030 mem_alloc.pNext = NULL;
9031 mem_alloc.allocationSize = 0;
9032 mem_alloc.memoryTypeIndex = 0;
9033 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
9034 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009035 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009036 ASSERT_TRUE(pass);
9037 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
9038 ASSERT_VK_SUCCESS(err);
9039 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
9040 ASSERT_VK_SUCCESS(err);
9041 // Now create view for image
9042 VkImageViewCreateInfo image_view_ci = {};
9043 image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
9044 image_view_ci.image = image;
9045 image_view_ci.format = VK_FORMAT_D24_UNORM_S8_UINT;
9046 image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D;
9047 image_view_ci.subresourceRange.layerCount = 1;
9048 image_view_ci.subresourceRange.baseArrayLayer = 0;
9049 image_view_ci.subresourceRange.levelCount = 1;
9050 // Setting both depth & stencil aspect bits is illegal for descriptor
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009051 image_view_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009052
9053 VkImageView image_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009054 err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, &image_view);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009055 ASSERT_VK_SUCCESS(err);
9056
9057 VkDescriptorImageInfo img_info = {};
9058 img_info.imageView = image_view;
9059 VkWriteDescriptorSet descriptor_write = {};
9060 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
9061 descriptor_write.dstBinding = 0;
9062 descriptor_write.descriptorCount = 1;
9063 descriptor_write.pTexelBufferView = NULL;
9064 descriptor_write.pBufferInfo = NULL;
9065 descriptor_write.pImageInfo = &img_info;
9066 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
9067 descriptor_write.dstSet = descriptor_set;
9068 const char *error_msg = " please only set either VK_IMAGE_ASPECT_DEPTH_BIT "
9069 "or VK_IMAGE_ASPECT_STENCIL_BIT ";
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009070 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, error_msg);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009071
9072 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9073
9074 m_errorMonitor->VerifyFound();
9075 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9076 vkDestroyImage(m_device->device(), image, NULL);
9077 vkFreeMemory(m_device->device(), image_mem, NULL);
9078 vkDestroyImageView(m_device->device(), image_view, NULL);
9079 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
9080 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9081}
9082
Karl Schultz6addd812016-02-02 17:17:23 -07009083TEST_F(VkLayerTest, DSTypeMismatch) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009084 // Create DS w/ layout of one type and attempt Update w/ mis-matched type
Karl Schultz6addd812016-02-02 17:17:23 -07009085 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009086
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009087 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9088 " binding #0 with type VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER but update "
9089 "type is VK_DESCRIPTOR_TYPE_SAMPLER");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009090
Tobin Ehlis3b780662015-05-28 12:11:26 -06009091 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07009092 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009093 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009094 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9095 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009096
9097 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009098 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9099 ds_pool_ci.pNext = NULL;
9100 ds_pool_ci.maxSets = 1;
9101 ds_pool_ci.poolSizeCount = 1;
9102 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06009103
Tobin Ehlis3b780662015-05-28 12:11:26 -06009104 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009105 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009106 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -06009107 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009108 dsl_binding.binding = 0;
9109 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9110 dsl_binding.descriptorCount = 1;
9111 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9112 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009113
Tony Barboureb254902015-07-15 12:50:33 -06009114 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009115 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9116 ds_layout_ci.pNext = NULL;
9117 ds_layout_ci.bindingCount = 1;
9118 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06009119
Tobin Ehlis3b780662015-05-28 12:11:26 -06009120 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009121 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009122 ASSERT_VK_SUCCESS(err);
9123
9124 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009125 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009126 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009127 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009128 alloc_info.descriptorPool = ds_pool;
9129 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009130 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009131 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009132
Tobin Ehlis30db8f82016-05-05 08:19:48 -06009133 VkSamplerCreateInfo sampler_ci = {};
9134 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9135 sampler_ci.pNext = NULL;
9136 sampler_ci.magFilter = VK_FILTER_NEAREST;
9137 sampler_ci.minFilter = VK_FILTER_NEAREST;
9138 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9139 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9140 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9141 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9142 sampler_ci.mipLodBias = 1.0;
9143 sampler_ci.anisotropyEnable = VK_FALSE;
9144 sampler_ci.maxAnisotropy = 1;
9145 sampler_ci.compareEnable = VK_FALSE;
9146 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9147 sampler_ci.minLod = 1.0;
9148 sampler_ci.maxLod = 1.0;
9149 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9150 sampler_ci.unnormalizedCoordinates = VK_FALSE;
9151 VkSampler sampler;
9152 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
9153 ASSERT_VK_SUCCESS(err);
9154
9155 VkDescriptorImageInfo info = {};
9156 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009157
9158 VkWriteDescriptorSet descriptor_write;
9159 memset(&descriptor_write, 0, sizeof(descriptor_write));
9160 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009161 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009162 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009163 // This is a mismatched type for the layout which expects BUFFER
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009164 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06009165 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009166
9167 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9168
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009169 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009170
Chia-I Wuf7458c52015-10-26 21:10:41 +08009171 vkDestroySampler(m_device->device(), sampler, NULL);
9172 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9173 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009174}
9175
Karl Schultz6addd812016-02-02 17:17:23 -07009176TEST_F(VkLayerTest, DSUpdateOutOfBounds) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009177 // For overlapping Update, have arrayIndex exceed that of layout
Karl Schultz6addd812016-02-02 17:17:23 -07009178 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009179
Tobin Ehlisf922ef82016-11-30 10:19:14 -07009180 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00938);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009181
Tobin Ehlis3b780662015-05-28 12:11:26 -06009182 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07009183 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009184 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009185 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9186 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009187
9188 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009189 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9190 ds_pool_ci.pNext = NULL;
9191 ds_pool_ci.maxSets = 1;
9192 ds_pool_ci.poolSizeCount = 1;
9193 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06009194
Tobin Ehlis3b780662015-05-28 12:11:26 -06009195 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009196 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009197 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009198
Tony Barboureb254902015-07-15 12:50:33 -06009199 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009200 dsl_binding.binding = 0;
9201 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9202 dsl_binding.descriptorCount = 1;
9203 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9204 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -06009205
9206 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009207 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9208 ds_layout_ci.pNext = NULL;
9209 ds_layout_ci.bindingCount = 1;
9210 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06009211
Tobin Ehlis3b780662015-05-28 12:11:26 -06009212 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009213 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009214 ASSERT_VK_SUCCESS(err);
9215
9216 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009217 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009218 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009219 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009220 alloc_info.descriptorPool = ds_pool;
9221 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009222 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009223 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009224
Tobin Ehlis30db8f82016-05-05 08:19:48 -06009225 // Correctly update descriptor to avoid "NOT_UPDATED" error
9226 VkDescriptorBufferInfo buff_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009227 buff_info.buffer = VkBuffer(0); // Don't care about buffer handle for this test
Tobin Ehlis30db8f82016-05-05 08:19:48 -06009228 buff_info.offset = 0;
9229 buff_info.range = 1024;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009230
9231 VkWriteDescriptorSet descriptor_write;
9232 memset(&descriptor_write, 0, sizeof(descriptor_write));
9233 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009234 descriptor_write.dstSet = descriptorSet;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009235 descriptor_write.dstArrayElement = 1; /* This index out of bounds for the update */
Chia-I Wud50a7d72015-10-26 20:48:51 +08009236 descriptor_write.descriptorCount = 1;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06009237 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9238 descriptor_write.pBufferInfo = &buff_info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009239
9240 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9241
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009242 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009243
Chia-I Wuf7458c52015-10-26 21:10:41 +08009244 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9245 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009246}
9247
Karl Schultz6addd812016-02-02 17:17:23 -07009248TEST_F(VkLayerTest, InvalidDSUpdateIndex) {
Tobin Ehlisc8d352d2016-11-21 10:33:40 -07009249 // Create layout w/ count of 1 and attempt update to that layout w/ binding index 2
Karl Schultz6addd812016-02-02 17:17:23 -07009250 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009251
Tobin Ehlisc8d352d2016-11-21 10:33:40 -07009252 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00936);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009253
Tobin Ehlis3b780662015-05-28 12:11:26 -06009254 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07009255 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009256 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009257 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9258 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009259
9260 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009261 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9262 ds_pool_ci.pNext = NULL;
9263 ds_pool_ci.maxSets = 1;
9264 ds_pool_ci.poolSizeCount = 1;
9265 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06009266
Tobin Ehlis3b780662015-05-28 12:11:26 -06009267 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009268 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009269 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009270
Tony Barboureb254902015-07-15 12:50:33 -06009271 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009272 dsl_binding.binding = 0;
9273 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9274 dsl_binding.descriptorCount = 1;
9275 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9276 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -06009277
9278 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009279 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9280 ds_layout_ci.pNext = NULL;
9281 ds_layout_ci.bindingCount = 1;
9282 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009283 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009284 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009285 ASSERT_VK_SUCCESS(err);
9286
9287 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009288 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009289 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009290 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009291 alloc_info.descriptorPool = ds_pool;
9292 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009293 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009294 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009295
Tony Barboureb254902015-07-15 12:50:33 -06009296 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009297 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9298 sampler_ci.pNext = NULL;
9299 sampler_ci.magFilter = VK_FILTER_NEAREST;
9300 sampler_ci.minFilter = VK_FILTER_NEAREST;
9301 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9302 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9303 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9304 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9305 sampler_ci.mipLodBias = 1.0;
9306 sampler_ci.anisotropyEnable = VK_FALSE;
9307 sampler_ci.maxAnisotropy = 1;
9308 sampler_ci.compareEnable = VK_FALSE;
9309 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9310 sampler_ci.minLod = 1.0;
9311 sampler_ci.maxLod = 1.0;
9312 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9313 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tony Barboureb254902015-07-15 12:50:33 -06009314
Tobin Ehlis3b780662015-05-28 12:11:26 -06009315 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009316 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009317 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009318
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06009319 VkDescriptorImageInfo info = {};
9320 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009321
9322 VkWriteDescriptorSet descriptor_write;
9323 memset(&descriptor_write, 0, sizeof(descriptor_write));
9324 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009325 descriptor_write.dstSet = descriptorSet;
9326 descriptor_write.dstBinding = 2;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009327 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009328 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009329 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06009330 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009331
9332 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9333
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009334 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009335
Chia-I Wuf7458c52015-10-26 21:10:41 +08009336 vkDestroySampler(m_device->device(), sampler, NULL);
9337 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9338 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009339}
9340
Tobin Ehlise202b2d2016-11-21 10:36:16 -07009341TEST_F(VkLayerTest, DSUpdateEmptyBinding) {
9342 // Create layout w/ empty binding and attempt to update it
9343 VkResult err;
9344
9345 ASSERT_NO_FATAL_FAILURE(InitState());
9346
9347 VkDescriptorPoolSize ds_type_count = {};
9348 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
9349 ds_type_count.descriptorCount = 1;
9350
9351 VkDescriptorPoolCreateInfo ds_pool_ci = {};
9352 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9353 ds_pool_ci.pNext = NULL;
9354 ds_pool_ci.maxSets = 1;
9355 ds_pool_ci.poolSizeCount = 1;
9356 ds_pool_ci.pPoolSizes = &ds_type_count;
9357
9358 VkDescriptorPool ds_pool;
9359 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
9360 ASSERT_VK_SUCCESS(err);
9361
9362 VkDescriptorSetLayoutBinding dsl_binding = {};
9363 dsl_binding.binding = 0;
9364 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9365 dsl_binding.descriptorCount = 0;
9366 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9367 dsl_binding.pImmutableSamplers = NULL;
9368
9369 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9370 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9371 ds_layout_ci.pNext = NULL;
9372 ds_layout_ci.bindingCount = 1;
9373 ds_layout_ci.pBindings = &dsl_binding;
9374 VkDescriptorSetLayout ds_layout;
9375 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
9376 ASSERT_VK_SUCCESS(err);
9377
9378 VkDescriptorSet descriptor_set;
9379 VkDescriptorSetAllocateInfo alloc_info = {};
9380 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
9381 alloc_info.descriptorSetCount = 1;
9382 alloc_info.descriptorPool = ds_pool;
9383 alloc_info.pSetLayouts = &ds_layout;
9384 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
9385 ASSERT_VK_SUCCESS(err);
9386
9387 VkSamplerCreateInfo sampler_ci = {};
9388 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9389 sampler_ci.magFilter = VK_FILTER_NEAREST;
9390 sampler_ci.minFilter = VK_FILTER_NEAREST;
9391 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9392 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9393 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9394 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9395 sampler_ci.mipLodBias = 1.0;
9396 sampler_ci.maxAnisotropy = 1;
9397 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9398 sampler_ci.minLod = 1.0;
9399 sampler_ci.maxLod = 1.0;
9400 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9401
9402 VkSampler sampler;
9403 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
9404 ASSERT_VK_SUCCESS(err);
9405
9406 VkDescriptorImageInfo info = {};
9407 info.sampler = sampler;
9408
9409 VkWriteDescriptorSet descriptor_write;
9410 memset(&descriptor_write, 0, sizeof(descriptor_write));
9411 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
9412 descriptor_write.dstSet = descriptor_set;
9413 descriptor_write.dstBinding = 0;
9414 descriptor_write.descriptorCount = 1; // Lie here to avoid parameter_validation error
9415 // This is the wrong type, but empty binding error will be flagged first
9416 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9417 descriptor_write.pImageInfo = &info;
9418
9419 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02348);
9420 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9421 m_errorMonitor->VerifyFound();
9422
9423 vkDestroySampler(m_device->device(), sampler, NULL);
9424 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9425 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9426}
9427
Karl Schultz6addd812016-02-02 17:17:23 -07009428TEST_F(VkLayerTest, InvalidDSUpdateStruct) {
9429 // Call UpdateDS w/ struct type other than valid VK_STRUCTUR_TYPE_UPDATE_*
9430 // types
9431 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009432
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009433 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 -06009434
Tobin Ehlis3b780662015-05-28 12:11:26 -06009435 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski209b5292015-09-17 09:44:05 -06009436
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009437 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009438 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9439 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009440
9441 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009442 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9443 ds_pool_ci.pNext = NULL;
9444 ds_pool_ci.maxSets = 1;
9445 ds_pool_ci.poolSizeCount = 1;
9446 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06009447
Tobin Ehlis3b780662015-05-28 12:11:26 -06009448 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009449 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009450 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -06009451 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009452 dsl_binding.binding = 0;
9453 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9454 dsl_binding.descriptorCount = 1;
9455 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9456 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009457
Tony Barboureb254902015-07-15 12:50:33 -06009458 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009459 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9460 ds_layout_ci.pNext = NULL;
9461 ds_layout_ci.bindingCount = 1;
9462 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06009463
Tobin Ehlis3b780662015-05-28 12:11:26 -06009464 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009465 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009466 ASSERT_VK_SUCCESS(err);
9467
9468 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009469 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009470 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009471 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009472 alloc_info.descriptorPool = ds_pool;
9473 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009474 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009475 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009476
Tony Barboureb254902015-07-15 12:50:33 -06009477 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009478 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9479 sampler_ci.pNext = NULL;
9480 sampler_ci.magFilter = VK_FILTER_NEAREST;
9481 sampler_ci.minFilter = VK_FILTER_NEAREST;
9482 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9483 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9484 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9485 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9486 sampler_ci.mipLodBias = 1.0;
9487 sampler_ci.anisotropyEnable = VK_FALSE;
9488 sampler_ci.maxAnisotropy = 1;
9489 sampler_ci.compareEnable = VK_FALSE;
9490 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9491 sampler_ci.minLod = 1.0;
9492 sampler_ci.maxLod = 1.0;
9493 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9494 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009495 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009496 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009497 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009498
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06009499 VkDescriptorImageInfo info = {};
9500 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009501
9502 VkWriteDescriptorSet descriptor_write;
9503 memset(&descriptor_write, 0, sizeof(descriptor_write));
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009504 descriptor_write.sType = (VkStructureType)0x99999999; /* Intentionally broken struct type */
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009505 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009506 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009507 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009508 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06009509 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009510
9511 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9512
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009513 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009514
Chia-I Wuf7458c52015-10-26 21:10:41 +08009515 vkDestroySampler(m_device->device(), sampler, NULL);
9516 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9517 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009518}
9519
Karl Schultz6addd812016-02-02 17:17:23 -07009520TEST_F(VkLayerTest, SampleDescriptorUpdateError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009521 // Create a single Sampler descriptor and send it an invalid Sampler
Karl Schultz6addd812016-02-02 17:17:23 -07009522 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009523
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009524 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9525 "Attempted write update to sampler descriptor with invalid sampler");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009526
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009527 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07009528 // TODO : Farm Descriptor setup code to helper function(s) to reduce copied
9529 // code
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009530 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009531 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
9532 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009533
9534 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009535 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9536 ds_pool_ci.pNext = NULL;
9537 ds_pool_ci.maxSets = 1;
9538 ds_pool_ci.poolSizeCount = 1;
9539 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009540
9541 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009542 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009543 ASSERT_VK_SUCCESS(err);
9544
9545 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009546 dsl_binding.binding = 0;
9547 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9548 dsl_binding.descriptorCount = 1;
9549 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9550 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009551
9552 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009553 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9554 ds_layout_ci.pNext = NULL;
9555 ds_layout_ci.bindingCount = 1;
9556 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009557 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009558 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009559 ASSERT_VK_SUCCESS(err);
9560
9561 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009562 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009563 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009564 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009565 alloc_info.descriptorPool = ds_pool;
9566 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009567 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009568 ASSERT_VK_SUCCESS(err);
9569
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009570 VkSampler sampler = (VkSampler)((size_t)0xbaadbeef); // Sampler with invalid handle
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009571
9572 VkDescriptorImageInfo descriptor_info;
9573 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
9574 descriptor_info.sampler = sampler;
9575
9576 VkWriteDescriptorSet descriptor_write;
9577 memset(&descriptor_write, 0, sizeof(descriptor_write));
9578 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009579 descriptor_write.dstSet = descriptorSet;
9580 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009581 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009582 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9583 descriptor_write.pImageInfo = &descriptor_info;
9584
9585 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9586
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009587 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009588
Chia-I Wuf7458c52015-10-26 21:10:41 +08009589 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9590 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009591}
9592
Karl Schultz6addd812016-02-02 17:17:23 -07009593TEST_F(VkLayerTest, ImageViewDescriptorUpdateError) {
9594 // Create a single combined Image/Sampler descriptor and send it an invalid
9595 // imageView
9596 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009597
Karl Schultzf78bcdd2016-11-30 12:36:01 -07009598 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00943);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009599
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009600 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009601 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009602 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
9603 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009604
9605 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009606 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9607 ds_pool_ci.pNext = NULL;
9608 ds_pool_ci.maxSets = 1;
9609 ds_pool_ci.poolSizeCount = 1;
9610 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009611
9612 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009613 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009614 ASSERT_VK_SUCCESS(err);
9615
9616 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009617 dsl_binding.binding = 0;
9618 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
9619 dsl_binding.descriptorCount = 1;
9620 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9621 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009622
9623 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009624 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9625 ds_layout_ci.pNext = NULL;
9626 ds_layout_ci.bindingCount = 1;
9627 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009628 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009629 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009630 ASSERT_VK_SUCCESS(err);
9631
9632 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009633 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009634 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009635 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009636 alloc_info.descriptorPool = ds_pool;
9637 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009638 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009639 ASSERT_VK_SUCCESS(err);
9640
9641 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009642 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9643 sampler_ci.pNext = NULL;
9644 sampler_ci.magFilter = VK_FILTER_NEAREST;
9645 sampler_ci.minFilter = VK_FILTER_NEAREST;
9646 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9647 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9648 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9649 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9650 sampler_ci.mipLodBias = 1.0;
9651 sampler_ci.anisotropyEnable = VK_FALSE;
9652 sampler_ci.maxAnisotropy = 1;
9653 sampler_ci.compareEnable = VK_FALSE;
9654 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9655 sampler_ci.minLod = 1.0;
9656 sampler_ci.maxLod = 1.0;
9657 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9658 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009659
9660 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009661 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009662 ASSERT_VK_SUCCESS(err);
9663
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009664 VkImageView view = (VkImageView)((size_t)0xbaadbeef); // invalid imageView object
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009665
9666 VkDescriptorImageInfo descriptor_info;
9667 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
9668 descriptor_info.sampler = sampler;
9669 descriptor_info.imageView = view;
9670
9671 VkWriteDescriptorSet descriptor_write;
9672 memset(&descriptor_write, 0, sizeof(descriptor_write));
9673 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009674 descriptor_write.dstSet = descriptorSet;
9675 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009676 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009677 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
9678 descriptor_write.pImageInfo = &descriptor_info;
9679
9680 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9681
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009682 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009683
Chia-I Wuf7458c52015-10-26 21:10:41 +08009684 vkDestroySampler(m_device->device(), sampler, NULL);
9685 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9686 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009687}
9688
Karl Schultz6addd812016-02-02 17:17:23 -07009689TEST_F(VkLayerTest, CopyDescriptorUpdateErrors) {
9690 // Create DS w/ layout of 2 types, write update 1 and attempt to copy-update
9691 // into the other
9692 VkResult err;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009693
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009694 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " binding #1 with type "
9695 "VK_DESCRIPTOR_TYPE_SAMPLER. Types do "
9696 "not match.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009697
Tobin Ehlis04356f92015-10-27 16:35:27 -06009698 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07009699 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009700 VkDescriptorPoolSize ds_type_count[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009701 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9702 ds_type_count[0].descriptorCount = 1;
9703 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLER;
9704 ds_type_count[1].descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009705
9706 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009707 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9708 ds_pool_ci.pNext = NULL;
9709 ds_pool_ci.maxSets = 1;
9710 ds_pool_ci.poolSizeCount = 2;
9711 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009712
9713 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009714 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis04356f92015-10-27 16:35:27 -06009715 ASSERT_VK_SUCCESS(err);
9716 VkDescriptorSetLayoutBinding dsl_binding[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009717 dsl_binding[0].binding = 0;
9718 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9719 dsl_binding[0].descriptorCount = 1;
9720 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
9721 dsl_binding[0].pImmutableSamplers = NULL;
9722 dsl_binding[1].binding = 1;
9723 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9724 dsl_binding[1].descriptorCount = 1;
9725 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
9726 dsl_binding[1].pImmutableSamplers = NULL;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009727
9728 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009729 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9730 ds_layout_ci.pNext = NULL;
9731 ds_layout_ci.bindingCount = 2;
9732 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009733
9734 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009735 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis04356f92015-10-27 16:35:27 -06009736 ASSERT_VK_SUCCESS(err);
9737
9738 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009739 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009740 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009741 alloc_info.descriptorSetCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009742 alloc_info.descriptorPool = ds_pool;
9743 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009744 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis04356f92015-10-27 16:35:27 -06009745 ASSERT_VK_SUCCESS(err);
9746
9747 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009748 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9749 sampler_ci.pNext = NULL;
9750 sampler_ci.magFilter = VK_FILTER_NEAREST;
9751 sampler_ci.minFilter = VK_FILTER_NEAREST;
9752 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9753 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9754 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9755 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9756 sampler_ci.mipLodBias = 1.0;
9757 sampler_ci.anisotropyEnable = VK_FALSE;
9758 sampler_ci.maxAnisotropy = 1;
9759 sampler_ci.compareEnable = VK_FALSE;
9760 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9761 sampler_ci.minLod = 1.0;
9762 sampler_ci.maxLod = 1.0;
9763 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9764 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009765
9766 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009767 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis04356f92015-10-27 16:35:27 -06009768 ASSERT_VK_SUCCESS(err);
9769
9770 VkDescriptorImageInfo info = {};
9771 info.sampler = sampler;
9772
9773 VkWriteDescriptorSet descriptor_write;
9774 memset(&descriptor_write, 0, sizeof(VkWriteDescriptorSet));
9775 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009776 descriptor_write.dstSet = descriptorSet;
9777 descriptor_write.dstBinding = 1; // SAMPLER binding from layout above
Chia-I Wud50a7d72015-10-26 20:48:51 +08009778 descriptor_write.descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009779 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9780 descriptor_write.pImageInfo = &info;
9781 // This write update should succeed
9782 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9783 // Now perform a copy update that fails due to type mismatch
9784 VkCopyDescriptorSet copy_ds_update;
9785 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
9786 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
9787 copy_ds_update.srcSet = descriptorSet;
Mark Young29927482016-05-04 14:38:51 -06009788 copy_ds_update.srcBinding = 1; // Copy from SAMPLER binding
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009789 copy_ds_update.dstSet = descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -07009790 copy_ds_update.dstBinding = 0; // ERROR : copy to UNIFORM binding
Chia-I Wud50a7d72015-10-26 20:48:51 +08009791 copy_ds_update.descriptorCount = 1; // copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -06009792 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
9793
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009794 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -06009795 // Now perform a copy update that fails due to binding out of bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009796 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 -06009797 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
9798 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
9799 copy_ds_update.srcSet = descriptorSet;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009800 copy_ds_update.srcBinding = 3; // ERROR : Invalid binding for matching layout
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009801 copy_ds_update.dstSet = descriptorSet;
9802 copy_ds_update.dstBinding = 0;
Mark Young29927482016-05-04 14:38:51 -06009803 copy_ds_update.descriptorCount = 1; // Copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -06009804 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
9805
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009806 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009807
Tobin Ehlis04356f92015-10-27 16:35:27 -06009808 // Now perform a copy update that fails due to binding out of bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009809 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " binding#1 with offset index of 1 plus "
9810 "update array offset of 0 and update of "
9811 "5 descriptors oversteps total number "
9812 "of descriptors in set: 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009813
Tobin Ehlis04356f92015-10-27 16:35:27 -06009814 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
9815 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
9816 copy_ds_update.srcSet = descriptorSet;
9817 copy_ds_update.srcBinding = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009818 copy_ds_update.dstSet = descriptorSet;
9819 copy_ds_update.dstBinding = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009820 copy_ds_update.descriptorCount = 5; // ERROR copy 5 descriptors (out of bounds for layout)
Tobin Ehlis04356f92015-10-27 16:35:27 -06009821 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
9822
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009823 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -06009824
Chia-I Wuf7458c52015-10-26 21:10:41 +08009825 vkDestroySampler(m_device->device(), sampler, NULL);
9826 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9827 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis04356f92015-10-27 16:35:27 -06009828}
9829
Karl Schultz6addd812016-02-02 17:17:23 -07009830TEST_F(VkLayerTest, NumSamplesMismatch) {
9831 // Create CommandBuffer where MSAA samples doesn't match RenderPass
9832 // sampleCount
9833 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009834
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009835 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Num samples mismatch! ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009836
Tobin Ehlis3b780662015-05-28 12:11:26 -06009837 ASSERT_NO_FATAL_FAILURE(InitState());
9838 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009839 VkDescriptorPoolSize ds_type_count = {};
Tony Barboureb254902015-07-15 12:50:33 -06009840 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009841 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009842
9843 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009844 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9845 ds_pool_ci.pNext = NULL;
9846 ds_pool_ci.maxSets = 1;
9847 ds_pool_ci.poolSizeCount = 1;
9848 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06009849
Tobin Ehlis3b780662015-05-28 12:11:26 -06009850 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009851 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009852 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009853
Tony Barboureb254902015-07-15 12:50:33 -06009854 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08009855 dsl_binding.binding = 0;
Tony Barboureb254902015-07-15 12:50:33 -06009856 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08009857 dsl_binding.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009858 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9859 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009860
Tony Barboureb254902015-07-15 12:50:33 -06009861 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9862 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9863 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009864 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07009865 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06009866
Tobin Ehlis3b780662015-05-28 12:11:26 -06009867 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009868 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009869 ASSERT_VK_SUCCESS(err);
9870
9871 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009872 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009873 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009874 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009875 alloc_info.descriptorPool = ds_pool;
9876 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009877 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009878 ASSERT_VK_SUCCESS(err);
9879
Tony Barboureb254902015-07-15 12:50:33 -06009880 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009881 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07009882 pipe_ms_state_ci.pNext = NULL;
9883 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
9884 pipe_ms_state_ci.sampleShadingEnable = 0;
9885 pipe_ms_state_ci.minSampleShading = 1.0;
9886 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009887
Tony Barboureb254902015-07-15 12:50:33 -06009888 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009889 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9890 pipeline_layout_ci.pNext = NULL;
9891 pipeline_layout_ci.setLayoutCount = 1;
9892 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009893
9894 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009895 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009896 ASSERT_VK_SUCCESS(err);
9897
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009898 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
9899 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
9900 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -06009901 VkPipelineObj pipe(m_device);
9902 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06009903 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -06009904 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -06009905 pipe.SetMSAA(&pipe_ms_state_ci);
9906 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tobin Ehlis3b780662015-05-28 12:11:26 -06009907
Tony Barbourfe3351b2015-07-28 10:17:20 -06009908 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009909 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis3b780662015-05-28 12:11:26 -06009910
Mark Young29927482016-05-04 14:38:51 -06009911 // Render triangle (the error should trigger on the attempt to draw).
9912 Draw(3, 1, 0, 0);
9913
9914 // Finalize recording of the command buffer
9915 EndCommandBuffer();
9916
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009917 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009918
Chia-I Wuf7458c52015-10-26 21:10:41 +08009919 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9920 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9921 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009922}
Mark Young29927482016-05-04 14:38:51 -06009923
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009924TEST_F(VkLayerTest, RenderPassIncompatible) {
9925 TEST_DESCRIPTION("Hit RenderPass incompatible cases. "
9926 "Initial case is drawing with an active renderpass that's "
Mike Weiblencce7ec72016-10-17 19:33:05 -06009927 "not compatible with the bound pipeline state object's creation renderpass");
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009928 VkResult err;
9929
9930 ASSERT_NO_FATAL_FAILURE(InitState());
9931 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9932
9933 VkDescriptorSetLayoutBinding dsl_binding = {};
9934 dsl_binding.binding = 0;
9935 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9936 dsl_binding.descriptorCount = 1;
9937 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9938 dsl_binding.pImmutableSamplers = NULL;
9939
9940 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9941 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9942 ds_layout_ci.pNext = NULL;
9943 ds_layout_ci.bindingCount = 1;
9944 ds_layout_ci.pBindings = &dsl_binding;
9945
9946 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009947 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009948 ASSERT_VK_SUCCESS(err);
9949
9950 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
9951 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9952 pipeline_layout_ci.pNext = NULL;
9953 pipeline_layout_ci.setLayoutCount = 1;
9954 pipeline_layout_ci.pSetLayouts = &ds_layout;
9955
9956 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009957 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009958 ASSERT_VK_SUCCESS(err);
9959
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009960 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
9961 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
9962 // but add it to be able to run on more devices
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009963 // Create a renderpass that will be incompatible with default renderpass
9964 VkAttachmentReference attach = {};
9965 attach.layout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
9966 VkAttachmentReference color_att = {};
9967 color_att.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
9968 VkSubpassDescription subpass = {};
9969 subpass.inputAttachmentCount = 1;
9970 subpass.pInputAttachments = &attach;
9971 subpass.colorAttachmentCount = 1;
9972 subpass.pColorAttachments = &color_att;
9973 VkRenderPassCreateInfo rpci = {};
9974 rpci.subpassCount = 1;
9975 rpci.pSubpasses = &subpass;
9976 rpci.attachmentCount = 1;
9977 VkAttachmentDescription attach_desc = {};
9978 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
Cody Northropbd16af12016-06-21 09:25:48 -06009979 // Format incompatible with PSO RP color attach format B8G8R8A8_UNORM
9980 attach_desc.format = VK_FORMAT_R8G8B8A8_UNORM;
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009981 rpci.pAttachments = &attach_desc;
9982 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
9983 VkRenderPass rp;
9984 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
9985 VkPipelineObj pipe(m_device);
9986 pipe.AddShader(&vs);
9987 pipe.AddShader(&fs);
9988 pipe.AddColorAttachment();
9989 VkViewport view_port = {};
9990 m_viewports.push_back(view_port);
9991 pipe.SetViewport(m_viewports);
9992 VkRect2D rect = {};
9993 m_scissors.push_back(rect);
9994 pipe.SetScissor(m_scissors);
9995 pipe.CreateVKPipeline(pipeline_layout, renderPass());
9996
9997 VkCommandBufferInheritanceInfo cbii = {};
9998 cbii.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
9999 cbii.renderPass = rp;
10000 cbii.subpass = 0;
10001 VkCommandBufferBeginInfo cbbi = {};
10002 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
10003 cbbi.pInheritanceInfo = &cbii;
10004 vkBeginCommandBuffer(m_commandBuffer->handle(), &cbbi);
10005 VkRenderPassBeginInfo rpbi = {};
10006 rpbi.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
10007 rpbi.framebuffer = m_framebuffer;
10008 rpbi.renderPass = rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010009 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
10010 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010011
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010012 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is incompatible w/ gfx pipeline ");
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010013 // Render triangle (the error should trigger on the attempt to draw).
10014 Draw(3, 1, 0, 0);
10015
10016 // Finalize recording of the command buffer
10017 EndCommandBuffer();
10018
10019 m_errorMonitor->VerifyFound();
10020
10021 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10022 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10023 vkDestroyRenderPass(m_device->device(), rp, NULL);
10024}
10025
Mark Youngc89c6312016-03-31 16:03:20 -060010026TEST_F(VkLayerTest, NumBlendAttachMismatch) {
10027 // Create Pipeline where the number of blend attachments doesn't match the
10028 // number of color attachments. In this case, we don't add any color
10029 // blend attachments even though we have a color attachment.
10030 VkResult err;
10031
10032 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010033 "Render pass subpass 0 mismatch with blending state defined and blend state attachment");
Mark Youngc89c6312016-03-31 16:03:20 -060010034
10035 ASSERT_NO_FATAL_FAILURE(InitState());
10036 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10037 VkDescriptorPoolSize ds_type_count = {};
10038 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10039 ds_type_count.descriptorCount = 1;
10040
10041 VkDescriptorPoolCreateInfo ds_pool_ci = {};
10042 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10043 ds_pool_ci.pNext = NULL;
10044 ds_pool_ci.maxSets = 1;
10045 ds_pool_ci.poolSizeCount = 1;
10046 ds_pool_ci.pPoolSizes = &ds_type_count;
10047
10048 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010049 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Mark Youngc89c6312016-03-31 16:03:20 -060010050 ASSERT_VK_SUCCESS(err);
10051
10052 VkDescriptorSetLayoutBinding dsl_binding = {};
10053 dsl_binding.binding = 0;
10054 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10055 dsl_binding.descriptorCount = 1;
10056 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10057 dsl_binding.pImmutableSamplers = NULL;
10058
10059 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10060 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10061 ds_layout_ci.pNext = NULL;
10062 ds_layout_ci.bindingCount = 1;
10063 ds_layout_ci.pBindings = &dsl_binding;
10064
10065 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010066 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Youngc89c6312016-03-31 16:03:20 -060010067 ASSERT_VK_SUCCESS(err);
10068
10069 VkDescriptorSet descriptorSet;
10070 VkDescriptorSetAllocateInfo alloc_info = {};
10071 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
10072 alloc_info.descriptorSetCount = 1;
10073 alloc_info.descriptorPool = ds_pool;
10074 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010075 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Youngc89c6312016-03-31 16:03:20 -060010076 ASSERT_VK_SUCCESS(err);
10077
10078 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010079 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Mark Youngc89c6312016-03-31 16:03:20 -060010080 pipe_ms_state_ci.pNext = NULL;
10081 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
10082 pipe_ms_state_ci.sampleShadingEnable = 0;
10083 pipe_ms_state_ci.minSampleShading = 1.0;
10084 pipe_ms_state_ci.pSampleMask = NULL;
10085
10086 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
10087 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10088 pipeline_layout_ci.pNext = NULL;
10089 pipeline_layout_ci.setLayoutCount = 1;
10090 pipeline_layout_ci.pSetLayouts = &ds_layout;
10091
10092 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010093 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Mark Youngc89c6312016-03-31 16:03:20 -060010094 ASSERT_VK_SUCCESS(err);
10095
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010096 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
10097 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
10098 // but add it to be able to run on more devices
Mark Youngc89c6312016-03-31 16:03:20 -060010099 VkPipelineObj pipe(m_device);
10100 pipe.AddShader(&vs);
10101 pipe.AddShader(&fs);
10102 pipe.SetMSAA(&pipe_ms_state_ci);
10103 pipe.CreateVKPipeline(pipeline_layout, renderPass());
10104
10105 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010106 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Mark Youngc89c6312016-03-31 16:03:20 -060010107
Mark Young29927482016-05-04 14:38:51 -060010108 // Render triangle (the error should trigger on the attempt to draw).
10109 Draw(3, 1, 0, 0);
10110
10111 // Finalize recording of the command buffer
10112 EndCommandBuffer();
10113
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010114 m_errorMonitor->VerifyFound();
Mark Youngc89c6312016-03-31 16:03:20 -060010115
10116 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10117 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10118 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
10119}
Mark Young29927482016-05-04 14:38:51 -060010120
Mark Muellerd4914412016-06-13 17:52:06 -060010121TEST_F(VkLayerTest, MissingClearAttachment) {
10122 TEST_DESCRIPTION("Points to a wrong colorAttachment index in a VkClearAttachment "
10123 "structure passed to vkCmdClearAttachments");
Cody Northropc31a84f2016-08-22 10:41:47 -060010124 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesda6ae6f2016-09-09 14:36:33 +120010125 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbesfa79fc72016-11-01 10:18:12 +130010126 "vkCmdClearAttachments() color attachment index 1 out of range for active subpass 0");
Mark Muellerd4914412016-06-13 17:52:06 -060010127
10128 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailCmdClearAttachments);
10129 m_errorMonitor->VerifyFound();
10130}
10131
Karl Schultz6addd812016-02-02 17:17:23 -070010132TEST_F(VkLayerTest, ClearCmdNoDraw) {
10133 // Create CommandBuffer where we add ClearCmd for FB Color attachment prior
10134 // to issuing a Draw
10135 VkResult err;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010136
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010137 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Mike Weiblencce7ec72016-10-17 19:33:05 -060010138 "vkCmdClearAttachments() issued on command buffer object ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010139
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010140 ASSERT_NO_FATAL_FAILURE(InitState());
10141 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -060010142
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010143 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010144 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10145 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010146
10147 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010148 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10149 ds_pool_ci.pNext = NULL;
10150 ds_pool_ci.maxSets = 1;
10151 ds_pool_ci.poolSizeCount = 1;
10152 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060010153
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010154 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010155 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010156 ASSERT_VK_SUCCESS(err);
10157
Tony Barboureb254902015-07-15 12:50:33 -060010158 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010159 dsl_binding.binding = 0;
10160 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10161 dsl_binding.descriptorCount = 1;
10162 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10163 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010164
Tony Barboureb254902015-07-15 12:50:33 -060010165 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010166 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10167 ds_layout_ci.pNext = NULL;
10168 ds_layout_ci.bindingCount = 1;
10169 ds_layout_ci.pBindings = &dsl_binding;
Mark Lobodzinski209b5292015-09-17 09:44:05 -060010170
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010171 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010172 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010173 ASSERT_VK_SUCCESS(err);
10174
10175 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010176 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010177 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010178 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060010179 alloc_info.descriptorPool = ds_pool;
10180 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010181 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010182 ASSERT_VK_SUCCESS(err);
10183
Tony Barboureb254902015-07-15 12:50:33 -060010184 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010185 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070010186 pipe_ms_state_ci.pNext = NULL;
10187 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
10188 pipe_ms_state_ci.sampleShadingEnable = 0;
10189 pipe_ms_state_ci.minSampleShading = 1.0;
10190 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010191
Tony Barboureb254902015-07-15 12:50:33 -060010192 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010193 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10194 pipeline_layout_ci.pNext = NULL;
10195 pipeline_layout_ci.setLayoutCount = 1;
10196 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010197
10198 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010199 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010200 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski209b5292015-09-17 09:44:05 -060010201
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010202 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -060010203 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -070010204 // on more devices
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010205 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010206
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010207 VkPipelineObj pipe(m_device);
10208 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -060010209 pipe.AddShader(&fs);
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010210 pipe.SetMSAA(&pipe_ms_state_ci);
10211 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -060010212
10213 BeginCommandBuffer();
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010214
Karl Schultz6addd812016-02-02 17:17:23 -070010215 // Main thing we care about for this test is that the VkImage obj we're
10216 // clearing matches Color Attachment of FB
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010217 // Also pass down other dummy params to keep driver and paramchecker happy
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -060010218 VkClearAttachment color_attachment;
10219 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10220 color_attachment.clearValue.color.float32[0] = 1.0;
10221 color_attachment.clearValue.color.float32[1] = 1.0;
10222 color_attachment.clearValue.color.float32[2] = 1.0;
10223 color_attachment.clearValue.color.float32[3] = 1.0;
10224 color_attachment.colorAttachment = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010225 VkClearRect clear_rect = {{{0, 0}, {(uint32_t)m_width, (uint32_t)m_height}}};
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010226
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010227 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010228
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010229 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010230
Chia-I Wuf7458c52015-10-26 21:10:41 +080010231 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10232 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10233 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010234}
10235
Karl Schultz6addd812016-02-02 17:17:23 -070010236TEST_F(VkLayerTest, VtxBufferBadIndex) {
10237 VkResult err;
Tobin Ehlis502480b2015-06-24 15:53:07 -060010238
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010239 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10240 "but no vertex buffers are attached to this Pipeline State Object");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010241
Tobin Ehlis502480b2015-06-24 15:53:07 -060010242 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisd332f282015-10-02 11:00:56 -060010243 ASSERT_NO_FATAL_FAILURE(InitViewport());
Tobin Ehlis502480b2015-06-24 15:53:07 -060010244 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -060010245
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010246 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010247 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10248 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010249
10250 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010251 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10252 ds_pool_ci.pNext = NULL;
10253 ds_pool_ci.maxSets = 1;
10254 ds_pool_ci.poolSizeCount = 1;
10255 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060010256
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -060010257 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010258 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis502480b2015-06-24 15:53:07 -060010259 ASSERT_VK_SUCCESS(err);
10260
Tony Barboureb254902015-07-15 12:50:33 -060010261 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010262 dsl_binding.binding = 0;
10263 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10264 dsl_binding.descriptorCount = 1;
10265 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10266 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -060010267
Tony Barboureb254902015-07-15 12:50:33 -060010268 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010269 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10270 ds_layout_ci.pNext = NULL;
10271 ds_layout_ci.bindingCount = 1;
10272 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060010273
Tobin Ehlis502480b2015-06-24 15:53:07 -060010274 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010275 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -060010276 ASSERT_VK_SUCCESS(err);
10277
10278 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010279 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010280 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010281 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060010282 alloc_info.descriptorPool = ds_pool;
10283 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010284 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis502480b2015-06-24 15:53:07 -060010285 ASSERT_VK_SUCCESS(err);
10286
Tony Barboureb254902015-07-15 12:50:33 -060010287 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010288 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070010289 pipe_ms_state_ci.pNext = NULL;
10290 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
10291 pipe_ms_state_ci.sampleShadingEnable = 0;
10292 pipe_ms_state_ci.minSampleShading = 1.0;
10293 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -060010294
Tony Barboureb254902015-07-15 12:50:33 -060010295 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010296 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10297 pipeline_layout_ci.pNext = NULL;
10298 pipeline_layout_ci.setLayoutCount = 1;
10299 pipeline_layout_ci.pSetLayouts = &ds_layout;
10300 VkPipelineLayout pipeline_layout;
Tobin Ehlis502480b2015-06-24 15:53:07 -060010301
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010302 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -060010303 ASSERT_VK_SUCCESS(err);
10304
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010305 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
10306 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
10307 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010308 VkPipelineObj pipe(m_device);
10309 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -060010310 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -060010311 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010312 pipe.SetMSAA(&pipe_ms_state_ci);
Tobin Ehlisd332f282015-10-02 11:00:56 -060010313 pipe.SetViewport(m_viewports);
10314 pipe.SetScissor(m_scissors);
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010315 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -060010316
10317 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010318 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisf7bf4502015-09-09 15:12:35 -060010319 // Don't care about actual data, just need to get to draw to flag error
10320 static const float vbo_data[3] = {1.f, 0.f, 1.f};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010321 VkConstantBufferObj vbo(m_device, sizeof(vbo_data), sizeof(float), (const void *)&vbo_data);
Tobin Ehlisf7bf4502015-09-09 15:12:35 -060010322 BindVertexBuffer(&vbo, (VkDeviceSize)0, 1); // VBO idx 1, but no VBO in PSO
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -060010323 Draw(1, 0, 0, 0);
Tobin Ehlis502480b2015-06-24 15:53:07 -060010324
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010325 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010326
Chia-I Wuf7458c52015-10-26 21:10:41 +080010327 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10328 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10329 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis502480b2015-06-24 15:53:07 -060010330}
Mark Muellerdfe37552016-07-07 14:47:42 -060010331
Mark Mueller2ee294f2016-08-04 12:59:48 -060010332TEST_F(VkLayerTest, MismatchCountQueueCreateRequestedFeature) {
10333 TEST_DESCRIPTION("Use an invalid count in a vkEnumeratePhysicalDevices call."
10334 "Use invalid Queue Family Index in vkCreateDevice");
Cody Northropc31a84f2016-08-22 10:41:47 -060010335 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Mueller2ee294f2016-08-04 12:59:48 -060010336
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010337 const char *mismatch_count_message = "Call to vkEnumeratePhysicalDevices() "
10338 "w/ pPhysicalDeviceCount value ";
Mark Mueller2ee294f2016-08-04 12:59:48 -060010339
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010340 const char *invalid_queueFamilyIndex_message = "Invalid queue create request in vkCreateDevice(). Invalid "
10341 "queueFamilyIndex ";
Mark Mueller2ee294f2016-08-04 12:59:48 -060010342
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010343 const char *unavailable_feature_message = "While calling vkCreateDevice(), requesting feature #";
Mark Mueller2ee294f2016-08-04 12:59:48 -060010344
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010345 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, mismatch_count_message);
Mark Mueller880fce52016-08-17 15:23:23 -060010346 // The following test fails with recent NVidia drivers.
10347 // By the time core_validation is reached, the NVidia
10348 // driver has sanitized the invalid condition and core_validation
10349 // is not introduced to the failure condition. This is not the case
10350 // with AMD and Mesa drivers. Futher investigation is required
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010351 // uint32_t count = static_cast<uint32_t>(~0);
10352 // VkPhysicalDevice physical_device;
10353 // vkEnumeratePhysicalDevices(instance(), &count, &physical_device);
10354 // m_errorMonitor->VerifyFound();
Mark Mueller2ee294f2016-08-04 12:59:48 -060010355
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010356 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_queueFamilyIndex_message);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010357 float queue_priority = 0.0;
10358
10359 VkDeviceQueueCreateInfo queue_create_info = {};
10360 queue_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
10361 queue_create_info.queueCount = 1;
10362 queue_create_info.pQueuePriorities = &queue_priority;
10363 queue_create_info.queueFamilyIndex = static_cast<uint32_t>(~0);
10364
10365 VkPhysicalDeviceFeatures features = m_device->phy().features();
10366 VkDevice testDevice;
10367 VkDeviceCreateInfo device_create_info = {};
10368 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
10369 device_create_info.queueCreateInfoCount = 1;
10370 device_create_info.pQueueCreateInfos = &queue_create_info;
10371 device_create_info.pEnabledFeatures = &features;
10372 vkCreateDevice(gpu(), &device_create_info, nullptr, &testDevice);
10373 m_errorMonitor->VerifyFound();
10374
10375 queue_create_info.queueFamilyIndex = 1;
10376
10377 unsigned feature_count = sizeof(VkPhysicalDeviceFeatures) / sizeof(VkBool32);
10378 VkBool32 *feature_array = reinterpret_cast<VkBool32 *>(&features);
10379 for (unsigned i = 0; i < feature_count; i++) {
10380 if (VK_FALSE == feature_array[i]) {
10381 feature_array[i] = VK_TRUE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010382 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, unavailable_feature_message);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010383 device_create_info.pEnabledFeatures = &features;
10384 vkCreateDevice(gpu(), &device_create_info, nullptr, &testDevice);
10385 m_errorMonitor->VerifyFound();
10386 break;
10387 }
10388 }
10389}
10390
Tobin Ehlis16edf082016-11-21 12:33:49 -070010391TEST_F(VkLayerTest, InvalidQueryPoolCreate) {
10392 TEST_DESCRIPTION("Attempt to create a query pool for PIPELINE_STATISTICS without enabling pipeline stats for the device.");
10393
10394 ASSERT_NO_FATAL_FAILURE(InitState());
10395
10396 const std::vector<VkQueueFamilyProperties> queue_props = m_device->queue_props;
10397 std::vector<VkDeviceQueueCreateInfo> queue_info;
10398 queue_info.reserve(queue_props.size());
10399 std::vector<std::vector<float>> queue_priorities;
10400 for (uint32_t i = 0; i < (uint32_t)queue_props.size(); i++) {
10401 VkDeviceQueueCreateInfo qi{};
10402 qi.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
10403 qi.queueFamilyIndex = i;
10404 qi.queueCount = queue_props[i].queueCount;
10405 queue_priorities.emplace_back(qi.queueCount, 0.0f);
10406 qi.pQueuePriorities = queue_priorities[i].data();
10407 queue_info.push_back(qi);
10408 }
10409
10410 std::vector<const char *> device_extension_names;
10411
10412 VkDevice local_device;
10413 VkDeviceCreateInfo device_create_info = {};
10414 auto features = m_device->phy().features();
10415 // Intentionally disable pipeline stats
10416 features.pipelineStatisticsQuery = VK_FALSE;
10417 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
10418 device_create_info.pNext = NULL;
10419 device_create_info.queueCreateInfoCount = queue_info.size();
10420 device_create_info.pQueueCreateInfos = queue_info.data();
10421 device_create_info.enabledLayerCount = 0;
10422 device_create_info.ppEnabledLayerNames = NULL;
10423 device_create_info.pEnabledFeatures = &features;
10424 VkResult err = vkCreateDevice(gpu(), &device_create_info, nullptr, &local_device);
10425 ASSERT_VK_SUCCESS(err);
10426
10427 VkQueryPoolCreateInfo qpci{};
10428 qpci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
10429 qpci.queryType = VK_QUERY_TYPE_PIPELINE_STATISTICS;
10430 qpci.queryCount = 1;
10431 VkQueryPool query_pool;
10432
10433 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01006);
10434 vkCreateQueryPool(local_device, &qpci, nullptr, &query_pool);
10435 m_errorMonitor->VerifyFound();
10436
10437 vkDestroyDevice(local_device, nullptr);
10438}
10439
Mark Mueller2ee294f2016-08-04 12:59:48 -060010440TEST_F(VkLayerTest, InvalidQueueIndexInvalidQuery) {
10441 TEST_DESCRIPTION("Use an invalid queue index in a vkCmdWaitEvents call."
10442 "End a command buffer with a query still in progress.");
10443
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010444 const char *invalid_queue_index = "was created with sharingMode of VK_SHARING_MODE_EXCLUSIVE. If one "
10445 "of src- or dstQueueFamilyIndex is VK_QUEUE_FAMILY_IGNORED, both "
10446 "must be.";
Mark Mueller2ee294f2016-08-04 12:59:48 -060010447
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010448 const char *invalid_query = "Ending command buffer with in progress query: queryPool 0x";
Mark Mueller2ee294f2016-08-04 12:59:48 -060010449
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010450 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_queue_index);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010451
10452 ASSERT_NO_FATAL_FAILURE(InitState());
10453
10454 VkEvent event;
10455 VkEventCreateInfo event_create_info{};
10456 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
10457 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
10458
Mark Mueller2ee294f2016-08-04 12:59:48 -060010459 VkQueue queue = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010460 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010461
10462 BeginCommandBuffer();
10463
10464 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010465 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 -060010466 ASSERT_TRUE(image.initialized());
10467 VkImageMemoryBarrier img_barrier = {};
10468 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
10469 img_barrier.pNext = NULL;
10470 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
10471 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
10472 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
10473 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
10474 img_barrier.image = image.handle();
10475 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
Mark Lobodzinski2a74c5c2016-08-17 13:26:28 -060010476
10477 // QueueFamilyIndex must be VK_QUEUE_FAMILY_IGNORED, this verifies
10478 // that layer validation catches the case when it is not.
10479 img_barrier.dstQueueFamilyIndex = 0;
Mark Mueller2ee294f2016-08-04 12:59:48 -060010480 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10481 img_barrier.subresourceRange.baseArrayLayer = 0;
10482 img_barrier.subresourceRange.baseMipLevel = 0;
10483 img_barrier.subresourceRange.layerCount = 1;
10484 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010485 vkCmdWaitEvents(m_commandBuffer->handle(), 1, &event, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0,
10486 nullptr, 0, nullptr, 1, &img_barrier);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010487 m_errorMonitor->VerifyFound();
10488
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010489 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_query);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010490
10491 VkQueryPool query_pool;
10492 VkQueryPoolCreateInfo query_pool_create_info = {};
10493 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
10494 query_pool_create_info.queryType = VK_QUERY_TYPE_OCCLUSION;
10495 query_pool_create_info.queryCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010496 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010497
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010498 vkCmdResetQueryPool(m_commandBuffer->handle(), query_pool, 0 /*startQuery*/, 1 /*queryCount*/);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010499 vkCmdBeginQuery(m_commandBuffer->handle(), query_pool, 0, 0);
10500
10501 vkEndCommandBuffer(m_commandBuffer->handle());
10502 m_errorMonitor->VerifyFound();
10503
10504 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
10505 vkDestroyEvent(m_device->device(), event, nullptr);
10506}
10507
Mark Muellerdfe37552016-07-07 14:47:42 -060010508TEST_F(VkLayerTest, VertexBufferInvalid) {
10509 TEST_DESCRIPTION("Submit a command buffer using deleted vertex buffer, "
10510 "delete a buffer twice, use an invalid offset for each "
10511 "buffer type, and attempt to bind a null buffer");
10512
10513 const char *deleted_buffer_in_command_buffer = "Cannot submit cmd buffer "
10514 "using deleted buffer ";
Mark Muellerdfe37552016-07-07 14:47:42 -060010515 const char *invalid_offset_message = "vkBindBufferMemory(): "
10516 "memoryOffset is 0x";
10517 const char *invalid_storage_buffer_offset_message = "vkBindBufferMemory(): "
10518 "storage memoryOffset "
10519 "is 0x";
10520 const char *invalid_texel_buffer_offset_message = "vkBindBufferMemory(): "
10521 "texel memoryOffset "
10522 "is 0x";
10523 const char *invalid_uniform_buffer_offset_message = "vkBindBufferMemory(): "
10524 "uniform memoryOffset "
10525 "is 0x";
Mark Muellerdfe37552016-07-07 14:47:42 -060010526
10527 ASSERT_NO_FATAL_FAILURE(InitState());
10528 ASSERT_NO_FATAL_FAILURE(InitViewport());
10529 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10530
10531 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010532 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Mark Muellerdfe37552016-07-07 14:47:42 -060010533 pipe_ms_state_ci.pNext = NULL;
10534 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
10535 pipe_ms_state_ci.sampleShadingEnable = 0;
10536 pipe_ms_state_ci.minSampleShading = 1.0;
10537 pipe_ms_state_ci.pSampleMask = nullptr;
10538
10539 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
10540 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10541 VkPipelineLayout pipeline_layout;
10542
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010543 VkResult err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, nullptr, &pipeline_layout);
Mark Muellerdfe37552016-07-07 14:47:42 -060010544 ASSERT_VK_SUCCESS(err);
10545
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010546 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
10547 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Muellerdfe37552016-07-07 14:47:42 -060010548 VkPipelineObj pipe(m_device);
10549 pipe.AddShader(&vs);
10550 pipe.AddShader(&fs);
10551 pipe.AddColorAttachment();
10552 pipe.SetMSAA(&pipe_ms_state_ci);
10553 pipe.SetViewport(m_viewports);
10554 pipe.SetScissor(m_scissors);
10555 pipe.CreateVKPipeline(pipeline_layout, renderPass());
10556
10557 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010558 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Mark Muellerdfe37552016-07-07 14:47:42 -060010559
10560 {
10561 // Create and bind a vertex buffer in a reduced scope, which will cause
10562 // it to be deleted upon leaving this scope
10563 const float vbo_data[3] = {1.f, 0.f, 1.f};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010564 VkVerticesObj draw_verticies(m_device, 1, 1, sizeof(vbo_data), 3, vbo_data);
Mark Muellerdfe37552016-07-07 14:47:42 -060010565 draw_verticies.BindVertexBuffers(m_commandBuffer->handle());
10566 draw_verticies.AddVertexInputToPipe(pipe);
10567 }
10568
10569 Draw(1, 0, 0, 0);
10570
10571 EndCommandBuffer();
10572
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010573 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, deleted_buffer_in_command_buffer);
Mark Muellerdfe37552016-07-07 14:47:42 -060010574 QueueCommandBuffer(false);
10575 m_errorMonitor->VerifyFound();
10576
10577 {
10578 // Create and bind a vertex buffer in a reduced scope, and delete it
10579 // twice, the second through the destructor
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010580 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eDoubleDelete);
Karl Schultzf78bcdd2016-11-30 12:36:01 -070010581 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00680);
Mark Muellerdfe37552016-07-07 14:47:42 -060010582 buffer_test.TestDoubleDestroy();
10583 }
10584 m_errorMonitor->VerifyFound();
10585
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010586 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidMemoryOffset)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060010587 // Create and bind a memory buffer with an invalid offset.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010588 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_offset_message);
10589 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT, VkBufferTest::eInvalidMemoryOffset);
10590 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010591 m_errorMonitor->VerifyFound();
10592 }
10593
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010594 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset,
10595 VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060010596 // Create and bind a memory buffer with an invalid offset again,
10597 // but look for a texel buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010598 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_texel_buffer_offset_message);
10599 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
10600 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010601 m_errorMonitor->VerifyFound();
10602 }
10603
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010604 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060010605 // Create and bind a memory buffer with an invalid offset again, but
10606 // look for a uniform buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010607 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_uniform_buffer_offset_message);
10608 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
10609 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010610 m_errorMonitor->VerifyFound();
10611 }
10612
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010613 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060010614 // Create and bind a memory buffer with an invalid offset again, but
10615 // look for a storage buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010616 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_storage_buffer_offset_message);
10617 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
10618 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010619 m_errorMonitor->VerifyFound();
10620 }
10621
10622 {
10623 // Attempt to bind a null buffer.
Karl Schultzf78bcdd2016-11-30 12:36:01 -070010624 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00799);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010625 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eBindNullBuffer);
10626 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010627 m_errorMonitor->VerifyFound();
10628 }
10629
10630 {
10631 // Attempt to use an invalid handle to delete a buffer.
Karl Schultzf78bcdd2016-11-30 12:36:01 -070010632 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00622);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010633 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eFreeInvalidHandle);
10634 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010635 }
10636 m_errorMonitor->VerifyFound();
10637
10638 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10639}
10640
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010641// INVALID_IMAGE_LAYOUT tests (one other case is hit by MapMemWithoutHostVisibleBit and not here)
10642TEST_F(VkLayerTest, InvalidImageLayout) {
10643 TEST_DESCRIPTION("Hit all possible validation checks associated with the "
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010644 "DRAWSTATE_INVALID_IMAGE_LAYOUT enum. Generally these involve having"
10645 "images in the wrong layout when they're copied or transitioned.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010646 // 3 in ValidateCmdBufImageLayouts
10647 // * -1 Attempt to submit cmd buf w/ deleted image
10648 // * -2 Cmd buf submit of image w/ layout not matching first use w/ subresource
10649 // * -3 Cmd buf submit of image w/ layout not matching first use w/o subresource
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010650
10651 ASSERT_NO_FATAL_FAILURE(InitState());
10652 // Create src & dst images to use for copy operations
10653 VkImage src_image;
10654 VkImage dst_image;
Cort3b021012016-12-07 12:00:57 -080010655 VkImage depth_image;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010656
10657 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
10658 const int32_t tex_width = 32;
10659 const int32_t tex_height = 32;
10660
10661 VkImageCreateInfo image_create_info = {};
10662 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
10663 image_create_info.pNext = NULL;
10664 image_create_info.imageType = VK_IMAGE_TYPE_2D;
10665 image_create_info.format = tex_format;
10666 image_create_info.extent.width = tex_width;
10667 image_create_info.extent.height = tex_height;
10668 image_create_info.extent.depth = 1;
10669 image_create_info.mipLevels = 1;
10670 image_create_info.arrayLayers = 4;
10671 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
10672 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
10673 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Cort3b021012016-12-07 12:00:57 -080010674 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010675 image_create_info.flags = 0;
10676
10677 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &src_image);
10678 ASSERT_VK_SUCCESS(err);
Cort3b021012016-12-07 12:00:57 -080010679 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010680 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dst_image);
10681 ASSERT_VK_SUCCESS(err);
Cort3b021012016-12-07 12:00:57 -080010682 image_create_info.format = VK_FORMAT_D32_SFLOAT;
10683 image_create_info.usage |= VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
10684 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &depth_image);
10685 ASSERT_VK_SUCCESS(err);
10686
10687 // Allocate memory
10688 VkMemoryRequirements img_mem_reqs = {};
Cort530cf382016-12-08 09:59:47 -080010689 VkMemoryAllocateInfo mem_alloc = {};
Cort3b021012016-12-07 12:00:57 -080010690 VkDeviceMemory src_image_mem, dst_image_mem, depth_image_mem;
Cort530cf382016-12-08 09:59:47 -080010691 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
10692 mem_alloc.pNext = NULL;
10693 mem_alloc.allocationSize = 0;
10694 mem_alloc.memoryTypeIndex = 0;
Cort3b021012016-12-07 12:00:57 -080010695
10696 vkGetImageMemoryRequirements(m_device->device(), src_image, &img_mem_reqs);
Cort530cf382016-12-08 09:59:47 -080010697 mem_alloc.allocationSize = img_mem_reqs.size;
10698 bool pass = m_device->phy().set_memory_type(img_mem_reqs.memoryTypeBits, &mem_alloc, 0);
Cort3b021012016-12-07 12:00:57 -080010699 ASSERT_TRUE(pass);
Cort530cf382016-12-08 09:59:47 -080010700 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &src_image_mem);
Cort3b021012016-12-07 12:00:57 -080010701 ASSERT_VK_SUCCESS(err);
10702
10703 vkGetImageMemoryRequirements(m_device->device(), dst_image, &img_mem_reqs);
Cort530cf382016-12-08 09:59:47 -080010704 mem_alloc.allocationSize = img_mem_reqs.size;
10705 pass = m_device->phy().set_memory_type(img_mem_reqs.memoryTypeBits, &mem_alloc, 0);
Cort3b021012016-12-07 12:00:57 -080010706 ASSERT_VK_SUCCESS(err);
Cort530cf382016-12-08 09:59:47 -080010707 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &dst_image_mem);
Cort3b021012016-12-07 12:00:57 -080010708 ASSERT_VK_SUCCESS(err);
10709
10710 vkGetImageMemoryRequirements(m_device->device(), depth_image, &img_mem_reqs);
Cort530cf382016-12-08 09:59:47 -080010711 mem_alloc.allocationSize = img_mem_reqs.size;
10712 pass = m_device->phy().set_memory_type(img_mem_reqs.memoryTypeBits, &mem_alloc, 0);
Cort3b021012016-12-07 12:00:57 -080010713 ASSERT_VK_SUCCESS(err);
Cort530cf382016-12-08 09:59:47 -080010714 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &depth_image_mem);
Cort3b021012016-12-07 12:00:57 -080010715 ASSERT_VK_SUCCESS(err);
10716
10717 err = vkBindImageMemory(m_device->device(), src_image, src_image_mem, 0);
10718 ASSERT_VK_SUCCESS(err);
10719 err = vkBindImageMemory(m_device->device(), dst_image, dst_image_mem, 0);
10720 ASSERT_VK_SUCCESS(err);
10721 err = vkBindImageMemory(m_device->device(), depth_image, depth_image_mem, 0);
10722 ASSERT_VK_SUCCESS(err);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010723
10724 BeginCommandBuffer();
Cort530cf382016-12-08 09:59:47 -080010725 VkImageCopy copy_region;
10726 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10727 copy_region.srcSubresource.mipLevel = 0;
10728 copy_region.srcSubresource.baseArrayLayer = 0;
10729 copy_region.srcSubresource.layerCount = 1;
10730 copy_region.srcOffset.x = 0;
10731 copy_region.srcOffset.y = 0;
10732 copy_region.srcOffset.z = 0;
10733 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10734 copy_region.dstSubresource.mipLevel = 0;
10735 copy_region.dstSubresource.baseArrayLayer = 0;
10736 copy_region.dstSubresource.layerCount = 1;
10737 copy_region.dstOffset.x = 0;
10738 copy_region.dstOffset.y = 0;
10739 copy_region.dstOffset.z = 0;
10740 copy_region.extent.width = 1;
10741 copy_region.extent.height = 1;
10742 copy_region.extent.depth = 1;
10743
10744 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10745 "Layout for input image should be TRANSFER_SRC_OPTIMAL instead of GENERAL.");
10746 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 -060010747 m_errorMonitor->VerifyFound();
10748 // Now cause error due to src image layout changing
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010749 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot copy from an image whose source layout is "
10750 "VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current "
10751 "layout VK_IMAGE_LAYOUT_GENERAL.");
Cort530cf382016-12-08 09:59:47 -080010752 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 -060010753 m_errorMonitor->VerifyFound();
10754 // Final src error is due to bad layout type
10755 m_errorMonitor->SetDesiredFailureMsg(
10756 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10757 "Layout for input image is VK_IMAGE_LAYOUT_UNDEFINED but can only be TRANSFER_SRC_OPTIMAL or GENERAL.");
Cort530cf382016-12-08 09:59:47 -080010758 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 -060010759 m_errorMonitor->VerifyFound();
10760 // Now verify same checks for dst
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010761 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10762 "Layout for output image should be TRANSFER_DST_OPTIMAL instead of GENERAL.");
Cort530cf382016-12-08 09:59:47 -080010763 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 -060010764 m_errorMonitor->VerifyFound();
10765 // Now cause error due to src image layout changing
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010766 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot copy from an image whose dest layout is "
10767 "VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current "
10768 "layout VK_IMAGE_LAYOUT_GENERAL.");
Cort530cf382016-12-08 09:59:47 -080010769 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 -060010770 m_errorMonitor->VerifyFound();
10771 m_errorMonitor->SetDesiredFailureMsg(
10772 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10773 "Layout for output image is VK_IMAGE_LAYOUT_UNDEFINED but can only be TRANSFER_DST_OPTIMAL or GENERAL.");
Cort530cf382016-12-08 09:59:47 -080010774 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 -060010775 m_errorMonitor->VerifyFound();
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010010776
Cort3b021012016-12-07 12:00:57 -080010777 // Convert dst and depth images to TRANSFER_DST for subsequent tests
10778 VkImageMemoryBarrier transfer_dst_image_barrier[1] = {};
10779 transfer_dst_image_barrier[0].sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
10780 transfer_dst_image_barrier[0].oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
10781 transfer_dst_image_barrier[0].newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
10782 transfer_dst_image_barrier[0].srcAccessMask = 0;
10783 transfer_dst_image_barrier[0].dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
10784 transfer_dst_image_barrier[0].image = dst_image;
10785 transfer_dst_image_barrier[0].subresourceRange.layerCount = image_create_info.arrayLayers;
10786 transfer_dst_image_barrier[0].subresourceRange.levelCount = image_create_info.mipLevels;
10787 transfer_dst_image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10788 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
10789 NULL, 0, NULL, 1, transfer_dst_image_barrier);
10790 transfer_dst_image_barrier[0].image = depth_image;
10791 transfer_dst_image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
10792 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
10793 NULL, 0, NULL, 1, transfer_dst_image_barrier);
10794
10795 // Cause errors due to clearing with invalid image layouts
Cort530cf382016-12-08 09:59:47 -080010796 VkClearColorValue color_clear_value = {};
10797 VkImageSubresourceRange clear_range;
10798 clear_range.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10799 clear_range.baseMipLevel = 0;
10800 clear_range.baseArrayLayer = 0;
10801 clear_range.layerCount = 1;
10802 clear_range.levelCount = 1;
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010010803
Cort3b021012016-12-07 12:00:57 -080010804 // Fail due to explicitly prohibited layout for color clear (only GENERAL and TRANSFER_DST are permitted).
10805 // Since the image is currently not in UNDEFINED layout, this will emit two errors.
10806 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01086);
10807 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01085);
Cort530cf382016-12-08 09:59:47 -080010808 m_commandBuffer->ClearColorImage(dst_image, VK_IMAGE_LAYOUT_UNDEFINED, &color_clear_value, 1, &clear_range);
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010010809 m_errorMonitor->VerifyFound();
Cort3b021012016-12-07 12:00:57 -080010810 // Fail due to provided layout not matching actual current layout for color clear.
10811 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01085);
Cort530cf382016-12-08 09:59:47 -080010812 m_commandBuffer->ClearColorImage(dst_image, VK_IMAGE_LAYOUT_GENERAL, &color_clear_value, 1, &clear_range);
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010010813 m_errorMonitor->VerifyFound();
Cort3b021012016-12-07 12:00:57 -080010814
Cort530cf382016-12-08 09:59:47 -080010815 VkClearDepthStencilValue depth_clear_value = {};
10816 clear_range.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
Cort3b021012016-12-07 12:00:57 -080010817
10818 // Fail due to explicitly prohibited layout for depth clear (only GENERAL and TRANSFER_DST are permitted).
10819 // Since the image is currently not in UNDEFINED layout, this will emit two errors.
10820 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01101);
10821 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01100);
Cort530cf382016-12-08 09:59:47 -080010822 m_commandBuffer->ClearDepthStencilImage(depth_image, VK_IMAGE_LAYOUT_UNDEFINED, &depth_clear_value, 1, &clear_range);
Cort3b021012016-12-07 12:00:57 -080010823 m_errorMonitor->VerifyFound();
10824 // Fail due to provided layout not matching actual current layout for depth clear.
10825 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01100);
Cort530cf382016-12-08 09:59:47 -080010826 m_commandBuffer->ClearDepthStencilImage(depth_image, VK_IMAGE_LAYOUT_GENERAL, &depth_clear_value, 1, &clear_range);
Cort3b021012016-12-07 12:00:57 -080010827 m_errorMonitor->VerifyFound();
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010010828
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010829 // Now cause error due to bad image layout transition in PipelineBarrier
10830 VkImageMemoryBarrier image_barrier[1] = {};
Cort3b021012016-12-07 12:00:57 -080010831 image_barrier[0].sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010832 image_barrier[0].oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
Cort3b021012016-12-07 12:00:57 -080010833 image_barrier[0].newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010834 image_barrier[0].image = src_image;
Cort3b021012016-12-07 12:00:57 -080010835 image_barrier[0].subresourceRange.layerCount = image_create_info.arrayLayers;
10836 image_barrier[0].subresourceRange.levelCount = image_create_info.mipLevels;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010837 image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010838 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "You cannot transition the layout from "
10839 "VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL when "
10840 "current layout is VK_IMAGE_LAYOUT_GENERAL.");
10841 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
10842 NULL, 0, NULL, 1, image_barrier);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010843 m_errorMonitor->VerifyFound();
10844
10845 // Finally some layout errors at RenderPass create time
10846 // Just hacking in specific state to get to the errors we want so don't copy this unless you know what you're doing.
10847 VkAttachmentReference attach = {};
10848 // perf warning for GENERAL layout w/ non-DS input attachment
10849 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
10850 VkSubpassDescription subpass = {};
10851 subpass.inputAttachmentCount = 1;
10852 subpass.pInputAttachments = &attach;
10853 VkRenderPassCreateInfo rpci = {};
10854 rpci.subpassCount = 1;
10855 rpci.pSubpasses = &subpass;
10856 rpci.attachmentCount = 1;
10857 VkAttachmentDescription attach_desc = {};
10858 attach_desc.format = VK_FORMAT_UNDEFINED;
10859 rpci.pAttachments = &attach_desc;
Tobin Ehlis1efce022016-05-11 10:40:34 -060010860 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010861 VkRenderPass rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010862 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10863 "Layout for input attachment is GENERAL but should be READ_ONLY_OPTIMAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010864 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10865 m_errorMonitor->VerifyFound();
10866 // error w/ non-general layout
10867 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
10868
10869 m_errorMonitor->SetDesiredFailureMsg(
10870 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10871 "Layout for input attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be READ_ONLY_OPTIMAL or GENERAL.");
10872 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10873 m_errorMonitor->VerifyFound();
10874 subpass.inputAttachmentCount = 0;
10875 subpass.colorAttachmentCount = 1;
10876 subpass.pColorAttachments = &attach;
10877 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
10878 // perf warning for GENERAL layout on color attachment
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010879 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10880 "Layout for color attachment is GENERAL but should be COLOR_ATTACHMENT_OPTIMAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010881 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10882 m_errorMonitor->VerifyFound();
10883 // error w/ non-color opt or GENERAL layout for color attachment
10884 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
10885 m_errorMonitor->SetDesiredFailureMsg(
10886 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10887 "Layout for color attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be COLOR_ATTACHMENT_OPTIMAL or GENERAL.");
10888 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10889 m_errorMonitor->VerifyFound();
10890 subpass.colorAttachmentCount = 0;
10891 subpass.pDepthStencilAttachment = &attach;
10892 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
10893 // perf warning for GENERAL layout on DS attachment
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010894 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10895 "GENERAL layout for depth attachment may not give optimal performance.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010896 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10897 m_errorMonitor->VerifyFound();
10898 // error w/ non-ds opt or GENERAL layout for color attachment
10899 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010900 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10901 "Layout for depth attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be "
10902 "DEPTH_STENCIL_ATTACHMENT_OPTIMAL, DEPTH_STENCIL_READ_ONLY_OPTIMAL or GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010903 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10904 m_errorMonitor->VerifyFound();
Tobin Ehlis1efce022016-05-11 10:40:34 -060010905 // For this error we need a valid renderpass so create default one
10906 attach.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
10907 attach.attachment = 0;
10908 attach_desc.format = VK_FORMAT_D24_UNORM_S8_UINT;
10909 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
10910 attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
10911 attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
10912 attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
10913 // Can't do a CLEAR load on READ_ONLY initialLayout
10914 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
10915 attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
10916 attach_desc.finalLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010917 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " with invalid first layout "
10918 "VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_"
10919 "ONLY_OPTIMAL");
Tobin Ehlis1efce022016-05-11 10:40:34 -060010920 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10921 m_errorMonitor->VerifyFound();
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010922
Cort3b021012016-12-07 12:00:57 -080010923 vkFreeMemory(m_device->device(), src_image_mem, NULL);
10924 vkFreeMemory(m_device->device(), dst_image_mem, NULL);
10925 vkFreeMemory(m_device->device(), depth_image_mem, NULL);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010926 vkDestroyImage(m_device->device(), src_image, NULL);
10927 vkDestroyImage(m_device->device(), dst_image, NULL);
Cort3b021012016-12-07 12:00:57 -080010928 vkDestroyImage(m_device->device(), depth_image, NULL);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010929}
Tobin Ehlisd8d89182016-07-18 20:13:11 -060010930
Tobin Ehlise0936662016-10-11 08:10:51 -060010931TEST_F(VkLayerTest, InvalidStorageImageLayout) {
10932 TEST_DESCRIPTION("Attempt to update a STORAGE_IMAGE descriptor w/o GENERAL layout.");
10933 VkResult err;
10934
10935 ASSERT_NO_FATAL_FAILURE(InitState());
10936
10937 const VkFormat tex_format = VK_FORMAT_R8G8B8A8_UNORM;
10938 VkImageTiling tiling;
10939 VkFormatProperties format_properties;
10940 vkGetPhysicalDeviceFormatProperties(gpu(), tex_format, &format_properties);
10941 if (format_properties.linearTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
10942 tiling = VK_IMAGE_TILING_LINEAR;
10943 } else if (format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
10944 tiling = VK_IMAGE_TILING_OPTIMAL;
10945 } else {
10946 printf("Device does not support VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT; "
10947 "skipped.\n");
10948 return;
10949 }
10950
10951 VkDescriptorPoolSize ds_type = {};
10952 ds_type.type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
10953 ds_type.descriptorCount = 1;
10954
10955 VkDescriptorPoolCreateInfo ds_pool_ci = {};
10956 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10957 ds_pool_ci.maxSets = 1;
10958 ds_pool_ci.poolSizeCount = 1;
10959 ds_pool_ci.pPoolSizes = &ds_type;
10960 ds_pool_ci.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
10961
10962 VkDescriptorPool ds_pool;
10963 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
10964 ASSERT_VK_SUCCESS(err);
10965
10966 VkDescriptorSetLayoutBinding dsl_binding = {};
10967 dsl_binding.binding = 0;
10968 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
10969 dsl_binding.descriptorCount = 1;
10970 dsl_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
10971 dsl_binding.pImmutableSamplers = NULL;
10972
10973 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10974 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10975 ds_layout_ci.pNext = NULL;
10976 ds_layout_ci.bindingCount = 1;
10977 ds_layout_ci.pBindings = &dsl_binding;
10978
10979 VkDescriptorSetLayout ds_layout;
10980 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
10981 ASSERT_VK_SUCCESS(err);
10982
10983 VkDescriptorSetAllocateInfo alloc_info = {};
10984 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
10985 alloc_info.descriptorSetCount = 1;
10986 alloc_info.descriptorPool = ds_pool;
10987 alloc_info.pSetLayouts = &ds_layout;
10988 VkDescriptorSet descriptor_set;
10989 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
10990 ASSERT_VK_SUCCESS(err);
10991
10992 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
10993 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10994 pipeline_layout_ci.pNext = NULL;
10995 pipeline_layout_ci.setLayoutCount = 1;
10996 pipeline_layout_ci.pSetLayouts = &ds_layout;
10997 VkPipelineLayout pipeline_layout;
10998 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
10999 ASSERT_VK_SUCCESS(err);
11000
11001 VkImageObj image(m_device);
11002 image.init(32, 32, tex_format, VK_IMAGE_USAGE_STORAGE_BIT, tiling, 0);
11003 ASSERT_TRUE(image.initialized());
11004 VkImageView view = image.targetView(tex_format);
11005
11006 VkDescriptorImageInfo image_info = {};
11007 image_info.imageView = view;
11008 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
11009
11010 VkWriteDescriptorSet descriptor_write = {};
11011 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
11012 descriptor_write.dstSet = descriptor_set;
11013 descriptor_write.dstBinding = 0;
11014 descriptor_write.descriptorCount = 1;
11015 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
11016 descriptor_write.pImageInfo = &image_info;
11017
11018 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11019 " of VK_DESCRIPTOR_TYPE_STORAGE_IMAGE type is being updated with layout "
11020 "VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL but according to spec ");
11021 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11022 m_errorMonitor->VerifyFound();
11023
11024 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11025 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11026 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
11027 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
11028}
11029
Mark Mueller93b938f2016-08-18 10:27:40 -060011030TEST_F(VkLayerTest, SimultaneousUse) {
11031 TEST_DESCRIPTION("Use vkCmdExecuteCommands with invalid state "
11032 "in primary and secondary command buffers.");
11033
11034 ASSERT_NO_FATAL_FAILURE(InitState());
11035 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11036
Mike Weiblen95dd0f92016-10-19 12:28:27 -060011037 const char *simultaneous_use_message1 = "without VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set!";
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011038 const char *simultaneous_use_message2 = "does not have VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set and "
11039 "will cause primary command buffer";
Mark Mueller93b938f2016-08-18 10:27:40 -060011040
11041 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011042 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Mueller93b938f2016-08-18 10:27:40 -060011043 command_buffer_allocate_info.commandPool = m_commandPool;
11044 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
11045 command_buffer_allocate_info.commandBufferCount = 1;
11046
11047 VkCommandBuffer secondary_command_buffer;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011048 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer));
Mark Mueller93b938f2016-08-18 10:27:40 -060011049 VkCommandBufferBeginInfo command_buffer_begin_info = {};
11050 VkCommandBufferInheritanceInfo command_buffer_inheritance_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011051 command_buffer_inheritance_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
Mark Mueller93b938f2016-08-18 10:27:40 -060011052 command_buffer_inheritance_info.renderPass = m_renderPass;
11053 command_buffer_inheritance_info.framebuffer = m_framebuffer;
11054 command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011055 command_buffer_begin_info.flags =
11056 VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT | VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT;
Mark Mueller93b938f2016-08-18 10:27:40 -060011057 command_buffer_begin_info.pInheritanceInfo = &command_buffer_inheritance_info;
11058
11059 vkBeginCommandBuffer(secondary_command_buffer, &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011060 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
11061 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller4042b652016-09-05 22:52:21 -060011062 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
Mark Mueller93b938f2016-08-18 10:27:40 -060011063 vkEndCommandBuffer(secondary_command_buffer);
11064
Mark Mueller93b938f2016-08-18 10:27:40 -060011065 VkSubmitInfo submit_info = {};
11066 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11067 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011068 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Mueller4042b652016-09-05 22:52:21 -060011069 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Mueller93b938f2016-08-18 10:27:40 -060011070
Mark Mueller4042b652016-09-05 22:52:21 -060011071 vkBeginCommandBuffer(m_commandBuffer->handle(), &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011072 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
11073 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, simultaneous_use_message1);
11074 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller93b938f2016-08-18 10:27:40 -060011075 m_errorMonitor->VerifyFound();
Mark Mueller4042b652016-09-05 22:52:21 -060011076 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
11077 vkEndCommandBuffer(m_commandBuffer->handle());
Mark Mueller93b938f2016-08-18 10:27:40 -060011078
11079 m_errorMonitor->SetDesiredFailureMsg(0, "");
Mark Mueller93b938f2016-08-18 10:27:40 -060011080 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11081
Mark Mueller4042b652016-09-05 22:52:21 -060011082 command_buffer_begin_info.flags = VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT;
Mark Mueller93b938f2016-08-18 10:27:40 -060011083 vkBeginCommandBuffer(m_commandBuffer->handle(), &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011084 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
Mark Mueller4042b652016-09-05 22:52:21 -060011085
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011086 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, simultaneous_use_message2);
11087 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller93b938f2016-08-18 10:27:40 -060011088 m_errorMonitor->VerifyFound();
Mark Mueller4042b652016-09-05 22:52:21 -060011089 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
11090 vkEndCommandBuffer(m_commandBuffer->handle());
Mark Mueller93b938f2016-08-18 10:27:40 -060011091}
11092
Mark Mueller917f6bc2016-08-30 10:57:19 -060011093TEST_F(VkLayerTest, InUseDestroyedSignaled) {
11094 TEST_DESCRIPTION("Use vkCmdExecuteCommands with invalid state "
11095 "in primary and secondary command buffers. "
Mark Muellerc8d441e2016-08-23 17:36:00 -060011096 "Delete objects that are inuse. Call VkQueueSubmit "
11097 "with an event that has been deleted.");
Mark Mueller917f6bc2016-08-30 10:57:19 -060011098
11099 ASSERT_NO_FATAL_FAILURE(InitState());
11100 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11101
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011102 const char *submit_with_deleted_event_message = "Cannot submit cmd buffer using deleted event 0x";
11103 const char *cannot_delete_event_message = "Cannot delete event 0x";
11104 const char *cannot_delete_semaphore_message = "Cannot delete semaphore 0x";
11105 const char *cannot_destroy_fence_message = "Fence 0x";
Mark Mueller917f6bc2016-08-30 10:57:19 -060011106
11107 BeginCommandBuffer();
11108
11109 VkEvent event;
11110 VkEventCreateInfo event_create_info = {};
11111 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
11112 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011113 vkCmdSetEvent(m_commandBuffer->handle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Mark Mueller917f6bc2016-08-30 10:57:19 -060011114
Mark Muellerc8d441e2016-08-23 17:36:00 -060011115 EndCommandBuffer();
11116 vkDestroyEvent(m_device->device(), event, nullptr);
11117
11118 VkSubmitInfo submit_info = {};
11119 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11120 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011121 submit_info.pCommandBuffers = &m_commandBuffer->handle();
11122 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, submit_with_deleted_event_message);
Mark Muellerc8d441e2016-08-23 17:36:00 -060011123 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11124 m_errorMonitor->VerifyFound();
11125
11126 m_errorMonitor->SetDesiredFailureMsg(0, "");
11127 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
11128
11129 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
11130
Mark Mueller917f6bc2016-08-30 10:57:19 -060011131 VkSemaphoreCreateInfo semaphore_create_info = {};
11132 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
11133 VkSemaphore semaphore;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011134 ASSERT_VK_SUCCESS(vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore));
Mark Mueller917f6bc2016-08-30 10:57:19 -060011135 VkFenceCreateInfo fence_create_info = {};
11136 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
11137 VkFence fence;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011138 ASSERT_VK_SUCCESS(vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence));
Mark Mueller917f6bc2016-08-30 10:57:19 -060011139
11140 VkDescriptorPoolSize descriptor_pool_type_count = {};
Mark Mueller4042b652016-09-05 22:52:21 -060011141 descriptor_pool_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Mark Mueller917f6bc2016-08-30 10:57:19 -060011142 descriptor_pool_type_count.descriptorCount = 1;
11143
11144 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
11145 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11146 descriptor_pool_create_info.maxSets = 1;
11147 descriptor_pool_create_info.poolSizeCount = 1;
11148 descriptor_pool_create_info.pPoolSizes = &descriptor_pool_type_count;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011149 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
Mark Mueller917f6bc2016-08-30 10:57:19 -060011150
11151 VkDescriptorPool descriptorset_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011152 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
Mark Mueller917f6bc2016-08-30 10:57:19 -060011153
11154 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
Mark Mueller4042b652016-09-05 22:52:21 -060011155 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Mark Mueller917f6bc2016-08-30 10:57:19 -060011156 descriptorset_layout_binding.descriptorCount = 1;
11157 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_ALL;
11158
11159 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011160 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060011161 descriptorset_layout_create_info.bindingCount = 1;
11162 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
11163
11164 VkDescriptorSetLayout descriptorset_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011165 ASSERT_VK_SUCCESS(
11166 vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
Mark Mueller917f6bc2016-08-30 10:57:19 -060011167
11168 VkDescriptorSet descriptorset;
11169 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011170 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060011171 descriptorset_allocate_info.descriptorSetCount = 1;
11172 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
11173 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011174 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
Mark Mueller917f6bc2016-08-30 10:57:19 -060011175
Mark Mueller4042b652016-09-05 22:52:21 -060011176 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
11177
11178 VkDescriptorBufferInfo buffer_info = {};
11179 buffer_info.buffer = buffer_test.GetBuffer();
11180 buffer_info.offset = 0;
11181 buffer_info.range = 1024;
11182
11183 VkWriteDescriptorSet write_descriptor_set = {};
11184 write_descriptor_set.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
11185 write_descriptor_set.dstSet = descriptorset;
11186 write_descriptor_set.descriptorCount = 1;
11187 write_descriptor_set.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11188 write_descriptor_set.pBufferInfo = &buffer_info;
11189
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011190 vkUpdateDescriptorSets(m_device->device(), 1, &write_descriptor_set, 0, nullptr);
Mark Mueller4042b652016-09-05 22:52:21 -060011191
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011192 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
11193 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Mueller917f6bc2016-08-30 10:57:19 -060011194
11195 VkPipelineObj pipe(m_device);
11196 pipe.AddColorAttachment();
11197 pipe.AddShader(&vs);
11198 pipe.AddShader(&fs);
11199
11200 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011201 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060011202 pipeline_layout_create_info.setLayoutCount = 1;
11203 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
11204
11205 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011206 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
Mark Mueller917f6bc2016-08-30 10:57:19 -060011207
11208 pipe.CreateVKPipeline(pipeline_layout, m_renderPass);
11209
Mark Muellerc8d441e2016-08-23 17:36:00 -060011210 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011211 vkCmdSetEvent(m_commandBuffer->handle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Mark Muellerc8d441e2016-08-23 17:36:00 -060011212
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011213 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
11214 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
11215 &descriptorset, 0, NULL);
Mark Mueller917f6bc2016-08-30 10:57:19 -060011216
Mark Muellerc8d441e2016-08-23 17:36:00 -060011217 EndCommandBuffer();
Mark Mueller917f6bc2016-08-30 10:57:19 -060011218
Mark Mueller917f6bc2016-08-30 10:57:19 -060011219 submit_info.signalSemaphoreCount = 1;
11220 submit_info.pSignalSemaphores = &semaphore;
11221 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
Mark Muellerc8d441e2016-08-23 17:36:00 -060011222
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011223 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, cannot_delete_event_message);
Mark Mueller917f6bc2016-08-30 10:57:19 -060011224 vkDestroyEvent(m_device->device(), event, nullptr);
11225 m_errorMonitor->VerifyFound();
11226
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011227 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, cannot_delete_semaphore_message);
Mark Mueller917f6bc2016-08-30 10:57:19 -060011228 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
11229 m_errorMonitor->VerifyFound();
11230
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011231 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, cannot_destroy_fence_message);
Mark Mueller917f6bc2016-08-30 10:57:19 -060011232 vkDestroyFence(m_device->device(), fence, nullptr);
11233 m_errorMonitor->VerifyFound();
11234
Tobin Ehlis122207b2016-09-01 08:50:06 -070011235 vkQueueWaitIdle(m_device->m_queue);
Mark Mueller917f6bc2016-08-30 10:57:19 -060011236 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
11237 vkDestroyFence(m_device->device(), fence, nullptr);
11238 vkDestroyEvent(m_device->device(), event, nullptr);
11239 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011240 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
Mark Mueller917f6bc2016-08-30 10:57:19 -060011241 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
11242}
11243
Tobin Ehlis2adda372016-09-01 08:51:06 -070011244TEST_F(VkLayerTest, QueryPoolInUseDestroyedSignaled) {
11245 TEST_DESCRIPTION("Delete in-use query pool.");
11246
11247 ASSERT_NO_FATAL_FAILURE(InitState());
11248 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11249
11250 VkQueryPool query_pool;
11251 VkQueryPoolCreateInfo query_pool_ci{};
11252 query_pool_ci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
11253 query_pool_ci.queryType = VK_QUERY_TYPE_TIMESTAMP;
11254 query_pool_ci.queryCount = 1;
11255 vkCreateQueryPool(m_device->device(), &query_pool_ci, nullptr, &query_pool);
11256 BeginCommandBuffer();
11257 // Reset query pool to create binding with cmd buffer
11258 vkCmdResetQueryPool(m_commandBuffer->handle(), query_pool, 0, 1);
11259
11260 EndCommandBuffer();
11261
11262 VkSubmitInfo submit_info = {};
11263 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11264 submit_info.commandBufferCount = 1;
11265 submit_info.pCommandBuffers = &m_commandBuffer->handle();
11266 // Submit cmd buffer and then destroy query pool while in-flight
11267 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11268
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011269 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete query pool 0x");
Tobin Ehlis2adda372016-09-01 08:51:06 -070011270 vkDestroyQueryPool(m_device->handle(), query_pool, NULL);
11271 m_errorMonitor->VerifyFound();
11272
11273 vkQueueWaitIdle(m_device->m_queue);
11274 // Now that cmd buffer done we can safely destroy query_pool
11275 vkDestroyQueryPool(m_device->handle(), query_pool, NULL);
11276}
11277
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060011278TEST_F(VkLayerTest, PipelineInUseDestroyedSignaled) {
11279 TEST_DESCRIPTION("Delete in-use pipeline.");
11280
11281 ASSERT_NO_FATAL_FAILURE(InitState());
11282 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11283
11284 // Empty pipeline layout used for binding PSO
11285 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11286 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11287 pipeline_layout_ci.setLayoutCount = 0;
11288 pipeline_layout_ci.pSetLayouts = NULL;
11289
11290 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011291 VkResult err = vkCreatePipelineLayout(m_device->handle(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060011292 ASSERT_VK_SUCCESS(err);
11293
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011294 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete pipeline 0x");
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060011295 // Create PSO to be used for draw-time errors below
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011296 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
11297 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060011298 // Store pipeline handle so we can actually delete it before test finishes
11299 VkPipeline delete_this_pipeline;
11300 { // Scope pipeline so it will be auto-deleted
11301 VkPipelineObj pipe(m_device);
11302 pipe.AddShader(&vs);
11303 pipe.AddShader(&fs);
11304 pipe.AddColorAttachment();
11305 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11306 delete_this_pipeline = pipe.handle();
11307
11308 BeginCommandBuffer();
11309 // Bind pipeline to cmd buffer
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011310 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060011311
11312 EndCommandBuffer();
11313
11314 VkSubmitInfo submit_info = {};
11315 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11316 submit_info.commandBufferCount = 1;
11317 submit_info.pCommandBuffers = &m_commandBuffer->handle();
11318 // Submit cmd buffer and then pipeline destroyed while in-flight
11319 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11320 } // Pipeline deletion triggered here
11321 m_errorMonitor->VerifyFound();
11322 // Make sure queue finished and then actually delete pipeline
11323 vkQueueWaitIdle(m_device->m_queue);
11324 vkDestroyPipeline(m_device->handle(), delete_this_pipeline, nullptr);
11325 vkDestroyPipelineLayout(m_device->handle(), pipeline_layout, nullptr);
11326}
11327
Tobin Ehlis7d965da2016-09-19 16:15:45 -060011328TEST_F(VkLayerTest, ImageViewInUseDestroyedSignaled) {
11329 TEST_DESCRIPTION("Delete in-use imageView.");
11330
11331 ASSERT_NO_FATAL_FAILURE(InitState());
11332 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11333
11334 VkDescriptorPoolSize ds_type_count;
11335 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11336 ds_type_count.descriptorCount = 1;
11337
11338 VkDescriptorPoolCreateInfo ds_pool_ci = {};
11339 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11340 ds_pool_ci.maxSets = 1;
11341 ds_pool_ci.poolSizeCount = 1;
11342 ds_pool_ci.pPoolSizes = &ds_type_count;
11343
11344 VkDescriptorPool ds_pool;
11345 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
11346 ASSERT_VK_SUCCESS(err);
11347
11348 VkSamplerCreateInfo sampler_ci = {};
11349 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
11350 sampler_ci.pNext = NULL;
11351 sampler_ci.magFilter = VK_FILTER_NEAREST;
11352 sampler_ci.minFilter = VK_FILTER_NEAREST;
11353 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
11354 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11355 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11356 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11357 sampler_ci.mipLodBias = 1.0;
11358 sampler_ci.anisotropyEnable = VK_FALSE;
11359 sampler_ci.maxAnisotropy = 1;
11360 sampler_ci.compareEnable = VK_FALSE;
11361 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
11362 sampler_ci.minLod = 1.0;
11363 sampler_ci.maxLod = 1.0;
11364 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
11365 sampler_ci.unnormalizedCoordinates = VK_FALSE;
11366 VkSampler sampler;
11367
11368 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
11369 ASSERT_VK_SUCCESS(err);
11370
11371 VkDescriptorSetLayoutBinding layout_binding;
11372 layout_binding.binding = 0;
11373 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11374 layout_binding.descriptorCount = 1;
11375 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
11376 layout_binding.pImmutableSamplers = NULL;
11377
11378 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11379 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11380 ds_layout_ci.bindingCount = 1;
11381 ds_layout_ci.pBindings = &layout_binding;
11382 VkDescriptorSetLayout ds_layout;
11383 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
11384 ASSERT_VK_SUCCESS(err);
11385
11386 VkDescriptorSetAllocateInfo alloc_info = {};
11387 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11388 alloc_info.descriptorSetCount = 1;
11389 alloc_info.descriptorPool = ds_pool;
11390 alloc_info.pSetLayouts = &ds_layout;
11391 VkDescriptorSet descriptor_set;
11392 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
11393 ASSERT_VK_SUCCESS(err);
11394
11395 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11396 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11397 pipeline_layout_ci.pNext = NULL;
11398 pipeline_layout_ci.setLayoutCount = 1;
11399 pipeline_layout_ci.pSetLayouts = &ds_layout;
11400
11401 VkPipelineLayout pipeline_layout;
11402 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
11403 ASSERT_VK_SUCCESS(err);
11404
11405 VkImageObj image(m_device);
11406 image.init(128, 128, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
11407 ASSERT_TRUE(image.initialized());
11408
11409 VkImageView view;
11410 VkImageViewCreateInfo ivci = {};
11411 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
11412 ivci.image = image.handle();
11413 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
11414 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
11415 ivci.subresourceRange.layerCount = 1;
11416 ivci.subresourceRange.baseMipLevel = 0;
11417 ivci.subresourceRange.levelCount = 1;
11418 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11419
11420 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
11421 ASSERT_VK_SUCCESS(err);
11422
11423 VkDescriptorImageInfo image_info{};
11424 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
11425 image_info.imageView = view;
11426 image_info.sampler = sampler;
11427
11428 VkWriteDescriptorSet descriptor_write = {};
11429 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
11430 descriptor_write.dstSet = descriptor_set;
11431 descriptor_write.dstBinding = 0;
11432 descriptor_write.descriptorCount = 1;
11433 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11434 descriptor_write.pImageInfo = &image_info;
11435
11436 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11437
11438 // Create PSO to use the sampler
11439 char const *vsSource = "#version 450\n"
11440 "\n"
11441 "out gl_PerVertex { \n"
11442 " vec4 gl_Position;\n"
11443 "};\n"
11444 "void main(){\n"
11445 " gl_Position = vec4(1);\n"
11446 "}\n";
11447 char const *fsSource = "#version 450\n"
11448 "\n"
11449 "layout(set=0, binding=0) uniform sampler2D s;\n"
11450 "layout(location=0) out vec4 x;\n"
11451 "void main(){\n"
11452 " x = texture(s, vec2(1));\n"
11453 "}\n";
11454 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
11455 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
11456 VkPipelineObj pipe(m_device);
11457 pipe.AddShader(&vs);
11458 pipe.AddShader(&fs);
11459 pipe.AddColorAttachment();
11460 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11461
11462 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete image view 0x");
11463
11464 BeginCommandBuffer();
11465 // Bind pipeline to cmd buffer
11466 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
11467 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
11468 &descriptor_set, 0, nullptr);
11469 Draw(1, 0, 0, 0);
11470 EndCommandBuffer();
11471 // Submit cmd buffer then destroy sampler
11472 VkSubmitInfo submit_info = {};
11473 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11474 submit_info.commandBufferCount = 1;
11475 submit_info.pCommandBuffers = &m_commandBuffer->handle();
11476 // Submit cmd buffer and then destroy imageView while in-flight
11477 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11478
11479 vkDestroyImageView(m_device->device(), view, nullptr);
11480 m_errorMonitor->VerifyFound();
11481 vkQueueWaitIdle(m_device->m_queue);
11482 // Now we can actually destroy imageView
11483 vkDestroyImageView(m_device->device(), view, NULL);
11484 vkDestroySampler(m_device->device(), sampler, nullptr);
11485 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11486 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11487 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
11488}
11489
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060011490TEST_F(VkLayerTest, BufferViewInUseDestroyedSignaled) {
11491 TEST_DESCRIPTION("Delete in-use bufferView.");
11492
11493 ASSERT_NO_FATAL_FAILURE(InitState());
11494 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11495
11496 VkDescriptorPoolSize ds_type_count;
11497 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
11498 ds_type_count.descriptorCount = 1;
11499
11500 VkDescriptorPoolCreateInfo ds_pool_ci = {};
11501 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11502 ds_pool_ci.maxSets = 1;
11503 ds_pool_ci.poolSizeCount = 1;
11504 ds_pool_ci.pPoolSizes = &ds_type_count;
11505
11506 VkDescriptorPool ds_pool;
11507 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
11508 ASSERT_VK_SUCCESS(err);
11509
11510 VkDescriptorSetLayoutBinding layout_binding;
11511 layout_binding.binding = 0;
11512 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
11513 layout_binding.descriptorCount = 1;
11514 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
11515 layout_binding.pImmutableSamplers = NULL;
11516
11517 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11518 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11519 ds_layout_ci.bindingCount = 1;
11520 ds_layout_ci.pBindings = &layout_binding;
11521 VkDescriptorSetLayout ds_layout;
11522 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
11523 ASSERT_VK_SUCCESS(err);
11524
11525 VkDescriptorSetAllocateInfo alloc_info = {};
11526 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11527 alloc_info.descriptorSetCount = 1;
11528 alloc_info.descriptorPool = ds_pool;
11529 alloc_info.pSetLayouts = &ds_layout;
11530 VkDescriptorSet descriptor_set;
11531 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
11532 ASSERT_VK_SUCCESS(err);
11533
11534 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11535 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11536 pipeline_layout_ci.pNext = NULL;
11537 pipeline_layout_ci.setLayoutCount = 1;
11538 pipeline_layout_ci.pSetLayouts = &ds_layout;
11539
11540 VkPipelineLayout pipeline_layout;
11541 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
11542 ASSERT_VK_SUCCESS(err);
11543
11544 VkBuffer buffer;
11545 uint32_t queue_family_index = 0;
11546 VkBufferCreateInfo buffer_create_info = {};
11547 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
11548 buffer_create_info.size = 1024;
11549 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
11550 buffer_create_info.queueFamilyIndexCount = 1;
11551 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
11552
11553 err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
11554 ASSERT_VK_SUCCESS(err);
11555
11556 VkMemoryRequirements memory_reqs;
11557 VkDeviceMemory buffer_memory;
11558
11559 VkMemoryAllocateInfo memory_info = {};
11560 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
11561 memory_info.allocationSize = 0;
11562 memory_info.memoryTypeIndex = 0;
11563
11564 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
11565 memory_info.allocationSize = memory_reqs.size;
11566 bool pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
11567 ASSERT_TRUE(pass);
11568
11569 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
11570 ASSERT_VK_SUCCESS(err);
11571 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
11572 ASSERT_VK_SUCCESS(err);
11573
11574 VkBufferView view;
11575 VkBufferViewCreateInfo bvci = {};
11576 bvci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
11577 bvci.buffer = buffer;
11578 bvci.format = VK_FORMAT_R8_UNORM;
11579 bvci.range = VK_WHOLE_SIZE;
11580
11581 err = vkCreateBufferView(m_device->device(), &bvci, NULL, &view);
11582 ASSERT_VK_SUCCESS(err);
11583
11584 VkWriteDescriptorSet descriptor_write = {};
11585 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
11586 descriptor_write.dstSet = descriptor_set;
11587 descriptor_write.dstBinding = 0;
11588 descriptor_write.descriptorCount = 1;
11589 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
11590 descriptor_write.pTexelBufferView = &view;
11591
11592 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11593
11594 char const *vsSource = "#version 450\n"
11595 "\n"
11596 "out gl_PerVertex { \n"
11597 " vec4 gl_Position;\n"
11598 "};\n"
11599 "void main(){\n"
11600 " gl_Position = vec4(1);\n"
11601 "}\n";
11602 char const *fsSource = "#version 450\n"
11603 "\n"
11604 "layout(set=0, binding=0, r8) uniform imageBuffer s;\n"
11605 "layout(location=0) out vec4 x;\n"
11606 "void main(){\n"
11607 " x = imageLoad(s, 0);\n"
11608 "}\n";
11609 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
11610 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
11611 VkPipelineObj pipe(m_device);
11612 pipe.AddShader(&vs);
11613 pipe.AddShader(&fs);
11614 pipe.AddColorAttachment();
11615 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11616
11617 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete buffer view 0x");
11618
11619 BeginCommandBuffer();
11620 VkViewport viewport = {0, 0, 16, 16, 0, 1};
11621 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
11622 VkRect2D scissor = {{0, 0}, {16, 16}};
11623 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
11624 // Bind pipeline to cmd buffer
11625 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
11626 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
11627 &descriptor_set, 0, nullptr);
11628 Draw(1, 0, 0, 0);
11629 EndCommandBuffer();
11630
11631 VkSubmitInfo submit_info = {};
11632 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11633 submit_info.commandBufferCount = 1;
11634 submit_info.pCommandBuffers = &m_commandBuffer->handle();
11635 // Submit cmd buffer and then destroy bufferView while in-flight
11636 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11637
11638 vkDestroyBufferView(m_device->device(), view, nullptr);
11639 m_errorMonitor->VerifyFound();
11640 vkQueueWaitIdle(m_device->m_queue);
11641 // Now we can actually destroy bufferView
11642 vkDestroyBufferView(m_device->device(), view, NULL);
11643 vkDestroyBuffer(m_device->device(), buffer, NULL);
11644 vkFreeMemory(m_device->device(), buffer_memory, NULL);
11645 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11646 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11647 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
11648}
11649
Tobin Ehlis209532e2016-09-07 13:52:18 -060011650TEST_F(VkLayerTest, SamplerInUseDestroyedSignaled) {
11651 TEST_DESCRIPTION("Delete in-use sampler.");
11652
11653 ASSERT_NO_FATAL_FAILURE(InitState());
11654 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11655
11656 VkDescriptorPoolSize ds_type_count;
11657 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11658 ds_type_count.descriptorCount = 1;
11659
11660 VkDescriptorPoolCreateInfo ds_pool_ci = {};
11661 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11662 ds_pool_ci.maxSets = 1;
11663 ds_pool_ci.poolSizeCount = 1;
11664 ds_pool_ci.pPoolSizes = &ds_type_count;
11665
11666 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011667 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis209532e2016-09-07 13:52:18 -060011668 ASSERT_VK_SUCCESS(err);
11669
11670 VkSamplerCreateInfo sampler_ci = {};
11671 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
11672 sampler_ci.pNext = NULL;
11673 sampler_ci.magFilter = VK_FILTER_NEAREST;
11674 sampler_ci.minFilter = VK_FILTER_NEAREST;
11675 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
11676 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11677 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11678 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11679 sampler_ci.mipLodBias = 1.0;
11680 sampler_ci.anisotropyEnable = VK_FALSE;
11681 sampler_ci.maxAnisotropy = 1;
11682 sampler_ci.compareEnable = VK_FALSE;
11683 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
11684 sampler_ci.minLod = 1.0;
11685 sampler_ci.maxLod = 1.0;
11686 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
11687 sampler_ci.unnormalizedCoordinates = VK_FALSE;
11688 VkSampler sampler;
11689
11690 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
11691 ASSERT_VK_SUCCESS(err);
11692
11693 VkDescriptorSetLayoutBinding layout_binding;
11694 layout_binding.binding = 0;
Tobin Ehlis94fc0ad2016-09-19 16:23:01 -060011695 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
Tobin Ehlis209532e2016-09-07 13:52:18 -060011696 layout_binding.descriptorCount = 1;
11697 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
11698 layout_binding.pImmutableSamplers = NULL;
11699
11700 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11701 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11702 ds_layout_ci.bindingCount = 1;
11703 ds_layout_ci.pBindings = &layout_binding;
11704 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011705 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis209532e2016-09-07 13:52:18 -060011706 ASSERT_VK_SUCCESS(err);
11707
11708 VkDescriptorSetAllocateInfo alloc_info = {};
11709 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11710 alloc_info.descriptorSetCount = 1;
11711 alloc_info.descriptorPool = ds_pool;
11712 alloc_info.pSetLayouts = &ds_layout;
11713 VkDescriptorSet descriptor_set;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011714 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis209532e2016-09-07 13:52:18 -060011715 ASSERT_VK_SUCCESS(err);
11716
11717 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11718 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11719 pipeline_layout_ci.pNext = NULL;
11720 pipeline_layout_ci.setLayoutCount = 1;
11721 pipeline_layout_ci.pSetLayouts = &ds_layout;
11722
11723 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011724 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis209532e2016-09-07 13:52:18 -060011725 ASSERT_VK_SUCCESS(err);
11726
11727 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011728 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 -060011729 ASSERT_TRUE(image.initialized());
11730
11731 VkImageView view;
11732 VkImageViewCreateInfo ivci = {};
11733 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
11734 ivci.image = image.handle();
11735 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
11736 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
11737 ivci.subresourceRange.layerCount = 1;
11738 ivci.subresourceRange.baseMipLevel = 0;
11739 ivci.subresourceRange.levelCount = 1;
11740 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11741
11742 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
11743 ASSERT_VK_SUCCESS(err);
11744
11745 VkDescriptorImageInfo image_info{};
11746 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
11747 image_info.imageView = view;
11748 image_info.sampler = sampler;
11749
11750 VkWriteDescriptorSet descriptor_write = {};
11751 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
11752 descriptor_write.dstSet = descriptor_set;
11753 descriptor_write.dstBinding = 0;
11754 descriptor_write.descriptorCount = 1;
11755 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11756 descriptor_write.pImageInfo = &image_info;
11757
11758 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11759
11760 // Create PSO to use the sampler
11761 char const *vsSource = "#version 450\n"
11762 "\n"
11763 "out gl_PerVertex { \n"
11764 " vec4 gl_Position;\n"
11765 "};\n"
11766 "void main(){\n"
11767 " gl_Position = vec4(1);\n"
11768 "}\n";
11769 char const *fsSource = "#version 450\n"
11770 "\n"
11771 "layout(set=0, binding=0) uniform sampler2D s;\n"
11772 "layout(location=0) out vec4 x;\n"
11773 "void main(){\n"
11774 " x = texture(s, vec2(1));\n"
11775 "}\n";
11776 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
11777 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
11778 VkPipelineObj pipe(m_device);
11779 pipe.AddShader(&vs);
11780 pipe.AddShader(&fs);
11781 pipe.AddColorAttachment();
11782 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11783
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011784 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete sampler 0x");
Tobin Ehlis209532e2016-09-07 13:52:18 -060011785
11786 BeginCommandBuffer();
11787 // Bind pipeline to cmd buffer
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011788 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
11789 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
11790 &descriptor_set, 0, nullptr);
Tobin Ehlis209532e2016-09-07 13:52:18 -060011791 Draw(1, 0, 0, 0);
11792 EndCommandBuffer();
11793 // Submit cmd buffer then destroy sampler
11794 VkSubmitInfo submit_info = {};
11795 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11796 submit_info.commandBufferCount = 1;
11797 submit_info.pCommandBuffers = &m_commandBuffer->handle();
11798 // Submit cmd buffer and then destroy sampler while in-flight
11799 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11800
11801 vkDestroySampler(m_device->device(), sampler, nullptr);
11802 m_errorMonitor->VerifyFound();
11803 vkQueueWaitIdle(m_device->m_queue);
11804 // Now we can actually destroy sampler
11805 vkDestroySampler(m_device->device(), sampler, nullptr);
11806 vkDestroyImageView(m_device->device(), view, NULL);
11807 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11808 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11809 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
11810}
11811
Mark Mueller1cd9f412016-08-25 13:23:52 -060011812TEST_F(VkLayerTest, QueueForwardProgressFenceWait) {
Mark Mueller96a56d52016-08-24 10:28:05 -060011813 TEST_DESCRIPTION("Call VkQueueSubmit with a semaphore that is already "
Mark Mueller1cd9f412016-08-25 13:23:52 -060011814 "signaled but not waited on by the queue. Wait on a "
11815 "fence that has not yet been submitted to a queue.");
Mark Mueller96a56d52016-08-24 10:28:05 -060011816
11817 ASSERT_NO_FATAL_FAILURE(InitState());
11818 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11819
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011820 const char *queue_forward_progress_message = " that has already been signaled but not waited on by queue 0x";
11821 const char *invalid_fence_wait_message = " which has not been submitted on a Queue or during "
11822 "acquire next image.";
Mark Mueller96a56d52016-08-24 10:28:05 -060011823
11824 BeginCommandBuffer();
11825 EndCommandBuffer();
11826
11827 VkSemaphoreCreateInfo semaphore_create_info = {};
11828 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
11829 VkSemaphore semaphore;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011830 ASSERT_VK_SUCCESS(vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore));
Mark Mueller96a56d52016-08-24 10:28:05 -060011831 VkSubmitInfo submit_info = {};
11832 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11833 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011834 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Mueller96a56d52016-08-24 10:28:05 -060011835 submit_info.signalSemaphoreCount = 1;
11836 submit_info.pSignalSemaphores = &semaphore;
11837 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11838 m_errorMonitor->SetDesiredFailureMsg(0, "");
11839 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
11840 BeginCommandBuffer();
11841 EndCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011842 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, queue_forward_progress_message);
Mark Mueller96a56d52016-08-24 10:28:05 -060011843 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11844 m_errorMonitor->VerifyFound();
11845
Mark Mueller1cd9f412016-08-25 13:23:52 -060011846 VkFenceCreateInfo fence_create_info = {};
11847 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
11848 VkFence fence;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011849 ASSERT_VK_SUCCESS(vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence));
Mark Mueller1cd9f412016-08-25 13:23:52 -060011850
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011851 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, invalid_fence_wait_message);
Mark Mueller1cd9f412016-08-25 13:23:52 -060011852 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
11853 m_errorMonitor->VerifyFound();
11854
Mark Mueller4042b652016-09-05 22:52:21 -060011855 vkDeviceWaitIdle(m_device->device());
Mark Mueller1cd9f412016-08-25 13:23:52 -060011856 vkDestroyFence(m_device->device(), fence, nullptr);
Mark Mueller96a56d52016-08-24 10:28:05 -060011857 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
11858}
11859
Tobin Ehlis4af23302016-07-19 10:50:30 -060011860TEST_F(VkLayerTest, FramebufferIncompatible) {
11861 TEST_DESCRIPTION("Bind a secondary command buffer with with a framebuffer "
11862 "that does not match the framebuffer for the active "
11863 "renderpass.");
11864 ASSERT_NO_FATAL_FAILURE(InitState());
11865 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11866
11867 // A renderpass with one color attachment.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011868 VkAttachmentDescription attachment = {0,
11869 VK_FORMAT_B8G8R8A8_UNORM,
11870 VK_SAMPLE_COUNT_1_BIT,
11871 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
11872 VK_ATTACHMENT_STORE_OP_STORE,
11873 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
11874 VK_ATTACHMENT_STORE_OP_DONT_CARE,
11875 VK_IMAGE_LAYOUT_UNDEFINED,
11876 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis4af23302016-07-19 10:50:30 -060011877
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011878 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis4af23302016-07-19 10:50:30 -060011879
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011880 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Tobin Ehlis4af23302016-07-19 10:50:30 -060011881
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011882 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
Tobin Ehlis4af23302016-07-19 10:50:30 -060011883
11884 VkRenderPass rp;
11885 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
11886 ASSERT_VK_SUCCESS(err);
11887
11888 // A compatible framebuffer.
11889 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011890 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 -060011891 ASSERT_TRUE(image.initialized());
11892
11893 VkImageViewCreateInfo ivci = {
11894 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
11895 nullptr,
11896 0,
11897 image.handle(),
11898 VK_IMAGE_VIEW_TYPE_2D,
11899 VK_FORMAT_B8G8R8A8_UNORM,
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011900 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
11901 VK_COMPONENT_SWIZZLE_IDENTITY},
Tobin Ehlis4af23302016-07-19 10:50:30 -060011902 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
11903 };
11904 VkImageView view;
11905 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
11906 ASSERT_VK_SUCCESS(err);
11907
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011908 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Tobin Ehlis4af23302016-07-19 10:50:30 -060011909 VkFramebuffer fb;
11910 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
11911 ASSERT_VK_SUCCESS(err);
11912
11913 VkCommandBufferAllocateInfo cbai = {};
11914 cbai.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
11915 cbai.commandPool = m_commandPool;
11916 cbai.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
11917 cbai.commandBufferCount = 1;
11918
11919 VkCommandBuffer sec_cb;
11920 err = vkAllocateCommandBuffers(m_device->device(), &cbai, &sec_cb);
11921 ASSERT_VK_SUCCESS(err);
11922 VkCommandBufferBeginInfo cbbi = {};
11923 VkCommandBufferInheritanceInfo cbii = {};
Chris Forbes98420382016-11-28 17:56:51 +130011924 cbii.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
Tobin Ehlis4af23302016-07-19 10:50:30 -060011925 cbii.renderPass = renderPass();
11926 cbii.framebuffer = fb;
11927 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
11928 cbbi.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011929 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 -060011930 cbbi.pInheritanceInfo = &cbii;
11931 vkBeginCommandBuffer(sec_cb, &cbbi);
11932 vkEndCommandBuffer(sec_cb);
11933
Chris Forbes3400bc52016-09-13 18:10:34 +120011934 VkCommandBufferBeginInfo cbbi2 = {
11935 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr,
11936 0, nullptr
11937 };
11938 vkBeginCommandBuffer(m_commandBuffer->GetBufferHandle(), &cbbi2);
11939 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
Tobin Ehlis4af23302016-07-19 10:50:30 -060011940
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011941 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mike Weiblencce7ec72016-10-17 19:33:05 -060011942 " that is not the same as the primary command buffer's current active framebuffer ");
Tobin Ehlis4af23302016-07-19 10:50:30 -060011943 vkCmdExecuteCommands(m_commandBuffer->GetBufferHandle(), 1, &sec_cb);
11944 m_errorMonitor->VerifyFound();
11945 // Cleanup
11946 vkDestroyImageView(m_device->device(), view, NULL);
11947 vkDestroyRenderPass(m_device->device(), rp, NULL);
11948 vkDestroyFramebuffer(m_device->device(), fb, NULL);
11949}
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011950
11951TEST_F(VkLayerTest, ColorBlendLogicOpTests) {
11952 TEST_DESCRIPTION("If logicOp is available on the device, set it to an "
11953 "invalid value. If logicOp is not available, attempt to "
11954 "use it and verify that we see the correct error.");
11955 ASSERT_NO_FATAL_FAILURE(InitState());
11956 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11957
11958 auto features = m_device->phy().features();
11959 // Set the expected error depending on whether or not logicOp available
11960 if (VK_FALSE == features.logicOp) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011961 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "If logic operations feature not "
11962 "enabled, logicOpEnable must be "
11963 "VK_FALSE");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011964 } else {
Chris Forbes34797bc2016-10-03 15:28:49 +130011965 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "pColorBlendState->logicOp (16)");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011966 }
11967 // Create a pipeline using logicOp
11968 VkResult err;
11969
11970 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11971 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11972
11973 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011974 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011975 ASSERT_VK_SUCCESS(err);
11976
11977 VkPipelineViewportStateCreateInfo vp_state_ci = {};
11978 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
11979 vp_state_ci.viewportCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011980 VkViewport vp = {}; // Just need dummy vp to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011981 vp_state_ci.pViewports = &vp;
11982 vp_state_ci.scissorCount = 1;
11983 VkRect2D scissors = {}; // Dummy scissors to point to
11984 vp_state_ci.pScissors = &scissors;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011985
11986 VkPipelineShaderStageCreateInfo shaderStages[2];
11987 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
11988
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011989 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
11990 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011991 shaderStages[0] = vs.GetStageCreateInfo();
11992 shaderStages[1] = fs.GetStageCreateInfo();
11993
11994 VkPipelineVertexInputStateCreateInfo vi_ci = {};
11995 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
11996
11997 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
11998 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
11999 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
12000
12001 VkPipelineRasterizationStateCreateInfo rs_ci = {};
12002 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Chris Forbes14088512016-10-03 14:28:00 +130012003 rs_ci.lineWidth = 1.0f;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012004
12005 VkPipelineColorBlendAttachmentState att = {};
12006 att.blendEnable = VK_FALSE;
12007 att.colorWriteMask = 0xf;
12008
12009 VkPipelineColorBlendStateCreateInfo cb_ci = {};
12010 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
12011 // Enable logicOp & set logicOp to value 1 beyond allowed entries
12012 cb_ci.logicOpEnable = VK_TRUE;
12013 cb_ci.logicOp = VK_LOGIC_OP_RANGE_SIZE; // This should cause an error
12014 cb_ci.attachmentCount = 1;
12015 cb_ci.pAttachments = &att;
12016
Chris Forbes8aeacbf2016-10-03 14:25:08 +130012017 VkPipelineMultisampleStateCreateInfo ms_ci = {};
12018 ms_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
12019 ms_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
12020
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012021 VkGraphicsPipelineCreateInfo gp_ci = {};
12022 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
12023 gp_ci.stageCount = 2;
12024 gp_ci.pStages = shaderStages;
12025 gp_ci.pVertexInputState = &vi_ci;
12026 gp_ci.pInputAssemblyState = &ia_ci;
12027 gp_ci.pViewportState = &vp_state_ci;
12028 gp_ci.pRasterizationState = &rs_ci;
12029 gp_ci.pColorBlendState = &cb_ci;
Chris Forbes8aeacbf2016-10-03 14:25:08 +130012030 gp_ci.pMultisampleState = &ms_ci;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012031 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
12032 gp_ci.layout = pipeline_layout;
12033 gp_ci.renderPass = renderPass();
12034
12035 VkPipelineCacheCreateInfo pc_ci = {};
12036 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
12037
12038 VkPipeline pipeline;
12039 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012040 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012041 ASSERT_VK_SUCCESS(err);
12042
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012043 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012044 m_errorMonitor->VerifyFound();
12045 if (VK_SUCCESS == err) {
12046 vkDestroyPipeline(m_device->device(), pipeline, NULL);
12047 }
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012048 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
12049 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
12050}
Mark Lobodzinski209b5292015-09-17 09:44:05 -060012051#endif // DRAW_STATE_TESTS
12052
Tobin Ehlis0788f522015-05-26 16:11:58 -060012053#if THREADING_TESTS
Mike Stroyanaccf7692015-05-12 16:00:45 -060012054#if GTEST_IS_THREADSAFE
12055struct thread_data_struct {
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012056 VkCommandBuffer commandBuffer;
Mike Stroyanaccf7692015-05-12 16:00:45 -060012057 VkEvent event;
12058 bool bailout;
12059};
12060
Karl Schultz6addd812016-02-02 17:17:23 -070012061extern "C" void *AddToCommandBuffer(void *arg) {
12062 struct thread_data_struct *data = (struct thread_data_struct *)arg;
Mike Stroyanaccf7692015-05-12 16:00:45 -060012063
Mike Stroyana6d14942016-07-13 15:10:05 -060012064 for (int i = 0; i < 80000; i++) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012065 vkCmdSetEvent(data->commandBuffer, data->event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Mike Stroyanaccf7692015-05-12 16:00:45 -060012066 if (data->bailout) {
12067 break;
12068 }
12069 }
12070 return NULL;
12071}
12072
Karl Schultz6addd812016-02-02 17:17:23 -070012073TEST_F(VkLayerTest, ThreadCommandBufferCollision) {
Mike Stroyan4268d1f2015-07-13 14:45:35 -060012074 test_platform_thread thread;
Mike Stroyanaccf7692015-05-12 16:00:45 -060012075
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012076 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "THREADING ERROR");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012077
Mike Stroyanaccf7692015-05-12 16:00:45 -060012078 ASSERT_NO_FATAL_FAILURE(InitState());
12079 ASSERT_NO_FATAL_FAILURE(InitViewport());
12080 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12081
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012082 // Calls AllocateCommandBuffers
12083 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Mark Lobodzinski5495d132015-09-30 16:19:16 -060012084
12085 // Avoid creating RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012086 commandBuffer.BeginCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -060012087
12088 VkEventCreateInfo event_info;
12089 VkEvent event;
Mike Stroyanaccf7692015-05-12 16:00:45 -060012090 VkResult err;
12091
12092 memset(&event_info, 0, sizeof(event_info));
12093 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
12094
Chia-I Wuf7458c52015-10-26 21:10:41 +080012095 err = vkCreateEvent(device(), &event_info, NULL, &event);
Mike Stroyanaccf7692015-05-12 16:00:45 -060012096 ASSERT_VK_SUCCESS(err);
12097
Mike Stroyanaccf7692015-05-12 16:00:45 -060012098 err = vkResetEvent(device(), event);
12099 ASSERT_VK_SUCCESS(err);
12100
12101 struct thread_data_struct data;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012102 data.commandBuffer = commandBuffer.GetBufferHandle();
Mike Stroyanaccf7692015-05-12 16:00:45 -060012103 data.event = event;
12104 data.bailout = false;
12105 m_errorMonitor->SetBailout(&data.bailout);
Mike Stroyana6d14942016-07-13 15:10:05 -060012106
12107 // First do some correct operations using multiple threads.
12108 // Add many entries to command buffer from another thread.
12109 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
12110 // Make non-conflicting calls from this thread at the same time.
12111 for (int i = 0; i < 80000; i++) {
Mike Stroyand6343902016-07-14 08:56:16 -060012112 uint32_t count;
12113 vkEnumeratePhysicalDevices(instance(), &count, NULL);
Mike Stroyana6d14942016-07-13 15:10:05 -060012114 }
12115 test_platform_thread_join(thread, NULL);
12116
12117 // Then do some incorrect operations using multiple threads.
Mike Stroyanaccf7692015-05-12 16:00:45 -060012118 // Add many entries to command buffer from another thread.
Mike Stroyan4268d1f2015-07-13 14:45:35 -060012119 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
Mike Stroyanaccf7692015-05-12 16:00:45 -060012120 // Add many entries to command buffer from this thread at the same time.
12121 AddToCommandBuffer(&data);
Mark Lobodzinski5495d132015-09-30 16:19:16 -060012122
Mike Stroyan4268d1f2015-07-13 14:45:35 -060012123 test_platform_thread_join(thread, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012124 commandBuffer.EndCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -060012125
Mike Stroyan10b8cb72016-01-22 15:22:03 -070012126 m_errorMonitor->SetBailout(NULL);
12127
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012128 m_errorMonitor->VerifyFound();
Mike Stroyanaccf7692015-05-12 16:00:45 -060012129
Chia-I Wuf7458c52015-10-26 21:10:41 +080012130 vkDestroyEvent(device(), event, NULL);
Mike Stroyanaccf7692015-05-12 16:00:45 -060012131}
Mark Lobodzinski209b5292015-09-17 09:44:05 -060012132#endif // GTEST_IS_THREADSAFE
12133#endif // THREADING_TESTS
12134
Chris Forbes9f7ff632015-05-25 11:13:08 +120012135#if SHADER_CHECKER_TESTS
Karl Schultz6addd812016-02-02 17:17:23 -070012136TEST_F(VkLayerTest, InvalidSPIRVCodeSize) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012137 TEST_DESCRIPTION("Test that an error is produced for a spirv module "
12138 "with an impossible code size");
12139
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012140 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012141
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012142 ASSERT_NO_FATAL_FAILURE(InitState());
12143 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12144
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012145 VkShaderModule module;
12146 VkShaderModuleCreateInfo moduleCreateInfo;
12147 struct icd_spv_header spv;
12148
12149 spv.magic = ICD_SPV_MAGIC;
12150 spv.version = ICD_SPV_VERSION;
12151 spv.gen_magic = 0;
12152
12153 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
12154 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -070012155 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012156 moduleCreateInfo.codeSize = 4;
12157 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080012158 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012159
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012160 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012161}
12162
Karl Schultz6addd812016-02-02 17:17:23 -070012163TEST_F(VkLayerTest, InvalidSPIRVMagic) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012164 TEST_DESCRIPTION("Test that an error is produced for a spirv module "
12165 "with a bad magic number");
12166
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012167 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid SPIR-V magic number");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012168
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012169 ASSERT_NO_FATAL_FAILURE(InitState());
12170 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12171
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012172 VkShaderModule module;
12173 VkShaderModuleCreateInfo moduleCreateInfo;
12174 struct icd_spv_header spv;
12175
12176 spv.magic = ~ICD_SPV_MAGIC;
12177 spv.version = ICD_SPV_VERSION;
12178 spv.gen_magic = 0;
12179
12180 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
12181 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -070012182 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012183 moduleCreateInfo.codeSize = sizeof(spv) + 10;
12184 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080012185 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012186
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012187 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012188}
12189
Chris Forbesb4afd0f2016-04-04 10:48:35 +120012190#if 0
12191// Not currently covered by SPIRV-Tools validator
Karl Schultz6addd812016-02-02 17:17:23 -070012192TEST_F(VkLayerTest, InvalidSPIRVVersion) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -070012193 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbesb4afd0f2016-04-04 10:48:35 +120012194 "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012195
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012196 ASSERT_NO_FATAL_FAILURE(InitState());
12197 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12198
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012199 VkShaderModule module;
12200 VkShaderModuleCreateInfo moduleCreateInfo;
12201 struct icd_spv_header spv;
12202
12203 spv.magic = ICD_SPV_MAGIC;
12204 spv.version = ~ICD_SPV_VERSION;
12205 spv.gen_magic = 0;
12206
12207 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
12208 moduleCreateInfo.pNext = NULL;
12209
Karl Schultz6addd812016-02-02 17:17:23 -070012210 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012211 moduleCreateInfo.codeSize = sizeof(spv) + 10;
12212 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080012213 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012214
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012215 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012216}
Chris Forbesb4afd0f2016-04-04 10:48:35 +120012217#endif
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012218
Karl Schultz6addd812016-02-02 17:17:23 -070012219TEST_F(VkLayerTest, CreatePipelineVertexOutputNotConsumed) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012220 TEST_DESCRIPTION("Test that a warning is produced for a vertex output that "
12221 "is not consumed by the fragment stage");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012222 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "not consumed by fragment shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012223
Chris Forbes9f7ff632015-05-25 11:13:08 +120012224 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060012225 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes9f7ff632015-05-25 11:13:08 +120012226
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012227 char const *vsSource = "#version 450\n"
12228 "\n"
12229 "layout(location=0) out float x;\n"
12230 "out gl_PerVertex {\n"
12231 " vec4 gl_Position;\n"
12232 "};\n"
12233 "void main(){\n"
12234 " gl_Position = vec4(1);\n"
12235 " x = 0;\n"
12236 "}\n";
12237 char const *fsSource = "#version 450\n"
12238 "\n"
12239 "layout(location=0) out vec4 color;\n"
12240 "void main(){\n"
12241 " color = vec4(1);\n"
12242 "}\n";
Chris Forbes9f7ff632015-05-25 11:13:08 +120012243
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012244 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12245 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes9f7ff632015-05-25 11:13:08 +120012246
12247 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080012248 pipe.AddColorAttachment();
Chris Forbes9f7ff632015-05-25 11:13:08 +120012249 pipe.AddShader(&vs);
12250 pipe.AddShader(&fs);
12251
Chris Forbes9f7ff632015-05-25 11:13:08 +120012252 VkDescriptorSetObj descriptorSet(m_device);
12253 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012254 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes9f7ff632015-05-25 11:13:08 +120012255
Tony Barbour5781e8f2015-08-04 16:23:11 -060012256 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes9f7ff632015-05-25 11:13:08 +120012257
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012258 m_errorMonitor->VerifyFound();
Chris Forbes9f7ff632015-05-25 11:13:08 +120012259}
Chris Forbes9f7ff632015-05-25 11:13:08 +120012260
Mark Mueller098c9cb2016-09-08 09:01:57 -060012261TEST_F(VkLayerTest, CreatePipelineCheckShaderBadSpecialization) {
12262 TEST_DESCRIPTION("Challenge core_validation with shader validation issues related to vkCreateGraphicsPipelines.");
12263
12264 ASSERT_NO_FATAL_FAILURE(InitState());
12265 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12266
12267 const char *bad_specialization_message =
12268 "Specialization entry 0 (for constant id 0) references memory outside provided specialization data ";
12269
12270 char const *vsSource =
12271 "#version 450\n"
12272 "\n"
12273 "out gl_PerVertex {\n"
12274 " vec4 gl_Position;\n"
12275 "};\n"
12276 "void main(){\n"
12277 " gl_Position = vec4(1);\n"
12278 "}\n";
12279
12280 char const *fsSource =
12281 "#version 450\n"
12282 "\n"
12283 "layout (constant_id = 0) const float r = 0.0f;\n"
12284 "layout(location = 0) out vec4 uFragColor;\n"
12285 "void main(){\n"
12286 " uFragColor = vec4(r,1,0,1);\n"
12287 "}\n";
12288
12289 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12290 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12291
12292 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
12293 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12294
12295 VkPipelineLayout pipeline_layout;
12296 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
12297
12298 VkPipelineViewportStateCreateInfo vp_state_create_info = {};
12299 vp_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
12300 vp_state_create_info.viewportCount = 1;
12301 VkViewport viewport = {};
12302 vp_state_create_info.pViewports = &viewport;
12303 vp_state_create_info.scissorCount = 1;
12304 VkRect2D scissors = {};
12305 vp_state_create_info.pScissors = &scissors;
12306
12307 VkDynamicState scissor_state = VK_DYNAMIC_STATE_SCISSOR;
12308
12309 VkPipelineDynamicStateCreateInfo pipeline_dynamic_state_create_info = {};
12310 pipeline_dynamic_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
12311 pipeline_dynamic_state_create_info.dynamicStateCount = 1;
12312 pipeline_dynamic_state_create_info.pDynamicStates = &scissor_state;
12313
12314 VkPipelineShaderStageCreateInfo shader_stage_create_info[2] = {
12315 vs.GetStageCreateInfo(),
12316 fs.GetStageCreateInfo()
12317 };
12318
12319 VkPipelineVertexInputStateCreateInfo vertex_input_create_info = {};
12320 vertex_input_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
12321
12322 VkPipelineInputAssemblyStateCreateInfo input_assembly_create_info = {};
12323 input_assembly_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
12324 input_assembly_create_info.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
12325
12326 VkPipelineRasterizationStateCreateInfo rasterization_state_create_info = {};
12327 rasterization_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
12328 rasterization_state_create_info.pNext = nullptr;
12329 rasterization_state_create_info.lineWidth = 1.0f;
12330 rasterization_state_create_info.rasterizerDiscardEnable = true;
12331
12332 VkPipelineColorBlendAttachmentState color_blend_attachment_state = {};
12333 color_blend_attachment_state.blendEnable = VK_FALSE;
12334 color_blend_attachment_state.colorWriteMask = 0xf;
12335
12336 VkPipelineColorBlendStateCreateInfo color_blend_state_create_info = {};
12337 color_blend_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
12338 color_blend_state_create_info.attachmentCount = 1;
12339 color_blend_state_create_info.pAttachments = &color_blend_attachment_state;
12340
12341 VkGraphicsPipelineCreateInfo graphicspipe_create_info = {};
12342 graphicspipe_create_info.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
12343 graphicspipe_create_info.stageCount = 2;
12344 graphicspipe_create_info.pStages = shader_stage_create_info;
12345 graphicspipe_create_info.pVertexInputState = &vertex_input_create_info;
12346 graphicspipe_create_info.pInputAssemblyState = &input_assembly_create_info;
12347 graphicspipe_create_info.pViewportState = &vp_state_create_info;
12348 graphicspipe_create_info.pRasterizationState = &rasterization_state_create_info;
12349 graphicspipe_create_info.pColorBlendState = &color_blend_state_create_info;
12350 graphicspipe_create_info.pDynamicState = &pipeline_dynamic_state_create_info;
12351 graphicspipe_create_info.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
12352 graphicspipe_create_info.layout = pipeline_layout;
12353 graphicspipe_create_info.renderPass = renderPass();
12354
12355 VkPipelineCacheCreateInfo pipeline_cache_create_info = {};
12356 pipeline_cache_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
12357
12358 VkPipelineCache pipelineCache;
12359 ASSERT_VK_SUCCESS(vkCreatePipelineCache(m_device->device(), &pipeline_cache_create_info, nullptr, &pipelineCache));
12360
12361 // This structure maps constant ids to data locations.
12362 const VkSpecializationMapEntry entry =
12363 // id, offset, size
12364 {0, 4, sizeof(uint32_t)}; // Challenge core validation by using a bogus offset.
12365
12366 uint32_t data = 1;
12367
12368 // Set up the info describing spec map and data
12369 const VkSpecializationInfo specialization_info = {
12370 1,
12371 &entry,
12372 1 * sizeof(float),
12373 &data,
12374 };
12375 shader_stage_create_info[0].pSpecializationInfo = &specialization_info;
12376
12377 VkPipeline pipeline;
12378 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bad_specialization_message);
12379 vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &graphicspipe_create_info, nullptr, &pipeline);
12380 m_errorMonitor->VerifyFound();
12381
12382 vkDestroyPipelineCache(m_device->device(), pipelineCache, nullptr);
12383 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
12384}
12385
12386TEST_F(VkLayerTest, CreatePipelineCheckShaderDescriptorTypeMismatch) {
12387 TEST_DESCRIPTION("Challenge core_validation with shader validation issues related to vkCreateGraphicsPipelines.");
12388
12389 ASSERT_NO_FATAL_FAILURE(InitState());
12390 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12391
12392 const char *descriptor_type_mismatch_message = "Type mismatch on descriptor slot 0.0 (used as type ";
12393
12394 VkDescriptorPoolSize descriptor_pool_type_count[2] = {};
12395 descriptor_pool_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
12396 descriptor_pool_type_count[0].descriptorCount = 1;
12397 descriptor_pool_type_count[1].type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
12398 descriptor_pool_type_count[1].descriptorCount = 1;
12399
12400 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
12401 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12402 descriptor_pool_create_info.maxSets = 1;
12403 descriptor_pool_create_info.poolSizeCount = 2;
12404 descriptor_pool_create_info.pPoolSizes = descriptor_pool_type_count;
12405 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
12406
12407 VkDescriptorPool descriptorset_pool;
12408 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
12409
12410 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
12411 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
12412 descriptorset_layout_binding.descriptorCount = 1;
12413 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_ALL;
12414
12415 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
12416 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
12417 descriptorset_layout_create_info.bindingCount = 1;
12418 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
12419
12420 VkDescriptorSetLayout descriptorset_layout;
12421 ASSERT_VK_SUCCESS(vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
12422
12423 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
12424 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
12425 descriptorset_allocate_info.descriptorSetCount = 1;
12426 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
12427 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
12428 VkDescriptorSet descriptorset;
12429 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
12430
12431 // Challenge core_validation with a non uniform buffer type.
12432 VkBufferTest storage_buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT);
12433
Mark Mueller098c9cb2016-09-08 09:01:57 -060012434 char const *vsSource =
12435 "#version 450\n"
12436 "\n"
12437 "layout (std140, set = 0, binding = 0) uniform buf {\n"
12438 " mat4 mvp;\n"
12439 "} ubuf;\n"
12440 "out gl_PerVertex {\n"
12441 " vec4 gl_Position;\n"
12442 "};\n"
12443 "void main(){\n"
12444 " gl_Position = ubuf.mvp * vec4(1);\n"
12445 "}\n";
12446
12447 char const *fsSource =
12448 "#version 450\n"
12449 "\n"
12450 "layout(location = 0) out vec4 uFragColor;\n"
12451 "void main(){\n"
12452 " uFragColor = vec4(0,1,0,1);\n"
12453 "}\n";
12454
12455 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12456 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12457
12458 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
12459 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12460 pipeline_layout_create_info.setLayoutCount = 1;
12461 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
12462
12463 VkPipelineLayout pipeline_layout;
12464 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
12465
12466 VkPipelineObj pipe(m_device);
12467 pipe.AddColorAttachment();
12468 pipe.AddShader(&vs);
12469 pipe.AddShader(&fs);
12470
12471 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, descriptor_type_mismatch_message);
12472 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12473 m_errorMonitor->VerifyFound();
12474
12475 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
12476 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
12477 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
12478}
12479
12480TEST_F(VkLayerTest, CreatePipelineCheckShaderDescriptorNotAccessible) {
12481 TEST_DESCRIPTION(
12482 "Create a pipeline in which a descriptor used by a shader stage does not include that stage in its stageFlags.");
12483
12484 ASSERT_NO_FATAL_FAILURE(InitState());
12485 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12486
12487 const char *descriptor_not_accessible_message = "Shader uses descriptor slot 0.0 (used as type ";
12488
12489 VkDescriptorPoolSize descriptor_pool_type_count = {};
12490 descriptor_pool_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
12491 descriptor_pool_type_count.descriptorCount = 1;
12492
12493 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
12494 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12495 descriptor_pool_create_info.maxSets = 1;
12496 descriptor_pool_create_info.poolSizeCount = 1;
12497 descriptor_pool_create_info.pPoolSizes = &descriptor_pool_type_count;
12498 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
12499
12500 VkDescriptorPool descriptorset_pool;
12501 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
12502
12503 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
12504 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
12505 descriptorset_layout_binding.descriptorCount = 1;
12506 // Intentionally make the uniform buffer inaccessible to the vertex shader to challenge core_validation
12507 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
12508
12509 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
12510 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
12511 descriptorset_layout_create_info.bindingCount = 1;
12512 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
12513
12514 VkDescriptorSetLayout descriptorset_layout;
12515 ASSERT_VK_SUCCESS(vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info,
12516 nullptr, &descriptorset_layout));
12517
12518 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
12519 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
12520 descriptorset_allocate_info.descriptorSetCount = 1;
12521 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
12522 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
12523 VkDescriptorSet descriptorset;
12524 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
12525
12526 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
12527
Mark Mueller098c9cb2016-09-08 09:01:57 -060012528 char const *vsSource =
12529 "#version 450\n"
12530 "\n"
12531 "layout (std140, set = 0, binding = 0) uniform buf {\n"
12532 " mat4 mvp;\n"
12533 "} ubuf;\n"
12534 "out gl_PerVertex {\n"
12535 " vec4 gl_Position;\n"
12536 "};\n"
12537 "void main(){\n"
12538 " gl_Position = ubuf.mvp * vec4(1);\n"
12539 "}\n";
12540
12541 char const *fsSource =
12542 "#version 450\n"
12543 "\n"
12544 "layout(location = 0) out vec4 uFragColor;\n"
12545 "void main(){\n"
12546 " uFragColor = vec4(0,1,0,1);\n"
12547 "}\n";
12548
12549 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12550 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12551
12552 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
12553 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12554 pipeline_layout_create_info.setLayoutCount = 1;
12555 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
12556
12557 VkPipelineLayout pipeline_layout;
12558 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
12559
12560 VkPipelineObj pipe(m_device);
12561 pipe.AddColorAttachment();
12562 pipe.AddShader(&vs);
12563 pipe.AddShader(&fs);
12564
12565 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, descriptor_not_accessible_message);
12566 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12567 m_errorMonitor->VerifyFound();
12568
12569 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
12570 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
12571 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
12572}
12573
12574TEST_F(VkLayerTest, CreatePipelineCheckShaderPushConstantNotAccessible) {
12575 TEST_DESCRIPTION("Create a graphics pipleine in which a push constant range containing a push constant block member is not "
12576 "accessible from the current shader stage.");
12577
12578 ASSERT_NO_FATAL_FAILURE(InitState());
12579 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12580
12581 const char *push_constant_not_accessible_message =
12582 "Push constant range covering variable starting at offset 0 not accessible from stage VK_SHADER_STAGE_VERTEX_BIT";
12583
12584 char const *vsSource =
12585 "#version 450\n"
12586 "\n"
12587 "layout(push_constant, std430) uniform foo { float x; } consts;\n"
12588 "out gl_PerVertex {\n"
12589 " vec4 gl_Position;\n"
12590 "};\n"
12591 "void main(){\n"
12592 " gl_Position = vec4(consts.x);\n"
12593 "}\n";
12594
12595 char const *fsSource =
12596 "#version 450\n"
12597 "\n"
12598 "layout(location = 0) out vec4 uFragColor;\n"
12599 "void main(){\n"
12600 " uFragColor = vec4(0,1,0,1);\n"
12601 "}\n";
12602
12603 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12604 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12605
12606 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
12607 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12608
12609 // Set up a push constant range
12610 VkPushConstantRange push_constant_ranges = {};
12611 // Set to the wrong stage to challenge core_validation
12612 push_constant_ranges.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
12613 push_constant_ranges.size = 4;
12614
12615 pipeline_layout_create_info.pPushConstantRanges = &push_constant_ranges;
12616 pipeline_layout_create_info.pushConstantRangeCount = 1;
12617
12618 VkPipelineLayout pipeline_layout;
12619 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
12620
12621 VkPipelineObj pipe(m_device);
12622 pipe.AddColorAttachment();
12623 pipe.AddShader(&vs);
12624 pipe.AddShader(&fs);
12625
12626 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, push_constant_not_accessible_message);
12627 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12628 m_errorMonitor->VerifyFound();
12629
12630 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
12631}
12632
12633TEST_F(VkLayerTest, CreatePipelineCheckShaderNotEnabled) {
12634 TEST_DESCRIPTION(
12635 "Create a graphics pipeline in which a capability declared by the shader requires a feature not enabled on the device.");
12636
12637 ASSERT_NO_FATAL_FAILURE(InitState());
12638 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12639
12640 const char *feature_not_enabled_message =
12641 "Shader requires VkPhysicalDeviceFeatures::shaderFloat64 but is not enabled on the device";
12642
12643 // Some awkward steps are required to test with custom device features.
12644 std::vector<const char *> device_extension_names;
12645 auto features = m_device->phy().features();
12646 // Disable support for 64 bit floats
12647 features.shaderFloat64 = false;
12648 // The sacrificial device object
12649 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
12650
12651 char const *vsSource = "#version 450\n"
12652 "\n"
12653 "out gl_PerVertex {\n"
12654 " vec4 gl_Position;\n"
12655 "};\n"
12656 "void main(){\n"
12657 " gl_Position = vec4(1);\n"
12658 "}\n";
12659 char const *fsSource = "#version 450\n"
12660 "\n"
12661 "layout(location=0) out vec4 color;\n"
12662 "void main(){\n"
12663 " dvec4 green = vec4(0.0, 1.0, 0.0, 1.0);\n"
12664 " color = vec4(green);\n"
12665 "}\n";
12666
12667 VkShaderObj vs(&test_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12668 VkShaderObj fs(&test_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12669
12670 VkRenderpassObj render_pass(&test_device);
Mark Mueller098c9cb2016-09-08 09:01:57 -060012671
12672 VkPipelineObj pipe(&test_device);
12673 pipe.AddColorAttachment();
12674 pipe.AddShader(&vs);
12675 pipe.AddShader(&fs);
12676
12677 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
12678 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12679 VkPipelineLayout pipeline_layout;
12680 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(test_device.device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
12681
12682 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, feature_not_enabled_message);
12683 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
12684 m_errorMonitor->VerifyFound();
12685
12686 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, nullptr);
12687}
12688
12689TEST_F(VkLayerTest, CreatePipelineCheckShaderBadCapability) {
12690 TEST_DESCRIPTION("Create a graphics pipeline in which a capability declared by the shader is not supported by Vulkan shaders.");
12691
12692 ASSERT_NO_FATAL_FAILURE(InitState());
12693 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12694
12695 const char *bad_capability_message = "Shader declares capability 53, not supported in Vulkan.";
12696
12697 char const *vsSource = "#version 450\n"
12698 "\n"
12699 "out gl_PerVertex {\n"
12700 " vec4 gl_Position;\n"
12701 "};\n"
12702 "layout(xfb_buffer = 1) out;"
12703 "void main(){\n"
12704 " gl_Position = vec4(1);\n"
12705 "}\n";
12706 char const *fsSource = "#version 450\n"
12707 "\n"
12708 "layout(location=0) out vec4 color;\n"
12709 "void main(){\n"
12710 " dvec4 green = vec4(0.0, 1.0, 0.0, 1.0);\n"
12711 " color = vec4(green);\n"
12712 "}\n";
12713
12714 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12715 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12716
12717 VkPipelineObj pipe(m_device);
12718 pipe.AddColorAttachment();
12719 pipe.AddShader(&vs);
12720 pipe.AddShader(&fs);
12721
12722 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
12723 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12724 VkPipelineLayout pipeline_layout;
12725 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
12726
12727 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bad_capability_message);
12728 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12729 m_errorMonitor->VerifyFound();
12730
12731 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
12732}
12733
Karl Schultz6addd812016-02-02 17:17:23 -070012734TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvided) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012735 TEST_DESCRIPTION("Test that an error is produced for a fragment shader input "
12736 "which is not present in the outputs of the previous stage");
12737
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012738 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not written by vertex shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012739
Chris Forbes59cb88d2015-05-25 11:13:13 +120012740 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060012741 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes59cb88d2015-05-25 11:13:13 +120012742
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012743 char const *vsSource = "#version 450\n"
12744 "\n"
12745 "out gl_PerVertex {\n"
12746 " vec4 gl_Position;\n"
12747 "};\n"
12748 "void main(){\n"
12749 " gl_Position = vec4(1);\n"
12750 "}\n";
12751 char const *fsSource = "#version 450\n"
12752 "\n"
12753 "layout(location=0) in float x;\n"
12754 "layout(location=0) out vec4 color;\n"
12755 "void main(){\n"
12756 " color = vec4(x);\n"
12757 "}\n";
Chris Forbes59cb88d2015-05-25 11:13:13 +120012758
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012759 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12760 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes59cb88d2015-05-25 11:13:13 +120012761
12762 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080012763 pipe.AddColorAttachment();
Chris Forbes59cb88d2015-05-25 11:13:13 +120012764 pipe.AddShader(&vs);
12765 pipe.AddShader(&fs);
12766
Chris Forbes59cb88d2015-05-25 11:13:13 +120012767 VkDescriptorSetObj descriptorSet(m_device);
12768 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012769 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes59cb88d2015-05-25 11:13:13 +120012770
Tony Barbour5781e8f2015-08-04 16:23:11 -060012771 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes59cb88d2015-05-25 11:13:13 +120012772
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012773 m_errorMonitor->VerifyFound();
Chris Forbes59cb88d2015-05-25 11:13:13 +120012774}
12775
Karl Schultz6addd812016-02-02 17:17:23 -070012776TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvidedInBlock) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012777 TEST_DESCRIPTION("Test that an error is produced for a fragment shader input "
12778 "within an interace block, which is not present in the outputs "
12779 "of the previous stage.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012780 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not written by vertex shader");
Chris Forbesa3e85f62016-01-15 14:53:11 +130012781
12782 ASSERT_NO_FATAL_FAILURE(InitState());
12783 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12784
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012785 char const *vsSource = "#version 450\n"
12786 "\n"
12787 "out gl_PerVertex {\n"
12788 " vec4 gl_Position;\n"
12789 "};\n"
12790 "void main(){\n"
12791 " gl_Position = vec4(1);\n"
12792 "}\n";
12793 char const *fsSource = "#version 450\n"
12794 "\n"
12795 "in block { layout(location=0) float x; } ins;\n"
12796 "layout(location=0) out vec4 color;\n"
12797 "void main(){\n"
12798 " color = vec4(ins.x);\n"
12799 "}\n";
Chris Forbesa3e85f62016-01-15 14:53:11 +130012800
12801 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12802 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12803
12804 VkPipelineObj pipe(m_device);
12805 pipe.AddColorAttachment();
12806 pipe.AddShader(&vs);
12807 pipe.AddShader(&fs);
12808
12809 VkDescriptorSetObj descriptorSet(m_device);
12810 descriptorSet.AppendDummy();
12811 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12812
12813 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12814
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012815 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +130012816}
12817
Karl Schultz6addd812016-02-02 17:17:23 -070012818TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchArraySize) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012819 TEST_DESCRIPTION("Test that an error is produced for mismatched array sizes "
Mike Weiblencce7ec72016-10-17 19:33:05 -060012820 "across the vertex->fragment shader interface");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012821 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0.0: 'ptr to "
12822 "output arr[2] of float32' vs 'ptr to "
12823 "input arr[3] of float32'");
Chris Forbes0036fd12016-01-26 14:19:49 +130012824
12825 ASSERT_NO_FATAL_FAILURE(InitState());
12826 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12827
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012828 char const *vsSource = "#version 450\n"
12829 "\n"
12830 "layout(location=0) out float x[2];\n"
12831 "out gl_PerVertex {\n"
12832 " vec4 gl_Position;\n"
12833 "};\n"
12834 "void main(){\n"
12835 " x[0] = 0; x[1] = 0;\n"
12836 " gl_Position = vec4(1);\n"
12837 "}\n";
12838 char const *fsSource = "#version 450\n"
12839 "\n"
12840 "layout(location=0) in float x[3];\n"
12841 "layout(location=0) out vec4 color;\n"
12842 "void main(){\n"
12843 " color = vec4(x[0] + x[1] + x[2]);\n"
12844 "}\n";
Chris Forbes0036fd12016-01-26 14:19:49 +130012845
12846 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12847 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12848
12849 VkPipelineObj pipe(m_device);
12850 pipe.AddColorAttachment();
12851 pipe.AddShader(&vs);
12852 pipe.AddShader(&fs);
12853
12854 VkDescriptorSetObj descriptorSet(m_device);
12855 descriptorSet.AppendDummy();
12856 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12857
12858 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12859
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012860 m_errorMonitor->VerifyFound();
Chris Forbes0036fd12016-01-26 14:19:49 +130012861}
12862
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060012863
Karl Schultz6addd812016-02-02 17:17:23 -070012864TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012865 TEST_DESCRIPTION("Test that an error is produced for mismatched types across "
Mike Weiblencce7ec72016-10-17 19:33:05 -060012866 "the vertex->fragment shader interface");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012867 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012868
Chris Forbesb56af562015-05-25 11:13:17 +120012869 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060012870 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesb56af562015-05-25 11:13:17 +120012871
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012872 char const *vsSource = "#version 450\n"
12873 "\n"
12874 "layout(location=0) out int x;\n"
12875 "out gl_PerVertex {\n"
12876 " vec4 gl_Position;\n"
12877 "};\n"
12878 "void main(){\n"
12879 " x = 0;\n"
12880 " gl_Position = vec4(1);\n"
12881 "}\n";
12882 char const *fsSource = "#version 450\n"
12883 "\n"
12884 "layout(location=0) in float x;\n" /* VS writes int */
12885 "layout(location=0) out vec4 color;\n"
12886 "void main(){\n"
12887 " color = vec4(x);\n"
12888 "}\n";
Chris Forbesb56af562015-05-25 11:13:17 +120012889
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012890 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12891 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesb56af562015-05-25 11:13:17 +120012892
12893 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080012894 pipe.AddColorAttachment();
Chris Forbesb56af562015-05-25 11:13:17 +120012895 pipe.AddShader(&vs);
12896 pipe.AddShader(&fs);
12897
Chris Forbesb56af562015-05-25 11:13:17 +120012898 VkDescriptorSetObj descriptorSet(m_device);
12899 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012900 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesb56af562015-05-25 11:13:17 +120012901
Tony Barbour5781e8f2015-08-04 16:23:11 -060012902 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesb56af562015-05-25 11:13:17 +120012903
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012904 m_errorMonitor->VerifyFound();
Chris Forbesb56af562015-05-25 11:13:17 +120012905}
12906
Karl Schultz6addd812016-02-02 17:17:23 -070012907TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchInBlock) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012908 TEST_DESCRIPTION("Test that an error is produced for mismatched types across "
Mike Weiblencce7ec72016-10-17 19:33:05 -060012909 "the vertex->fragment shader interface, when the variable is contained within "
Chris Forbes1cc79542016-07-20 11:13:44 +120012910 "an interface block");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012911 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0");
Chris Forbesa3e85f62016-01-15 14:53:11 +130012912
12913 ASSERT_NO_FATAL_FAILURE(InitState());
12914 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12915
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012916 char const *vsSource = "#version 450\n"
12917 "\n"
12918 "out block { layout(location=0) int x; } outs;\n"
12919 "out gl_PerVertex {\n"
12920 " vec4 gl_Position;\n"
12921 "};\n"
12922 "void main(){\n"
12923 " outs.x = 0;\n"
12924 " gl_Position = vec4(1);\n"
12925 "}\n";
12926 char const *fsSource = "#version 450\n"
12927 "\n"
12928 "in block { layout(location=0) float x; } ins;\n" /* VS writes int */
12929 "layout(location=0) out vec4 color;\n"
12930 "void main(){\n"
12931 " color = vec4(ins.x);\n"
12932 "}\n";
Chris Forbesa3e85f62016-01-15 14:53:11 +130012933
12934 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12935 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12936
12937 VkPipelineObj pipe(m_device);
12938 pipe.AddColorAttachment();
12939 pipe.AddShader(&vs);
12940 pipe.AddShader(&fs);
12941
12942 VkDescriptorSetObj descriptorSet(m_device);
12943 descriptorSet.AppendDummy();
12944 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12945
12946 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12947
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012948 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +130012949}
12950
12951TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByLocation) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012952 TEST_DESCRIPTION("Test that an error is produced for location mismatches across "
Mike Weiblencce7ec72016-10-17 19:33:05 -060012953 "the vertex->fragment shader interface; This should manifest as a not-written/not-consumed "
Chris Forbes1cc79542016-07-20 11:13:44 +120012954 "pair, but flushes out broken walking of the interfaces");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012955 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 +130012956
12957 ASSERT_NO_FATAL_FAILURE(InitState());
12958 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12959
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012960 char const *vsSource = "#version 450\n"
12961 "\n"
12962 "out block { layout(location=1) float x; } outs;\n"
12963 "out gl_PerVertex {\n"
12964 " vec4 gl_Position;\n"
12965 "};\n"
12966 "void main(){\n"
12967 " outs.x = 0;\n"
12968 " gl_Position = vec4(1);\n"
12969 "}\n";
12970 char const *fsSource = "#version 450\n"
12971 "\n"
12972 "in block { layout(location=0) float x; } ins;\n"
12973 "layout(location=0) out vec4 color;\n"
12974 "void main(){\n"
12975 " color = vec4(ins.x);\n"
12976 "}\n";
Chris Forbese9928822016-02-17 14:44:52 +130012977
12978 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12979 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12980
12981 VkPipelineObj pipe(m_device);
12982 pipe.AddColorAttachment();
12983 pipe.AddShader(&vs);
12984 pipe.AddShader(&fs);
12985
12986 VkDescriptorSetObj descriptorSet(m_device);
12987 descriptorSet.AppendDummy();
12988 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12989
12990 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12991
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012992 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +130012993}
12994
12995TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByComponent) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012996 TEST_DESCRIPTION("Test that an error is produced for component mismatches across the "
Mike Weiblencce7ec72016-10-17 19:33:05 -060012997 "vertex->fragment shader interface. It's not enough to have the same set of locations in "
Chris Forbes1cc79542016-07-20 11:13:44 +120012998 "use; matching is defined in terms of spirv variables.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012999 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 +130013000
13001 ASSERT_NO_FATAL_FAILURE(InitState());
13002 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13003
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013004 char const *vsSource = "#version 450\n"
13005 "\n"
13006 "out block { layout(location=0, component=0) float x; } outs;\n"
13007 "out gl_PerVertex {\n"
13008 " vec4 gl_Position;\n"
13009 "};\n"
13010 "void main(){\n"
13011 " outs.x = 0;\n"
13012 " gl_Position = vec4(1);\n"
13013 "}\n";
13014 char const *fsSource = "#version 450\n"
13015 "\n"
13016 "in block { layout(location=0, component=1) float x; } ins;\n"
13017 "layout(location=0) out vec4 color;\n"
13018 "void main(){\n"
13019 " color = vec4(ins.x);\n"
13020 "}\n";
Chris Forbese9928822016-02-17 14:44:52 +130013021
13022 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13023 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13024
13025 VkPipelineObj pipe(m_device);
13026 pipe.AddColorAttachment();
13027 pipe.AddShader(&vs);
13028 pipe.AddShader(&fs);
13029
13030 VkDescriptorSetObj descriptorSet(m_device);
13031 descriptorSet.AppendDummy();
13032 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13033
13034 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13035
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013036 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +130013037}
13038
Chris Forbes1f3b0152016-11-30 12:48:40 +130013039TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByPrecision) {
13040 TEST_DESCRIPTION("Test that the RelaxedPrecision decoration is validated to match");
13041
13042 ASSERT_NO_FATAL_FAILURE(InitState());
13043 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13044
13045 char const *vsSource = "#version 450\n"
13046 "layout(location=0) out mediump float x;\n"
13047 "void main() { gl_Position = vec4(0); x = 1.0; }\n";
13048 char const *fsSource = "#version 450\n"
13049 "layout(location=0) in highp float x;\n"
13050 "layout(location=0) out vec4 color;\n"
13051 "void main() { color = vec4(x); }\n";
13052
13053 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13054 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13055
13056 VkPipelineObj pipe(m_device);
13057 pipe.AddColorAttachment();
13058 pipe.AddShader(&vs);
13059 pipe.AddShader(&fs);
13060
13061 VkDescriptorSetObj descriptorSet(m_device);
13062 descriptorSet.AppendDummy();
13063 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13064
13065 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "differ in precision");
13066
13067 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13068
13069 m_errorMonitor->VerifyFound();
13070}
13071
Chris Forbes870a39e2016-11-30 12:55:56 +130013072TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByPrecisionBlock) {
13073 TEST_DESCRIPTION("Test that the RelaxedPrecision decoration is validated to match");
13074
13075 ASSERT_NO_FATAL_FAILURE(InitState());
13076 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13077
13078 char const *vsSource = "#version 450\n"
13079 "out block { layout(location=0) mediump float x; };\n"
13080 "void main() { gl_Position = vec4(0); x = 1.0; }\n";
13081 char const *fsSource = "#version 450\n"
13082 "in block { layout(location=0) highp float x; };\n"
13083 "layout(location=0) out vec4 color;\n"
13084 "void main() { color = vec4(x); }\n";
13085
13086 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13087 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13088
13089 VkPipelineObj pipe(m_device);
13090 pipe.AddColorAttachment();
13091 pipe.AddShader(&vs);
13092 pipe.AddShader(&fs);
13093
13094 VkDescriptorSetObj descriptorSet(m_device);
13095 descriptorSet.AppendDummy();
13096 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13097
13098 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "differ in precision");
13099
13100 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13101
13102 m_errorMonitor->VerifyFound();
13103}
13104
Karl Schultz6addd812016-02-02 17:17:23 -070013105TEST_F(VkLayerTest, CreatePipelineAttribNotConsumed) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013106 TEST_DESCRIPTION("Test that a warning is produced for a vertex attribute which is "
13107 "not consumed by the vertex shader");
Mike Weiblencce7ec72016-10-17 19:33:05 -060013108 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "location 0 not consumed by vertex shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013109
Chris Forbesde136e02015-05-25 11:13:28 +120013110 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013111 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesde136e02015-05-25 11:13:28 +120013112
13113 VkVertexInputBindingDescription input_binding;
13114 memset(&input_binding, 0, sizeof(input_binding));
13115
13116 VkVertexInputAttributeDescription input_attrib;
13117 memset(&input_attrib, 0, sizeof(input_attrib));
13118 input_attrib.format = VK_FORMAT_R32_SFLOAT;
13119
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013120 char const *vsSource = "#version 450\n"
13121 "\n"
13122 "out gl_PerVertex {\n"
13123 " vec4 gl_Position;\n"
13124 "};\n"
13125 "void main(){\n"
13126 " gl_Position = vec4(1);\n"
13127 "}\n";
13128 char const *fsSource = "#version 450\n"
13129 "\n"
13130 "layout(location=0) out vec4 color;\n"
13131 "void main(){\n"
13132 " color = vec4(1);\n"
13133 "}\n";
Chris Forbesde136e02015-05-25 11:13:28 +120013134
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013135 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13136 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesde136e02015-05-25 11:13:28 +120013137
13138 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013139 pipe.AddColorAttachment();
Chris Forbesde136e02015-05-25 11:13:28 +120013140 pipe.AddShader(&vs);
13141 pipe.AddShader(&fs);
13142
13143 pipe.AddVertexInputBindings(&input_binding, 1);
13144 pipe.AddVertexInputAttribs(&input_attrib, 1);
13145
Chris Forbesde136e02015-05-25 11:13:28 +120013146 VkDescriptorSetObj descriptorSet(m_device);
13147 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013148 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesde136e02015-05-25 11:13:28 +120013149
Tony Barbour5781e8f2015-08-04 16:23:11 -060013150 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesde136e02015-05-25 11:13:28 +120013151
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013152 m_errorMonitor->VerifyFound();
Chris Forbesde136e02015-05-25 11:13:28 +120013153}
13154
Karl Schultz6addd812016-02-02 17:17:23 -070013155TEST_F(VkLayerTest, CreatePipelineAttribLocationMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013156 TEST_DESCRIPTION("Test that a warning is produced for a location mismatch on "
13157 "vertex attributes. This flushes out bad behavior in the interface walker");
Mike Weiblencce7ec72016-10-17 19:33:05 -060013158 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "location 0 not consumed by vertex shader");
Chris Forbes7d83cd52016-01-15 11:32:03 +130013159
13160 ASSERT_NO_FATAL_FAILURE(InitState());
13161 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13162
13163 VkVertexInputBindingDescription input_binding;
13164 memset(&input_binding, 0, sizeof(input_binding));
13165
13166 VkVertexInputAttributeDescription input_attrib;
13167 memset(&input_attrib, 0, sizeof(input_attrib));
13168 input_attrib.format = VK_FORMAT_R32_SFLOAT;
13169
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013170 char const *vsSource = "#version 450\n"
13171 "\n"
13172 "layout(location=1) in float x;\n"
13173 "out gl_PerVertex {\n"
13174 " vec4 gl_Position;\n"
13175 "};\n"
13176 "void main(){\n"
13177 " gl_Position = vec4(x);\n"
13178 "}\n";
13179 char const *fsSource = "#version 450\n"
13180 "\n"
13181 "layout(location=0) out vec4 color;\n"
13182 "void main(){\n"
13183 " color = vec4(1);\n"
13184 "}\n";
Chris Forbes7d83cd52016-01-15 11:32:03 +130013185
13186 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13187 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13188
13189 VkPipelineObj pipe(m_device);
13190 pipe.AddColorAttachment();
13191 pipe.AddShader(&vs);
13192 pipe.AddShader(&fs);
13193
13194 pipe.AddVertexInputBindings(&input_binding, 1);
13195 pipe.AddVertexInputAttribs(&input_attrib, 1);
13196
13197 VkDescriptorSetObj descriptorSet(m_device);
13198 descriptorSet.AppendDummy();
13199 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13200
13201 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13202
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013203 m_errorMonitor->VerifyFound();
Chris Forbes7d83cd52016-01-15 11:32:03 +130013204}
13205
Karl Schultz6addd812016-02-02 17:17:23 -070013206TEST_F(VkLayerTest, CreatePipelineAttribNotProvided) {
Mike Weiblen15bd38e2016-10-03 19:19:41 -060013207 TEST_DESCRIPTION("Test that an error is produced for a vertex shader input which is not "
Chris Forbes1cc79542016-07-20 11:13:44 +120013208 "provided by a vertex attribute");
Mike Weiblen15bd38e2016-10-03 19:19:41 -060013209 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 -060013210
Chris Forbes62e8e502015-05-25 11:13:29 +120013211 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013212 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes62e8e502015-05-25 11:13:29 +120013213
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013214 char const *vsSource = "#version 450\n"
13215 "\n"
13216 "layout(location=0) in vec4 x;\n" /* not provided */
13217 "out gl_PerVertex {\n"
13218 " vec4 gl_Position;\n"
13219 "};\n"
13220 "void main(){\n"
13221 " gl_Position = x;\n"
13222 "}\n";
13223 char const *fsSource = "#version 450\n"
13224 "\n"
13225 "layout(location=0) out vec4 color;\n"
13226 "void main(){\n"
13227 " color = vec4(1);\n"
13228 "}\n";
Chris Forbes62e8e502015-05-25 11:13:29 +120013229
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013230 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13231 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes62e8e502015-05-25 11:13:29 +120013232
13233 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013234 pipe.AddColorAttachment();
Chris Forbes62e8e502015-05-25 11:13:29 +120013235 pipe.AddShader(&vs);
13236 pipe.AddShader(&fs);
13237
Chris Forbes62e8e502015-05-25 11:13:29 +120013238 VkDescriptorSetObj descriptorSet(m_device);
13239 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013240 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes62e8e502015-05-25 11:13:29 +120013241
Tony Barbour5781e8f2015-08-04 16:23:11 -060013242 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes62e8e502015-05-25 11:13:29 +120013243
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013244 m_errorMonitor->VerifyFound();
Chris Forbes62e8e502015-05-25 11:13:29 +120013245}
13246
Karl Schultz6addd812016-02-02 17:17:23 -070013247TEST_F(VkLayerTest, CreatePipelineAttribTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013248 TEST_DESCRIPTION("Test that an error is produced for a mismatch between the "
13249 "fundamental type (float/int/uint) of an attribute and the "
Mike Weiblen15bd38e2016-10-03 19:19:41 -060013250 "vertex shader input that consumes it");
13251 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 -060013252
Chris Forbesc97d98e2015-05-25 11:13:31 +120013253 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013254 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesc97d98e2015-05-25 11:13:31 +120013255
13256 VkVertexInputBindingDescription input_binding;
13257 memset(&input_binding, 0, sizeof(input_binding));
13258
13259 VkVertexInputAttributeDescription input_attrib;
13260 memset(&input_attrib, 0, sizeof(input_attrib));
13261 input_attrib.format = VK_FORMAT_R32_SFLOAT;
13262
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013263 char const *vsSource = "#version 450\n"
13264 "\n"
13265 "layout(location=0) in int x;\n" /* attrib provided float */
13266 "out gl_PerVertex {\n"
13267 " vec4 gl_Position;\n"
13268 "};\n"
13269 "void main(){\n"
13270 " gl_Position = vec4(x);\n"
13271 "}\n";
13272 char const *fsSource = "#version 450\n"
13273 "\n"
13274 "layout(location=0) out vec4 color;\n"
13275 "void main(){\n"
13276 " color = vec4(1);\n"
13277 "}\n";
Chris Forbesc97d98e2015-05-25 11:13:31 +120013278
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013279 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13280 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesc97d98e2015-05-25 11:13:31 +120013281
13282 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013283 pipe.AddColorAttachment();
Chris Forbesc97d98e2015-05-25 11:13:31 +120013284 pipe.AddShader(&vs);
13285 pipe.AddShader(&fs);
13286
13287 pipe.AddVertexInputBindings(&input_binding, 1);
13288 pipe.AddVertexInputAttribs(&input_attrib, 1);
13289
Chris Forbesc97d98e2015-05-25 11:13:31 +120013290 VkDescriptorSetObj descriptorSet(m_device);
13291 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013292 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesc97d98e2015-05-25 11:13:31 +120013293
Tony Barbour5781e8f2015-08-04 16:23:11 -060013294 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesc97d98e2015-05-25 11:13:31 +120013295
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013296 m_errorMonitor->VerifyFound();
Chris Forbesc97d98e2015-05-25 11:13:31 +120013297}
13298
Chris Forbesc68b43c2016-04-06 11:18:47 +120013299TEST_F(VkLayerTest, CreatePipelineDuplicateStage) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013300 TEST_DESCRIPTION("Test that an error is produced for a pipeline containing multiple "
13301 "shaders for the same stage");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013302 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13303 "Multiple shaders provided for stage VK_SHADER_STAGE_VERTEX_BIT");
Chris Forbesc68b43c2016-04-06 11:18:47 +120013304
13305 ASSERT_NO_FATAL_FAILURE(InitState());
13306 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13307
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013308 char const *vsSource = "#version 450\n"
13309 "\n"
13310 "out gl_PerVertex {\n"
13311 " vec4 gl_Position;\n"
13312 "};\n"
13313 "void main(){\n"
13314 " gl_Position = vec4(1);\n"
13315 "}\n";
13316 char const *fsSource = "#version 450\n"
13317 "\n"
13318 "layout(location=0) out vec4 color;\n"
13319 "void main(){\n"
13320 " color = vec4(1);\n"
13321 "}\n";
Chris Forbesc68b43c2016-04-06 11:18:47 +120013322
13323 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13324 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13325
13326 VkPipelineObj pipe(m_device);
13327 pipe.AddColorAttachment();
13328 pipe.AddShader(&vs);
Mike Weiblencce7ec72016-10-17 19:33:05 -060013329 pipe.AddShader(&vs); // intentionally duplicate vertex shader attachment
Chris Forbesc68b43c2016-04-06 11:18:47 +120013330 pipe.AddShader(&fs);
13331
13332 VkDescriptorSetObj descriptorSet(m_device);
13333 descriptorSet.AppendDummy();
13334 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13335
13336 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13337
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013338 m_errorMonitor->VerifyFound();
Chris Forbesc68b43c2016-04-06 11:18:47 +120013339}
13340
Chris Forbes82ff92a2016-09-09 10:50:24 +120013341TEST_F(VkLayerTest, CreatePipelineMissingEntrypoint) {
13342 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13343 "No entrypoint found named `foo`");
13344
13345 ASSERT_NO_FATAL_FAILURE(InitState());
13346 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13347
13348 char const *vsSource = "#version 450\n"
13349 "out gl_PerVertex {\n"
13350 " vec4 gl_Position;\n"
13351 "};\n"
13352 "void main(){\n"
13353 " gl_Position = vec4(0);\n"
13354 "}\n";
13355 char const *fsSource = "#version 450\n"
13356 "\n"
13357 "layout(location=0) out vec4 color;\n"
13358 "void main(){\n"
13359 " color = vec4(1);\n"
13360 "}\n";
13361
13362 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13363 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this, "foo");
13364
13365 VkPipelineObj pipe(m_device);
13366 pipe.AddColorAttachment();
13367 pipe.AddShader(&vs);
13368 pipe.AddShader(&fs);
13369
13370 VkDescriptorSetObj descriptorSet(m_device);
13371 descriptorSet.AppendDummy();
13372 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13373
13374 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13375
13376 m_errorMonitor->VerifyFound();
13377}
13378
Chris Forbesae9d8cd2016-09-13 16:32:57 +120013379TEST_F(VkLayerTest, CreatePipelineDepthStencilRequired) {
13380 m_errorMonitor->SetDesiredFailureMsg(
13381 VK_DEBUG_REPORT_ERROR_BIT_EXT,
13382 "pDepthStencilState is NULL when rasterization is enabled and subpass "
13383 "uses a depth/stencil attachment");
13384
13385 ASSERT_NO_FATAL_FAILURE(InitState());
13386 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13387
13388 char const *vsSource = "#version 450\n"
13389 "void main(){ gl_Position = vec4(0); }\n";
13390 char const *fsSource = "#version 450\n"
13391 "\n"
13392 "layout(location=0) out vec4 color;\n"
13393 "void main(){\n"
13394 " color = vec4(1);\n"
13395 "}\n";
13396
13397 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13398 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13399
13400 VkPipelineObj pipe(m_device);
13401 pipe.AddColorAttachment();
13402 pipe.AddShader(&vs);
13403 pipe.AddShader(&fs);
13404
13405 VkDescriptorSetObj descriptorSet(m_device);
13406 descriptorSet.AppendDummy();
13407 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13408
13409 VkAttachmentDescription attachments[] = {
13410 { 0, VK_FORMAT_B8G8R8A8_UNORM, VK_SAMPLE_COUNT_1_BIT,
13411 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
13412 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
13413 VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
13414 },
13415 { 0, VK_FORMAT_D16_UNORM, VK_SAMPLE_COUNT_1_BIT,
13416 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
13417 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
13418 VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
13419 },
13420 };
13421 VkAttachmentReference refs[] = {
13422 { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL },
13423 { 1, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL },
13424 };
13425 VkSubpassDescription subpass = {
13426 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr,
13427 1, &refs[0], nullptr, &refs[1],
13428 0, nullptr
13429 };
13430 VkRenderPassCreateInfo rpci = {
13431 VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr,
13432 0, 2, attachments, 1, &subpass, 0, nullptr
13433 };
13434 VkRenderPass rp;
13435 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
13436 ASSERT_VK_SUCCESS(err);
13437
13438 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), rp);
13439
13440 m_errorMonitor->VerifyFound();
13441
13442 vkDestroyRenderPass(m_device->device(), rp, nullptr);
13443}
13444
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013445TEST_F(VkLayerTest, CreatePipelineTessPatchDecorationMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013446 TEST_DESCRIPTION("Test that an error is produced for a variable output from "
13447 "the TCS without the patch decoration, but consumed in the TES "
13448 "with the decoration.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013449 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is per-vertex in tessellation control shader stage "
13450 "but per-patch in tessellation evaluation shader stage");
Chris Forbesa0193bc2016-04-04 19:19:47 +120013451
13452 ASSERT_NO_FATAL_FAILURE(InitState());
13453 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13454
Chris Forbesc1e852d2016-04-04 19:26:42 +120013455 if (!m_device->phy().features().tessellationShader) {
13456 printf("Device does not support tessellation shaders; skipped.\n");
13457 return;
13458 }
13459
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013460 char const *vsSource = "#version 450\n"
13461 "void main(){}\n";
13462 char const *tcsSource = "#version 450\n"
13463 "layout(location=0) out int x[];\n"
13464 "layout(vertices=3) out;\n"
13465 "void main(){\n"
13466 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
13467 " gl_TessLevelInner[0] = 1;\n"
13468 " x[gl_InvocationID] = gl_InvocationID;\n"
13469 "}\n";
13470 char const *tesSource = "#version 450\n"
13471 "layout(triangles, equal_spacing, cw) in;\n"
13472 "layout(location=0) patch in int x;\n"
13473 "out gl_PerVertex { vec4 gl_Position; };\n"
13474 "void main(){\n"
13475 " gl_Position.xyz = gl_TessCoord;\n"
13476 " gl_Position.w = x;\n"
13477 "}\n";
13478 char const *fsSource = "#version 450\n"
13479 "layout(location=0) out vec4 color;\n"
13480 "void main(){\n"
13481 " color = vec4(1);\n"
13482 "}\n";
Chris Forbesa0193bc2016-04-04 19:19:47 +120013483
13484 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13485 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
13486 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
13487 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13488
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013489 VkPipelineInputAssemblyStateCreateInfo iasci{VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, nullptr, 0,
13490 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, VK_FALSE};
Chris Forbesa0193bc2016-04-04 19:19:47 +120013491
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013492 VkPipelineTessellationStateCreateInfo tsci{VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, nullptr, 0, 3};
Chris Forbesa0193bc2016-04-04 19:19:47 +120013493
13494 VkPipelineObj pipe(m_device);
13495 pipe.SetInputAssembly(&iasci);
13496 pipe.SetTessellation(&tsci);
13497 pipe.AddColorAttachment();
13498 pipe.AddShader(&vs);
13499 pipe.AddShader(&tcs);
13500 pipe.AddShader(&tes);
13501 pipe.AddShader(&fs);
13502
13503 VkDescriptorSetObj descriptorSet(m_device);
13504 descriptorSet.AppendDummy();
13505 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13506
13507 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13508
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013509 m_errorMonitor->VerifyFound();
Chris Forbesa0193bc2016-04-04 19:19:47 +120013510}
13511
Karl Schultz6addd812016-02-02 17:17:23 -070013512TEST_F(VkLayerTest, CreatePipelineAttribBindingConflict) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013513 TEST_DESCRIPTION("Test that an error is produced for a vertex attribute setup where multiple "
13514 "bindings provide the same location");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013515 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13516 "Duplicate vertex input binding descriptions for binding 0");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013517
Chris Forbes280ba2c2015-06-12 11:16:41 +120013518 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013519 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes280ba2c2015-06-12 11:16:41 +120013520
13521 /* Two binding descriptions for binding 0 */
13522 VkVertexInputBindingDescription input_bindings[2];
13523 memset(input_bindings, 0, sizeof(input_bindings));
13524
13525 VkVertexInputAttributeDescription input_attrib;
13526 memset(&input_attrib, 0, sizeof(input_attrib));
13527 input_attrib.format = VK_FORMAT_R32_SFLOAT;
13528
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013529 char const *vsSource = "#version 450\n"
13530 "\n"
13531 "layout(location=0) in float x;\n" /* attrib provided float */
13532 "out gl_PerVertex {\n"
13533 " vec4 gl_Position;\n"
13534 "};\n"
13535 "void main(){\n"
13536 " gl_Position = vec4(x);\n"
13537 "}\n";
13538 char const *fsSource = "#version 450\n"
13539 "\n"
13540 "layout(location=0) out vec4 color;\n"
13541 "void main(){\n"
13542 " color = vec4(1);\n"
13543 "}\n";
Chris Forbes280ba2c2015-06-12 11:16:41 +120013544
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013545 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13546 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes280ba2c2015-06-12 11:16:41 +120013547
13548 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013549 pipe.AddColorAttachment();
Chris Forbes280ba2c2015-06-12 11:16:41 +120013550 pipe.AddShader(&vs);
13551 pipe.AddShader(&fs);
13552
13553 pipe.AddVertexInputBindings(input_bindings, 2);
13554 pipe.AddVertexInputAttribs(&input_attrib, 1);
13555
Chris Forbes280ba2c2015-06-12 11:16:41 +120013556 VkDescriptorSetObj descriptorSet(m_device);
13557 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013558 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes280ba2c2015-06-12 11:16:41 +120013559
Tony Barbour5781e8f2015-08-04 16:23:11 -060013560 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes280ba2c2015-06-12 11:16:41 +120013561
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013562 m_errorMonitor->VerifyFound();
Chris Forbes280ba2c2015-06-12 11:16:41 +120013563}
Chris Forbes8f68b562015-05-25 11:13:32 +120013564
Karl Schultz6addd812016-02-02 17:17:23 -070013565TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotWritten) {
Mike Weiblencce7ec72016-10-17 19:33:05 -060013566 TEST_DESCRIPTION("Test that an error is produced for a fragment shader which does not "
Chris Forbes1cc79542016-07-20 11:13:44 +120013567 "provide an output for one of the pipeline's color attachments");
Mike Weiblencce7ec72016-10-17 19:33:05 -060013568 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attachment 0 not written by fragment shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013569
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013570 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013571
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013572 char const *vsSource = "#version 450\n"
13573 "\n"
13574 "out gl_PerVertex {\n"
13575 " vec4 gl_Position;\n"
13576 "};\n"
13577 "void main(){\n"
13578 " gl_Position = vec4(1);\n"
13579 "}\n";
13580 char const *fsSource = "#version 450\n"
13581 "\n"
13582 "void main(){\n"
13583 "}\n";
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013584
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013585 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13586 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013587
13588 VkPipelineObj pipe(m_device);
13589 pipe.AddShader(&vs);
13590 pipe.AddShader(&fs);
13591
Chia-I Wu08accc62015-07-07 11:50:03 +080013592 /* set up CB 0, not written */
13593 pipe.AddColorAttachment();
13594 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013595
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013596 VkDescriptorSetObj descriptorSet(m_device);
13597 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013598 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013599
Tony Barbour5781e8f2015-08-04 16:23:11 -060013600 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013601
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013602 m_errorMonitor->VerifyFound();
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013603}
13604
Karl Schultz6addd812016-02-02 17:17:23 -070013605TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotConsumed) {
Mike Weiblencce7ec72016-10-17 19:33:05 -060013606 TEST_DESCRIPTION("Test that a warning is produced for a fragment shader which provides a spurious "
Chris Forbes1cc79542016-07-20 11:13:44 +120013607 "output with no matching attachment");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013608 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
Mike Weiblencce7ec72016-10-17 19:33:05 -060013609 "fragment shader writes to output location 1 with no matching attachment");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013610
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013611 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013612
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013613 char const *vsSource = "#version 450\n"
13614 "\n"
13615 "out gl_PerVertex {\n"
13616 " vec4 gl_Position;\n"
13617 "};\n"
13618 "void main(){\n"
13619 " gl_Position = vec4(1);\n"
13620 "}\n";
13621 char const *fsSource = "#version 450\n"
13622 "\n"
13623 "layout(location=0) out vec4 x;\n"
13624 "layout(location=1) out vec4 y;\n" /* no matching attachment for this */
13625 "void main(){\n"
13626 " x = vec4(1);\n"
13627 " y = vec4(1);\n"
13628 "}\n";
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013629
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013630 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13631 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013632
13633 VkPipelineObj pipe(m_device);
13634 pipe.AddShader(&vs);
13635 pipe.AddShader(&fs);
13636
Chia-I Wu08accc62015-07-07 11:50:03 +080013637 /* set up CB 0, not written */
13638 pipe.AddColorAttachment();
13639 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013640 /* FS writes CB 1, but we don't configure it */
13641
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013642 VkDescriptorSetObj descriptorSet(m_device);
13643 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013644 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013645
Tony Barbour5781e8f2015-08-04 16:23:11 -060013646 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013647
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013648 m_errorMonitor->VerifyFound();
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013649}
13650
Karl Schultz6addd812016-02-02 17:17:23 -070013651TEST_F(VkLayerTest, CreatePipelineFragmentOutputTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013652 TEST_DESCRIPTION("Test that an error is produced for a mismatch between the fundamental "
Mike Weiblencce7ec72016-10-17 19:33:05 -060013653 "type of an fragment shader output variable, and the format of the corresponding attachment");
13654 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "does not match fragment shader output type");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013655
Chris Forbesa36d69e2015-05-25 11:13:44 +120013656 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesa36d69e2015-05-25 11:13:44 +120013657
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013658 char const *vsSource = "#version 450\n"
13659 "\n"
13660 "out gl_PerVertex {\n"
13661 " vec4 gl_Position;\n"
13662 "};\n"
13663 "void main(){\n"
13664 " gl_Position = vec4(1);\n"
13665 "}\n";
13666 char const *fsSource = "#version 450\n"
13667 "\n"
13668 "layout(location=0) out ivec4 x;\n" /* not UNORM */
13669 "void main(){\n"
13670 " x = ivec4(1);\n"
13671 "}\n";
Chris Forbesa36d69e2015-05-25 11:13:44 +120013672
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013673 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13674 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesa36d69e2015-05-25 11:13:44 +120013675
13676 VkPipelineObj pipe(m_device);
13677 pipe.AddShader(&vs);
13678 pipe.AddShader(&fs);
13679
Chia-I Wu08accc62015-07-07 11:50:03 +080013680 /* set up CB 0; type is UNORM by default */
13681 pipe.AddColorAttachment();
13682 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesa36d69e2015-05-25 11:13:44 +120013683
Chris Forbesa36d69e2015-05-25 11:13:44 +120013684 VkDescriptorSetObj descriptorSet(m_device);
13685 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013686 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesa36d69e2015-05-25 11:13:44 +120013687
Tony Barbour5781e8f2015-08-04 16:23:11 -060013688 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesa36d69e2015-05-25 11:13:44 +120013689
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013690 m_errorMonitor->VerifyFound();
Chris Forbesa36d69e2015-05-25 11:13:44 +120013691}
Chris Forbes7b1b8932015-06-05 14:43:36 +120013692
Karl Schultz6addd812016-02-02 17:17:23 -070013693TEST_F(VkLayerTest, CreatePipelineUniformBlockNotProvided) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013694 TEST_DESCRIPTION("Test that an error is produced for a shader consuming a uniform "
13695 "block which has no corresponding binding in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013696 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not declared in pipeline layout");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013697
Chris Forbes556c76c2015-08-14 12:04:59 +120013698 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes556c76c2015-08-14 12:04:59 +120013699
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013700 char const *vsSource = "#version 450\n"
13701 "\n"
13702 "out gl_PerVertex {\n"
13703 " vec4 gl_Position;\n"
13704 "};\n"
13705 "void main(){\n"
13706 " gl_Position = vec4(1);\n"
13707 "}\n";
13708 char const *fsSource = "#version 450\n"
13709 "\n"
13710 "layout(location=0) out vec4 x;\n"
13711 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
13712 "void main(){\n"
13713 " x = vec4(bar.y);\n"
13714 "}\n";
Chris Forbes556c76c2015-08-14 12:04:59 +120013715
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013716 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13717 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes556c76c2015-08-14 12:04:59 +120013718
Chris Forbes556c76c2015-08-14 12:04:59 +120013719 VkPipelineObj pipe(m_device);
13720 pipe.AddShader(&vs);
13721 pipe.AddShader(&fs);
13722
13723 /* set up CB 0; type is UNORM by default */
13724 pipe.AddColorAttachment();
13725 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13726
13727 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013728 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes556c76c2015-08-14 12:04:59 +120013729
13730 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13731
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013732 m_errorMonitor->VerifyFound();
Chris Forbes556c76c2015-08-14 12:04:59 +120013733}
13734
Chris Forbes5c59e902016-02-26 16:56:09 +130013735TEST_F(VkLayerTest, CreatePipelinePushConstantsNotInLayout) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013736 TEST_DESCRIPTION("Test that an error is produced for a shader consuming push constants "
13737 "which are not provided in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013738 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not declared in layout");
Chris Forbes5c59e902016-02-26 16:56:09 +130013739
13740 ASSERT_NO_FATAL_FAILURE(InitState());
13741
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013742 char const *vsSource = "#version 450\n"
13743 "\n"
13744 "layout(push_constant, std430) uniform foo { float x; } consts;\n"
13745 "out gl_PerVertex {\n"
13746 " vec4 gl_Position;\n"
13747 "};\n"
13748 "void main(){\n"
13749 " gl_Position = vec4(consts.x);\n"
13750 "}\n";
13751 char const *fsSource = "#version 450\n"
13752 "\n"
13753 "layout(location=0) out vec4 x;\n"
13754 "void main(){\n"
13755 " x = vec4(1);\n"
13756 "}\n";
Chris Forbes5c59e902016-02-26 16:56:09 +130013757
13758 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13759 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13760
13761 VkPipelineObj pipe(m_device);
13762 pipe.AddShader(&vs);
13763 pipe.AddShader(&fs);
13764
13765 /* set up CB 0; type is UNORM by default */
13766 pipe.AddColorAttachment();
13767 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13768
13769 VkDescriptorSetObj descriptorSet(m_device);
13770 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13771
13772 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13773
13774 /* should have generated an error -- no push constant ranges provided! */
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013775 m_errorMonitor->VerifyFound();
Chris Forbes5c59e902016-02-26 16:56:09 +130013776}
13777
Chris Forbes3fb17902016-08-22 14:57:55 +120013778TEST_F(VkLayerTest, CreatePipelineInputAttachmentMissing) {
13779 TEST_DESCRIPTION("Test that an error is produced for a shader consuming an input attachment "
13780 "which is not included in the subpass description");
13781 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13782 "consumes input attachment index 0 but not provided in subpass");
13783
13784 ASSERT_NO_FATAL_FAILURE(InitState());
13785
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013786 char const *vsSource = "#version 450\n"
13787 "\n"
13788 "out gl_PerVertex {\n"
13789 " vec4 gl_Position;\n"
13790 "};\n"
13791 "void main(){\n"
13792 " gl_Position = vec4(1);\n"
13793 "}\n";
13794 char const *fsSource = "#version 450\n"
13795 "\n"
13796 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
13797 "layout(location=0) out vec4 color;\n"
13798 "void main() {\n"
13799 " color = subpassLoad(x);\n"
13800 "}\n";
Chris Forbes3fb17902016-08-22 14:57:55 +120013801
13802 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13803 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13804
13805 VkPipelineObj pipe(m_device);
13806 pipe.AddShader(&vs);
13807 pipe.AddShader(&fs);
13808 pipe.AddColorAttachment();
13809 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13810
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013811 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
13812 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes3fb17902016-08-22 14:57:55 +120013813 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013814 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes3fb17902016-08-22 14:57:55 +120013815 ASSERT_VK_SUCCESS(err);
13816
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013817 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes3fb17902016-08-22 14:57:55 +120013818 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013819 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes3fb17902016-08-22 14:57:55 +120013820 ASSERT_VK_SUCCESS(err);
13821
13822 // error here.
13823 pipe.CreateVKPipeline(pl, renderPass());
13824
13825 m_errorMonitor->VerifyFound();
13826
13827 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
13828 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
13829}
13830
Chris Forbes5a9a0472016-08-22 16:02:09 +120013831TEST_F(VkLayerTest, CreatePipelineInputAttachmentTypeMismatch) {
13832 TEST_DESCRIPTION("Test that an error is produced for a shader consuming an input attachment "
13833 "with a format having a different fundamental type");
13834 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13835 "input attachment 0 format of VK_FORMAT_R8G8B8A8_UINT does not match");
13836
13837 ASSERT_NO_FATAL_FAILURE(InitState());
13838
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013839 char const *vsSource = "#version 450\n"
13840 "\n"
13841 "out gl_PerVertex {\n"
13842 " vec4 gl_Position;\n"
13843 "};\n"
13844 "void main(){\n"
13845 " gl_Position = vec4(1);\n"
13846 "}\n";
13847 char const *fsSource = "#version 450\n"
13848 "\n"
13849 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
13850 "layout(location=0) out vec4 color;\n"
13851 "void main() {\n"
13852 " color = subpassLoad(x);\n"
13853 "}\n";
Chris Forbes5a9a0472016-08-22 16:02:09 +120013854
13855 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13856 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13857
13858 VkPipelineObj pipe(m_device);
13859 pipe.AddShader(&vs);
13860 pipe.AddShader(&fs);
13861 pipe.AddColorAttachment();
13862 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13863
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013864 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
13865 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes5a9a0472016-08-22 16:02:09 +120013866 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013867 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes5a9a0472016-08-22 16:02:09 +120013868 ASSERT_VK_SUCCESS(err);
13869
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013870 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120013871 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013872 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes5a9a0472016-08-22 16:02:09 +120013873 ASSERT_VK_SUCCESS(err);
13874
13875 VkAttachmentDescription descs[2] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013876 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
13877 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
13878 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
13879 {0, VK_FORMAT_R8G8B8A8_UINT, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
13880 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 +120013881 };
13882 VkAttachmentReference color = {
13883 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
13884 };
13885 VkAttachmentReference input = {
13886 1, VK_IMAGE_LAYOUT_GENERAL,
13887 };
13888
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013889 VkSubpassDescription sd = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 1, &input, 1, &color, nullptr, nullptr, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120013890
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013891 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, descs, 1, &sd, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120013892 VkRenderPass rp;
13893 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
13894 ASSERT_VK_SUCCESS(err);
13895
13896 // error here.
13897 pipe.CreateVKPipeline(pl, rp);
13898
13899 m_errorMonitor->VerifyFound();
13900
13901 vkDestroyRenderPass(m_device->device(), rp, nullptr);
13902 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
13903 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
13904}
13905
Chris Forbes541f7b02016-08-22 15:30:27 +120013906TEST_F(VkLayerTest, CreatePipelineInputAttachmentMissingArray) {
13907 TEST_DESCRIPTION("Test that an error is produced for a shader consuming an input attachment "
13908 "which is not included in the subpass description -- array case");
13909 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13910 "consumes input attachment index 1 but not provided in subpass");
13911
13912 ASSERT_NO_FATAL_FAILURE(InitState());
13913
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013914 char const *vsSource = "#version 450\n"
13915 "\n"
13916 "out gl_PerVertex {\n"
13917 " vec4 gl_Position;\n"
13918 "};\n"
13919 "void main(){\n"
13920 " gl_Position = vec4(1);\n"
13921 "}\n";
13922 char const *fsSource = "#version 450\n"
13923 "\n"
13924 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput xs[2];\n"
13925 "layout(location=0) out vec4 color;\n"
13926 "void main() {\n"
13927 " color = subpassLoad(xs[1]);\n"
13928 "}\n";
Chris Forbes541f7b02016-08-22 15:30:27 +120013929
13930 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13931 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13932
13933 VkPipelineObj pipe(m_device);
13934 pipe.AddShader(&vs);
13935 pipe.AddShader(&fs);
13936 pipe.AddColorAttachment();
13937 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13938
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013939 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 2, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
13940 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes541f7b02016-08-22 15:30:27 +120013941 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013942 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes541f7b02016-08-22 15:30:27 +120013943 ASSERT_VK_SUCCESS(err);
13944
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013945 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes541f7b02016-08-22 15:30:27 +120013946 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013947 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes541f7b02016-08-22 15:30:27 +120013948 ASSERT_VK_SUCCESS(err);
13949
13950 // error here.
13951 pipe.CreateVKPipeline(pl, renderPass());
13952
13953 m_errorMonitor->VerifyFound();
13954
13955 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
13956 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
13957}
13958
Chris Forbes10eb9ae2016-05-31 16:09:42 +120013959TEST_F(VkLayerTest, CreateComputePipelineMissingDescriptor) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013960 TEST_DESCRIPTION("Test that an error is produced for a compute pipeline consuming a "
13961 "descriptor which is not provided in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013962 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Shader uses descriptor slot 0.0");
Chris Forbes10eb9ae2016-05-31 16:09:42 +120013963
13964 ASSERT_NO_FATAL_FAILURE(InitState());
13965
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013966 char const *csSource = "#version 450\n"
13967 "\n"
13968 "layout(local_size_x=1) in;\n"
13969 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
13970 "void main(){\n"
13971 " x = vec4(1);\n"
13972 "}\n";
Chris Forbes10eb9ae2016-05-31 16:09:42 +120013973
13974 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
13975
13976 VkDescriptorSetObj descriptorSet(m_device);
13977 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13978
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013979 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
13980 nullptr,
13981 0,
13982 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
13983 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
13984 descriptorSet.GetPipelineLayout(),
13985 VK_NULL_HANDLE,
13986 -1};
Chris Forbes10eb9ae2016-05-31 16:09:42 +120013987
13988 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013989 VkResult err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes10eb9ae2016-05-31 16:09:42 +120013990
13991 m_errorMonitor->VerifyFound();
13992
13993 if (err == VK_SUCCESS) {
13994 vkDestroyPipeline(m_device->device(), pipe, nullptr);
13995 }
13996}
13997
Chris Forbes22a9b092016-07-19 14:34:05 +120013998TEST_F(VkLayerTest, CreateComputePipelineDescriptorTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013999 TEST_DESCRIPTION("Test that an error is produced for a pipeline consuming a "
14000 "descriptor-backed resource of a mismatched type");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014001 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14002 "but descriptor of type VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER");
Chris Forbes22a9b092016-07-19 14:34:05 +120014003
14004 ASSERT_NO_FATAL_FAILURE(InitState());
14005
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014006 VkDescriptorSetLayoutBinding binding = {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr};
14007 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &binding};
Chris Forbes22a9b092016-07-19 14:34:05 +120014008 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014009 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes22a9b092016-07-19 14:34:05 +120014010 ASSERT_VK_SUCCESS(err);
14011
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014012 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes22a9b092016-07-19 14:34:05 +120014013 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014014 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes22a9b092016-07-19 14:34:05 +120014015 ASSERT_VK_SUCCESS(err);
14016
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014017 char const *csSource = "#version 450\n"
14018 "\n"
14019 "layout(local_size_x=1) in;\n"
14020 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
14021 "void main() {\n"
14022 " x.x = 1.0f;\n"
14023 "}\n";
Chris Forbes22a9b092016-07-19 14:34:05 +120014024 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
14025
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014026 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
14027 nullptr,
14028 0,
14029 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
14030 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
14031 pl,
14032 VK_NULL_HANDLE,
14033 -1};
Chris Forbes22a9b092016-07-19 14:34:05 +120014034
14035 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014036 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes22a9b092016-07-19 14:34:05 +120014037
14038 m_errorMonitor->VerifyFound();
14039
14040 if (err == VK_SUCCESS) {
14041 vkDestroyPipeline(m_device->device(), pipe, nullptr);
14042 }
14043
14044 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
14045 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
14046}
14047
Chris Forbes50020592016-07-27 13:52:41 +120014048TEST_F(VkLayerTest, DrawTimeImageViewTypeMismatchWithPipeline) {
14049 TEST_DESCRIPTION("Test that an error is produced when an image view type "
14050 "does not match the dimensionality declared in the shader");
14051
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014052 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 +120014053
14054 ASSERT_NO_FATAL_FAILURE(InitState());
14055 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14056
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014057 char const *vsSource = "#version 450\n"
14058 "\n"
14059 "out gl_PerVertex { vec4 gl_Position; };\n"
14060 "void main() { gl_Position = vec4(0); }\n";
14061 char const *fsSource = "#version 450\n"
14062 "\n"
14063 "layout(set=0, binding=0) uniform sampler3D s;\n"
14064 "layout(location=0) out vec4 color;\n"
14065 "void main() {\n"
14066 " color = texture(s, vec3(0));\n"
14067 "}\n";
Chris Forbes50020592016-07-27 13:52:41 +120014068 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14069 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14070
14071 VkPipelineObj pipe(m_device);
14072 pipe.AddShader(&vs);
14073 pipe.AddShader(&fs);
14074 pipe.AddColorAttachment();
14075
14076 VkTextureObj texture(m_device, nullptr);
14077 VkSamplerObj sampler(m_device);
14078
14079 VkDescriptorSetObj descriptorSet(m_device);
14080 descriptorSet.AppendSamplerTexture(&sampler, &texture);
14081 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14082
14083 VkResult err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14084 ASSERT_VK_SUCCESS(err);
14085
14086 BeginCommandBuffer();
14087
14088 m_commandBuffer->BindPipeline(pipe);
14089 m_commandBuffer->BindDescriptorSet(descriptorSet);
14090
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014091 VkViewport viewport = {0, 0, 16, 16, 0, 1};
Chris Forbes50020592016-07-27 13:52:41 +120014092 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014093 VkRect2D scissor = {{0, 0}, {16, 16}};
Chris Forbes50020592016-07-27 13:52:41 +120014094 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
14095
14096 // error produced here.
14097 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
14098
14099 m_errorMonitor->VerifyFound();
14100
14101 EndCommandBuffer();
14102}
14103
Chris Forbes5533bfc2016-07-27 14:12:34 +120014104TEST_F(VkLayerTest, DrawTimeImageMultisampleMismatchWithPipeline) {
14105 TEST_DESCRIPTION("Test that an error is produced when a multisampled images "
14106 "are consumed via singlesample images types in the shader, or vice versa.");
14107
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014108 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "requires bound image to have multiple samples");
Chris Forbes5533bfc2016-07-27 14:12:34 +120014109
14110 ASSERT_NO_FATAL_FAILURE(InitState());
14111 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14112
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014113 char const *vsSource = "#version 450\n"
14114 "\n"
14115 "out gl_PerVertex { vec4 gl_Position; };\n"
14116 "void main() { gl_Position = vec4(0); }\n";
14117 char const *fsSource = "#version 450\n"
14118 "\n"
14119 "layout(set=0, binding=0) uniform sampler2DMS s;\n"
14120 "layout(location=0) out vec4 color;\n"
14121 "void main() {\n"
14122 " color = texelFetch(s, ivec2(0), 0);\n"
14123 "}\n";
Chris Forbes5533bfc2016-07-27 14:12:34 +120014124 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14125 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14126
14127 VkPipelineObj pipe(m_device);
14128 pipe.AddShader(&vs);
14129 pipe.AddShader(&fs);
14130 pipe.AddColorAttachment();
14131
14132 VkTextureObj texture(m_device, nullptr);
14133 VkSamplerObj sampler(m_device);
14134
14135 VkDescriptorSetObj descriptorSet(m_device);
14136 descriptorSet.AppendSamplerTexture(&sampler, &texture);
14137 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14138
14139 VkResult err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14140 ASSERT_VK_SUCCESS(err);
14141
14142 BeginCommandBuffer();
14143
14144 m_commandBuffer->BindPipeline(pipe);
14145 m_commandBuffer->BindDescriptorSet(descriptorSet);
14146
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014147 VkViewport viewport = {0, 0, 16, 16, 0, 1};
Chris Forbes5533bfc2016-07-27 14:12:34 +120014148 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014149 VkRect2D scissor = {{0, 0}, {16, 16}};
Chris Forbes5533bfc2016-07-27 14:12:34 +120014150 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
14151
14152 // error produced here.
14153 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
14154
14155 m_errorMonitor->VerifyFound();
14156
14157 EndCommandBuffer();
14158}
14159
Mark Lobodzinski209b5292015-09-17 09:44:05 -060014160#endif // SHADER_CHECKER_TESTS
14161
14162#if DEVICE_LIMITS_TESTS
Mark Youngc48c4c12016-04-11 14:26:49 -060014163TEST_F(VkLayerTest, CreateImageLimitsViolationMaxWidth) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014164 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "CreateImage extents exceed allowable limits for format");
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060014165
14166 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060014167
14168 // Create an image
14169 VkImage image;
14170
Karl Schultz6addd812016-02-02 17:17:23 -070014171 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
14172 const int32_t tex_width = 32;
14173 const int32_t tex_height = 32;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060014174
14175 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014176 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14177 image_create_info.pNext = NULL;
14178 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14179 image_create_info.format = tex_format;
14180 image_create_info.extent.width = tex_width;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060014181 image_create_info.extent.height = tex_height;
Karl Schultz6addd812016-02-02 17:17:23 -070014182 image_create_info.extent.depth = 1;
14183 image_create_info.mipLevels = 1;
14184 image_create_info.arrayLayers = 1;
14185 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14186 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
14187 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
14188 image_create_info.flags = 0;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060014189
14190 // Introduce error by sending down a bogus width extent
14191 image_create_info.extent.width = 65536;
Chia-I Wuf7458c52015-10-26 21:10:41 +080014192 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060014193
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014194 m_errorMonitor->VerifyFound();
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060014195}
14196
Mark Youngc48c4c12016-04-11 14:26:49 -060014197TEST_F(VkLayerTest, CreateImageLimitsViolationMinWidth) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014198 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14199 "CreateImage extents is 0 for at least one required dimension");
Mark Youngc48c4c12016-04-11 14:26:49 -060014200
14201 ASSERT_NO_FATAL_FAILURE(InitState());
14202
14203 // Create an image
14204 VkImage image;
14205
14206 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
14207 const int32_t tex_width = 32;
14208 const int32_t tex_height = 32;
14209
14210 VkImageCreateInfo image_create_info = {};
14211 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14212 image_create_info.pNext = NULL;
14213 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14214 image_create_info.format = tex_format;
14215 image_create_info.extent.width = tex_width;
14216 image_create_info.extent.height = tex_height;
14217 image_create_info.extent.depth = 1;
14218 image_create_info.mipLevels = 1;
14219 image_create_info.arrayLayers = 1;
14220 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14221 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
14222 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
14223 image_create_info.flags = 0;
14224
14225 // Introduce error by sending down a bogus width extent
14226 image_create_info.extent.width = 0;
14227 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
14228
14229 m_errorMonitor->VerifyFound();
14230}
Mark Lobodzinski209b5292015-09-17 09:44:05 -060014231#endif // DEVICE_LIMITS_TESTS
Chris Forbesa36d69e2015-05-25 11:13:44 +120014232
Tobin Ehliscde08892015-09-22 10:11:37 -060014233#if IMAGE_TESTS
Mark Lobodzinski66e5eab2016-11-15 13:30:38 -070014234
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060014235TEST_F(VkLayerTest, AttachmentDescriptionUndefinedFormat) {
14236 TEST_DESCRIPTION("Create a render pass with an attachment description "
14237 "format set to VK_FORMAT_UNDEFINED");
14238
14239 ASSERT_NO_FATAL_FAILURE(InitState());
14240 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14241
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014242 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "format is VK_FORMAT_UNDEFINED");
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060014243
14244 VkAttachmentReference color_attach = {};
14245 color_attach.layout = VK_IMAGE_LAYOUT_GENERAL;
14246 color_attach.attachment = 0;
14247 VkSubpassDescription subpass = {};
14248 subpass.colorAttachmentCount = 1;
14249 subpass.pColorAttachments = &color_attach;
14250
14251 VkRenderPassCreateInfo rpci = {};
14252 rpci.subpassCount = 1;
14253 rpci.pSubpasses = &subpass;
14254 rpci.attachmentCount = 1;
14255 VkAttachmentDescription attach_desc = {};
14256 attach_desc.format = VK_FORMAT_UNDEFINED;
14257 rpci.pAttachments = &attach_desc;
14258 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
14259 VkRenderPass rp;
14260 VkResult result = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
14261
14262 m_errorMonitor->VerifyFound();
14263
14264 if (result == VK_SUCCESS) {
14265 vkDestroyRenderPass(m_device->device(), rp, NULL);
14266 }
14267}
14268
Karl Schultz6addd812016-02-02 17:17:23 -070014269TEST_F(VkLayerTest, InvalidImageView) {
14270 VkResult err;
Tobin Ehliscde08892015-09-22 10:11:37 -060014271
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014272 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with baseMipLevel 10 ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014273
Tobin Ehliscde08892015-09-22 10:11:37 -060014274 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehliscde08892015-09-22 10:11:37 -060014275
Mike Stroyana3082432015-09-25 13:39:21 -060014276 // Create an image and try to create a view with bad baseMipLevel
Karl Schultz6addd812016-02-02 17:17:23 -070014277 VkImage image;
Tobin Ehliscde08892015-09-22 10:11:37 -060014278
Karl Schultz6addd812016-02-02 17:17:23 -070014279 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
14280 const int32_t tex_width = 32;
14281 const int32_t tex_height = 32;
Tobin Ehliscde08892015-09-22 10:11:37 -060014282
14283 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014284 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14285 image_create_info.pNext = NULL;
14286 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14287 image_create_info.format = tex_format;
14288 image_create_info.extent.width = tex_width;
14289 image_create_info.extent.height = tex_height;
14290 image_create_info.extent.depth = 1;
14291 image_create_info.mipLevels = 1;
14292 image_create_info.arrayLayers = 1;
14293 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14294 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
14295 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
14296 image_create_info.flags = 0;
Tobin Ehliscde08892015-09-22 10:11:37 -060014297
Chia-I Wuf7458c52015-10-26 21:10:41 +080014298 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehliscde08892015-09-22 10:11:37 -060014299 ASSERT_VK_SUCCESS(err);
14300
14301 VkImageViewCreateInfo image_view_create_info = {};
Chris Forbes53bef902016-11-28 17:53:04 +130014302 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070014303 image_view_create_info.image = image;
14304 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
14305 image_view_create_info.format = tex_format;
14306 image_view_create_info.subresourceRange.layerCount = 1;
14307 image_view_create_info.subresourceRange.baseMipLevel = 10; // cause an error
14308 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014309 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehliscde08892015-09-22 10:11:37 -060014310
14311 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014312 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehliscde08892015-09-22 10:11:37 -060014313
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014314 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -060014315 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehliscde08892015-09-22 10:11:37 -060014316}
Mike Stroyana3082432015-09-25 13:39:21 -060014317
Mark Youngd339ba32016-05-30 13:28:35 -060014318TEST_F(VkLayerTest, CreateImageViewNoMemoryBoundToImage) {
14319 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -060014320 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -060014321 " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Mark Youngd339ba32016-05-30 13:28:35 -060014322
14323 ASSERT_NO_FATAL_FAILURE(InitState());
14324
14325 // Create an image and try to create a view with no memory backing the image
14326 VkImage image;
14327
14328 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
14329 const int32_t tex_width = 32;
14330 const int32_t tex_height = 32;
14331
14332 VkImageCreateInfo image_create_info = {};
14333 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14334 image_create_info.pNext = NULL;
14335 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14336 image_create_info.format = tex_format;
14337 image_create_info.extent.width = tex_width;
14338 image_create_info.extent.height = tex_height;
14339 image_create_info.extent.depth = 1;
14340 image_create_info.mipLevels = 1;
14341 image_create_info.arrayLayers = 1;
14342 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14343 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
14344 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
14345 image_create_info.flags = 0;
14346
14347 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
14348 ASSERT_VK_SUCCESS(err);
14349
14350 VkImageViewCreateInfo image_view_create_info = {};
Chris Forbes53bef902016-11-28 17:53:04 +130014351 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Mark Youngd339ba32016-05-30 13:28:35 -060014352 image_view_create_info.image = image;
14353 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
14354 image_view_create_info.format = tex_format;
14355 image_view_create_info.subresourceRange.layerCount = 1;
14356 image_view_create_info.subresourceRange.baseMipLevel = 0;
14357 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014358 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Youngd339ba32016-05-30 13:28:35 -060014359
14360 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014361 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Youngd339ba32016-05-30 13:28:35 -060014362
14363 m_errorMonitor->VerifyFound();
14364 vkDestroyImage(m_device->device(), image, NULL);
14365 // If last error is success, it still created the view, so delete it.
14366 if (err == VK_SUCCESS) {
14367 vkDestroyImageView(m_device->device(), view, NULL);
14368 }
Mark Youngd339ba32016-05-30 13:28:35 -060014369}
14370
Karl Schultz6addd812016-02-02 17:17:23 -070014371TEST_F(VkLayerTest, InvalidImageViewAspect) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014372 TEST_DESCRIPTION("Create an image and try to create a view with an invalid aspectMask");
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060014373 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView(): Color image "
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014374 "formats must have ONLY the "
14375 "VK_IMAGE_ASPECT_COLOR_BIT set");
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060014376 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14377 "Color image formats must have the VK_IMAGE_ASPECT_COLOR_BIT set.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014378
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060014379 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060014380
Karl Schultz6addd812016-02-02 17:17:23 -070014381 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060014382 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014383 image.init(32, 32, tex_format, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_LINEAR, 0);
Tobin Ehlis1f567a22016-05-25 16:15:18 -060014384 ASSERT_TRUE(image.initialized());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060014385
14386 VkImageViewCreateInfo image_view_create_info = {};
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060014387 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060014388 image_view_create_info.image = image.handle();
Karl Schultz6addd812016-02-02 17:17:23 -070014389 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
14390 image_view_create_info.format = tex_format;
14391 image_view_create_info.subresourceRange.baseMipLevel = 0;
14392 image_view_create_info.subresourceRange.levelCount = 1;
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060014393 image_view_create_info.subresourceRange.layerCount = 1;
Karl Schultz6addd812016-02-02 17:17:23 -070014394 // Cause an error by setting an invalid image aspect
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014395 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060014396
14397 VkImageView view;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060014398 vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060014399
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014400 m_errorMonitor->VerifyFound();
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060014401}
14402
Mark Lobodzinskidb117632016-03-31 10:45:56 -060014403TEST_F(VkLayerTest, CopyImageLayerCountMismatch) {
Karl Schultz6addd812016-02-02 17:17:23 -070014404 VkResult err;
14405 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060014406
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014407 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14408 "vkCmdCopyImage: number of layers in source and destination subresources for pRegions");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014409
Mike Stroyana3082432015-09-25 13:39:21 -060014410 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060014411
14412 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070014413 VkImage srcImage;
14414 VkImage dstImage;
14415 VkDeviceMemory srcMem;
14416 VkDeviceMemory destMem;
14417 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060014418
14419 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014420 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14421 image_create_info.pNext = NULL;
14422 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14423 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
14424 image_create_info.extent.width = 32;
14425 image_create_info.extent.height = 32;
14426 image_create_info.extent.depth = 1;
14427 image_create_info.mipLevels = 1;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060014428 image_create_info.arrayLayers = 4;
Karl Schultz6addd812016-02-02 17:17:23 -070014429 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14430 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
14431 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
14432 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014433
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014434 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014435 ASSERT_VK_SUCCESS(err);
14436
Mark Lobodzinski867787a2016-10-14 11:49:55 -060014437 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014438 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014439 ASSERT_VK_SUCCESS(err);
14440
14441 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014442 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014443 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
14444 memAlloc.pNext = NULL;
14445 memAlloc.allocationSize = 0;
14446 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014447
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060014448 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014449 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014450 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014451 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014452 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014453 ASSERT_VK_SUCCESS(err);
14454
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014455 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014456 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014457 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060014458 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014459 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014460 ASSERT_VK_SUCCESS(err);
14461
14462 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
14463 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014464 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060014465 ASSERT_VK_SUCCESS(err);
14466
14467 BeginCommandBuffer();
14468 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014469 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014470 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060014471 copyRegion.srcSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060014472 copyRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060014473 copyRegion.srcOffset.x = 0;
14474 copyRegion.srcOffset.y = 0;
14475 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014476 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014477 copyRegion.dstSubresource.mipLevel = 0;
14478 copyRegion.dstSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060014479 // Introduce failure by forcing the dst layerCount to differ from src
14480 copyRegion.dstSubresource.layerCount = 3;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014481 copyRegion.dstOffset.x = 0;
14482 copyRegion.dstOffset.y = 0;
14483 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014484 copyRegion.extent.width = 1;
14485 copyRegion.extent.height = 1;
14486 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014487 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060014488 EndCommandBuffer();
14489
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014490 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060014491
Chia-I Wuf7458c52015-10-26 21:10:41 +080014492 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014493 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080014494 vkFreeMemory(m_device->device(), srcMem, NULL);
14495 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060014496}
14497
Tony Barbourd6673642016-05-05 14:46:39 -060014498TEST_F(VkLayerTest, ImageLayerUnsupportedFormat) {
14499
14500 TEST_DESCRIPTION("Creating images with unsuported formats ");
14501
14502 ASSERT_NO_FATAL_FAILURE(InitState());
14503 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14504 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014505 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 -060014506 VK_IMAGE_TILING_OPTIMAL, 0);
14507 ASSERT_TRUE(image.initialized());
14508
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014509 // Create image with unsupported format - Expect FORMAT_UNSUPPORTED
Chris Forbesf4d8e332016-11-28 17:51:10 +130014510 VkImageCreateInfo image_create_info = {};
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014511 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014512 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14513 image_create_info.format = VK_FORMAT_UNDEFINED;
14514 image_create_info.extent.width = 32;
14515 image_create_info.extent.height = 32;
14516 image_create_info.extent.depth = 1;
14517 image_create_info.mipLevels = 1;
14518 image_create_info.arrayLayers = 1;
14519 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14520 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
14521 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014522
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014523 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14524 "vkCreateImage: VkFormat for image must not be VK_FORMAT_UNDEFINED");
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014525
14526 VkImage localImage;
14527 vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage);
14528 m_errorMonitor->VerifyFound();
14529
Tony Barbourd6673642016-05-05 14:46:39 -060014530 VkFormat unsupported = VK_FORMAT_UNDEFINED;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014531 // Look for a format that is COMPLETELY unsupported with this hardware
Tony Barbourd6673642016-05-05 14:46:39 -060014532 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
14533 VkFormat format = static_cast<VkFormat>(f);
14534 VkFormatProperties fProps = m_device->format_properties(format);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014535 if (format != VK_FORMAT_UNDEFINED && fProps.linearTilingFeatures == 0 && fProps.optimalTilingFeatures == 0) {
Tony Barbourd6673642016-05-05 14:46:39 -060014536 unsupported = format;
14537 break;
14538 }
14539 }
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014540
Tony Barbourd6673642016-05-05 14:46:39 -060014541 if (unsupported != VK_FORMAT_UNDEFINED) {
Tony Barbourd6673642016-05-05 14:46:39 -060014542 image_create_info.format = unsupported;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014543 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is an unsupported format");
Tony Barbourd6673642016-05-05 14:46:39 -060014544
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014545 vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage);
Tony Barbourd6673642016-05-05 14:46:39 -060014546 m_errorMonitor->VerifyFound();
14547 }
14548}
14549
14550TEST_F(VkLayerTest, ImageLayerViewTests) {
14551 VkResult ret;
14552 TEST_DESCRIPTION("Passing bad parameters to CreateImageView");
14553
14554 ASSERT_NO_FATAL_FAILURE(InitState());
14555
14556 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014557 image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
Tony Barbourd6673642016-05-05 14:46:39 -060014558 VK_IMAGE_TILING_OPTIMAL, 0);
14559 ASSERT_TRUE(image.initialized());
14560
14561 VkImageView imgView;
14562 VkImageViewCreateInfo imgViewInfo = {};
14563 imgViewInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
14564 imgViewInfo.image = image.handle();
14565 imgViewInfo.viewType = VK_IMAGE_VIEW_TYPE_2D;
14566 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
14567 imgViewInfo.subresourceRange.layerCount = 1;
14568 imgViewInfo.subresourceRange.baseMipLevel = 0;
14569 imgViewInfo.subresourceRange.levelCount = 1;
14570 imgViewInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14571
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014572 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with baseMipLevel");
Tony Barbourd6673642016-05-05 14:46:39 -060014573 // View can't have baseMipLevel >= image's mipLevels - Expect
14574 // VIEW_CREATE_ERROR
14575 imgViewInfo.subresourceRange.baseMipLevel = 1;
14576 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14577 m_errorMonitor->VerifyFound();
14578 imgViewInfo.subresourceRange.baseMipLevel = 0;
14579
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014580 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with baseArrayLayer");
Tony Barbourd6673642016-05-05 14:46:39 -060014581 // View can't have baseArrayLayer >= image's arraySize - Expect
14582 // VIEW_CREATE_ERROR
14583 imgViewInfo.subresourceRange.baseArrayLayer = 1;
14584 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14585 m_errorMonitor->VerifyFound();
14586 imgViewInfo.subresourceRange.baseArrayLayer = 0;
14587
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014588 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with 0 in "
14589 "pCreateInfo->subresourceRange."
14590 "levelCount");
Tony Barbourd6673642016-05-05 14:46:39 -060014591 // View's levelCount can't be 0 - Expect VIEW_CREATE_ERROR
14592 imgViewInfo.subresourceRange.levelCount = 0;
14593 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14594 m_errorMonitor->VerifyFound();
14595 imgViewInfo.subresourceRange.levelCount = 1;
14596
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014597 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with 0 in "
14598 "pCreateInfo->subresourceRange."
14599 "layerCount");
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060014600 m_errorMonitor->SetDesiredFailureMsg(
14601 VK_DEBUG_REPORT_ERROR_BIT_EXT,
14602 "if pCreateInfo->viewType is VK_IMAGE_TYPE_2D, pCreateInfo->subresourceRange.layerCount must be 1");
Tony Barbourd6673642016-05-05 14:46:39 -060014603 // View's layerCount can't be 0 - Expect VIEW_CREATE_ERROR
14604 imgViewInfo.subresourceRange.layerCount = 0;
14605 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14606 m_errorMonitor->VerifyFound();
14607 imgViewInfo.subresourceRange.layerCount = 1;
14608
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014609 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "but both must be color formats");
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060014610 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Formats MUST be IDENTICAL unless "
14611 "VK_IMAGE_CREATE_MUTABLE_FORMAT BIT "
14612 "was set on image creation.");
Tony Barbourd6673642016-05-05 14:46:39 -060014613 // Can't use depth format for view into color image - Expect INVALID_FORMAT
14614 imgViewInfo.format = VK_FORMAT_D24_UNORM_S8_UINT;
14615 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14616 m_errorMonitor->VerifyFound();
14617 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
14618
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014619 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Formats MUST be IDENTICAL unless "
14620 "VK_IMAGE_CREATE_MUTABLE_FORMAT BIT "
14621 "was set on image creation.");
Tony Barbourd6673642016-05-05 14:46:39 -060014622 // Same compatibility class but no MUTABLE_FORMAT bit - Expect
14623 // VIEW_CREATE_ERROR
14624 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UINT;
14625 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14626 m_errorMonitor->VerifyFound();
14627 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
14628
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014629 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "can support ImageViews with "
14630 "differing formats but they must be "
14631 "in the same compatibility class.");
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060014632 // TODO: Update framework to easily passing mutable flag into ImageObj init
14633 // For now just allowing image for this one test to not have memory bound
14634 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14635 " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Tony Barbourd6673642016-05-05 14:46:39 -060014636 // Have MUTABLE_FORMAT bit but not in same compatibility class - Expect
14637 // VIEW_CREATE_ERROR
14638 VkImageCreateInfo mutImgInfo = image.create_info();
14639 VkImage mutImage;
14640 mutImgInfo.format = VK_FORMAT_R8_UINT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014641 assert(m_device->format_properties(VK_FORMAT_R8_UINT).optimalTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT);
Tony Barbourd6673642016-05-05 14:46:39 -060014642 mutImgInfo.flags = VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT;
14643 mutImgInfo.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
14644 ret = vkCreateImage(m_device->handle(), &mutImgInfo, NULL, &mutImage);
14645 ASSERT_VK_SUCCESS(ret);
14646 imgViewInfo.image = mutImage;
14647 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14648 m_errorMonitor->VerifyFound();
14649 imgViewInfo.image = image.handle();
14650 vkDestroyImage(m_device->handle(), mutImage, NULL);
14651}
14652
14653TEST_F(VkLayerTest, MiscImageLayerTests) {
14654
14655 TEST_DESCRIPTION("Image layer tests that don't belong elsewhare");
14656
14657 ASSERT_NO_FATAL_FAILURE(InitState());
14658
14659 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014660 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 -060014661 VK_IMAGE_TILING_OPTIMAL, 0);
14662 ASSERT_TRUE(image.initialized());
14663
Tony Barbourd6673642016-05-05 14:46:39 -060014664 vk_testing::Buffer buffer;
14665 VkMemoryPropertyFlags reqs = 0;
14666 buffer.init_as_src(*m_device, 128 * 128 * 4, reqs);
14667 VkBufferImageCopy region = {};
14668 region.bufferRowLength = 128;
14669 region.bufferImageHeight = 128;
14670 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14671 // layerCount can't be 0 - Expect MISMATCHED_IMAGE_ASPECT
Mark Lobodzinski3702e932016-11-22 11:40:48 -070014672 region.imageSubresource.layerCount = 1;
Tony Barbourd6673642016-05-05 14:46:39 -060014673 region.imageExtent.height = 4;
14674 region.imageExtent.width = 4;
14675 region.imageExtent.depth = 1;
14676 m_commandBuffer->BeginCommandBuffer();
Tony Barbourd6673642016-05-05 14:46:39 -060014677
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070014678 // Image must have offset.z of 0 and extent.depth of 1
14679 // Introduce failure by setting imageExtent.depth to 0
14680 region.imageExtent.depth = 0;
14681 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01269);
14682 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
14683 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
14684 m_errorMonitor->VerifyFound();
14685
14686 region.imageExtent.depth = 1;
14687
14688 // Image must have offset.z of 0 and extent.depth of 1
14689 // Introduce failure by setting imageOffset.z to 4
14690 region.imageOffset.z = 4;
14691 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01269);
14692 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
14693 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
14694 m_errorMonitor->VerifyFound();
14695
14696 region.imageOffset.z = 0;
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060014697 // BufferOffset must be a multiple of the calling command's VkImage parameter's texel size
14698 // Introduce failure by setting bufferOffset to 1 and 1/2 texels
14699 region.bufferOffset = 6;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070014700 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01263);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014701 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
14702 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060014703 m_errorMonitor->VerifyFound();
14704
14705 // BufferOffset must be a multiple of 4
14706 // Introduce failure by setting bufferOffset to a value not divisible by 4
14707 region.bufferOffset = 6;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070014708 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01264);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014709 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
14710 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060014711 m_errorMonitor->VerifyFound();
14712
14713 // BufferRowLength must be 0, or greater than or equal to the width member of imageExtent
14714 region.bufferOffset = 0;
14715 region.imageExtent.height = 128;
14716 region.imageExtent.width = 128;
14717 // Introduce failure by setting bufferRowLength > 0 but less than width
14718 region.bufferRowLength = 64;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070014719 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01265);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014720 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
14721 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060014722 m_errorMonitor->VerifyFound();
14723
14724 // BufferImageHeight must be 0, or greater than or equal to the height member of imageExtent
14725 region.bufferRowLength = 128;
14726 // Introduce failure by setting bufferRowHeight > 0 but less than height
14727 region.bufferImageHeight = 64;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070014728 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01266);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014729 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
14730 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060014731 m_errorMonitor->VerifyFound();
14732
14733 region.bufferImageHeight = 128;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014734 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14735 "If the format of srcImage is a depth, stencil, depth stencil or "
14736 "integer-based format then filter must be VK_FILTER_NEAREST");
Tony Barbourd6673642016-05-05 14:46:39 -060014737 // Expect INVALID_FILTER
14738 VkImageObj intImage1(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014739 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 -060014740 VkImageObj intImage2(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014741 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 -060014742 VkImageBlit blitRegion = {};
14743 blitRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14744 blitRegion.srcSubresource.baseArrayLayer = 0;
14745 blitRegion.srcSubresource.layerCount = 1;
14746 blitRegion.srcSubresource.mipLevel = 0;
14747 blitRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14748 blitRegion.dstSubresource.baseArrayLayer = 0;
14749 blitRegion.dstSubresource.layerCount = 1;
14750 blitRegion.dstSubresource.mipLevel = 0;
14751
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014752 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), intImage1.handle(), intImage1.layout(), intImage2.handle(),
14753 intImage2.layout(), 16, &blitRegion, VK_FILTER_LINEAR);
Tony Barbourd6673642016-05-05 14:46:39 -060014754 m_errorMonitor->VerifyFound();
14755
Mark Lobodzinskib02ea642016-08-17 13:03:57 -060014756 // Look for NULL-blit warning
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014757 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "Offsets specify a zero-volume area.");
14758 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), intImage1.handle(), intImage1.layout(), intImage2.handle(),
14759 intImage2.layout(), 1, &blitRegion, VK_FILTER_LINEAR);
Mark Lobodzinskib02ea642016-08-17 13:03:57 -060014760 m_errorMonitor->VerifyFound();
14761
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014762 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with 0 in ppMemoryBarriers");
Tony Barbourd6673642016-05-05 14:46:39 -060014763 VkImageMemoryBarrier img_barrier;
14764 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
14765 img_barrier.pNext = NULL;
14766 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
14767 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
14768 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
14769 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
14770 img_barrier.image = image.handle();
14771 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
14772 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
14773 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14774 img_barrier.subresourceRange.baseArrayLayer = 0;
14775 img_barrier.subresourceRange.baseMipLevel = 0;
14776 // layerCount should not be 0 - Expect INVALID_IMAGE_RESOURCE
14777 img_barrier.subresourceRange.layerCount = 0;
14778 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014779 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
14780 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbourd6673642016-05-05 14:46:39 -060014781 m_errorMonitor->VerifyFound();
14782 img_barrier.subresourceRange.layerCount = 1;
14783}
14784
14785TEST_F(VkLayerTest, ImageFormatLimits) {
14786
14787 TEST_DESCRIPTION("Exceed the limits of image format ");
14788
Cody Northropc31a84f2016-08-22 10:41:47 -060014789 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014790 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "CreateImage extents exceed allowable limits for format");
Tony Barbourd6673642016-05-05 14:46:39 -060014791 VkImageCreateInfo image_create_info = {};
14792 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14793 image_create_info.pNext = NULL;
14794 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14795 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
14796 image_create_info.extent.width = 32;
14797 image_create_info.extent.height = 32;
14798 image_create_info.extent.depth = 1;
14799 image_create_info.mipLevels = 1;
14800 image_create_info.arrayLayers = 1;
14801 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14802 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
14803 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
14804 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
14805 image_create_info.flags = 0;
14806
14807 VkImage nullImg;
14808 VkImageFormatProperties imgFmtProps;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014809 vkGetPhysicalDeviceImageFormatProperties(gpu(), image_create_info.format, image_create_info.imageType, image_create_info.tiling,
14810 image_create_info.usage, image_create_info.flags, &imgFmtProps);
Tony Barbourd6673642016-05-05 14:46:39 -060014811 image_create_info.extent.depth = imgFmtProps.maxExtent.depth + 1;
14812 // Expect INVALID_FORMAT_LIMITS_VIOLATION
14813 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
14814 m_errorMonitor->VerifyFound();
14815 image_create_info.extent.depth = 1;
14816
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014817 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "exceeds allowable maximum supported by format of");
Tony Barbourd6673642016-05-05 14:46:39 -060014818 image_create_info.mipLevels = imgFmtProps.maxMipLevels + 1;
14819 // Expect INVALID_FORMAT_LIMITS_VIOLATION
14820 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
14821 m_errorMonitor->VerifyFound();
14822 image_create_info.mipLevels = 1;
14823
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014824 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "exceeds allowable maximum supported by format of");
Tony Barbourd6673642016-05-05 14:46:39 -060014825 image_create_info.arrayLayers = imgFmtProps.maxArrayLayers + 1;
14826 // Expect INVALID_FORMAT_LIMITS_VIOLATION
14827 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
14828 m_errorMonitor->VerifyFound();
14829 image_create_info.arrayLayers = 1;
14830
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014831 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is not supported by format");
Tony Barbourd6673642016-05-05 14:46:39 -060014832 int samples = imgFmtProps.sampleCounts >> 1;
14833 image_create_info.samples = (VkSampleCountFlagBits)samples;
14834 // Expect INVALID_FORMAT_LIMITS_VIOLATION
14835 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
14836 m_errorMonitor->VerifyFound();
14837 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14838
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014839 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "pCreateInfo->initialLayout, must be "
14840 "VK_IMAGE_LAYOUT_UNDEFINED or "
14841 "VK_IMAGE_LAYOUT_PREINITIALIZED");
Tony Barbourd6673642016-05-05 14:46:39 -060014842 image_create_info.initialLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
14843 // Expect INVALID_LAYOUT
14844 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
14845 m_errorMonitor->VerifyFound();
14846 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
14847}
14848
Mark Lobodzinskicea14992016-10-14 10:59:42 -060014849TEST_F(VkLayerTest, CopyImageSrcSizeExceeded) {
14850
14851 // Image copy with source region specified greater than src image size
Mark Lobodzinski629d47b2016-10-18 13:34:58 -060014852 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01175);
Mark Lobodzinskicea14992016-10-14 10:59:42 -060014853
14854 ASSERT_NO_FATAL_FAILURE(InitState());
14855
14856 VkImageObj src_image(m_device);
14857 src_image.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_LINEAR, 0);
14858 VkImageObj dst_image(m_device);
14859 dst_image.init(64, 64, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
14860
14861 BeginCommandBuffer();
14862 VkImageCopy copy_region;
14863 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14864 copy_region.srcSubresource.mipLevel = 0;
14865 copy_region.srcSubresource.baseArrayLayer = 0;
14866 copy_region.srcSubresource.layerCount = 0;
14867 copy_region.srcOffset.x = 0;
14868 copy_region.srcOffset.y = 0;
14869 copy_region.srcOffset.z = 0;
14870 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14871 copy_region.dstSubresource.mipLevel = 0;
14872 copy_region.dstSubresource.baseArrayLayer = 0;
14873 copy_region.dstSubresource.layerCount = 0;
14874 copy_region.dstOffset.x = 0;
14875 copy_region.dstOffset.y = 0;
14876 copy_region.dstOffset.z = 0;
14877 copy_region.extent.width = 64;
14878 copy_region.extent.height = 64;
14879 copy_region.extent.depth = 1;
14880 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
14881 &copy_region);
14882 EndCommandBuffer();
14883
14884 m_errorMonitor->VerifyFound();
14885}
14886
14887TEST_F(VkLayerTest, CopyImageDstSizeExceeded) {
14888
14889 // Image copy with dest region specified greater than dest image size
Mark Lobodzinski629d47b2016-10-18 13:34:58 -060014890 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01176);
Mark Lobodzinskicea14992016-10-14 10:59:42 -060014891
14892 ASSERT_NO_FATAL_FAILURE(InitState());
14893
14894 VkImageObj src_image(m_device);
14895 src_image.init(64, 64, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_LINEAR, 0);
14896 VkImageObj dst_image(m_device);
14897 dst_image.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
14898
14899 BeginCommandBuffer();
14900 VkImageCopy copy_region;
14901 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14902 copy_region.srcSubresource.mipLevel = 0;
14903 copy_region.srcSubresource.baseArrayLayer = 0;
14904 copy_region.srcSubresource.layerCount = 0;
14905 copy_region.srcOffset.x = 0;
14906 copy_region.srcOffset.y = 0;
14907 copy_region.srcOffset.z = 0;
14908 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14909 copy_region.dstSubresource.mipLevel = 0;
14910 copy_region.dstSubresource.baseArrayLayer = 0;
14911 copy_region.dstSubresource.layerCount = 0;
14912 copy_region.dstOffset.x = 0;
14913 copy_region.dstOffset.y = 0;
14914 copy_region.dstOffset.z = 0;
14915 copy_region.extent.width = 64;
14916 copy_region.extent.height = 64;
14917 copy_region.extent.depth = 1;
14918 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
14919 &copy_region);
14920 EndCommandBuffer();
14921
14922 m_errorMonitor->VerifyFound();
14923}
14924
Karl Schultz6addd812016-02-02 17:17:23 -070014925TEST_F(VkLayerTest, CopyImageFormatSizeMismatch) {
Karl Schultzbdb75952016-04-19 11:36:49 -060014926 VkResult err;
14927 bool pass;
14928
14929 // Create color images with different format sizes and try to copy between them
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014930 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14931 "vkCmdCopyImage called with unmatched source and dest image format sizes");
Karl Schultzbdb75952016-04-19 11:36:49 -060014932
14933 ASSERT_NO_FATAL_FAILURE(InitState());
14934
14935 // Create two images of different types and try to copy between them
14936 VkImage srcImage;
14937 VkImage dstImage;
14938 VkDeviceMemory srcMem;
14939 VkDeviceMemory destMem;
14940 VkMemoryRequirements memReqs;
14941
14942 VkImageCreateInfo image_create_info = {};
14943 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14944 image_create_info.pNext = NULL;
14945 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14946 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
14947 image_create_info.extent.width = 32;
14948 image_create_info.extent.height = 32;
14949 image_create_info.extent.depth = 1;
14950 image_create_info.mipLevels = 1;
14951 image_create_info.arrayLayers = 1;
14952 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14953 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
14954 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
14955 image_create_info.flags = 0;
14956
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014957 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Karl Schultzbdb75952016-04-19 11:36:49 -060014958 ASSERT_VK_SUCCESS(err);
14959
14960 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
14961 // Introduce failure by creating second image with a different-sized format.
14962 image_create_info.format = VK_FORMAT_R5G5B5A1_UNORM_PACK16;
14963
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014964 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Karl Schultzbdb75952016-04-19 11:36:49 -060014965 ASSERT_VK_SUCCESS(err);
14966
14967 // Allocate memory
14968 VkMemoryAllocateInfo memAlloc = {};
14969 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
14970 memAlloc.pNext = NULL;
14971 memAlloc.allocationSize = 0;
14972 memAlloc.memoryTypeIndex = 0;
14973
14974 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
14975 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014976 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -060014977 ASSERT_TRUE(pass);
14978 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
14979 ASSERT_VK_SUCCESS(err);
14980
14981 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
14982 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014983 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -060014984 ASSERT_TRUE(pass);
14985 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
14986 ASSERT_VK_SUCCESS(err);
14987
14988 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
14989 ASSERT_VK_SUCCESS(err);
14990 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
14991 ASSERT_VK_SUCCESS(err);
14992
14993 BeginCommandBuffer();
14994 VkImageCopy copyRegion;
14995 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14996 copyRegion.srcSubresource.mipLevel = 0;
14997 copyRegion.srcSubresource.baseArrayLayer = 0;
14998 copyRegion.srcSubresource.layerCount = 0;
14999 copyRegion.srcOffset.x = 0;
15000 copyRegion.srcOffset.y = 0;
15001 copyRegion.srcOffset.z = 0;
15002 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15003 copyRegion.dstSubresource.mipLevel = 0;
15004 copyRegion.dstSubresource.baseArrayLayer = 0;
15005 copyRegion.dstSubresource.layerCount = 0;
15006 copyRegion.dstOffset.x = 0;
15007 copyRegion.dstOffset.y = 0;
15008 copyRegion.dstOffset.z = 0;
15009 copyRegion.extent.width = 1;
15010 copyRegion.extent.height = 1;
15011 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015012 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Karl Schultzbdb75952016-04-19 11:36:49 -060015013 EndCommandBuffer();
15014
15015 m_errorMonitor->VerifyFound();
15016
15017 vkDestroyImage(m_device->device(), srcImage, NULL);
15018 vkDestroyImage(m_device->device(), dstImage, NULL);
15019 vkFreeMemory(m_device->device(), srcMem, NULL);
15020 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060015021}
15022
Karl Schultz6addd812016-02-02 17:17:23 -070015023TEST_F(VkLayerTest, CopyImageDepthStencilFormatMismatch) {
15024 VkResult err;
15025 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060015026
Mark Lobodzinskidb117632016-03-31 10:45:56 -060015027 // Create a color image and a depth/stencil image and try to copy between them
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015028 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15029 "vkCmdCopyImage called with unmatched source and dest image depth");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015030
Mike Stroyana3082432015-09-25 13:39:21 -060015031 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060015032
15033 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070015034 VkImage srcImage;
15035 VkImage dstImage;
15036 VkDeviceMemory srcMem;
15037 VkDeviceMemory destMem;
15038 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060015039
15040 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015041 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15042 image_create_info.pNext = NULL;
15043 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15044 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
15045 image_create_info.extent.width = 32;
15046 image_create_info.extent.height = 32;
15047 image_create_info.extent.depth = 1;
15048 image_create_info.mipLevels = 1;
15049 image_create_info.arrayLayers = 1;
15050 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15051 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15052 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
15053 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015054
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015055 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015056 ASSERT_VK_SUCCESS(err);
15057
Karl Schultzbdb75952016-04-19 11:36:49 -060015058 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
15059
Mark Lobodzinskidb117632016-03-31 10:45:56 -060015060 // Introduce failure by creating second image with a depth/stencil format
Karl Schultz6addd812016-02-02 17:17:23 -070015061 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060015062 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
Mark Lobodzinski867787a2016-10-14 11:49:55 -060015063 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015064
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015065 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015066 ASSERT_VK_SUCCESS(err);
15067
15068 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015069 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015070 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15071 memAlloc.pNext = NULL;
15072 memAlloc.allocationSize = 0;
15073 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015074
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060015075 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015076 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015077 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015078 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015079 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015080 ASSERT_VK_SUCCESS(err);
15081
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015082 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015083 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015084 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015085 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015086 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015087 ASSERT_VK_SUCCESS(err);
15088
15089 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
15090 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015091 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060015092 ASSERT_VK_SUCCESS(err);
15093
15094 BeginCommandBuffer();
15095 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015096 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015097 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060015098 copyRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015099 copyRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015100 copyRegion.srcOffset.x = 0;
15101 copyRegion.srcOffset.y = 0;
15102 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015103 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015104 copyRegion.dstSubresource.mipLevel = 0;
15105 copyRegion.dstSubresource.baseArrayLayer = 0;
15106 copyRegion.dstSubresource.layerCount = 0;
15107 copyRegion.dstOffset.x = 0;
15108 copyRegion.dstOffset.y = 0;
15109 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015110 copyRegion.extent.width = 1;
15111 copyRegion.extent.height = 1;
15112 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015113 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060015114 EndCommandBuffer();
15115
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015116 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060015117
Chia-I Wuf7458c52015-10-26 21:10:41 +080015118 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015119 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080015120 vkFreeMemory(m_device->device(), srcMem, NULL);
15121 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060015122}
15123
Karl Schultz6addd812016-02-02 17:17:23 -070015124TEST_F(VkLayerTest, ResolveImageLowSampleCount) {
15125 VkResult err;
15126 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060015127
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015128 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15129 "vkCmdResolveImage called with source sample count less than 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015130
Mike Stroyana3082432015-09-25 13:39:21 -060015131 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060015132
15133 // Create two images of sample count 1 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070015134 VkImage srcImage;
15135 VkImage dstImage;
15136 VkDeviceMemory srcMem;
15137 VkDeviceMemory destMem;
15138 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060015139
15140 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015141 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15142 image_create_info.pNext = NULL;
15143 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15144 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
15145 image_create_info.extent.width = 32;
15146 image_create_info.extent.height = 1;
15147 image_create_info.extent.depth = 1;
15148 image_create_info.mipLevels = 1;
15149 image_create_info.arrayLayers = 1;
15150 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15151 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15152 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
15153 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015154
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015155 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015156 ASSERT_VK_SUCCESS(err);
15157
Karl Schultz6addd812016-02-02 17:17:23 -070015158 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015159
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015160 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015161 ASSERT_VK_SUCCESS(err);
15162
15163 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015164 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015165 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15166 memAlloc.pNext = NULL;
15167 memAlloc.allocationSize = 0;
15168 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015169
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060015170 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015171 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015172 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015173 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015174 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015175 ASSERT_VK_SUCCESS(err);
15176
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015177 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015178 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015179 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015180 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015181 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015182 ASSERT_VK_SUCCESS(err);
15183
15184 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
15185 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015186 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060015187 ASSERT_VK_SUCCESS(err);
15188
15189 BeginCommandBuffer();
15190 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070015191 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
15192 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060015193 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015194 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015195 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060015196 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130015197 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060015198 resolveRegion.srcOffset.x = 0;
15199 resolveRegion.srcOffset.y = 0;
15200 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015201 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015202 resolveRegion.dstSubresource.mipLevel = 0;
15203 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130015204 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015205 resolveRegion.dstOffset.x = 0;
15206 resolveRegion.dstOffset.y = 0;
15207 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015208 resolveRegion.extent.width = 1;
15209 resolveRegion.extent.height = 1;
15210 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015211 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060015212 EndCommandBuffer();
15213
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015214 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060015215
Chia-I Wuf7458c52015-10-26 21:10:41 +080015216 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015217 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080015218 vkFreeMemory(m_device->device(), srcMem, NULL);
15219 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060015220}
15221
Karl Schultz6addd812016-02-02 17:17:23 -070015222TEST_F(VkLayerTest, ResolveImageHighSampleCount) {
15223 VkResult err;
15224 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060015225
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015226 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15227 "vkCmdResolveImage called with dest sample count greater than 1.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015228
Mike Stroyana3082432015-09-25 13:39:21 -060015229 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060015230
Chris Forbesa7530692016-05-08 12:35:39 +120015231 // Create two images of sample count 4 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070015232 VkImage srcImage;
15233 VkImage dstImage;
15234 VkDeviceMemory srcMem;
15235 VkDeviceMemory destMem;
15236 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060015237
15238 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015239 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15240 image_create_info.pNext = NULL;
15241 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15242 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
15243 image_create_info.extent.width = 32;
15244 image_create_info.extent.height = 1;
15245 image_create_info.extent.depth = 1;
15246 image_create_info.mipLevels = 1;
15247 image_create_info.arrayLayers = 1;
Chris Forbesa7530692016-05-08 12:35:39 +120015248 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070015249 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15250 // Note: Some implementations expect color attachment usage for any
15251 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015252 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070015253 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015254
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015255 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015256 ASSERT_VK_SUCCESS(err);
15257
Karl Schultz6addd812016-02-02 17:17:23 -070015258 // Note: Some implementations expect color attachment usage for any
15259 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015260 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015261
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015262 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015263 ASSERT_VK_SUCCESS(err);
15264
15265 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015266 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015267 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15268 memAlloc.pNext = NULL;
15269 memAlloc.allocationSize = 0;
15270 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015271
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060015272 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015273 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015274 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015275 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015276 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015277 ASSERT_VK_SUCCESS(err);
15278
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015279 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015280 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015281 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015282 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015283 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015284 ASSERT_VK_SUCCESS(err);
15285
15286 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
15287 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015288 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060015289 ASSERT_VK_SUCCESS(err);
15290
15291 BeginCommandBuffer();
15292 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070015293 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
15294 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060015295 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015296 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015297 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060015298 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130015299 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060015300 resolveRegion.srcOffset.x = 0;
15301 resolveRegion.srcOffset.y = 0;
15302 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015303 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015304 resolveRegion.dstSubresource.mipLevel = 0;
15305 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130015306 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015307 resolveRegion.dstOffset.x = 0;
15308 resolveRegion.dstOffset.y = 0;
15309 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015310 resolveRegion.extent.width = 1;
15311 resolveRegion.extent.height = 1;
15312 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015313 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060015314 EndCommandBuffer();
15315
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015316 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060015317
Chia-I Wuf7458c52015-10-26 21:10:41 +080015318 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015319 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080015320 vkFreeMemory(m_device->device(), srcMem, NULL);
15321 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060015322}
15323
Karl Schultz6addd812016-02-02 17:17:23 -070015324TEST_F(VkLayerTest, ResolveImageFormatMismatch) {
15325 VkResult err;
15326 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060015327
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015328 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15329 "vkCmdResolveImage called with unmatched source and dest formats.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015330
Mike Stroyana3082432015-09-25 13:39:21 -060015331 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060015332
15333 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070015334 VkImage srcImage;
15335 VkImage dstImage;
15336 VkDeviceMemory srcMem;
15337 VkDeviceMemory destMem;
15338 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060015339
15340 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015341 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15342 image_create_info.pNext = NULL;
15343 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15344 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
15345 image_create_info.extent.width = 32;
15346 image_create_info.extent.height = 1;
15347 image_create_info.extent.depth = 1;
15348 image_create_info.mipLevels = 1;
15349 image_create_info.arrayLayers = 1;
15350 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
15351 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15352 // Note: Some implementations expect color attachment usage for any
15353 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015354 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070015355 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015356
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015357 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015358 ASSERT_VK_SUCCESS(err);
15359
Karl Schultz6addd812016-02-02 17:17:23 -070015360 // Set format to something other than source image
15361 image_create_info.format = VK_FORMAT_R32_SFLOAT;
15362 // Note: Some implementations expect color attachment usage for any
15363 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015364 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070015365 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015366
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015367 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015368 ASSERT_VK_SUCCESS(err);
15369
15370 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015371 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015372 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15373 memAlloc.pNext = NULL;
15374 memAlloc.allocationSize = 0;
15375 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015376
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060015377 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015378 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015379 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015380 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015381 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015382 ASSERT_VK_SUCCESS(err);
15383
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015384 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015385 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015386 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015387 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015388 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015389 ASSERT_VK_SUCCESS(err);
15390
15391 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
15392 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015393 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060015394 ASSERT_VK_SUCCESS(err);
15395
15396 BeginCommandBuffer();
15397 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070015398 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
15399 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060015400 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015401 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015402 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060015403 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130015404 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060015405 resolveRegion.srcOffset.x = 0;
15406 resolveRegion.srcOffset.y = 0;
15407 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015408 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015409 resolveRegion.dstSubresource.mipLevel = 0;
15410 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130015411 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015412 resolveRegion.dstOffset.x = 0;
15413 resolveRegion.dstOffset.y = 0;
15414 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015415 resolveRegion.extent.width = 1;
15416 resolveRegion.extent.height = 1;
15417 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015418 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060015419 EndCommandBuffer();
15420
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015421 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060015422
Chia-I Wuf7458c52015-10-26 21:10:41 +080015423 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015424 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080015425 vkFreeMemory(m_device->device(), srcMem, NULL);
15426 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060015427}
15428
Karl Schultz6addd812016-02-02 17:17:23 -070015429TEST_F(VkLayerTest, ResolveImageTypeMismatch) {
15430 VkResult err;
15431 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060015432
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015433 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15434 "vkCmdResolveImage called with unmatched source and dest image types.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015435
Mike Stroyana3082432015-09-25 13:39:21 -060015436 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060015437
15438 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070015439 VkImage srcImage;
15440 VkImage dstImage;
15441 VkDeviceMemory srcMem;
15442 VkDeviceMemory destMem;
15443 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060015444
15445 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015446 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15447 image_create_info.pNext = NULL;
15448 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15449 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
15450 image_create_info.extent.width = 32;
15451 image_create_info.extent.height = 1;
15452 image_create_info.extent.depth = 1;
15453 image_create_info.mipLevels = 1;
15454 image_create_info.arrayLayers = 1;
15455 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
15456 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15457 // Note: Some implementations expect color attachment usage for any
15458 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015459 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070015460 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015461
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015462 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015463 ASSERT_VK_SUCCESS(err);
15464
Karl Schultz6addd812016-02-02 17:17:23 -070015465 image_create_info.imageType = VK_IMAGE_TYPE_1D;
15466 // Note: Some implementations expect color attachment usage for any
15467 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015468 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070015469 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015470
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015471 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015472 ASSERT_VK_SUCCESS(err);
15473
15474 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015475 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015476 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15477 memAlloc.pNext = NULL;
15478 memAlloc.allocationSize = 0;
15479 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015480
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060015481 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015482 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015483 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015484 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015485 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015486 ASSERT_VK_SUCCESS(err);
15487
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015488 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015489 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015490 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015491 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015492 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015493 ASSERT_VK_SUCCESS(err);
15494
15495 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
15496 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015497 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060015498 ASSERT_VK_SUCCESS(err);
15499
15500 BeginCommandBuffer();
15501 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070015502 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
15503 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060015504 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015505 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015506 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060015507 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130015508 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060015509 resolveRegion.srcOffset.x = 0;
15510 resolveRegion.srcOffset.y = 0;
15511 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015512 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015513 resolveRegion.dstSubresource.mipLevel = 0;
15514 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130015515 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015516 resolveRegion.dstOffset.x = 0;
15517 resolveRegion.dstOffset.y = 0;
15518 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015519 resolveRegion.extent.width = 1;
15520 resolveRegion.extent.height = 1;
15521 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015522 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060015523 EndCommandBuffer();
15524
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015525 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060015526
Chia-I Wuf7458c52015-10-26 21:10:41 +080015527 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015528 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080015529 vkFreeMemory(m_device->device(), srcMem, NULL);
15530 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060015531}
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015532
Karl Schultz6addd812016-02-02 17:17:23 -070015533TEST_F(VkLayerTest, DepthStencilImageViewWithColorAspectBitError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015534 // Create a single Image descriptor and cause it to first hit an error due
Karl Schultz6addd812016-02-02 17:17:23 -070015535 // to using a DS format, then cause it to hit error due to COLOR_BIT not
15536 // set in aspect
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015537 // The image format check comes 2nd in validation so we trigger it first,
15538 // then when we cause aspect fail next, bad format check will be preempted
Karl Schultz6addd812016-02-02 17:17:23 -070015539 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015540
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015541 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15542 "Combination depth/stencil image formats can have only the ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015543
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015544 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015545
Chia-I Wu1b99bb22015-10-27 19:25:11 +080015546 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015547 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
15548 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015549
15550 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015551 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
15552 ds_pool_ci.pNext = NULL;
15553 ds_pool_ci.maxSets = 1;
15554 ds_pool_ci.poolSizeCount = 1;
15555 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015556
15557 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015558 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015559 ASSERT_VK_SUCCESS(err);
15560
15561 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015562 dsl_binding.binding = 0;
15563 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
15564 dsl_binding.descriptorCount = 1;
15565 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
15566 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015567
15568 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015569 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
15570 ds_layout_ci.pNext = NULL;
15571 ds_layout_ci.bindingCount = 1;
15572 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015573 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015574 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015575 ASSERT_VK_SUCCESS(err);
15576
15577 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015578 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080015579 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070015580 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015581 alloc_info.descriptorPool = ds_pool;
15582 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015583 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015584 ASSERT_VK_SUCCESS(err);
15585
Karl Schultz6addd812016-02-02 17:17:23 -070015586 VkImage image_bad;
15587 VkImage image_good;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015588 // One bad format and one good format for Color attachment
Tobin Ehlis269f0322016-05-25 16:24:21 -060015589 const VkFormat tex_format_bad = VK_FORMAT_D24_UNORM_S8_UINT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015590 const VkFormat tex_format_good = VK_FORMAT_B8G8R8A8_UNORM;
Karl Schultz6addd812016-02-02 17:17:23 -070015591 const int32_t tex_width = 32;
15592 const int32_t tex_height = 32;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015593
15594 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015595 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15596 image_create_info.pNext = NULL;
15597 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15598 image_create_info.format = tex_format_bad;
15599 image_create_info.extent.width = tex_width;
15600 image_create_info.extent.height = tex_height;
15601 image_create_info.extent.depth = 1;
15602 image_create_info.mipLevels = 1;
15603 image_create_info.arrayLayers = 1;
15604 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15605 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015606 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070015607 image_create_info.flags = 0;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015608
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015609 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_bad);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015610 ASSERT_VK_SUCCESS(err);
15611 image_create_info.format = tex_format_good;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015612 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
15613 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_good);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015614 ASSERT_VK_SUCCESS(err);
15615
15616 VkImageViewCreateInfo image_view_create_info = {};
Chris Forbes53bef902016-11-28 17:53:04 +130015617 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070015618 image_view_create_info.image = image_bad;
15619 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
15620 image_view_create_info.format = tex_format_bad;
15621 image_view_create_info.subresourceRange.baseArrayLayer = 0;
15622 image_view_create_info.subresourceRange.baseMipLevel = 0;
15623 image_view_create_info.subresourceRange.layerCount = 1;
15624 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015625 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015626
15627 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015628 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015629
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015630 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015631
Chia-I Wuf7458c52015-10-26 21:10:41 +080015632 vkDestroyImage(m_device->device(), image_bad, NULL);
15633 vkDestroyImage(m_device->device(), image_good, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080015634 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
15635 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015636}
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015637
15638TEST_F(VkLayerTest, ClearImageErrors) {
15639 TEST_DESCRIPTION("Call ClearColorImage w/ a depth|stencil image and "
15640 "ClearDepthStencilImage with a color image.");
15641
15642 ASSERT_NO_FATAL_FAILURE(InitState());
15643 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15644
15645 // Renderpass is started here so end it as Clear cmds can't be in renderpass
15646 BeginCommandBuffer();
15647 m_commandBuffer->EndRenderPass();
15648
15649 // Color image
15650 VkClearColorValue clear_color;
15651 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
15652 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
15653 const VkFormat color_format = VK_FORMAT_B8G8R8A8_UNORM;
15654 const int32_t img_width = 32;
15655 const int32_t img_height = 32;
15656 VkImageCreateInfo image_create_info = {};
15657 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15658 image_create_info.pNext = NULL;
15659 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15660 image_create_info.format = color_format;
15661 image_create_info.extent.width = img_width;
15662 image_create_info.extent.height = img_height;
15663 image_create_info.extent.depth = 1;
15664 image_create_info.mipLevels = 1;
15665 image_create_info.arrayLayers = 1;
15666 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15667 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15668 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
15669
15670 vk_testing::Image color_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015671 color_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015672
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015673 const VkImageSubresourceRange color_range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015674
15675 // Depth/Stencil image
15676 VkClearDepthStencilValue clear_value = {0};
15677 reqs = 0; // don't need HOST_VISIBLE DS image
15678 VkImageCreateInfo ds_image_create_info = vk_testing::Image::create_info();
15679 ds_image_create_info.imageType = VK_IMAGE_TYPE_2D;
15680 ds_image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
15681 ds_image_create_info.extent.width = 64;
15682 ds_image_create_info.extent.height = 64;
15683 ds_image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15684 ds_image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
15685
15686 vk_testing::Image ds_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015687 ds_image.init(*m_device, (const VkImageCreateInfo &)ds_image_create_info, reqs);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015688
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015689 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 -060015690
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015691 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdClearColorImage called with depth/stencil image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015692
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015693 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), ds_image.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015694 &color_range);
15695
15696 m_errorMonitor->VerifyFound();
15697
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015698 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdClearColorImage called with "
15699 "image created without "
15700 "VK_IMAGE_USAGE_TRANSFER_DST_BIT");
Tony Barbour26434b92016-06-02 09:43:50 -060015701
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015702 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), ds_image.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
Tony Barbour26434b92016-06-02 09:43:50 -060015703 &color_range);
15704
15705 m_errorMonitor->VerifyFound();
15706
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015707 // Call CmdClearDepthStencilImage with color image
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015708 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15709 "vkCmdClearDepthStencilImage called without a depth/stencil image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015710
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015711 vkCmdClearDepthStencilImage(m_commandBuffer->GetBufferHandle(), color_image.handle(),
15712 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, &clear_value, 1, &ds_range);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015713
15714 m_errorMonitor->VerifyFound();
15715}
Tobin Ehliscde08892015-09-22 10:11:37 -060015716#endif // IMAGE_TESTS
15717
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060015718
15719// WSI Enabled Tests
15720//
Chris Forbes09368e42016-10-13 11:59:22 +130015721#if 0
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060015722TEST_F(VkWsiEnabledLayerTest, TestEnabledWsi) {
15723
15724#if defined(VK_USE_PLATFORM_XCB_KHR)
15725 VkSurfaceKHR surface = VK_NULL_HANDLE;
15726
15727 VkResult err;
15728 bool pass;
15729 VkSwapchainKHR swapchain = VK_NULL_HANDLE;
15730 VkSwapchainCreateInfoKHR swapchain_create_info = {};
15731 // uint32_t swapchain_image_count = 0;
15732 // VkImage swapchain_images[1] = {VK_NULL_HANDLE};
15733 // uint32_t image_index = 0;
15734 // VkPresentInfoKHR present_info = {};
15735
15736 ASSERT_NO_FATAL_FAILURE(InitState());
15737
15738 // Use the create function from one of the VK_KHR_*_surface extension in
15739 // order to create a surface, testing all known errors in the process,
15740 // before successfully creating a surface:
15741 // First, try to create a surface without a VkXcbSurfaceCreateInfoKHR:
15742 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pCreateInfo specified as NULL");
15743 err = vkCreateXcbSurfaceKHR(instance(), NULL, NULL, &surface);
15744 pass = (err != VK_SUCCESS);
15745 ASSERT_TRUE(pass);
15746 m_errorMonitor->VerifyFound();
15747
15748 // Next, try to create a surface with the wrong
15749 // VkXcbSurfaceCreateInfoKHR::sType:
15750 VkXcbSurfaceCreateInfoKHR xcb_create_info = {};
15751 xcb_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
15752 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pCreateInfo->sType must be");
15753 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
15754 pass = (err != VK_SUCCESS);
15755 ASSERT_TRUE(pass);
15756 m_errorMonitor->VerifyFound();
15757
15758 // Create a native window, and then correctly create a surface:
15759 xcb_connection_t *connection;
15760 xcb_screen_t *screen;
15761 xcb_window_t xcb_window;
15762 xcb_intern_atom_reply_t *atom_wm_delete_window;
15763
15764 const xcb_setup_t *setup;
15765 xcb_screen_iterator_t iter;
15766 int scr;
15767 uint32_t value_mask, value_list[32];
15768 int width = 1;
15769 int height = 1;
15770
15771 connection = xcb_connect(NULL, &scr);
15772 ASSERT_TRUE(connection != NULL);
15773 setup = xcb_get_setup(connection);
15774 iter = xcb_setup_roots_iterator(setup);
15775 while (scr-- > 0)
15776 xcb_screen_next(&iter);
15777 screen = iter.data;
15778
15779 xcb_window = xcb_generate_id(connection);
15780
15781 value_mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK;
15782 value_list[0] = screen->black_pixel;
15783 value_list[1] = XCB_EVENT_MASK_KEY_RELEASE | XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_STRUCTURE_NOTIFY;
15784
15785 xcb_create_window(connection, XCB_COPY_FROM_PARENT, xcb_window, screen->root, 0, 0, width, height, 0,
15786 XCB_WINDOW_CLASS_INPUT_OUTPUT, screen->root_visual, value_mask, value_list);
15787
15788 /* Magic code that will send notification when window is destroyed */
15789 xcb_intern_atom_cookie_t cookie = xcb_intern_atom(connection, 1, 12, "WM_PROTOCOLS");
15790 xcb_intern_atom_reply_t *reply = xcb_intern_atom_reply(connection, cookie, 0);
15791
15792 xcb_intern_atom_cookie_t cookie2 = xcb_intern_atom(connection, 0, 16, "WM_DELETE_WINDOW");
15793 atom_wm_delete_window = xcb_intern_atom_reply(connection, cookie2, 0);
15794 xcb_change_property(connection, XCB_PROP_MODE_REPLACE, xcb_window, (*reply).atom, 4, 32, 1, &(*atom_wm_delete_window).atom);
15795 free(reply);
15796
15797 xcb_map_window(connection, xcb_window);
15798
15799 // Force the x/y coordinates to 100,100 results are identical in consecutive
15800 // runs
15801 const uint32_t coords[] = { 100, 100 };
15802 xcb_configure_window(connection, xcb_window, XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y, coords);
15803
15804 // Finally, try to correctly create a surface:
15805 xcb_create_info.sType = VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR;
15806 xcb_create_info.pNext = NULL;
15807 xcb_create_info.flags = 0;
15808 xcb_create_info.connection = connection;
15809 xcb_create_info.window = xcb_window;
15810 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
15811 pass = (err == VK_SUCCESS);
15812 ASSERT_TRUE(pass);
15813
15814 // Check if surface supports presentation:
15815
15816 // 1st, do so without having queried the queue families:
15817 VkBool32 supported = false;
15818 // TODO: Get the following error to come out:
15819 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15820 "called before calling the vkGetPhysicalDeviceQueueFamilyProperties "
15821 "function");
15822 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
15823 pass = (err != VK_SUCCESS);
15824 // ASSERT_TRUE(pass);
15825 // m_errorMonitor->VerifyFound();
15826
15827 // Next, query a queue family index that's too large:
15828 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with a queueFamilyIndex that is too large");
15829 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 100000, surface, &supported);
15830 pass = (err != VK_SUCCESS);
15831 ASSERT_TRUE(pass);
15832 m_errorMonitor->VerifyFound();
15833
15834 // Finally, do so correctly:
15835 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
15836 // SUPPORTED
15837 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
15838 pass = (err == VK_SUCCESS);
15839 ASSERT_TRUE(pass);
15840
15841 // Before proceeding, try to create a swapchain without having called
15842 // vkGetPhysicalDeviceSurfaceCapabilitiesKHR():
15843 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
15844 swapchain_create_info.pNext = NULL;
15845 swapchain_create_info.flags = 0;
15846 swapchain_create_info.imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
15847 swapchain_create_info.surface = surface;
15848 swapchain_create_info.imageArrayLayers = 1;
15849 swapchain_create_info.preTransform = VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR;
15850 swapchain_create_info.compositeAlpha = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR;
15851 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15852 "called before calling vkGetPhysicalDeviceSurfaceCapabilitiesKHR().");
15853 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
15854 pass = (err != VK_SUCCESS);
15855 ASSERT_TRUE(pass);
15856 m_errorMonitor->VerifyFound();
15857
15858 // Get the surface capabilities:
15859 VkSurfaceCapabilitiesKHR surface_capabilities;
15860
15861 // Do so correctly (only error logged by this entrypoint is if the
15862 // extension isn't enabled):
15863 err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), surface, &surface_capabilities);
15864 pass = (err == VK_SUCCESS);
15865 ASSERT_TRUE(pass);
15866
15867 // Get the surface formats:
15868 uint32_t surface_format_count;
15869
15870 // First, try without a pointer to surface_format_count:
15871 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pSurfaceFormatCount "
15872 "specified as NULL");
15873 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, NULL, NULL);
15874 pass = (err == VK_SUCCESS);
15875 ASSERT_TRUE(pass);
15876 m_errorMonitor->VerifyFound();
15877
15878 // Next, call with a non-NULL pSurfaceFormats, even though we haven't
15879 // correctly done a 1st try (to get the count):
15880 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "but no prior positive value has been seen for");
15881 surface_format_count = 0;
15882 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, (VkSurfaceFormatKHR *)&surface_format_count);
15883 pass = (err == VK_SUCCESS);
15884 ASSERT_TRUE(pass);
15885 m_errorMonitor->VerifyFound();
15886
15887 // Next, correctly do a 1st try (with a NULL pointer to surface_formats):
15888 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, NULL);
15889 pass = (err == VK_SUCCESS);
15890 ASSERT_TRUE(pass);
15891
15892 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
15893 VkSurfaceFormatKHR *surface_formats = (VkSurfaceFormatKHR *)malloc(surface_format_count * sizeof(VkSurfaceFormatKHR));
15894
15895 // Next, do a 2nd try with surface_format_count being set too high:
15896 surface_format_count += 5;
15897 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is greater than the value");
15898 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, surface_formats);
15899 pass = (err == VK_SUCCESS);
15900 ASSERT_TRUE(pass);
15901 m_errorMonitor->VerifyFound();
15902
15903 // Finally, do a correct 1st and 2nd try:
15904 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, NULL);
15905 pass = (err == VK_SUCCESS);
15906 ASSERT_TRUE(pass);
15907 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, surface_formats);
15908 pass = (err == VK_SUCCESS);
15909 ASSERT_TRUE(pass);
15910
15911 // Get the surface present modes:
15912 uint32_t surface_present_mode_count;
15913
15914 // First, try without a pointer to surface_format_count:
15915 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pPresentModeCount "
15916 "specified as NULL");
15917
15918 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, NULL, NULL);
15919 pass = (err == VK_SUCCESS);
15920 ASSERT_TRUE(pass);
15921 m_errorMonitor->VerifyFound();
15922
15923 // Next, call with a non-NULL VkPresentModeKHR, even though we haven't
15924 // correctly done a 1st try (to get the count):
15925 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "but no prior positive value has been seen for");
15926 surface_present_mode_count = 0;
15927 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count,
15928 (VkPresentModeKHR *)&surface_present_mode_count);
15929 pass = (err == VK_SUCCESS);
15930 ASSERT_TRUE(pass);
15931 m_errorMonitor->VerifyFound();
15932
15933 // Next, correctly do a 1st try (with a NULL pointer to surface_formats):
15934 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, NULL);
15935 pass = (err == VK_SUCCESS);
15936 ASSERT_TRUE(pass);
15937
15938 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
15939 VkPresentModeKHR *surface_present_modes = (VkPresentModeKHR *)malloc(surface_present_mode_count * sizeof(VkPresentModeKHR));
15940
15941 // Next, do a 2nd try with surface_format_count being set too high:
15942 surface_present_mode_count += 5;
15943 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is greater than the value");
15944 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, surface_present_modes);
15945 pass = (err == VK_SUCCESS);
15946 ASSERT_TRUE(pass);
15947 m_errorMonitor->VerifyFound();
15948
15949 // Finally, do a correct 1st and 2nd try:
15950 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, NULL);
15951 pass = (err == VK_SUCCESS);
15952 ASSERT_TRUE(pass);
15953 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, surface_present_modes);
15954 pass = (err == VK_SUCCESS);
15955 ASSERT_TRUE(pass);
15956
15957 // Create a swapchain:
15958
15959 // First, try without a pointer to swapchain_create_info:
15960 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pCreateInfo "
15961 "specified as NULL");
15962
15963 err = vkCreateSwapchainKHR(m_device->device(), NULL, NULL, &swapchain);
15964 pass = (err != VK_SUCCESS);
15965 ASSERT_TRUE(pass);
15966 m_errorMonitor->VerifyFound();
15967
15968 // Next, call with a non-NULL swapchain_create_info, that has the wrong
15969 // sType:
15970 swapchain_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
15971 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pCreateInfo->sType must be");
15972
15973 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
15974 pass = (err != VK_SUCCESS);
15975 ASSERT_TRUE(pass);
15976 m_errorMonitor->VerifyFound();
15977
15978 // Next, call with a NULL swapchain pointer:
15979 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
15980 swapchain_create_info.pNext = NULL;
15981 swapchain_create_info.flags = 0;
15982 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pSwapchain "
15983 "specified as NULL");
15984
15985 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, NULL);
15986 pass = (err != VK_SUCCESS);
15987 ASSERT_TRUE(pass);
15988 m_errorMonitor->VerifyFound();
15989
15990 // TODO: Enhance swapchain layer so that
15991 // swapchain_create_info.queueFamilyIndexCount is checked against something?
15992
15993 // Next, call with a queue family index that's too large:
15994 uint32_t queueFamilyIndex[2] = { 100000, 0 };
15995 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
15996 swapchain_create_info.queueFamilyIndexCount = 2;
15997 swapchain_create_info.pQueueFamilyIndices = queueFamilyIndex;
15998 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with a queueFamilyIndex that is too large");
15999 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
16000 pass = (err != VK_SUCCESS);
16001 ASSERT_TRUE(pass);
16002 m_errorMonitor->VerifyFound();
16003
16004 // Next, call a queueFamilyIndexCount that's too small for CONCURRENT:
16005 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
16006 swapchain_create_info.queueFamilyIndexCount = 1;
16007 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16008 "but with a bad value(s) for pCreateInfo->queueFamilyIndexCount or "
16009 "pCreateInfo->pQueueFamilyIndices).");
16010 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
16011 pass = (err != VK_SUCCESS);
16012 ASSERT_TRUE(pass);
16013 m_errorMonitor->VerifyFound();
16014
16015 // Next, call with an invalid imageSharingMode:
16016 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_MAX_ENUM;
16017 swapchain_create_info.queueFamilyIndexCount = 1;
16018 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16019 "called with a non-supported pCreateInfo->imageSharingMode (i.e.");
16020 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
16021 pass = (err != VK_SUCCESS);
16022 ASSERT_TRUE(pass);
16023 m_errorMonitor->VerifyFound();
16024 // Fix for the future:
16025 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
16026 // SUPPORTED
16027 swapchain_create_info.queueFamilyIndexCount = 0;
16028 queueFamilyIndex[0] = 0;
16029 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE;
16030
16031 // TODO: CONTINUE TESTING VALIDATION OF vkCreateSwapchainKHR() ...
16032 // Get the images from a swapchain:
16033 // Acquire an image from a swapchain:
16034 // Present an image to a swapchain:
16035 // Destroy the swapchain:
16036
16037 // TODOs:
16038 //
16039 // - Try destroying the device without first destroying the swapchain
16040 //
16041 // - Try destroying the device without first destroying the surface
16042 //
16043 // - Try destroying the surface without first destroying the swapchain
16044
16045 // Destroy the surface:
16046 vkDestroySurfaceKHR(instance(), surface, NULL);
16047
16048 // Tear down the window:
16049 xcb_destroy_window(connection, xcb_window);
16050 xcb_disconnect(connection);
16051
16052#else // VK_USE_PLATFORM_XCB_KHR
16053 return;
16054#endif // VK_USE_PLATFORM_XCB_KHR
16055}
Chris Forbes09368e42016-10-13 11:59:22 +130016056#endif
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016057
16058//
16059// POSITIVE VALIDATION TESTS
16060//
16061// These tests do not expect to encounter ANY validation errors pass only if this is true
16062
Tobin Ehlise0006882016-11-03 10:14:28 -060016063TEST_F(VkPositiveLayerTest, SecondaryCommandBufferImageLayoutTransitions) {
16064 TEST_DESCRIPTION("Perform an image layout transition in a secondary command buffer followed "
16065 "by a transition in the primary.");
16066 VkResult err;
16067 m_errorMonitor->ExpectSuccess();
16068 ASSERT_NO_FATAL_FAILURE(InitState());
16069 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
16070 // Allocate a secondary and primary cmd buffer
16071 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
16072 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
16073 command_buffer_allocate_info.commandPool = m_commandPool;
16074 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
16075 command_buffer_allocate_info.commandBufferCount = 1;
16076
16077 VkCommandBuffer secondary_command_buffer;
16078 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer));
16079 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
16080 VkCommandBuffer primary_command_buffer;
16081 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &primary_command_buffer));
16082 VkCommandBufferBeginInfo command_buffer_begin_info = {};
16083 VkCommandBufferInheritanceInfo command_buffer_inheritance_info = {};
16084 command_buffer_inheritance_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
16085 command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
16086 command_buffer_begin_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
16087 command_buffer_begin_info.pInheritanceInfo = &command_buffer_inheritance_info;
16088
16089 err = vkBeginCommandBuffer(secondary_command_buffer, &command_buffer_begin_info);
16090 ASSERT_VK_SUCCESS(err);
16091 VkImageObj image(m_device);
16092 image.init(128, 128, VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
16093 ASSERT_TRUE(image.initialized());
16094 VkImageMemoryBarrier img_barrier = {};
16095 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
16096 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
16097 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
16098 img_barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
16099 img_barrier.newLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
16100 img_barrier.image = image.handle();
16101 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
16102 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
16103 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
16104 img_barrier.subresourceRange.baseArrayLayer = 0;
16105 img_barrier.subresourceRange.baseMipLevel = 0;
16106 img_barrier.subresourceRange.layerCount = 1;
16107 img_barrier.subresourceRange.levelCount = 1;
16108 vkCmdPipelineBarrier(secondary_command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr,
16109 0, nullptr, 1, &img_barrier);
16110 err = vkEndCommandBuffer(secondary_command_buffer);
16111 ASSERT_VK_SUCCESS(err);
16112
16113 // Now update primary cmd buffer to execute secondary and transitions image
16114 command_buffer_begin_info.pInheritanceInfo = nullptr;
16115 err = vkBeginCommandBuffer(primary_command_buffer, &command_buffer_begin_info);
16116 ASSERT_VK_SUCCESS(err);
16117 vkCmdExecuteCommands(primary_command_buffer, 1, &secondary_command_buffer);
16118 VkImageMemoryBarrier img_barrier2 = {};
16119 img_barrier2.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
16120 img_barrier2.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
16121 img_barrier2.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
16122 img_barrier2.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
16123 img_barrier2.newLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
16124 img_barrier2.image = image.handle();
16125 img_barrier2.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
16126 img_barrier2.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
16127 img_barrier2.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
16128 img_barrier2.subresourceRange.baseArrayLayer = 0;
16129 img_barrier2.subresourceRange.baseMipLevel = 0;
16130 img_barrier2.subresourceRange.layerCount = 1;
16131 img_barrier2.subresourceRange.levelCount = 1;
16132 vkCmdPipelineBarrier(primary_command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0,
16133 nullptr, 1, &img_barrier2);
16134 err = vkEndCommandBuffer(primary_command_buffer);
16135 ASSERT_VK_SUCCESS(err);
16136 VkSubmitInfo submit_info = {};
16137 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
16138 submit_info.commandBufferCount = 1;
16139 submit_info.pCommandBuffers = &primary_command_buffer;
16140 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
16141 ASSERT_VK_SUCCESS(err);
16142 m_errorMonitor->VerifyNotFound();
16143 err = vkDeviceWaitIdle(m_device->device());
16144 ASSERT_VK_SUCCESS(err);
16145 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &secondary_command_buffer);
16146 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &primary_command_buffer);
16147}
16148
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016149// This is a positive test. No failures are expected.
16150TEST_F(VkPositiveLayerTest, IgnoreUnrelatedDescriptor) {
16151 TEST_DESCRIPTION("Ensure that the vkUpdateDescriptorSets validation code "
16152 "is ignoring VkWriteDescriptorSet members that are not "
16153 "related to the descriptor type specified by "
16154 "VkWriteDescriptorSet::descriptorType. Correct "
16155 "validation behavior will result in the test running to "
16156 "completion without validation errors.");
16157
16158 const uintptr_t invalid_ptr = 0xcdcdcdcd;
16159
16160 ASSERT_NO_FATAL_FAILURE(InitState());
16161
16162 // Image Case
16163 {
16164 m_errorMonitor->ExpectSuccess();
16165
16166 VkImage image;
16167 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
16168 const int32_t tex_width = 32;
16169 const int32_t tex_height = 32;
16170 VkImageCreateInfo image_create_info = {};
16171 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16172 image_create_info.pNext = NULL;
16173 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16174 image_create_info.format = tex_format;
16175 image_create_info.extent.width = tex_width;
16176 image_create_info.extent.height = tex_height;
16177 image_create_info.extent.depth = 1;
16178 image_create_info.mipLevels = 1;
16179 image_create_info.arrayLayers = 1;
16180 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16181 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
16182 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
16183 image_create_info.flags = 0;
16184 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
16185 ASSERT_VK_SUCCESS(err);
16186
16187 VkMemoryRequirements memory_reqs;
16188 VkDeviceMemory image_memory;
16189 bool pass;
16190 VkMemoryAllocateInfo memory_info = {};
16191 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16192 memory_info.pNext = NULL;
16193 memory_info.allocationSize = 0;
16194 memory_info.memoryTypeIndex = 0;
16195 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
16196 memory_info.allocationSize = memory_reqs.size;
16197 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
16198 ASSERT_TRUE(pass);
16199 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
16200 ASSERT_VK_SUCCESS(err);
16201 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
16202 ASSERT_VK_SUCCESS(err);
16203
16204 VkImageViewCreateInfo image_view_create_info = {};
16205 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
16206 image_view_create_info.image = image;
16207 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
16208 image_view_create_info.format = tex_format;
16209 image_view_create_info.subresourceRange.layerCount = 1;
16210 image_view_create_info.subresourceRange.baseMipLevel = 0;
16211 image_view_create_info.subresourceRange.levelCount = 1;
16212 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16213
16214 VkImageView view;
16215 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
16216 ASSERT_VK_SUCCESS(err);
16217
16218 VkDescriptorPoolSize ds_type_count = {};
16219 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
16220 ds_type_count.descriptorCount = 1;
16221
16222 VkDescriptorPoolCreateInfo ds_pool_ci = {};
16223 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
16224 ds_pool_ci.pNext = NULL;
16225 ds_pool_ci.maxSets = 1;
16226 ds_pool_ci.poolSizeCount = 1;
16227 ds_pool_ci.pPoolSizes = &ds_type_count;
16228
16229 VkDescriptorPool ds_pool;
16230 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
16231 ASSERT_VK_SUCCESS(err);
16232
16233 VkDescriptorSetLayoutBinding dsl_binding = {};
16234 dsl_binding.binding = 0;
16235 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
16236 dsl_binding.descriptorCount = 1;
16237 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
16238 dsl_binding.pImmutableSamplers = NULL;
16239
16240 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
16241 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
16242 ds_layout_ci.pNext = NULL;
16243 ds_layout_ci.bindingCount = 1;
16244 ds_layout_ci.pBindings = &dsl_binding;
16245 VkDescriptorSetLayout ds_layout;
16246 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
16247 ASSERT_VK_SUCCESS(err);
16248
16249 VkDescriptorSet descriptor_set;
16250 VkDescriptorSetAllocateInfo alloc_info = {};
16251 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
16252 alloc_info.descriptorSetCount = 1;
16253 alloc_info.descriptorPool = ds_pool;
16254 alloc_info.pSetLayouts = &ds_layout;
16255 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
16256 ASSERT_VK_SUCCESS(err);
16257
16258 VkDescriptorImageInfo image_info = {};
16259 image_info.imageView = view;
16260 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
16261
16262 VkWriteDescriptorSet descriptor_write;
16263 memset(&descriptor_write, 0, sizeof(descriptor_write));
16264 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
16265 descriptor_write.dstSet = descriptor_set;
16266 descriptor_write.dstBinding = 0;
16267 descriptor_write.descriptorCount = 1;
16268 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
16269 descriptor_write.pImageInfo = &image_info;
16270
16271 // Set pBufferInfo and pTexelBufferView to invalid values, which should
16272 // be
16273 // ignored for descriptorType == VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE.
16274 // This will most likely produce a crash if the parameter_validation
16275 // layer
16276 // does not correctly ignore pBufferInfo.
16277 descriptor_write.pBufferInfo = reinterpret_cast<const VkDescriptorBufferInfo *>(invalid_ptr);
16278 descriptor_write.pTexelBufferView = reinterpret_cast<const VkBufferView *>(invalid_ptr);
16279
16280 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
16281
16282 m_errorMonitor->VerifyNotFound();
16283
16284 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
16285 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
16286 vkDestroyImageView(m_device->device(), view, NULL);
16287 vkDestroyImage(m_device->device(), image, NULL);
16288 vkFreeMemory(m_device->device(), image_memory, NULL);
16289 }
16290
16291 // Buffer Case
16292 {
16293 m_errorMonitor->ExpectSuccess();
16294
16295 VkBuffer buffer;
16296 uint32_t queue_family_index = 0;
16297 VkBufferCreateInfo buffer_create_info = {};
16298 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
16299 buffer_create_info.size = 1024;
16300 buffer_create_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
16301 buffer_create_info.queueFamilyIndexCount = 1;
16302 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
16303
16304 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
16305 ASSERT_VK_SUCCESS(err);
16306
16307 VkMemoryRequirements memory_reqs;
16308 VkDeviceMemory buffer_memory;
16309 bool pass;
16310 VkMemoryAllocateInfo memory_info = {};
16311 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16312 memory_info.pNext = NULL;
16313 memory_info.allocationSize = 0;
16314 memory_info.memoryTypeIndex = 0;
16315
16316 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
16317 memory_info.allocationSize = memory_reqs.size;
16318 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
16319 ASSERT_TRUE(pass);
16320
16321 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
16322 ASSERT_VK_SUCCESS(err);
16323 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
16324 ASSERT_VK_SUCCESS(err);
16325
16326 VkDescriptorPoolSize ds_type_count = {};
16327 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16328 ds_type_count.descriptorCount = 1;
16329
16330 VkDescriptorPoolCreateInfo ds_pool_ci = {};
16331 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
16332 ds_pool_ci.pNext = NULL;
16333 ds_pool_ci.maxSets = 1;
16334 ds_pool_ci.poolSizeCount = 1;
16335 ds_pool_ci.pPoolSizes = &ds_type_count;
16336
16337 VkDescriptorPool ds_pool;
16338 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
16339 ASSERT_VK_SUCCESS(err);
16340
16341 VkDescriptorSetLayoutBinding dsl_binding = {};
16342 dsl_binding.binding = 0;
16343 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16344 dsl_binding.descriptorCount = 1;
16345 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
16346 dsl_binding.pImmutableSamplers = NULL;
16347
16348 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
16349 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
16350 ds_layout_ci.pNext = NULL;
16351 ds_layout_ci.bindingCount = 1;
16352 ds_layout_ci.pBindings = &dsl_binding;
16353 VkDescriptorSetLayout ds_layout;
16354 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
16355 ASSERT_VK_SUCCESS(err);
16356
16357 VkDescriptorSet descriptor_set;
16358 VkDescriptorSetAllocateInfo alloc_info = {};
16359 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
16360 alloc_info.descriptorSetCount = 1;
16361 alloc_info.descriptorPool = ds_pool;
16362 alloc_info.pSetLayouts = &ds_layout;
16363 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
16364 ASSERT_VK_SUCCESS(err);
16365
16366 VkDescriptorBufferInfo buffer_info = {};
16367 buffer_info.buffer = buffer;
16368 buffer_info.offset = 0;
16369 buffer_info.range = 1024;
16370
16371 VkWriteDescriptorSet descriptor_write;
16372 memset(&descriptor_write, 0, sizeof(descriptor_write));
16373 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
16374 descriptor_write.dstSet = descriptor_set;
16375 descriptor_write.dstBinding = 0;
16376 descriptor_write.descriptorCount = 1;
16377 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16378 descriptor_write.pBufferInfo = &buffer_info;
16379
16380 // Set pImageInfo and pTexelBufferView to invalid values, which should
16381 // be
16382 // ignored for descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER.
16383 // This will most likely produce a crash if the parameter_validation
16384 // layer
16385 // does not correctly ignore pImageInfo.
16386 descriptor_write.pImageInfo = reinterpret_cast<const VkDescriptorImageInfo *>(invalid_ptr);
16387 descriptor_write.pTexelBufferView = reinterpret_cast<const VkBufferView *>(invalid_ptr);
16388
16389 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
16390
16391 m_errorMonitor->VerifyNotFound();
16392
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016393 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
16394 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
16395 vkDestroyBuffer(m_device->device(), buffer, NULL);
16396 vkFreeMemory(m_device->device(), buffer_memory, NULL);
16397 }
16398
16399 // Texel Buffer Case
16400 {
16401 m_errorMonitor->ExpectSuccess();
16402
16403 VkBuffer buffer;
16404 uint32_t queue_family_index = 0;
16405 VkBufferCreateInfo buffer_create_info = {};
16406 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
16407 buffer_create_info.size = 1024;
16408 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
16409 buffer_create_info.queueFamilyIndexCount = 1;
16410 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
16411
16412 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
16413 ASSERT_VK_SUCCESS(err);
16414
16415 VkMemoryRequirements memory_reqs;
16416 VkDeviceMemory buffer_memory;
16417 bool pass;
16418 VkMemoryAllocateInfo memory_info = {};
16419 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16420 memory_info.pNext = NULL;
16421 memory_info.allocationSize = 0;
16422 memory_info.memoryTypeIndex = 0;
16423
16424 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
16425 memory_info.allocationSize = memory_reqs.size;
16426 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
16427 ASSERT_TRUE(pass);
16428
16429 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
16430 ASSERT_VK_SUCCESS(err);
16431 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
16432 ASSERT_VK_SUCCESS(err);
16433
16434 VkBufferViewCreateInfo buff_view_ci = {};
16435 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
16436 buff_view_ci.buffer = buffer;
16437 buff_view_ci.format = VK_FORMAT_R8_UNORM;
16438 buff_view_ci.range = VK_WHOLE_SIZE;
16439 VkBufferView buffer_view;
16440 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buffer_view);
16441
16442 VkDescriptorPoolSize ds_type_count = {};
16443 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
16444 ds_type_count.descriptorCount = 1;
16445
16446 VkDescriptorPoolCreateInfo ds_pool_ci = {};
16447 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
16448 ds_pool_ci.pNext = NULL;
16449 ds_pool_ci.maxSets = 1;
16450 ds_pool_ci.poolSizeCount = 1;
16451 ds_pool_ci.pPoolSizes = &ds_type_count;
16452
16453 VkDescriptorPool ds_pool;
16454 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
16455 ASSERT_VK_SUCCESS(err);
16456
16457 VkDescriptorSetLayoutBinding dsl_binding = {};
16458 dsl_binding.binding = 0;
16459 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
16460 dsl_binding.descriptorCount = 1;
16461 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
16462 dsl_binding.pImmutableSamplers = NULL;
16463
16464 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
16465 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
16466 ds_layout_ci.pNext = NULL;
16467 ds_layout_ci.bindingCount = 1;
16468 ds_layout_ci.pBindings = &dsl_binding;
16469 VkDescriptorSetLayout ds_layout;
16470 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
16471 ASSERT_VK_SUCCESS(err);
16472
16473 VkDescriptorSet descriptor_set;
16474 VkDescriptorSetAllocateInfo alloc_info = {};
16475 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
16476 alloc_info.descriptorSetCount = 1;
16477 alloc_info.descriptorPool = ds_pool;
16478 alloc_info.pSetLayouts = &ds_layout;
16479 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
16480 ASSERT_VK_SUCCESS(err);
16481
16482 VkWriteDescriptorSet descriptor_write;
16483 memset(&descriptor_write, 0, sizeof(descriptor_write));
16484 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
16485 descriptor_write.dstSet = descriptor_set;
16486 descriptor_write.dstBinding = 0;
16487 descriptor_write.descriptorCount = 1;
16488 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
16489 descriptor_write.pTexelBufferView = &buffer_view;
16490
16491 // Set pImageInfo and pBufferInfo to invalid values, which should be
16492 // ignored for descriptorType ==
16493 // VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER.
16494 // This will most likely produce a crash if the parameter_validation
16495 // layer
16496 // does not correctly ignore pImageInfo and pBufferInfo.
16497 descriptor_write.pImageInfo = reinterpret_cast<const VkDescriptorImageInfo *>(invalid_ptr);
16498 descriptor_write.pBufferInfo = reinterpret_cast<const VkDescriptorBufferInfo *>(invalid_ptr);
16499
16500 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
16501
16502 m_errorMonitor->VerifyNotFound();
16503
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016504 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
16505 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
16506 vkDestroyBufferView(m_device->device(), buffer_view, NULL);
16507 vkDestroyBuffer(m_device->device(), buffer, NULL);
16508 vkFreeMemory(m_device->device(), buffer_memory, NULL);
16509 }
16510}
16511
Tobin Ehlisf7428442016-10-25 07:58:24 -060016512TEST_F(VkLayerTest, DuplicateDescriptorBinding) {
16513 TEST_DESCRIPTION("Create a descriptor set layout with a duplicate binding number.");
16514
16515 ASSERT_NO_FATAL_FAILURE(InitState());
16516 // Create layout where two binding #s are "1"
16517 static const uint32_t NUM_BINDINGS = 3;
16518 VkDescriptorSetLayoutBinding dsl_binding[NUM_BINDINGS] = {};
16519 dsl_binding[0].binding = 1;
16520 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16521 dsl_binding[0].descriptorCount = 1;
16522 dsl_binding[0].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
16523 dsl_binding[0].pImmutableSamplers = NULL;
16524 dsl_binding[1].binding = 0;
16525 dsl_binding[1].descriptorCount = 1;
16526 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16527 dsl_binding[1].descriptorCount = 1;
16528 dsl_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
16529 dsl_binding[1].pImmutableSamplers = NULL;
16530 dsl_binding[2].binding = 1; // Duplicate binding should cause error
16531 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16532 dsl_binding[2].descriptorCount = 1;
16533 dsl_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
16534 dsl_binding[2].pImmutableSamplers = NULL;
16535
16536 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
16537 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
16538 ds_layout_ci.pNext = NULL;
16539 ds_layout_ci.bindingCount = NUM_BINDINGS;
16540 ds_layout_ci.pBindings = dsl_binding;
16541 VkDescriptorSetLayout ds_layout;
16542 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02345);
16543 vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
16544 m_errorMonitor->VerifyFound();
16545}
16546
Mike Weiblen9a0f55d2016-10-31 22:35:00 -060016547TEST_F(VkLayerTest, ViewportAndScissorBoundsChecking) {
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060016548 TEST_DESCRIPTION("Verify errors are detected on misuse of SetViewport and SetScissor.");
16549
16550 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060016551
16552 BeginCommandBuffer();
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060016553
Mike Weiblen9a0f55d2016-10-31 22:35:00 -060016554 const VkPhysicalDeviceLimits &limits = m_device->props.limits;
16555
16556 {
16557 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01448);
16558 VkViewport viewport = {0, 0, static_cast<float>(limits.maxViewportDimensions[0] + 1), 16, 0, 1};
16559 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
16560 m_errorMonitor->VerifyFound();
16561 }
16562
16563 {
16564 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01449);
16565 VkViewport viewport = {0, 0, 16, static_cast<float>(limits.maxViewportDimensions[1] + 1), 0, 1};
16566 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
16567 m_errorMonitor->VerifyFound();
16568 }
16569
16570 {
16571 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01450);
16572 VkViewport viewport = {limits.viewportBoundsRange[0] - 1, 0, 16, 16, 0, 1};
16573 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
16574 m_errorMonitor->VerifyFound();
16575 }
16576
16577 {
16578 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01450);
16579 VkViewport viewport = {0, limits.viewportBoundsRange[0] - 1, 16, 16, 0, 1};
16580 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
16581 m_errorMonitor->VerifyFound();
16582 }
16583
16584 {
16585 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01451);
16586 VkViewport viewport = {limits.viewportBoundsRange[1], 0, 16, 16, 0, 1};
16587 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
16588 m_errorMonitor->VerifyFound();
16589 }
16590
16591 {
16592 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01452);
16593 VkViewport viewport = {0, limits.viewportBoundsRange[1], 16, 16, 0, 1};
16594 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
16595 m_errorMonitor->VerifyFound();
16596 }
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060016597
16598 {
16599 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01489);
16600 VkRect2D scissor = {{-1, 0}, {16, 16}};
16601 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
16602 m_errorMonitor->VerifyFound();
16603 }
16604
16605 {
16606 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01489);
16607 VkRect2D scissor = {{0, -2}, {16, 16}};
16608 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
16609 m_errorMonitor->VerifyFound();
16610 }
16611
16612 {
16613 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01490);
16614 VkRect2D scissor = {{100, 100}, {INT_MAX, 16}};
16615 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
16616 m_errorMonitor->VerifyFound();
16617 }
16618
16619 {
16620 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01491);
16621 VkRect2D scissor = {{100, 100}, {16, INT_MAX}};
16622 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
16623 m_errorMonitor->VerifyFound();
16624 }
16625
16626 EndCommandBuffer();
16627}
16628
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016629// This is a positive test. No failures are expected.
16630TEST_F(VkPositiveLayerTest, EmptyDescriptorUpdateTest) {
16631 TEST_DESCRIPTION("Update last descriptor in a set that includes an empty binding");
16632 VkResult err;
16633
16634 ASSERT_NO_FATAL_FAILURE(InitState());
16635 m_errorMonitor->ExpectSuccess();
16636 VkDescriptorPoolSize ds_type_count = {};
16637 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16638 ds_type_count.descriptorCount = 2;
16639
16640 VkDescriptorPoolCreateInfo ds_pool_ci = {};
16641 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
16642 ds_pool_ci.pNext = NULL;
16643 ds_pool_ci.maxSets = 1;
16644 ds_pool_ci.poolSizeCount = 1;
16645 ds_pool_ci.pPoolSizes = &ds_type_count;
16646
16647 VkDescriptorPool ds_pool;
16648 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
16649 ASSERT_VK_SUCCESS(err);
16650
16651 // Create layout with two uniform buffer descriptors w/ empty binding between them
16652 static const uint32_t NUM_BINDINGS = 3;
16653 VkDescriptorSetLayoutBinding dsl_binding[NUM_BINDINGS] = {};
16654 dsl_binding[0].binding = 0;
16655 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16656 dsl_binding[0].descriptorCount = 1;
16657 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
16658 dsl_binding[0].pImmutableSamplers = NULL;
16659 dsl_binding[1].binding = 1;
16660 dsl_binding[1].descriptorCount = 0; // empty binding
16661 dsl_binding[2].binding = 2;
16662 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16663 dsl_binding[2].descriptorCount = 1;
16664 dsl_binding[2].stageFlags = VK_SHADER_STAGE_ALL;
16665 dsl_binding[2].pImmutableSamplers = NULL;
16666
16667 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
16668 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
16669 ds_layout_ci.pNext = NULL;
16670 ds_layout_ci.bindingCount = NUM_BINDINGS;
16671 ds_layout_ci.pBindings = dsl_binding;
16672 VkDescriptorSetLayout ds_layout;
16673 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
16674 ASSERT_VK_SUCCESS(err);
16675
16676 VkDescriptorSet descriptor_set = {};
16677 VkDescriptorSetAllocateInfo alloc_info = {};
16678 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
16679 alloc_info.descriptorSetCount = 1;
16680 alloc_info.descriptorPool = ds_pool;
16681 alloc_info.pSetLayouts = &ds_layout;
16682 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
16683 ASSERT_VK_SUCCESS(err);
16684
16685 // Create a buffer to be used for update
16686 VkBufferCreateInfo buff_ci = {};
16687 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
16688 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
16689 buff_ci.size = 256;
16690 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
16691 VkBuffer buffer;
16692 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
16693 ASSERT_VK_SUCCESS(err);
16694 // Have to bind memory to buffer before descriptor update
16695 VkMemoryAllocateInfo mem_alloc = {};
16696 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16697 mem_alloc.pNext = NULL;
16698 mem_alloc.allocationSize = 512; // one allocation for both buffers
16699 mem_alloc.memoryTypeIndex = 0;
16700
16701 VkMemoryRequirements mem_reqs;
16702 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
16703 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
16704 if (!pass) {
16705 vkDestroyBuffer(m_device->device(), buffer, NULL);
16706 return;
16707 }
16708
16709 VkDeviceMemory mem;
16710 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
16711 ASSERT_VK_SUCCESS(err);
16712 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
16713 ASSERT_VK_SUCCESS(err);
16714
16715 // Only update the descriptor at binding 2
16716 VkDescriptorBufferInfo buff_info = {};
16717 buff_info.buffer = buffer;
16718 buff_info.offset = 0;
16719 buff_info.range = VK_WHOLE_SIZE;
16720 VkWriteDescriptorSet descriptor_write = {};
16721 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
16722 descriptor_write.dstBinding = 2;
16723 descriptor_write.descriptorCount = 1;
16724 descriptor_write.pTexelBufferView = nullptr;
16725 descriptor_write.pBufferInfo = &buff_info;
16726 descriptor_write.pImageInfo = nullptr;
16727 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16728 descriptor_write.dstSet = descriptor_set;
16729
16730 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
16731
16732 m_errorMonitor->VerifyNotFound();
16733 // Cleanup
16734 vkFreeMemory(m_device->device(), mem, NULL);
16735 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
16736 vkDestroyBuffer(m_device->device(), buffer, NULL);
16737 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
16738}
16739
16740// This is a positive test. No failures are expected.
16741TEST_F(VkPositiveLayerTest, TestAliasedMemoryTracking) {
16742 VkResult err;
16743 bool pass;
16744
16745 TEST_DESCRIPTION("Create a buffer, allocate memory, bind memory, destroy "
16746 "the buffer, create an image, and bind the same memory to "
16747 "it");
16748
16749 m_errorMonitor->ExpectSuccess();
16750
16751 ASSERT_NO_FATAL_FAILURE(InitState());
16752
16753 VkBuffer buffer;
16754 VkImage image;
16755 VkDeviceMemory mem;
16756 VkMemoryRequirements mem_reqs;
16757
16758 VkBufferCreateInfo buf_info = {};
16759 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
16760 buf_info.pNext = NULL;
16761 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
16762 buf_info.size = 256;
16763 buf_info.queueFamilyIndexCount = 0;
16764 buf_info.pQueueFamilyIndices = NULL;
16765 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
16766 buf_info.flags = 0;
16767 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
16768 ASSERT_VK_SUCCESS(err);
16769
16770 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
16771
16772 VkMemoryAllocateInfo alloc_info = {};
16773 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16774 alloc_info.pNext = NULL;
16775 alloc_info.memoryTypeIndex = 0;
16776
16777 // Ensure memory is big enough for both bindings
16778 alloc_info.allocationSize = 0x10000;
16779
16780 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
16781 if (!pass) {
16782 vkDestroyBuffer(m_device->device(), buffer, NULL);
16783 return;
16784 }
16785
16786 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
16787 ASSERT_VK_SUCCESS(err);
16788
16789 uint8_t *pData;
16790 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
16791 ASSERT_VK_SUCCESS(err);
16792
16793 memset(pData, 0xCADECADE, static_cast<size_t>(mem_reqs.size));
16794
16795 vkUnmapMemory(m_device->device(), mem);
16796
16797 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
16798 ASSERT_VK_SUCCESS(err);
16799
16800 // NOW, destroy the buffer. Obviously, the resource no longer occupies this
16801 // memory. In fact, it was never used by the GPU.
16802 // Just be be sure, wait for idle.
16803 vkDestroyBuffer(m_device->device(), buffer, NULL);
16804 vkDeviceWaitIdle(m_device->device());
16805
16806 VkImageCreateInfo image_create_info = {};
16807 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16808 image_create_info.pNext = NULL;
16809 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16810 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
16811 image_create_info.extent.width = 64;
16812 image_create_info.extent.height = 64;
16813 image_create_info.extent.depth = 1;
16814 image_create_info.mipLevels = 1;
16815 image_create_info.arrayLayers = 1;
16816 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16817 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
16818 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
16819 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
16820 image_create_info.queueFamilyIndexCount = 0;
16821 image_create_info.pQueueFamilyIndices = NULL;
16822 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
16823 image_create_info.flags = 0;
16824
16825 VkMemoryAllocateInfo mem_alloc = {};
16826 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16827 mem_alloc.pNext = NULL;
16828 mem_alloc.allocationSize = 0;
16829 mem_alloc.memoryTypeIndex = 0;
16830
16831 /* Create a mappable image. It will be the texture if linear images are ok
16832 * to be textures or it will be the staging image if they are not.
16833 */
16834 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
16835 ASSERT_VK_SUCCESS(err);
16836
16837 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
16838
16839 mem_alloc.allocationSize = mem_reqs.size;
16840
16841 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
16842 if (!pass) {
16843 vkDestroyImage(m_device->device(), image, NULL);
16844 return;
16845 }
16846
16847 // VALIDATION FAILURE:
16848 err = vkBindImageMemory(m_device->device(), image, mem, 0);
16849 ASSERT_VK_SUCCESS(err);
16850
16851 m_errorMonitor->VerifyNotFound();
16852
16853 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016854 vkDestroyImage(m_device->device(), image, NULL);
16855}
16856
Tobin Ehlis953e8392016-11-17 10:54:13 -070016857TEST_F(VkPositiveLayerTest, DynamicOffsetWithInactiveBinding) {
16858 // Create a descriptorSet w/ dynamic descriptors where 1 binding is inactive
16859 // We previously had a bug where dynamic offset of inactive bindings was still being used
16860 VkResult err;
16861 m_errorMonitor->ExpectSuccess();
16862
16863 ASSERT_NO_FATAL_FAILURE(InitState());
16864 ASSERT_NO_FATAL_FAILURE(InitViewport());
16865 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
16866
16867 VkDescriptorPoolSize ds_type_count = {};
16868 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
16869 ds_type_count.descriptorCount = 3;
16870
16871 VkDescriptorPoolCreateInfo ds_pool_ci = {};
16872 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
16873 ds_pool_ci.pNext = NULL;
16874 ds_pool_ci.maxSets = 1;
16875 ds_pool_ci.poolSizeCount = 1;
16876 ds_pool_ci.pPoolSizes = &ds_type_count;
16877
16878 VkDescriptorPool ds_pool;
16879 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
16880 ASSERT_VK_SUCCESS(err);
16881
16882 const uint32_t BINDING_COUNT = 3;
16883 VkDescriptorSetLayoutBinding dsl_binding[BINDING_COUNT] = {};
Tobin Ehlis0050fba2016-11-30 10:22:02 -070016884 dsl_binding[0].binding = 2;
Tobin Ehlis953e8392016-11-17 10:54:13 -070016885 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
16886 dsl_binding[0].descriptorCount = 1;
16887 dsl_binding[0].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
16888 dsl_binding[0].pImmutableSamplers = NULL;
Tobin Ehlis0050fba2016-11-30 10:22:02 -070016889 dsl_binding[1].binding = 0;
Tobin Ehlis953e8392016-11-17 10:54:13 -070016890 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
16891 dsl_binding[1].descriptorCount = 1;
16892 dsl_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
16893 dsl_binding[1].pImmutableSamplers = NULL;
Tobin Ehlis0050fba2016-11-30 10:22:02 -070016894 dsl_binding[2].binding = 1;
Tobin Ehlis953e8392016-11-17 10:54:13 -070016895 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
16896 dsl_binding[2].descriptorCount = 1;
16897 dsl_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
16898 dsl_binding[2].pImmutableSamplers = NULL;
16899
16900 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
16901 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
16902 ds_layout_ci.pNext = NULL;
16903 ds_layout_ci.bindingCount = BINDING_COUNT;
16904 ds_layout_ci.pBindings = dsl_binding;
16905 VkDescriptorSetLayout ds_layout;
16906 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
16907 ASSERT_VK_SUCCESS(err);
16908
16909 VkDescriptorSet descriptor_set;
16910 VkDescriptorSetAllocateInfo alloc_info = {};
16911 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
16912 alloc_info.descriptorSetCount = 1;
16913 alloc_info.descriptorPool = ds_pool;
16914 alloc_info.pSetLayouts = &ds_layout;
16915 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
16916 ASSERT_VK_SUCCESS(err);
16917
16918 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
16919 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
16920 pipeline_layout_ci.pNext = NULL;
16921 pipeline_layout_ci.setLayoutCount = 1;
16922 pipeline_layout_ci.pSetLayouts = &ds_layout;
16923
16924 VkPipelineLayout pipeline_layout;
16925 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
16926 ASSERT_VK_SUCCESS(err);
16927
16928 // Create two buffers to update the descriptors with
16929 // The first will be 2k and used for bindings 0 & 1, the second is 1k for binding 2
16930 uint32_t qfi = 0;
16931 VkBufferCreateInfo buffCI = {};
16932 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
16933 buffCI.size = 2048;
16934 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
16935 buffCI.queueFamilyIndexCount = 1;
16936 buffCI.pQueueFamilyIndices = &qfi;
16937
16938 VkBuffer dyub1;
16939 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub1);
16940 ASSERT_VK_SUCCESS(err);
16941 // buffer2
16942 buffCI.size = 1024;
16943 VkBuffer dyub2;
16944 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub2);
16945 ASSERT_VK_SUCCESS(err);
16946 // Allocate memory and bind to buffers
16947 VkMemoryAllocateInfo mem_alloc[2] = {};
16948 mem_alloc[0].sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16949 mem_alloc[0].pNext = NULL;
16950 mem_alloc[0].memoryTypeIndex = 0;
16951 mem_alloc[1].sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16952 mem_alloc[1].pNext = NULL;
16953 mem_alloc[1].memoryTypeIndex = 0;
16954
16955 VkMemoryRequirements mem_reqs1;
16956 vkGetBufferMemoryRequirements(m_device->device(), dyub1, &mem_reqs1);
16957 VkMemoryRequirements mem_reqs2;
16958 vkGetBufferMemoryRequirements(m_device->device(), dyub2, &mem_reqs2);
16959 mem_alloc[0].allocationSize = mem_reqs1.size;
16960 bool pass = m_device->phy().set_memory_type(mem_reqs1.memoryTypeBits, &mem_alloc[0], 0);
16961 mem_alloc[1].allocationSize = mem_reqs2.size;
16962 pass &= m_device->phy().set_memory_type(mem_reqs2.memoryTypeBits, &mem_alloc[1], 0);
16963 if (!pass) {
16964 vkDestroyBuffer(m_device->device(), dyub1, NULL);
16965 vkDestroyBuffer(m_device->device(), dyub2, NULL);
16966 return;
16967 }
16968
16969 VkDeviceMemory mem1;
16970 err = vkAllocateMemory(m_device->device(), &mem_alloc[0], NULL, &mem1);
16971 ASSERT_VK_SUCCESS(err);
16972 err = vkBindBufferMemory(m_device->device(), dyub1, mem1, 0);
16973 ASSERT_VK_SUCCESS(err);
16974 VkDeviceMemory mem2;
16975 err = vkAllocateMemory(m_device->device(), &mem_alloc[1], NULL, &mem2);
16976 ASSERT_VK_SUCCESS(err);
16977 err = vkBindBufferMemory(m_device->device(), dyub2, mem2, 0);
16978 ASSERT_VK_SUCCESS(err);
16979 // Update descriptors
16980 VkDescriptorBufferInfo buff_info[BINDING_COUNT] = {};
16981 buff_info[0].buffer = dyub1;
16982 buff_info[0].offset = 0;
16983 buff_info[0].range = 256;
16984 buff_info[1].buffer = dyub1;
16985 buff_info[1].offset = 256;
16986 buff_info[1].range = 512;
16987 buff_info[2].buffer = dyub2;
16988 buff_info[2].offset = 0;
16989 buff_info[2].range = 512;
16990
16991 VkWriteDescriptorSet descriptor_write;
16992 memset(&descriptor_write, 0, sizeof(descriptor_write));
16993 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
16994 descriptor_write.dstSet = descriptor_set;
16995 descriptor_write.dstBinding = 0;
16996 descriptor_write.descriptorCount = BINDING_COUNT;
16997 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
16998 descriptor_write.pBufferInfo = buff_info;
16999
17000 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
17001
17002 BeginCommandBuffer();
17003
17004 // Create PSO to be used for draw-time errors below
17005 char const *vsSource = "#version 450\n"
17006 "\n"
17007 "out gl_PerVertex { \n"
17008 " vec4 gl_Position;\n"
17009 "};\n"
17010 "void main(){\n"
17011 " gl_Position = vec4(1);\n"
17012 "}\n";
17013 char const *fsSource = "#version 450\n"
17014 "\n"
17015 "layout(location=0) out vec4 x;\n"
17016 "layout(set=0) layout(binding=0) uniform foo1 { int x; int y; } bar1;\n"
17017 "layout(set=0) layout(binding=2) uniform foo2 { int x; int y; } bar2;\n"
17018 "void main(){\n"
17019 " x = vec4(bar1.y) + vec4(bar2.y);\n"
17020 "}\n";
17021 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
17022 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
17023 VkPipelineObj pipe(m_device);
17024 pipe.SetViewport(m_viewports);
17025 pipe.SetScissor(m_scissors);
17026 pipe.AddShader(&vs);
17027 pipe.AddShader(&fs);
17028 pipe.AddColorAttachment();
17029 pipe.CreateVKPipeline(pipeline_layout, renderPass());
17030
17031 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
17032 // This update should succeed, but offset of inactive binding 1 oversteps binding 2 buffer size
17033 // we used to have a bug in this case.
17034 uint32_t dyn_off[BINDING_COUNT] = {0, 1024, 256};
17035 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
17036 &descriptor_set, BINDING_COUNT, dyn_off);
17037 Draw(1, 0, 0, 0);
17038 m_errorMonitor->VerifyNotFound();
17039
17040 vkDestroyBuffer(m_device->device(), dyub1, NULL);
17041 vkDestroyBuffer(m_device->device(), dyub2, NULL);
17042 vkFreeMemory(m_device->device(), mem1, NULL);
17043 vkFreeMemory(m_device->device(), mem2, NULL);
17044
17045 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
17046 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
17047 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
17048}
17049
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017050TEST_F(VkPositiveLayerTest, NonCoherentMemoryMapping) {
17051
17052 TEST_DESCRIPTION("Ensure that validations handling of non-coherent memory "
17053 "mapping while using VK_WHOLE_SIZE does not cause access "
17054 "violations");
17055 VkResult err;
17056 uint8_t *pData;
17057 ASSERT_NO_FATAL_FAILURE(InitState());
17058
17059 VkDeviceMemory mem;
17060 VkMemoryRequirements mem_reqs;
17061 mem_reqs.memoryTypeBits = 0xFFFFFFFF;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017062 const VkDeviceSize atom_size = m_device->props.limits.nonCoherentAtomSize;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017063 VkMemoryAllocateInfo alloc_info = {};
17064 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17065 alloc_info.pNext = NULL;
17066 alloc_info.memoryTypeIndex = 0;
17067
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017068 static const VkDeviceSize allocation_size = 32 * atom_size;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017069 alloc_info.allocationSize = allocation_size;
17070
17071 // Find a memory configurations WITHOUT a COHERENT bit, otherwise exit
17072 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT,
17073 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
17074 if (!pass) {
17075 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info,
17076 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT,
17077 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
17078 if (!pass) {
17079 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info,
17080 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT |
17081 VK_MEMORY_PROPERTY_HOST_CACHED_BIT,
17082 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
17083 if (!pass) {
17084 return;
17085 }
17086 }
17087 }
17088
17089 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
17090 ASSERT_VK_SUCCESS(err);
17091
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017092 // Map/Flush/Invalidate using WHOLE_SIZE and zero offsets and entire mapped range
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017093 m_errorMonitor->ExpectSuccess();
17094 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, (void **)&pData);
17095 ASSERT_VK_SUCCESS(err);
17096 VkMappedMemoryRange mmr = {};
17097 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
17098 mmr.memory = mem;
17099 mmr.offset = 0;
17100 mmr.size = VK_WHOLE_SIZE;
17101 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
17102 ASSERT_VK_SUCCESS(err);
17103 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
17104 ASSERT_VK_SUCCESS(err);
17105 m_errorMonitor->VerifyNotFound();
17106 vkUnmapMemory(m_device->device(), mem);
17107
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017108 // Map/Flush/Invalidate using WHOLE_SIZE and an offset and entire mapped range
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017109 m_errorMonitor->ExpectSuccess();
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017110 err = vkMapMemory(m_device->device(), mem, 5 * atom_size, VK_WHOLE_SIZE, 0, (void **)&pData);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017111 ASSERT_VK_SUCCESS(err);
17112 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
17113 mmr.memory = mem;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017114 mmr.offset = 6 * atom_size;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017115 mmr.size = VK_WHOLE_SIZE;
17116 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
17117 ASSERT_VK_SUCCESS(err);
17118 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
17119 ASSERT_VK_SUCCESS(err);
17120 m_errorMonitor->VerifyNotFound();
17121 vkUnmapMemory(m_device->device(), mem);
17122
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017123 // Map with offset and size
17124 // Flush/Invalidate subrange of mapped area with offset and size
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017125 m_errorMonitor->ExpectSuccess();
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017126 err = vkMapMemory(m_device->device(), mem, 3 * atom_size, 9 * atom_size, 0, (void **)&pData);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017127 ASSERT_VK_SUCCESS(err);
17128 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
17129 mmr.memory = mem;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017130 mmr.offset = 4 * atom_size;
17131 mmr.size = 2 * atom_size;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017132 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
17133 ASSERT_VK_SUCCESS(err);
17134 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
17135 ASSERT_VK_SUCCESS(err);
17136 m_errorMonitor->VerifyNotFound();
17137 vkUnmapMemory(m_device->device(), mem);
17138
17139 // Map without offset and flush WHOLE_SIZE with two separate offsets
17140 m_errorMonitor->ExpectSuccess();
17141 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, (void **)&pData);
17142 ASSERT_VK_SUCCESS(err);
17143 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
17144 mmr.memory = mem;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017145 mmr.offset = allocation_size - (4 * atom_size);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017146 mmr.size = VK_WHOLE_SIZE;
17147 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
17148 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017149 mmr.offset = allocation_size - (6 * atom_size);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017150 mmr.size = VK_WHOLE_SIZE;
17151 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
17152 ASSERT_VK_SUCCESS(err);
17153 m_errorMonitor->VerifyNotFound();
17154 vkUnmapMemory(m_device->device(), mem);
17155
17156 vkFreeMemory(m_device->device(), mem, NULL);
17157}
17158
17159// This is a positive test. We used to expect error in this case but spec now allows it
17160TEST_F(VkPositiveLayerTest, ResetUnsignaledFence) {
17161 m_errorMonitor->ExpectSuccess();
17162 vk_testing::Fence testFence;
17163 VkFenceCreateInfo fenceInfo = {};
17164 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
17165 fenceInfo.pNext = NULL;
17166
17167 ASSERT_NO_FATAL_FAILURE(InitState());
17168 testFence.init(*m_device, fenceInfo);
17169 VkFence fences[1] = { testFence.handle() };
17170 VkResult result = vkResetFences(m_device->device(), 1, fences);
17171 ASSERT_VK_SUCCESS(result);
17172
17173 m_errorMonitor->VerifyNotFound();
17174}
17175
17176TEST_F(VkPositiveLayerTest, CommandBufferSimultaneousUseSync) {
17177 m_errorMonitor->ExpectSuccess();
17178
17179 ASSERT_NO_FATAL_FAILURE(InitState());
17180 VkResult err;
17181
17182 // Record (empty!) command buffer that can be submitted multiple times
17183 // simultaneously.
17184 VkCommandBufferBeginInfo cbbi = { VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr,
17185 VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT, nullptr };
17186 m_commandBuffer->BeginCommandBuffer(&cbbi);
17187 m_commandBuffer->EndCommandBuffer();
17188
17189 VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
17190 VkFence fence;
17191 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
17192 ASSERT_VK_SUCCESS(err);
17193
17194 VkSemaphoreCreateInfo sci = { VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0 };
17195 VkSemaphore s1, s2;
17196 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s1);
17197 ASSERT_VK_SUCCESS(err);
17198 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s2);
17199 ASSERT_VK_SUCCESS(err);
17200
17201 // Submit CB once signaling s1, with fence so we can roll forward to its retirement.
17202 VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 1, &m_commandBuffer->handle(), 1, &s1 };
17203 err = vkQueueSubmit(m_device->m_queue, 1, &si, fence);
17204 ASSERT_VK_SUCCESS(err);
17205
17206 // Submit CB again, signaling s2.
17207 si.pSignalSemaphores = &s2;
17208 err = vkQueueSubmit(m_device->m_queue, 1, &si, VK_NULL_HANDLE);
17209 ASSERT_VK_SUCCESS(err);
17210
17211 // Wait for fence.
17212 err = vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
17213 ASSERT_VK_SUCCESS(err);
17214
17215 // CB is still in flight from second submission, but semaphore s1 is no
17216 // longer in flight. delete it.
17217 vkDestroySemaphore(m_device->device(), s1, nullptr);
17218
17219 m_errorMonitor->VerifyNotFound();
17220
17221 // Force device idle and clean up remaining objects
17222 vkDeviceWaitIdle(m_device->device());
17223 vkDestroySemaphore(m_device->device(), s2, nullptr);
17224 vkDestroyFence(m_device->device(), fence, nullptr);
17225}
17226
17227TEST_F(VkPositiveLayerTest, FenceCreateSignaledWaitHandling) {
17228 m_errorMonitor->ExpectSuccess();
17229
17230 ASSERT_NO_FATAL_FAILURE(InitState());
17231 VkResult err;
17232
17233 // A fence created signaled
17234 VkFenceCreateInfo fci1 = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, VK_FENCE_CREATE_SIGNALED_BIT };
17235 VkFence f1;
17236 err = vkCreateFence(m_device->device(), &fci1, nullptr, &f1);
17237 ASSERT_VK_SUCCESS(err);
17238
17239 // A fence created not
17240 VkFenceCreateInfo fci2 = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
17241 VkFence f2;
17242 err = vkCreateFence(m_device->device(), &fci2, nullptr, &f2);
17243 ASSERT_VK_SUCCESS(err);
17244
17245 // Submit the unsignaled fence
17246 VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 0, nullptr, 0, nullptr };
17247 err = vkQueueSubmit(m_device->m_queue, 1, &si, f2);
17248
17249 // Wait on both fences, with signaled first.
17250 VkFence fences[] = { f1, f2 };
17251 vkWaitForFences(m_device->device(), 2, fences, VK_TRUE, UINT64_MAX);
17252
17253 // Should have both retired!
17254 vkDestroyFence(m_device->device(), f1, nullptr);
17255 vkDestroyFence(m_device->device(), f2, nullptr);
17256
17257 m_errorMonitor->VerifyNotFound();
17258}
17259
17260TEST_F(VkPositiveLayerTest, ValidUsage) {
17261 TEST_DESCRIPTION("Verify that creating an image view from an image with valid usage "
17262 "doesn't generate validation errors");
17263
17264 ASSERT_NO_FATAL_FAILURE(InitState());
17265
17266 m_errorMonitor->ExpectSuccess();
17267 // Verify that we can create a view with usage INPUT_ATTACHMENT
17268 VkImageObj image(m_device);
17269 image.init(128, 128, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
17270 ASSERT_TRUE(image.initialized());
17271 VkImageView imageView;
17272 VkImageViewCreateInfo ivci = {};
17273 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
17274 ivci.image = image.handle();
17275 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
17276 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
17277 ivci.subresourceRange.layerCount = 1;
17278 ivci.subresourceRange.baseMipLevel = 0;
17279 ivci.subresourceRange.levelCount = 1;
17280 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
17281
17282 vkCreateImageView(m_device->device(), &ivci, NULL, &imageView);
17283 m_errorMonitor->VerifyNotFound();
17284 vkDestroyImageView(m_device->device(), imageView, NULL);
17285}
17286
17287// This is a positive test. No failures are expected.
17288TEST_F(VkPositiveLayerTest, BindSparse) {
17289 TEST_DESCRIPTION("Bind 2 memory ranges to one image using vkQueueBindSparse, destroy the image"
17290 "and then free the memory");
17291
17292 ASSERT_NO_FATAL_FAILURE(InitState());
17293
17294 auto index = m_device->graphics_queue_node_index_;
17295 if (!(m_device->queue_props[index].queueFlags & VK_QUEUE_SPARSE_BINDING_BIT))
17296 return;
17297
17298 m_errorMonitor->ExpectSuccess();
17299
17300 VkImage image;
17301 VkImageCreateInfo image_create_info = {};
17302 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
17303 image_create_info.pNext = NULL;
17304 image_create_info.imageType = VK_IMAGE_TYPE_2D;
17305 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
17306 image_create_info.extent.width = 64;
17307 image_create_info.extent.height = 64;
17308 image_create_info.extent.depth = 1;
17309 image_create_info.mipLevels = 1;
17310 image_create_info.arrayLayers = 1;
17311 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
17312 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
17313 image_create_info.usage = VK_IMAGE_USAGE_STORAGE_BIT;
17314 image_create_info.flags = VK_IMAGE_CREATE_SPARSE_BINDING_BIT;
17315 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
17316 ASSERT_VK_SUCCESS(err);
17317
17318 VkMemoryRequirements memory_reqs;
17319 VkDeviceMemory memory_one, memory_two;
17320 bool pass;
17321 VkMemoryAllocateInfo memory_info = {};
17322 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17323 memory_info.pNext = NULL;
17324 memory_info.allocationSize = 0;
17325 memory_info.memoryTypeIndex = 0;
17326 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
17327 // Find an image big enough to allow sparse mapping of 2 memory regions
17328 // Increase the image size until it is at least twice the
17329 // size of the required alignment, to ensure we can bind both
17330 // allocated memory blocks to the image on aligned offsets.
17331 while (memory_reqs.size < (memory_reqs.alignment * 2)) {
17332 vkDestroyImage(m_device->device(), image, nullptr);
17333 image_create_info.extent.width *= 2;
17334 image_create_info.extent.height *= 2;
17335 err = vkCreateImage(m_device->device(), &image_create_info, nullptr, &image);
17336 ASSERT_VK_SUCCESS(err);
17337 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
17338 }
17339 // Allocate 2 memory regions of minimum alignment size, bind one at 0, the other
17340 // at the end of the first
17341 memory_info.allocationSize = memory_reqs.alignment;
17342 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
17343 ASSERT_TRUE(pass);
17344 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &memory_one);
17345 ASSERT_VK_SUCCESS(err);
17346 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &memory_two);
17347 ASSERT_VK_SUCCESS(err);
17348 VkSparseMemoryBind binds[2];
17349 binds[0].flags = 0;
17350 binds[0].memory = memory_one;
17351 binds[0].memoryOffset = 0;
17352 binds[0].resourceOffset = 0;
17353 binds[0].size = memory_info.allocationSize;
17354 binds[1].flags = 0;
17355 binds[1].memory = memory_two;
17356 binds[1].memoryOffset = 0;
17357 binds[1].resourceOffset = memory_info.allocationSize;
17358 binds[1].size = memory_info.allocationSize;
17359
17360 VkSparseImageOpaqueMemoryBindInfo opaqueBindInfo;
17361 opaqueBindInfo.image = image;
17362 opaqueBindInfo.bindCount = 2;
17363 opaqueBindInfo.pBinds = binds;
17364
17365 VkFence fence = VK_NULL_HANDLE;
17366 VkBindSparseInfo bindSparseInfo = {};
17367 bindSparseInfo.sType = VK_STRUCTURE_TYPE_BIND_SPARSE_INFO;
17368 bindSparseInfo.imageOpaqueBindCount = 1;
17369 bindSparseInfo.pImageOpaqueBinds = &opaqueBindInfo;
17370
17371 vkQueueBindSparse(m_device->m_queue, 1, &bindSparseInfo, fence);
17372 vkQueueWaitIdle(m_device->m_queue);
17373 vkDestroyImage(m_device->device(), image, NULL);
17374 vkFreeMemory(m_device->device(), memory_one, NULL);
17375 vkFreeMemory(m_device->device(), memory_two, NULL);
17376 m_errorMonitor->VerifyNotFound();
17377}
17378
17379TEST_F(VkPositiveLayerTest, RenderPassInitialLayoutUndefined) {
17380 TEST_DESCRIPTION("Ensure that CmdBeginRenderPass with an attachment's "
17381 "initialLayout of VK_IMAGE_LAYOUT_UNDEFINED works when "
17382 "the command buffer has prior knowledge of that "
17383 "attachment's layout.");
17384
17385 m_errorMonitor->ExpectSuccess();
17386
17387 ASSERT_NO_FATAL_FAILURE(InitState());
17388
17389 // A renderpass with one color attachment.
17390 VkAttachmentDescription attachment = { 0,
17391 VK_FORMAT_R8G8B8A8_UNORM,
17392 VK_SAMPLE_COUNT_1_BIT,
17393 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
17394 VK_ATTACHMENT_STORE_OP_STORE,
17395 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
17396 VK_ATTACHMENT_STORE_OP_DONT_CARE,
17397 VK_IMAGE_LAYOUT_UNDEFINED,
17398 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
17399
17400 VkAttachmentReference att_ref = { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
17401
17402 VkSubpassDescription subpass = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr };
17403
17404 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr };
17405
17406 VkRenderPass rp;
17407 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
17408 ASSERT_VK_SUCCESS(err);
17409
17410 // A compatible framebuffer.
17411 VkImageObj image(m_device);
17412 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
17413 ASSERT_TRUE(image.initialized());
17414
17415 VkImageViewCreateInfo ivci = {
17416 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
17417 nullptr,
17418 0,
17419 image.handle(),
17420 VK_IMAGE_VIEW_TYPE_2D,
17421 VK_FORMAT_R8G8B8A8_UNORM,
17422 { VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
17423 VK_COMPONENT_SWIZZLE_IDENTITY },
17424 { VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 },
17425 };
17426 VkImageView view;
17427 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
17428 ASSERT_VK_SUCCESS(err);
17429
17430 VkFramebufferCreateInfo fci = { VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1 };
17431 VkFramebuffer fb;
17432 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
17433 ASSERT_VK_SUCCESS(err);
17434
17435 // Record a single command buffer which uses this renderpass twice. The
17436 // bug is triggered at the beginning of the second renderpass, when the
17437 // command buffer already has a layout recorded for the attachment.
17438 VkRenderPassBeginInfo rpbi = { VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb,{ { 0, 0 },{ 32, 32 } }, 0, nullptr };
17439 BeginCommandBuffer();
17440 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
17441 vkCmdEndRenderPass(m_commandBuffer->handle());
17442 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
17443
17444 m_errorMonitor->VerifyNotFound();
17445
17446 vkCmdEndRenderPass(m_commandBuffer->handle());
17447 EndCommandBuffer();
17448
17449 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
17450 vkDestroyRenderPass(m_device->device(), rp, nullptr);
17451 vkDestroyImageView(m_device->device(), view, nullptr);
17452}
17453
17454TEST_F(VkPositiveLayerTest, FramebufferBindingDestroyCommandPool) {
17455 TEST_DESCRIPTION("This test should pass. Create a Framebuffer and "
17456 "command buffer, bind them together, then destroy "
17457 "command pool and framebuffer and verify there are no "
17458 "errors.");
17459
17460 m_errorMonitor->ExpectSuccess();
17461
17462 ASSERT_NO_FATAL_FAILURE(InitState());
17463
17464 // A renderpass with one color attachment.
17465 VkAttachmentDescription attachment = { 0,
17466 VK_FORMAT_R8G8B8A8_UNORM,
17467 VK_SAMPLE_COUNT_1_BIT,
17468 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
17469 VK_ATTACHMENT_STORE_OP_STORE,
17470 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
17471 VK_ATTACHMENT_STORE_OP_DONT_CARE,
17472 VK_IMAGE_LAYOUT_UNDEFINED,
17473 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
17474
17475 VkAttachmentReference att_ref = { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
17476
17477 VkSubpassDescription subpass = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr };
17478
17479 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr };
17480
17481 VkRenderPass rp;
17482 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
17483 ASSERT_VK_SUCCESS(err);
17484
17485 // A compatible framebuffer.
17486 VkImageObj image(m_device);
17487 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
17488 ASSERT_TRUE(image.initialized());
17489
17490 VkImageViewCreateInfo ivci = {
17491 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
17492 nullptr,
17493 0,
17494 image.handle(),
17495 VK_IMAGE_VIEW_TYPE_2D,
17496 VK_FORMAT_R8G8B8A8_UNORM,
17497 { VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
17498 VK_COMPONENT_SWIZZLE_IDENTITY },
17499 { VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 },
17500 };
17501 VkImageView view;
17502 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
17503 ASSERT_VK_SUCCESS(err);
17504
17505 VkFramebufferCreateInfo fci = { VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1 };
17506 VkFramebuffer fb;
17507 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
17508 ASSERT_VK_SUCCESS(err);
17509
17510 // Explicitly create a command buffer to bind the FB to so that we can then
17511 // destroy the command pool in order to implicitly free command buffer
17512 VkCommandPool command_pool;
17513 VkCommandPoolCreateInfo pool_create_info{};
17514 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17515 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
17516 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17517 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
17518
17519 VkCommandBuffer command_buffer;
17520 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
17521 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17522 command_buffer_allocate_info.commandPool = command_pool;
17523 command_buffer_allocate_info.commandBufferCount = 1;
17524 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17525 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
17526
17527 // Begin our cmd buffer with renderpass using our framebuffer
17528 VkRenderPassBeginInfo rpbi = { VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb,{ { 0, 0 },{ 32, 32 } }, 0, nullptr };
17529 VkCommandBufferBeginInfo begin_info{};
17530 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17531 vkBeginCommandBuffer(command_buffer, &begin_info);
17532
17533 vkCmdBeginRenderPass(command_buffer, &rpbi, VK_SUBPASS_CONTENTS_INLINE);
17534 vkCmdEndRenderPass(command_buffer);
17535 vkEndCommandBuffer(command_buffer);
17536 vkDestroyImageView(m_device->device(), view, nullptr);
17537 // Destroy command pool to implicitly free command buffer
17538 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
17539 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
17540 vkDestroyRenderPass(m_device->device(), rp, nullptr);
17541 m_errorMonitor->VerifyNotFound();
17542}
17543
17544TEST_F(VkPositiveLayerTest, RenderPassSubpassZeroTransitionsApplied) {
17545 TEST_DESCRIPTION("Ensure that CmdBeginRenderPass applies the layout "
17546 "transitions for the first subpass");
17547
17548 m_errorMonitor->ExpectSuccess();
17549
17550 ASSERT_NO_FATAL_FAILURE(InitState());
17551
17552 // A renderpass with one color attachment.
17553 VkAttachmentDescription attachment = { 0,
17554 VK_FORMAT_R8G8B8A8_UNORM,
17555 VK_SAMPLE_COUNT_1_BIT,
17556 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
17557 VK_ATTACHMENT_STORE_OP_STORE,
17558 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
17559 VK_ATTACHMENT_STORE_OP_DONT_CARE,
17560 VK_IMAGE_LAYOUT_UNDEFINED,
17561 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
17562
17563 VkAttachmentReference att_ref = { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
17564
17565 VkSubpassDescription subpass = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr };
17566
17567 VkSubpassDependency dep = { 0,
17568 0,
17569 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
17570 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
17571 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
17572 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
17573 VK_DEPENDENCY_BY_REGION_BIT };
17574
17575 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 1, &dep };
17576
17577 VkResult err;
17578 VkRenderPass rp;
17579 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
17580 ASSERT_VK_SUCCESS(err);
17581
17582 // A compatible framebuffer.
17583 VkImageObj image(m_device);
17584 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
17585 ASSERT_TRUE(image.initialized());
17586
17587 VkImageViewCreateInfo ivci = {
17588 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
17589 nullptr,
17590 0,
17591 image.handle(),
17592 VK_IMAGE_VIEW_TYPE_2D,
17593 VK_FORMAT_R8G8B8A8_UNORM,
17594 { VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
17595 VK_COMPONENT_SWIZZLE_IDENTITY },
17596 { VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 },
17597 };
17598 VkImageView view;
17599 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
17600 ASSERT_VK_SUCCESS(err);
17601
17602 VkFramebufferCreateInfo fci = { VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1 };
17603 VkFramebuffer fb;
17604 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
17605 ASSERT_VK_SUCCESS(err);
17606
17607 // Record a single command buffer which issues a pipeline barrier w/
17608 // image memory barrier for the attachment. This detects the previously
17609 // missing tracking of the subpass layout by throwing a validation error
17610 // if it doesn't occur.
17611 VkRenderPassBeginInfo rpbi = { VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb,{ { 0, 0 },{ 32, 32 } }, 0, nullptr };
17612 BeginCommandBuffer();
17613 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
17614
17615 VkImageMemoryBarrier imb = { VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,
17616 nullptr,
17617 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
17618 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
17619 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
17620 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
17621 VK_QUEUE_FAMILY_IGNORED,
17622 VK_QUEUE_FAMILY_IGNORED,
17623 image.handle(),
17624 { VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 } };
17625 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
17626 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_DEPENDENCY_BY_REGION_BIT, 0, nullptr, 0, nullptr, 1,
17627 &imb);
17628
17629 vkCmdEndRenderPass(m_commandBuffer->handle());
17630 m_errorMonitor->VerifyNotFound();
17631 EndCommandBuffer();
17632
17633 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
17634 vkDestroyRenderPass(m_device->device(), rp, nullptr);
17635 vkDestroyImageView(m_device->device(), view, nullptr);
17636}
17637
17638TEST_F(VkPositiveLayerTest, DepthStencilLayoutTransitionForDepthOnlyImageview) {
17639 TEST_DESCRIPTION("Validate that when an imageView of a depth/stencil image "
17640 "is used as a depth/stencil framebuffer attachment, the "
17641 "aspectMask is ignored and both depth and stencil image "
17642 "subresources are used.");
17643
17644 VkFormatProperties format_properties;
17645 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_D32_SFLOAT_S8_UINT, &format_properties);
17646 if (!(format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)) {
17647 return;
17648 }
17649
17650 m_errorMonitor->ExpectSuccess();
17651
17652 ASSERT_NO_FATAL_FAILURE(InitState());
17653
17654 VkAttachmentDescription attachment = { 0,
17655 VK_FORMAT_D32_SFLOAT_S8_UINT,
17656 VK_SAMPLE_COUNT_1_BIT,
17657 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
17658 VK_ATTACHMENT_STORE_OP_STORE,
17659 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
17660 VK_ATTACHMENT_STORE_OP_DONT_CARE,
17661 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
17662 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL };
17663
17664 VkAttachmentReference att_ref = { 0, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL };
17665
17666 VkSubpassDescription subpass = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, &att_ref, 0, nullptr };
17667
17668 VkSubpassDependency dep = { 0,
17669 0,
17670 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
17671 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
17672 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
17673 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
17674 VK_DEPENDENCY_BY_REGION_BIT};
17675
17676 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 1, &dep };
17677
17678 VkResult err;
17679 VkRenderPass rp;
17680 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
17681 ASSERT_VK_SUCCESS(err);
17682
17683 VkImageObj image(m_device);
17684 image.init_no_layout(32, 32, VK_FORMAT_D32_SFLOAT_S8_UINT,
17685 0x26, // usage
17686 VK_IMAGE_TILING_OPTIMAL, 0);
17687 ASSERT_TRUE(image.initialized());
17688 image.SetLayout(0x6, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL);
17689
17690 VkImageViewCreateInfo ivci = {
17691 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
17692 nullptr,
17693 0,
17694 image.handle(),
17695 VK_IMAGE_VIEW_TYPE_2D,
17696 VK_FORMAT_D32_SFLOAT_S8_UINT,
17697 { VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A },
17698 { 0x2, 0, 1, 0, 1 },
17699 };
17700 VkImageView view;
17701 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
17702 ASSERT_VK_SUCCESS(err);
17703
17704 VkFramebufferCreateInfo fci = { VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1 };
17705 VkFramebuffer fb;
17706 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
17707 ASSERT_VK_SUCCESS(err);
17708
17709 VkRenderPassBeginInfo rpbi = { VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb,{ { 0, 0 },{ 32, 32 } }, 0, nullptr };
17710 BeginCommandBuffer();
17711 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
17712
17713 VkImageMemoryBarrier imb = {};
17714 imb.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
17715 imb.pNext = nullptr;
17716 imb.srcAccessMask = VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
17717 imb.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
17718 imb.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
17719 imb.newLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
17720 imb.srcQueueFamilyIndex = 0;
17721 imb.dstQueueFamilyIndex = 0;
17722 imb.image = image.handle();
17723 imb.subresourceRange.aspectMask = 0x6;
17724 imb.subresourceRange.baseMipLevel = 0;
17725 imb.subresourceRange.levelCount = 0x1;
17726 imb.subresourceRange.baseArrayLayer = 0;
17727 imb.subresourceRange.layerCount = 0x1;
17728
17729 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
17730 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_DEPENDENCY_BY_REGION_BIT, 0, nullptr, 0, nullptr, 1,
17731 &imb);
17732
17733 vkCmdEndRenderPass(m_commandBuffer->handle());
17734 EndCommandBuffer();
17735 QueueCommandBuffer(false);
17736 m_errorMonitor->VerifyNotFound();
17737
17738 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
17739 vkDestroyRenderPass(m_device->device(), rp, nullptr);
17740 vkDestroyImageView(m_device->device(), view, nullptr);
17741}
17742
17743TEST_F(VkPositiveLayerTest, RenderPassTransitionsAttachmentUnused) {
17744 TEST_DESCRIPTION("Ensure that layout transitions work correctly without "
17745 "errors, when an attachment reference is "
17746 "VK_ATTACHMENT_UNUSED");
17747
17748 m_errorMonitor->ExpectSuccess();
17749
17750 ASSERT_NO_FATAL_FAILURE(InitState());
17751
17752 // A renderpass with no attachments
17753 VkAttachmentReference att_ref = { VK_ATTACHMENT_UNUSED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
17754
17755 VkSubpassDescription subpass = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr };
17756
17757 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 1, &subpass, 0, nullptr };
17758
17759 VkRenderPass rp;
17760 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
17761 ASSERT_VK_SUCCESS(err);
17762
17763 // A compatible framebuffer.
17764 VkFramebufferCreateInfo fci = { VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 0, nullptr, 32, 32, 1 };
17765 VkFramebuffer fb;
17766 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
17767 ASSERT_VK_SUCCESS(err);
17768
17769 // Record a command buffer which just begins and ends the renderpass. The
17770 // bug manifests in BeginRenderPass.
17771 VkRenderPassBeginInfo rpbi = { VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb,{ { 0, 0 },{ 32, 32 } }, 0, nullptr };
17772 BeginCommandBuffer();
17773 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
17774 vkCmdEndRenderPass(m_commandBuffer->handle());
17775 m_errorMonitor->VerifyNotFound();
17776 EndCommandBuffer();
17777
17778 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
17779 vkDestroyRenderPass(m_device->device(), rp, nullptr);
17780}
17781
17782// This is a positive test. No errors are expected.
17783TEST_F(VkPositiveLayerTest, StencilLoadOp) {
17784 TEST_DESCRIPTION("Create a stencil-only attachment with a LOAD_OP set to "
17785 "CLEAR. stencil[Load|Store]Op used to be ignored.");
17786 VkResult result = VK_SUCCESS;
17787 VkImageFormatProperties formatProps;
17788 vkGetPhysicalDeviceImageFormatProperties(gpu(), VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
17789 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT, 0,
17790 &formatProps);
17791 if (formatProps.maxExtent.width < 100 || formatProps.maxExtent.height < 100) {
17792 return;
17793 }
17794
17795 ASSERT_NO_FATAL_FAILURE(InitState());
17796 VkFormat depth_stencil_fmt = VK_FORMAT_D24_UNORM_S8_UINT;
17797 m_depthStencil->Init(m_device, 100, 100, depth_stencil_fmt,
17798 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT);
17799 VkAttachmentDescription att = {};
17800 VkAttachmentReference ref = {};
17801 att.format = depth_stencil_fmt;
17802 att.samples = VK_SAMPLE_COUNT_1_BIT;
17803 att.loadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
17804 att.storeOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
17805 att.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
17806 att.stencilStoreOp = VK_ATTACHMENT_STORE_OP_STORE;
17807 att.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
17808 att.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
17809
17810 VkClearValue clear;
17811 clear.depthStencil.depth = 1.0;
17812 clear.depthStencil.stencil = 0;
17813 ref.attachment = 0;
17814 ref.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
17815
17816 VkSubpassDescription subpass = {};
17817 subpass.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;
17818 subpass.flags = 0;
17819 subpass.inputAttachmentCount = 0;
17820 subpass.pInputAttachments = NULL;
17821 subpass.colorAttachmentCount = 0;
17822 subpass.pColorAttachments = NULL;
17823 subpass.pResolveAttachments = NULL;
17824 subpass.pDepthStencilAttachment = &ref;
17825 subpass.preserveAttachmentCount = 0;
17826 subpass.pPreserveAttachments = NULL;
17827
17828 VkRenderPass rp;
17829 VkRenderPassCreateInfo rp_info = {};
17830 rp_info.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
17831 rp_info.attachmentCount = 1;
17832 rp_info.pAttachments = &att;
17833 rp_info.subpassCount = 1;
17834 rp_info.pSubpasses = &subpass;
17835 result = vkCreateRenderPass(device(), &rp_info, NULL, &rp);
17836 ASSERT_VK_SUCCESS(result);
17837
17838 VkImageView *depthView = m_depthStencil->BindInfo();
17839 VkFramebufferCreateInfo fb_info = {};
17840 fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
17841 fb_info.pNext = NULL;
17842 fb_info.renderPass = rp;
17843 fb_info.attachmentCount = 1;
17844 fb_info.pAttachments = depthView;
17845 fb_info.width = 100;
17846 fb_info.height = 100;
17847 fb_info.layers = 1;
17848 VkFramebuffer fb;
17849 result = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
17850 ASSERT_VK_SUCCESS(result);
17851
17852 VkRenderPassBeginInfo rpbinfo = {};
17853 rpbinfo.clearValueCount = 1;
17854 rpbinfo.pClearValues = &clear;
17855 rpbinfo.pNext = NULL;
17856 rpbinfo.renderPass = rp;
17857 rpbinfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
17858 rpbinfo.renderArea.extent.width = 100;
17859 rpbinfo.renderArea.extent.height = 100;
17860 rpbinfo.renderArea.offset.x = 0;
17861 rpbinfo.renderArea.offset.y = 0;
17862 rpbinfo.framebuffer = fb;
17863
17864 VkFence fence = {};
17865 VkFenceCreateInfo fence_ci = {};
17866 fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
17867 fence_ci.pNext = nullptr;
17868 fence_ci.flags = 0;
17869 result = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fence);
17870 ASSERT_VK_SUCCESS(result);
17871
17872 m_commandBuffer->BeginCommandBuffer();
17873 m_commandBuffer->BeginRenderPass(rpbinfo);
17874 m_commandBuffer->EndRenderPass();
17875 m_commandBuffer->EndCommandBuffer();
17876 m_commandBuffer->QueueCommandBuffer(fence);
17877
17878 VkImageObj destImage(m_device);
17879 destImage.init(100, 100, depth_stencil_fmt, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
17880 VK_IMAGE_TILING_OPTIMAL, 0);
17881 VkImageMemoryBarrier barrier = {};
17882 VkImageSubresourceRange range;
17883 barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
17884 barrier.srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
17885 barrier.dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT;
17886 barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
17887 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
17888 barrier.image = m_depthStencil->handle();
17889 range.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
17890 range.baseMipLevel = 0;
17891 range.levelCount = 1;
17892 range.baseArrayLayer = 0;
17893 range.layerCount = 1;
17894 barrier.subresourceRange = range;
17895 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
17896 VkCommandBufferObj cmdbuf(m_device, m_commandPool);
17897 cmdbuf.BeginCommandBuffer();
17898 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
17899 &barrier);
17900 barrier.srcAccessMask = 0;
17901 barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
17902 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
17903 barrier.image = destImage.handle();
17904 barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
17905 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
17906 &barrier);
17907 VkImageCopy cregion;
17908 cregion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
17909 cregion.srcSubresource.mipLevel = 0;
17910 cregion.srcSubresource.baseArrayLayer = 0;
17911 cregion.srcSubresource.layerCount = 1;
17912 cregion.srcOffset.x = 0;
17913 cregion.srcOffset.y = 0;
17914 cregion.srcOffset.z = 0;
17915 cregion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
17916 cregion.dstSubresource.mipLevel = 0;
17917 cregion.dstSubresource.baseArrayLayer = 0;
17918 cregion.dstSubresource.layerCount = 1;
17919 cregion.dstOffset.x = 0;
17920 cregion.dstOffset.y = 0;
17921 cregion.dstOffset.z = 0;
17922 cregion.extent.width = 100;
17923 cregion.extent.height = 100;
17924 cregion.extent.depth = 1;
17925 cmdbuf.CopyImage(m_depthStencil->handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, destImage.handle(),
17926 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &cregion);
17927 cmdbuf.EndCommandBuffer();
17928
17929 VkSubmitInfo submit_info;
17930 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17931 submit_info.pNext = NULL;
17932 submit_info.waitSemaphoreCount = 0;
17933 submit_info.pWaitSemaphores = NULL;
17934 submit_info.pWaitDstStageMask = NULL;
17935 submit_info.commandBufferCount = 1;
17936 submit_info.pCommandBuffers = &cmdbuf.handle();
17937 submit_info.signalSemaphoreCount = 0;
17938 submit_info.pSignalSemaphores = NULL;
17939
17940 m_errorMonitor->ExpectSuccess();
17941 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
17942 m_errorMonitor->VerifyNotFound();
17943
17944 vkQueueWaitIdle(m_device->m_queue);
17945 vkDestroyFence(m_device->device(), fence, nullptr);
17946 vkDestroyRenderPass(m_device->device(), rp, nullptr);
17947 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
17948}
17949
17950// This is a positive test. No errors should be generated.
17951TEST_F(VkPositiveLayerTest, WaitEventThenSet) {
17952 TEST_DESCRIPTION("Wait on a event then set it after the wait has been submitted.");
17953
17954 m_errorMonitor->ExpectSuccess();
17955 ASSERT_NO_FATAL_FAILURE(InitState());
17956
17957 VkEvent event;
17958 VkEventCreateInfo event_create_info{};
17959 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
17960 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
17961
17962 VkCommandPool command_pool;
17963 VkCommandPoolCreateInfo pool_create_info{};
17964 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17965 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
17966 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17967 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
17968
17969 VkCommandBuffer command_buffer;
17970 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
17971 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17972 command_buffer_allocate_info.commandPool = command_pool;
17973 command_buffer_allocate_info.commandBufferCount = 1;
17974 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17975 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
17976
17977 VkQueue queue = VK_NULL_HANDLE;
17978 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
17979
17980 {
17981 VkCommandBufferBeginInfo begin_info{};
17982 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17983 vkBeginCommandBuffer(command_buffer, &begin_info);
17984
17985 vkCmdWaitEvents(command_buffer, 1, &event, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, nullptr, 0,
17986 nullptr, 0, nullptr);
17987 vkCmdResetEvent(command_buffer, event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
17988 vkEndCommandBuffer(command_buffer);
17989 }
17990 {
17991 VkSubmitInfo submit_info{};
17992 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17993 submit_info.commandBufferCount = 1;
17994 submit_info.pCommandBuffers = &command_buffer;
17995 submit_info.signalSemaphoreCount = 0;
17996 submit_info.pSignalSemaphores = nullptr;
17997 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
17998 }
17999 { vkSetEvent(m_device->device(), event); }
18000
18001 vkQueueWaitIdle(queue);
18002
18003 vkDestroyEvent(m_device->device(), event, nullptr);
18004 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
18005 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18006
18007 m_errorMonitor->VerifyNotFound();
18008}
18009// This is a positive test. No errors should be generated.
18010TEST_F(VkPositiveLayerTest, QueryAndCopySecondaryCommandBuffers) {
18011 TEST_DESCRIPTION("Issue a query on a secondary command buffery and copy it on a primary.");
18012
18013 ASSERT_NO_FATAL_FAILURE(InitState());
18014 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
18015 return;
18016
18017 m_errorMonitor->ExpectSuccess();
18018
18019 VkQueryPool query_pool;
18020 VkQueryPoolCreateInfo query_pool_create_info{};
18021 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
18022 query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP;
18023 query_pool_create_info.queryCount = 1;
18024 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
18025
18026 VkCommandPool command_pool;
18027 VkCommandPoolCreateInfo pool_create_info{};
18028 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18029 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18030 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18031 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18032
18033 VkCommandBuffer command_buffer;
18034 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18035 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18036 command_buffer_allocate_info.commandPool = command_pool;
18037 command_buffer_allocate_info.commandBufferCount = 1;
18038 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18039 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
18040
18041 VkCommandBuffer secondary_command_buffer;
18042 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
18043 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer);
18044
18045 VkQueue queue = VK_NULL_HANDLE;
18046 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
18047
18048 uint32_t qfi = 0;
18049 VkBufferCreateInfo buff_create_info = {};
18050 buff_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
18051 buff_create_info.size = 1024;
18052 buff_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
18053 buff_create_info.queueFamilyIndexCount = 1;
18054 buff_create_info.pQueueFamilyIndices = &qfi;
18055
18056 VkResult err;
18057 VkBuffer buffer;
18058 err = vkCreateBuffer(m_device->device(), &buff_create_info, NULL, &buffer);
18059 ASSERT_VK_SUCCESS(err);
18060 VkMemoryAllocateInfo mem_alloc = {};
18061 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18062 mem_alloc.pNext = NULL;
18063 mem_alloc.allocationSize = 1024;
18064 mem_alloc.memoryTypeIndex = 0;
18065
18066 VkMemoryRequirements memReqs;
18067 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
18068 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
18069 if (!pass) {
18070 vkDestroyBuffer(m_device->device(), buffer, NULL);
18071 return;
18072 }
18073
18074 VkDeviceMemory mem;
18075 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
18076 ASSERT_VK_SUCCESS(err);
18077 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
18078 ASSERT_VK_SUCCESS(err);
18079
18080 VkCommandBufferInheritanceInfo hinfo = {};
18081 hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
18082 hinfo.renderPass = VK_NULL_HANDLE;
18083 hinfo.subpass = 0;
18084 hinfo.framebuffer = VK_NULL_HANDLE;
18085 hinfo.occlusionQueryEnable = VK_FALSE;
18086 hinfo.queryFlags = 0;
18087 hinfo.pipelineStatistics = 0;
18088
18089 {
18090 VkCommandBufferBeginInfo begin_info{};
18091 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18092 begin_info.pInheritanceInfo = &hinfo;
18093 vkBeginCommandBuffer(secondary_command_buffer, &begin_info);
18094
18095 vkCmdResetQueryPool(secondary_command_buffer, query_pool, 0, 1);
18096 vkCmdWriteTimestamp(secondary_command_buffer, VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0);
18097
18098 vkEndCommandBuffer(secondary_command_buffer);
18099
18100 begin_info.pInheritanceInfo = nullptr;
18101 vkBeginCommandBuffer(command_buffer, &begin_info);
18102
18103 vkCmdExecuteCommands(command_buffer, 1, &secondary_command_buffer);
18104 vkCmdCopyQueryPoolResults(command_buffer, query_pool, 0, 1, buffer, 0, 0, 0);
18105
18106 vkEndCommandBuffer(command_buffer);
18107 }
18108 {
18109 VkSubmitInfo submit_info{};
18110 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18111 submit_info.commandBufferCount = 1;
18112 submit_info.pCommandBuffers = &command_buffer;
18113 submit_info.signalSemaphoreCount = 0;
18114 submit_info.pSignalSemaphores = nullptr;
18115 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
18116 }
18117
18118 vkQueueWaitIdle(queue);
18119
18120 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
18121 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
18122 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &secondary_command_buffer);
18123 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18124 vkDestroyBuffer(m_device->device(), buffer, NULL);
18125 vkFreeMemory(m_device->device(), mem, NULL);
18126
18127 m_errorMonitor->VerifyNotFound();
18128}
18129
18130// This is a positive test. No errors should be generated.
18131TEST_F(VkPositiveLayerTest, QueryAndCopyMultipleCommandBuffers) {
18132 TEST_DESCRIPTION("Issue a query and copy from it on a second command buffer.");
18133
18134 ASSERT_NO_FATAL_FAILURE(InitState());
18135 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
18136 return;
18137
18138 m_errorMonitor->ExpectSuccess();
18139
18140 VkQueryPool query_pool;
18141 VkQueryPoolCreateInfo query_pool_create_info{};
18142 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
18143 query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP;
18144 query_pool_create_info.queryCount = 1;
18145 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
18146
18147 VkCommandPool command_pool;
18148 VkCommandPoolCreateInfo pool_create_info{};
18149 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18150 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18151 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18152 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18153
18154 VkCommandBuffer command_buffer[2];
18155 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18156 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18157 command_buffer_allocate_info.commandPool = command_pool;
18158 command_buffer_allocate_info.commandBufferCount = 2;
18159 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18160 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18161
18162 VkQueue queue = VK_NULL_HANDLE;
18163 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
18164
18165 uint32_t qfi = 0;
18166 VkBufferCreateInfo buff_create_info = {};
18167 buff_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
18168 buff_create_info.size = 1024;
18169 buff_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
18170 buff_create_info.queueFamilyIndexCount = 1;
18171 buff_create_info.pQueueFamilyIndices = &qfi;
18172
18173 VkResult err;
18174 VkBuffer buffer;
18175 err = vkCreateBuffer(m_device->device(), &buff_create_info, NULL, &buffer);
18176 ASSERT_VK_SUCCESS(err);
18177 VkMemoryAllocateInfo mem_alloc = {};
18178 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18179 mem_alloc.pNext = NULL;
18180 mem_alloc.allocationSize = 1024;
18181 mem_alloc.memoryTypeIndex = 0;
18182
18183 VkMemoryRequirements memReqs;
18184 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
18185 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
18186 if (!pass) {
18187 vkDestroyBuffer(m_device->device(), buffer, NULL);
18188 return;
18189 }
18190
18191 VkDeviceMemory mem;
18192 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
18193 ASSERT_VK_SUCCESS(err);
18194 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
18195 ASSERT_VK_SUCCESS(err);
18196
18197 {
18198 VkCommandBufferBeginInfo begin_info{};
18199 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18200 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18201
18202 vkCmdResetQueryPool(command_buffer[0], query_pool, 0, 1);
18203 vkCmdWriteTimestamp(command_buffer[0], VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0);
18204
18205 vkEndCommandBuffer(command_buffer[0]);
18206
18207 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18208
18209 vkCmdCopyQueryPoolResults(command_buffer[1], query_pool, 0, 1, buffer, 0, 0, 0);
18210
18211 vkEndCommandBuffer(command_buffer[1]);
18212 }
18213 {
18214 VkSubmitInfo submit_info{};
18215 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18216 submit_info.commandBufferCount = 2;
18217 submit_info.pCommandBuffers = command_buffer;
18218 submit_info.signalSemaphoreCount = 0;
18219 submit_info.pSignalSemaphores = nullptr;
18220 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
18221 }
18222
18223 vkQueueWaitIdle(queue);
18224
18225 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
18226 vkFreeCommandBuffers(m_device->device(), command_pool, 2, command_buffer);
18227 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18228 vkDestroyBuffer(m_device->device(), buffer, NULL);
18229 vkFreeMemory(m_device->device(), mem, NULL);
18230
18231 m_errorMonitor->VerifyNotFound();
18232}
18233
Tony Barbourc46924f2016-11-04 11:49:52 -060018234TEST_F(VkLayerTest, ResetEventThenSet) {
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018235 TEST_DESCRIPTION("Reset an event then set it after the reset has been submitted.");
18236
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018237 ASSERT_NO_FATAL_FAILURE(InitState());
18238 VkEvent event;
18239 VkEventCreateInfo event_create_info{};
18240 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
18241 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
18242
18243 VkCommandPool command_pool;
18244 VkCommandPoolCreateInfo pool_create_info{};
18245 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18246 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18247 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18248 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18249
18250 VkCommandBuffer command_buffer;
18251 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18252 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18253 command_buffer_allocate_info.commandPool = command_pool;
18254 command_buffer_allocate_info.commandBufferCount = 1;
18255 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18256 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
18257
18258 VkQueue queue = VK_NULL_HANDLE;
18259 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
18260
18261 {
18262 VkCommandBufferBeginInfo begin_info{};
18263 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18264 vkBeginCommandBuffer(command_buffer, &begin_info);
18265
18266 vkCmdResetEvent(command_buffer, event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018267 vkEndCommandBuffer(command_buffer);
18268 }
18269 {
18270 VkSubmitInfo submit_info{};
18271 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18272 submit_info.commandBufferCount = 1;
18273 submit_info.pCommandBuffers = &command_buffer;
18274 submit_info.signalSemaphoreCount = 0;
18275 submit_info.pSignalSemaphores = nullptr;
18276 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
18277 }
18278 {
18279 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is already in use by a "
18280 "command buffer.");
18281 vkSetEvent(m_device->device(), event);
18282 m_errorMonitor->VerifyFound();
18283 }
18284
18285 vkQueueWaitIdle(queue);
18286
18287 vkDestroyEvent(m_device->device(), event, nullptr);
18288 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
18289 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18290}
18291
18292// This is a positive test. No errors should be generated.
18293TEST_F(VkPositiveLayerTest, TwoFencesThreeFrames) {
18294 TEST_DESCRIPTION("Two command buffers with two separate fences are each "
18295 "run through a Submit & WaitForFences cycle 3 times. This "
18296 "previously revealed a bug so running this positive test "
18297 "to prevent a regression.");
18298 m_errorMonitor->ExpectSuccess();
18299
18300 ASSERT_NO_FATAL_FAILURE(InitState());
18301 VkQueue queue = VK_NULL_HANDLE;
18302 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
18303
18304 static const uint32_t NUM_OBJECTS = 2;
18305 static const uint32_t NUM_FRAMES = 3;
18306 VkCommandBuffer cmd_buffers[NUM_OBJECTS] = {};
18307 VkFence fences[NUM_OBJECTS] = {};
18308
18309 VkCommandPool cmd_pool;
18310 VkCommandPoolCreateInfo cmd_pool_ci = {};
18311 cmd_pool_ci.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18312 cmd_pool_ci.queueFamilyIndex = m_device->graphics_queue_node_index_;
18313 cmd_pool_ci.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18314 VkResult err = vkCreateCommandPool(m_device->device(), &cmd_pool_ci, nullptr, &cmd_pool);
18315 ASSERT_VK_SUCCESS(err);
18316
18317 VkCommandBufferAllocateInfo cmd_buf_info = {};
18318 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18319 cmd_buf_info.commandPool = cmd_pool;
18320 cmd_buf_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18321 cmd_buf_info.commandBufferCount = 1;
18322
18323 VkFenceCreateInfo fence_ci = {};
18324 fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18325 fence_ci.pNext = nullptr;
18326 fence_ci.flags = 0;
18327
18328 for (uint32_t i = 0; i < NUM_OBJECTS; ++i) {
18329 err = vkAllocateCommandBuffers(m_device->device(), &cmd_buf_info, &cmd_buffers[i]);
18330 ASSERT_VK_SUCCESS(err);
18331 err = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fences[i]);
18332 ASSERT_VK_SUCCESS(err);
18333 }
18334
18335 for (uint32_t frame = 0; frame < NUM_FRAMES; ++frame) {
18336 for (uint32_t obj = 0; obj < NUM_OBJECTS; ++obj) {
18337 // Create empty cmd buffer
18338 VkCommandBufferBeginInfo cmdBufBeginDesc = {};
18339 cmdBufBeginDesc.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18340
18341 err = vkBeginCommandBuffer(cmd_buffers[obj], &cmdBufBeginDesc);
18342 ASSERT_VK_SUCCESS(err);
18343 err = vkEndCommandBuffer(cmd_buffers[obj]);
18344 ASSERT_VK_SUCCESS(err);
18345
18346 VkSubmitInfo submit_info = {};
18347 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18348 submit_info.commandBufferCount = 1;
18349 submit_info.pCommandBuffers = &cmd_buffers[obj];
18350 // Submit cmd buffer and wait for fence
18351 err = vkQueueSubmit(queue, 1, &submit_info, fences[obj]);
18352 ASSERT_VK_SUCCESS(err);
18353 err = vkWaitForFences(m_device->device(), 1, &fences[obj], VK_TRUE, UINT64_MAX);
18354 ASSERT_VK_SUCCESS(err);
18355 err = vkResetFences(m_device->device(), 1, &fences[obj]);
18356 ASSERT_VK_SUCCESS(err);
18357 }
18358 }
18359 m_errorMonitor->VerifyNotFound();
18360 vkDestroyCommandPool(m_device->device(), cmd_pool, NULL);
18361 for (uint32_t i = 0; i < NUM_OBJECTS; ++i) {
18362 vkDestroyFence(m_device->device(), fences[i], nullptr);
18363 }
18364}
18365// This is a positive test. No errors should be generated.
18366TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWI) {
18367
18368 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
18369 "submitted on separate queues followed by a QueueWaitIdle.");
18370
18371 ASSERT_NO_FATAL_FAILURE(InitState());
18372 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
18373 return;
18374
18375 m_errorMonitor->ExpectSuccess();
18376
18377 VkSemaphore semaphore;
18378 VkSemaphoreCreateInfo semaphore_create_info{};
18379 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
18380 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
18381
18382 VkCommandPool command_pool;
18383 VkCommandPoolCreateInfo pool_create_info{};
18384 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18385 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18386 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18387 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18388
18389 VkCommandBuffer command_buffer[2];
18390 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18391 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18392 command_buffer_allocate_info.commandPool = command_pool;
18393 command_buffer_allocate_info.commandBufferCount = 2;
18394 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18395 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18396
18397 VkQueue queue = VK_NULL_HANDLE;
18398 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
18399
18400 {
18401 VkCommandBufferBeginInfo begin_info{};
18402 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18403 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18404
18405 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
18406 nullptr, 0, nullptr, 0, nullptr);
18407
18408 VkViewport viewport{};
18409 viewport.maxDepth = 1.0f;
18410 viewport.minDepth = 0.0f;
18411 viewport.width = 512;
18412 viewport.height = 512;
18413 viewport.x = 0;
18414 viewport.y = 0;
18415 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
18416 vkEndCommandBuffer(command_buffer[0]);
18417 }
18418 {
18419 VkCommandBufferBeginInfo begin_info{};
18420 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18421 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18422
18423 VkViewport viewport{};
18424 viewport.maxDepth = 1.0f;
18425 viewport.minDepth = 0.0f;
18426 viewport.width = 512;
18427 viewport.height = 512;
18428 viewport.x = 0;
18429 viewport.y = 0;
18430 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
18431 vkEndCommandBuffer(command_buffer[1]);
18432 }
18433 {
18434 VkSubmitInfo submit_info{};
18435 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18436 submit_info.commandBufferCount = 1;
18437 submit_info.pCommandBuffers = &command_buffer[0];
18438 submit_info.signalSemaphoreCount = 1;
18439 submit_info.pSignalSemaphores = &semaphore;
18440 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
18441 }
18442 {
18443 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
18444 VkSubmitInfo submit_info{};
18445 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18446 submit_info.commandBufferCount = 1;
18447 submit_info.pCommandBuffers = &command_buffer[1];
18448 submit_info.waitSemaphoreCount = 1;
18449 submit_info.pWaitSemaphores = &semaphore;
18450 submit_info.pWaitDstStageMask = flags;
18451 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
18452 }
18453
18454 vkQueueWaitIdle(m_device->m_queue);
18455
18456 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
18457 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
18458 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18459
18460 m_errorMonitor->VerifyNotFound();
18461}
18462
18463// This is a positive test. No errors should be generated.
18464TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWIFence) {
18465
18466 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
18467 "submitted on separate queues, the second having a fence"
18468 "followed by a QueueWaitIdle.");
18469
18470 ASSERT_NO_FATAL_FAILURE(InitState());
18471 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
18472 return;
18473
18474 m_errorMonitor->ExpectSuccess();
18475
18476 VkFence fence;
18477 VkFenceCreateInfo fence_create_info{};
18478 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18479 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
18480
18481 VkSemaphore semaphore;
18482 VkSemaphoreCreateInfo semaphore_create_info{};
18483 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
18484 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
18485
18486 VkCommandPool command_pool;
18487 VkCommandPoolCreateInfo pool_create_info{};
18488 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18489 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18490 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18491 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18492
18493 VkCommandBuffer command_buffer[2];
18494 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18495 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18496 command_buffer_allocate_info.commandPool = command_pool;
18497 command_buffer_allocate_info.commandBufferCount = 2;
18498 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18499 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18500
18501 VkQueue queue = VK_NULL_HANDLE;
18502 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
18503
18504 {
18505 VkCommandBufferBeginInfo begin_info{};
18506 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18507 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18508
18509 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
18510 nullptr, 0, nullptr, 0, nullptr);
18511
18512 VkViewport viewport{};
18513 viewport.maxDepth = 1.0f;
18514 viewport.minDepth = 0.0f;
18515 viewport.width = 512;
18516 viewport.height = 512;
18517 viewport.x = 0;
18518 viewport.y = 0;
18519 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
18520 vkEndCommandBuffer(command_buffer[0]);
18521 }
18522 {
18523 VkCommandBufferBeginInfo begin_info{};
18524 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18525 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18526
18527 VkViewport viewport{};
18528 viewport.maxDepth = 1.0f;
18529 viewport.minDepth = 0.0f;
18530 viewport.width = 512;
18531 viewport.height = 512;
18532 viewport.x = 0;
18533 viewport.y = 0;
18534 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
18535 vkEndCommandBuffer(command_buffer[1]);
18536 }
18537 {
18538 VkSubmitInfo submit_info{};
18539 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18540 submit_info.commandBufferCount = 1;
18541 submit_info.pCommandBuffers = &command_buffer[0];
18542 submit_info.signalSemaphoreCount = 1;
18543 submit_info.pSignalSemaphores = &semaphore;
18544 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
18545 }
18546 {
18547 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
18548 VkSubmitInfo submit_info{};
18549 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18550 submit_info.commandBufferCount = 1;
18551 submit_info.pCommandBuffers = &command_buffer[1];
18552 submit_info.waitSemaphoreCount = 1;
18553 submit_info.pWaitSemaphores = &semaphore;
18554 submit_info.pWaitDstStageMask = flags;
18555 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
18556 }
18557
18558 vkQueueWaitIdle(m_device->m_queue);
18559
18560 vkDestroyFence(m_device->device(), fence, nullptr);
18561 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
18562 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
18563 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18564
18565 m_errorMonitor->VerifyNotFound();
18566}
18567
18568// This is a positive test. No errors should be generated.
18569TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceTwoWFF) {
18570
18571 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
18572 "submitted on separate queues, the second having a fence"
18573 "followed by two consecutive WaitForFences calls on the same fence.");
18574
18575 ASSERT_NO_FATAL_FAILURE(InitState());
18576 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
18577 return;
18578
18579 m_errorMonitor->ExpectSuccess();
18580
18581 VkFence fence;
18582 VkFenceCreateInfo fence_create_info{};
18583 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18584 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
18585
18586 VkSemaphore semaphore;
18587 VkSemaphoreCreateInfo semaphore_create_info{};
18588 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
18589 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
18590
18591 VkCommandPool command_pool;
18592 VkCommandPoolCreateInfo pool_create_info{};
18593 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18594 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18595 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18596 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18597
18598 VkCommandBuffer command_buffer[2];
18599 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18600 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18601 command_buffer_allocate_info.commandPool = command_pool;
18602 command_buffer_allocate_info.commandBufferCount = 2;
18603 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18604 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18605
18606 VkQueue queue = VK_NULL_HANDLE;
18607 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
18608
18609 {
18610 VkCommandBufferBeginInfo begin_info{};
18611 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18612 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18613
18614 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
18615 nullptr, 0, nullptr, 0, nullptr);
18616
18617 VkViewport viewport{};
18618 viewport.maxDepth = 1.0f;
18619 viewport.minDepth = 0.0f;
18620 viewport.width = 512;
18621 viewport.height = 512;
18622 viewport.x = 0;
18623 viewport.y = 0;
18624 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
18625 vkEndCommandBuffer(command_buffer[0]);
18626 }
18627 {
18628 VkCommandBufferBeginInfo begin_info{};
18629 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18630 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18631
18632 VkViewport viewport{};
18633 viewport.maxDepth = 1.0f;
18634 viewport.minDepth = 0.0f;
18635 viewport.width = 512;
18636 viewport.height = 512;
18637 viewport.x = 0;
18638 viewport.y = 0;
18639 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
18640 vkEndCommandBuffer(command_buffer[1]);
18641 }
18642 {
18643 VkSubmitInfo submit_info{};
18644 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18645 submit_info.commandBufferCount = 1;
18646 submit_info.pCommandBuffers = &command_buffer[0];
18647 submit_info.signalSemaphoreCount = 1;
18648 submit_info.pSignalSemaphores = &semaphore;
18649 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
18650 }
18651 {
18652 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
18653 VkSubmitInfo submit_info{};
18654 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18655 submit_info.commandBufferCount = 1;
18656 submit_info.pCommandBuffers = &command_buffer[1];
18657 submit_info.waitSemaphoreCount = 1;
18658 submit_info.pWaitSemaphores = &semaphore;
18659 submit_info.pWaitDstStageMask = flags;
18660 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
18661 }
18662
18663 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
18664 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
18665
18666 vkDestroyFence(m_device->device(), fence, nullptr);
18667 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
18668 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
18669 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18670
18671 m_errorMonitor->VerifyNotFound();
18672}
18673
18674TEST_F(VkPositiveLayerTest, TwoQueuesEnsureCorrectRetirementWithWorkStolen) {
18675
18676 ASSERT_NO_FATAL_FAILURE(InitState());
18677 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) {
18678 printf("Test requires two queues, skipping\n");
18679 return;
18680 }
18681
18682 VkResult err;
18683
18684 m_errorMonitor->ExpectSuccess();
18685
18686 VkQueue q0 = m_device->m_queue;
18687 VkQueue q1 = nullptr;
18688 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &q1);
18689 ASSERT_NE(q1, nullptr);
18690
18691 // An (empty) command buffer. We must have work in the first submission --
18692 // the layer treats unfenced work differently from fenced work.
18693 VkCommandPoolCreateInfo cpci = { VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, nullptr, 0, 0 };
18694 VkCommandPool pool;
18695 err = vkCreateCommandPool(m_device->device(), &cpci, nullptr, &pool);
18696 ASSERT_VK_SUCCESS(err);
18697 VkCommandBufferAllocateInfo cbai = { VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, nullptr, pool,
18698 VK_COMMAND_BUFFER_LEVEL_PRIMARY, 1 };
18699 VkCommandBuffer cb;
18700 err = vkAllocateCommandBuffers(m_device->device(), &cbai, &cb);
18701 ASSERT_VK_SUCCESS(err);
18702 VkCommandBufferBeginInfo cbbi = { VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr, 0, nullptr };
18703 err = vkBeginCommandBuffer(cb, &cbbi);
18704 ASSERT_VK_SUCCESS(err);
18705 err = vkEndCommandBuffer(cb);
18706 ASSERT_VK_SUCCESS(err);
18707
18708 // A semaphore
18709 VkSemaphoreCreateInfo sci = { VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0 };
18710 VkSemaphore s;
18711 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s);
18712 ASSERT_VK_SUCCESS(err);
18713
18714 // First submission, to q0
18715 VkSubmitInfo s0 = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 1, &cb, 1, &s };
18716
18717 err = vkQueueSubmit(q0, 1, &s0, VK_NULL_HANDLE);
18718 ASSERT_VK_SUCCESS(err);
18719
18720 // Second submission, to q1, waiting on s
18721 VkFlags waitmask = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT; // doesn't really matter what this value is.
18722 VkSubmitInfo s1 = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 1, &s, &waitmask, 0, nullptr, 0, nullptr };
18723
18724 err = vkQueueSubmit(q1, 1, &s1, VK_NULL_HANDLE);
18725 ASSERT_VK_SUCCESS(err);
18726
18727 // Wait for q0 idle
18728 err = vkQueueWaitIdle(q0);
18729 ASSERT_VK_SUCCESS(err);
18730
18731 // Command buffer should have been completed (it was on q0); reset the pool.
18732 vkFreeCommandBuffers(m_device->device(), pool, 1, &cb);
18733
18734 m_errorMonitor->VerifyNotFound();
18735
18736 // Force device completely idle and clean up resources
18737 vkDeviceWaitIdle(m_device->device());
18738 vkDestroyCommandPool(m_device->device(), pool, nullptr);
18739 vkDestroySemaphore(m_device->device(), s, nullptr);
18740}
18741
18742// This is a positive test. No errors should be generated.
18743TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFence) {
18744
18745 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
18746 "submitted on separate queues, the second having a fence, "
18747 "followed by a WaitForFences call.");
18748
18749 ASSERT_NO_FATAL_FAILURE(InitState());
18750 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
18751 return;
18752
18753 m_errorMonitor->ExpectSuccess();
18754
18755 ASSERT_NO_FATAL_FAILURE(InitState());
18756 VkFence fence;
18757 VkFenceCreateInfo fence_create_info{};
18758 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18759 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
18760
18761 VkSemaphore semaphore;
18762 VkSemaphoreCreateInfo semaphore_create_info{};
18763 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
18764 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
18765
18766 VkCommandPool command_pool;
18767 VkCommandPoolCreateInfo pool_create_info{};
18768 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18769 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18770 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18771 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18772
18773 VkCommandBuffer command_buffer[2];
18774 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18775 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18776 command_buffer_allocate_info.commandPool = command_pool;
18777 command_buffer_allocate_info.commandBufferCount = 2;
18778 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18779 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18780
18781 VkQueue queue = VK_NULL_HANDLE;
18782 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
18783
18784 {
18785 VkCommandBufferBeginInfo begin_info{};
18786 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18787 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18788
18789 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
18790 nullptr, 0, nullptr, 0, nullptr);
18791
18792 VkViewport viewport{};
18793 viewport.maxDepth = 1.0f;
18794 viewport.minDepth = 0.0f;
18795 viewport.width = 512;
18796 viewport.height = 512;
18797 viewport.x = 0;
18798 viewport.y = 0;
18799 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
18800 vkEndCommandBuffer(command_buffer[0]);
18801 }
18802 {
18803 VkCommandBufferBeginInfo begin_info{};
18804 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18805 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18806
18807 VkViewport viewport{};
18808 viewport.maxDepth = 1.0f;
18809 viewport.minDepth = 0.0f;
18810 viewport.width = 512;
18811 viewport.height = 512;
18812 viewport.x = 0;
18813 viewport.y = 0;
18814 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
18815 vkEndCommandBuffer(command_buffer[1]);
18816 }
18817 {
18818 VkSubmitInfo submit_info{};
18819 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18820 submit_info.commandBufferCount = 1;
18821 submit_info.pCommandBuffers = &command_buffer[0];
18822 submit_info.signalSemaphoreCount = 1;
18823 submit_info.pSignalSemaphores = &semaphore;
18824 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
18825 }
18826 {
18827 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
18828 VkSubmitInfo submit_info{};
18829 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18830 submit_info.commandBufferCount = 1;
18831 submit_info.pCommandBuffers = &command_buffer[1];
18832 submit_info.waitSemaphoreCount = 1;
18833 submit_info.pWaitSemaphores = &semaphore;
18834 submit_info.pWaitDstStageMask = flags;
18835 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
18836 }
18837
18838 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
18839
18840 vkDestroyFence(m_device->device(), fence, nullptr);
18841 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
18842 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
18843 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18844
18845 m_errorMonitor->VerifyNotFound();
18846}
18847
18848// This is a positive test. No errors should be generated.
18849TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueWithSemaphoreAndOneFence) {
18850
18851 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
18852 "on the same queue, sharing a signal/wait semaphore, the "
18853 "second having a fence, "
18854 "followed by a WaitForFences call.");
18855
18856 m_errorMonitor->ExpectSuccess();
18857
18858 ASSERT_NO_FATAL_FAILURE(InitState());
18859 VkFence fence;
18860 VkFenceCreateInfo fence_create_info{};
18861 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18862 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
18863
18864 VkSemaphore semaphore;
18865 VkSemaphoreCreateInfo semaphore_create_info{};
18866 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
18867 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
18868
18869 VkCommandPool command_pool;
18870 VkCommandPoolCreateInfo pool_create_info{};
18871 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18872 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18873 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18874 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18875
18876 VkCommandBuffer command_buffer[2];
18877 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18878 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18879 command_buffer_allocate_info.commandPool = command_pool;
18880 command_buffer_allocate_info.commandBufferCount = 2;
18881 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18882 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18883
18884 {
18885 VkCommandBufferBeginInfo begin_info{};
18886 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18887 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18888
18889 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
18890 nullptr, 0, nullptr, 0, nullptr);
18891
18892 VkViewport viewport{};
18893 viewport.maxDepth = 1.0f;
18894 viewport.minDepth = 0.0f;
18895 viewport.width = 512;
18896 viewport.height = 512;
18897 viewport.x = 0;
18898 viewport.y = 0;
18899 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
18900 vkEndCommandBuffer(command_buffer[0]);
18901 }
18902 {
18903 VkCommandBufferBeginInfo begin_info{};
18904 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18905 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18906
18907 VkViewport viewport{};
18908 viewport.maxDepth = 1.0f;
18909 viewport.minDepth = 0.0f;
18910 viewport.width = 512;
18911 viewport.height = 512;
18912 viewport.x = 0;
18913 viewport.y = 0;
18914 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
18915 vkEndCommandBuffer(command_buffer[1]);
18916 }
18917 {
18918 VkSubmitInfo submit_info{};
18919 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18920 submit_info.commandBufferCount = 1;
18921 submit_info.pCommandBuffers = &command_buffer[0];
18922 submit_info.signalSemaphoreCount = 1;
18923 submit_info.pSignalSemaphores = &semaphore;
18924 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
18925 }
18926 {
18927 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
18928 VkSubmitInfo submit_info{};
18929 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18930 submit_info.commandBufferCount = 1;
18931 submit_info.pCommandBuffers = &command_buffer[1];
18932 submit_info.waitSemaphoreCount = 1;
18933 submit_info.pWaitSemaphores = &semaphore;
18934 submit_info.pWaitDstStageMask = flags;
18935 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
18936 }
18937
18938 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
18939
18940 vkDestroyFence(m_device->device(), fence, nullptr);
18941 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
18942 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
18943 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18944
18945 m_errorMonitor->VerifyNotFound();
18946}
18947
18948// This is a positive test. No errors should be generated.
18949TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueNullQueueSubmitWithFence) {
18950
18951 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
18952 "on the same queue, no fences, followed by a third QueueSubmit with NO "
18953 "SubmitInfos but with a fence, followed by a WaitForFences call.");
18954
18955 m_errorMonitor->ExpectSuccess();
18956
18957 ASSERT_NO_FATAL_FAILURE(InitState());
18958 VkFence fence;
18959 VkFenceCreateInfo fence_create_info{};
18960 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18961 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
18962
18963 VkCommandPool command_pool;
18964 VkCommandPoolCreateInfo pool_create_info{};
18965 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18966 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18967 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18968 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18969
18970 VkCommandBuffer command_buffer[2];
18971 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18972 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18973 command_buffer_allocate_info.commandPool = command_pool;
18974 command_buffer_allocate_info.commandBufferCount = 2;
18975 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18976 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18977
18978 {
18979 VkCommandBufferBeginInfo begin_info{};
18980 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18981 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18982
18983 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
18984 nullptr, 0, nullptr, 0, nullptr);
18985
18986 VkViewport viewport{};
18987 viewport.maxDepth = 1.0f;
18988 viewport.minDepth = 0.0f;
18989 viewport.width = 512;
18990 viewport.height = 512;
18991 viewport.x = 0;
18992 viewport.y = 0;
18993 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
18994 vkEndCommandBuffer(command_buffer[0]);
18995 }
18996 {
18997 VkCommandBufferBeginInfo begin_info{};
18998 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18999 vkBeginCommandBuffer(command_buffer[1], &begin_info);
19000
19001 VkViewport viewport{};
19002 viewport.maxDepth = 1.0f;
19003 viewport.minDepth = 0.0f;
19004 viewport.width = 512;
19005 viewport.height = 512;
19006 viewport.x = 0;
19007 viewport.y = 0;
19008 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
19009 vkEndCommandBuffer(command_buffer[1]);
19010 }
19011 {
19012 VkSubmitInfo submit_info{};
19013 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19014 submit_info.commandBufferCount = 1;
19015 submit_info.pCommandBuffers = &command_buffer[0];
19016 submit_info.signalSemaphoreCount = 0;
19017 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
19018 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
19019 }
19020 {
19021 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
19022 VkSubmitInfo submit_info{};
19023 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19024 submit_info.commandBufferCount = 1;
19025 submit_info.pCommandBuffers = &command_buffer[1];
19026 submit_info.waitSemaphoreCount = 0;
19027 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
19028 submit_info.pWaitDstStageMask = flags;
19029 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
19030 }
19031
19032 vkQueueSubmit(m_device->m_queue, 0, NULL, fence);
19033
19034 VkResult err = vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
19035 ASSERT_VK_SUCCESS(err);
19036
19037 vkDestroyFence(m_device->device(), fence, nullptr);
19038 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
19039 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
19040
19041 m_errorMonitor->VerifyNotFound();
19042}
19043
19044// This is a positive test. No errors should be generated.
19045TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueOneFence) {
19046
19047 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
19048 "on the same queue, the second having a fence, followed "
19049 "by a WaitForFences call.");
19050
19051 m_errorMonitor->ExpectSuccess();
19052
19053 ASSERT_NO_FATAL_FAILURE(InitState());
19054 VkFence fence;
19055 VkFenceCreateInfo fence_create_info{};
19056 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
19057 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
19058
19059 VkCommandPool command_pool;
19060 VkCommandPoolCreateInfo pool_create_info{};
19061 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
19062 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
19063 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
19064 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
19065
19066 VkCommandBuffer command_buffer[2];
19067 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
19068 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
19069 command_buffer_allocate_info.commandPool = command_pool;
19070 command_buffer_allocate_info.commandBufferCount = 2;
19071 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
19072 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
19073
19074 {
19075 VkCommandBufferBeginInfo begin_info{};
19076 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19077 vkBeginCommandBuffer(command_buffer[0], &begin_info);
19078
19079 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
19080 nullptr, 0, nullptr, 0, nullptr);
19081
19082 VkViewport viewport{};
19083 viewport.maxDepth = 1.0f;
19084 viewport.minDepth = 0.0f;
19085 viewport.width = 512;
19086 viewport.height = 512;
19087 viewport.x = 0;
19088 viewport.y = 0;
19089 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
19090 vkEndCommandBuffer(command_buffer[0]);
19091 }
19092 {
19093 VkCommandBufferBeginInfo begin_info{};
19094 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19095 vkBeginCommandBuffer(command_buffer[1], &begin_info);
19096
19097 VkViewport viewport{};
19098 viewport.maxDepth = 1.0f;
19099 viewport.minDepth = 0.0f;
19100 viewport.width = 512;
19101 viewport.height = 512;
19102 viewport.x = 0;
19103 viewport.y = 0;
19104 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
19105 vkEndCommandBuffer(command_buffer[1]);
19106 }
19107 {
19108 VkSubmitInfo submit_info{};
19109 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19110 submit_info.commandBufferCount = 1;
19111 submit_info.pCommandBuffers = &command_buffer[0];
19112 submit_info.signalSemaphoreCount = 0;
19113 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
19114 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
19115 }
19116 {
19117 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
19118 VkSubmitInfo submit_info{};
19119 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19120 submit_info.commandBufferCount = 1;
19121 submit_info.pCommandBuffers = &command_buffer[1];
19122 submit_info.waitSemaphoreCount = 0;
19123 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
19124 submit_info.pWaitDstStageMask = flags;
19125 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
19126 }
19127
19128 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
19129
19130 vkDestroyFence(m_device->device(), fence, nullptr);
19131 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
19132 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
19133
19134 m_errorMonitor->VerifyNotFound();
19135}
19136
19137// This is a positive test. No errors should be generated.
19138TEST_F(VkPositiveLayerTest, TwoSubmitInfosWithSemaphoreOneQueueSubmitsOneFence) {
19139
19140 TEST_DESCRIPTION("Two command buffers each in a separate SubmitInfo sent in a single "
19141 "QueueSubmit call followed by a WaitForFences call.");
19142 ASSERT_NO_FATAL_FAILURE(InitState());
19143
19144 m_errorMonitor->ExpectSuccess();
19145
19146 VkFence fence;
19147 VkFenceCreateInfo fence_create_info{};
19148 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
19149 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
19150
19151 VkSemaphore semaphore;
19152 VkSemaphoreCreateInfo semaphore_create_info{};
19153 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
19154 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
19155
19156 VkCommandPool command_pool;
19157 VkCommandPoolCreateInfo pool_create_info{};
19158 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
19159 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
19160 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
19161 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
19162
19163 VkCommandBuffer command_buffer[2];
19164 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
19165 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
19166 command_buffer_allocate_info.commandPool = command_pool;
19167 command_buffer_allocate_info.commandBufferCount = 2;
19168 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
19169 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
19170
19171 {
19172 VkCommandBufferBeginInfo begin_info{};
19173 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19174 vkBeginCommandBuffer(command_buffer[0], &begin_info);
19175
19176 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
19177 nullptr, 0, nullptr, 0, nullptr);
19178
19179 VkViewport viewport{};
19180 viewport.maxDepth = 1.0f;
19181 viewport.minDepth = 0.0f;
19182 viewport.width = 512;
19183 viewport.height = 512;
19184 viewport.x = 0;
19185 viewport.y = 0;
19186 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
19187 vkEndCommandBuffer(command_buffer[0]);
19188 }
19189 {
19190 VkCommandBufferBeginInfo begin_info{};
19191 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19192 vkBeginCommandBuffer(command_buffer[1], &begin_info);
19193
19194 VkViewport viewport{};
19195 viewport.maxDepth = 1.0f;
19196 viewport.minDepth = 0.0f;
19197 viewport.width = 512;
19198 viewport.height = 512;
19199 viewport.x = 0;
19200 viewport.y = 0;
19201 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
19202 vkEndCommandBuffer(command_buffer[1]);
19203 }
19204 {
19205 VkSubmitInfo submit_info[2];
19206 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
19207
19208 submit_info[0].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19209 submit_info[0].pNext = NULL;
19210 submit_info[0].commandBufferCount = 1;
19211 submit_info[0].pCommandBuffers = &command_buffer[0];
19212 submit_info[0].signalSemaphoreCount = 1;
19213 submit_info[0].pSignalSemaphores = &semaphore;
19214 submit_info[0].waitSemaphoreCount = 0;
19215 submit_info[0].pWaitSemaphores = NULL;
19216 submit_info[0].pWaitDstStageMask = 0;
19217
19218 submit_info[1].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19219 submit_info[1].pNext = NULL;
19220 submit_info[1].commandBufferCount = 1;
19221 submit_info[1].pCommandBuffers = &command_buffer[1];
19222 submit_info[1].waitSemaphoreCount = 1;
19223 submit_info[1].pWaitSemaphores = &semaphore;
19224 submit_info[1].pWaitDstStageMask = flags;
19225 submit_info[1].signalSemaphoreCount = 0;
19226 submit_info[1].pSignalSemaphores = NULL;
19227 vkQueueSubmit(m_device->m_queue, 2, &submit_info[0], fence);
19228 }
19229
19230 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
19231
19232 vkDestroyFence(m_device->device(), fence, nullptr);
19233 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
19234 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
19235 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
19236
19237 m_errorMonitor->VerifyNotFound();
19238}
19239
19240TEST_F(VkPositiveLayerTest, RenderPassSecondaryCommandBuffersMultipleTimes) {
19241 m_errorMonitor->ExpectSuccess();
19242
19243 ASSERT_NO_FATAL_FAILURE(InitState());
19244 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19245
19246 BeginCommandBuffer(); // Framework implicitly begins the renderpass.
19247 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle()); // End implicit.
19248
19249 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
19250 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
19251 m_errorMonitor->VerifyNotFound();
19252 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
19253 m_errorMonitor->VerifyNotFound();
19254 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
19255 m_errorMonitor->VerifyNotFound();
19256
19257 m_commandBuffer->EndCommandBuffer();
19258 m_errorMonitor->VerifyNotFound();
19259}
19260
19261TEST_F(VkPositiveLayerTest, ValidRenderPassAttachmentLayoutWithLoadOp) {
19262 TEST_DESCRIPTION("Positive test where we create a renderpass with an "
19263 "attachment that uses LOAD_OP_CLEAR, the first subpass "
19264 "has a valid layout, and a second subpass then uses a "
19265 "valid *READ_ONLY* layout.");
19266 m_errorMonitor->ExpectSuccess();
19267 ASSERT_NO_FATAL_FAILURE(InitState());
19268
19269 VkAttachmentReference attach[2] = {};
19270 attach[0].attachment = 0;
19271 attach[0].layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
19272 attach[1].attachment = 0;
19273 attach[1].layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
19274 VkSubpassDescription subpasses[2] = {};
19275 // First subpass clears DS attach on load
19276 subpasses[0].pDepthStencilAttachment = &attach[0];
19277 // 2nd subpass reads in DS as input attachment
19278 subpasses[1].inputAttachmentCount = 1;
19279 subpasses[1].pInputAttachments = &attach[1];
19280 VkAttachmentDescription attach_desc = {};
19281 attach_desc.format = VK_FORMAT_D24_UNORM_S8_UINT;
19282 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
19283 attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
19284 attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
19285 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
19286 attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
19287 attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
19288 attach_desc.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
19289 VkRenderPassCreateInfo rpci = {};
19290 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
19291 rpci.attachmentCount = 1;
19292 rpci.pAttachments = &attach_desc;
19293 rpci.subpassCount = 2;
19294 rpci.pSubpasses = subpasses;
19295
19296 // Now create RenderPass and verify no errors
19297 VkRenderPass rp;
19298 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
19299 m_errorMonitor->VerifyNotFound();
19300
19301 vkDestroyRenderPass(m_device->device(), rp, NULL);
19302}
19303
19304TEST_F(VkPositiveLayerTest, CreatePipelineAttribMatrixType) {
19305 TEST_DESCRIPTION("Test that pipeline validation accepts matrices passed "
19306 "as vertex attributes");
19307 m_errorMonitor->ExpectSuccess();
19308
19309 ASSERT_NO_FATAL_FAILURE(InitState());
19310 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19311
19312 VkVertexInputBindingDescription input_binding;
19313 memset(&input_binding, 0, sizeof(input_binding));
19314
19315 VkVertexInputAttributeDescription input_attribs[2];
19316 memset(input_attribs, 0, sizeof(input_attribs));
19317
19318 for (int i = 0; i < 2; i++) {
19319 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
19320 input_attribs[i].location = i;
19321 }
19322
19323 char const *vsSource = "#version 450\n"
19324 "\n"
19325 "layout(location=0) in mat2x4 x;\n"
19326 "out gl_PerVertex {\n"
19327 " vec4 gl_Position;\n"
19328 "};\n"
19329 "void main(){\n"
19330 " gl_Position = x[0] + x[1];\n"
19331 "}\n";
19332 char const *fsSource = "#version 450\n"
19333 "\n"
19334 "layout(location=0) out vec4 color;\n"
19335 "void main(){\n"
19336 " color = vec4(1);\n"
19337 "}\n";
19338
19339 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19340 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19341
19342 VkPipelineObj pipe(m_device);
19343 pipe.AddColorAttachment();
19344 pipe.AddShader(&vs);
19345 pipe.AddShader(&fs);
19346
19347 pipe.AddVertexInputBindings(&input_binding, 1);
19348 pipe.AddVertexInputAttribs(input_attribs, 2);
19349
19350 VkDescriptorSetObj descriptorSet(m_device);
19351 descriptorSet.AppendDummy();
19352 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19353
19354 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
19355
19356 /* expect success */
19357 m_errorMonitor->VerifyNotFound();
19358}
19359
19360TEST_F(VkPositiveLayerTest, CreatePipelineAttribArrayType) {
19361 m_errorMonitor->ExpectSuccess();
19362
19363 ASSERT_NO_FATAL_FAILURE(InitState());
19364 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19365
19366 VkVertexInputBindingDescription input_binding;
19367 memset(&input_binding, 0, sizeof(input_binding));
19368
19369 VkVertexInputAttributeDescription input_attribs[2];
19370 memset(input_attribs, 0, sizeof(input_attribs));
19371
19372 for (int i = 0; i < 2; i++) {
19373 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
19374 input_attribs[i].location = i;
19375 }
19376
19377 char const *vsSource = "#version 450\n"
19378 "\n"
19379 "layout(location=0) in vec4 x[2];\n"
19380 "out gl_PerVertex {\n"
19381 " vec4 gl_Position;\n"
19382 "};\n"
19383 "void main(){\n"
19384 " gl_Position = x[0] + x[1];\n"
19385 "}\n";
19386 char const *fsSource = "#version 450\n"
19387 "\n"
19388 "layout(location=0) out vec4 color;\n"
19389 "void main(){\n"
19390 " color = vec4(1);\n"
19391 "}\n";
19392
19393 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19394 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19395
19396 VkPipelineObj pipe(m_device);
19397 pipe.AddColorAttachment();
19398 pipe.AddShader(&vs);
19399 pipe.AddShader(&fs);
19400
19401 pipe.AddVertexInputBindings(&input_binding, 1);
19402 pipe.AddVertexInputAttribs(input_attribs, 2);
19403
19404 VkDescriptorSetObj descriptorSet(m_device);
19405 descriptorSet.AppendDummy();
19406 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19407
19408 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
19409
19410 m_errorMonitor->VerifyNotFound();
19411}
19412
19413TEST_F(VkPositiveLayerTest, CreatePipelineAttribComponents) {
19414 TEST_DESCRIPTION("Test that pipeline validation accepts consuming a vertex attribute "
19415 "through multiple vertex shader inputs, each consuming a different "
19416 "subset of the components.");
19417 m_errorMonitor->ExpectSuccess();
19418
19419 ASSERT_NO_FATAL_FAILURE(InitState());
19420 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19421
19422 VkVertexInputBindingDescription input_binding;
19423 memset(&input_binding, 0, sizeof(input_binding));
19424
19425 VkVertexInputAttributeDescription input_attribs[3];
19426 memset(input_attribs, 0, sizeof(input_attribs));
19427
19428 for (int i = 0; i < 3; i++) {
19429 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
19430 input_attribs[i].location = i;
19431 }
19432
19433 char const *vsSource = "#version 450\n"
19434 "\n"
19435 "layout(location=0) in vec4 x;\n"
19436 "layout(location=1) in vec3 y1;\n"
19437 "layout(location=1, component=3) in float y2;\n"
19438 "layout(location=2) in vec4 z;\n"
19439 "out gl_PerVertex {\n"
19440 " vec4 gl_Position;\n"
19441 "};\n"
19442 "void main(){\n"
19443 " gl_Position = x + vec4(y1, y2) + z;\n"
19444 "}\n";
19445 char const *fsSource = "#version 450\n"
19446 "\n"
19447 "layout(location=0) out vec4 color;\n"
19448 "void main(){\n"
19449 " color = vec4(1);\n"
19450 "}\n";
19451
19452 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19453 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19454
19455 VkPipelineObj pipe(m_device);
19456 pipe.AddColorAttachment();
19457 pipe.AddShader(&vs);
19458 pipe.AddShader(&fs);
19459
19460 pipe.AddVertexInputBindings(&input_binding, 1);
19461 pipe.AddVertexInputAttribs(input_attribs, 3);
19462
19463 VkDescriptorSetObj descriptorSet(m_device);
19464 descriptorSet.AppendDummy();
19465 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19466
19467 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
19468
19469 m_errorMonitor->VerifyNotFound();
19470}
19471
19472TEST_F(VkPositiveLayerTest, CreatePipelineSimplePositive) {
19473 m_errorMonitor->ExpectSuccess();
19474
19475 ASSERT_NO_FATAL_FAILURE(InitState());
19476 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19477
19478 char const *vsSource = "#version 450\n"
19479 "out gl_PerVertex {\n"
19480 " vec4 gl_Position;\n"
19481 "};\n"
19482 "void main(){\n"
19483 " gl_Position = vec4(0);\n"
19484 "}\n";
19485 char const *fsSource = "#version 450\n"
19486 "\n"
19487 "layout(location=0) out vec4 color;\n"
19488 "void main(){\n"
19489 " color = vec4(1);\n"
19490 "}\n";
19491
19492 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19493 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19494
19495 VkPipelineObj pipe(m_device);
19496 pipe.AddColorAttachment();
19497 pipe.AddShader(&vs);
19498 pipe.AddShader(&fs);
19499
19500 VkDescriptorSetObj descriptorSet(m_device);
19501 descriptorSet.AppendDummy();
19502 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19503
19504 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
19505
19506 m_errorMonitor->VerifyNotFound();
19507}
19508
19509TEST_F(VkPositiveLayerTest, CreatePipelineRelaxedTypeMatch) {
19510 TEST_DESCRIPTION("Test that pipeline validation accepts the relaxed type matching rules "
19511 "set out in 14.1.3: fundamental type must match, and producer side must "
19512 "have at least as many components");
19513 m_errorMonitor->ExpectSuccess();
19514
19515 // VK 1.0.8 Specification, 14.1.3 "Additionally,..." block
19516
19517 ASSERT_NO_FATAL_FAILURE(InitState());
19518 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19519
19520 char const *vsSource = "#version 450\n"
19521 "out gl_PerVertex {\n"
19522 " vec4 gl_Position;\n"
19523 "};\n"
19524 "layout(location=0) out vec3 x;\n"
19525 "layout(location=1) out ivec3 y;\n"
19526 "layout(location=2) out vec3 z;\n"
19527 "void main(){\n"
19528 " gl_Position = vec4(0);\n"
19529 " x = vec3(0); y = ivec3(0); z = vec3(0);\n"
19530 "}\n";
19531 char const *fsSource = "#version 450\n"
19532 "\n"
19533 "layout(location=0) out vec4 color;\n"
19534 "layout(location=0) in float x;\n"
19535 "layout(location=1) flat in int y;\n"
19536 "layout(location=2) in vec2 z;\n"
19537 "void main(){\n"
19538 " color = vec4(1 + x + y + z.x);\n"
19539 "}\n";
19540
19541 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19542 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19543
19544 VkPipelineObj pipe(m_device);
19545 pipe.AddColorAttachment();
19546 pipe.AddShader(&vs);
19547 pipe.AddShader(&fs);
19548
19549 VkDescriptorSetObj descriptorSet(m_device);
19550 descriptorSet.AppendDummy();
19551 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19552
19553 VkResult err = VK_SUCCESS;
19554 err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
19555 ASSERT_VK_SUCCESS(err);
19556
19557 m_errorMonitor->VerifyNotFound();
19558}
19559
19560TEST_F(VkPositiveLayerTest, CreatePipelineTessPerVertex) {
19561 TEST_DESCRIPTION("Test that pipeline validation accepts per-vertex variables "
19562 "passed between the TCS and TES stages");
19563 m_errorMonitor->ExpectSuccess();
19564
19565 ASSERT_NO_FATAL_FAILURE(InitState());
19566 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19567
19568 if (!m_device->phy().features().tessellationShader) {
19569 printf("Device does not support tessellation shaders; skipped.\n");
19570 return;
19571 }
19572
19573 char const *vsSource = "#version 450\n"
19574 "void main(){}\n";
19575 char const *tcsSource = "#version 450\n"
19576 "layout(location=0) out int x[];\n"
19577 "layout(vertices=3) out;\n"
19578 "void main(){\n"
19579 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
19580 " gl_TessLevelInner[0] = 1;\n"
19581 " x[gl_InvocationID] = gl_InvocationID;\n"
19582 "}\n";
19583 char const *tesSource = "#version 450\n"
19584 "layout(triangles, equal_spacing, cw) in;\n"
19585 "layout(location=0) in int x[];\n"
19586 "out gl_PerVertex { vec4 gl_Position; };\n"
19587 "void main(){\n"
19588 " gl_Position.xyz = gl_TessCoord;\n"
19589 " gl_Position.w = x[0] + x[1] + x[2];\n"
19590 "}\n";
19591 char const *fsSource = "#version 450\n"
19592 "layout(location=0) out vec4 color;\n"
19593 "void main(){\n"
19594 " color = vec4(1);\n"
19595 "}\n";
19596
19597 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19598 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
19599 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
19600 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19601
19602 VkPipelineInputAssemblyStateCreateInfo iasci{ VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, nullptr, 0,
19603 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, VK_FALSE };
19604
19605 VkPipelineTessellationStateCreateInfo tsci{ VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, nullptr, 0, 3 };
19606
19607 VkPipelineObj pipe(m_device);
19608 pipe.SetInputAssembly(&iasci);
19609 pipe.SetTessellation(&tsci);
19610 pipe.AddColorAttachment();
19611 pipe.AddShader(&vs);
19612 pipe.AddShader(&tcs);
19613 pipe.AddShader(&tes);
19614 pipe.AddShader(&fs);
19615
19616 VkDescriptorSetObj descriptorSet(m_device);
19617 descriptorSet.AppendDummy();
19618 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19619
19620 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
19621
19622 m_errorMonitor->VerifyNotFound();
19623}
19624
19625TEST_F(VkPositiveLayerTest, CreatePipelineGeometryInputBlockPositive) {
19626 TEST_DESCRIPTION("Test that pipeline validation accepts a user-defined "
19627 "interface block passed into the geometry shader. This "
19628 "is interesting because the 'extra' array level is not "
19629 "present on the member type, but on the block instance.");
19630 m_errorMonitor->ExpectSuccess();
19631
19632 ASSERT_NO_FATAL_FAILURE(InitState());
19633 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19634
19635 if (!m_device->phy().features().geometryShader) {
19636 printf("Device does not support geometry shaders; skipped.\n");
19637 return;
19638 }
19639
19640 char const *vsSource = "#version 450\n"
19641 "layout(location=0) out VertexData { vec4 x; } vs_out;\n"
19642 "void main(){\n"
19643 " vs_out.x = vec4(1);\n"
19644 "}\n";
19645 char const *gsSource = "#version 450\n"
19646 "layout(triangles) in;\n"
19647 "layout(triangle_strip, max_vertices=3) out;\n"
19648 "layout(location=0) in VertexData { vec4 x; } gs_in[];\n"
19649 "out gl_PerVertex { vec4 gl_Position; };\n"
19650 "void main() {\n"
19651 " gl_Position = gs_in[0].x;\n"
19652 " EmitVertex();\n"
19653 "}\n";
19654 char const *fsSource = "#version 450\n"
19655 "layout(location=0) out vec4 color;\n"
19656 "void main(){\n"
19657 " color = vec4(1);\n"
19658 "}\n";
19659
19660 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19661 VkShaderObj gs(m_device, gsSource, VK_SHADER_STAGE_GEOMETRY_BIT, this);
19662 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19663
19664 VkPipelineObj pipe(m_device);
19665 pipe.AddColorAttachment();
19666 pipe.AddShader(&vs);
19667 pipe.AddShader(&gs);
19668 pipe.AddShader(&fs);
19669
19670 VkDescriptorSetObj descriptorSet(m_device);
19671 descriptorSet.AppendDummy();
19672 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19673
19674 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
19675
19676 m_errorMonitor->VerifyNotFound();
19677}
19678
19679TEST_F(VkPositiveLayerTest, CreatePipeline64BitAttributesPositive) {
19680 TEST_DESCRIPTION("Test that pipeline validation accepts basic use of 64bit vertex "
19681 "attributes. This is interesting because they consume multiple "
19682 "locations.");
19683 m_errorMonitor->ExpectSuccess();
19684
19685 ASSERT_NO_FATAL_FAILURE(InitState());
19686 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19687
19688 if (!m_device->phy().features().shaderFloat64) {
19689 printf("Device does not support 64bit vertex attributes; skipped.\n");
19690 return;
19691 }
19692
19693 VkVertexInputBindingDescription input_bindings[1];
19694 memset(input_bindings, 0, sizeof(input_bindings));
19695
19696 VkVertexInputAttributeDescription input_attribs[4];
19697 memset(input_attribs, 0, sizeof(input_attribs));
19698 input_attribs[0].location = 0;
19699 input_attribs[0].offset = 0;
19700 input_attribs[0].format = VK_FORMAT_R64G64B64A64_SFLOAT;
19701 input_attribs[1].location = 2;
19702 input_attribs[1].offset = 32;
19703 input_attribs[1].format = VK_FORMAT_R64G64B64A64_SFLOAT;
19704 input_attribs[2].location = 4;
19705 input_attribs[2].offset = 64;
19706 input_attribs[2].format = VK_FORMAT_R64G64B64A64_SFLOAT;
19707 input_attribs[3].location = 6;
19708 input_attribs[3].offset = 96;
19709 input_attribs[3].format = VK_FORMAT_R64G64B64A64_SFLOAT;
19710
19711 char const *vsSource = "#version 450\n"
19712 "\n"
19713 "layout(location=0) in dmat4 x;\n"
19714 "out gl_PerVertex {\n"
19715 " vec4 gl_Position;\n"
19716 "};\n"
19717 "void main(){\n"
19718 " gl_Position = vec4(x[0][0]);\n"
19719 "}\n";
19720 char const *fsSource = "#version 450\n"
19721 "\n"
19722 "layout(location=0) out vec4 color;\n"
19723 "void main(){\n"
19724 " color = vec4(1);\n"
19725 "}\n";
19726
19727 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19728 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19729
19730 VkPipelineObj pipe(m_device);
19731 pipe.AddColorAttachment();
19732 pipe.AddShader(&vs);
19733 pipe.AddShader(&fs);
19734
19735 pipe.AddVertexInputBindings(input_bindings, 1);
19736 pipe.AddVertexInputAttribs(input_attribs, 4);
19737
19738 VkDescriptorSetObj descriptorSet(m_device);
19739 descriptorSet.AppendDummy();
19740 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19741
19742 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
19743
19744 m_errorMonitor->VerifyNotFound();
19745}
19746
19747TEST_F(VkPositiveLayerTest, CreatePipelineInputAttachmentPositive) {
19748 TEST_DESCRIPTION("Positive test for a correctly matched input attachment");
19749 m_errorMonitor->ExpectSuccess();
19750
19751 ASSERT_NO_FATAL_FAILURE(InitState());
19752
19753 char const *vsSource = "#version 450\n"
19754 "\n"
19755 "out gl_PerVertex {\n"
19756 " vec4 gl_Position;\n"
19757 "};\n"
19758 "void main(){\n"
19759 " gl_Position = vec4(1);\n"
19760 "}\n";
19761 char const *fsSource = "#version 450\n"
19762 "\n"
19763 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
19764 "layout(location=0) out vec4 color;\n"
19765 "void main() {\n"
19766 " color = subpassLoad(x);\n"
19767 "}\n";
19768
19769 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19770 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19771
19772 VkPipelineObj pipe(m_device);
19773 pipe.AddShader(&vs);
19774 pipe.AddShader(&fs);
19775 pipe.AddColorAttachment();
19776 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19777
19778 VkDescriptorSetLayoutBinding dslb = { 0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr };
19779 VkDescriptorSetLayoutCreateInfo dslci = { VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb };
19780 VkDescriptorSetLayout dsl;
19781 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
19782 ASSERT_VK_SUCCESS(err);
19783
19784 VkPipelineLayoutCreateInfo plci = { VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr };
19785 VkPipelineLayout pl;
19786 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
19787 ASSERT_VK_SUCCESS(err);
19788
19789 VkAttachmentDescription descs[2] = {
19790 { 0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
19791 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
19792 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL },
19793 { 0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
19794 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_GENERAL, VK_IMAGE_LAYOUT_GENERAL },
19795 };
19796 VkAttachmentReference color = {
19797 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
19798 };
19799 VkAttachmentReference input = {
19800 1, VK_IMAGE_LAYOUT_GENERAL,
19801 };
19802
19803 VkSubpassDescription sd = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 1, &input, 1, &color, nullptr, nullptr, 0, nullptr };
19804
19805 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, descs, 1, &sd, 0, nullptr };
19806 VkRenderPass rp;
19807 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
19808 ASSERT_VK_SUCCESS(err);
19809
19810 // should be OK. would go wrong here if it's going to...
19811 pipe.CreateVKPipeline(pl, rp);
19812
19813 m_errorMonitor->VerifyNotFound();
19814
19815 vkDestroyRenderPass(m_device->device(), rp, nullptr);
19816 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
19817 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
19818}
19819
19820TEST_F(VkPositiveLayerTest, CreateComputePipelineMissingDescriptorUnusedPositive) {
19821 TEST_DESCRIPTION("Test that pipeline validation accepts a compute pipeline which declares a "
19822 "descriptor-backed resource which is not provided, but the shader does not "
19823 "statically use it. This is interesting because it requires compute pipelines "
19824 "to have a proper descriptor use walk, which they didn't for some time.");
19825 m_errorMonitor->ExpectSuccess();
19826
19827 ASSERT_NO_FATAL_FAILURE(InitState());
19828
19829 char const *csSource = "#version 450\n"
19830 "\n"
19831 "layout(local_size_x=1) in;\n"
19832 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
19833 "void main(){\n"
19834 " // x is not used.\n"
19835 "}\n";
19836
19837 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
19838
19839 VkDescriptorSetObj descriptorSet(m_device);
19840 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19841
19842 VkComputePipelineCreateInfo cpci = { VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
19843 nullptr,
19844 0,
19845 { VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
19846 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr },
19847 descriptorSet.GetPipelineLayout(),
19848 VK_NULL_HANDLE,
19849 -1 };
19850
19851 VkPipeline pipe;
19852 VkResult err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
19853
19854 m_errorMonitor->VerifyNotFound();
19855
19856 if (err == VK_SUCCESS) {
19857 vkDestroyPipeline(m_device->device(), pipe, nullptr);
19858 }
19859}
19860
19861TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsSampler) {
19862 TEST_DESCRIPTION("Test that pipeline validation accepts a shader consuming only the "
19863 "sampler portion of a combined image + sampler");
19864 m_errorMonitor->ExpectSuccess();
19865
19866 ASSERT_NO_FATAL_FAILURE(InitState());
19867
19868 VkDescriptorSetLayoutBinding bindings[] = {
19869 { 0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
19870 { 1, VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
19871 { 2, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
19872 };
19873 VkDescriptorSetLayoutCreateInfo dslci = { VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 3, bindings };
19874 VkDescriptorSetLayout dsl;
19875 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
19876 ASSERT_VK_SUCCESS(err);
19877
19878 VkPipelineLayoutCreateInfo plci = { VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr };
19879 VkPipelineLayout pl;
19880 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
19881 ASSERT_VK_SUCCESS(err);
19882
19883 char const *csSource = "#version 450\n"
19884 "\n"
19885 "layout(local_size_x=1) in;\n"
19886 "layout(set=0, binding=0) uniform sampler s;\n"
19887 "layout(set=0, binding=1) uniform texture2D t;\n"
19888 "layout(set=0, binding=2) buffer block { vec4 x; };\n"
19889 "void main() {\n"
19890 " x = texture(sampler2D(t, s), vec2(0));\n"
19891 "}\n";
19892 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
19893
19894 VkComputePipelineCreateInfo cpci = { VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
19895 nullptr,
19896 0,
19897 { VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
19898 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr },
19899 pl,
19900 VK_NULL_HANDLE,
19901 -1 };
19902
19903 VkPipeline pipe;
19904 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
19905
19906 m_errorMonitor->VerifyNotFound();
19907
19908 if (err == VK_SUCCESS) {
19909 vkDestroyPipeline(m_device->device(), pipe, nullptr);
19910 }
19911
19912 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
19913 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
19914}
19915
19916TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsImage) {
19917 TEST_DESCRIPTION("Test that pipeline validation accepts a shader consuming only the "
19918 "image portion of a combined image + sampler");
19919 m_errorMonitor->ExpectSuccess();
19920
19921 ASSERT_NO_FATAL_FAILURE(InitState());
19922
19923 VkDescriptorSetLayoutBinding bindings[] = {
19924 { 0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
19925 { 1, VK_DESCRIPTOR_TYPE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
19926 { 2, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
19927 };
19928 VkDescriptorSetLayoutCreateInfo dslci = { VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 3, bindings };
19929 VkDescriptorSetLayout dsl;
19930 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
19931 ASSERT_VK_SUCCESS(err);
19932
19933 VkPipelineLayoutCreateInfo plci = { VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr };
19934 VkPipelineLayout pl;
19935 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
19936 ASSERT_VK_SUCCESS(err);
19937
19938 char const *csSource = "#version 450\n"
19939 "\n"
19940 "layout(local_size_x=1) in;\n"
19941 "layout(set=0, binding=0) uniform texture2D t;\n"
19942 "layout(set=0, binding=1) uniform sampler s;\n"
19943 "layout(set=0, binding=2) buffer block { vec4 x; };\n"
19944 "void main() {\n"
19945 " x = texture(sampler2D(t, s), vec2(0));\n"
19946 "}\n";
19947 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
19948
19949 VkComputePipelineCreateInfo cpci = { VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
19950 nullptr,
19951 0,
19952 { VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
19953 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr },
19954 pl,
19955 VK_NULL_HANDLE,
19956 -1 };
19957
19958 VkPipeline pipe;
19959 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
19960
19961 m_errorMonitor->VerifyNotFound();
19962
19963 if (err == VK_SUCCESS) {
19964 vkDestroyPipeline(m_device->device(), pipe, nullptr);
19965 }
19966
19967 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
19968 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
19969}
19970
19971TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsBoth) {
19972 TEST_DESCRIPTION("Test that pipeline validation accepts a shader consuming "
19973 "both the sampler and the image of a combined image+sampler "
19974 "but via separate variables");
19975 m_errorMonitor->ExpectSuccess();
19976
19977 ASSERT_NO_FATAL_FAILURE(InitState());
19978
19979 VkDescriptorSetLayoutBinding bindings[] = {
19980 { 0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
19981 { 1, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
19982 };
19983 VkDescriptorSetLayoutCreateInfo dslci = { VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 2, bindings };
19984 VkDescriptorSetLayout dsl;
19985 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
19986 ASSERT_VK_SUCCESS(err);
19987
19988 VkPipelineLayoutCreateInfo plci = { VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr };
19989 VkPipelineLayout pl;
19990 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
19991 ASSERT_VK_SUCCESS(err);
19992
19993 char const *csSource = "#version 450\n"
19994 "\n"
19995 "layout(local_size_x=1) in;\n"
19996 "layout(set=0, binding=0) uniform texture2D t;\n"
19997 "layout(set=0, binding=0) uniform sampler s; // both binding 0!\n"
19998 "layout(set=0, binding=1) buffer block { vec4 x; };\n"
19999 "void main() {\n"
20000 " x = texture(sampler2D(t, s), vec2(0));\n"
20001 "}\n";
20002 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
20003
20004 VkComputePipelineCreateInfo cpci = { VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
20005 nullptr,
20006 0,
20007 { VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
20008 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr },
20009 pl,
20010 VK_NULL_HANDLE,
20011 -1 };
20012
20013 VkPipeline pipe;
20014 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
20015
20016 m_errorMonitor->VerifyNotFound();
20017
20018 if (err == VK_SUCCESS) {
20019 vkDestroyPipeline(m_device->device(), pipe, nullptr);
20020 }
20021
20022 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
20023 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
20024}
20025
20026TEST_F(VkPositiveLayerTest, ValidStructPNext) {
20027 TEST_DESCRIPTION("Verify that a valid pNext value is handled correctly");
20028
20029 ASSERT_NO_FATAL_FAILURE(InitState());
20030
20031 // Positive test to check parameter_validation and unique_objects support
20032 // for NV_dedicated_allocation
20033 uint32_t extension_count = 0;
20034 bool supports_nv_dedicated_allocation = false;
20035 VkResult err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, nullptr);
20036 ASSERT_VK_SUCCESS(err);
20037
20038 if (extension_count > 0) {
20039 std::vector<VkExtensionProperties> available_extensions(extension_count);
20040
20041 err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, &available_extensions[0]);
20042 ASSERT_VK_SUCCESS(err);
20043
20044 for (const auto &extension_props : available_extensions) {
20045 if (strcmp(extension_props.extensionName, VK_NV_DEDICATED_ALLOCATION_EXTENSION_NAME) == 0) {
20046 supports_nv_dedicated_allocation = true;
20047 }
20048 }
20049 }
20050
20051 if (supports_nv_dedicated_allocation) {
20052 m_errorMonitor->ExpectSuccess();
20053
20054 VkDedicatedAllocationBufferCreateInfoNV dedicated_buffer_create_info = {};
20055 dedicated_buffer_create_info.sType = VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_BUFFER_CREATE_INFO_NV;
20056 dedicated_buffer_create_info.pNext = nullptr;
20057 dedicated_buffer_create_info.dedicatedAllocation = VK_TRUE;
20058
20059 uint32_t queue_family_index = 0;
20060 VkBufferCreateInfo buffer_create_info = {};
20061 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
20062 buffer_create_info.pNext = &dedicated_buffer_create_info;
20063 buffer_create_info.size = 1024;
20064 buffer_create_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
20065 buffer_create_info.queueFamilyIndexCount = 1;
20066 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
20067
20068 VkBuffer buffer;
20069 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
20070 ASSERT_VK_SUCCESS(err);
20071
20072 VkMemoryRequirements memory_reqs;
20073 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
20074
20075 VkDedicatedAllocationMemoryAllocateInfoNV dedicated_memory_info = {};
20076 dedicated_memory_info.sType = VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_MEMORY_ALLOCATE_INFO_NV;
20077 dedicated_memory_info.pNext = nullptr;
20078 dedicated_memory_info.buffer = buffer;
20079 dedicated_memory_info.image = VK_NULL_HANDLE;
20080
20081 VkMemoryAllocateInfo memory_info = {};
20082 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
20083 memory_info.pNext = &dedicated_memory_info;
20084 memory_info.allocationSize = memory_reqs.size;
20085
20086 bool pass;
20087 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
20088 ASSERT_TRUE(pass);
20089
20090 VkDeviceMemory buffer_memory;
20091 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
20092 ASSERT_VK_SUCCESS(err);
20093
20094 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
20095 ASSERT_VK_SUCCESS(err);
20096
20097 vkDestroyBuffer(m_device->device(), buffer, NULL);
20098 vkFreeMemory(m_device->device(), buffer_memory, NULL);
20099
20100 m_errorMonitor->VerifyNotFound();
20101 }
20102}
20103
20104TEST_F(VkPositiveLayerTest, PSOPolygonModeValid) {
20105 VkResult err;
20106
20107 TEST_DESCRIPTION("Verify that using a solid polygon fill mode works correctly.");
20108
20109 ASSERT_NO_FATAL_FAILURE(InitState());
20110 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
20111
20112 std::vector<const char *> device_extension_names;
20113 auto features = m_device->phy().features();
20114 // Artificially disable support for non-solid fill modes
20115 features.fillModeNonSolid = false;
20116 // The sacrificial device object
20117 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
20118
20119 VkRenderpassObj render_pass(&test_device);
20120
20121 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
20122 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
20123 pipeline_layout_ci.setLayoutCount = 0;
20124 pipeline_layout_ci.pSetLayouts = NULL;
20125
20126 VkPipelineLayout pipeline_layout;
20127 err = vkCreatePipelineLayout(test_device.device(), &pipeline_layout_ci, NULL, &pipeline_layout);
20128 ASSERT_VK_SUCCESS(err);
20129
20130 VkPipelineRasterizationStateCreateInfo rs_ci = {};
20131 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
20132 rs_ci.pNext = nullptr;
20133 rs_ci.lineWidth = 1.0f;
20134 rs_ci.rasterizerDiscardEnable = true;
20135
20136 VkShaderObj vs(&test_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
20137 VkShaderObj fs(&test_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
20138
20139 // Set polygonMode=FILL. No error is expected
20140 m_errorMonitor->ExpectSuccess();
20141 {
20142 VkPipelineObj pipe(&test_device);
20143 pipe.AddShader(&vs);
20144 pipe.AddShader(&fs);
20145 pipe.AddColorAttachment();
20146 // Set polygonMode to a good value
20147 rs_ci.polygonMode = VK_POLYGON_MODE_FILL;
20148 pipe.SetRasterization(&rs_ci);
20149 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
20150 }
20151 m_errorMonitor->VerifyNotFound();
20152
20153 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, NULL);
20154}
20155
20156TEST_F(VkPositiveLayerTest, ValidPushConstants) {
20157 VkResult err;
20158 ASSERT_NO_FATAL_FAILURE(InitState());
20159 ASSERT_NO_FATAL_FAILURE(InitViewport());
20160 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
20161
20162 VkPipelineLayout pipeline_layout;
20163 VkPushConstantRange pc_range = {};
20164 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
20165 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
20166 pipeline_layout_ci.pushConstantRangeCount = 1;
20167 pipeline_layout_ci.pPushConstantRanges = &pc_range;
20168
20169 //
20170 // Check for invalid push constant ranges in pipeline layouts.
20171 //
20172 struct PipelineLayoutTestCase {
20173 VkPushConstantRange const range;
20174 char const *msg;
20175 };
20176
20177 // Check for overlapping ranges
20178 const uint32_t ranges_per_test = 5;
20179 struct OverlappingRangeTestCase {
20180 VkPushConstantRange const ranges[ranges_per_test];
20181 char const *msg;
20182 };
20183
20184 // Run some positive tests to make sure overlap checking in the layer is OK
20185 const std::array<OverlappingRangeTestCase, 2> overlapping_range_tests_pos = { { { { { VK_SHADER_STAGE_VERTEX_BIT, 0, 4 },
20186 { VK_SHADER_STAGE_VERTEX_BIT, 4, 4 },
20187 { VK_SHADER_STAGE_VERTEX_BIT, 8, 4 },
20188 { VK_SHADER_STAGE_VERTEX_BIT, 12, 4 },
20189 { VK_SHADER_STAGE_VERTEX_BIT, 16, 4 } },
20190 "" },
20191 { { { VK_SHADER_STAGE_VERTEX_BIT, 92, 24 },
20192 { VK_SHADER_STAGE_VERTEX_BIT, 80, 4 },
20193 { VK_SHADER_STAGE_VERTEX_BIT, 64, 8 },
20194 { VK_SHADER_STAGE_VERTEX_BIT, 4, 16 },
20195 { VK_SHADER_STAGE_VERTEX_BIT, 0, 4 } },
20196 "" } } };
20197 for (const auto &iter : overlapping_range_tests_pos) {
20198 pipeline_layout_ci.pPushConstantRanges = iter.ranges;
20199 m_errorMonitor->ExpectSuccess();
20200 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
20201 m_errorMonitor->VerifyNotFound();
20202 if (VK_SUCCESS == err) {
20203 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
20204 }
20205 }
20206
20207 //
20208 // CmdPushConstants tests
20209 //
20210 const uint8_t dummy_values[100] = {};
20211
20212 BeginCommandBuffer();
20213
20214 // positive overlapping range tests with cmd
20215 const std::array<PipelineLayoutTestCase, 4> cmd_overlap_tests_pos = { {
20216 { { VK_SHADER_STAGE_VERTEX_BIT, 0, 16 }, "" },
20217 { { VK_SHADER_STAGE_VERTEX_BIT, 0, 4 }, "" },
20218 { { VK_SHADER_STAGE_VERTEX_BIT, 20, 12 }, "" },
20219 { { VK_SHADER_STAGE_VERTEX_BIT, 56, 36 }, "" },
20220 } };
20221
20222 // Setup ranges: [0,16) [20,36) [36,44) [44,52) [56,80) [80,92)
20223 const VkPushConstantRange pc_range4[] = {
20224 { VK_SHADER_STAGE_VERTEX_BIT, 20, 16 },{ VK_SHADER_STAGE_VERTEX_BIT, 0, 16 },{ VK_SHADER_STAGE_VERTEX_BIT, 44, 8 },
20225 { VK_SHADER_STAGE_VERTEX_BIT, 80, 12 },{ VK_SHADER_STAGE_VERTEX_BIT, 36, 8 },{ VK_SHADER_STAGE_VERTEX_BIT, 56, 24 },
20226 };
20227
20228 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range4) / sizeof(VkPushConstantRange);
20229 pipeline_layout_ci.pPushConstantRanges = pc_range4;
20230 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
20231 ASSERT_VK_SUCCESS(err);
20232 for (const auto &iter : cmd_overlap_tests_pos) {
20233 m_errorMonitor->ExpectSuccess();
20234 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.range.stageFlags, iter.range.offset,
20235 iter.range.size, dummy_values);
20236 m_errorMonitor->VerifyNotFound();
20237 }
20238 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
20239
20240 EndCommandBuffer();
20241}
20242
20243
20244
20245
20246
20247
20248
20249#if 0 // A few devices have issues with this test so disabling for now
20250TEST_F(VkPositiveLayerTest, LongFenceChain)
20251{
20252 m_errorMonitor->ExpectSuccess();
20253
20254 ASSERT_NO_FATAL_FAILURE(InitState());
20255 VkResult err;
20256
20257 std::vector<VkFence> fences;
20258
20259 const int chainLength = 32768;
20260
20261 for (int i = 0; i < chainLength; i++) {
20262 VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
20263 VkFence fence;
20264 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
20265 ASSERT_VK_SUCCESS(err);
20266
20267 fences.push_back(fence);
20268
20269 VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr,
20270 0, nullptr, 0, nullptr };
20271 err = vkQueueSubmit(m_device->m_queue, 1, &si, fence);
20272 ASSERT_VK_SUCCESS(err);
20273
20274 }
20275
20276 // BOOM, stack overflow.
20277 vkWaitForFences(m_device->device(), 1, &fences.back(), VK_TRUE, UINT64_MAX);
20278
20279 for (auto fence : fences)
20280 vkDestroyFence(m_device->device(), fence, nullptr);
20281
20282 m_errorMonitor->VerifyNotFound();
20283}
20284#endif
20285
20286
Cody Northrop1242dfd2016-07-13 17:24:59 -060020287#if defined(ANDROID) && defined(VALIDATION_APK)
20288static bool initialized = false;
20289static bool active = false;
20290
20291// Convert Intents to argv
20292// Ported from Hologram sample, only difference is flexible key
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020293std::vector<std::string> get_args(android_app &app, const char *intent_extra_data_key) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060020294 std::vector<std::string> args;
20295 JavaVM &vm = *app.activity->vm;
20296 JNIEnv *p_env;
20297 if (vm.AttachCurrentThread(&p_env, nullptr) != JNI_OK)
20298 return args;
20299
20300 JNIEnv &env = *p_env;
20301 jobject activity = app.activity->clazz;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020302 jmethodID get_intent_method = env.GetMethodID(env.GetObjectClass(activity), "getIntent", "()Landroid/content/Intent;");
Cody Northrop1242dfd2016-07-13 17:24:59 -060020303 jobject intent = env.CallObjectMethod(activity, get_intent_method);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020304 jmethodID get_string_extra_method =
20305 env.GetMethodID(env.GetObjectClass(intent), "getStringExtra", "(Ljava/lang/String;)Ljava/lang/String;");
Cody Northrop1242dfd2016-07-13 17:24:59 -060020306 jvalue get_string_extra_args;
20307 get_string_extra_args.l = env.NewStringUTF(intent_extra_data_key);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020308 jstring extra_str = static_cast<jstring>(env.CallObjectMethodA(intent, get_string_extra_method, &get_string_extra_args));
Cody Northrop1242dfd2016-07-13 17:24:59 -060020309
20310 std::string args_str;
20311 if (extra_str) {
20312 const char *extra_utf = env.GetStringUTFChars(extra_str, nullptr);
20313 args_str = extra_utf;
20314 env.ReleaseStringUTFChars(extra_str, extra_utf);
20315 env.DeleteLocalRef(extra_str);
20316 }
20317
20318 env.DeleteLocalRef(get_string_extra_args.l);
20319 env.DeleteLocalRef(intent);
20320 vm.DetachCurrentThread();
20321
20322 // split args_str
20323 std::stringstream ss(args_str);
20324 std::string arg;
20325 while (std::getline(ss, arg, ' ')) {
20326 if (!arg.empty())
20327 args.push_back(arg);
20328 }
20329
20330 return args;
20331}
20332
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020333static int32_t processInput(struct android_app *app, AInputEvent *event) { return 0; }
Cody Northrop1242dfd2016-07-13 17:24:59 -060020334
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020335static void processCommand(struct android_app *app, int32_t cmd) {
20336 switch (cmd) {
20337 case APP_CMD_INIT_WINDOW: {
20338 if (app->window) {
20339 initialized = true;
Cody Northrop1242dfd2016-07-13 17:24:59 -060020340 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020341 break;
20342 }
20343 case APP_CMD_GAINED_FOCUS: {
20344 active = true;
20345 break;
20346 }
20347 case APP_CMD_LOST_FOCUS: {
20348 active = false;
20349 break;
20350 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060020351 }
20352}
20353
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020354void android_main(struct android_app *app) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060020355 app_dummy();
20356
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020357 const char *appTag = "VulkanLayerValidationTests";
Cody Northrop1242dfd2016-07-13 17:24:59 -060020358
20359 int vulkanSupport = InitVulkan();
20360 if (vulkanSupport == 0) {
20361 __android_log_print(ANDROID_LOG_INFO, appTag, "==== FAILED ==== No Vulkan support found");
20362 return;
20363 }
20364
20365 app->onAppCmd = processCommand;
20366 app->onInputEvent = processInput;
20367
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020368 while (1) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060020369 int events;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020370 struct android_poll_source *source;
20371 while (ALooper_pollAll(active ? 0 : -1, NULL, &events, (void **)&source) >= 0) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060020372 if (source) {
20373 source->process(app, source);
20374 }
20375
20376 if (app->destroyRequested != 0) {
20377 VkTestFramework::Finish();
20378 return;
20379 }
20380 }
20381
20382 if (initialized && active) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020383 // Use the following key to send arguments to gtest, i.e.
20384 // --es args "--gtest_filter=-VkLayerTest.foo"
20385 const char key[] = "args";
20386 std::vector<std::string> args = get_args(*app, key);
Cody Northrop1242dfd2016-07-13 17:24:59 -060020387
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020388 std::string filter = "";
20389 if (args.size() > 0) {
20390 __android_log_print(ANDROID_LOG_INFO, appTag, "Intent args = %s", args[0].c_str());
20391 filter += args[0];
20392 } else {
20393 __android_log_print(ANDROID_LOG_INFO, appTag, "No Intent args detected");
20394 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060020395
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020396 int argc = 2;
20397 char *argv[] = {(char *)"foo", (char *)filter.c_str()};
20398 __android_log_print(ANDROID_LOG_DEBUG, appTag, "filter = %s", argv[1]);
Cody Northrop1242dfd2016-07-13 17:24:59 -060020399
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020400 // Route output to files until we can override the gtest output
20401 freopen("/sdcard/Android/data/com.example.VulkanLayerValidationTests/files/out.txt", "w", stdout);
20402 freopen("/sdcard/Android/data/com.example.VulkanLayerValidationTests/files/err.txt", "w", stderr);
Cody Northrop1242dfd2016-07-13 17:24:59 -060020403
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020404 ::testing::InitGoogleTest(&argc, argv);
20405 VkTestFramework::InitArgs(&argc, argv);
20406 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
Cody Northrop1242dfd2016-07-13 17:24:59 -060020407
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020408 int result = RUN_ALL_TESTS();
Cody Northrop1242dfd2016-07-13 17:24:59 -060020409
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020410 if (result != 0) {
20411 __android_log_print(ANDROID_LOG_INFO, appTag, "==== Tests FAILED ====");
20412 } else {
20413 __android_log_print(ANDROID_LOG_INFO, appTag, "==== Tests PASSED ====");
20414 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060020415
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020416 VkTestFramework::Finish();
Cody Northrop1242dfd2016-07-13 17:24:59 -060020417
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020418 fclose(stdout);
20419 fclose(stderr);
Cody Northrop1242dfd2016-07-13 17:24:59 -060020420
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020421 ANativeActivity_finish(app->activity);
Cody Northrop1242dfd2016-07-13 17:24:59 -060020422
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020423 return;
Cody Northrop1242dfd2016-07-13 17:24:59 -060020424 }
20425 }
20426}
20427#endif
20428
Tony Barbour300a6082015-04-07 13:44:53 -060020429int main(int argc, char **argv) {
20430 int result;
20431
Cody Northrop8e54a402016-03-08 22:25:52 -070020432#ifdef ANDROID
20433 int vulkanSupport = InitVulkan();
20434 if (vulkanSupport == 0)
20435 return 1;
20436#endif
20437
Tony Barbour300a6082015-04-07 13:44:53 -060020438 ::testing::InitGoogleTest(&argc, argv);
Tony Barbour6918cd52015-04-09 12:58:51 -060020439 VkTestFramework::InitArgs(&argc, argv);
Tony Barbour300a6082015-04-07 13:44:53 -060020440
20441 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
20442
20443 result = RUN_ALL_TESTS();
20444
Tony Barbour6918cd52015-04-09 12:58:51 -060020445 VkTestFramework::Finish();
Tony Barbour300a6082015-04-07 13:44:53 -060020446 return result;
20447}