blob: 19cad5758d3c5ba24cdba1b3ce8ac41d9058b19d [file] [log] [blame]
Karl Schultz6addd812016-02-02 17:17:23 -07001/*
2 * Copyright (c) 2015-2016 The Khronos Group Inc.
3 * Copyright (c) 2015-2016 Valve Corporation
4 * Copyright (c) 2015-2016 LunarG, Inc.
Michael Lentine0a369f62016-02-03 16:51:46 -06005 * Copyright (c) 2015-2016 Google, Inc.
Karl Schultz6addd812016-02-02 17:17:23 -07006 *
Jon Ashburn3ebf1252016-04-19 11:30:31 -06007 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
Karl Schultz6addd812016-02-02 17:17:23 -070010 *
Jon Ashburn3ebf1252016-04-19 11:30:31 -060011 * http://www.apache.org/licenses/LICENSE-2.0
Karl Schultz6addd812016-02-02 17:17:23 -070012 *
13 * Author: Chia-I Wu <olvaffe@gmail.com>
14 * Author: Chris Forbes <chrisf@ijw.co.nz>
15 * Author: Courtney Goeltzenleuchter <courtney@LunarG.com>
16 * Author: Mark Lobodzinski <mark@lunarg.com>
17 * Author: Mike Stroyan <mike@LunarG.com>
18 * Author: Tobin Ehlis <tobine@google.com>
19 * Author: Tony Barbour <tony@LunarG.com>
Cody Northrop1242dfd2016-07-13 17:24:59 -060020 * Author: Cody Northrop <cnorthrop@google.com>
Karl Schultz6addd812016-02-02 17:17:23 -070021 */
Tony Barbour65c48b32015-11-17 10:02:56 -070022
Cody Northrop8e54a402016-03-08 22:25:52 -070023#ifdef ANDROID
24#include "vulkan_wrapper.h"
25#else
David Pinedo9316d3b2015-11-06 12:54:48 -070026#include <vulkan/vulkan.h>
Cody Northrop8e54a402016-03-08 22:25:52 -070027#endif
Cody Northrop1242dfd2016-07-13 17:24:59 -060028
29#if defined(ANDROID) && defined(VALIDATION_APK)
30#include <android/log.h>
31#include <android_native_app_glue.h>
32#endif
33
Jon Ashburn7fa7e222016-02-02 12:08:10 -070034#include "icd-spv.h"
Mark Lobodzinskice751c62016-09-08 10:45:35 -060035#include "test_common.h"
36#include "vk_layer_config.h"
Mark Lobodzinski629d47b2016-10-18 13:34:58 -060037#include "vk_validation_error_messages.h"
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060038#include "vkrenderframework.h"
39#include <limits.h>
40#include <unordered_set>
Tony Barbour300a6082015-04-07 13:44:53 -060041
Mark Lobodzinski3780e142015-05-14 15:08:13 -050042#define GLM_FORCE_RADIANS
43#include "glm/glm.hpp"
44#include <glm/gtc/matrix_transform.hpp>
45
Dustin Gravesffa90fa2016-05-06 11:20:38 -060046#define PARAMETER_VALIDATION_TESTS 1
Tobin Ehlis0788f522015-05-26 16:11:58 -060047#define MEM_TRACKER_TESTS 1
48#define OBJ_TRACKER_TESTS 1
49#define DRAW_STATE_TESTS 1
50#define THREADING_TESTS 1
Chris Forbes9f7ff632015-05-25 11:13:08 +120051#define SHADER_CHECKER_TESTS 1
Mark Lobodzinski209b5292015-09-17 09:44:05 -060052#define DEVICE_LIMITS_TESTS 1
Tobin Ehliscde08892015-09-22 10:11:37 -060053#define IMAGE_TESTS 1
Tobin Ehlis0788f522015-05-26 16:11:58 -060054
Mark Lobodzinski3780e142015-05-14 15:08:13 -050055//--------------------------------------------------------------------------------------
56// Mesh and VertexFormat Data
57//--------------------------------------------------------------------------------------
Karl Schultz6addd812016-02-02 17:17:23 -070058struct Vertex {
59 float posX, posY, posZ, posW; // Position data
60 float r, g, b, a; // Color
Mark Lobodzinski3780e142015-05-14 15:08:13 -050061};
62
Karl Schultz6addd812016-02-02 17:17:23 -070063#define XYZ1(_x_, _y_, _z_) (_x_), (_y_), (_z_), 1.f
Mark Lobodzinski3780e142015-05-14 15:08:13 -050064
65typedef enum _BsoFailSelect {
Karl Schultz6addd812016-02-02 17:17:23 -070066 BsoFailNone = 0x00000000,
67 BsoFailLineWidth = 0x00000001,
68 BsoFailDepthBias = 0x00000002,
69 BsoFailViewport = 0x00000004,
70 BsoFailScissor = 0x00000008,
71 BsoFailBlend = 0x00000010,
72 BsoFailDepthBounds = 0x00000020,
73 BsoFailStencilReadMask = 0x00000040,
74 BsoFailStencilWriteMask = 0x00000080,
75 BsoFailStencilReference = 0x00000100,
Mark Muellerd4914412016-06-13 17:52:06 -060076 BsoFailCmdClearAttachments = 0x00000200,
Tobin Ehlis379ba3b2016-07-19 11:22:29 -060077 BsoFailIndexBuffer = 0x00000400,
Mark Lobodzinski3780e142015-05-14 15:08:13 -050078} BsoFailSelect;
79
80struct vktriangle_vs_uniform {
81 // Must start with MVP
Karl Schultz6addd812016-02-02 17:17:23 -070082 float mvp[4][4];
83 float position[3][4];
84 float color[3][4];
Mark Lobodzinski3780e142015-05-14 15:08:13 -050085};
86
Mark Lobodzinskice751c62016-09-08 10:45:35 -060087static const char bindStateVertShaderText[] = "#version 450\n"
88 "vec2 vertices[3];\n"
89 "out gl_PerVertex {\n"
90 " vec4 gl_Position;\n"
91 "};\n"
92 "void main() {\n"
93 " vertices[0] = vec2(-1.0, -1.0);\n"
94 " vertices[1] = vec2( 1.0, -1.0);\n"
95 " vertices[2] = vec2( 0.0, 1.0);\n"
96 " gl_Position = vec4(vertices[gl_VertexIndex % 3], 0.0, 1.0);\n"
97 "}\n";
Mark Lobodzinski3780e142015-05-14 15:08:13 -050098
Mark Lobodzinskice751c62016-09-08 10:45:35 -060099static const char bindStateFragShaderText[] = "#version 450\n"
100 "\n"
101 "layout(location = 0) out vec4 uFragColor;\n"
102 "void main(){\n"
103 " uFragColor = vec4(0,1,0,1);\n"
104 "}\n";
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500105
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600106static VKAPI_ATTR VkBool32 VKAPI_CALL myDbgFunc(VkFlags msgFlags, VkDebugReportObjectTypeEXT objType, uint64_t srcObject,
107 size_t location, int32_t msgCode, const char *pLayerPrefix, const char *pMsg,
108 void *pUserData);
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600109
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600110// ErrorMonitor Usage:
111//
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600112// Call SetDesiredFailureMsg with: a string to be compared against all
113// encountered log messages, or a validation error enum identifying
114// desired error message. Passing NULL or VALIDATION_ERROR_MAX_ENUM
115// will match all log messages. logMsg will return true for skipCall
116// only if msg is matched or NULL.
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600117//
118// Call DesiredMsgFound to determine if the desired failure message
119// was encountered.
Tony Barbour300a6082015-04-07 13:44:53 -0600120class ErrorMonitor {
Karl Schultz6addd812016-02-02 17:17:23 -0700121 public:
122 ErrorMonitor() {
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600123 test_platform_thread_create_mutex(&m_mutex);
124 test_platform_thread_lock_mutex(&m_mutex);
Chris Forbes17756132016-09-16 14:36:39 +1200125 m_msgFlags = VK_DEBUG_REPORT_ERROR_BIT_EXT;
Karl Schultz6addd812016-02-02 17:17:23 -0700126 m_bailout = NULL;
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600127 test_platform_thread_unlock_mutex(&m_mutex);
Tony Barbour300a6082015-04-07 13:44:53 -0600128 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600129
Dustin Graves48458142016-04-29 16:11:55 -0600130 ~ErrorMonitor() { test_platform_thread_delete_mutex(&m_mutex); }
131
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600132 // ErrorMonitor will look for an error message containing the specified string
Karl Schultz6addd812016-02-02 17:17:23 -0700133 void SetDesiredFailureMsg(VkFlags msgFlags, const char *msgString) {
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600134 // Also discard all collected messages to this point
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600135 test_platform_thread_lock_mutex(&m_mutex);
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600136 m_failure_message_strings.clear();
137 // If we are looking for a matching string, ignore any IDs
138 m_desired_message_ids.clear();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600139 m_otherMsgs.clear();
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600140 m_desired_message_strings.insert(msgString);
Karl Schultz6addd812016-02-02 17:17:23 -0700141 m_msgFound = VK_FALSE;
142 m_msgFlags = msgFlags;
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600143 test_platform_thread_unlock_mutex(&m_mutex);
Tony Barbour300a6082015-04-07 13:44:53 -0600144 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600145
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600146 // ErrorMonitor will look for a message ID matching the specified one
147 void SetDesiredFailureMsg(VkFlags msgFlags, UNIQUE_VALIDATION_ERROR_CODE msg_id) {
148 // Also discard all collected messages to this point
149 test_platform_thread_lock_mutex(&m_mutex);
150 m_failure_message_strings.clear();
151 // If we are looking for IDs don't look for strings
152 m_desired_message_strings.clear();
153 m_otherMsgs.clear();
154 m_desired_message_ids.insert(msg_id);
155 m_msgFound = VK_FALSE;
156 m_msgFlags = msgFlags;
157 test_platform_thread_unlock_mutex(&m_mutex);
158 }
159
160 VkBool32 CheckForDesiredMsg(uint32_t message_code, const char *msgString) {
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600161 VkBool32 result = VK_FALSE;
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600162 test_platform_thread_lock_mutex(&m_mutex);
Mike Stroyanaccf7692015-05-12 16:00:45 -0600163 if (m_bailout != NULL) {
164 *m_bailout = true;
165 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600166 string errorString(msgString);
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600167 bool found_expected = false;
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600168
169 for (auto desired_msg : m_desired_message_strings) {
Karl Schultz05cc4e32016-10-12 13:25:23 -0600170 if (desired_msg.length() == 0) {
171 // An empty desired_msg string "" indicates a positive test - not expecting an error.
172 // Return true to avoid calling layers/driver with this error.
173 // And don't erase the "" string, so it remains if another error is found.
174 result = VK_TRUE;
Tony Barbourae58dba2016-12-13 16:30:36 -0700175 found_expected = true;
176 m_msgFound = VK_TRUE;
177 m_failure_message_strings.insert(errorString);
Karl Schultz05cc4e32016-10-12 13:25:23 -0600178 } else if (errorString.find(desired_msg) != string::npos) {
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600179 found_expected = true;
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600180 m_failure_message_strings.insert(errorString);
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600181 m_msgFound = VK_TRUE;
182 result = VK_TRUE;
183 // We only want one match for each expected error so remove from set here
184 // Since we're about the break the loop it's ok to remove from set we're iterating over
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600185 m_desired_message_strings.erase(desired_msg);
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600186 break;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600187 }
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600188 }
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600189 for (auto desired_id : m_desired_message_ids) {
190 if (desired_id == VALIDATION_ERROR_MAX_ENUM) {
191 // A message ID set to MAX_ENUM indicates a positive test - not expecting an error.
192 // Return true to avoid calling layers/driver with this error.
193 result = VK_TRUE;
194 } else if (desired_id == message_code) {
195 // Double-check that the string matches the error enum
196 if (errorString.find(validation_error_map[desired_id]) != string::npos) {
197 found_expected = true;
198 result = VK_TRUE;
199 m_msgFound = VK_TRUE;
200 m_desired_message_ids.erase(desired_id);
201 break;
202 } else {
203 // Treat this message as a regular unexpected error, but print a warning jic
204 printf("Message (%s) from MessageID %d does not correspond to expected message from error Database (%s)\n",
205 errorString.c_str(), desired_id, validation_error_map[desired_id]);
206 }
207 }
208 }
209
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600210 if (!found_expected) {
Chris Forbes5b9442b2016-09-13 16:49:57 +1200211 printf("Unexpected: %s\n", msgString);
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600212 m_otherMsgs.push_back(errorString);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600213 }
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600214 test_platform_thread_unlock_mutex(&m_mutex);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600215 return result;
Mike Stroyanaccf7692015-05-12 16:00:45 -0600216 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600217
Karl Schultz6addd812016-02-02 17:17:23 -0700218 vector<string> GetOtherFailureMsgs(void) { return m_otherMsgs; }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600219
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600220 VkDebugReportFlagsEXT GetMessageFlags(void) { return m_msgFlags; }
221
Karl Schultz6addd812016-02-02 17:17:23 -0700222 VkBool32 DesiredMsgFound(void) { return m_msgFound; }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600223
Karl Schultz6addd812016-02-02 17:17:23 -0700224 void SetBailout(bool *bailout) { m_bailout = bailout; }
Tony Barbour300a6082015-04-07 13:44:53 -0600225
Karl Schultz6addd812016-02-02 17:17:23 -0700226 void DumpFailureMsgs(void) {
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600227 vector<string> otherMsgs = GetOtherFailureMsgs();
Tony Barbour59b42282016-11-03 13:31:28 -0600228 if (otherMsgs.size()) {
229 cout << "Other error messages logged for this test were:" << endl;
230 for (auto iter = otherMsgs.begin(); iter != otherMsgs.end(); iter++) {
231 cout << " " << *iter << endl;
232 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600233 }
234 }
235
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600236 // Helpers
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200237
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600238 // ExpectSuccess now takes an optional argument allowing a custom combination of debug flags
239 void ExpectSuccess(VkDebugReportFlagsEXT message_flag_mask = VK_DEBUG_REPORT_ERROR_BIT_EXT) {
240 m_msgFlags = message_flag_mask;
241 // Match ANY message matching specified type
242 SetDesiredFailureMsg(message_flag_mask, "");
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200243 }
244
245 void VerifyFound() {
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600246 // Not seeing the desired message is a failure. /Before/ throwing, dump any other messages.
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200247 if (!DesiredMsgFound()) {
248 DumpFailureMsgs();
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600249 for (auto desired_msg : m_desired_message_strings) {
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600250 FAIL() << "Did not receive expected error '" << desired_msg << "'";
251 }
Tony Barbour59b42282016-11-03 13:31:28 -0600252 for (auto desired_id : m_desired_message_ids) {
253 FAIL() << "Did not receive expected error '" << desired_id << "'";
254 }
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200255 }
256 }
257
258 void VerifyNotFound() {
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600259 // ExpectSuccess() configured us to match anything. Any error is a failure.
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200260 if (DesiredMsgFound()) {
261 DumpFailureMsgs();
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600262 for (auto msg : m_failure_message_strings) {
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600263 FAIL() << "Expected to succeed but got error: " << msg;
264 }
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200265 }
266 }
267
Karl Schultz6addd812016-02-02 17:17:23 -0700268 private:
269 VkFlags m_msgFlags;
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600270 std::unordered_set<uint32_t>m_desired_message_ids;
271 std::unordered_set<string> m_desired_message_strings;
272 std::unordered_set<string> m_failure_message_strings;
Karl Schultz6addd812016-02-02 17:17:23 -0700273 vector<string> m_otherMsgs;
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600274 test_platform_thread_mutex m_mutex;
Karl Schultz6addd812016-02-02 17:17:23 -0700275 bool *m_bailout;
276 VkBool32 m_msgFound;
Tony Barbour300a6082015-04-07 13:44:53 -0600277};
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500278
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600279static VKAPI_ATTR VkBool32 VKAPI_CALL myDbgFunc(VkFlags msgFlags, VkDebugReportObjectTypeEXT objType, uint64_t srcObject,
280 size_t location, int32_t msgCode, const char *pLayerPrefix, const char *pMsg,
281 void *pUserData) {
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600282 ErrorMonitor *errMonitor = (ErrorMonitor *)pUserData;
283 if (msgFlags & errMonitor->GetMessageFlags()) {
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600284 return errMonitor->CheckForDesiredMsg(msgCode, pMsg);
Tony Barbour0b4d9562015-04-09 10:48:04 -0600285 }
Courtney Goeltzenleuchter06640832015-09-04 13:52:24 -0600286 return false;
Tony Barbour300a6082015-04-07 13:44:53 -0600287}
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500288
Karl Schultz6addd812016-02-02 17:17:23 -0700289class VkLayerTest : public VkRenderFramework {
290 public:
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800291 VkResult BeginCommandBuffer(VkCommandBufferObj &commandBuffer);
292 VkResult EndCommandBuffer(VkCommandBufferObj &commandBuffer);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600293 void VKTriangleTest(const char *vertShaderText, const char *fragShaderText, BsoFailSelect failMask);
294 void GenericDrawPreparation(VkCommandBufferObj *commandBuffer, VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet,
Karl Schultz6addd812016-02-02 17:17:23 -0700295 BsoFailSelect failMask);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600296 void GenericDrawPreparation(VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet, BsoFailSelect failMask) {
297 GenericDrawPreparation(m_commandBuffer, pipelineobj, descriptorSet, failMask);
Karl Schultz6addd812016-02-02 17:17:23 -0700298 }
Tony Barbour300a6082015-04-07 13:44:53 -0600299
Tony Barbourfe3351b2015-07-28 10:17:20 -0600300 /* Convenience functions that use built-in command buffer */
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600301 VkResult BeginCommandBuffer() { return BeginCommandBuffer(*m_commandBuffer); }
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800302 VkResult EndCommandBuffer() { return EndCommandBuffer(*m_commandBuffer); }
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600303 void Draw(uint32_t vertexCount, uint32_t instanceCount, uint32_t firstVertex, uint32_t firstInstance) {
304 m_commandBuffer->Draw(vertexCount, instanceCount, firstVertex, firstInstance);
Karl Schultz6addd812016-02-02 17:17:23 -0700305 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600306 void DrawIndexed(uint32_t indexCount, uint32_t instanceCount, uint32_t firstIndex, int32_t vertexOffset,
Karl Schultz6addd812016-02-02 17:17:23 -0700307 uint32_t firstInstance) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600308 m_commandBuffer->DrawIndexed(indexCount, instanceCount, firstIndex, vertexOffset, firstInstance);
Karl Schultz6addd812016-02-02 17:17:23 -0700309 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600310 void QueueCommandBuffer(bool checkSuccess = true) { m_commandBuffer->QueueCommandBuffer(checkSuccess); }
311 void QueueCommandBuffer(const VkFence &fence) { m_commandBuffer->QueueCommandBuffer(fence); }
312 void BindVertexBuffer(VkConstantBufferObj *vertexBuffer, VkDeviceSize offset, uint32_t binding) {
Karl Schultz6addd812016-02-02 17:17:23 -0700313 m_commandBuffer->BindVertexBuffer(vertexBuffer, offset, binding);
314 }
315 void BindIndexBuffer(VkIndexBufferObj *indexBuffer, VkDeviceSize offset) {
316 m_commandBuffer->BindIndexBuffer(indexBuffer, offset);
317 }
318
319 protected:
320 ErrorMonitor *m_errorMonitor;
Ian Elliott2c1daf52016-05-12 09:41:46 -0600321 bool m_enableWSI;
Tony Barbour300a6082015-04-07 13:44:53 -0600322
323 virtual void SetUp() {
Courtney Goeltzenleuchtercd69eee2015-07-06 09:10:47 -0600324 std::vector<const char *> instance_layer_names;
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600325 std::vector<const char *> instance_extension_names;
326 std::vector<const char *> device_extension_names;
Tony Barbour3fdff9e2015-04-23 12:55:36 -0600327
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700328 instance_extension_names.push_back(VK_EXT_DEBUG_REPORT_EXTENSION_NAME);
Courtney Goeltzenleuchterc2b06fe2015-06-16 15:59:11 -0600329 /*
330 * Since CreateDbgMsgCallback is an instance level extension call
331 * any extension / layer that utilizes that feature also needs
332 * to be enabled at create instance time.
333 */
Karl Schultz6addd812016-02-02 17:17:23 -0700334 // Use Threading layer first to protect others from
335 // ThreadCommandBufferCollision test
Courtney Goeltzenleuchter76885322016-02-06 17:11:22 -0700336 instance_layer_names.push_back("VK_LAYER_GOOGLE_threading");
Tobin Ehlis24aab042016-03-24 10:54:18 -0600337 instance_layer_names.push_back("VK_LAYER_LUNARG_parameter_validation");
Michael Lentine03107b42015-12-11 10:49:51 -0800338 instance_layer_names.push_back("VK_LAYER_LUNARG_object_tracker");
Tobin Ehlisc96f8062016-03-09 16:12:48 -0700339 instance_layer_names.push_back("VK_LAYER_LUNARG_core_validation");
Michael Lentine03107b42015-12-11 10:49:51 -0800340 instance_layer_names.push_back("VK_LAYER_LUNARG_image");
Ian Elliotte48a1382016-04-28 14:22:58 -0600341 instance_layer_names.push_back("VK_LAYER_LUNARG_swapchain");
Dustin Graveseaa78cd2016-01-26 16:30:22 -0700342 instance_layer_names.push_back("VK_LAYER_GOOGLE_unique_objects");
Courtney Goeltzenleuchterd971b612015-06-17 20:51:59 -0600343
Ian Elliott2c1daf52016-05-12 09:41:46 -0600344 if (m_enableWSI) {
345 instance_extension_names.push_back(VK_KHR_SURFACE_EXTENSION_NAME);
346 device_extension_names.push_back(VK_KHR_SWAPCHAIN_EXTENSION_NAME);
347#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
348#if defined(VK_USE_PLATFORM_ANDROID_KHR)
349 instance_extension_names.push_back(VK_KHR_ANDROID_SURFACE_EXTENSION_NAME);
350#endif // VK_USE_PLATFORM_ANDROID_KHR
351#if defined(VK_USE_PLATFORM_MIR_KHR)
352 instance_extension_names.push_back(VK_KHR_MIR_SURFACE_EXTENSION_NAME);
353#endif // VK_USE_PLATFORM_MIR_KHR
354#if defined(VK_USE_PLATFORM_WAYLAND_KHR)
355 instance_extension_names.push_back(VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME);
356#endif // VK_USE_PLATFORM_WAYLAND_KHR
357#if defined(VK_USE_PLATFORM_WIN32_KHR)
358 instance_extension_names.push_back(VK_KHR_WIN32_SURFACE_EXTENSION_NAME);
359#endif // VK_USE_PLATFORM_WIN32_KHR
360#endif // NEED_TO_TEST_THIS_ON_PLATFORM
361#if defined(VK_USE_PLATFORM_XCB_KHR)
362 instance_extension_names.push_back(VK_KHR_XCB_SURFACE_EXTENSION_NAME);
363#elif defined(VK_USE_PLATFORM_XLIB_KHR)
364 instance_extension_names.push_back(VK_KHR_XLIB_SURFACE_EXTENSION_NAME);
365#endif // VK_USE_PLATFORM_XLIB_KHR
366 }
367
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600368 this->app_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
Tony Barbour300a6082015-04-07 13:44:53 -0600369 this->app_info.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800370 this->app_info.pApplicationName = "layer_tests";
371 this->app_info.applicationVersion = 1;
Tony Barbour300a6082015-04-07 13:44:53 -0600372 this->app_info.pEngineName = "unittest";
373 this->app_info.engineVersion = 1;
Jon Ashburnc5012ff2016-03-22 13:57:46 -0600374 this->app_info.apiVersion = VK_API_VERSION_1_0;
Tony Barbour300a6082015-04-07 13:44:53 -0600375
Tony Barbour15524c32015-04-29 17:34:29 -0600376 m_errorMonitor = new ErrorMonitor;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600377 InitFramework(instance_layer_names, instance_extension_names, device_extension_names, myDbgFunc, m_errorMonitor);
Tony Barbour300a6082015-04-07 13:44:53 -0600378 }
379
380 virtual void TearDown() {
381 // Clean up resources before we reset
Tony Barbour300a6082015-04-07 13:44:53 -0600382 ShutdownFramework();
Tony Barbour0b4d9562015-04-09 10:48:04 -0600383 delete m_errorMonitor;
Tony Barbour300a6082015-04-07 13:44:53 -0600384 }
Ian Elliott2c1daf52016-05-12 09:41:46 -0600385
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600386 VkLayerTest() { m_enableWSI = false; }
Tony Barbour300a6082015-04-07 13:44:53 -0600387};
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500388
Karl Schultz6addd812016-02-02 17:17:23 -0700389VkResult VkLayerTest::BeginCommandBuffer(VkCommandBufferObj &commandBuffer) {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600390 VkResult result;
Tony Barbour300a6082015-04-07 13:44:53 -0600391
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800392 result = commandBuffer.BeginCommandBuffer();
Tony Barbour300a6082015-04-07 13:44:53 -0600393
394 /*
395 * For render test all drawing happens in a single render pass
396 * on a single command buffer.
397 */
Chris Forbes76a5eeb2015-06-16 14:05:59 +1200398 if (VK_SUCCESS == result && renderPass()) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800399 commandBuffer.BeginRenderPass(renderPassBeginInfo());
Tony Barbour300a6082015-04-07 13:44:53 -0600400 }
401
402 return result;
403}
404
Karl Schultz6addd812016-02-02 17:17:23 -0700405VkResult VkLayerTest::EndCommandBuffer(VkCommandBufferObj &commandBuffer) {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600406 VkResult result;
Tony Barbour300a6082015-04-07 13:44:53 -0600407
Chris Forbes76a5eeb2015-06-16 14:05:59 +1200408 if (renderPass()) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800409 commandBuffer.EndRenderPass();
Chris Forbes76a5eeb2015-06-16 14:05:59 +1200410 }
Tony Barbour300a6082015-04-07 13:44:53 -0600411
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800412 result = commandBuffer.EndCommandBuffer();
Tony Barbour300a6082015-04-07 13:44:53 -0600413
414 return result;
415}
416
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600417void VkLayerTest::VKTriangleTest(const char *vertShaderText, const char *fragShaderText, BsoFailSelect failMask) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500418 // Create identity matrix
419 int i;
420 struct vktriangle_vs_uniform data;
421
422 glm::mat4 Projection = glm::mat4(1.0f);
Karl Schultz6addd812016-02-02 17:17:23 -0700423 glm::mat4 View = glm::mat4(1.0f);
424 glm::mat4 Model = glm::mat4(1.0f);
425 glm::mat4 MVP = Projection * View * Model;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500426 const int matrixSize = sizeof(MVP);
Karl Schultz6addd812016-02-02 17:17:23 -0700427 const int bufSize = sizeof(vktriangle_vs_uniform) / sizeof(float);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500428
429 memcpy(&data.mvp, &MVP[0][0], matrixSize);
430
Karl Schultz6addd812016-02-02 17:17:23 -0700431 static const Vertex tri_data[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600432 {XYZ1(-1, -1, 0), XYZ1(1.f, 0.f, 0.f)}, {XYZ1(1, -1, 0), XYZ1(0.f, 1.f, 0.f)}, {XYZ1(0, 1, 0), XYZ1(0.f, 0.f, 1.f)},
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500433 };
434
Karl Schultz6addd812016-02-02 17:17:23 -0700435 for (i = 0; i < 3; i++) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500436 data.position[i][0] = tri_data[i].posX;
437 data.position[i][1] = tri_data[i].posY;
438 data.position[i][2] = tri_data[i].posZ;
439 data.position[i][3] = tri_data[i].posW;
Karl Schultz6addd812016-02-02 17:17:23 -0700440 data.color[i][0] = tri_data[i].r;
441 data.color[i][1] = tri_data[i].g;
442 data.color[i][2] = tri_data[i].b;
443 data.color[i][3] = tri_data[i].a;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500444 }
445
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500446 ASSERT_NO_FATAL_FAILURE(InitViewport());
447
Chris Forbesbcfaadd2016-09-16 14:13:53 +1200448 VkConstantBufferObj constantBuffer(m_device, bufSize * 2, sizeof(float), (const void *)&data,
449 VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500450
Karl Schultz6addd812016-02-02 17:17:23 -0700451 VkShaderObj vs(m_device, vertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600452 VkShaderObj ps(m_device, fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500453
454 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +0800455 pipelineobj.AddColorAttachment();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500456 pipelineobj.AddShader(&vs);
457 pipelineobj.AddShader(&ps);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600458 if (failMask & BsoFailLineWidth) {
459 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_LINE_WIDTH);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600460 VkPipelineInputAssemblyStateCreateInfo ia_state = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600461 ia_state.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600462 ia_state.topology = VK_PRIMITIVE_TOPOLOGY_LINE_LIST;
463 pipelineobj.SetInputAssembly(&ia_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600464 }
465 if (failMask & BsoFailDepthBias) {
466 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_DEPTH_BIAS);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600467 VkPipelineRasterizationStateCreateInfo rs_state = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600468 rs_state.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600469 rs_state.depthBiasEnable = VK_TRUE;
Mark Young7394fdd2016-03-31 14:56:43 -0600470 rs_state.lineWidth = 1.0f;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600471 pipelineobj.SetRasterization(&rs_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600472 }
Karl Schultz6addd812016-02-02 17:17:23 -0700473 // Viewport and scissors must stay in synch or other errors will occur than
474 // the ones we want
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600475 if (failMask & BsoFailViewport) {
476 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_VIEWPORT);
477 }
478 if (failMask & BsoFailScissor) {
479 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_SCISSOR);
480 }
481 if (failMask & BsoFailBlend) {
482 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_BLEND_CONSTANTS);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600483 VkPipelineColorBlendAttachmentState att_state = {};
484 att_state.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
485 att_state.blendEnable = VK_TRUE;
486 pipelineobj.AddColorAttachment(0, &att_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600487 }
488 if (failMask & BsoFailDepthBounds) {
489 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_DEPTH_BOUNDS);
490 }
491 if (failMask & BsoFailStencilReadMask) {
492 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK);
493 }
494 if (failMask & BsoFailStencilWriteMask) {
495 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_WRITE_MASK);
496 }
497 if (failMask & BsoFailStencilReference) {
498 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_REFERENCE);
499 }
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500500
501 VkDescriptorSetObj descriptorSet(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600502 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, constantBuffer);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500503
504 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -0600505 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500506
Tony Barbourfe3351b2015-07-28 10:17:20 -0600507 GenericDrawPreparation(pipelineobj, descriptorSet, failMask);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500508
509 // render triangle
Tobin Ehlis379ba3b2016-07-19 11:22:29 -0600510 if (failMask & BsoFailIndexBuffer) {
511 // Use DrawIndexed w/o an index buffer bound
512 DrawIndexed(3, 1, 0, 0, 0);
513 } else {
514 Draw(3, 1, 0, 0);
515 }
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500516
Mark Muellerd4914412016-06-13 17:52:06 -0600517 if (failMask & BsoFailCmdClearAttachments) {
518 VkClearAttachment color_attachment = {};
519 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
520 color_attachment.colorAttachment = 1; // Someone who knew what they were doing would use 0 for the index;
521 VkClearRect clear_rect = {{{0, 0}, {static_cast<uint32_t>(m_width), static_cast<uint32_t>(m_height)}}, 0, 0};
522
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600523 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Muellerd4914412016-06-13 17:52:06 -0600524 }
525
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500526 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -0600527 EndCommandBuffer();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500528
Tony Barbourfe3351b2015-07-28 10:17:20 -0600529 QueueCommandBuffer();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500530}
531
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600532void VkLayerTest::GenericDrawPreparation(VkCommandBufferObj *commandBuffer, VkPipelineObj &pipelineobj,
533 VkDescriptorSetObj &descriptorSet, BsoFailSelect failMask) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500534 if (m_depthStencil->Initialized()) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600535 commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, m_depthStencil);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500536 } else {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600537 commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500538 }
539
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800540 commandBuffer->PrepareAttachments();
Karl Schultz6addd812016-02-02 17:17:23 -0700541 // Make sure depthWriteEnable is set so that Depth fail test will work
542 // correctly
543 // Make sure stencilTestEnable is set so that Stencil fail test will work
544 // correctly
Tony Barboureb254902015-07-15 12:50:33 -0600545 VkStencilOpState stencil = {};
Chia-I Wu1b99bb22015-10-27 19:25:11 +0800546 stencil.failOp = VK_STENCIL_OP_KEEP;
547 stencil.passOp = VK_STENCIL_OP_KEEP;
548 stencil.depthFailOp = VK_STENCIL_OP_KEEP;
549 stencil.compareOp = VK_COMPARE_OP_NEVER;
Tony Barboureb254902015-07-15 12:50:33 -0600550
551 VkPipelineDepthStencilStateCreateInfo ds_ci = {};
552 ds_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO;
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600553 ds_ci.pNext = NULL;
554 ds_ci.depthTestEnable = VK_FALSE;
555 ds_ci.depthWriteEnable = VK_TRUE;
556 ds_ci.depthCompareOp = VK_COMPARE_OP_NEVER;
557 ds_ci.depthBoundsTestEnable = VK_FALSE;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600558 if (failMask & BsoFailDepthBounds) {
559 ds_ci.depthBoundsTestEnable = VK_TRUE;
Tobin Ehlis21c88352016-05-26 06:15:45 -0600560 ds_ci.maxDepthBounds = 0.0f;
561 ds_ci.minDepthBounds = 0.0f;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600562 }
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600563 ds_ci.stencilTestEnable = VK_TRUE;
564 ds_ci.front = stencil;
565 ds_ci.back = stencil;
Tony Barboureb254902015-07-15 12:50:33 -0600566
Tobin Ehlis4bf96d12015-06-25 11:58:41 -0600567 pipelineobj.SetDepthStencil(&ds_ci);
Tobin Ehlisd332f282015-10-02 11:00:56 -0600568 pipelineobj.SetViewport(m_viewports);
569 pipelineobj.SetScissor(m_scissors);
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800570 descriptorSet.CreateVKDescriptorSet(commandBuffer);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600571 VkResult err = pipelineobj.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Cody Northrop29a08f22015-08-27 10:20:35 -0600572 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800573 commandBuffer->BindPipeline(pipelineobj);
574 commandBuffer->BindDescriptorSet(descriptorSet);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500575}
576
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600577class VkPositiveLayerTest : public VkLayerTest {
578 public:
579 protected:
580};
581
Ian Elliott2c1daf52016-05-12 09:41:46 -0600582class VkWsiEnabledLayerTest : public VkLayerTest {
583 public:
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600584 protected:
585 VkWsiEnabledLayerTest() { m_enableWSI = true; }
Ian Elliott2c1daf52016-05-12 09:41:46 -0600586};
587
Mark Muellerdfe37552016-07-07 14:47:42 -0600588class VkBufferTest {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600589 public:
Mark Muellerdfe37552016-07-07 14:47:42 -0600590 enum eTestEnFlags {
591 eDoubleDelete,
592 eInvalidDeviceOffset,
593 eInvalidMemoryOffset,
594 eBindNullBuffer,
595 eFreeInvalidHandle,
Mark Mueller4042b652016-09-05 22:52:21 -0600596 eNone,
Mark Muellerdfe37552016-07-07 14:47:42 -0600597 };
598
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600599 enum eTestConditions { eOffsetAlignment = 1 };
Mark Muellerdfe37552016-07-07 14:47:42 -0600600
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600601 static bool GetTestConditionValid(VkDeviceObj *aVulkanDevice, eTestEnFlags aTestFlag, VkBufferUsageFlags aBufferUsage = 0) {
602 if (eInvalidDeviceOffset != aTestFlag && eInvalidMemoryOffset != aTestFlag) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600603 return true;
604 }
605 VkDeviceSize offset_limit = 0;
606 if (eInvalidMemoryOffset == aTestFlag) {
607 VkBuffer vulkanBuffer;
608 VkBufferCreateInfo buffer_create_info = {};
609 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
610 buffer_create_info.size = 32;
611 buffer_create_info.usage = aBufferUsage;
612
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600613 vkCreateBuffer(aVulkanDevice->device(), &buffer_create_info, nullptr, &vulkanBuffer);
Mark Mueller4042b652016-09-05 22:52:21 -0600614 VkMemoryRequirements memory_reqs = {};
Mark Muellerdfe37552016-07-07 14:47:42 -0600615
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600616 vkGetBufferMemoryRequirements(aVulkanDevice->device(), vulkanBuffer, &memory_reqs);
Mark Muellerdfe37552016-07-07 14:47:42 -0600617 vkDestroyBuffer(aVulkanDevice->device(), vulkanBuffer, nullptr);
618 offset_limit = memory_reqs.alignment;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600619 } else if ((VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT | VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT) & aBufferUsage) {
620 offset_limit = aVulkanDevice->props.limits.minTexelBufferOffsetAlignment;
Mark Muellerdfe37552016-07-07 14:47:42 -0600621 } else if (VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT & aBufferUsage) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600622 offset_limit = aVulkanDevice->props.limits.minUniformBufferOffsetAlignment;
Mark Muellerdfe37552016-07-07 14:47:42 -0600623 } else if (VK_BUFFER_USAGE_STORAGE_BUFFER_BIT & aBufferUsage) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600624 offset_limit = aVulkanDevice->props.limits.minStorageBufferOffsetAlignment;
Mark Muellerdfe37552016-07-07 14:47:42 -0600625 }
626 if (eOffsetAlignment < offset_limit) {
627 return true;
628 }
629 return false;
630 }
631
632 // A constructor which performs validation tests within construction.
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600633 VkBufferTest(VkDeviceObj *aVulkanDevice, VkBufferUsageFlags aBufferUsage, eTestEnFlags aTestFlag = eNone)
634 : AllocateCurrent(false), BoundCurrent(false), CreateCurrent(false), VulkanDevice(aVulkanDevice->device()) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600635
636 if (eBindNullBuffer == aTestFlag) {
637 VulkanMemory = 0;
638 vkBindBufferMemory(VulkanDevice, VulkanBuffer, VulkanMemory, 0);
639 } else {
640 VkBufferCreateInfo buffer_create_info = {};
641 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
642 buffer_create_info.size = 32;
643 buffer_create_info.usage = aBufferUsage;
644
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600645 vkCreateBuffer(VulkanDevice, &buffer_create_info, nullptr, &VulkanBuffer);
Mark Muellerdfe37552016-07-07 14:47:42 -0600646
647 CreateCurrent = true;
648
649 VkMemoryRequirements memory_requirements;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600650 vkGetBufferMemoryRequirements(VulkanDevice, VulkanBuffer, &memory_requirements);
Mark Muellerdfe37552016-07-07 14:47:42 -0600651
652 VkMemoryAllocateInfo memory_allocate_info = {};
653 memory_allocate_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
654 memory_allocate_info.allocationSize = memory_requirements.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600655 bool pass = aVulkanDevice->phy().set_memory_type(memory_requirements.memoryTypeBits, &memory_allocate_info,
656 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
Mark Muellerdfe37552016-07-07 14:47:42 -0600657 if (!pass) {
658 vkDestroyBuffer(VulkanDevice, VulkanBuffer, nullptr);
659 return;
660 }
661
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600662 vkAllocateMemory(VulkanDevice, &memory_allocate_info, NULL, &VulkanMemory);
Mark Muellerdfe37552016-07-07 14:47:42 -0600663 AllocateCurrent = true;
664 // NB: 1 is intentionally an invalid offset value
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600665 const bool offset_en = eInvalidDeviceOffset == aTestFlag || eInvalidMemoryOffset == aTestFlag;
666 vkBindBufferMemory(VulkanDevice, VulkanBuffer, VulkanMemory, offset_en ? eOffsetAlignment : 0);
Mark Muellerdfe37552016-07-07 14:47:42 -0600667 BoundCurrent = true;
668
669 InvalidDeleteEn = (eFreeInvalidHandle == aTestFlag);
670 }
671 }
672
673 ~VkBufferTest() {
674 if (CreateCurrent) {
675 vkDestroyBuffer(VulkanDevice, VulkanBuffer, nullptr);
676 }
677 if (AllocateCurrent) {
678 if (InvalidDeleteEn) {
679 union {
680 VkDeviceMemory device_memory;
681 unsigned long long index_access;
682 } bad_index;
683
684 bad_index.device_memory = VulkanMemory;
685 bad_index.index_access++;
686
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600687 vkFreeMemory(VulkanDevice, bad_index.device_memory, nullptr);
Mark Muellerdfe37552016-07-07 14:47:42 -0600688 }
689 vkFreeMemory(VulkanDevice, VulkanMemory, nullptr);
690 }
691 }
692
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600693 bool GetBufferCurrent() { return AllocateCurrent && BoundCurrent && CreateCurrent; }
Mark Muellerdfe37552016-07-07 14:47:42 -0600694
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600695 const VkBuffer &GetBuffer() { return VulkanBuffer; }
Mark Muellerdfe37552016-07-07 14:47:42 -0600696
697 void TestDoubleDestroy() {
698 // Destroy the buffer but leave the flag set, which will cause
699 // the buffer to be destroyed again in the destructor.
700 vkDestroyBuffer(VulkanDevice, VulkanBuffer, nullptr);
701 }
702
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600703 protected:
Mark Muellerdfe37552016-07-07 14:47:42 -0600704 bool AllocateCurrent;
705 bool BoundCurrent;
706 bool CreateCurrent;
707 bool InvalidDeleteEn;
708
709 VkBuffer VulkanBuffer;
710 VkDevice VulkanDevice;
711 VkDeviceMemory VulkanMemory;
Mark Muellerdfe37552016-07-07 14:47:42 -0600712};
713
714class VkVerticesObj {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600715 public:
716 VkVerticesObj(VkDeviceObj *aVulkanDevice, unsigned aAttributeCount, unsigned aBindingCount, unsigned aByteStride,
Mark Muellerdfe37552016-07-07 14:47:42 -0600717 VkDeviceSize aVertexCount, const float *aVerticies)
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600718 : BoundCurrent(false), AttributeCount(aAttributeCount), BindingCount(aBindingCount), BindId(BindIdGenerator),
Mark Muellerdfe37552016-07-07 14:47:42 -0600719 PipelineVertexInputStateCreateInfo(),
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600720 VulkanMemoryBuffer(aVulkanDevice, 1, static_cast<int>(aByteStride * aVertexCount),
721 reinterpret_cast<const void *>(aVerticies), VK_BUFFER_USAGE_VERTEX_BUFFER_BIT) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600722 BindIdGenerator++; // NB: This can wrap w/misuse
723
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600724 VertexInputAttributeDescription = new VkVertexInputAttributeDescription[AttributeCount];
725 VertexInputBindingDescription = new VkVertexInputBindingDescription[BindingCount];
Mark Muellerdfe37552016-07-07 14:47:42 -0600726
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600727 PipelineVertexInputStateCreateInfo.pVertexAttributeDescriptions = VertexInputAttributeDescription;
728 PipelineVertexInputStateCreateInfo.vertexAttributeDescriptionCount = AttributeCount;
729 PipelineVertexInputStateCreateInfo.pVertexBindingDescriptions = VertexInputBindingDescription;
730 PipelineVertexInputStateCreateInfo.vertexBindingDescriptionCount = BindingCount;
731 PipelineVertexInputStateCreateInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
Mark Muellerdfe37552016-07-07 14:47:42 -0600732
733 unsigned i = 0;
734 do {
735 VertexInputAttributeDescription[i].binding = BindId;
736 VertexInputAttributeDescription[i].location = i;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600737 VertexInputAttributeDescription[i].format = VK_FORMAT_R32G32B32_SFLOAT;
738 VertexInputAttributeDescription[i].offset = sizeof(float) * aByteStride;
Mark Muellerdfe37552016-07-07 14:47:42 -0600739 i++;
740 } while (AttributeCount < i);
741
742 i = 0;
743 do {
744 VertexInputBindingDescription[i].binding = BindId;
745 VertexInputBindingDescription[i].stride = aByteStride;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600746 VertexInputBindingDescription[i].inputRate = VK_VERTEX_INPUT_RATE_VERTEX;
Mark Muellerdfe37552016-07-07 14:47:42 -0600747 i++;
748 } while (BindingCount < i);
749 }
750
751 ~VkVerticesObj() {
752 if (VertexInputAttributeDescription) {
753 delete[] VertexInputAttributeDescription;
754 }
755 if (VertexInputBindingDescription) {
756 delete[] VertexInputBindingDescription;
757 }
758 }
759
760 bool AddVertexInputToPipe(VkPipelineObj &aPipelineObj) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600761 aPipelineObj.AddVertexInputAttribs(VertexInputAttributeDescription, AttributeCount);
762 aPipelineObj.AddVertexInputBindings(VertexInputBindingDescription, BindingCount);
Mark Muellerdfe37552016-07-07 14:47:42 -0600763 return true;
764 }
765
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600766 void BindVertexBuffers(VkCommandBuffer aCommandBuffer, unsigned aOffsetCount = 0, VkDeviceSize *aOffsetList = nullptr) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600767 VkDeviceSize *offsetList;
768 unsigned offsetCount;
769
770 if (aOffsetCount) {
771 offsetList = aOffsetList;
772 offsetCount = aOffsetCount;
773 } else {
774 offsetList = new VkDeviceSize[1]();
775 offsetCount = 1;
776 }
777
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600778 vkCmdBindVertexBuffers(aCommandBuffer, BindId, offsetCount, &VulkanMemoryBuffer.handle(), offsetList);
Mark Muellerdfe37552016-07-07 14:47:42 -0600779 BoundCurrent = true;
780
781 if (!aOffsetCount) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600782 delete[] offsetList;
Mark Muellerdfe37552016-07-07 14:47:42 -0600783 }
784 }
785
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600786 protected:
Mark Muellerdfe37552016-07-07 14:47:42 -0600787 static uint32_t BindIdGenerator;
788
789 bool BoundCurrent;
790 unsigned AttributeCount;
791 unsigned BindingCount;
792 uint32_t BindId;
793
794 VkPipelineVertexInputStateCreateInfo PipelineVertexInputStateCreateInfo;
795 VkVertexInputAttributeDescription *VertexInputAttributeDescription;
796 VkVertexInputBindingDescription *VertexInputBindingDescription;
797 VkConstantBufferObj VulkanMemoryBuffer;
798};
799
800uint32_t VkVerticesObj::BindIdGenerator;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500801// ********************************************************************************************************************
802// ********************************************************************************************************************
803// ********************************************************************************************************************
804// ********************************************************************************************************************
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600805#if PARAMETER_VALIDATION_TESTS
806TEST_F(VkLayerTest, RequiredParameter) {
807 TEST_DESCRIPTION("Specify VK_NULL_HANDLE, NULL, and 0 for required handle, "
808 "pointer, array, and array count parameters");
809
810 ASSERT_NO_FATAL_FAILURE(InitState());
811
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600812 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pFeatures specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600813 // Specify NULL for a pointer to a handle
814 // Expected to trigger an error with
815 // parameter_validation::validate_required_pointer
816 vkGetPhysicalDeviceFeatures(gpu(), NULL);
817 m_errorMonitor->VerifyFound();
818
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600819 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
820 "required parameter pQueueFamilyPropertyCount specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600821 // Specify NULL for pointer to array count
822 // Expected to trigger an error with parameter_validation::validate_array
Dustin Gravesa4bb8c12016-05-16 17:22:51 -0600823 vkGetPhysicalDeviceQueueFamilyProperties(gpu(), NULL, NULL);
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600824 m_errorMonitor->VerifyFound();
825
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600826 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter viewportCount must be greater than 0");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600827 // Specify 0 for a required array count
828 // Expected to trigger an error with parameter_validation::validate_array
829 VkViewport view_port = {};
830 m_commandBuffer->SetViewport(0, 0, &view_port);
831 m_errorMonitor->VerifyFound();
832
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600833 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pViewports specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600834 // Specify NULL for a required array
835 // Expected to trigger an error with parameter_validation::validate_array
836 m_commandBuffer->SetViewport(0, 1, NULL);
837 m_errorMonitor->VerifyFound();
838
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600839 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter memory specified as VK_NULL_HANDLE");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600840 // Specify VK_NULL_HANDLE for a required handle
841 // Expected to trigger an error with
842 // parameter_validation::validate_required_handle
843 vkUnmapMemory(device(), VK_NULL_HANDLE);
844 m_errorMonitor->VerifyFound();
845
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600846 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
847 "required parameter pFences[0] specified as VK_NULL_HANDLE");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600848 // Specify VK_NULL_HANDLE for a required handle array entry
849 // Expected to trigger an error with
850 // parameter_validation::validate_required_handle_array
851 VkFence fence = VK_NULL_HANDLE;
852 vkResetFences(device(), 1, &fence);
853 m_errorMonitor->VerifyFound();
854
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600855 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pAllocateInfo specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600856 // Specify NULL for a required struct pointer
857 // Expected to trigger an error with
858 // parameter_validation::validate_struct_type
859 VkDeviceMemory memory = VK_NULL_HANDLE;
860 vkAllocateMemory(device(), NULL, NULL, &memory);
861 m_errorMonitor->VerifyFound();
862
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600863 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "value of faceMask must not be 0");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600864 // Specify 0 for a required VkFlags parameter
865 // Expected to trigger an error with parameter_validation::validate_flags
866 m_commandBuffer->SetStencilReference(0, 0);
867 m_errorMonitor->VerifyFound();
868
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600869 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "value of pSubmits[0].pWaitDstStageMask[0] must not be 0");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600870 // Specify 0 for a required VkFlags array entry
871 // Expected to trigger an error with
872 // parameter_validation::validate_flags_array
873 VkSemaphore semaphore = VK_NULL_HANDLE;
874 VkPipelineStageFlags stageFlags = 0;
875 VkSubmitInfo submitInfo = {};
876 submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
877 submitInfo.waitSemaphoreCount = 1;
878 submitInfo.pWaitSemaphores = &semaphore;
879 submitInfo.pWaitDstStageMask = &stageFlags;
880 vkQueueSubmit(m_device->m_queue, 1, &submitInfo, VK_NULL_HANDLE);
881 m_errorMonitor->VerifyFound();
882}
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600883
Dustin Gravesfce74c02016-05-10 11:42:58 -0600884TEST_F(VkLayerTest, ReservedParameter) {
885 TEST_DESCRIPTION("Specify a non-zero value for a reserved parameter");
886
887 ASSERT_NO_FATAL_FAILURE(InitState());
888
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600889 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " must be 0");
Dustin Gravesfce74c02016-05-10 11:42:58 -0600890 // Specify 0 for a reserved VkFlags parameter
891 // Expected to trigger an error with
892 // parameter_validation::validate_reserved_flags
893 VkEvent event_handle = VK_NULL_HANDLE;
894 VkEventCreateInfo event_info = {};
895 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
896 event_info.flags = 1;
897 vkCreateEvent(device(), &event_info, NULL, &event_handle);
898 m_errorMonitor->VerifyFound();
899}
900
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600901TEST_F(VkLayerTest, InvalidStructSType) {
902 TEST_DESCRIPTION("Specify an invalid VkStructureType for a Vulkan "
903 "structure's sType field");
904
905 ASSERT_NO_FATAL_FAILURE(InitState());
906
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600907 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pAllocateInfo->sType must be");
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600908 // Zero struct memory, effectively setting sType to
909 // VK_STRUCTURE_TYPE_APPLICATION_INFO
910 // Expected to trigger an error with
911 // parameter_validation::validate_struct_type
912 VkMemoryAllocateInfo alloc_info = {};
913 VkDeviceMemory memory = VK_NULL_HANDLE;
914 vkAllocateMemory(device(), &alloc_info, NULL, &memory);
915 m_errorMonitor->VerifyFound();
916
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600917 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pSubmits[0].sType must be");
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600918 // Zero struct memory, effectively setting sType to
919 // VK_STRUCTURE_TYPE_APPLICATION_INFO
920 // Expected to trigger an error with
921 // parameter_validation::validate_struct_type_array
922 VkSubmitInfo submit_info = {};
923 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
924 m_errorMonitor->VerifyFound();
925}
926
927TEST_F(VkLayerTest, InvalidStructPNext) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600928 TEST_DESCRIPTION("Specify an invalid value for a Vulkan structure's pNext field");
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600929
930 ASSERT_NO_FATAL_FAILURE(InitState());
931
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600932 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "value of pCreateInfo->pNext must be NULL");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600933 // Set VkMemoryAllocateInfo::pNext to a non-NULL value, when pNext must be NULL.
Karl Schultz38b50992016-07-11 16:09:09 -0600934 // Need to pick a function that has no allowed pNext structure types.
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600935 // Expected to trigger an error with parameter_validation::validate_struct_pnext
Karl Schultz38b50992016-07-11 16:09:09 -0600936 VkEvent event = VK_NULL_HANDLE;
Karl Schultz70db3902016-07-11 16:22:10 -0600937 VkEventCreateInfo event_alloc_info = {};
Karl Schultz38b50992016-07-11 16:09:09 -0600938 // Zero-initialization will provide the correct sType
939 VkApplicationInfo app_info = {};
940 event_alloc_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
941 event_alloc_info.pNext = &app_info;
942 vkCreateEvent(device(), &event_alloc_info, NULL, &event);
943 m_errorMonitor->VerifyFound();
944
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600945 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
946 " chain includes a structure with unexpected VkStructureType ");
Karl Schultz38b50992016-07-11 16:09:09 -0600947 // Set VkMemoryAllocateInfo::pNext to a non-NULL value, but use
948 // a function that has allowed pNext structure types and specify
949 // a structure type that is not allowed.
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600950 // Expected to trigger an error with parameter_validation::validate_struct_pnext
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600951 VkDeviceMemory memory = VK_NULL_HANDLE;
Dustin Graves47b6cba2016-05-10 17:34:38 -0600952 VkMemoryAllocateInfo memory_alloc_info = {};
953 memory_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
954 memory_alloc_info.pNext = &app_info;
955 vkAllocateMemory(device(), &memory_alloc_info, NULL, &memory);
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600956 m_errorMonitor->VerifyFound();
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600957}
Dustin Graves5d33d532016-05-09 16:21:12 -0600958
959TEST_F(VkLayerTest, UnrecognizedValue) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600960 TEST_DESCRIPTION("Specify unrecognized Vulkan enumeration, flags, and VkBool32 values");
Dustin Graves5d33d532016-05-09 16:21:12 -0600961
962 ASSERT_NO_FATAL_FAILURE(InitState());
963
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600964 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "does not fall within the begin..end "
965 "range of the core VkFormat "
966 "enumeration tokens");
Dustin Graves5d33d532016-05-09 16:21:12 -0600967 // Specify an invalid VkFormat value
968 // Expected to trigger an error with
969 // parameter_validation::validate_ranged_enum
970 VkFormatProperties format_properties;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600971 vkGetPhysicalDeviceFormatProperties(gpu(), static_cast<VkFormat>(8000), &format_properties);
Dustin Graves5d33d532016-05-09 16:21:12 -0600972 m_errorMonitor->VerifyFound();
973
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600974 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "contains flag bits that are not recognized members of");
Dustin Graves5d33d532016-05-09 16:21:12 -0600975 // Specify an invalid VkFlags bitmask value
976 // Expected to trigger an error with parameter_validation::validate_flags
977 VkImageFormatProperties image_format_properties;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600978 vkGetPhysicalDeviceImageFormatProperties(gpu(), VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
979 static_cast<VkImageUsageFlags>(1 << 25), 0, &image_format_properties);
Dustin Graves5d33d532016-05-09 16:21:12 -0600980 m_errorMonitor->VerifyFound();
981
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600982 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "contains flag bits that are not recognized members of");
Dustin Graves5d33d532016-05-09 16:21:12 -0600983 // Specify an invalid VkFlags array entry
984 // Expected to trigger an error with
985 // parameter_validation::validate_flags_array
986 VkSemaphore semaphore = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600987 VkPipelineStageFlags stage_flags = static_cast<VkPipelineStageFlags>(1 << 25);
Dustin Graves5d33d532016-05-09 16:21:12 -0600988 VkSubmitInfo submit_info = {};
989 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
990 submit_info.waitSemaphoreCount = 1;
991 submit_info.pWaitSemaphores = &semaphore;
992 submit_info.pWaitDstStageMask = &stage_flags;
993 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
994 m_errorMonitor->VerifyFound();
995
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600996 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "is neither VK_TRUE nor VK_FALSE");
Dustin Graves5d33d532016-05-09 16:21:12 -0600997 // Specify an invalid VkBool32 value
998 // Expected to trigger a warning with
999 // parameter_validation::validate_bool32
1000 VkSampler sampler = VK_NULL_HANDLE;
1001 VkSamplerCreateInfo sampler_info = {};
1002 sampler_info.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
1003 sampler_info.pNext = NULL;
1004 sampler_info.magFilter = VK_FILTER_NEAREST;
1005 sampler_info.minFilter = VK_FILTER_NEAREST;
1006 sampler_info.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
1007 sampler_info.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
1008 sampler_info.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
1009 sampler_info.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
1010 sampler_info.mipLodBias = 1.0;
1011 sampler_info.maxAnisotropy = 1;
1012 sampler_info.compareEnable = VK_FALSE;
1013 sampler_info.compareOp = VK_COMPARE_OP_NEVER;
1014 sampler_info.minLod = 1.0;
1015 sampler_info.maxLod = 1.0;
1016 sampler_info.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
1017 sampler_info.unnormalizedCoordinates = VK_FALSE;
1018 // Not VK_TRUE or VK_FALSE
1019 sampler_info.anisotropyEnable = 3;
1020 vkCreateSampler(m_device->device(), &sampler_info, NULL, &sampler);
1021 m_errorMonitor->VerifyFound();
1022}
Dustin Gravesfce74c02016-05-10 11:42:58 -06001023
1024TEST_F(VkLayerTest, FailedReturnValue) {
1025 TEST_DESCRIPTION("Check for a message describing a VkResult failure code");
1026
1027 ASSERT_NO_FATAL_FAILURE(InitState());
1028
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001029 // Find an unsupported image format
1030 VkFormat unsupported = VK_FORMAT_UNDEFINED;
1031 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
1032 VkFormat format = static_cast<VkFormat>(f);
1033 VkFormatProperties fProps = m_device->format_properties(format);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001034 if (format != VK_FORMAT_UNDEFINED && fProps.linearTilingFeatures == 0 && fProps.optimalTilingFeatures == 0) {
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001035 unsupported = format;
1036 break;
1037 }
1038 }
1039
1040 if (unsupported != VK_FORMAT_UNDEFINED) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001041 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
1042 "the requested format is not supported on this device");
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001043 // Specify an unsupported VkFormat value to generate a
1044 // VK_ERROR_FORMAT_NOT_SUPPORTED return code
1045 // Expected to trigger a warning from
1046 // parameter_validation::validate_result
1047 VkImageFormatProperties image_format_properties;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001048 VkResult err = vkGetPhysicalDeviceImageFormatProperties(gpu(), unsupported, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
1049 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, 0, &image_format_properties);
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001050 ASSERT_TRUE(err == VK_ERROR_FORMAT_NOT_SUPPORTED);
1051 m_errorMonitor->VerifyFound();
1052 }
Dustin Gravesfce74c02016-05-10 11:42:58 -06001053}
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001054
1055TEST_F(VkLayerTest, UpdateBufferAlignment) {
1056 TEST_DESCRIPTION("Check alignment parameters for vkCmdUpdateBuffer");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001057 uint32_t updateData[] = {1, 2, 3, 4, 5, 6, 7, 8};
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001058
1059 ASSERT_NO_FATAL_FAILURE(InitState());
1060
1061 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
1062 vk_testing::Buffer buffer;
1063 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
1064
1065 BeginCommandBuffer();
1066 // Introduce failure by using dstOffset that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001067 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001068 m_commandBuffer->UpdateBuffer(buffer.handle(), 1, 4, updateData);
1069 m_errorMonitor->VerifyFound();
1070
1071 // Introduce failure by using dataSize that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001072 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001073 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, 6, updateData);
1074 m_errorMonitor->VerifyFound();
1075
1076 // Introduce failure by using dataSize that is < 0
1077 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001078 "must be greater than zero and less than or equal to 65536");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001079 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, -44, updateData);
1080 m_errorMonitor->VerifyFound();
1081
1082 // Introduce failure by using dataSize that is > 65536
1083 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001084 "must be greater than zero and less than or equal to 65536");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001085 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, 80000, updateData);
1086 m_errorMonitor->VerifyFound();
1087
1088 EndCommandBuffer();
1089}
1090
1091TEST_F(VkLayerTest, FillBufferAlignment) {
1092 TEST_DESCRIPTION("Check alignment parameters for vkCmdFillBuffer");
1093
1094 ASSERT_NO_FATAL_FAILURE(InitState());
1095
1096 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
1097 vk_testing::Buffer buffer;
1098 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
1099
1100 BeginCommandBuffer();
1101
1102 // Introduce failure by using dstOffset that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001103 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001104 m_commandBuffer->FillBuffer(buffer.handle(), 1, 4, 0x11111111);
1105 m_errorMonitor->VerifyFound();
1106
1107 // Introduce failure by using size that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001108 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001109 m_commandBuffer->FillBuffer(buffer.handle(), 0, 6, 0x11111111);
1110 m_errorMonitor->VerifyFound();
1111
1112 // Introduce failure by using size that is zero
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001113 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "must be greater than zero");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001114 m_commandBuffer->FillBuffer(buffer.handle(), 0, 0, 0x11111111);
1115 m_errorMonitor->VerifyFound();
1116
1117 EndCommandBuffer();
1118}
Dustin Graves40f35822016-06-23 11:12:53 -06001119
Cortd889ff92016-07-27 09:51:27 -07001120TEST_F(VkLayerTest, PSOPolygonModeInvalid) {
1121 VkResult err;
1122
1123 TEST_DESCRIPTION("Attempt to use a non-solid polygon fill mode in a "
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001124 "pipeline when this feature is not enabled.");
Cortd889ff92016-07-27 09:51:27 -07001125
1126 ASSERT_NO_FATAL_FAILURE(InitState());
1127 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1128
1129 std::vector<const char *> device_extension_names;
1130 auto features = m_device->phy().features();
1131 // Artificially disable support for non-solid fill modes
1132 features.fillModeNonSolid = false;
1133 // The sacrificial device object
1134 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
1135
1136 VkRenderpassObj render_pass(&test_device);
1137
1138 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1139 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1140 pipeline_layout_ci.setLayoutCount = 0;
1141 pipeline_layout_ci.pSetLayouts = NULL;
1142
1143 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001144 err = vkCreatePipelineLayout(test_device.device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Cortd889ff92016-07-27 09:51:27 -07001145 ASSERT_VK_SUCCESS(err);
1146
1147 VkPipelineRasterizationStateCreateInfo rs_ci = {};
1148 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
1149 rs_ci.pNext = nullptr;
1150 rs_ci.lineWidth = 1.0f;
1151 rs_ci.rasterizerDiscardEnable = true;
1152
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001153 VkShaderObj vs(&test_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
1154 VkShaderObj fs(&test_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Cortd889ff92016-07-27 09:51:27 -07001155
Mark Lobodzinski5e644732016-08-15 16:51:19 -06001156 // Set polygonMode to unsupported value POINT, should fail
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001157 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1158 "polygonMode cannot be VK_POLYGON_MODE_POINT or VK_POLYGON_MODE_LINE");
Cortd889ff92016-07-27 09:51:27 -07001159 {
1160 VkPipelineObj pipe(&test_device);
1161 pipe.AddShader(&vs);
1162 pipe.AddShader(&fs);
1163 pipe.AddColorAttachment();
1164 // Introduce failure by setting unsupported polygon mode
1165 rs_ci.polygonMode = VK_POLYGON_MODE_POINT;
1166 pipe.SetRasterization(&rs_ci);
1167 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
1168 }
1169 m_errorMonitor->VerifyFound();
1170
1171 // Try again with polygonMode=LINE, should fail
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001172 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1173 "polygonMode cannot be VK_POLYGON_MODE_POINT or VK_POLYGON_MODE_LINE");
Cortd889ff92016-07-27 09:51:27 -07001174 {
1175 VkPipelineObj pipe(&test_device);
1176 pipe.AddShader(&vs);
1177 pipe.AddShader(&fs);
1178 pipe.AddColorAttachment();
1179 // Introduce failure by setting unsupported polygon mode
1180 rs_ci.polygonMode = VK_POLYGON_MODE_LINE;
1181 pipe.SetRasterization(&rs_ci);
1182 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
1183 }
1184 m_errorMonitor->VerifyFound();
1185
Cortd889ff92016-07-27 09:51:27 -07001186 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, NULL);
1187}
1188
Dustin Gravesffa90fa2016-05-06 11:20:38 -06001189#endif // PARAMETER_VALIDATION_TESTS
1190
Tobin Ehlis0788f522015-05-26 16:11:58 -06001191#if MEM_TRACKER_TESTS
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001192#if 0
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001193TEST_F(VkLayerTest, CallResetCommandBufferBeforeCompletion)
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001194{
1195 vk_testing::Fence testFence;
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001196 VkFenceCreateInfo fenceInfo = {};
1197 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1198 fenceInfo.pNext = NULL;
1199 fenceInfo.flags = 0;
1200
Mike Weiblencce7ec72016-10-17 19:33:05 -06001201 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Resetting command buffer");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001202
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001203 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbourc1eb1a52015-07-20 13:00:10 -06001204
1205 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
1206 vk_testing::Buffer buffer;
1207 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001208
Tony Barbourfe3351b2015-07-28 10:17:20 -06001209 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001210 m_commandBuffer->FillBuffer(buffer.handle(), 0, 4, 0x11111111);
Tony Barbourfe3351b2015-07-28 10:17:20 -06001211 EndCommandBuffer();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001212
1213 testFence.init(*m_device, fenceInfo);
1214
1215 // Bypass framework since it does the waits automatically
1216 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001217 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08001218 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1219 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001220 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001221 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07001222 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001223 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001224 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08001225 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001226 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06001227
1228 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001229 ASSERT_VK_SUCCESS( err );
1230
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001231 // Introduce failure by calling begin again before checking fence
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001232 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001233
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001234 m_errorMonitor->VerifyFound();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001235}
1236
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001237TEST_F(VkLayerTest, CallBeginCommandBufferBeforeCompletion)
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001238{
1239 vk_testing::Fence testFence;
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001240 VkFenceCreateInfo fenceInfo = {};
1241 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1242 fenceInfo.pNext = NULL;
1243 fenceInfo.flags = 0;
1244
Mike Weiblencce7ec72016-10-17 19:33:05 -06001245 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Calling vkBeginCommandBuffer() on active command buffer");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001246
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001247 ASSERT_NO_FATAL_FAILURE(InitState());
1248 ASSERT_NO_FATAL_FAILURE(InitViewport());
1249 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1250
Tony Barbourfe3351b2015-07-28 10:17:20 -06001251 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001252 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbourfe3351b2015-07-28 10:17:20 -06001253 EndCommandBuffer();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001254
1255 testFence.init(*m_device, fenceInfo);
1256
1257 // Bypass framework since it does the waits automatically
1258 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001259 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08001260 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1261 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001262 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001263 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07001264 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001265 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001266 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08001267 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001268 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06001269
1270 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001271 ASSERT_VK_SUCCESS( err );
1272
Jon Ashburnf19916e2016-01-11 13:12:43 -07001273 VkCommandBufferInheritanceInfo hinfo = {};
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001274 VkCommandBufferBeginInfo info = {};
1275 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
1276 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001277 info.renderPass = VK_NULL_HANDLE;
1278 info.subpass = 0;
1279 info.framebuffer = VK_NULL_HANDLE;
Chia-I Wub8d47ae2015-11-11 10:18:12 +08001280 info.occlusionQueryEnable = VK_FALSE;
1281 info.queryFlags = 0;
1282 info.pipelineStatistics = 0;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001283
1284 // Introduce failure by calling BCB again before checking fence
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001285 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001286
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001287 m_errorMonitor->VerifyFound();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001288}
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001289#endif
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001290
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;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001347
1348 VkBufferCreateInfo buf_info = {};
1349 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1350 buf_info.pNext = NULL;
1351 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
1352 buf_info.size = 256;
1353 buf_info.queueFamilyIndexCount = 0;
1354 buf_info.pQueueFamilyIndices = NULL;
1355 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1356 buf_info.flags = 0;
1357 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1358 ASSERT_VK_SUCCESS(err);
1359
Tobin Ehlis077ded32016-05-12 17:39:13 -06001360 vkGetBufferMemoryRequirements(m_device->device(), buffer, &buff_mem_reqs);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001361
1362 VkImageCreateInfo image_create_info = {};
1363 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1364 image_create_info.pNext = NULL;
1365 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1366 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
1367 image_create_info.extent.width = 64;
1368 image_create_info.extent.height = 64;
1369 image_create_info.extent.depth = 1;
1370 image_create_info.mipLevels = 1;
1371 image_create_info.arrayLayers = 1;
1372 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehlis12a4b5e2016-08-08 12:33:11 -06001373 // Image tiling must be optimal to trigger error when aliasing linear buffer
1374 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001375 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
1376 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
1377 image_create_info.queueFamilyIndexCount = 0;
1378 image_create_info.pQueueFamilyIndices = NULL;
1379 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1380 image_create_info.flags = 0;
1381
Tobin Ehlisf11be982016-05-11 13:52:53 -06001382 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1383 ASSERT_VK_SUCCESS(err);
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001384 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image2);
1385 ASSERT_VK_SUCCESS(err);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001386
Tobin Ehlis077ded32016-05-12 17:39:13 -06001387 vkGetImageMemoryRequirements(m_device->device(), image, &img_mem_reqs);
1388
1389 VkMemoryAllocateInfo alloc_info = {};
1390 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1391 alloc_info.pNext = NULL;
1392 alloc_info.memoryTypeIndex = 0;
1393 // Ensure memory is big enough for both bindings
1394 alloc_info.allocationSize = buff_mem_reqs.size + img_mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001395 pass = m_device->phy().set_memory_type(buff_mem_reqs.memoryTypeBits & img_mem_reqs.memoryTypeBits, &alloc_info,
1396 VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001397 if (!pass) {
Tobin Ehlis077ded32016-05-12 17:39:13 -06001398 vkDestroyBuffer(m_device->device(), buffer, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001399 vkDestroyImage(m_device->device(), image, NULL);
1400 return;
1401 }
Tobin Ehlis077ded32016-05-12 17:39:13 -06001402 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
1403 ASSERT_VK_SUCCESS(err);
1404 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
1405 ASSERT_VK_SUCCESS(err);
1406
Tobin Ehlis32b2bbc2016-12-13 17:33:41 -07001407 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, " is aliased with linear buffer 0x");
Tobin Ehlis077ded32016-05-12 17:39:13 -06001408 // VALIDATION FAILURE due to image mapping overlapping buffer mapping
Tobin Ehlisf11be982016-05-11 13:52:53 -06001409 err = vkBindImageMemory(m_device->device(), image, mem, 0);
1410 m_errorMonitor->VerifyFound();
1411
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001412 // Now correctly bind image2 to second mem allocation before incorrectly
Tobin Ehlis077ded32016-05-12 17:39:13 -06001413 // aliasing buffer2
1414 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer2);
1415 ASSERT_VK_SUCCESS(err);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001416 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem_img);
1417 ASSERT_VK_SUCCESS(err);
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001418 err = vkBindImageMemory(m_device->device(), image2, mem_img, 0);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001419 ASSERT_VK_SUCCESS(err);
Tobin Ehlis32b2bbc2016-12-13 17:33:41 -07001420 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "is aliased with non-linear image 0x");
Tobin Ehlis077ded32016-05-12 17:39:13 -06001421 err = vkBindBufferMemory(m_device->device(), buffer2, mem_img, 0);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001422 m_errorMonitor->VerifyFound();
1423
1424 vkDestroyBuffer(m_device->device(), buffer, NULL);
Tobin Ehlis077ded32016-05-12 17:39:13 -06001425 vkDestroyBuffer(m_device->device(), buffer2, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001426 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001427 vkDestroyImage(m_device->device(), image2, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001428 vkFreeMemory(m_device->device(), mem, NULL);
1429 vkFreeMemory(m_device->device(), mem_img, NULL);
1430}
1431
Tobin Ehlis35372522016-05-12 08:32:31 -06001432TEST_F(VkLayerTest, InvalidMemoryMapping) {
1433 TEST_DESCRIPTION("Attempt to map memory in a number of incorrect ways");
1434 VkResult err;
1435 bool pass;
1436 ASSERT_NO_FATAL_FAILURE(InitState());
1437
1438 VkBuffer buffer;
1439 VkDeviceMemory mem;
1440 VkMemoryRequirements mem_reqs;
1441
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001442 const VkDeviceSize atom_size = m_device->props.limits.nonCoherentAtomSize;
1443
Tobin Ehlis35372522016-05-12 08:32:31 -06001444 VkBufferCreateInfo buf_info = {};
1445 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1446 buf_info.pNext = NULL;
1447 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
1448 buf_info.size = 256;
1449 buf_info.queueFamilyIndexCount = 0;
1450 buf_info.pQueueFamilyIndices = NULL;
1451 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1452 buf_info.flags = 0;
1453 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1454 ASSERT_VK_SUCCESS(err);
1455
1456 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
1457 VkMemoryAllocateInfo alloc_info = {};
1458 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1459 alloc_info.pNext = NULL;
1460 alloc_info.memoryTypeIndex = 0;
1461
1462 // Ensure memory is big enough for both bindings
1463 static const VkDeviceSize allocation_size = 0x10000;
1464 alloc_info.allocationSize = allocation_size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001465 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 -06001466 if (!pass) {
1467 vkDestroyBuffer(m_device->device(), buffer, NULL);
1468 return;
1469 }
1470 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
1471 ASSERT_VK_SUCCESS(err);
1472
1473 uint8_t *pData;
1474 // Attempt to map memory size 0 is invalid
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001475 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 -06001476 err = vkMapMemory(m_device->device(), mem, 0, 0, 0, (void **)&pData);
1477 m_errorMonitor->VerifyFound();
1478 // Map memory twice
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001479 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001480 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001481 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1482 "VkMapMemory: Attempting to map memory on an already-mapped object ");
1483 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001484 m_errorMonitor->VerifyFound();
1485
1486 // Unmap the memory to avoid re-map error
1487 vkUnmapMemory(m_device->device(), mem);
1488 // overstep allocation with VK_WHOLE_SIZE
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001489 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1490 " with size of VK_WHOLE_SIZE oversteps total array size 0x");
1491 err = vkMapMemory(m_device->device(), mem, allocation_size + 1, VK_WHOLE_SIZE, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001492 m_errorMonitor->VerifyFound();
1493 // overstep allocation w/o VK_WHOLE_SIZE
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001494 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " oversteps total array size 0x");
1495 err = vkMapMemory(m_device->device(), mem, 1, allocation_size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001496 m_errorMonitor->VerifyFound();
1497 // Now error due to unmapping memory that's not mapped
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001498 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Unmapping Memory without memory being mapped: ");
Tobin Ehlis35372522016-05-12 08:32:31 -06001499 vkUnmapMemory(m_device->device(), mem);
1500 m_errorMonitor->VerifyFound();
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001501
Tobin Ehlis35372522016-05-12 08:32:31 -06001502 // Now map memory and cause errors due to flushing invalid ranges
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001503 err = vkMapMemory(m_device->device(), mem, 4 * atom_size, VK_WHOLE_SIZE, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001504 ASSERT_VK_SUCCESS(err);
1505 VkMappedMemoryRange mmr = {};
Chris Forbes3aec0892016-06-13 10:29:26 +12001506 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
Tobin Ehlis35372522016-05-12 08:32:31 -06001507 mmr.memory = mem;
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001508 mmr.offset = atom_size; // Error b/c offset less than offset of mapped mem
Mark Lobodzinskib3c675e2016-11-15 08:56:03 -07001509 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00642);
Tobin Ehlis35372522016-05-12 08:32:31 -06001510 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1511 m_errorMonitor->VerifyFound();
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001512
Tobin Ehlis35372522016-05-12 08:32:31 -06001513 // Now flush range that oversteps mapped range
1514 vkUnmapMemory(m_device->device(), mem);
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001515 err = vkMapMemory(m_device->device(), mem, 0, 4 * atom_size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001516 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001517 mmr.offset = atom_size;
1518 mmr.size = 4 * atom_size; // Flushing bounds exceed mapped bounds
Mark Lobodzinskib3c675e2016-11-15 08:56:03 -07001519 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00642);
1520 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1521 m_errorMonitor->VerifyFound();
1522
1523 // Now flush range with VK_WHOLE_SIZE that oversteps offset
1524 vkUnmapMemory(m_device->device(), mem);
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001525 err = vkMapMemory(m_device->device(), mem, 2 * atom_size, 4 * atom_size, 0, (void **)&pData);
Mark Lobodzinskib3c675e2016-11-15 08:56:03 -07001526 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001527 mmr.offset = atom_size;
Mark Lobodzinskib3c675e2016-11-15 08:56:03 -07001528 mmr.size = VK_WHOLE_SIZE;
1529 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00643);
Tobin Ehlis35372522016-05-12 08:32:31 -06001530 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1531 m_errorMonitor->VerifyFound();
1532
Tony Barboure3975eb2016-12-15 14:52:44 -07001533#if 0 // Planning discussion with working group on this validation check.
Mark Lobodzinski3826a4f2016-11-15 09:38:51 -07001534 // Some platforms have an atomsize of 1 which makes the test meaningless
1535 if (atom_size > 3) {
1536 // Now with an offset NOT a multiple of the device limit
1537 vkUnmapMemory(m_device->device(), mem);
1538 err = vkMapMemory(m_device->device(), mem, 0, 4 * atom_size, 0, (void **)&pData);
1539 ASSERT_VK_SUCCESS(err);
1540 mmr.offset = 3; // Not a multiple of atom_size
1541 mmr.size = VK_WHOLE_SIZE;
1542 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00644);
1543 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1544 m_errorMonitor->VerifyFound();
1545
1546 // Now with a size NOT a multiple of the device limit
1547 vkUnmapMemory(m_device->device(), mem);
1548 err = vkMapMemory(m_device->device(), mem, 0, 4 * atom_size, 0, (void **)&pData);
1549 ASSERT_VK_SUCCESS(err);
1550 mmr.offset = atom_size;
1551 mmr.size = 2 * atom_size + 1; // Not a multiple of atom_size
1552 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00645);
1553 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1554 m_errorMonitor->VerifyFound();
1555 }
Tony Barboure3975eb2016-12-15 14:52:44 -07001556#endif
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001557 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT,
1558 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Tobin Ehlis35372522016-05-12 08:32:31 -06001559 if (!pass) {
1560 vkFreeMemory(m_device->device(), mem, NULL);
1561 vkDestroyBuffer(m_device->device(), buffer, NULL);
1562 return;
1563 }
1564 // TODO : If we can get HOST_VISIBLE w/o HOST_COHERENT we can test cases of
1565 // MEMTRACK_INVALID_MAP in validateAndCopyNoncoherentMemoryToDriver()
1566
1567 vkDestroyBuffer(m_device->device(), buffer, NULL);
1568 vkFreeMemory(m_device->device(), mem, NULL);
1569}
1570
Chris Forbes09368e42016-10-13 11:59:22 +13001571#if 0 // disabled until PV gets real extension enable checks
Ian Elliott1c32c772016-04-28 14:47:13 -06001572TEST_F(VkLayerTest, EnableWsiBeforeUse) {
1573 VkResult err;
1574 bool pass;
1575
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001576 // FIXME: After we turn on this code for non-Linux platforms, uncomment the
1577 // following declaration (which is temporarily being moved below):
1578 // VkSurfaceKHR surface = VK_NULL_HANDLE;
Ian Elliott1c32c772016-04-28 14:47:13 -06001579 VkSwapchainKHR swapchain = VK_NULL_HANDLE;
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001580 VkSwapchainCreateInfoKHR swapchain_create_info = {VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR};
Ian Elliott1c32c772016-04-28 14:47:13 -06001581 uint32_t swapchain_image_count = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001582 // VkImage swapchain_images[1] = {VK_NULL_HANDLE};
Ian Elliott1c32c772016-04-28 14:47:13 -06001583 uint32_t image_index = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001584 // VkPresentInfoKHR present_info = {};
Ian Elliott1c32c772016-04-28 14:47:13 -06001585
1586 ASSERT_NO_FATAL_FAILURE(InitState());
1587
Ian Elliott3f06ce52016-04-29 14:46:21 -06001588#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
1589#if defined(VK_USE_PLATFORM_ANDROID_KHR)
1590 // Use the functions from the VK_KHR_android_surface extension without
1591 // enabling that extension:
1592
1593 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001594 VkAndroidSurfaceCreateInfoKHR android_create_info = {VK_STRUCTURE_TYPE_ANDROID_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001595 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1596 err = vkCreateAndroidSurfaceKHR(instance(), &android_create_info, NULL, &surface);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001597 pass = (err != VK_SUCCESS);
1598 ASSERT_TRUE(pass);
1599 m_errorMonitor->VerifyFound();
1600#endif // VK_USE_PLATFORM_ANDROID_KHR
1601
Ian Elliott3f06ce52016-04-29 14:46:21 -06001602#if defined(VK_USE_PLATFORM_MIR_KHR)
1603 // Use the functions from the VK_KHR_mir_surface extension without enabling
1604 // that extension:
1605
1606 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001607 VkMirSurfaceCreateInfoKHR mir_create_info = {VK_STRUCTURE_TYPE_MIR_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001608 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott3f06ce52016-04-29 14:46:21 -06001609 err = vkCreateMirSurfaceKHR(instance(), &mir_create_info, NULL, &surface);
1610 pass = (err != VK_SUCCESS);
1611 ASSERT_TRUE(pass);
1612 m_errorMonitor->VerifyFound();
1613
1614 // Tell whether an mir_connection supports presentation:
1615 MirConnection *mir_connection = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001616 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1617 vkGetPhysicalDeviceMirPresentationSupportKHR(gpu(), 0, mir_connection, visual_id);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001618 m_errorMonitor->VerifyFound();
1619#endif // VK_USE_PLATFORM_MIR_KHR
1620
Ian Elliott3f06ce52016-04-29 14:46:21 -06001621#if defined(VK_USE_PLATFORM_WAYLAND_KHR)
1622 // Use the functions from the VK_KHR_wayland_surface extension without
1623 // enabling that extension:
1624
1625 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001626 VkWaylandSurfaceCreateInfoKHR wayland_create_info = {VK_STRUCTURE_TYPE_WAYLAND_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001627 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1628 err = vkCreateWaylandSurfaceKHR(instance(), &wayland_create_info, NULL, &surface);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001629 pass = (err != VK_SUCCESS);
1630 ASSERT_TRUE(pass);
1631 m_errorMonitor->VerifyFound();
1632
1633 // Tell whether an wayland_display supports presentation:
1634 struct wl_display wayland_display = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001635 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1636 vkGetPhysicalDeviceWaylandPresentationSupportKHR(gpu(), 0, &wayland_display);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001637 m_errorMonitor->VerifyFound();
1638#endif // VK_USE_PLATFORM_WAYLAND_KHR
Ian Elliott489eec02016-05-05 14:12:44 -06001639#endif // NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott3f06ce52016-04-29 14:46:21 -06001640
Ian Elliott3f06ce52016-04-29 14:46:21 -06001641#if defined(VK_USE_PLATFORM_WIN32_KHR)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001642 // FIXME: REMOVE THIS HERE, AND UNCOMMENT ABOVE, WHEN THIS TEST HAS BEEN PORTED
1643 // TO NON-LINUX PLATFORMS:
1644 VkSurfaceKHR surface = VK_NULL_HANDLE;
Ian Elliott3f06ce52016-04-29 14:46:21 -06001645 // Use the functions from the VK_KHR_win32_surface extension without
1646 // enabling that extension:
1647
1648 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001649 VkWin32SurfaceCreateInfoKHR win32_create_info = {VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001650 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1651 err = vkCreateWin32SurfaceKHR(instance(), &win32_create_info, NULL, &surface);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001652 pass = (err != VK_SUCCESS);
1653 ASSERT_TRUE(pass);
1654 m_errorMonitor->VerifyFound();
1655
1656 // Tell whether win32 supports presentation:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001657 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott489eec02016-05-05 14:12:44 -06001658 vkGetPhysicalDeviceWin32PresentationSupportKHR(gpu(), 0);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001659 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001660// Set this (for now, until all platforms are supported and tested):
1661#define NEED_TO_TEST_THIS_ON_PLATFORM
1662#endif // VK_USE_PLATFORM_WIN32_KHR
Tony Barbour2e7bd402016-11-14 14:46:33 -07001663#if defined(VK_USE_PLATFORM_XCB_KHR) || defined (VK_USE_PLATFORM_XLIB_KHR)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001664 // FIXME: REMOVE THIS HERE, AND UNCOMMENT ABOVE, WHEN THIS TEST HAS BEEN PORTED
1665 // TO NON-LINUX PLATFORMS:
1666 VkSurfaceKHR surface = VK_NULL_HANDLE;
Tony Barbour2e7bd402016-11-14 14:46:33 -07001667#endif
1668#if defined(VK_USE_PLATFORM_XCB_KHR)
Ian Elliott1c32c772016-04-28 14:47:13 -06001669 // Use the functions from the VK_KHR_xcb_surface extension without enabling
1670 // that extension:
1671
1672 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001673 VkXcbSurfaceCreateInfoKHR xcb_create_info = {VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001674 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001675 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
1676 pass = (err != VK_SUCCESS);
1677 ASSERT_TRUE(pass);
1678 m_errorMonitor->VerifyFound();
1679
1680 // Tell whether an xcb_visualid_t supports presentation:
Ian Elliott3f06ce52016-04-29 14:46:21 -06001681 xcb_connection_t *xcb_connection = NULL;
Ian Elliott1c32c772016-04-28 14:47:13 -06001682 xcb_visualid_t visual_id = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001683 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1684 vkGetPhysicalDeviceXcbPresentationSupportKHR(gpu(), 0, xcb_connection, visual_id);
Ian Elliott1c32c772016-04-28 14:47:13 -06001685 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001686// Set this (for now, until all platforms are supported and tested):
1687#define NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06001688#endif // VK_USE_PLATFORM_XCB_KHR
1689
Ian Elliott12630812016-04-29 14:35:43 -06001690#if defined(VK_USE_PLATFORM_XLIB_KHR)
1691 // Use the functions from the VK_KHR_xlib_surface extension without enabling
1692 // that extension:
1693
1694 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001695 VkXlibSurfaceCreateInfoKHR xlib_create_info = {VK_STRUCTURE_TYPE_XLIB_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001696 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott12630812016-04-29 14:35:43 -06001697 err = vkCreateXlibSurfaceKHR(instance(), &xlib_create_info, NULL, &surface);
1698 pass = (err != VK_SUCCESS);
1699 ASSERT_TRUE(pass);
1700 m_errorMonitor->VerifyFound();
1701
1702 // Tell whether an Xlib VisualID supports presentation:
1703 Display *dpy = NULL;
1704 VisualID visual = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001705 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott12630812016-04-29 14:35:43 -06001706 vkGetPhysicalDeviceXlibPresentationSupportKHR(gpu(), 0, dpy, visual);
1707 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001708// Set this (for now, until all platforms are supported and tested):
1709#define NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott12630812016-04-29 14:35:43 -06001710#endif // VK_USE_PLATFORM_XLIB_KHR
1711
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001712// Use the functions from the VK_KHR_surface extension without enabling
1713// that extension:
Ian Elliott1c32c772016-04-28 14:47:13 -06001714
Ian Elliott489eec02016-05-05 14:12:44 -06001715#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06001716 // Destroy a surface:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001717 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001718 vkDestroySurfaceKHR(instance(), surface, NULL);
1719 m_errorMonitor->VerifyFound();
1720
1721 // Check if surface supports presentation:
1722 VkBool32 supported = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001723 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001724 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
1725 pass = (err != VK_SUCCESS);
1726 ASSERT_TRUE(pass);
1727 m_errorMonitor->VerifyFound();
1728
1729 // Check surface capabilities:
1730 VkSurfaceCapabilitiesKHR capabilities = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001731 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1732 err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), surface, &capabilities);
Ian Elliott1c32c772016-04-28 14:47:13 -06001733 pass = (err != VK_SUCCESS);
1734 ASSERT_TRUE(pass);
1735 m_errorMonitor->VerifyFound();
1736
1737 // Check surface formats:
1738 uint32_t format_count = 0;
1739 VkSurfaceFormatKHR *formats = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001740 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1741 err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &format_count, formats);
Ian Elliott1c32c772016-04-28 14:47:13 -06001742 pass = (err != VK_SUCCESS);
1743 ASSERT_TRUE(pass);
1744 m_errorMonitor->VerifyFound();
1745
1746 // Check surface present modes:
1747 uint32_t present_mode_count = 0;
1748 VkSurfaceFormatKHR *present_modes = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001749 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1750 err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &present_mode_count, present_modes);
Ian Elliott1c32c772016-04-28 14:47:13 -06001751 pass = (err != VK_SUCCESS);
1752 ASSERT_TRUE(pass);
1753 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001754#endif // NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06001755
Ian Elliott1c32c772016-04-28 14:47:13 -06001756 // Use the functions from the VK_KHR_swapchain extension without enabling
1757 // that extension:
1758
1759 // Create a swapchain:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001760 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001761 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
1762 swapchain_create_info.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001763 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
Ian Elliott1c32c772016-04-28 14:47:13 -06001764 pass = (err != VK_SUCCESS);
1765 ASSERT_TRUE(pass);
1766 m_errorMonitor->VerifyFound();
1767
1768 // Get the images from the swapchain:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001769 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1770 err = vkGetSwapchainImagesKHR(m_device->device(), swapchain, &swapchain_image_count, NULL);
Ian Elliott1c32c772016-04-28 14:47:13 -06001771 pass = (err != VK_SUCCESS);
1772 ASSERT_TRUE(pass);
1773 m_errorMonitor->VerifyFound();
1774
Chris Forbeseb7d5502016-09-13 18:19:21 +12001775 // Add a fence to avoid (justifiable) error about not providing fence OR semaphore
1776 VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
1777 VkFence fence;
1778 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
1779
Ian Elliott1c32c772016-04-28 14:47:13 -06001780 // Try to acquire an image:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001781 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Chris Forbeseb7d5502016-09-13 18:19:21 +12001782 err = vkAcquireNextImageKHR(m_device->device(), swapchain, 0, VK_NULL_HANDLE, fence, &image_index);
Ian Elliott1c32c772016-04-28 14:47:13 -06001783 pass = (err != VK_SUCCESS);
1784 ASSERT_TRUE(pass);
1785 m_errorMonitor->VerifyFound();
1786
Chris Forbeseb7d5502016-09-13 18:19:21 +12001787 vkDestroyFence(m_device->device(), fence, nullptr);
1788
Ian Elliott1c32c772016-04-28 14:47:13 -06001789 // Try to present an image:
Ian Elliott2c1daf52016-05-12 09:41:46 -06001790 //
1791 // NOTE: Currently can't test this because a real swapchain is needed (as
1792 // opposed to the fake one we created) in order for the layer to lookup the
1793 // VkDevice used to enable the extension:
Ian Elliott1c32c772016-04-28 14:47:13 -06001794
1795 // Destroy the swapchain:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001796 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001797 vkDestroySwapchainKHR(m_device->device(), swapchain, NULL);
1798 m_errorMonitor->VerifyFound();
1799}
Chris Forbes09368e42016-10-13 11:59:22 +13001800#endif
Ian Elliott1c32c772016-04-28 14:47:13 -06001801
Karl Schultz6addd812016-02-02 17:17:23 -07001802TEST_F(VkLayerTest, MapMemWithoutHostVisibleBit) {
1803 VkResult err;
1804 bool pass;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001805
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001806 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1807 "Mapping Memory without VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001808
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001809 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001810
1811 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07001812 VkImage image;
1813 VkDeviceMemory mem;
1814 VkMemoryRequirements mem_reqs;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001815
Karl Schultz6addd812016-02-02 17:17:23 -07001816 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
1817 const int32_t tex_width = 32;
1818 const int32_t tex_height = 32;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001819
Tony Barboureb254902015-07-15 12:50:33 -06001820 VkImageCreateInfo image_create_info = {};
1821 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07001822 image_create_info.pNext = NULL;
1823 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1824 image_create_info.format = tex_format;
1825 image_create_info.extent.width = tex_width;
1826 image_create_info.extent.height = tex_height;
1827 image_create_info.extent.depth = 1;
1828 image_create_info.mipLevels = 1;
1829 image_create_info.arrayLayers = 1;
1830 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
1831 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
1832 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
1833 image_create_info.flags = 0;
Chris Forbese65e4d02016-09-13 17:39:18 +12001834 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001835
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001836 VkMemoryAllocateInfo mem_alloc = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08001837 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07001838 mem_alloc.pNext = NULL;
1839 mem_alloc.allocationSize = 0;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001840
Chia-I Wuf7458c52015-10-26 21:10:41 +08001841 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001842 ASSERT_VK_SUCCESS(err);
1843
Karl Schultz6addd812016-02-02 17:17:23 -07001844 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001845
Mark Lobodzinski23065352015-05-29 09:32:35 -05001846 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001847
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001848 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 -07001849 if (!pass) { // If we can't find any unmappable memory this test doesn't
1850 // make sense
Chia-I Wuf7458c52015-10-26 21:10:41 +08001851 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbour02fdc7d2015-08-04 16:13:01 -06001852 return;
Mike Stroyand1c84a52015-08-18 14:40:24 -06001853 }
Mike Stroyan713b2d72015-08-04 10:49:29 -06001854
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001855 // allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001856 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001857 ASSERT_VK_SUCCESS(err);
1858
1859 // Try to bind free memory that has been freed
Tony Barbour67e99152015-07-10 14:10:27 -06001860 err = vkBindImageMemory(m_device->device(), image, mem, 0);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001861 ASSERT_VK_SUCCESS(err);
1862
1863 // Map memory as if to initialize the image
1864 void *mappedAddress = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001865 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, &mappedAddress);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001866
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001867 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06001868
Chia-I Wuf7458c52015-10-26 21:10:41 +08001869 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06001870 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001871}
1872
Karl Schultz6addd812016-02-02 17:17:23 -07001873TEST_F(VkLayerTest, RebindMemory) {
1874 VkResult err;
1875 bool pass;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001876
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001877 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "which has already been bound to mem object");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001878
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001879 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001880
1881 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07001882 VkImage image;
1883 VkDeviceMemory mem1;
1884 VkDeviceMemory mem2;
1885 VkMemoryRequirements mem_reqs;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001886
Karl Schultz6addd812016-02-02 17:17:23 -07001887 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
1888 const int32_t tex_width = 32;
1889 const int32_t tex_height = 32;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001890
Tony Barboureb254902015-07-15 12:50:33 -06001891 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07001892 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1893 image_create_info.pNext = NULL;
1894 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1895 image_create_info.format = tex_format;
1896 image_create_info.extent.width = tex_width;
1897 image_create_info.extent.height = tex_height;
1898 image_create_info.extent.depth = 1;
1899 image_create_info.mipLevels = 1;
1900 image_create_info.arrayLayers = 1;
1901 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
1902 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
1903 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
1904 image_create_info.flags = 0;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001905
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001906 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07001907 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1908 mem_alloc.pNext = NULL;
1909 mem_alloc.allocationSize = 0;
1910 mem_alloc.memoryTypeIndex = 0;
Tony Barboureb254902015-07-15 12:50:33 -06001911
Karl Schultz6addd812016-02-02 17:17:23 -07001912 // Introduce failure, do NOT set memProps to
1913 // VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
Tony Barboureb254902015-07-15 12:50:33 -06001914 mem_alloc.memoryTypeIndex = 1;
Chia-I Wuf7458c52015-10-26 21:10:41 +08001915 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001916 ASSERT_VK_SUCCESS(err);
1917
Karl Schultz6addd812016-02-02 17:17:23 -07001918 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001919
1920 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001921 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06001922 ASSERT_TRUE(pass);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001923
1924 // allocate 2 memory objects
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001925 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem1);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001926 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001927 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem2);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001928 ASSERT_VK_SUCCESS(err);
1929
1930 // Bind first memory object to Image object
Tony Barbour67e99152015-07-10 14:10:27 -06001931 err = vkBindImageMemory(m_device->device(), image, mem1, 0);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001932 ASSERT_VK_SUCCESS(err);
1933
Karl Schultz6addd812016-02-02 17:17:23 -07001934 // Introduce validation failure, try to bind a different memory object to
1935 // the same image object
Tony Barbour67e99152015-07-10 14:10:27 -06001936 err = vkBindImageMemory(m_device->device(), image, mem2, 0);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001937
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001938 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06001939
Chia-I Wuf7458c52015-10-26 21:10:41 +08001940 vkDestroyImage(m_device->device(), image, NULL);
1941 vkFreeMemory(m_device->device(), mem1, NULL);
1942 vkFreeMemory(m_device->device(), mem2, NULL);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001943}
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001944
Karl Schultz6addd812016-02-02 17:17:23 -07001945TEST_F(VkLayerTest, SubmitSignaledFence) {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001946 vk_testing::Fence testFence;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001947
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001948 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "submitted in SIGNALED state. Fences "
1949 "must be reset before being submitted");
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001950
1951 VkFenceCreateInfo fenceInfo = {};
Tony Barbour0b4d9562015-04-09 10:48:04 -06001952 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1953 fenceInfo.pNext = NULL;
1954 fenceInfo.flags = VK_FENCE_CREATE_SIGNALED_BIT;
Tony Barbour300a6082015-04-07 13:44:53 -06001955
Tony Barbour300a6082015-04-07 13:44:53 -06001956 ASSERT_NO_FATAL_FAILURE(InitState());
1957 ASSERT_NO_FATAL_FAILURE(InitViewport());
1958 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1959
Tony Barbourfe3351b2015-07-28 10:17:20 -06001960 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001961 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbourfe3351b2015-07-28 10:17:20 -06001962 EndCommandBuffer();
Tony Barbour300a6082015-04-07 13:44:53 -06001963
1964 testFence.init(*m_device, fenceInfo);
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001965
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001966 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08001967 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1968 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001969 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001970 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07001971 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001972 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001973 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08001974 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001975 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06001976
1977 vkQueueSubmit(m_device->m_queue, 1, &submit_info, testFence.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07001978 vkQueueWaitIdle(m_device->m_queue);
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001979
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001980 m_errorMonitor->VerifyFound();
Tony Barbour0b4d9562015-04-09 10:48:04 -06001981}
Chris Forbes4e44c912016-06-16 10:20:00 +12001982
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001983TEST_F(VkLayerTest, InvalidUsageBits) {
1984 TEST_DESCRIPTION("Specify wrong usage for image then create conflicting view of image "
1985 "Initialize buffer with wrong usage then perform copy expecting errors "
1986 "from both the image and the buffer (2 calls)");
1987 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid usage flag for image ");
Tobin Ehlis41376e12015-07-03 08:45:14 -06001988
1989 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesd2b5fe42016-11-28 18:00:00 +13001990
1991 auto format = VK_FORMAT_D24_UNORM_S8_UINT;
1992
Tony Barbourf92621a2016-05-02 14:28:12 -06001993 VkImageObj image(m_device);
Tony Barbour75d79f02016-08-30 09:39:07 -06001994 // Initialize image with USAGE_TRANSIENT_ATTACHMENT
Chris Forbesd2b5fe42016-11-28 18:00:00 +13001995 image.init(128, 128, format, VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
Karl Schultzb5bc11e2016-05-04 08:36:08 -06001996 ASSERT_TRUE(image.initialized());
Tobin Ehlis41376e12015-07-03 08:45:14 -06001997
Tony Barbourf92621a2016-05-02 14:28:12 -06001998 VkImageView dsv;
1999 VkImageViewCreateInfo dsvci = {};
2000 dsvci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
2001 dsvci.image = image.handle();
2002 dsvci.viewType = VK_IMAGE_VIEW_TYPE_2D;
Chris Forbesd2b5fe42016-11-28 18:00:00 +13002003 dsvci.format = format;
Tony Barbourf92621a2016-05-02 14:28:12 -06002004 dsvci.subresourceRange.layerCount = 1;
2005 dsvci.subresourceRange.baseMipLevel = 0;
2006 dsvci.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002007 dsvci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
Tobin Ehlis41376e12015-07-03 08:45:14 -06002008
Tony Barbourf92621a2016-05-02 14:28:12 -06002009 // Create a view with depth / stencil aspect for image with different usage
2010 vkCreateImageView(m_device->device(), &dsvci, NULL, &dsv);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002011
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002012 m_errorMonitor->VerifyFound();
Tony Barbourf92621a2016-05-02 14:28:12 -06002013
2014 // Initialize buffer with TRANSFER_DST usage
2015 vk_testing::Buffer buffer;
2016 VkMemoryPropertyFlags reqs = 0;
2017 buffer.init_as_dst(*m_device, 128 * 128, reqs);
2018 VkBufferImageCopy region = {};
2019 region.bufferRowLength = 128;
2020 region.bufferImageHeight = 128;
2021 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2022 region.imageSubresource.layerCount = 1;
2023 region.imageExtent.height = 16;
2024 region.imageExtent.width = 16;
2025 region.imageExtent.depth = 1;
2026
Tony Barbourf92621a2016-05-02 14:28:12 -06002027 // Buffer usage not set to TRANSFER_SRC and image usage not set to
2028 // TRANSFER_DST
2029 BeginCommandBuffer();
Tony Barbourf92621a2016-05-02 14:28:12 -06002030
Chris Forbesda581202016-10-06 18:25:26 +13002031 // two separate errors from this call:
2032 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "image should have VK_IMAGE_USAGE_TRANSFER_DST_BIT");
2033 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "buffer should have VK_BUFFER_USAGE_TRANSFER_SRC_BIT");
2034
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002035 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
2036 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Tony Barbourf92621a2016-05-02 14:28:12 -06002037 m_errorMonitor->VerifyFound();
Tobin Ehlis41376e12015-07-03 08:45:14 -06002038}
Tony Barbour75d79f02016-08-30 09:39:07 -06002039
Tony Barbour75d79f02016-08-30 09:39:07 -06002040
Mark Lobodzinski209b5292015-09-17 09:44:05 -06002041#endif // MEM_TRACKER_TESTS
2042
Tobin Ehlis4bf96d12015-06-25 11:58:41 -06002043#if OBJ_TRACKER_TESTS
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002044
2045TEST_F(VkLayerTest, LeakAnObject) {
2046 VkResult err;
2047
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002048 TEST_DESCRIPTION("Create a fence and destroy its device without first destroying the fence.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002049
2050 // Note that we have to create a new device since destroying the
2051 // framework's device causes Teardown() to fail and just calling Teardown
2052 // will destroy the errorMonitor.
2053
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002054 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "has not been destroyed.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002055
2056 ASSERT_NO_FATAL_FAILURE(InitState());
2057
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002058 const std::vector<VkQueueFamilyProperties> queue_props = m_device->queue_props;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002059 std::vector<VkDeviceQueueCreateInfo> queue_info;
2060 queue_info.reserve(queue_props.size());
2061 std::vector<std::vector<float>> queue_priorities;
2062 for (uint32_t i = 0; i < (uint32_t)queue_props.size(); i++) {
2063 VkDeviceQueueCreateInfo qi = {};
2064 qi.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
2065 qi.pNext = NULL;
2066 qi.queueFamilyIndex = i;
2067 qi.queueCount = queue_props[i].queueCount;
2068 queue_priorities.emplace_back(qi.queueCount, 0.0f);
2069 qi.pQueuePriorities = queue_priorities[i].data();
2070 queue_info.push_back(qi);
2071 }
2072
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002073 std::vector<const char *> device_extension_names;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002074
2075 // The sacrificial device object
2076 VkDevice testDevice;
2077 VkDeviceCreateInfo device_create_info = {};
2078 auto features = m_device->phy().features();
2079 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
2080 device_create_info.pNext = NULL;
2081 device_create_info.queueCreateInfoCount = queue_info.size();
2082 device_create_info.pQueueCreateInfos = queue_info.data();
Tony Barbour4c70d102016-08-08 16:06:56 -06002083 device_create_info.enabledLayerCount = 0;
2084 device_create_info.ppEnabledLayerNames = NULL;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002085 device_create_info.pEnabledFeatures = &features;
2086 err = vkCreateDevice(gpu(), &device_create_info, NULL, &testDevice);
2087 ASSERT_VK_SUCCESS(err);
2088
2089 VkFence fence;
2090 VkFenceCreateInfo fence_create_info = {};
2091 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
2092 fence_create_info.pNext = NULL;
2093 fence_create_info.flags = 0;
2094 err = vkCreateFence(testDevice, &fence_create_info, NULL, &fence);
2095 ASSERT_VK_SUCCESS(err);
2096
2097 // Induce failure by not calling vkDestroyFence
2098 vkDestroyDevice(testDevice, NULL);
2099 m_errorMonitor->VerifyFound();
2100}
2101
2102TEST_F(VkLayerTest, InvalidCommandPoolConsistency) {
2103
2104 TEST_DESCRIPTION("Allocate command buffers from one command pool and "
2105 "attempt to delete them from another.");
2106
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002107 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "FreeCommandBuffers is attempting to free Command Buffer");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002108
Cody Northropc31a84f2016-08-22 10:41:47 -06002109 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002110 VkCommandPool command_pool_one;
2111 VkCommandPool command_pool_two;
2112
2113 VkCommandPoolCreateInfo pool_create_info{};
2114 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
2115 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
2116 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
2117
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002118 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool_one);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002119
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002120 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool_two);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002121
Chris Forbes5ab04ec2016-11-28 18:03:11 +13002122 VkCommandBuffer cb;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002123 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002124 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002125 command_buffer_allocate_info.commandPool = command_pool_one;
Chris Forbes5ab04ec2016-11-28 18:03:11 +13002126 command_buffer_allocate_info.commandBufferCount = 1;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002127 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Chris Forbes5ab04ec2016-11-28 18:03:11 +13002128 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &cb);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002129
Chris Forbes5ab04ec2016-11-28 18:03:11 +13002130 vkFreeCommandBuffers(m_device->device(), command_pool_two, 1, &cb);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002131
2132 m_errorMonitor->VerifyFound();
2133
2134 vkDestroyCommandPool(m_device->device(), command_pool_one, NULL);
2135 vkDestroyCommandPool(m_device->device(), command_pool_two, NULL);
2136}
2137
2138TEST_F(VkLayerTest, InvalidDescriptorPoolConsistency) {
2139 VkResult err;
2140
2141 TEST_DESCRIPTION("Allocate descriptor sets from one DS pool and "
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002142 "attempt to delete them from another.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002143
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002144 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "FreeDescriptorSets is attempting to free descriptorSet");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002145
2146 ASSERT_NO_FATAL_FAILURE(InitState());
2147 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2148
2149 VkDescriptorPoolSize ds_type_count = {};
2150 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
2151 ds_type_count.descriptorCount = 1;
2152
2153 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2154 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2155 ds_pool_ci.pNext = NULL;
2156 ds_pool_ci.flags = 0;
2157 ds_pool_ci.maxSets = 1;
2158 ds_pool_ci.poolSizeCount = 1;
2159 ds_pool_ci.pPoolSizes = &ds_type_count;
2160
2161 VkDescriptorPool ds_pool_one;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002162 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool_one);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002163 ASSERT_VK_SUCCESS(err);
2164
2165 // Create a second descriptor pool
2166 VkDescriptorPool ds_pool_two;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002167 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool_two);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002168 ASSERT_VK_SUCCESS(err);
2169
2170 VkDescriptorSetLayoutBinding dsl_binding = {};
2171 dsl_binding.binding = 0;
2172 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
2173 dsl_binding.descriptorCount = 1;
2174 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2175 dsl_binding.pImmutableSamplers = NULL;
2176
2177 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2178 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2179 ds_layout_ci.pNext = NULL;
2180 ds_layout_ci.bindingCount = 1;
2181 ds_layout_ci.pBindings = &dsl_binding;
2182
2183 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002184 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002185 ASSERT_VK_SUCCESS(err);
2186
2187 VkDescriptorSet descriptorSet;
2188 VkDescriptorSetAllocateInfo alloc_info = {};
2189 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
2190 alloc_info.descriptorSetCount = 1;
2191 alloc_info.descriptorPool = ds_pool_one;
2192 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002193 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002194 ASSERT_VK_SUCCESS(err);
2195
2196 err = vkFreeDescriptorSets(m_device->device(), ds_pool_two, 1, &descriptorSet);
2197
2198 m_errorMonitor->VerifyFound();
2199
2200 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2201 vkDestroyDescriptorPool(m_device->device(), ds_pool_one, NULL);
2202 vkDestroyDescriptorPool(m_device->device(), ds_pool_two, NULL);
2203}
2204
2205TEST_F(VkLayerTest, CreateUnknownObject) {
Karl Schultzf78bcdd2016-11-30 12:36:01 -07002206 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00788);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002207
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002208 TEST_DESCRIPTION("Pass an invalid image object handle into a Vulkan API call.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002209
2210 ASSERT_NO_FATAL_FAILURE(InitState());
2211
2212 // Pass bogus handle into GetImageMemoryRequirements
2213 VkMemoryRequirements mem_reqs;
2214 uint64_t fakeImageHandle = 0xCADECADE;
2215 VkImage fauxImage = reinterpret_cast<VkImage &>(fakeImageHandle);
2216
2217 vkGetImageMemoryRequirements(m_device->device(), fauxImage, &mem_reqs);
2218
2219 m_errorMonitor->VerifyFound();
2220}
2221
Karl Schultz6addd812016-02-02 17:17:23 -07002222TEST_F(VkLayerTest, PipelineNotBound) {
2223 VkResult err;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002224
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002225 TEST_DESCRIPTION("Pass in an invalid pipeline object handle into a Vulkan API call.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002226
Karl Schultzf78bcdd2016-11-30 12:36:01 -07002227 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00601);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002228
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002229 ASSERT_NO_FATAL_FAILURE(InitState());
2230 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002231
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002232 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002233 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2234 ds_type_count.descriptorCount = 1;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002235
2236 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002237 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2238 ds_pool_ci.pNext = NULL;
2239 ds_pool_ci.maxSets = 1;
2240 ds_pool_ci.poolSizeCount = 1;
2241 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002242
2243 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002244 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002245 ASSERT_VK_SUCCESS(err);
2246
2247 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002248 dsl_binding.binding = 0;
2249 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2250 dsl_binding.descriptorCount = 1;
2251 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2252 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002253
2254 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002255 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2256 ds_layout_ci.pNext = NULL;
2257 ds_layout_ci.bindingCount = 1;
2258 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002259
2260 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002261 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002262 ASSERT_VK_SUCCESS(err);
2263
2264 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002265 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08002266 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07002267 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06002268 alloc_info.descriptorPool = ds_pool;
2269 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002270 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002271 ASSERT_VK_SUCCESS(err);
2272
2273 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002274 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
2275 pipeline_layout_ci.pNext = NULL;
2276 pipeline_layout_ci.setLayoutCount = 1;
2277 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002278
2279 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002280 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002281 ASSERT_VK_SUCCESS(err);
2282
Mark Youngad779052016-01-06 14:26:04 -07002283 VkPipeline badPipeline = (VkPipeline)((size_t)0xbaadb1be);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002284
2285 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002286 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, badPipeline);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002287
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002288 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002289
Chia-I Wuf7458c52015-10-26 21:10:41 +08002290 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
2291 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2292 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002293}
Mike Stroyan80fc6c32016-06-20 15:42:29 -06002294
Mark Lobodzinskibc185762016-06-15 16:28:53 -06002295TEST_F(VkLayerTest, BindImageInvalidMemoryType) {
2296 VkResult err;
2297
2298 TEST_DESCRIPTION("Test validation check for an invalid memory type index "
2299 "during bind[Buffer|Image]Memory time");
2300
Mark Lobodzinskibc185762016-06-15 16:28:53 -06002301 ASSERT_NO_FATAL_FAILURE(InitState());
2302
2303 // Create an image, allocate memory, set a bad typeIndex and then try to
2304 // bind it
2305 VkImage image;
2306 VkDeviceMemory mem;
2307 VkMemoryRequirements mem_reqs;
2308 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2309 const int32_t tex_width = 32;
2310 const int32_t tex_height = 32;
2311
2312 VkImageCreateInfo image_create_info = {};
2313 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2314 image_create_info.pNext = NULL;
2315 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2316 image_create_info.format = tex_format;
2317 image_create_info.extent.width = tex_width;
2318 image_create_info.extent.height = tex_height;
2319 image_create_info.extent.depth = 1;
2320 image_create_info.mipLevels = 1;
2321 image_create_info.arrayLayers = 1;
2322 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2323 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
2324 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2325 image_create_info.flags = 0;
2326
2327 VkMemoryAllocateInfo mem_alloc = {};
2328 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2329 mem_alloc.pNext = NULL;
2330 mem_alloc.allocationSize = 0;
2331 mem_alloc.memoryTypeIndex = 0;
2332
2333 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
2334 ASSERT_VK_SUCCESS(err);
2335
2336 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
2337 mem_alloc.allocationSize = mem_reqs.size;
Mike Stroyan80fc6c32016-06-20 15:42:29 -06002338
2339 // Introduce Failure, select invalid TypeIndex
2340 VkPhysicalDeviceMemoryProperties memory_info;
2341
2342 vkGetPhysicalDeviceMemoryProperties(gpu(), &memory_info);
2343 unsigned int i;
2344 for (i = 0; i < memory_info.memoryTypeCount; i++) {
2345 if ((mem_reqs.memoryTypeBits & (1 << i)) == 0) {
2346 mem_alloc.memoryTypeIndex = i;
2347 break;
2348 }
2349 }
2350 if (i >= memory_info.memoryTypeCount) {
2351 printf("No invalid memory type index could be found; skipped.\n");
2352 vkDestroyImage(m_device->device(), image, NULL);
2353 return;
2354 }
2355
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002356 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 -06002357
2358 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
2359 ASSERT_VK_SUCCESS(err);
2360
2361 err = vkBindImageMemory(m_device->device(), image, mem, 0);
2362 (void)err;
2363
2364 m_errorMonitor->VerifyFound();
2365
2366 vkDestroyImage(m_device->device(), image, NULL);
2367 vkFreeMemory(m_device->device(), mem, NULL);
2368}
Mike Stroyan80fc6c32016-06-20 15:42:29 -06002369
Karl Schultz6addd812016-02-02 17:17:23 -07002370TEST_F(VkLayerTest, BindInvalidMemory) {
2371 VkResult err;
2372 bool pass;
Tobin Ehlisec598302015-09-15 15:02:17 -06002373
Karl Schultzf78bcdd2016-11-30 12:36:01 -07002374 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00809);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002375
Tobin Ehlisec598302015-09-15 15:02:17 -06002376 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisec598302015-09-15 15:02:17 -06002377
2378 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07002379 VkImage image;
2380 VkDeviceMemory mem;
2381 VkMemoryRequirements mem_reqs;
Tobin Ehlisec598302015-09-15 15:02:17 -06002382
Karl Schultz6addd812016-02-02 17:17:23 -07002383 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2384 const int32_t tex_width = 32;
2385 const int32_t tex_height = 32;
Tobin Ehlisec598302015-09-15 15:02:17 -06002386
2387 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002388 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2389 image_create_info.pNext = NULL;
2390 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2391 image_create_info.format = tex_format;
2392 image_create_info.extent.width = tex_width;
2393 image_create_info.extent.height = tex_height;
2394 image_create_info.extent.depth = 1;
2395 image_create_info.mipLevels = 1;
2396 image_create_info.arrayLayers = 1;
2397 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2398 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2399 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2400 image_create_info.flags = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002401
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002402 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002403 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2404 mem_alloc.pNext = NULL;
2405 mem_alloc.allocationSize = 0;
2406 mem_alloc.memoryTypeIndex = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002407
Chia-I Wuf7458c52015-10-26 21:10:41 +08002408 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlisec598302015-09-15 15:02:17 -06002409 ASSERT_VK_SUCCESS(err);
2410
Karl Schultz6addd812016-02-02 17:17:23 -07002411 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Tobin Ehlisec598302015-09-15 15:02:17 -06002412
2413 mem_alloc.allocationSize = mem_reqs.size;
2414
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002415 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06002416 ASSERT_TRUE(pass);
Tobin Ehlisec598302015-09-15 15:02:17 -06002417
2418 // allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002419 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlisec598302015-09-15 15:02:17 -06002420 ASSERT_VK_SUCCESS(err);
2421
2422 // Introduce validation failure, free memory before binding
Chia-I Wuf7458c52015-10-26 21:10:41 +08002423 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002424
2425 // Try to bind free memory that has been freed
2426 err = vkBindImageMemory(m_device->device(), image, mem, 0);
2427 // This may very well return an error.
2428 (void)err;
2429
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002430 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002431
Chia-I Wuf7458c52015-10-26 21:10:41 +08002432 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002433}
2434
Karl Schultz6addd812016-02-02 17:17:23 -07002435TEST_F(VkLayerTest, BindMemoryToDestroyedObject) {
2436 VkResult err;
2437 bool pass;
Tobin Ehlisec598302015-09-15 15:02:17 -06002438
Karl Schultzf78bcdd2016-11-30 12:36:01 -07002439 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00808);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002440
Tobin Ehlisec598302015-09-15 15:02:17 -06002441 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisec598302015-09-15 15:02:17 -06002442
Karl Schultz6addd812016-02-02 17:17:23 -07002443 // Create an image object, allocate memory, destroy the object and then try
2444 // to bind it
2445 VkImage image;
2446 VkDeviceMemory mem;
2447 VkMemoryRequirements mem_reqs;
Tobin Ehlisec598302015-09-15 15:02:17 -06002448
Karl Schultz6addd812016-02-02 17:17:23 -07002449 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2450 const int32_t tex_width = 32;
2451 const int32_t tex_height = 32;
Tobin Ehlisec598302015-09-15 15:02:17 -06002452
2453 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002454 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2455 image_create_info.pNext = NULL;
2456 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2457 image_create_info.format = tex_format;
2458 image_create_info.extent.width = tex_width;
2459 image_create_info.extent.height = tex_height;
2460 image_create_info.extent.depth = 1;
2461 image_create_info.mipLevels = 1;
2462 image_create_info.arrayLayers = 1;
2463 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2464 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2465 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2466 image_create_info.flags = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002467
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002468 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002469 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2470 mem_alloc.pNext = NULL;
2471 mem_alloc.allocationSize = 0;
2472 mem_alloc.memoryTypeIndex = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002473
Chia-I Wuf7458c52015-10-26 21:10:41 +08002474 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlisec598302015-09-15 15:02:17 -06002475 ASSERT_VK_SUCCESS(err);
2476
Karl Schultz6addd812016-02-02 17:17:23 -07002477 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Tobin Ehlisec598302015-09-15 15:02:17 -06002478
2479 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002480 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06002481 ASSERT_TRUE(pass);
Tobin Ehlisec598302015-09-15 15:02:17 -06002482
2483 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002484 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlisec598302015-09-15 15:02:17 -06002485 ASSERT_VK_SUCCESS(err);
2486
2487 // Introduce validation failure, destroy Image object before binding
Chia-I Wuf7458c52015-10-26 21:10:41 +08002488 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002489 ASSERT_VK_SUCCESS(err);
2490
2491 // Now Try to bind memory to this destroyed object
2492 err = vkBindImageMemory(m_device->device(), image, mem, 0);
2493 // This may very well return an error.
Karl Schultz6addd812016-02-02 17:17:23 -07002494 (void)err;
Tobin Ehlisec598302015-09-15 15:02:17 -06002495
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002496 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002497
Chia-I Wuf7458c52015-10-26 21:10:41 +08002498 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002499}
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002500
Mark Lobodzinski209b5292015-09-17 09:44:05 -06002501#endif // OBJ_TRACKER_TESTS
2502
Tobin Ehlis0788f522015-05-26 16:11:58 -06002503#if DRAW_STATE_TESTS
Mark Lobodzinskic808d442016-04-14 10:57:23 -06002504
Mark Lobodzinski66e5eab2016-11-15 13:30:38 -07002505TEST_F(VkLayerTest, CreatePipelineBadVertexAttributeFormat) {
2506 TEST_DESCRIPTION("Test that pipeline validation catches invalid vertex attribute formats");
2507
2508 ASSERT_NO_FATAL_FAILURE(InitState());
2509 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2510
2511 VkVertexInputBindingDescription input_binding;
2512 memset(&input_binding, 0, sizeof(input_binding));
2513
2514 VkVertexInputAttributeDescription input_attribs;
2515 memset(&input_attribs, 0, sizeof(input_attribs));
2516
2517 // Pick a really bad format for this purpose and make sure it should fail
2518 input_attribs.format = VK_FORMAT_BC2_UNORM_BLOCK;
2519 VkFormatProperties format_props = m_device->format_properties(input_attribs.format);
2520 if ((format_props.bufferFeatures & VK_FORMAT_FEATURE_VERTEX_BUFFER_BIT) != 0) {
2521 printf("Format unsuitable for test; skipped.\n");
2522 return;
2523 }
2524
2525 input_attribs.location = 0;
2526 char const *vsSource = "#version 450\n"
2527 "\n"
2528 "out gl_PerVertex {\n"
2529 " vec4 gl_Position;\n"
2530 "};\n"
2531 "void main(){\n"
2532 " gl_Position = vec4(1);\n"
2533 "}\n";
2534 char const *fsSource = "#version 450\n"
2535 "\n"
2536 "layout(location=0) out vec4 color;\n"
2537 "void main(){\n"
2538 " color = vec4(1);\n"
2539 "}\n";
2540
2541 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01413);
2542 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
2543 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
2544
2545 VkPipelineObj pipe(m_device);
2546 pipe.AddColorAttachment();
2547 pipe.AddShader(&vs);
2548 pipe.AddShader(&fs);
2549
2550 pipe.AddVertexInputBindings(&input_binding, 1);
2551 pipe.AddVertexInputAttribs(&input_attribs, 1);
2552
2553 VkDescriptorSetObj descriptorSet(m_device);
2554 descriptorSet.AppendDummy();
2555 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
2556
2557 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
2558
2559 m_errorMonitor->VerifyFound();
2560}
2561
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002562TEST_F(VkLayerTest, ImageSampleCounts) {
2563
2564 TEST_DESCRIPTION("Use bad sample counts in image transfer calls to trigger "
2565 "validation errors.");
2566 ASSERT_NO_FATAL_FAILURE(InitState());
2567
2568 VkMemoryPropertyFlags reqs = 0;
2569 VkImageCreateInfo image_create_info = {};
2570 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2571 image_create_info.pNext = NULL;
2572 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2573 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
2574 image_create_info.extent.width = 256;
2575 image_create_info.extent.height = 256;
2576 image_create_info.extent.depth = 1;
2577 image_create_info.mipLevels = 1;
2578 image_create_info.arrayLayers = 1;
2579 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
2580 image_create_info.flags = 0;
2581
2582 VkImageBlit blit_region = {};
2583 blit_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2584 blit_region.srcSubresource.baseArrayLayer = 0;
2585 blit_region.srcSubresource.layerCount = 1;
2586 blit_region.srcSubresource.mipLevel = 0;
2587 blit_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2588 blit_region.dstSubresource.baseArrayLayer = 0;
2589 blit_region.dstSubresource.layerCount = 1;
2590 blit_region.dstSubresource.mipLevel = 0;
2591
2592 // Create two images, the source with sampleCount = 2, and attempt to blit
2593 // between them
2594 {
2595 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002596 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002597 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002598 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002599 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002600 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002601 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002602 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002603 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002604 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "was created with a sample count "
2605 "of VK_SAMPLE_COUNT_2_BIT but "
2606 "must be VK_SAMPLE_COUNT_1_BIT");
2607 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
2608 dst_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, 1, &blit_region, VK_FILTER_NEAREST);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002609 m_errorMonitor->VerifyFound();
2610 m_commandBuffer->EndCommandBuffer();
2611 }
2612
2613 // Create two images, the dest with sampleCount = 4, and attempt to blit
2614 // between them
2615 {
2616 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002617 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002618 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002619 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002620 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002621 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002622 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002623 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002624 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002625 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "was created with a sample count "
2626 "of VK_SAMPLE_COUNT_4_BIT but "
2627 "must be VK_SAMPLE_COUNT_1_BIT");
2628 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
2629 dst_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, 1, &blit_region, VK_FILTER_NEAREST);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002630 m_errorMonitor->VerifyFound();
2631 m_commandBuffer->EndCommandBuffer();
2632 }
2633
2634 VkBufferImageCopy copy_region = {};
2635 copy_region.bufferRowLength = 128;
2636 copy_region.bufferImageHeight = 128;
2637 copy_region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2638 copy_region.imageSubresource.layerCount = 1;
2639 copy_region.imageExtent.height = 64;
2640 copy_region.imageExtent.width = 64;
2641 copy_region.imageExtent.depth = 1;
2642
2643 // Create src buffer and dst image with sampleCount = 4 and attempt to copy
2644 // buffer to image
2645 {
2646 vk_testing::Buffer src_buffer;
2647 VkMemoryPropertyFlags reqs = 0;
2648 src_buffer.init_as_src(*m_device, 128 * 128 * 4, reqs);
2649 image_create_info.samples = VK_SAMPLE_COUNT_8_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002650 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002651 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002652 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002653 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002654 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "was created with a sample count "
2655 "of VK_SAMPLE_COUNT_8_BIT but "
2656 "must be VK_SAMPLE_COUNT_1_BIT");
2657 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), src_buffer.handle(), dst_image.handle(),
2658 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &copy_region);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002659 m_errorMonitor->VerifyFound();
2660 m_commandBuffer->EndCommandBuffer();
2661 }
2662
2663 // Create dst buffer and src image with sampleCount = 2 and attempt to copy
2664 // image to buffer
2665 {
2666 vk_testing::Buffer dst_buffer;
2667 dst_buffer.init_as_dst(*m_device, 128 * 128 * 4, reqs);
2668 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002669 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002670 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002671 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002672 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002673 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "was created with a sample count "
2674 "of VK_SAMPLE_COUNT_2_BIT but "
2675 "must be VK_SAMPLE_COUNT_1_BIT");
2676 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002677 dst_buffer.handle(), 1, &copy_region);
2678 m_errorMonitor->VerifyFound();
2679 m_commandBuffer->EndCommandBuffer();
2680 }
2681}
2682
Mike Stroyanac5afeb2016-10-17 13:58:10 -06002683TEST_F(VkLayerTest, BlitImageFormats) {
2684
2685 // Image blit with mismatched formats
2686 const char * expected_message =
2687 "vkCmdBlitImage: If one of srcImage and dstImage images has signed/unsigned integer format,"
2688 " the other one must also have signed/unsigned integer format";
2689
2690 ASSERT_NO_FATAL_FAILURE(InitState());
2691
2692 VkImageObj src_image(m_device);
2693 src_image.init(64, 64, VK_FORMAT_A2B10G10R10_UINT_PACK32, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_LINEAR, 0);
2694 VkImageObj dst_image(m_device);
2695 dst_image.init(64, 64, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
2696 VkImageObj dst_image2(m_device);
Mike Stroyan131f3e72016-10-18 11:10:23 -06002697 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 -06002698
2699 VkImageBlit blitRegion = {};
2700 blitRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2701 blitRegion.srcSubresource.baseArrayLayer = 0;
2702 blitRegion.srcSubresource.layerCount = 1;
2703 blitRegion.srcSubresource.mipLevel = 0;
2704 blitRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2705 blitRegion.dstSubresource.baseArrayLayer = 0;
2706 blitRegion.dstSubresource.layerCount = 1;
2707 blitRegion.dstSubresource.mipLevel = 0;
2708
2709 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, expected_message);
2710
2711 // Unsigned int vs not an int
2712 BeginCommandBuffer();
2713 vkCmdBlitImage(m_commandBuffer->handle(), src_image.image(), src_image.layout(), dst_image.image(),
2714 dst_image.layout(), 1, &blitRegion, VK_FILTER_NEAREST);
2715
2716 m_errorMonitor->VerifyFound();
2717
2718 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, expected_message);
2719
2720 // Unsigned int vs signed int
2721 vkCmdBlitImage(m_commandBuffer->handle(), src_image.image(), src_image.layout(), dst_image2.image(),
2722 dst_image2.layout(), 1, &blitRegion, VK_FILTER_NEAREST);
2723
2724 m_errorMonitor->VerifyFound();
2725
2726 EndCommandBuffer();
2727}
2728
2729
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002730TEST_F(VkLayerTest, DSImageTransferGranularityTests) {
2731 VkResult err;
2732 bool pass;
2733
2734 TEST_DESCRIPTION("Tests for validaiton of Queue Family property minImageTransferGranularity.");
2735 ASSERT_NO_FATAL_FAILURE(InitState());
2736
2737 // If w/d/h granularity is 1, test is not meaningful
2738 // TODO: When virtual device limits are available, create a set of limits for this test that
2739 // will always have a granularity of > 1 for w, h, and d
2740 auto index = m_device->graphics_queue_node_index_;
2741 auto queue_family_properties = m_device->phy().queue_properties();
2742
2743 if ((queue_family_properties[index].minImageTransferGranularity.depth < 4) ||
2744 (queue_family_properties[index].minImageTransferGranularity.width < 4) ||
2745 (queue_family_properties[index].minImageTransferGranularity.height < 4)) {
2746 return;
2747 }
2748
2749 // Create two images of different types and try to copy between them
2750 VkImage srcImage;
2751 VkImage dstImage;
2752 VkDeviceMemory srcMem;
2753 VkDeviceMemory destMem;
2754 VkMemoryRequirements memReqs;
2755
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002756 VkImageCreateInfo image_create_info = {};
2757 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2758 image_create_info.pNext = NULL;
2759 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2760 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
2761 image_create_info.extent.width = 32;
2762 image_create_info.extent.height = 32;
2763 image_create_info.extent.depth = 1;
2764 image_create_info.mipLevels = 1;
2765 image_create_info.arrayLayers = 4;
2766 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2767 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
2768 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
2769 image_create_info.flags = 0;
2770
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002771 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002772 ASSERT_VK_SUCCESS(err);
2773
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002774 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002775 ASSERT_VK_SUCCESS(err);
2776
2777 // Allocate memory
2778 VkMemoryAllocateInfo memAlloc = {};
2779 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2780 memAlloc.pNext = NULL;
2781 memAlloc.allocationSize = 0;
2782 memAlloc.memoryTypeIndex = 0;
2783
2784 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
2785 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002786 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002787 ASSERT_TRUE(pass);
2788 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
2789 ASSERT_VK_SUCCESS(err);
2790
2791 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
2792 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002793 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002794 ASSERT_VK_SUCCESS(err);
2795 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
2796 ASSERT_VK_SUCCESS(err);
2797
2798 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
2799 ASSERT_VK_SUCCESS(err);
2800 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
2801 ASSERT_VK_SUCCESS(err);
2802
2803 BeginCommandBuffer();
2804 VkImageCopy copyRegion;
2805 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2806 copyRegion.srcSubresource.mipLevel = 0;
2807 copyRegion.srcSubresource.baseArrayLayer = 0;
2808 copyRegion.srcSubresource.layerCount = 1;
2809 copyRegion.srcOffset.x = 0;
2810 copyRegion.srcOffset.y = 0;
2811 copyRegion.srcOffset.z = 0;
2812 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2813 copyRegion.dstSubresource.mipLevel = 0;
2814 copyRegion.dstSubresource.baseArrayLayer = 0;
2815 copyRegion.dstSubresource.layerCount = 1;
2816 copyRegion.dstOffset.x = 0;
2817 copyRegion.dstOffset.y = 0;
2818 copyRegion.dstOffset.z = 0;
2819 copyRegion.extent.width = 1;
2820 copyRegion.extent.height = 1;
2821 copyRegion.extent.depth = 1;
2822
2823 // Introduce failure by setting srcOffset to a bad granularity value
2824 copyRegion.srcOffset.y = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002825 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2826 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002827 m_errorMonitor->VerifyFound();
2828
2829 // Introduce failure by setting extent to a bad granularity value
2830 copyRegion.srcOffset.y = 0;
2831 copyRegion.extent.width = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002832 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2833 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002834 m_errorMonitor->VerifyFound();
2835
2836 // Now do some buffer/image copies
2837 vk_testing::Buffer buffer;
2838 VkMemoryPropertyFlags reqs = 0;
2839 buffer.init_as_dst(*m_device, 128 * 128, reqs);
2840 VkBufferImageCopy region = {};
2841 region.bufferOffset = 0;
2842 region.bufferRowLength = 3;
2843 region.bufferImageHeight = 128;
2844 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2845 region.imageSubresource.layerCount = 1;
2846 region.imageExtent.height = 16;
2847 region.imageExtent.width = 16;
2848 region.imageExtent.depth = 1;
2849 region.imageOffset.x = 0;
2850 region.imageOffset.y = 0;
2851 region.imageOffset.z = 0;
2852
2853 // Introduce failure by setting bufferRowLength to a bad granularity value
2854 region.bufferRowLength = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002855 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2856 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
2857 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002858 m_errorMonitor->VerifyFound();
2859 region.bufferRowLength = 128;
2860
2861 // Introduce failure by setting bufferOffset to a bad granularity value
2862 region.bufferOffset = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002863 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2864 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
2865 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002866 m_errorMonitor->VerifyFound();
2867 region.bufferOffset = 0;
2868
2869 // Introduce failure by setting bufferImageHeight to a bad granularity value
2870 region.bufferImageHeight = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002871 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2872 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
2873 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002874 m_errorMonitor->VerifyFound();
2875 region.bufferImageHeight = 128;
2876
2877 // Introduce failure by setting imageExtent to a bad granularity value
2878 region.imageExtent.width = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002879 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2880 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
2881 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002882 m_errorMonitor->VerifyFound();
2883 region.imageExtent.width = 16;
2884
2885 // Introduce failure by setting imageOffset to a bad granularity value
2886 region.imageOffset.z = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002887 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2888 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
2889 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002890 m_errorMonitor->VerifyFound();
2891
2892 EndCommandBuffer();
2893
2894 vkDestroyImage(m_device->device(), srcImage, NULL);
2895 vkDestroyImage(m_device->device(), dstImage, NULL);
2896 vkFreeMemory(m_device->device(), srcMem, NULL);
2897 vkFreeMemory(m_device->device(), destMem, NULL);
2898}
2899
Mark Lobodzinski570efc62016-08-09 16:43:19 -06002900TEST_F(VkLayerTest, MismatchedQueueFamiliesOnSubmit) {
Mark Lobodzinski570efc62016-08-09 16:43:19 -06002901 TEST_DESCRIPTION("Submit command buffer created using one queue family and "
2902 "attempt to submit them on a queue created in a different "
2903 "queue family.");
2904
Cody Northropc31a84f2016-08-22 10:41:47 -06002905 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski570efc62016-08-09 16:43:19 -06002906 // This test is meaningless unless we have multiple queue families
2907 auto queue_family_properties = m_device->phy().queue_properties();
2908 if (queue_family_properties.size() < 2) {
2909 return;
2910 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002911 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is being submitted on queue ");
Mark Lobodzinski570efc62016-08-09 16:43:19 -06002912 // Get safe index of another queue family
2913 uint32_t other_queue_family = (m_device->graphics_queue_node_index_ == 0) ? 1 : 0;
2914 ASSERT_NO_FATAL_FAILURE(InitState());
2915 // Create a second queue using a different queue family
2916 VkQueue other_queue;
2917 vkGetDeviceQueue(m_device->device(), other_queue_family, 0, &other_queue);
2918
2919 // Record an empty cmd buffer
2920 VkCommandBufferBeginInfo cmdBufBeginDesc = {};
2921 cmdBufBeginDesc.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
2922 vkBeginCommandBuffer(m_commandBuffer->handle(), &cmdBufBeginDesc);
2923 vkEndCommandBuffer(m_commandBuffer->handle());
2924
2925 // And submit on the wrong queue
2926 VkSubmitInfo submit_info = {};
2927 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
2928 submit_info.commandBufferCount = 1;
2929 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Tobin Ehlisfd213ea2016-08-10 17:10:46 -06002930 vkQueueSubmit(other_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Lobodzinski570efc62016-08-09 16:43:19 -06002931
2932 m_errorMonitor->VerifyFound();
Mark Lobodzinski570efc62016-08-09 16:43:19 -06002933}
2934
Chris Forbes4c24a922016-11-16 08:59:10 +13002935TEST_F(VkLayerTest, RenderPassAttachmentIndexOutOfRange) {
2936 ASSERT_NO_FATAL_FAILURE(InitState());
2937
Chris Forbes2d9b2a82016-11-21 10:45:39 +13002938 // There are no attachments, but refer to attachment 0.
2939 VkAttachmentReference ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Chris Forbes4c24a922016-11-16 08:59:10 +13002940 VkSubpassDescription subpasses[] = {
Chris Forbes2d9b2a82016-11-21 10:45:39 +13002941 {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &ref, nullptr,
2942 nullptr, 0, nullptr},
Chris Forbes4c24a922016-11-16 08:59:10 +13002943 };
2944
Chris Forbes2d9b2a82016-11-21 10:45:39 +13002945 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO,
2946 nullptr,
2947 0,
2948 0,
2949 nullptr,
2950 1,
2951 subpasses,
2952 0,
2953 nullptr};
Chris Forbes4c24a922016-11-16 08:59:10 +13002954 VkRenderPass rp;
2955
Chris Forbes2d9b2a82016-11-21 10:45:39 +13002956 // "... must be less than the total number of attachments ..."
Chris Forbes4c24a922016-11-16 08:59:10 +13002957 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbes2d9b2a82016-11-21 10:45:39 +13002958 VALIDATION_ERROR_00325);
Chris Forbes4c24a922016-11-16 08:59:10 +13002959 vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
2960 m_errorMonitor->VerifyFound();
2961}
2962
Chris Forbesa58c4522016-09-28 15:19:39 +13002963TEST_F(VkLayerTest, RenderPassPipelineSubpassMismatch) {
2964 TEST_DESCRIPTION("Use a pipeline for the wrong subpass in a render pass instance");
2965 ASSERT_NO_FATAL_FAILURE(InitState());
2966
2967 // A renderpass with two subpasses, both writing the same attachment.
2968 VkAttachmentDescription attach[] = {
2969 { 0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT,
2970 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
2971 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
2972 VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL
2973 },
2974 };
2975 VkAttachmentReference ref = { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
2976 VkSubpassDescription subpasses[] = {
2977 { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr,
2978 1, &ref, nullptr, nullptr, 0, nullptr },
2979 { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr,
2980 1, &ref, nullptr, nullptr, 0, nullptr },
2981 };
2982 VkSubpassDependency dep = {
2983 0, 1,
2984 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
2985 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
2986 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
2987 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
2988 VK_DEPENDENCY_BY_REGION_BIT
2989 };
2990 VkRenderPassCreateInfo rpci = {
2991 VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr,
2992 0, 1, attach, 2, subpasses, 1, &dep
2993 };
2994 VkRenderPass rp;
2995 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
2996 ASSERT_VK_SUCCESS(err);
2997
2998 VkImageObj image(m_device);
2999 image.init_no_layout(32, 32, VK_FORMAT_R8G8B8A8_UNORM,
3000 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT,
3001 VK_IMAGE_TILING_OPTIMAL, 0);
3002 VkImageView imageView = image.targetView(VK_FORMAT_R8G8B8A8_UNORM);
3003
3004 VkFramebufferCreateInfo fbci = {
3005 VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr,
3006 0, rp, 1, &imageView, 32, 32, 1
3007 };
3008 VkFramebuffer fb;
3009 err = vkCreateFramebuffer(m_device->device(), &fbci, nullptr, &fb);
3010 ASSERT_VK_SUCCESS(err);
3011
3012 char const *vsSource =
3013 "#version 450\n"
3014 "void main() { gl_Position = vec4(1); }\n";
3015 char const *fsSource =
3016 "#version 450\n"
3017 "layout(location=0) out vec4 color;\n"
3018 "void main() { color = vec4(1); }\n";
3019
3020 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
3021 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
3022 VkPipelineObj pipe(m_device);
3023 pipe.AddColorAttachment();
3024 pipe.AddShader(&vs);
3025 pipe.AddShader(&fs);
3026 VkViewport view_port = {};
3027 m_viewports.push_back(view_port);
3028 pipe.SetViewport(m_viewports);
3029 VkRect2D rect = {};
3030 m_scissors.push_back(rect);
3031 pipe.SetScissor(m_scissors);
3032
3033 VkPipelineLayoutCreateInfo plci = {
3034 VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr,
3035 0, 0, nullptr, 0, nullptr
3036 };
3037 VkPipelineLayout pl;
3038 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
3039 ASSERT_VK_SUCCESS(err);
3040 pipe.CreateVKPipeline(pl, rp);
3041
3042 BeginCommandBuffer();
3043
3044 VkRenderPassBeginInfo rpbi = {
3045 VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr,
3046 rp, fb, { { 0, 0, }, { 32, 32 } }, 0, nullptr
3047 };
3048
3049 // subtest 1: bind in the wrong subpass
3050 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
3051 vkCmdNextSubpass(m_commandBuffer->handle(), VK_SUBPASS_CONTENTS_INLINE);
3052 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3053 "built for subpass 0 but used in subpass 1");
3054 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
3055 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
3056 m_errorMonitor->VerifyFound();
3057
3058 vkCmdEndRenderPass(m_commandBuffer->handle());
3059
3060 // subtest 2: bind in correct subpass, then transition to next subpass
3061 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
3062 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
3063 vkCmdNextSubpass(m_commandBuffer->handle(), VK_SUBPASS_CONTENTS_INLINE);
3064 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3065 "built for subpass 0 but used in subpass 1");
3066 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
3067 m_errorMonitor->VerifyFound();
3068
3069 vkCmdEndRenderPass(m_commandBuffer->handle());
3070
3071 EndCommandBuffer();
3072
3073 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
3074 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
3075 vkDestroyRenderPass(m_device->device(), rp, nullptr);
3076}
3077
Tony Barbour4e919972016-08-09 13:27:40 -06003078TEST_F(VkLayerTest, RenderPassInvalidRenderArea) {
3079 TEST_DESCRIPTION("Generate INVALID_RENDER_AREA error by beginning renderpass"
3080 "with extent outside of framebuffer");
3081 ASSERT_NO_FATAL_FAILURE(InitState());
3082 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3083
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003084 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot execute a render pass with renderArea "
3085 "not within the bound of the framebuffer.");
Tony Barbour4e919972016-08-09 13:27:40 -06003086
3087 // Framebuffer for render target is 256x256, exceed that for INVALID_RENDER_AREA
3088 m_renderPassBeginInfo.renderArea.extent.width = 257;
3089 m_renderPassBeginInfo.renderArea.extent.height = 257;
3090 BeginCommandBuffer();
3091 m_errorMonitor->VerifyFound();
3092}
3093
3094TEST_F(VkLayerTest, DisabledIndependentBlend) {
3095 TEST_DESCRIPTION("Generate INDEPENDENT_BLEND by disabling independent "
3096 "blend and then specifying different blend states for two "
3097 "attachements");
Cody Northrop5703cc72016-08-19 09:57:10 -06003098 VkPhysicalDeviceFeatures features = {};
3099 features.independentBlend = VK_FALSE;
Cody Northropc31a84f2016-08-22 10:41:47 -06003100 ASSERT_NO_FATAL_FAILURE(InitState(&features));
Tony Barbour4e919972016-08-09 13:27:40 -06003101
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003102 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3103 "Invalid Pipeline CreateInfo: If independent blend feature not "
3104 "enabled, all elements of pAttachments must be identical");
Tony Barbour4e919972016-08-09 13:27:40 -06003105
Cody Northropc31a84f2016-08-22 10:41:47 -06003106 VkDescriptorSetObj descriptorSet(m_device);
3107 descriptorSet.AppendDummy();
3108 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Tony Barbour4e919972016-08-09 13:27:40 -06003109
Cody Northropc31a84f2016-08-22 10:41:47 -06003110 VkPipelineObj pipeline(m_device);
3111 VkRenderpassObj renderpass(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003112 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Cody Northropc31a84f2016-08-22 10:41:47 -06003113 pipeline.AddShader(&vs);
Cody Northrop5703cc72016-08-19 09:57:10 -06003114
Cody Northropc31a84f2016-08-22 10:41:47 -06003115 VkPipelineColorBlendAttachmentState att_state1 = {}, att_state2 = {};
3116 att_state1.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
3117 att_state1.blendEnable = VK_TRUE;
3118 att_state2.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
3119 att_state2.blendEnable = VK_FALSE;
3120 pipeline.AddColorAttachment(0, &att_state1);
3121 pipeline.AddColorAttachment(1, &att_state2);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003122 pipeline.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderpass.handle());
Cody Northropc31a84f2016-08-22 10:41:47 -06003123 m_errorMonitor->VerifyFound();
Tony Barbour4e919972016-08-09 13:27:40 -06003124}
3125
Chris Forbes26ec2122016-11-29 08:58:33 +13003126#if 0
Tony Barbour4e919972016-08-09 13:27:40 -06003127TEST_F(VkLayerTest, RenderPassDepthStencilAttachmentUnused) {
3128 TEST_DESCRIPTION("Specify no depth attachement in renderpass then specify "
3129 "depth attachments in subpass");
Cody Northropc31a84f2016-08-22 10:41:47 -06003130 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbour4e919972016-08-09 13:27:40 -06003131
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003132 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3133 "vkCreateRenderPass has no depth/stencil attachment, yet subpass");
Tony Barbour4e919972016-08-09 13:27:40 -06003134
3135 // Create a renderPass with a single color attachment
3136 VkAttachmentReference attach = {};
3137 attach.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
3138 VkSubpassDescription subpass = {};
3139 VkRenderPassCreateInfo rpci = {};
3140 rpci.subpassCount = 1;
3141 rpci.pSubpasses = &subpass;
3142 rpci.attachmentCount = 1;
3143 VkAttachmentDescription attach_desc = {};
3144 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
3145 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
3146 rpci.pAttachments = &attach_desc;
3147 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3148 VkRenderPass rp;
3149 subpass.pDepthStencilAttachment = &attach;
3150 subpass.pColorAttachments = NULL;
3151 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3152 m_errorMonitor->VerifyFound();
3153}
Chris Forbes26ec2122016-11-29 08:58:33 +13003154#endif
Tony Barbour4e919972016-08-09 13:27:40 -06003155
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003156TEST_F(VkLayerTest, UnusedPreserveAttachment) {
3157 TEST_DESCRIPTION("Create a framebuffer where a subpass has a preserve "
3158 "attachment reference of VK_ATTACHMENT_UNUSED");
3159
3160 ASSERT_NO_FATAL_FAILURE(InitState());
3161 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3162
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003163 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "must not be VK_ATTACHMENT_UNUSED");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003164
3165 VkAttachmentReference color_attach = {};
3166 color_attach.layout = VK_IMAGE_LAYOUT_GENERAL;
3167 color_attach.attachment = 0;
3168 uint32_t preserve_attachment = VK_ATTACHMENT_UNUSED;
3169 VkSubpassDescription subpass = {};
3170 subpass.colorAttachmentCount = 1;
3171 subpass.pColorAttachments = &color_attach;
3172 subpass.preserveAttachmentCount = 1;
3173 subpass.pPreserveAttachments = &preserve_attachment;
3174
3175 VkRenderPassCreateInfo rpci = {};
3176 rpci.subpassCount = 1;
3177 rpci.pSubpasses = &subpass;
3178 rpci.attachmentCount = 1;
3179 VkAttachmentDescription attach_desc = {};
3180 attach_desc.format = VK_FORMAT_UNDEFINED;
3181 rpci.pAttachments = &attach_desc;
3182 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3183 VkRenderPass rp;
Mark Lobodzinskia4feeeb2016-06-17 12:00:46 -06003184 VkResult result = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003185
3186 m_errorMonitor->VerifyFound();
3187
Mark Lobodzinskia4feeeb2016-06-17 12:00:46 -06003188 if (result == VK_SUCCESS) {
3189 vkDestroyRenderPass(m_device->device(), rp, NULL);
3190 }
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003191}
3192
Chris Forbesc5389742016-06-29 11:49:23 +12003193TEST_F(VkLayerTest, CreateRenderPassResolveRequiresColorMsaa) {
Chris Forbes6655bb32016-07-01 18:27:30 +12003194 TEST_DESCRIPTION("Ensure that CreateRenderPass produces a validation error "
3195 "when the source of a subpass multisample resolve "
3196 "does not have multiple samples.");
3197
Chris Forbesc5389742016-06-29 11:49:23 +12003198 ASSERT_NO_FATAL_FAILURE(InitState());
3199
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003200 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3201 "Subpass 0 requests multisample resolve from attachment 0 which has "
3202 "VK_SAMPLE_COUNT_1_BIT");
Chris Forbesc5389742016-06-29 11:49:23 +12003203
3204 VkAttachmentDescription attachments[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003205 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3206 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3207 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3208 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3209 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3210 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbesc5389742016-06-29 11:49:23 +12003211 };
3212
3213 VkAttachmentReference color = {
3214 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3215 };
3216
3217 VkAttachmentReference resolve = {
3218 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3219 };
3220
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003221 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &color, &resolve, nullptr, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003222
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003223 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003224
3225 VkRenderPass rp;
3226 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3227
3228 m_errorMonitor->VerifyFound();
3229
3230 if (err == VK_SUCCESS)
3231 vkDestroyRenderPass(m_device->device(), rp, nullptr);
3232}
3233
3234TEST_F(VkLayerTest, CreateRenderPassResolveRequiresSingleSampleDest) {
Chris Forbes6655bb32016-07-01 18:27:30 +12003235 TEST_DESCRIPTION("Ensure CreateRenderPass produces a validation error "
3236 "when a subpass multisample resolve operation is "
3237 "requested, and the destination of that resolve has "
3238 "multiple samples.");
3239
Chris Forbesc5389742016-06-29 11:49:23 +12003240 ASSERT_NO_FATAL_FAILURE(InitState());
3241
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003242 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3243 "Subpass 0 requests multisample resolve into attachment 1, which "
3244 "must have VK_SAMPLE_COUNT_1_BIT but has VK_SAMPLE_COUNT_4_BIT");
Chris Forbesc5389742016-06-29 11:49:23 +12003245
3246 VkAttachmentDescription attachments[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003247 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3248 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3249 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3250 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3251 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3252 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbesc5389742016-06-29 11:49:23 +12003253 };
3254
3255 VkAttachmentReference color = {
3256 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3257 };
3258
3259 VkAttachmentReference resolve = {
3260 1, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3261 };
3262
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003263 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &color, &resolve, nullptr, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003264
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003265 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003266
3267 VkRenderPass rp;
3268 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3269
3270 m_errorMonitor->VerifyFound();
3271
3272 if (err == VK_SUCCESS)
3273 vkDestroyRenderPass(m_device->device(), rp, nullptr);
3274}
3275
Chris Forbes3f128ef2016-06-29 14:58:53 +12003276TEST_F(VkLayerTest, CreateRenderPassSubpassSampleCountConsistency) {
Chris Forbes6655bb32016-07-01 18:27:30 +12003277 TEST_DESCRIPTION("Ensure CreateRenderPass produces a validation error "
3278 "when the color and depth attachments used by a subpass "
3279 "have inconsistent sample counts");
3280
Chris Forbes3f128ef2016-06-29 14:58:53 +12003281 ASSERT_NO_FATAL_FAILURE(InitState());
3282
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003283 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3284 "Subpass 0 attempts to render to attachments with inconsistent sample counts");
Chris Forbes3f128ef2016-06-29 14:58:53 +12003285
3286 VkAttachmentDescription attachments[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003287 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3288 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3289 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3290 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3291 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3292 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbes3f128ef2016-06-29 14:58:53 +12003293 };
3294
3295 VkAttachmentReference color[] = {
3296 {
3297 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3298 },
3299 {
3300 1, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3301 },
3302 };
3303
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003304 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 2, color, nullptr, nullptr, 0, nullptr};
Chris Forbes3f128ef2016-06-29 14:58:53 +12003305
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003306 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbes3f128ef2016-06-29 14:58:53 +12003307
3308 VkRenderPass rp;
3309 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3310
3311 m_errorMonitor->VerifyFound();
3312
3313 if (err == VK_SUCCESS)
3314 vkDestroyRenderPass(m_device->device(), rp, nullptr);
3315}
3316
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003317TEST_F(VkLayerTest, FramebufferCreateErrors) {
3318 TEST_DESCRIPTION("Hit errors when attempting to create a framebuffer :\n"
Mike Weiblencce7ec72016-10-17 19:33:05 -06003319 " 1. Mismatch between framebuffer & renderPass attachmentCount\n"
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003320 " 2. Use a color image as depthStencil attachment\n"
Mike Weiblencce7ec72016-10-17 19:33:05 -06003321 " 3. Mismatch framebuffer & renderPass attachment formats\n"
3322 " 4. Mismatch framebuffer & renderPass attachment #samples\n"
3323 " 5. Framebuffer attachment w/ non-1 mip-levels\n"
3324 " 6. Framebuffer attachment where dimensions don't match\n"
3325 " 7. Framebuffer attachment w/o identity swizzle\n"
3326 " 8. framebuffer dimensions exceed physical device limits\n");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003327
3328 ASSERT_NO_FATAL_FAILURE(InitState());
3329 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3330
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003331 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3332 "vkCreateFramebuffer(): VkFramebufferCreateInfo attachmentCount of 2 "
3333 "does not match attachmentCount of 1 of ");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003334
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003335 // Create a renderPass with a single color attachment
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003336 VkAttachmentReference attach = {};
3337 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
3338 VkSubpassDescription subpass = {};
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003339 subpass.pColorAttachments = &attach;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003340 VkRenderPassCreateInfo rpci = {};
3341 rpci.subpassCount = 1;
3342 rpci.pSubpasses = &subpass;
3343 rpci.attachmentCount = 1;
3344 VkAttachmentDescription attach_desc = {};
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003345 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis77d717c2016-06-22 14:19:19 -06003346 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003347 rpci.pAttachments = &attach_desc;
3348 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3349 VkRenderPass rp;
3350 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3351 ASSERT_VK_SUCCESS(err);
3352
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003353 VkImageView ivs[2];
3354 ivs[0] = m_renderTargets[0]->targetView(VK_FORMAT_B8G8R8A8_UNORM);
3355 ivs[1] = m_renderTargets[0]->targetView(VK_FORMAT_B8G8R8A8_UNORM);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003356 VkFramebufferCreateInfo fb_info = {};
3357 fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
3358 fb_info.pNext = NULL;
3359 fb_info.renderPass = rp;
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003360 // Set mis-matching attachmentCount
3361 fb_info.attachmentCount = 2;
3362 fb_info.pAttachments = ivs;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003363 fb_info.width = 100;
3364 fb_info.height = 100;
3365 fb_info.layers = 1;
3366
3367 VkFramebuffer fb;
3368 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3369
3370 m_errorMonitor->VerifyFound();
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003371 if (err == VK_SUCCESS) {
3372 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3373 }
3374 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003375
3376 // Create a renderPass with a depth-stencil attachment created with
3377 // IMAGE_USAGE_COLOR_ATTACHMENT
3378 // Add our color attachment to pDepthStencilAttachment
3379 subpass.pDepthStencilAttachment = &attach;
3380 subpass.pColorAttachments = NULL;
3381 VkRenderPass rp_ds;
3382 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp_ds);
3383 ASSERT_VK_SUCCESS(err);
3384 // Set correct attachment count, but attachment has COLOR usage bit set
3385 fb_info.attachmentCount = 1;
3386 fb_info.renderPass = rp_ds;
3387
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003388 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " conflicts with the image's IMAGE_USAGE flags ");
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003389 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3390
3391 m_errorMonitor->VerifyFound();
3392 if (err == VK_SUCCESS) {
3393 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3394 }
3395 vkDestroyRenderPass(m_device->device(), rp_ds, NULL);
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003396
3397 // Create new renderpass with alternate attachment format from fb
3398 attach_desc.format = VK_FORMAT_R8G8B8A8_UNORM;
3399 subpass.pDepthStencilAttachment = NULL;
3400 subpass.pColorAttachments = &attach;
3401 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3402 ASSERT_VK_SUCCESS(err);
3403
3404 // Cause error due to mis-matched formats between rp & fb
3405 // rp attachment 0 now has RGBA8 but corresponding fb attach is BGRA8
3406 fb_info.renderPass = rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003407 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3408 " has format of VK_FORMAT_B8G8R8A8_UNORM that does not match ");
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003409 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3410
3411 m_errorMonitor->VerifyFound();
3412 if (err == VK_SUCCESS) {
3413 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3414 }
Tobin Ehlis77d717c2016-06-22 14:19:19 -06003415 vkDestroyRenderPass(m_device->device(), rp, NULL);
3416
3417 // Create new renderpass with alternate sample count from fb
3418 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
3419 attach_desc.samples = VK_SAMPLE_COUNT_4_BIT;
3420 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3421 ASSERT_VK_SUCCESS(err);
3422
3423 // Cause error due to mis-matched sample count between rp & fb
3424 fb_info.renderPass = rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003425 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has VK_SAMPLE_COUNT_1_BIT samples "
3426 "that do not match the "
3427 "VK_SAMPLE_COUNT_4_BIT ");
Tobin Ehlis77d717c2016-06-22 14:19:19 -06003428 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3429
3430 m_errorMonitor->VerifyFound();
3431 if (err == VK_SUCCESS) {
3432 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3433 }
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003434
3435 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003436
3437 // Create a custom imageView with non-1 mip levels
3438 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003439 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 -06003440 ASSERT_TRUE(image.initialized());
3441
3442 VkImageView view;
3443 VkImageViewCreateInfo ivci = {};
3444 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
3445 ivci.image = image.handle();
3446 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
3447 ivci.format = VK_FORMAT_B8G8R8A8_UNORM;
3448 ivci.subresourceRange.layerCount = 1;
3449 ivci.subresourceRange.baseMipLevel = 0;
3450 // Set level count 2 (only 1 is allowed for FB attachment)
3451 ivci.subresourceRange.levelCount = 2;
3452 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3453 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
3454 ASSERT_VK_SUCCESS(err);
3455 // Re-create renderpass to have matching sample count
3456 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
3457 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3458 ASSERT_VK_SUCCESS(err);
3459
3460 fb_info.renderPass = rp;
3461 fb_info.pAttachments = &view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003462 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has mip levelCount of 2 but only ");
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003463 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3464
3465 m_errorMonitor->VerifyFound();
3466 if (err == VK_SUCCESS) {
3467 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3468 }
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003469 vkDestroyImageView(m_device->device(), view, NULL);
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06003470 // Update view to original color buffer and grow FB dimensions too big
3471 fb_info.pAttachments = ivs;
3472 fb_info.height = 1024;
3473 fb_info.width = 1024;
3474 fb_info.layers = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003475 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " Attachment dimensions must be at "
3476 "least as large. ");
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06003477 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3478
3479 m_errorMonitor->VerifyFound();
3480 if (err == VK_SUCCESS) {
3481 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3482 }
Tobin Ehlisb1f303b2016-06-23 08:19:55 -06003483 // Create view attachment with non-identity swizzle
3484 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
3485 ivci.image = image.handle();
3486 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
3487 ivci.format = VK_FORMAT_B8G8R8A8_UNORM;
3488 ivci.subresourceRange.layerCount = 1;
3489 ivci.subresourceRange.baseMipLevel = 0;
3490 ivci.subresourceRange.levelCount = 1;
3491 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3492 ivci.components.r = VK_COMPONENT_SWIZZLE_G;
3493 ivci.components.g = VK_COMPONENT_SWIZZLE_R;
3494 ivci.components.b = VK_COMPONENT_SWIZZLE_A;
3495 ivci.components.a = VK_COMPONENT_SWIZZLE_B;
3496 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
3497 ASSERT_VK_SUCCESS(err);
3498
3499 fb_info.pAttachments = &view;
3500 fb_info.height = 100;
3501 fb_info.width = 100;
3502 fb_info.layers = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003503 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has non-identy swizzle. All "
3504 "framebuffer attachments must have "
3505 "been created with the identity "
3506 "swizzle. ");
Tobin Ehlisb1f303b2016-06-23 08:19:55 -06003507 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3508
3509 m_errorMonitor->VerifyFound();
3510 if (err == VK_SUCCESS) {
3511 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3512 }
3513 vkDestroyImageView(m_device->device(), view, NULL);
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06003514 // Request fb that exceeds max dimensions
3515 // reset attachment to color attachment
3516 fb_info.pAttachments = ivs;
3517 fb_info.width = m_device->props.limits.maxFramebufferWidth + 1;
3518 fb_info.height = m_device->props.limits.maxFramebufferHeight + 1;
3519 fb_info.layers = m_device->props.limits.maxFramebufferLayers + 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003520 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " Requested VkFramebufferCreateInfo "
3521 "dimensions exceed physical device "
3522 "limits. ");
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06003523 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3524
3525 m_errorMonitor->VerifyFound();
3526 if (err == VK_SUCCESS) {
3527 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3528 }
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06003529
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003530 vkDestroyRenderPass(m_device->device(), rp, NULL);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003531}
3532
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003533TEST_F(VkLayerTest, DynamicDepthBiasNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003534 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Depth Bias dynamic "
3535 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003536
Cody Northropc31a84f2016-08-22 10:41:47 -06003537 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003538 // Dynamic depth bias
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003539 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic depth bias state not set for this command buffer");
3540 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthBias);
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003541 m_errorMonitor->VerifyFound();
3542}
3543
3544TEST_F(VkLayerTest, DynamicLineWidthNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003545 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Line Width dynamic "
3546 "state is required but not correctly bound.");
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003547
Cody Northropc31a84f2016-08-22 10:41:47 -06003548 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003549 // Dynamic line width
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003550 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic line width state not set for this command buffer");
3551 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailLineWidth);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003552 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003553}
3554
3555TEST_F(VkLayerTest, DynamicViewportNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003556 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Viewport dynamic "
3557 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003558
Cody Northropc31a84f2016-08-22 10:41:47 -06003559 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003560 // Dynamic viewport state
Mike Weiblen95dd0f92016-10-19 12:28:27 -06003561 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 -06003562 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailViewport);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003563 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003564}
3565
3566TEST_F(VkLayerTest, DynamicScissorNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003567 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Scissor dynamic "
3568 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003569
Cody Northropc31a84f2016-08-22 10:41:47 -06003570 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003571 // Dynamic scissor state
Mike Weiblen95dd0f92016-10-19 12:28:27 -06003572 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 -06003573 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailScissor);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003574 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003575}
3576
Cortd713fe82016-07-27 09:51:27 -07003577TEST_F(VkLayerTest, DynamicBlendConstantsNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003578 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Blend Constants "
3579 "dynamic state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003580
3581 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis21c88352016-05-26 06:15:45 -06003582 // Dynamic blend constant state
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003583 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3584 "Dynamic blend constants state not set for this command buffer");
3585 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailBlend);
Tobin Ehlis21c88352016-05-26 06:15:45 -06003586 m_errorMonitor->VerifyFound();
3587}
3588
3589TEST_F(VkLayerTest, DynamicDepthBoundsNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003590 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Depth Bounds dynamic "
3591 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003592
3593 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis21c88352016-05-26 06:15:45 -06003594 if (!m_device->phy().features().depthBounds) {
3595 printf("Device does not support depthBounds test; skipped.\n");
3596 return;
3597 }
3598 // Dynamic depth bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003599 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3600 "Dynamic depth bounds state not set for this command buffer");
3601 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthBounds);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003602 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003603}
3604
3605TEST_F(VkLayerTest, DynamicStencilReadNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003606 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Stencil Read dynamic "
3607 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003608
3609 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003610 // Dynamic stencil read mask
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003611 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3612 "Dynamic stencil read mask state not set for this command buffer");
3613 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilReadMask);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003614 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003615}
3616
3617TEST_F(VkLayerTest, DynamicStencilWriteNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003618 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Stencil Write dynamic"
3619 " state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003620
3621 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003622 // Dynamic stencil write mask
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003623 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3624 "Dynamic stencil write mask state not set for this command buffer");
3625 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilWriteMask);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003626 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003627}
3628
3629TEST_F(VkLayerTest, DynamicStencilRefNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003630 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Stencil Ref dynamic "
3631 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003632
3633 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003634 // Dynamic stencil reference
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003635 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3636 "Dynamic stencil reference state not set for this command buffer");
3637 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilReference);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003638 m_errorMonitor->VerifyFound();
Tobin Ehlis963a4042015-09-29 08:18:34 -06003639}
3640
Tobin Ehlis379ba3b2016-07-19 11:22:29 -06003641TEST_F(VkLayerTest, IndexBufferNotBound) {
3642 TEST_DESCRIPTION("Run an indexed draw call without an index buffer bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003643
3644 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003645 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3646 "Index buffer object not bound to this command buffer when Indexed ");
3647 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailIndexBuffer);
Tobin Ehlis379ba3b2016-07-19 11:22:29 -06003648 m_errorMonitor->VerifyFound();
3649}
3650
Karl Schultz6addd812016-02-02 17:17:23 -07003651TEST_F(VkLayerTest, CommandBufferTwoSubmits) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003652 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3653 "was begun w/ VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set, but has "
3654 "been submitted");
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003655
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003656 ASSERT_NO_FATAL_FAILURE(InitState());
3657 ASSERT_NO_FATAL_FAILURE(InitViewport());
3658 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3659
Karl Schultz6addd812016-02-02 17:17:23 -07003660 // We luck out b/c by default the framework creates CB w/ the
3661 // VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003662 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003663 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003664 EndCommandBuffer();
3665
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003666 // Bypass framework since it does the waits automatically
3667 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06003668 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08003669 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3670 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003671 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06003672 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07003673 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003674 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003675 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08003676 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06003677 submit_info.pSignalSemaphores = NULL;
3678
Chris Forbes40028e22016-06-13 09:59:34 +12003679 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Karl Schultz6addd812016-02-02 17:17:23 -07003680 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski89cad1a2016-11-11 15:51:31 -07003681 vkQueueWaitIdle(m_device->m_queue);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003682
Karl Schultz6addd812016-02-02 17:17:23 -07003683 // Cause validation error by re-submitting cmd buffer that should only be
3684 // submitted once
Chris Forbes40028e22016-06-13 09:59:34 +12003685 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Lobodzinski89cad1a2016-11-11 15:51:31 -07003686 vkQueueWaitIdle(m_device->m_queue);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003687
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003688 m_errorMonitor->VerifyFound();
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003689}
3690
Karl Schultz6addd812016-02-02 17:17:23 -07003691TEST_F(VkLayerTest, AllocDescriptorFromEmptyPool) {
Tobin Ehlis14cd5852016-11-23 12:52:48 -07003692 TEST_DESCRIPTION("Attempt to allocate more sets and descriptors than descriptor pool has available.");
Karl Schultz6addd812016-02-02 17:17:23 -07003693 VkResult err;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003694
3695 ASSERT_NO_FATAL_FAILURE(InitState());
3696 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003697
Karl Schultz6addd812016-02-02 17:17:23 -07003698 // Create Pool w/ 1 Sampler descriptor, but try to alloc Uniform Buffer
3699 // descriptor from it
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003700 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003701 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
Tobin Ehlis14cd5852016-11-23 12:52:48 -07003702 ds_type_count.descriptorCount = 2;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003703
3704 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003705 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3706 ds_pool_ci.pNext = NULL;
3707 ds_pool_ci.flags = 0;
3708 ds_pool_ci.maxSets = 1;
3709 ds_pool_ci.poolSizeCount = 1;
3710 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003711
3712 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003713 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003714 ASSERT_VK_SUCCESS(err);
3715
Tobin Ehlis14cd5852016-11-23 12:52:48 -07003716 VkDescriptorSetLayoutBinding dsl_binding_samp = {};
3717 dsl_binding_samp.binding = 0;
3718 dsl_binding_samp.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
3719 dsl_binding_samp.descriptorCount = 1;
3720 dsl_binding_samp.stageFlags = VK_SHADER_STAGE_ALL;
3721 dsl_binding_samp.pImmutableSamplers = NULL;
3722
3723 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3724 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3725 ds_layout_ci.pNext = NULL;
3726 ds_layout_ci.bindingCount = 1;
3727 ds_layout_ci.pBindings = &dsl_binding_samp;
3728
3729 VkDescriptorSetLayout ds_layout_samp;
3730 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout_samp);
3731 ASSERT_VK_SUCCESS(err);
3732
3733 // Try to allocate 2 sets when pool only has 1 set
3734 VkDescriptorSet descriptor_sets[2];
3735 VkDescriptorSetLayout set_layouts[2] = {ds_layout_samp, ds_layout_samp};
3736 VkDescriptorSetAllocateInfo alloc_info = {};
3737 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
3738 alloc_info.descriptorSetCount = 2;
3739 alloc_info.descriptorPool = ds_pool;
3740 alloc_info.pSetLayouts = set_layouts;
3741 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00911);
3742 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptor_sets);
3743 m_errorMonitor->VerifyFound();
3744
3745 alloc_info.descriptorSetCount = 1;
3746 // Create layout w/ descriptor type not available in pool
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003747 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003748 dsl_binding.binding = 0;
3749 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3750 dsl_binding.descriptorCount = 1;
3751 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3752 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003753
Karl Schultz6addd812016-02-02 17:17:23 -07003754 ds_layout_ci.bindingCount = 1;
3755 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003756
Tobin Ehlis14cd5852016-11-23 12:52:48 -07003757 VkDescriptorSetLayout ds_layout_ub;
3758 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout_ub);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003759 ASSERT_VK_SUCCESS(err);
3760
Tobin Ehlis14cd5852016-11-23 12:52:48 -07003761 VkDescriptorSet descriptor_set;
Jon Ashburnf19916e2016-01-11 13:12:43 -07003762 alloc_info.descriptorSetCount = 1;
Tobin Ehlis14cd5852016-11-23 12:52:48 -07003763 alloc_info.pSetLayouts = &ds_layout_ub;
3764 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00912);
3765 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003766
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003767 m_errorMonitor->VerifyFound();
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003768
Karl Schultz2825ab92016-12-02 08:23:14 -07003769 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_samp, NULL);
Tobin Ehlis14cd5852016-11-23 12:52:48 -07003770 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_ub, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +08003771 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003772}
3773
Karl Schultz6addd812016-02-02 17:17:23 -07003774TEST_F(VkLayerTest, FreeDescriptorFromOneShotPool) {
3775 VkResult err;
Tobin Ehlise735c692015-10-08 13:13:50 -06003776
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003777 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3778 "It is invalid to call vkFreeDescriptorSets() with a pool created "
3779 "without setting VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003780
Tobin Ehlise735c692015-10-08 13:13:50 -06003781 ASSERT_NO_FATAL_FAILURE(InitState());
3782 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise735c692015-10-08 13:13:50 -06003783
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003784 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003785 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3786 ds_type_count.descriptorCount = 1;
Tobin Ehlise735c692015-10-08 13:13:50 -06003787
3788 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003789 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3790 ds_pool_ci.pNext = NULL;
3791 ds_pool_ci.maxSets = 1;
3792 ds_pool_ci.poolSizeCount = 1;
3793 ds_pool_ci.flags = 0;
3794 // Not specifying VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT means
3795 // app can only call vkResetDescriptorPool on this pool.;
3796 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise735c692015-10-08 13:13:50 -06003797
3798 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003799 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise735c692015-10-08 13:13:50 -06003800 ASSERT_VK_SUCCESS(err);
3801
3802 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003803 dsl_binding.binding = 0;
3804 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3805 dsl_binding.descriptorCount = 1;
3806 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3807 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlise735c692015-10-08 13:13:50 -06003808
3809 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003810 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3811 ds_layout_ci.pNext = NULL;
3812 ds_layout_ci.bindingCount = 1;
3813 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise735c692015-10-08 13:13:50 -06003814
3815 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003816 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise735c692015-10-08 13:13:50 -06003817 ASSERT_VK_SUCCESS(err);
3818
3819 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003820 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08003821 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07003822 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06003823 alloc_info.descriptorPool = ds_pool;
3824 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003825 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise735c692015-10-08 13:13:50 -06003826 ASSERT_VK_SUCCESS(err);
3827
3828 err = vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003829 m_errorMonitor->VerifyFound();
Tobin Ehlise735c692015-10-08 13:13:50 -06003830
Chia-I Wuf7458c52015-10-26 21:10:41 +08003831 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3832 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise735c692015-10-08 13:13:50 -06003833}
3834
Karl Schultz6addd812016-02-02 17:17:23 -07003835TEST_F(VkLayerTest, InvalidDescriptorPool) {
Karl Schultzbdb75952016-04-19 11:36:49 -06003836 // Attempt to clear Descriptor Pool with bad object.
3837 // ObjectTracker should catch this.
Cody Northropc31a84f2016-08-22 10:41:47 -06003838
3839 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultzf78bcdd2016-11-30 12:36:01 -07003840 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00930);
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06003841 uint64_t fake_pool_handle = 0xbaad6001;
3842 VkDescriptorPool bad_pool = reinterpret_cast<VkDescriptorPool &>(fake_pool_handle);
3843 vkResetDescriptorPool(device(), bad_pool, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -06003844 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003845}
3846
Karl Schultzf78bcdd2016-11-30 12:36:01 -07003847TEST_F(VkLayerTest, InvalidDescriptorSet) {
Karl Schultzbdb75952016-04-19 11:36:49 -06003848 // Attempt to bind an invalid Descriptor Set to a valid Command Buffer
3849 // ObjectTracker should catch this.
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003850 // Create a valid cmd buffer
Karl Schultzbdb75952016-04-19 11:36:49 -06003851 // call vkCmdBindDescriptorSets w/ false Descriptor Set
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06003852
3853 uint64_t fake_set_handle = 0xbaad6001;
3854 VkDescriptorSet bad_set = reinterpret_cast<VkDescriptorSet &>(fake_set_handle);
Karl Schultzbdb75952016-04-19 11:36:49 -06003855 VkResult err;
Karl Schultzf78bcdd2016-11-30 12:36:01 -07003856 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00982);
Karl Schultzbdb75952016-04-19 11:36:49 -06003857
3858 ASSERT_NO_FATAL_FAILURE(InitState());
3859
3860 VkDescriptorSetLayoutBinding layout_bindings[1] = {};
3861 layout_bindings[0].binding = 0;
3862 layout_bindings[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3863 layout_bindings[0].descriptorCount = 1;
3864 layout_bindings[0].stageFlags = VK_SHADER_STAGE_VERTEX_BIT;
3865 layout_bindings[0].pImmutableSamplers = NULL;
3866
3867 VkDescriptorSetLayout descriptor_set_layout;
3868 VkDescriptorSetLayoutCreateInfo dslci = {};
3869 dslci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3870 dslci.pNext = NULL;
3871 dslci.bindingCount = 1;
3872 dslci.pBindings = layout_bindings;
3873 err = vkCreateDescriptorSetLayout(device(), &dslci, NULL, &descriptor_set_layout);
Karl Schultz5cb21112016-04-21 17:17:40 -06003874 ASSERT_VK_SUCCESS(err);
Karl Schultzbdb75952016-04-19 11:36:49 -06003875
3876 VkPipelineLayout pipeline_layout;
3877 VkPipelineLayoutCreateInfo plci = {};
3878 plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
3879 plci.pNext = NULL;
3880 plci.setLayoutCount = 1;
3881 plci.pSetLayouts = &descriptor_set_layout;
3882 err = vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout);
Karl Schultz5cb21112016-04-21 17:17:40 -06003883 ASSERT_VK_SUCCESS(err);
Karl Schultzbdb75952016-04-19 11:36:49 -06003884
3885 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003886 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1, &bad_set, 0,
3887 NULL);
Karl Schultzbdb75952016-04-19 11:36:49 -06003888 m_errorMonitor->VerifyFound();
3889 EndCommandBuffer();
3890 vkDestroyPipelineLayout(device(), pipeline_layout, NULL);
3891 vkDestroyDescriptorSetLayout(device(), descriptor_set_layout, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003892}
3893
Karl Schultz6addd812016-02-02 17:17:23 -07003894TEST_F(VkLayerTest, InvalidDescriptorSetLayout) {
Karl Schultzbdb75952016-04-19 11:36:49 -06003895 // Attempt to create a Pipeline Layout with an invalid Descriptor Set Layout.
3896 // ObjectTracker should catch this.
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06003897 uint64_t fake_layout_handle = 0xbaad6001;
3898 VkDescriptorSetLayout bad_layout = reinterpret_cast<VkDescriptorSetLayout &>(fake_layout_handle);
Karl Schultzf78bcdd2016-11-30 12:36:01 -07003899 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00875);
Cody Northropc31a84f2016-08-22 10:41:47 -06003900 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultzbdb75952016-04-19 11:36:49 -06003901 VkPipelineLayout pipeline_layout;
3902 VkPipelineLayoutCreateInfo plci = {};
3903 plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
3904 plci.pNext = NULL;
3905 plci.setLayoutCount = 1;
3906 plci.pSetLayouts = &bad_layout;
3907 vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout);
3908
3909 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003910}
3911
Mark Muellerd4914412016-06-13 17:52:06 -06003912TEST_F(VkLayerTest, WriteDescriptorSetIntegrityCheck) {
3913 TEST_DESCRIPTION("This test verifies some requirements of chapter 13.2.3 of the Vulkan Spec "
3914 "1) A uniform buffer update must have a valid buffer index."
3915 "2) When using an array of descriptors in a single WriteDescriptor,"
3916 " the descriptor types and stageflags must all be the same."
3917 "3) Immutable Sampler state must match across descriptors");
3918
3919 const char *invalid_BufferInfo_ErrorMessage =
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003920 "vkUpdateDescriptorSets: if pDescriptorWrites[0].descriptorType is VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, "
3921 "VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC or "
3922 "VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC, pDescriptorWrites[0].pBufferInfo must not be NULL";
3923 const char *stateFlag_ErrorMessage = "Attempting write update to descriptor set ";
3924 const char *immutable_ErrorMessage = "Attempting write update to descriptor set ";
Mark Muellerd4914412016-06-13 17:52:06 -06003925
Mark Muellerd4914412016-06-13 17:52:06 -06003926 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_BufferInfo_ErrorMessage);
3927
3928 ASSERT_NO_FATAL_FAILURE(InitState());
3929 VkDescriptorPoolSize ds_type_count[4] = {};
3930 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3931 ds_type_count[0].descriptorCount = 1;
Tony Barboure132c5f2016-12-12 11:50:20 -07003932 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLER;
Mark Muellerd4914412016-06-13 17:52:06 -06003933 ds_type_count[1].descriptorCount = 1;
Tony Barboure132c5f2016-12-12 11:50:20 -07003934 ds_type_count[2].type = VK_DESCRIPTOR_TYPE_SAMPLER;
Mark Muellerd4914412016-06-13 17:52:06 -06003935 ds_type_count[2].descriptorCount = 1;
3936 ds_type_count[3].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
3937 ds_type_count[3].descriptorCount = 1;
3938
3939 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3940 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3941 ds_pool_ci.maxSets = 1;
3942 ds_pool_ci.poolSizeCount = sizeof(ds_type_count) / sizeof(VkDescriptorPoolSize);
3943 ds_pool_ci.pPoolSizes = ds_type_count;
3944
3945 VkDescriptorPool ds_pool;
3946 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
3947 ASSERT_VK_SUCCESS(err);
3948
Mark Muellerb9896722016-06-16 09:54:29 -06003949 VkDescriptorSetLayoutBinding layout_binding[3] = {};
Mark Muellerd4914412016-06-13 17:52:06 -06003950 layout_binding[0].binding = 0;
3951 layout_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3952 layout_binding[0].descriptorCount = 1;
3953 layout_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
3954 layout_binding[0].pImmutableSamplers = NULL;
3955
3956 layout_binding[1].binding = 1;
3957 layout_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
3958 layout_binding[1].descriptorCount = 1;
3959 layout_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
3960 layout_binding[1].pImmutableSamplers = NULL;
3961
3962 VkSamplerCreateInfo sampler_ci = {};
3963 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
3964 sampler_ci.pNext = NULL;
3965 sampler_ci.magFilter = VK_FILTER_NEAREST;
3966 sampler_ci.minFilter = VK_FILTER_NEAREST;
3967 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
3968 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3969 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3970 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3971 sampler_ci.mipLodBias = 1.0;
3972 sampler_ci.anisotropyEnable = VK_FALSE;
3973 sampler_ci.maxAnisotropy = 1;
3974 sampler_ci.compareEnable = VK_FALSE;
3975 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
3976 sampler_ci.minLod = 1.0;
3977 sampler_ci.maxLod = 1.0;
3978 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
3979 sampler_ci.unnormalizedCoordinates = VK_FALSE;
3980 VkSampler sampler;
3981
3982 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
3983 ASSERT_VK_SUCCESS(err);
3984
3985 layout_binding[2].binding = 2;
3986 layout_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
3987 layout_binding[2].descriptorCount = 1;
3988 layout_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
3989 layout_binding[2].pImmutableSamplers = static_cast<VkSampler *>(&sampler);
3990
Mark Muellerd4914412016-06-13 17:52:06 -06003991 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3992 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3993 ds_layout_ci.bindingCount = sizeof(layout_binding) / sizeof(VkDescriptorSetLayoutBinding);
3994 ds_layout_ci.pBindings = layout_binding;
3995 VkDescriptorSetLayout ds_layout;
3996 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
3997 ASSERT_VK_SUCCESS(err);
3998
3999 VkDescriptorSetAllocateInfo alloc_info = {};
4000 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
4001 alloc_info.descriptorSetCount = 1;
4002 alloc_info.descriptorPool = ds_pool;
4003 alloc_info.pSetLayouts = &ds_layout;
4004 VkDescriptorSet descriptorSet;
4005 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
4006 ASSERT_VK_SUCCESS(err);
4007
4008 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4009 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4010 pipeline_layout_ci.pNext = NULL;
4011 pipeline_layout_ci.setLayoutCount = 1;
4012 pipeline_layout_ci.pSetLayouts = &ds_layout;
4013
4014 VkPipelineLayout pipeline_layout;
4015 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
4016 ASSERT_VK_SUCCESS(err);
4017
Mark Mueller5c838ce2016-06-16 09:54:29 -06004018 VkWriteDescriptorSet descriptor_write = {};
Mark Muellerd4914412016-06-13 17:52:06 -06004019 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
4020 descriptor_write.dstSet = descriptorSet;
4021 descriptor_write.dstBinding = 0;
4022 descriptor_write.descriptorCount = 1;
4023 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4024
Mark Mueller5c838ce2016-06-16 09:54:29 -06004025 // 1) The uniform buffer is intentionally invalid here
Mark Muellerd4914412016-06-13 17:52:06 -06004026 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4027 m_errorMonitor->VerifyFound();
4028
4029 // Create a buffer to update the descriptor with
4030 uint32_t qfi = 0;
4031 VkBufferCreateInfo buffCI = {};
4032 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
4033 buffCI.size = 1024;
4034 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
4035 buffCI.queueFamilyIndexCount = 1;
4036 buffCI.pQueueFamilyIndices = &qfi;
4037
4038 VkBuffer dyub;
4039 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
4040 ASSERT_VK_SUCCESS(err);
Mark Muellerd4914412016-06-13 17:52:06 -06004041
Tony Barboure132c5f2016-12-12 11:50:20 -07004042 VkDeviceMemory mem;
4043 VkMemoryRequirements mem_reqs;
4044 vkGetBufferMemoryRequirements(m_device->device(), dyub, &mem_reqs);
4045
4046 VkMemoryAllocateInfo mem_alloc_info = {};
4047 mem_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4048 mem_alloc_info.allocationSize = mem_reqs.size;
4049 m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
4050 err = vkAllocateMemory(m_device->device(), &mem_alloc_info, NULL, &mem);
4051 ASSERT_VK_SUCCESS(err);
4052
4053 err = vkBindBufferMemory(m_device->device(), dyub, mem, 0);
4054 ASSERT_VK_SUCCESS(err);
4055
4056 VkDescriptorBufferInfo buffInfo[2] = {};
4057 buffInfo[0].buffer = dyub;
4058 buffInfo[0].offset = 0;
4059 buffInfo[0].range = 1024;
4060 buffInfo[1].buffer = dyub;
4061 buffInfo[1].offset = 0;
4062 buffInfo[1].range = 1024;
4063 descriptor_write.pBufferInfo = buffInfo;
Mark Muellerd4914412016-06-13 17:52:06 -06004064 descriptor_write.descriptorCount = 2;
4065
Mark Mueller5c838ce2016-06-16 09:54:29 -06004066 // 2) The stateFlags don't match between the first and second descriptor
Mark Muellerd4914412016-06-13 17:52:06 -06004067 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, stateFlag_ErrorMessage);
4068 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4069 m_errorMonitor->VerifyFound();
4070
Mark Mueller5c838ce2016-06-16 09:54:29 -06004071 // 3) The second descriptor has a null_ptr pImmutableSamplers and
4072 // the third descriptor contains an immutable sampler
Mark Muellerd4914412016-06-13 17:52:06 -06004073 descriptor_write.dstBinding = 1;
4074 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Mark Mueller5c838ce2016-06-16 09:54:29 -06004075
Mark Mueller5c838ce2016-06-16 09:54:29 -06004076 // Make pImageInfo index non-null to avoid complaints of it missing
4077 VkDescriptorImageInfo imageInfo = {};
4078 imageInfo.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
4079 descriptor_write.pImageInfo = &imageInfo;
Mark Muellerd4914412016-06-13 17:52:06 -06004080 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, immutable_ErrorMessage);
4081 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4082 m_errorMonitor->VerifyFound();
4083
Mark Muellerd4914412016-06-13 17:52:06 -06004084 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tony Barboure132c5f2016-12-12 11:50:20 -07004085 vkFreeMemory(m_device->device(), mem, NULL);
Mark Muellerd4914412016-06-13 17:52:06 -06004086 vkDestroySampler(m_device->device(), sampler, NULL);
4087 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4088 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4089 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
4090}
4091
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004092TEST_F(VkLayerTest, InvalidCmdBufferBufferDestroyed) {
4093 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4094 "due to a buffer dependency being destroyed.");
4095 ASSERT_NO_FATAL_FAILURE(InitState());
4096
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004097 VkBuffer buffer;
4098 VkDeviceMemory mem;
4099 VkMemoryRequirements mem_reqs;
4100
4101 VkBufferCreateInfo buf_info = {};
4102 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes3d5882f2016-09-16 17:37:17 +12004103 buf_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004104 buf_info.size = 256;
4105 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
4106 VkResult err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
4107 ASSERT_VK_SUCCESS(err);
4108
4109 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
4110
4111 VkMemoryAllocateInfo alloc_info = {};
4112 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4113 alloc_info.allocationSize = 256;
4114 bool pass = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004115 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 -06004116 if (!pass) {
4117 vkDestroyBuffer(m_device->device(), buffer, NULL);
4118 return;
4119 }
4120 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
4121 ASSERT_VK_SUCCESS(err);
4122
4123 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
4124 ASSERT_VK_SUCCESS(err);
4125
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004126 m_commandBuffer->BeginCommandBuffer();
Chris Forbes3d5882f2016-09-16 17:37:17 +12004127 vkCmdFillBuffer(m_commandBuffer->GetBufferHandle(), buffer, 0, VK_WHOLE_SIZE, 0);
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004128 m_commandBuffer->EndCommandBuffer();
4129
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004130 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound buffer ");
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004131 // Destroy buffer dependency prior to submit to cause ERROR
4132 vkDestroyBuffer(m_device->device(), buffer, NULL);
4133
4134 VkSubmitInfo submit_info = {};
4135 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4136 submit_info.commandBufferCount = 1;
4137 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4138 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4139
4140 m_errorMonitor->VerifyFound();
4141 vkFreeMemory(m_device->handle(), mem, NULL);
4142}
4143
Tobin Ehlisea413442016-09-28 10:23:59 -06004144TEST_F(VkLayerTest, InvalidCmdBufferBufferViewDestroyed) {
4145 TEST_DESCRIPTION("Delete bufferView bound to cmd buffer, then attempt to submit cmd buffer.");
4146
4147 ASSERT_NO_FATAL_FAILURE(InitState());
4148 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4149
4150 VkDescriptorPoolSize ds_type_count;
4151 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
4152 ds_type_count.descriptorCount = 1;
4153
4154 VkDescriptorPoolCreateInfo ds_pool_ci = {};
4155 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4156 ds_pool_ci.maxSets = 1;
4157 ds_pool_ci.poolSizeCount = 1;
4158 ds_pool_ci.pPoolSizes = &ds_type_count;
4159
4160 VkDescriptorPool ds_pool;
4161 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
4162 ASSERT_VK_SUCCESS(err);
4163
4164 VkDescriptorSetLayoutBinding layout_binding;
4165 layout_binding.binding = 0;
4166 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
4167 layout_binding.descriptorCount = 1;
4168 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
4169 layout_binding.pImmutableSamplers = NULL;
4170
4171 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
4172 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4173 ds_layout_ci.bindingCount = 1;
4174 ds_layout_ci.pBindings = &layout_binding;
4175 VkDescriptorSetLayout ds_layout;
4176 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
4177 ASSERT_VK_SUCCESS(err);
4178
4179 VkDescriptorSetAllocateInfo alloc_info = {};
4180 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
4181 alloc_info.descriptorSetCount = 1;
4182 alloc_info.descriptorPool = ds_pool;
4183 alloc_info.pSetLayouts = &ds_layout;
4184 VkDescriptorSet descriptor_set;
4185 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
4186 ASSERT_VK_SUCCESS(err);
4187
4188 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4189 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4190 pipeline_layout_ci.pNext = NULL;
4191 pipeline_layout_ci.setLayoutCount = 1;
4192 pipeline_layout_ci.pSetLayouts = &ds_layout;
4193
4194 VkPipelineLayout pipeline_layout;
4195 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
4196 ASSERT_VK_SUCCESS(err);
4197
4198 VkBuffer buffer;
4199 uint32_t queue_family_index = 0;
4200 VkBufferCreateInfo buffer_create_info = {};
4201 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
4202 buffer_create_info.size = 1024;
4203 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
4204 buffer_create_info.queueFamilyIndexCount = 1;
4205 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
4206
4207 err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
4208 ASSERT_VK_SUCCESS(err);
4209
4210 VkMemoryRequirements memory_reqs;
4211 VkDeviceMemory buffer_memory;
4212
4213 VkMemoryAllocateInfo memory_info = {};
4214 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4215 memory_info.allocationSize = 0;
4216 memory_info.memoryTypeIndex = 0;
4217
4218 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
4219 memory_info.allocationSize = memory_reqs.size;
4220 bool pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
4221 ASSERT_TRUE(pass);
4222
4223 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
4224 ASSERT_VK_SUCCESS(err);
4225 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
4226 ASSERT_VK_SUCCESS(err);
4227
4228 VkBufferView view;
4229 VkBufferViewCreateInfo bvci = {};
4230 bvci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
4231 bvci.buffer = buffer;
4232 bvci.format = VK_FORMAT_R8_UNORM;
4233 bvci.range = VK_WHOLE_SIZE;
4234
4235 err = vkCreateBufferView(m_device->device(), &bvci, NULL, &view);
4236 ASSERT_VK_SUCCESS(err);
4237
4238 VkWriteDescriptorSet descriptor_write = {};
4239 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
4240 descriptor_write.dstSet = descriptor_set;
4241 descriptor_write.dstBinding = 0;
4242 descriptor_write.descriptorCount = 1;
4243 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
4244 descriptor_write.pTexelBufferView = &view;
4245
4246 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4247
4248 char const *vsSource = "#version 450\n"
4249 "\n"
4250 "out gl_PerVertex { \n"
4251 " vec4 gl_Position;\n"
4252 "};\n"
4253 "void main(){\n"
4254 " gl_Position = vec4(1);\n"
4255 "}\n";
4256 char const *fsSource = "#version 450\n"
4257 "\n"
4258 "layout(set=0, binding=0, r8) uniform imageBuffer s;\n"
4259 "layout(location=0) out vec4 x;\n"
4260 "void main(){\n"
4261 " x = imageLoad(s, 0);\n"
4262 "}\n";
4263 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4264 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
4265 VkPipelineObj pipe(m_device);
4266 pipe.AddShader(&vs);
4267 pipe.AddShader(&fs);
4268 pipe.AddColorAttachment();
4269 pipe.CreateVKPipeline(pipeline_layout, renderPass());
4270
4271 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot submit cmd buffer using deleted buffer view ");
4272 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound buffer view ");
4273
4274 BeginCommandBuffer();
4275 VkViewport viewport = {0, 0, 16, 16, 0, 1};
4276 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
4277 VkRect2D scissor = {{0, 0}, {16, 16}};
4278 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
4279 // Bind pipeline to cmd buffer
4280 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
4281 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
4282 &descriptor_set, 0, nullptr);
4283 Draw(1, 0, 0, 0);
4284 EndCommandBuffer();
4285
4286 // Delete BufferView in order to invalidate cmd buffer
4287 vkDestroyBufferView(m_device->device(), view, NULL);
4288 // Now attempt submit of cmd buffer
4289 VkSubmitInfo submit_info = {};
4290 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4291 submit_info.commandBufferCount = 1;
4292 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4293 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4294 m_errorMonitor->VerifyFound();
4295
4296 // Clean-up
4297 vkDestroyBuffer(m_device->device(), buffer, NULL);
4298 vkFreeMemory(m_device->device(), buffer_memory, NULL);
4299 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4300 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4301 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
4302}
4303
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004304TEST_F(VkLayerTest, InvalidCmdBufferImageDestroyed) {
4305 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4306 "due to an image dependency being destroyed.");
4307 ASSERT_NO_FATAL_FAILURE(InitState());
4308
4309 VkImage image;
4310 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
4311 VkImageCreateInfo image_create_info = {};
4312 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4313 image_create_info.pNext = NULL;
4314 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4315 image_create_info.format = tex_format;
4316 image_create_info.extent.width = 32;
4317 image_create_info.extent.height = 32;
4318 image_create_info.extent.depth = 1;
4319 image_create_info.mipLevels = 1;
4320 image_create_info.arrayLayers = 1;
4321 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
4322 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004323 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004324 image_create_info.flags = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004325 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004326 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004327 // Have to bind memory to image before recording cmd in cmd buffer using it
4328 VkMemoryRequirements mem_reqs;
4329 VkDeviceMemory image_mem;
4330 bool pass;
4331 VkMemoryAllocateInfo mem_alloc = {};
4332 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4333 mem_alloc.pNext = NULL;
4334 mem_alloc.memoryTypeIndex = 0;
4335 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
4336 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004337 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004338 ASSERT_TRUE(pass);
4339 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
4340 ASSERT_VK_SUCCESS(err);
4341 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
4342 ASSERT_VK_SUCCESS(err);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004343
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004344 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlis764d7072016-07-01 12:54:29 -06004345 VkClearColorValue ccv;
4346 ccv.float32[0] = 1.0f;
4347 ccv.float32[1] = 1.0f;
4348 ccv.float32[2] = 1.0f;
4349 ccv.float32[3] = 1.0f;
4350 VkImageSubresourceRange isr = {};
4351 isr.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004352 isr.baseArrayLayer = 0;
4353 isr.baseMipLevel = 0;
Tobin Ehlis764d7072016-07-01 12:54:29 -06004354 isr.layerCount = 1;
4355 isr.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004356 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), image, VK_IMAGE_LAYOUT_GENERAL, &ccv, 1, &isr);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004357 m_commandBuffer->EndCommandBuffer();
4358
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004359 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004360 // Destroy image dependency prior to submit to cause ERROR
4361 vkDestroyImage(m_device->device(), image, NULL);
4362
4363 VkSubmitInfo submit_info = {};
4364 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4365 submit_info.commandBufferCount = 1;
4366 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4367 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4368
4369 m_errorMonitor->VerifyFound();
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004370 vkFreeMemory(m_device->device(), image_mem, nullptr);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004371}
4372
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004373TEST_F(VkLayerTest, InvalidCmdBufferFramebufferImageDestroyed) {
4374 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4375 "due to a framebuffer image dependency being destroyed.");
4376 VkFormatProperties format_properties;
4377 VkResult err = VK_SUCCESS;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004378 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
4379 if (!(format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)) {
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004380 return;
4381 }
4382
4383 ASSERT_NO_FATAL_FAILURE(InitState());
4384 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4385
4386 VkImageCreateInfo image_ci = {};
4387 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4388 image_ci.pNext = NULL;
4389 image_ci.imageType = VK_IMAGE_TYPE_2D;
4390 image_ci.format = VK_FORMAT_B8G8R8A8_UNORM;
4391 image_ci.extent.width = 32;
4392 image_ci.extent.height = 32;
4393 image_ci.extent.depth = 1;
4394 image_ci.mipLevels = 1;
4395 image_ci.arrayLayers = 1;
4396 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
4397 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004398 image_ci.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_SAMPLED_BIT;
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004399 image_ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
4400 image_ci.flags = 0;
4401 VkImage image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004402 ASSERT_VK_SUCCESS(vkCreateImage(m_device->handle(), &image_ci, NULL, &image));
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004403
4404 VkMemoryRequirements memory_reqs;
4405 VkDeviceMemory image_memory;
4406 bool pass;
4407 VkMemoryAllocateInfo memory_info = {};
4408 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4409 memory_info.pNext = NULL;
4410 memory_info.allocationSize = 0;
4411 memory_info.memoryTypeIndex = 0;
4412 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
4413 memory_info.allocationSize = memory_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004414 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004415 ASSERT_TRUE(pass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004416 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004417 ASSERT_VK_SUCCESS(err);
4418 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
4419 ASSERT_VK_SUCCESS(err);
4420
4421 VkImageViewCreateInfo ivci = {
4422 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
4423 nullptr,
4424 0,
4425 image,
4426 VK_IMAGE_VIEW_TYPE_2D,
4427 VK_FORMAT_B8G8R8A8_UNORM,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004428 {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A},
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004429 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
4430 };
4431 VkImageView view;
4432 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
4433 ASSERT_VK_SUCCESS(err);
4434
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004435 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 32, 32, 1};
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004436 VkFramebuffer fb;
4437 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
4438 ASSERT_VK_SUCCESS(err);
4439
4440 // Just use default renderpass with our framebuffer
4441 m_renderPassBeginInfo.framebuffer = fb;
4442 // Create Null cmd buffer for submit
4443 BeginCommandBuffer();
4444 EndCommandBuffer();
4445 // Destroy image attached to framebuffer to invalidate cmd buffer
4446 vkDestroyImage(m_device->device(), image, NULL);
4447 // Now attempt to submit cmd buffer and verify error
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004448 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004449 QueueCommandBuffer(false);
4450 m_errorMonitor->VerifyFound();
4451
4452 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
4453 vkDestroyImageView(m_device->device(), view, nullptr);
4454 vkFreeMemory(m_device->device(), image_memory, nullptr);
4455}
4456
Tobin Ehlisb329f992016-10-12 13:20:29 -06004457TEST_F(VkLayerTest, FramebufferInUseDestroyedSignaled) {
4458 TEST_DESCRIPTION("Delete in-use framebuffer.");
4459 VkFormatProperties format_properties;
4460 VkResult err = VK_SUCCESS;
4461 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
4462
4463 ASSERT_NO_FATAL_FAILURE(InitState());
4464 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4465
4466 VkImageObj image(m_device);
4467 image.init(256, 256, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
4468 ASSERT_TRUE(image.initialized());
4469 VkImageView view = image.targetView(VK_FORMAT_B8G8R8A8_UNORM);
4470
4471 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 256, 256, 1};
4472 VkFramebuffer fb;
4473 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
4474 ASSERT_VK_SUCCESS(err);
4475
4476 // Just use default renderpass with our framebuffer
4477 m_renderPassBeginInfo.framebuffer = fb;
4478 // Create Null cmd buffer for submit
4479 BeginCommandBuffer();
4480 EndCommandBuffer();
4481 // Submit cmd buffer to put it in-flight
4482 VkSubmitInfo submit_info = {};
4483 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4484 submit_info.commandBufferCount = 1;
4485 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4486 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4487 // Destroy framebuffer while in-flight
4488 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete framebuffer 0x");
4489 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4490 m_errorMonitor->VerifyFound();
4491 // Wait for queue to complete so we can safely destroy everything
4492 vkQueueWaitIdle(m_device->m_queue);
4493 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
4494}
4495
Tobin Ehlis88becd72016-09-21 14:33:41 -06004496TEST_F(VkLayerTest, FramebufferImageInUseDestroyedSignaled) {
4497 TEST_DESCRIPTION("Delete in-use image that's child of framebuffer.");
4498 VkFormatProperties format_properties;
4499 VkResult err = VK_SUCCESS;
4500 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
Tobin Ehlis88becd72016-09-21 14:33:41 -06004501
4502 ASSERT_NO_FATAL_FAILURE(InitState());
4503 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4504
4505 VkImageCreateInfo image_ci = {};
4506 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4507 image_ci.pNext = NULL;
4508 image_ci.imageType = VK_IMAGE_TYPE_2D;
4509 image_ci.format = VK_FORMAT_B8G8R8A8_UNORM;
4510 image_ci.extent.width = 256;
4511 image_ci.extent.height = 256;
4512 image_ci.extent.depth = 1;
4513 image_ci.mipLevels = 1;
4514 image_ci.arrayLayers = 1;
4515 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
4516 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
Tobin Ehlisc8ca0312016-09-22 07:30:05 -06004517 image_ci.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Tobin Ehlis88becd72016-09-21 14:33:41 -06004518 image_ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
4519 image_ci.flags = 0;
4520 VkImage image;
4521 ASSERT_VK_SUCCESS(vkCreateImage(m_device->handle(), &image_ci, NULL, &image));
4522
4523 VkMemoryRequirements memory_reqs;
4524 VkDeviceMemory image_memory;
4525 bool pass;
4526 VkMemoryAllocateInfo memory_info = {};
4527 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4528 memory_info.pNext = NULL;
4529 memory_info.allocationSize = 0;
4530 memory_info.memoryTypeIndex = 0;
4531 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
4532 memory_info.allocationSize = memory_reqs.size;
4533 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
4534 ASSERT_TRUE(pass);
4535 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
4536 ASSERT_VK_SUCCESS(err);
4537 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
4538 ASSERT_VK_SUCCESS(err);
4539
4540 VkImageViewCreateInfo ivci = {
4541 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
4542 nullptr,
4543 0,
4544 image,
4545 VK_IMAGE_VIEW_TYPE_2D,
4546 VK_FORMAT_B8G8R8A8_UNORM,
4547 {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A},
4548 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
4549 };
4550 VkImageView view;
4551 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
4552 ASSERT_VK_SUCCESS(err);
4553
4554 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 256, 256, 1};
4555 VkFramebuffer fb;
4556 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
4557 ASSERT_VK_SUCCESS(err);
4558
4559 // Just use default renderpass with our framebuffer
4560 m_renderPassBeginInfo.framebuffer = fb;
4561 // Create Null cmd buffer for submit
4562 BeginCommandBuffer();
4563 EndCommandBuffer();
4564 // Submit cmd buffer to put it (and attached imageView) in-flight
4565 VkSubmitInfo submit_info = {};
4566 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4567 submit_info.commandBufferCount = 1;
4568 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4569 // Submit cmd buffer to put framebuffer and children in-flight
4570 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4571 // Destroy image attached to framebuffer while in-flight
4572 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete image 0x");
4573 vkDestroyImage(m_device->device(), image, NULL);
4574 m_errorMonitor->VerifyFound();
4575 // Wait for queue to complete so we can safely destroy image and other objects
4576 vkQueueWaitIdle(m_device->m_queue);
4577 vkDestroyImage(m_device->device(), image, NULL);
4578 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
4579 vkDestroyImageView(m_device->device(), view, nullptr);
4580 vkFreeMemory(m_device->device(), image_memory, nullptr);
4581}
4582
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06004583TEST_F(VkLayerTest, RenderPassInUseDestroyedSignaled) {
4584 TEST_DESCRIPTION("Delete in-use renderPass.");
4585
4586 ASSERT_NO_FATAL_FAILURE(InitState());
4587 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4588
4589 // Create simple renderpass
4590 VkAttachmentReference attach = {};
4591 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
4592 VkSubpassDescription subpass = {};
4593 subpass.pColorAttachments = &attach;
4594 VkRenderPassCreateInfo rpci = {};
4595 rpci.subpassCount = 1;
4596 rpci.pSubpasses = &subpass;
4597 rpci.attachmentCount = 1;
4598 VkAttachmentDescription attach_desc = {};
4599 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
4600 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
4601 rpci.pAttachments = &attach_desc;
4602 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
4603 VkRenderPass rp;
4604 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
4605 ASSERT_VK_SUCCESS(err);
4606
4607 // Create a pipeline that uses the given renderpass
4608 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4609 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4610
4611 VkPipelineLayout pipeline_layout;
4612 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
4613 ASSERT_VK_SUCCESS(err);
4614
4615 VkPipelineViewportStateCreateInfo vp_state_ci = {};
4616 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
4617 vp_state_ci.viewportCount = 1;
4618 VkViewport vp = {}; // Just need dummy vp to point to
4619 vp_state_ci.pViewports = &vp;
4620 vp_state_ci.scissorCount = 1;
4621 VkRect2D scissors = {}; // Dummy scissors to point to
4622 vp_state_ci.pScissors = &scissors;
4623
4624 VkPipelineShaderStageCreateInfo shaderStages[2];
4625 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
4626
4627 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
4628 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
4629 // but add it to be able to run on more devices
4630 shaderStages[0] = vs.GetStageCreateInfo();
4631 shaderStages[1] = fs.GetStageCreateInfo();
4632
4633 VkPipelineVertexInputStateCreateInfo vi_ci = {};
4634 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
4635
4636 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
4637 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
4638 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
4639
4640 VkPipelineRasterizationStateCreateInfo rs_ci = {};
4641 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
4642 rs_ci.rasterizerDiscardEnable = true;
4643 rs_ci.lineWidth = 1.0f;
4644
4645 VkPipelineColorBlendAttachmentState att = {};
4646 att.blendEnable = VK_FALSE;
4647 att.colorWriteMask = 0xf;
4648
4649 VkPipelineColorBlendStateCreateInfo cb_ci = {};
4650 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
4651 cb_ci.attachmentCount = 1;
4652 cb_ci.pAttachments = &att;
4653
4654 VkGraphicsPipelineCreateInfo gp_ci = {};
4655 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
4656 gp_ci.stageCount = 2;
4657 gp_ci.pStages = shaderStages;
4658 gp_ci.pVertexInputState = &vi_ci;
4659 gp_ci.pInputAssemblyState = &ia_ci;
4660 gp_ci.pViewportState = &vp_state_ci;
4661 gp_ci.pRasterizationState = &rs_ci;
4662 gp_ci.pColorBlendState = &cb_ci;
4663 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
4664 gp_ci.layout = pipeline_layout;
4665 gp_ci.renderPass = rp;
4666
4667 VkPipelineCacheCreateInfo pc_ci = {};
4668 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
4669
4670 VkPipeline pipeline;
4671 VkPipelineCache pipe_cache;
4672 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipe_cache);
4673 ASSERT_VK_SUCCESS(err);
4674
4675 err = vkCreateGraphicsPipelines(m_device->device(), pipe_cache, 1, &gp_ci, NULL, &pipeline);
4676 ASSERT_VK_SUCCESS(err);
4677 // Bind pipeline to cmd buffer, will also bind renderpass
4678 m_commandBuffer->BeginCommandBuffer();
4679 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
4680 m_commandBuffer->EndCommandBuffer();
4681
4682 VkSubmitInfo submit_info = {};
4683 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4684 submit_info.commandBufferCount = 1;
4685 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4686 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4687
4688 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00393);
4689 vkDestroyRenderPass(m_device->device(), rp, nullptr);
4690 m_errorMonitor->VerifyFound();
4691
4692 // Wait for queue to complete so we can safely destroy everything
4693 vkQueueWaitIdle(m_device->m_queue);
4694 vkDestroyRenderPass(m_device->device(), rp, nullptr);
4695 vkDestroyPipeline(m_device->device(), pipeline, nullptr);
4696 vkDestroyPipelineCache(m_device->device(), pipe_cache, nullptr);
4697 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
4698}
4699
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004700TEST_F(VkLayerTest, ImageMemoryNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004701 TEST_DESCRIPTION("Attempt to draw with an image which has not had memory bound to it.");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004702 ASSERT_NO_FATAL_FAILURE(InitState());
4703
4704 VkImage image;
4705 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
4706 VkImageCreateInfo image_create_info = {};
4707 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4708 image_create_info.pNext = NULL;
4709 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4710 image_create_info.format = tex_format;
4711 image_create_info.extent.width = 32;
4712 image_create_info.extent.height = 32;
4713 image_create_info.extent.depth = 1;
4714 image_create_info.mipLevels = 1;
4715 image_create_info.arrayLayers = 1;
4716 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
4717 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004718 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004719 image_create_info.flags = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004720 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004721 ASSERT_VK_SUCCESS(err);
4722 // Have to bind memory to image before recording cmd in cmd buffer using it
4723 VkMemoryRequirements mem_reqs;
4724 VkDeviceMemory image_mem;
4725 bool pass;
4726 VkMemoryAllocateInfo mem_alloc = {};
4727 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4728 mem_alloc.pNext = NULL;
4729 mem_alloc.memoryTypeIndex = 0;
4730 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
4731 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004732 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004733 ASSERT_TRUE(pass);
4734 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
4735 ASSERT_VK_SUCCESS(err);
4736
Tobin Ehlisfed999f2016-09-21 15:09:45 -06004737 // Introduce error, do not call vkBindImageMemory(m_device->device(), image, image_mem, 0);
4738 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06004739 " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004740
4741 m_commandBuffer->BeginCommandBuffer();
4742 VkClearColorValue ccv;
4743 ccv.float32[0] = 1.0f;
4744 ccv.float32[1] = 1.0f;
4745 ccv.float32[2] = 1.0f;
4746 ccv.float32[3] = 1.0f;
4747 VkImageSubresourceRange isr = {};
4748 isr.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
4749 isr.baseArrayLayer = 0;
4750 isr.baseMipLevel = 0;
4751 isr.layerCount = 1;
4752 isr.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004753 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), image, VK_IMAGE_LAYOUT_GENERAL, &ccv, 1, &isr);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004754 m_commandBuffer->EndCommandBuffer();
4755
4756 m_errorMonitor->VerifyFound();
4757 vkDestroyImage(m_device->device(), image, NULL);
4758 vkFreeMemory(m_device->device(), image_mem, nullptr);
4759}
4760
4761TEST_F(VkLayerTest, BufferMemoryNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004762 TEST_DESCRIPTION("Attempt to copy from a buffer which has not had memory bound to it.");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004763 ASSERT_NO_FATAL_FAILURE(InitState());
4764
4765 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004766 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 -06004767 VK_IMAGE_TILING_OPTIMAL, 0);
4768 ASSERT_TRUE(image.initialized());
4769
4770 VkBuffer buffer;
4771 VkDeviceMemory mem;
4772 VkMemoryRequirements mem_reqs;
4773
4774 VkBufferCreateInfo buf_info = {};
4775 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes8d260dd2016-09-16 17:42:42 +12004776 buf_info.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004777 buf_info.size = 256;
4778 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
4779 VkResult err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
4780 ASSERT_VK_SUCCESS(err);
4781
4782 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
4783
4784 VkMemoryAllocateInfo alloc_info = {};
4785 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4786 alloc_info.allocationSize = 256;
4787 bool pass = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004788 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 -06004789 if (!pass) {
4790 vkDestroyBuffer(m_device->device(), buffer, NULL);
4791 return;
4792 }
4793 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
4794 ASSERT_VK_SUCCESS(err);
4795
Tobin Ehlisfed999f2016-09-21 15:09:45 -06004796 // Introduce failure by not calling vkBindBufferMemory(m_device->device(), buffer, mem, 0);
4797 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06004798 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004799 VkBufferImageCopy region = {};
4800 region.bufferRowLength = 128;
4801 region.bufferImageHeight = 128;
4802 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
4803
4804 region.imageSubresource.layerCount = 1;
4805 region.imageExtent.height = 4;
4806 region.imageExtent.width = 4;
4807 region.imageExtent.depth = 1;
4808 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004809 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer, image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
4810 &region);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004811 m_commandBuffer->EndCommandBuffer();
4812
4813 m_errorMonitor->VerifyFound();
4814
4815 vkDestroyBuffer(m_device->device(), buffer, NULL);
4816 vkFreeMemory(m_device->handle(), mem, NULL);
4817}
4818
Tobin Ehlis85940f52016-07-07 16:57:21 -06004819TEST_F(VkLayerTest, InvalidCmdBufferEventDestroyed) {
4820 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4821 "due to an event dependency being destroyed.");
4822 ASSERT_NO_FATAL_FAILURE(InitState());
4823
4824 VkEvent event;
4825 VkEventCreateInfo evci = {};
4826 evci.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
4827 VkResult result = vkCreateEvent(m_device->device(), &evci, NULL, &event);
4828 ASSERT_VK_SUCCESS(result);
4829
4830 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004831 vkCmdSetEvent(m_commandBuffer->GetBufferHandle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Tobin Ehlis85940f52016-07-07 16:57:21 -06004832 m_commandBuffer->EndCommandBuffer();
4833
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004834 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound event ");
Tobin Ehlis85940f52016-07-07 16:57:21 -06004835 // Destroy event dependency prior to submit to cause ERROR
4836 vkDestroyEvent(m_device->device(), event, NULL);
4837
4838 VkSubmitInfo submit_info = {};
4839 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4840 submit_info.commandBufferCount = 1;
4841 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4842 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4843
4844 m_errorMonitor->VerifyFound();
4845}
4846
Tobin Ehlisdbea7552016-07-08 14:33:31 -06004847TEST_F(VkLayerTest, InvalidCmdBufferQueryPoolDestroyed) {
4848 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4849 "due to a query pool dependency being destroyed.");
4850 ASSERT_NO_FATAL_FAILURE(InitState());
4851
4852 VkQueryPool query_pool;
4853 VkQueryPoolCreateInfo qpci{};
4854 qpci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
4855 qpci.queryType = VK_QUERY_TYPE_TIMESTAMP;
4856 qpci.queryCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004857 VkResult result = vkCreateQueryPool(m_device->device(), &qpci, nullptr, &query_pool);
Tobin Ehlisdbea7552016-07-08 14:33:31 -06004858 ASSERT_VK_SUCCESS(result);
4859
4860 m_commandBuffer->BeginCommandBuffer();
4861 vkCmdResetQueryPool(m_commandBuffer->GetBufferHandle(), query_pool, 0, 1);
4862 m_commandBuffer->EndCommandBuffer();
4863
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004864 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound query pool ");
Tobin Ehlisdbea7552016-07-08 14:33:31 -06004865 // Destroy query pool dependency prior to submit to cause ERROR
4866 vkDestroyQueryPool(m_device->device(), query_pool, NULL);
4867
4868 VkSubmitInfo submit_info = {};
4869 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4870 submit_info.commandBufferCount = 1;
4871 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4872 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4873
4874 m_errorMonitor->VerifyFound();
4875}
4876
Tobin Ehlis24130d92016-07-08 15:50:53 -06004877TEST_F(VkLayerTest, InvalidCmdBufferPipelineDestroyed) {
4878 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4879 "due to a pipeline dependency being destroyed.");
4880 ASSERT_NO_FATAL_FAILURE(InitState());
4881 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4882
4883 VkResult err;
4884
4885 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4886 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4887
4888 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004889 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis24130d92016-07-08 15:50:53 -06004890 ASSERT_VK_SUCCESS(err);
4891
4892 VkPipelineViewportStateCreateInfo vp_state_ci = {};
4893 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
4894 vp_state_ci.viewportCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004895 VkViewport vp = {}; // Just need dummy vp to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -06004896 vp_state_ci.pViewports = &vp;
Tobin Ehlis24130d92016-07-08 15:50:53 -06004897 vp_state_ci.scissorCount = 1;
4898 VkRect2D scissors = {}; // Dummy scissors to point to
4899 vp_state_ci.pScissors = &scissors;
Tobin Ehlis24130d92016-07-08 15:50:53 -06004900
4901 VkPipelineShaderStageCreateInfo shaderStages[2];
4902 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
4903
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004904 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
4905 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
4906 // but add it to be able to run on more devices
Tobin Ehlis24130d92016-07-08 15:50:53 -06004907 shaderStages[0] = vs.GetStageCreateInfo();
4908 shaderStages[1] = fs.GetStageCreateInfo();
4909
4910 VkPipelineVertexInputStateCreateInfo vi_ci = {};
4911 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
4912
4913 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
4914 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
4915 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
4916
4917 VkPipelineRasterizationStateCreateInfo rs_ci = {};
4918 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Chris Forbese06ba252016-09-16 17:48:53 +12004919 rs_ci.rasterizerDiscardEnable = true;
4920 rs_ci.lineWidth = 1.0f;
Tobin Ehlis24130d92016-07-08 15:50:53 -06004921
4922 VkPipelineColorBlendAttachmentState att = {};
4923 att.blendEnable = VK_FALSE;
4924 att.colorWriteMask = 0xf;
4925
4926 VkPipelineColorBlendStateCreateInfo cb_ci = {};
4927 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
4928 cb_ci.attachmentCount = 1;
4929 cb_ci.pAttachments = &att;
4930
4931 VkGraphicsPipelineCreateInfo gp_ci = {};
4932 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
4933 gp_ci.stageCount = 2;
4934 gp_ci.pStages = shaderStages;
4935 gp_ci.pVertexInputState = &vi_ci;
4936 gp_ci.pInputAssemblyState = &ia_ci;
4937 gp_ci.pViewportState = &vp_state_ci;
4938 gp_ci.pRasterizationState = &rs_ci;
4939 gp_ci.pColorBlendState = &cb_ci;
Tobin Ehlis24130d92016-07-08 15:50:53 -06004940 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
4941 gp_ci.layout = pipeline_layout;
4942 gp_ci.renderPass = renderPass();
4943
4944 VkPipelineCacheCreateInfo pc_ci = {};
4945 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
4946
4947 VkPipeline pipeline;
4948 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004949 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis24130d92016-07-08 15:50:53 -06004950 ASSERT_VK_SUCCESS(err);
4951
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004952 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis24130d92016-07-08 15:50:53 -06004953 ASSERT_VK_SUCCESS(err);
4954
4955 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004956 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Tobin Ehlis24130d92016-07-08 15:50:53 -06004957 m_commandBuffer->EndCommandBuffer();
4958 // Now destroy pipeline in order to cause error when submitting
4959 vkDestroyPipeline(m_device->device(), pipeline, nullptr);
4960
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004961 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound pipeline ");
Tobin Ehlis24130d92016-07-08 15:50:53 -06004962
4963 VkSubmitInfo submit_info = {};
4964 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4965 submit_info.commandBufferCount = 1;
4966 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4967 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4968
4969 m_errorMonitor->VerifyFound();
4970 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
4971 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4972}
4973
Tobin Ehlis31289162016-08-17 14:57:58 -06004974TEST_F(VkLayerTest, InvalidCmdBufferDescriptorSetBufferDestroyed) {
4975 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4976 "due to a bound descriptor set with a buffer dependency "
4977 "being destroyed.");
4978 ASSERT_NO_FATAL_FAILURE(InitState());
4979 ASSERT_NO_FATAL_FAILURE(InitViewport());
4980 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4981
4982 VkDescriptorPoolSize ds_type_count = {};
4983 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4984 ds_type_count.descriptorCount = 1;
4985
4986 VkDescriptorPoolCreateInfo ds_pool_ci = {};
4987 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4988 ds_pool_ci.pNext = NULL;
4989 ds_pool_ci.maxSets = 1;
4990 ds_pool_ci.poolSizeCount = 1;
4991 ds_pool_ci.pPoolSizes = &ds_type_count;
4992
4993 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004994 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis31289162016-08-17 14:57:58 -06004995 ASSERT_VK_SUCCESS(err);
4996
4997 VkDescriptorSetLayoutBinding dsl_binding = {};
4998 dsl_binding.binding = 0;
4999 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5000 dsl_binding.descriptorCount = 1;
5001 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5002 dsl_binding.pImmutableSamplers = NULL;
5003
5004 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5005 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5006 ds_layout_ci.pNext = NULL;
5007 ds_layout_ci.bindingCount = 1;
5008 ds_layout_ci.pBindings = &dsl_binding;
5009 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005010 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis31289162016-08-17 14:57:58 -06005011 ASSERT_VK_SUCCESS(err);
5012
5013 VkDescriptorSet descriptorSet;
5014 VkDescriptorSetAllocateInfo alloc_info = {};
5015 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
5016 alloc_info.descriptorSetCount = 1;
5017 alloc_info.descriptorPool = ds_pool;
5018 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005019 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis31289162016-08-17 14:57:58 -06005020 ASSERT_VK_SUCCESS(err);
5021
5022 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5023 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5024 pipeline_layout_ci.pNext = NULL;
5025 pipeline_layout_ci.setLayoutCount = 1;
5026 pipeline_layout_ci.pSetLayouts = &ds_layout;
5027
5028 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005029 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis31289162016-08-17 14:57:58 -06005030 ASSERT_VK_SUCCESS(err);
5031
5032 // Create a buffer to update the descriptor with
5033 uint32_t qfi = 0;
5034 VkBufferCreateInfo buffCI = {};
5035 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
5036 buffCI.size = 1024;
5037 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
5038 buffCI.queueFamilyIndexCount = 1;
5039 buffCI.pQueueFamilyIndices = &qfi;
5040
5041 VkBuffer buffer;
5042 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &buffer);
5043 ASSERT_VK_SUCCESS(err);
5044 // Allocate memory and bind to buffer so we can make it to the appropriate
5045 // error
5046 VkMemoryAllocateInfo mem_alloc = {};
5047 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5048 mem_alloc.pNext = NULL;
5049 mem_alloc.allocationSize = 1024;
5050 mem_alloc.memoryTypeIndex = 0;
5051
5052 VkMemoryRequirements memReqs;
5053 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005054 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis31289162016-08-17 14:57:58 -06005055 if (!pass) {
5056 vkDestroyBuffer(m_device->device(), buffer, NULL);
5057 return;
5058 }
5059
5060 VkDeviceMemory mem;
5061 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
5062 ASSERT_VK_SUCCESS(err);
5063 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
5064 ASSERT_VK_SUCCESS(err);
5065 // Correctly update descriptor to avoid "NOT_UPDATED" error
5066 VkDescriptorBufferInfo buffInfo = {};
5067 buffInfo.buffer = buffer;
5068 buffInfo.offset = 0;
5069 buffInfo.range = 1024;
5070
5071 VkWriteDescriptorSet descriptor_write;
5072 memset(&descriptor_write, 0, sizeof(descriptor_write));
5073 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5074 descriptor_write.dstSet = descriptorSet;
5075 descriptor_write.dstBinding = 0;
5076 descriptor_write.descriptorCount = 1;
5077 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5078 descriptor_write.pBufferInfo = &buffInfo;
5079
5080 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5081
5082 // Create PSO to be used for draw-time errors below
5083 char const *vsSource = "#version 450\n"
5084 "\n"
5085 "out gl_PerVertex { \n"
5086 " vec4 gl_Position;\n"
5087 "};\n"
5088 "void main(){\n"
5089 " gl_Position = vec4(1);\n"
5090 "}\n";
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005091 char const *fsSource = "#version 450\n"
5092 "\n"
5093 "layout(location=0) out vec4 x;\n"
5094 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
5095 "void main(){\n"
5096 " x = vec4(bar.y);\n"
5097 "}\n";
Tobin Ehlis31289162016-08-17 14:57:58 -06005098 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5099 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5100 VkPipelineObj pipe(m_device);
5101 pipe.AddShader(&vs);
5102 pipe.AddShader(&fs);
5103 pipe.AddColorAttachment();
5104 pipe.CreateVKPipeline(pipeline_layout, renderPass());
5105
5106 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005107 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5108 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5109 &descriptorSet, 0, NULL);
Tobin Ehlis31289162016-08-17 14:57:58 -06005110 Draw(1, 0, 0, 0);
5111 EndCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005112 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound buffer ");
Tobin Ehlis31289162016-08-17 14:57:58 -06005113 // Destroy buffer should invalidate the cmd buffer, causing error on submit
5114 vkDestroyBuffer(m_device->device(), buffer, NULL);
5115 // Attempt to submit cmd buffer
5116 VkSubmitInfo submit_info = {};
5117 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5118 submit_info.commandBufferCount = 1;
5119 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5120 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5121 m_errorMonitor->VerifyFound();
5122 // Cleanup
5123 vkFreeMemory(m_device->device(), mem, NULL);
5124
5125 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5126 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5127 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5128}
5129
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005130TEST_F(VkLayerTest, InvalidCmdBufferDescriptorSetImageSamplerDestroyed) {
5131 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
5132 "due to a bound descriptor sets with a combined image "
5133 "sampler having their image, sampler, and descriptor set "
5134 "each respectively destroyed and then attempting to "
Mark Mueller917f6bc2016-08-30 10:57:19 -06005135 "submit associated cmd buffers. Attempt to destroy a "
5136 "DescriptorSet that is in use.");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005137 ASSERT_NO_FATAL_FAILURE(InitState());
5138 ASSERT_NO_FATAL_FAILURE(InitViewport());
5139 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5140
5141 VkDescriptorPoolSize ds_type_count = {};
5142 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5143 ds_type_count.descriptorCount = 1;
5144
5145 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5146 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5147 ds_pool_ci.pNext = NULL;
5148 ds_pool_ci.maxSets = 1;
5149 ds_pool_ci.poolSizeCount = 1;
5150 ds_pool_ci.pPoolSizes = &ds_type_count;
5151
5152 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005153 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005154 ASSERT_VK_SUCCESS(err);
5155
5156 VkDescriptorSetLayoutBinding dsl_binding = {};
5157 dsl_binding.binding = 0;
5158 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5159 dsl_binding.descriptorCount = 1;
5160 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5161 dsl_binding.pImmutableSamplers = NULL;
5162
5163 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5164 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5165 ds_layout_ci.pNext = NULL;
5166 ds_layout_ci.bindingCount = 1;
5167 ds_layout_ci.pBindings = &dsl_binding;
5168 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005169 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005170 ASSERT_VK_SUCCESS(err);
5171
5172 VkDescriptorSet descriptorSet;
5173 VkDescriptorSetAllocateInfo alloc_info = {};
5174 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
5175 alloc_info.descriptorSetCount = 1;
5176 alloc_info.descriptorPool = ds_pool;
5177 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005178 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005179 ASSERT_VK_SUCCESS(err);
5180
5181 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5182 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5183 pipeline_layout_ci.pNext = NULL;
5184 pipeline_layout_ci.setLayoutCount = 1;
5185 pipeline_layout_ci.pSetLayouts = &ds_layout;
5186
5187 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005188 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005189 ASSERT_VK_SUCCESS(err);
5190
5191 // Create images to update the descriptor with
5192 VkImage image;
5193 VkImage image2;
5194 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
5195 const int32_t tex_width = 32;
5196 const int32_t tex_height = 32;
5197 VkImageCreateInfo image_create_info = {};
5198 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5199 image_create_info.pNext = NULL;
5200 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5201 image_create_info.format = tex_format;
5202 image_create_info.extent.width = tex_width;
5203 image_create_info.extent.height = tex_height;
5204 image_create_info.extent.depth = 1;
5205 image_create_info.mipLevels = 1;
5206 image_create_info.arrayLayers = 1;
5207 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
5208 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
5209 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
5210 image_create_info.flags = 0;
5211 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
5212 ASSERT_VK_SUCCESS(err);
5213 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image2);
5214 ASSERT_VK_SUCCESS(err);
5215
5216 VkMemoryRequirements memory_reqs;
5217 VkDeviceMemory image_memory;
5218 bool pass;
5219 VkMemoryAllocateInfo memory_info = {};
5220 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5221 memory_info.pNext = NULL;
5222 memory_info.allocationSize = 0;
5223 memory_info.memoryTypeIndex = 0;
5224 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
5225 // Allocate enough memory for both images
5226 memory_info.allocationSize = memory_reqs.size * 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005227 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005228 ASSERT_TRUE(pass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005229 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005230 ASSERT_VK_SUCCESS(err);
5231 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
5232 ASSERT_VK_SUCCESS(err);
5233 // Bind second image to memory right after first image
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005234 err = vkBindImageMemory(m_device->device(), image2, image_memory, memory_reqs.size);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005235 ASSERT_VK_SUCCESS(err);
5236
5237 VkImageViewCreateInfo image_view_create_info = {};
5238 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
5239 image_view_create_info.image = image;
5240 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
5241 image_view_create_info.format = tex_format;
5242 image_view_create_info.subresourceRange.layerCount = 1;
5243 image_view_create_info.subresourceRange.baseMipLevel = 0;
5244 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005245 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005246
5247 VkImageView view;
5248 VkImageView view2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005249 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005250 ASSERT_VK_SUCCESS(err);
5251 image_view_create_info.image = image2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005252 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view2);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005253 ASSERT_VK_SUCCESS(err);
5254 // Create Samplers
5255 VkSamplerCreateInfo sampler_ci = {};
5256 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
5257 sampler_ci.pNext = NULL;
5258 sampler_ci.magFilter = VK_FILTER_NEAREST;
5259 sampler_ci.minFilter = VK_FILTER_NEAREST;
5260 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
5261 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5262 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5263 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5264 sampler_ci.mipLodBias = 1.0;
5265 sampler_ci.anisotropyEnable = VK_FALSE;
5266 sampler_ci.maxAnisotropy = 1;
5267 sampler_ci.compareEnable = VK_FALSE;
5268 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
5269 sampler_ci.minLod = 1.0;
5270 sampler_ci.maxLod = 1.0;
5271 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
5272 sampler_ci.unnormalizedCoordinates = VK_FALSE;
5273 VkSampler sampler;
5274 VkSampler sampler2;
5275 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
5276 ASSERT_VK_SUCCESS(err);
5277 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler2);
5278 ASSERT_VK_SUCCESS(err);
5279 // Update descriptor with image and sampler
5280 VkDescriptorImageInfo img_info = {};
5281 img_info.sampler = sampler;
5282 img_info.imageView = view;
5283 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
5284
5285 VkWriteDescriptorSet descriptor_write;
5286 memset(&descriptor_write, 0, sizeof(descriptor_write));
5287 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5288 descriptor_write.dstSet = descriptorSet;
5289 descriptor_write.dstBinding = 0;
5290 descriptor_write.descriptorCount = 1;
5291 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5292 descriptor_write.pImageInfo = &img_info;
5293
5294 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5295
5296 // Create PSO to be used for draw-time errors below
5297 char const *vsSource = "#version 450\n"
5298 "\n"
5299 "out gl_PerVertex { \n"
5300 " vec4 gl_Position;\n"
5301 "};\n"
5302 "void main(){\n"
5303 " gl_Position = vec4(1);\n"
5304 "}\n";
5305 char const *fsSource = "#version 450\n"
5306 "\n"
5307 "layout(set=0, binding=0) uniform sampler2D s;\n"
5308 "layout(location=0) out vec4 x;\n"
5309 "void main(){\n"
5310 " x = texture(s, vec2(1));\n"
5311 "}\n";
5312 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5313 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5314 VkPipelineObj pipe(m_device);
5315 pipe.AddShader(&vs);
5316 pipe.AddShader(&fs);
5317 pipe.AddColorAttachment();
5318 pipe.CreateVKPipeline(pipeline_layout, renderPass());
5319
5320 // First error case is destroying sampler prior to cmd buffer submission
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005321 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot submit cmd buffer using deleted sampler ");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005322 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005323 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5324 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5325 &descriptorSet, 0, NULL);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005326 Draw(1, 0, 0, 0);
5327 EndCommandBuffer();
5328 // Destroy sampler invalidates the cmd buffer, causing error on submit
5329 vkDestroySampler(m_device->device(), sampler, NULL);
5330 // Attempt to submit cmd buffer
5331 VkSubmitInfo submit_info = {};
5332 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5333 submit_info.commandBufferCount = 1;
5334 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5335 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5336 m_errorMonitor->VerifyFound();
5337 // Now re-update descriptor with valid sampler and delete image
5338 img_info.sampler = sampler2;
5339 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005340 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005341 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005342 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5343 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5344 &descriptorSet, 0, NULL);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005345 Draw(1, 0, 0, 0);
5346 EndCommandBuffer();
5347 // Destroy image invalidates the cmd buffer, causing error on submit
5348 vkDestroyImage(m_device->device(), image, NULL);
5349 // Attempt to submit cmd buffer
5350 submit_info = {};
5351 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5352 submit_info.commandBufferCount = 1;
5353 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5354 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5355 m_errorMonitor->VerifyFound();
5356 // Now update descriptor to be valid, but then free descriptor
5357 img_info.imageView = view2;
5358 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005359 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound descriptor set ");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005360 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005361 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5362 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5363 &descriptorSet, 0, NULL);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005364 Draw(1, 0, 0, 0);
5365 EndCommandBuffer();
5366 // Destroy descriptor set invalidates the cb, causing error on submit
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005367 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot call vkFreeDescriptorSets() on descriptor set 0x");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005368 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
Mark Mueller917f6bc2016-08-30 10:57:19 -06005369 m_errorMonitor->VerifyFound();
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005370 // Attempt to submit cmd buffer
5371 submit_info = {};
5372 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5373 submit_info.commandBufferCount = 1;
5374 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5375 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5376 m_errorMonitor->VerifyFound();
5377 // Cleanup
5378 vkFreeMemory(m_device->device(), image_memory, NULL);
5379 vkDestroySampler(m_device->device(), sampler2, NULL);
5380 vkDestroyImage(m_device->device(), image2, NULL);
5381 vkDestroyImageView(m_device->device(), view, NULL);
5382 vkDestroyImageView(m_device->device(), view2, NULL);
5383 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5384 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5385 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5386}
5387
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06005388TEST_F(VkLayerTest, DescriptorPoolInUseDestroyedSignaled) {
5389 TEST_DESCRIPTION("Delete a DescriptorPool with a DescriptorSet that is in use.");
5390 ASSERT_NO_FATAL_FAILURE(InitState());
5391 ASSERT_NO_FATAL_FAILURE(InitViewport());
5392 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5393
5394 VkDescriptorPoolSize ds_type_count = {};
5395 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5396 ds_type_count.descriptorCount = 1;
5397
5398 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5399 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5400 ds_pool_ci.pNext = NULL;
5401 ds_pool_ci.maxSets = 1;
5402 ds_pool_ci.poolSizeCount = 1;
5403 ds_pool_ci.pPoolSizes = &ds_type_count;
5404
5405 VkDescriptorPool ds_pool;
5406 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
5407 ASSERT_VK_SUCCESS(err);
5408
5409 VkDescriptorSetLayoutBinding dsl_binding = {};
5410 dsl_binding.binding = 0;
5411 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5412 dsl_binding.descriptorCount = 1;
5413 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5414 dsl_binding.pImmutableSamplers = NULL;
5415
5416 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5417 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5418 ds_layout_ci.pNext = NULL;
5419 ds_layout_ci.bindingCount = 1;
5420 ds_layout_ci.pBindings = &dsl_binding;
5421 VkDescriptorSetLayout ds_layout;
5422 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
5423 ASSERT_VK_SUCCESS(err);
5424
5425 VkDescriptorSet descriptor_set;
5426 VkDescriptorSetAllocateInfo alloc_info = {};
5427 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
5428 alloc_info.descriptorSetCount = 1;
5429 alloc_info.descriptorPool = ds_pool;
5430 alloc_info.pSetLayouts = &ds_layout;
5431 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
5432 ASSERT_VK_SUCCESS(err);
5433
5434 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5435 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5436 pipeline_layout_ci.pNext = NULL;
5437 pipeline_layout_ci.setLayoutCount = 1;
5438 pipeline_layout_ci.pSetLayouts = &ds_layout;
5439
5440 VkPipelineLayout pipeline_layout;
5441 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
5442 ASSERT_VK_SUCCESS(err);
5443
5444 // Create image to update the descriptor with
5445 VkImageObj image(m_device);
5446 image.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
5447 ASSERT_TRUE(image.initialized());
5448
5449 VkImageView view = image.targetView(VK_FORMAT_B8G8R8A8_UNORM);
5450 // Create Sampler
5451 VkSamplerCreateInfo sampler_ci = {};
5452 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
5453 sampler_ci.pNext = NULL;
5454 sampler_ci.magFilter = VK_FILTER_NEAREST;
5455 sampler_ci.minFilter = VK_FILTER_NEAREST;
5456 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
5457 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5458 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5459 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5460 sampler_ci.mipLodBias = 1.0;
5461 sampler_ci.anisotropyEnable = VK_FALSE;
5462 sampler_ci.maxAnisotropy = 1;
5463 sampler_ci.compareEnable = VK_FALSE;
5464 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
5465 sampler_ci.minLod = 1.0;
5466 sampler_ci.maxLod = 1.0;
5467 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
5468 sampler_ci.unnormalizedCoordinates = VK_FALSE;
5469 VkSampler sampler;
5470 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
5471 ASSERT_VK_SUCCESS(err);
5472 // Update descriptor with image and sampler
5473 VkDescriptorImageInfo img_info = {};
5474 img_info.sampler = sampler;
5475 img_info.imageView = view;
5476 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
5477
5478 VkWriteDescriptorSet descriptor_write;
5479 memset(&descriptor_write, 0, sizeof(descriptor_write));
5480 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5481 descriptor_write.dstSet = descriptor_set;
5482 descriptor_write.dstBinding = 0;
5483 descriptor_write.descriptorCount = 1;
5484 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5485 descriptor_write.pImageInfo = &img_info;
5486
5487 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5488
5489 // Create PSO to be used for draw-time errors below
5490 char const *vsSource = "#version 450\n"
5491 "\n"
5492 "out gl_PerVertex { \n"
5493 " vec4 gl_Position;\n"
5494 "};\n"
5495 "void main(){\n"
5496 " gl_Position = vec4(1);\n"
5497 "}\n";
5498 char const *fsSource = "#version 450\n"
5499 "\n"
5500 "layout(set=0, binding=0) uniform sampler2D s;\n"
5501 "layout(location=0) out vec4 x;\n"
5502 "void main(){\n"
5503 " x = texture(s, vec2(1));\n"
5504 "}\n";
5505 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5506 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5507 VkPipelineObj pipe(m_device);
5508 pipe.AddShader(&vs);
5509 pipe.AddShader(&fs);
5510 pipe.AddColorAttachment();
5511 pipe.CreateVKPipeline(pipeline_layout, renderPass());
5512
5513 BeginCommandBuffer();
5514 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5515 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5516 &descriptor_set, 0, NULL);
5517 Draw(1, 0, 0, 0);
5518 EndCommandBuffer();
5519 // Submit cmd buffer to put pool in-flight
5520 VkSubmitInfo submit_info = {};
5521 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5522 submit_info.commandBufferCount = 1;
5523 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5524 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5525 // Destroy pool while in-flight, causing error
5526 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete descriptor pool ");
5527 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5528 m_errorMonitor->VerifyFound();
5529 vkQueueWaitIdle(m_device->m_queue);
5530 // Cleanup
5531 vkDestroySampler(m_device->device(), sampler, NULL);
5532 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5533 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5534 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5535}
5536
Tobin Ehlis50a095d2016-09-21 17:32:49 -06005537TEST_F(VkLayerTest, DescriptorImageUpdateNoMemoryBound) {
5538 TEST_DESCRIPTION("Attempt an image descriptor set update where image's bound memory has been freed.");
5539 ASSERT_NO_FATAL_FAILURE(InitState());
5540 ASSERT_NO_FATAL_FAILURE(InitViewport());
5541 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5542
5543 VkDescriptorPoolSize ds_type_count = {};
5544 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5545 ds_type_count.descriptorCount = 1;
5546
5547 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5548 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5549 ds_pool_ci.pNext = NULL;
5550 ds_pool_ci.maxSets = 1;
5551 ds_pool_ci.poolSizeCount = 1;
5552 ds_pool_ci.pPoolSizes = &ds_type_count;
5553
5554 VkDescriptorPool ds_pool;
5555 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
5556 ASSERT_VK_SUCCESS(err);
5557
5558 VkDescriptorSetLayoutBinding dsl_binding = {};
5559 dsl_binding.binding = 0;
5560 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5561 dsl_binding.descriptorCount = 1;
5562 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5563 dsl_binding.pImmutableSamplers = NULL;
5564
5565 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5566 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5567 ds_layout_ci.pNext = NULL;
5568 ds_layout_ci.bindingCount = 1;
5569 ds_layout_ci.pBindings = &dsl_binding;
5570 VkDescriptorSetLayout ds_layout;
5571 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
5572 ASSERT_VK_SUCCESS(err);
5573
5574 VkDescriptorSet descriptorSet;
5575 VkDescriptorSetAllocateInfo alloc_info = {};
5576 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
5577 alloc_info.descriptorSetCount = 1;
5578 alloc_info.descriptorPool = ds_pool;
5579 alloc_info.pSetLayouts = &ds_layout;
5580 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
5581 ASSERT_VK_SUCCESS(err);
5582
5583 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5584 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5585 pipeline_layout_ci.pNext = NULL;
5586 pipeline_layout_ci.setLayoutCount = 1;
5587 pipeline_layout_ci.pSetLayouts = &ds_layout;
5588
5589 VkPipelineLayout pipeline_layout;
5590 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
5591 ASSERT_VK_SUCCESS(err);
5592
5593 // Create images to update the descriptor with
5594 VkImage image;
5595 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
5596 const int32_t tex_width = 32;
5597 const int32_t tex_height = 32;
5598 VkImageCreateInfo image_create_info = {};
5599 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5600 image_create_info.pNext = NULL;
5601 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5602 image_create_info.format = tex_format;
5603 image_create_info.extent.width = tex_width;
5604 image_create_info.extent.height = tex_height;
5605 image_create_info.extent.depth = 1;
5606 image_create_info.mipLevels = 1;
5607 image_create_info.arrayLayers = 1;
5608 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
5609 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
5610 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
5611 image_create_info.flags = 0;
5612 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
5613 ASSERT_VK_SUCCESS(err);
5614 // Initially bind memory to avoid error at bind view time. We'll break binding before update.
5615 VkMemoryRequirements memory_reqs;
5616 VkDeviceMemory image_memory;
5617 bool pass;
5618 VkMemoryAllocateInfo memory_info = {};
5619 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5620 memory_info.pNext = NULL;
5621 memory_info.allocationSize = 0;
5622 memory_info.memoryTypeIndex = 0;
5623 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
5624 // Allocate enough memory for image
5625 memory_info.allocationSize = memory_reqs.size;
5626 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
5627 ASSERT_TRUE(pass);
5628 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
5629 ASSERT_VK_SUCCESS(err);
5630 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
5631 ASSERT_VK_SUCCESS(err);
5632
5633 VkImageViewCreateInfo image_view_create_info = {};
5634 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
5635 image_view_create_info.image = image;
5636 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
5637 image_view_create_info.format = tex_format;
5638 image_view_create_info.subresourceRange.layerCount = 1;
5639 image_view_create_info.subresourceRange.baseMipLevel = 0;
5640 image_view_create_info.subresourceRange.levelCount = 1;
5641 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
5642
5643 VkImageView view;
5644 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
5645 ASSERT_VK_SUCCESS(err);
5646 // Create Samplers
5647 VkSamplerCreateInfo sampler_ci = {};
5648 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
5649 sampler_ci.pNext = NULL;
5650 sampler_ci.magFilter = VK_FILTER_NEAREST;
5651 sampler_ci.minFilter = VK_FILTER_NEAREST;
5652 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
5653 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5654 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5655 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5656 sampler_ci.mipLodBias = 1.0;
5657 sampler_ci.anisotropyEnable = VK_FALSE;
5658 sampler_ci.maxAnisotropy = 1;
5659 sampler_ci.compareEnable = VK_FALSE;
5660 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
5661 sampler_ci.minLod = 1.0;
5662 sampler_ci.maxLod = 1.0;
5663 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
5664 sampler_ci.unnormalizedCoordinates = VK_FALSE;
5665 VkSampler sampler;
5666 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
5667 ASSERT_VK_SUCCESS(err);
5668 // Update descriptor with image and sampler
5669 VkDescriptorImageInfo img_info = {};
5670 img_info.sampler = sampler;
5671 img_info.imageView = view;
5672 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
5673
5674 VkWriteDescriptorSet descriptor_write;
5675 memset(&descriptor_write, 0, sizeof(descriptor_write));
5676 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5677 descriptor_write.dstSet = descriptorSet;
5678 descriptor_write.dstBinding = 0;
5679 descriptor_write.descriptorCount = 1;
5680 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5681 descriptor_write.pImageInfo = &img_info;
5682 // Break memory binding and attempt update
5683 vkFreeMemory(m_device->device(), image_memory, nullptr);
5684 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06005685 " previously bound memory was freed. Memory must not be freed prior to this operation.");
Tobin Ehlis50a095d2016-09-21 17:32:49 -06005686 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
5687 "vkUpdateDescriptorsSets() failed write update validation for Descriptor Set 0x");
5688 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5689 m_errorMonitor->VerifyFound();
5690 // Cleanup
5691 vkDestroyImage(m_device->device(), image, NULL);
5692 vkDestroySampler(m_device->device(), sampler, NULL);
5693 vkDestroyImageView(m_device->device(), view, NULL);
5694 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5695 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5696 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5697}
5698
Karl Schultz6addd812016-02-02 17:17:23 -07005699TEST_F(VkLayerTest, InvalidPipeline) {
Karl Schultzbdb75952016-04-19 11:36:49 -06005700 // Attempt to bind an invalid Pipeline to a valid Command Buffer
5701 // ObjectTracker should catch this.
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06005702 // Create a valid cmd buffer
5703 // call vkCmdBindPipeline w/ false Pipeline
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06005704 uint64_t fake_pipeline_handle = 0xbaad6001;
5705 VkPipeline bad_pipeline = reinterpret_cast<VkPipeline &>(fake_pipeline_handle);
Karl Schultzbdb75952016-04-19 11:36:49 -06005706 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes4dbf70f2016-09-16 17:58:00 +12005707 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5708
Karl Schultzf78bcdd2016-11-30 12:36:01 -07005709 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00601);
Karl Schultzbdb75952016-04-19 11:36:49 -06005710 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005711 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, bad_pipeline);
Karl Schultzbdb75952016-04-19 11:36:49 -06005712 m_errorMonitor->VerifyFound();
Chris Forbes4dbf70f2016-09-16 17:58:00 +12005713
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06005714 // Now issue a draw call with no pipeline bound
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005715 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 -06005716 Draw(1, 0, 0, 0);
5717 m_errorMonitor->VerifyFound();
Chris Forbes4dbf70f2016-09-16 17:58:00 +12005718
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06005719 // Finally same check once more but with Dispatch/Compute
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005720 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 +12005721 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle()); // must be outside renderpass
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06005722 vkCmdDispatch(m_commandBuffer->GetBufferHandle(), 0, 0, 0);
5723 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06005724}
5725
Karl Schultz6addd812016-02-02 17:17:23 -07005726TEST_F(VkLayerTest, DescriptorSetNotUpdated) {
Tobin Ehlis5a5f5ef2016-08-17 13:56:55 -06005727 TEST_DESCRIPTION("Bind a descriptor set that hasn't been updated.");
Karl Schultz6addd812016-02-02 17:17:23 -07005728 VkResult err;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005729
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005730 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, " bound but it was never updated. ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005731
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005732 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyan713b2d72015-08-04 10:49:29 -06005733 ASSERT_NO_FATAL_FAILURE(InitViewport());
5734 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08005735 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005736 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5737 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06005738
5739 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005740 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5741 ds_pool_ci.pNext = NULL;
5742 ds_pool_ci.maxSets = 1;
5743 ds_pool_ci.poolSizeCount = 1;
5744 ds_pool_ci.pPoolSizes = &ds_type_count;
Mike Stroyan713b2d72015-08-04 10:49:29 -06005745
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005746 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005747 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005748 ASSERT_VK_SUCCESS(err);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005749
Tony Barboureb254902015-07-15 12:50:33 -06005750 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005751 dsl_binding.binding = 0;
5752 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5753 dsl_binding.descriptorCount = 1;
5754 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5755 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005756
Tony Barboureb254902015-07-15 12:50:33 -06005757 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005758 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5759 ds_layout_ci.pNext = NULL;
5760 ds_layout_ci.bindingCount = 1;
5761 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005762 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005763 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005764 ASSERT_VK_SUCCESS(err);
5765
5766 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005767 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08005768 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07005769 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06005770 alloc_info.descriptorPool = ds_pool;
5771 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005772 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005773 ASSERT_VK_SUCCESS(err);
5774
Tony Barboureb254902015-07-15 12:50:33 -06005775 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005776 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5777 pipeline_layout_ci.pNext = NULL;
5778 pipeline_layout_ci.setLayoutCount = 1;
5779 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005780
5781 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005782 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005783 ASSERT_VK_SUCCESS(err);
5784
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005785 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -06005786 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -07005787 // on more devices
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005788 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005789
Tony Barbourc95e4ac2015-08-04 17:05:26 -06005790 VkPipelineObj pipe(m_device);
5791 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06005792 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -06005793 pipe.AddColorAttachment();
Tony Barbourc95e4ac2015-08-04 17:05:26 -06005794 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06005795
5796 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005797 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5798 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5799 &descriptorSet, 0, NULL);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005800
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005801 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06005802
Chia-I Wuf7458c52015-10-26 21:10:41 +08005803 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5804 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5805 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06005806}
5807
Karl Schultz6addd812016-02-02 17:17:23 -07005808TEST_F(VkLayerTest, InvalidBufferViewObject) {
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005809 // Create a single TEXEL_BUFFER descriptor and send it an invalid bufferView
Karl Schultz6addd812016-02-02 17:17:23 -07005810 VkResult err;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005811
Karl Schultzf78bcdd2016-11-30 12:36:01 -07005812 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00940);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005813
5814 ASSERT_NO_FATAL_FAILURE(InitState());
5815 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005816 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
5817 ds_type_count.descriptorCount = 1;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005818
5819 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005820 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5821 ds_pool_ci.pNext = NULL;
5822 ds_pool_ci.maxSets = 1;
5823 ds_pool_ci.poolSizeCount = 1;
5824 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005825
5826 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005827 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005828 ASSERT_VK_SUCCESS(err);
5829
5830 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005831 dsl_binding.binding = 0;
5832 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
5833 dsl_binding.descriptorCount = 1;
5834 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5835 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005836
5837 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005838 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5839 ds_layout_ci.pNext = NULL;
5840 ds_layout_ci.bindingCount = 1;
5841 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005842 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005843 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005844 ASSERT_VK_SUCCESS(err);
5845
5846 VkDescriptorSet descriptorSet;
5847 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08005848 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07005849 alloc_info.descriptorSetCount = 1;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005850 alloc_info.descriptorPool = ds_pool;
5851 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005852 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005853 ASSERT_VK_SUCCESS(err);
5854
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005855 VkBufferView view = (VkBufferView)((size_t)0xbaadbeef); // invalid bufferView object
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005856 VkWriteDescriptorSet descriptor_write;
5857 memset(&descriptor_write, 0, sizeof(descriptor_write));
5858 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5859 descriptor_write.dstSet = descriptorSet;
5860 descriptor_write.dstBinding = 0;
5861 descriptor_write.descriptorCount = 1;
5862 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
5863 descriptor_write.pTexelBufferView = &view;
5864
5865 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5866
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005867 m_errorMonitor->VerifyFound();
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005868
5869 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5870 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5871}
5872
Mark Youngd339ba32016-05-30 13:28:35 -06005873TEST_F(VkLayerTest, CreateBufferViewNoMemoryBoundToBuffer) {
Tobin Ehlis4ff58172016-09-22 10:52:00 -06005874 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 -06005875
5876 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -06005877 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06005878 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Mark Youngd339ba32016-05-30 13:28:35 -06005879
5880 ASSERT_NO_FATAL_FAILURE(InitState());
5881
5882 // Create a buffer with no bound memory and then attempt to create
5883 // a buffer view.
5884 VkBufferCreateInfo buff_ci = {};
5885 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes4538d242016-09-13 18:13:58 +12005886 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT;
Mark Youngd339ba32016-05-30 13:28:35 -06005887 buff_ci.size = 256;
5888 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
5889 VkBuffer buffer;
5890 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
5891 ASSERT_VK_SUCCESS(err);
5892
5893 VkBufferViewCreateInfo buff_view_ci = {};
5894 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
5895 buff_view_ci.buffer = buffer;
5896 buff_view_ci.format = VK_FORMAT_R8_UNORM;
5897 buff_view_ci.range = VK_WHOLE_SIZE;
5898 VkBufferView buff_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005899 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buff_view);
Mark Youngd339ba32016-05-30 13:28:35 -06005900
5901 m_errorMonitor->VerifyFound();
5902 vkDestroyBuffer(m_device->device(), buffer, NULL);
5903 // If last error is success, it still created the view, so delete it.
5904 if (err == VK_SUCCESS) {
5905 vkDestroyBufferView(m_device->device(), buff_view, NULL);
5906 }
5907}
5908
Karl Schultz6addd812016-02-02 17:17:23 -07005909TEST_F(VkLayerTest, InvalidDynamicOffsetCases) {
5910 // Create a descriptorSet w/ dynamic descriptor and then hit 3 offset error
5911 // cases:
Tobin Ehlisf6585052015-12-17 11:48:42 -07005912 // 1. No dynamicOffset supplied
5913 // 2. Too many dynamicOffsets supplied
5914 // 3. Dynamic offset oversteps buffer being updated
Karl Schultz6addd812016-02-02 17:17:23 -07005915 VkResult err;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005916 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " requires 1 dynamicOffsets, but only "
5917 "0 dynamicOffsets are left in "
5918 "pDynamicOffsets ");
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005919
5920 ASSERT_NO_FATAL_FAILURE(InitState());
5921 ASSERT_NO_FATAL_FAILURE(InitViewport());
5922 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5923
5924 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005925 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
5926 ds_type_count.descriptorCount = 1;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005927
5928 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005929 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5930 ds_pool_ci.pNext = NULL;
5931 ds_pool_ci.maxSets = 1;
5932 ds_pool_ci.poolSizeCount = 1;
5933 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005934
5935 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005936 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005937 ASSERT_VK_SUCCESS(err);
5938
5939 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005940 dsl_binding.binding = 0;
5941 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
5942 dsl_binding.descriptorCount = 1;
5943 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5944 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005945
5946 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005947 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5948 ds_layout_ci.pNext = NULL;
5949 ds_layout_ci.bindingCount = 1;
5950 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005951 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005952 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005953 ASSERT_VK_SUCCESS(err);
5954
5955 VkDescriptorSet descriptorSet;
5956 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08005957 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07005958 alloc_info.descriptorSetCount = 1;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005959 alloc_info.descriptorPool = ds_pool;
5960 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005961 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005962 ASSERT_VK_SUCCESS(err);
5963
5964 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005965 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5966 pipeline_layout_ci.pNext = NULL;
5967 pipeline_layout_ci.setLayoutCount = 1;
5968 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005969
5970 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005971 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005972 ASSERT_VK_SUCCESS(err);
5973
5974 // Create a buffer to update the descriptor with
5975 uint32_t qfi = 0;
5976 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005977 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
5978 buffCI.size = 1024;
5979 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
5980 buffCI.queueFamilyIndexCount = 1;
5981 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005982
5983 VkBuffer dyub;
5984 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
5985 ASSERT_VK_SUCCESS(err);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06005986 // Allocate memory and bind to buffer so we can make it to the appropriate
5987 // error
5988 VkMemoryAllocateInfo mem_alloc = {};
5989 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5990 mem_alloc.pNext = NULL;
5991 mem_alloc.allocationSize = 1024;
Chris Forbesb6116cc2016-05-08 11:39:59 +12005992 mem_alloc.memoryTypeIndex = 0;
5993
5994 VkMemoryRequirements memReqs;
5995 vkGetBufferMemoryRequirements(m_device->device(), dyub, &memReqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005996 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
Chris Forbesb6116cc2016-05-08 11:39:59 +12005997 if (!pass) {
5998 vkDestroyBuffer(m_device->device(), dyub, NULL);
5999 return;
6000 }
6001
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06006002 VkDeviceMemory mem;
6003 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
6004 ASSERT_VK_SUCCESS(err);
6005 err = vkBindBufferMemory(m_device->device(), dyub, mem, 0);
6006 ASSERT_VK_SUCCESS(err);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006007 // Correctly update descriptor to avoid "NOT_UPDATED" error
6008 VkDescriptorBufferInfo buffInfo = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006009 buffInfo.buffer = dyub;
6010 buffInfo.offset = 0;
6011 buffInfo.range = 1024;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006012
6013 VkWriteDescriptorSet descriptor_write;
6014 memset(&descriptor_write, 0, sizeof(descriptor_write));
6015 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6016 descriptor_write.dstSet = descriptorSet;
6017 descriptor_write.dstBinding = 0;
6018 descriptor_write.descriptorCount = 1;
6019 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6020 descriptor_write.pBufferInfo = &buffInfo;
6021
6022 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6023
6024 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006025 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6026 &descriptorSet, 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006027 m_errorMonitor->VerifyFound();
Tobin Ehlisf6585052015-12-17 11:48:42 -07006028 uint32_t pDynOff[2] = {512, 756};
6029 // Now cause error b/c too many dynOffsets in array for # of dyn descriptors
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006030 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6031 "Attempting to bind 1 descriptorSets with 1 dynamic descriptors, but ");
6032 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6033 &descriptorSet, 2, pDynOff);
Chris Forbes7b342802016-04-07 13:20:10 +12006034 m_errorMonitor->VerifyFound();
Tobin Ehlisf6585052015-12-17 11:48:42 -07006035 // Finally cause error due to dynamicOffset being too big
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006036 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " dynamic offset 512 combined with "
6037 "offset 0 and range 1024 that "
6038 "oversteps the buffer size of 1024");
Tobin Ehlisf6585052015-12-17 11:48:42 -07006039 // Create PSO to be used for draw-time errors below
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006040 char const *vsSource = "#version 450\n"
6041 "\n"
6042 "out gl_PerVertex { \n"
6043 " vec4 gl_Position;\n"
6044 "};\n"
6045 "void main(){\n"
6046 " gl_Position = vec4(1);\n"
6047 "}\n";
6048 char const *fsSource = "#version 450\n"
6049 "\n"
6050 "layout(location=0) out vec4 x;\n"
6051 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
6052 "void main(){\n"
6053 " x = vec4(bar.y);\n"
6054 "}\n";
Tobin Ehlisf6585052015-12-17 11:48:42 -07006055 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
6056 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
6057 VkPipelineObj pipe(m_device);
6058 pipe.AddShader(&vs);
6059 pipe.AddShader(&fs);
6060 pipe.AddColorAttachment();
6061 pipe.CreateVKPipeline(pipeline_layout, renderPass());
6062
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006063 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07006064 // This update should succeed, but offset size of 512 will overstep buffer
6065 // /w range 1024 & size 1024
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006066 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6067 &descriptorSet, 1, pDynOff);
Tobin Ehlisf6585052015-12-17 11:48:42 -07006068 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006069 m_errorMonitor->VerifyFound();
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006070
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06006071 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tobin Ehlis512098e2016-05-05 09:06:12 -06006072 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06006073
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006074 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06006075 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006076 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6077}
6078
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006079TEST_F(VkLayerTest, DescriptorBufferUpdateNoMemoryBound) {
6080 TEST_DESCRIPTION("Attempt to update a descriptor with a non-sparse buffer "
6081 "that doesn't have memory bound");
6082 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -06006083 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06006084 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Tobin Ehlisfed999f2016-09-21 15:09:45 -06006085 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6086 "vkUpdateDescriptorsSets() failed write update validation for Descriptor Set 0x");
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006087
6088 ASSERT_NO_FATAL_FAILURE(InitState());
6089 ASSERT_NO_FATAL_FAILURE(InitViewport());
6090 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6091
6092 VkDescriptorPoolSize ds_type_count = {};
6093 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6094 ds_type_count.descriptorCount = 1;
6095
6096 VkDescriptorPoolCreateInfo ds_pool_ci = {};
6097 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6098 ds_pool_ci.pNext = NULL;
6099 ds_pool_ci.maxSets = 1;
6100 ds_pool_ci.poolSizeCount = 1;
6101 ds_pool_ci.pPoolSizes = &ds_type_count;
6102
6103 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006104 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006105 ASSERT_VK_SUCCESS(err);
6106
6107 VkDescriptorSetLayoutBinding dsl_binding = {};
6108 dsl_binding.binding = 0;
6109 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6110 dsl_binding.descriptorCount = 1;
6111 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6112 dsl_binding.pImmutableSamplers = NULL;
6113
6114 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
6115 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6116 ds_layout_ci.pNext = NULL;
6117 ds_layout_ci.bindingCount = 1;
6118 ds_layout_ci.pBindings = &dsl_binding;
6119 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006120 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006121 ASSERT_VK_SUCCESS(err);
6122
6123 VkDescriptorSet descriptorSet;
6124 VkDescriptorSetAllocateInfo alloc_info = {};
6125 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
6126 alloc_info.descriptorSetCount = 1;
6127 alloc_info.descriptorPool = ds_pool;
6128 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006129 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006130 ASSERT_VK_SUCCESS(err);
6131
6132 // Create a buffer to update the descriptor with
6133 uint32_t qfi = 0;
6134 VkBufferCreateInfo buffCI = {};
6135 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
6136 buffCI.size = 1024;
6137 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
6138 buffCI.queueFamilyIndexCount = 1;
6139 buffCI.pQueueFamilyIndices = &qfi;
6140
6141 VkBuffer dyub;
6142 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
6143 ASSERT_VK_SUCCESS(err);
6144
6145 // Attempt to update descriptor without binding memory to it
6146 VkDescriptorBufferInfo buffInfo = {};
6147 buffInfo.buffer = dyub;
6148 buffInfo.offset = 0;
6149 buffInfo.range = 1024;
6150
6151 VkWriteDescriptorSet descriptor_write;
6152 memset(&descriptor_write, 0, sizeof(descriptor_write));
6153 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6154 descriptor_write.dstSet = descriptorSet;
6155 descriptor_write.dstBinding = 0;
6156 descriptor_write.descriptorCount = 1;
6157 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6158 descriptor_write.pBufferInfo = &buffInfo;
6159
6160 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6161 m_errorMonitor->VerifyFound();
6162
6163 vkDestroyBuffer(m_device->device(), dyub, NULL);
6164 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6165 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6166}
6167
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006168TEST_F(VkLayerTest, InvalidPushConstants) {
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006169 VkResult err;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006170 ASSERT_NO_FATAL_FAILURE(InitState());
6171 ASSERT_NO_FATAL_FAILURE(InitViewport());
6172 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6173
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006174 VkPipelineLayout pipeline_layout;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006175 VkPushConstantRange pc_range = {};
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006176 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
6177 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6178 pipeline_layout_ci.pushConstantRangeCount = 1;
6179 pipeline_layout_ci.pPushConstantRanges = &pc_range;
6180
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006181 //
6182 // Check for invalid push constant ranges in pipeline layouts.
6183 //
6184 struct PipelineLayoutTestCase {
Karl Schultzc81037d2016-05-12 08:11:23 -06006185 VkPushConstantRange const range;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006186 char const *msg;
6187 };
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006188
Karl Schultzc81037d2016-05-12 08:11:23 -06006189 const uint32_t too_big = m_device->props.limits.maxPushConstantsSize + 0x4;
6190 const std::array<PipelineLayoutTestCase, 10> range_tests = {{
6191 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 0},
6192 "vkCreatePipelineLayout() call has push constants index 0 with "
6193 "size 0."},
6194 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 1},
6195 "vkCreatePipelineLayout() call has push constants index 0 with "
6196 "size 1."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006197 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 1},
Karl Schultzc81037d2016-05-12 08:11:23 -06006198 "vkCreatePipelineLayout() call has push constants index 0 with "
6199 "size 1."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006200 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 0},
Karl Schultzc81037d2016-05-12 08:11:23 -06006201 "vkCreatePipelineLayout() call has push constants index 0 with "
6202 "size 0."},
6203 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
6204 "vkCreatePipelineLayout() call has push constants index 0 with "
6205 "offset 1. Offset must"},
6206 {{VK_SHADER_STAGE_VERTEX_BIT, 0, too_big},
6207 "vkCreatePipelineLayout() call has push constants index 0 "
6208 "with offset "},
6209 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, too_big},
6210 "vkCreatePipelineLayout() call has push constants "
6211 "index 0 with offset "},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006212 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, 4},
Karl Schultzc81037d2016-05-12 08:11:23 -06006213 "vkCreatePipelineLayout() call has push constants index 0 "
6214 "with offset "},
6215 {{VK_SHADER_STAGE_VERTEX_BIT, 0xFFFFFFF0, 0x00000020},
6216 "vkCreatePipelineLayout() call has push "
6217 "constants index 0 with offset "},
6218 {{VK_SHADER_STAGE_VERTEX_BIT, 0x00000020, 0xFFFFFFF0},
6219 "vkCreatePipelineLayout() call has push "
6220 "constants index 0 with offset "},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006221 }};
6222
6223 // Check for invalid offset and size
Karl Schultzc81037d2016-05-12 08:11:23 -06006224 for (const auto &iter : range_tests) {
6225 pc_range = iter.range;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006226 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
6227 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006228 m_errorMonitor->VerifyFound();
6229 if (VK_SUCCESS == err) {
6230 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6231 }
6232 }
6233
6234 // Check for invalid stage flag
6235 pc_range.offset = 0;
6236 pc_range.size = 16;
6237 pc_range.stageFlags = 0;
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006238 m_errorMonitor->SetDesiredFailureMsg(
6239 VK_DEBUG_REPORT_ERROR_BIT_EXT,
6240 "vkCreatePipelineLayout: value of pCreateInfo->pPushConstantRanges[0].stageFlags must not be 0");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006241 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006242 m_errorMonitor->VerifyFound();
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006243 if (VK_SUCCESS == err) {
6244 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6245 }
6246
6247 // Check for overlapping ranges
Karl Schultzc81037d2016-05-12 08:11:23 -06006248 const uint32_t ranges_per_test = 5;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006249 struct OverlappingRangeTestCase {
Karl Schultzc81037d2016-05-12 08:11:23 -06006250 VkPushConstantRange const ranges[ranges_per_test];
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006251 char const *msg;
6252 };
6253
Karl Schultzc81037d2016-05-12 08:11:23 -06006254 const std::array<OverlappingRangeTestCase, 5> overlapping_range_tests = {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006255 {{{{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6256 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6257 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6258 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6259 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006260 "vkCreatePipelineLayout() call has push constants with overlapping ranges:"},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006261 {
6262 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6263 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
6264 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
6265 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
6266 {VK_SHADER_STAGE_VERTEX_BIT, 16, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006267 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 3:[12, 20), 4:[16, 20)",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006268 },
6269 {
6270 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
6271 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
6272 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
6273 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
6274 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006275 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 0:[16, 20), 1:[12, 20)",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006276 },
6277 {
6278 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
6279 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
6280 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
6281 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
6282 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006283 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 0:[16, 20), 3:[12, 20)",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006284 },
6285 {
6286 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
6287 {VK_SHADER_STAGE_VERTEX_BIT, 32, 4},
6288 {VK_SHADER_STAGE_VERTEX_BIT, 4, 96},
6289 {VK_SHADER_STAGE_VERTEX_BIT, 40, 8},
6290 {VK_SHADER_STAGE_VERTEX_BIT, 52, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006291 "vkCreatePipelineLayout() call has push constants with overlapping ranges:",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006292 }}};
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006293
Karl Schultzc81037d2016-05-12 08:11:23 -06006294 for (const auto &iter : overlapping_range_tests) {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006295 pipeline_layout_ci.pPushConstantRanges = iter.ranges;
Karl Schultzc81037d2016-05-12 08:11:23 -06006296 pipeline_layout_ci.pushConstantRangeCount = ranges_per_test;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006297 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, iter.msg);
6298 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006299 m_errorMonitor->VerifyFound();
6300 if (VK_SUCCESS == err) {
6301 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6302 }
6303 }
6304
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006305 //
6306 // CmdPushConstants tests
6307 //
Karl Schultzc81037d2016-05-12 08:11:23 -06006308 const uint8_t dummy_values[100] = {};
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006309
6310 // Check for invalid offset and size and if range is within layout range(s)
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006311 const std::array<PipelineLayoutTestCase, 11> cmd_range_tests = {{
6312 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 0}, "vkCmdPushConstants: parameter size must be greater than 0"},
Karl Schultzc81037d2016-05-12 08:11:23 -06006313 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 1},
6314 "vkCmdPushConstants() call has push constants with size 1. Size "
6315 "must be greater than zero and a multiple of 4."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006316 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 1},
Karl Schultzc81037d2016-05-12 08:11:23 -06006317 "vkCmdPushConstants() call has push constants with size 1. Size "
6318 "must be greater than zero and a multiple of 4."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006319 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
Karl Schultzc81037d2016-05-12 08:11:23 -06006320 "vkCmdPushConstants() call has push constants with offset 1. "
6321 "Offset must be a multiple of 4."},
6322 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
6323 "vkCmdPushConstants() call has push constants with offset 1. "
6324 "Offset must be a multiple of 4."},
6325 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 20},
6326 "vkCmdPushConstants() Push constant range [0, 20) with stageFlags = "
6327 "0x1 not within flag-matching ranges in pipeline layout"},
6328 {{VK_SHADER_STAGE_VERTEX_BIT, 60, 8},
6329 "vkCmdPushConstants() Push constant range [60, 68) with stageFlags = "
6330 "0x1 not within flag-matching ranges in pipeline layout"},
6331 {{VK_SHADER_STAGE_VERTEX_BIT, 76, 8},
6332 "vkCmdPushConstants() Push constant range [76, 84) with stageFlags = "
6333 "0x1 not within flag-matching ranges in pipeline layout"},
6334 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 80},
6335 "vkCmdPushConstants() Push constant range [0, 80) with stageFlags = "
6336 "0x1 not within flag-matching ranges in pipeline layout"},
6337 {{VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, 0, 4},
6338 "vkCmdPushConstants() stageFlags = 0x2 do not match the stageFlags in "
6339 "any of the ranges in pipeline layout"},
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006340 {{VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, 0, 16},
Karl Schultzc81037d2016-05-12 08:11:23 -06006341 "vkCmdPushConstants() stageFlags = 0x3 do not match the stageFlags in "
6342 "any of the ranges in pipeline layout"},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006343 }};
6344
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006345 BeginCommandBuffer();
6346
6347 // Setup ranges: [0,16) [64,80)
Karl Schultzc81037d2016-05-12 08:11:23 -06006348 const VkPushConstantRange pc_range2[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006349 {VK_SHADER_STAGE_VERTEX_BIT, 64, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 0, 16},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006350 };
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006351 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range2) / sizeof(VkPushConstantRange);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006352 pipeline_layout_ci.pPushConstantRanges = pc_range2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006353 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006354 ASSERT_VK_SUCCESS(err);
Karl Schultzc81037d2016-05-12 08:11:23 -06006355 for (const auto &iter : cmd_range_tests) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006356 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
6357 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.range.stageFlags, iter.range.offset,
Karl Schultzc81037d2016-05-12 08:11:23 -06006358 iter.range.size, dummy_values);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006359 m_errorMonitor->VerifyFound();
6360 }
6361
6362 // Check for invalid stage flag
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006363 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdPushConstants: value of stageFlags must not be 0");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006364 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, 0, 0, 16, dummy_values);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006365 m_errorMonitor->VerifyFound();
Karl Schultzc81037d2016-05-12 08:11:23 -06006366 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006367
Karl Schultzc81037d2016-05-12 08:11:23 -06006368 // overlapping range tests with cmd
6369 const std::array<PipelineLayoutTestCase, 3> cmd_overlap_tests = {{
6370 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 20},
6371 "vkCmdPushConstants() Push constant range [0, 20) with stageFlags = "
6372 "0x1 not within flag-matching ranges in pipeline layout"},
6373 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
6374 "vkCmdPushConstants() Push constant range [16, 20) with stageFlags = "
6375 "0x1 not within flag-matching ranges in pipeline layout"},
6376 {{VK_SHADER_STAGE_VERTEX_BIT, 40, 16},
6377 "vkCmdPushConstants() Push constant range [40, 56) with stageFlags = "
6378 "0x1 not within flag-matching ranges in pipeline layout"},
6379 }};
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006380 // Setup ranges: [0,16), [20,36), [36,44), [44,52), [80,92)
Karl Schultzc81037d2016-05-12 08:11:23 -06006381 const VkPushConstantRange pc_range3[] = {
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006382 {VK_SHADER_STAGE_VERTEX_BIT, 20, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 0, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 44, 8},
6383 {VK_SHADER_STAGE_VERTEX_BIT, 80, 12}, {VK_SHADER_STAGE_VERTEX_BIT, 36, 8},
Karl Schultzc81037d2016-05-12 08:11:23 -06006384 };
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006385 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range3) / sizeof(VkPushConstantRange);
Karl Schultzc81037d2016-05-12 08:11:23 -06006386 pipeline_layout_ci.pPushConstantRanges = pc_range3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006387 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzc81037d2016-05-12 08:11:23 -06006388 ASSERT_VK_SUCCESS(err);
Karl Schultzc81037d2016-05-12 08:11:23 -06006389 for (const auto &iter : cmd_overlap_tests) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006390 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
6391 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.range.stageFlags, iter.range.offset,
Karl Schultzc81037d2016-05-12 08:11:23 -06006392 iter.range.size, dummy_values);
6393 m_errorMonitor->VerifyFound();
6394 }
Karl Schultzc81037d2016-05-12 08:11:23 -06006395 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6396
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006397 EndCommandBuffer();
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006398}
6399
Karl Schultz6addd812016-02-02 17:17:23 -07006400TEST_F(VkLayerTest, DescriptorSetCompatibility) {
Tobin Ehlis559c6382015-11-05 09:52:49 -07006401 // Test various desriptorSet errors with bad binding combinations
Karl Schultz6addd812016-02-02 17:17:23 -07006402 VkResult err;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006403
6404 ASSERT_NO_FATAL_FAILURE(InitState());
6405 ASSERT_NO_FATAL_FAILURE(InitViewport());
6406 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6407
Mike Stroyanb8a61002016-06-20 16:00:28 -06006408 const VkFormat tex_format = VK_FORMAT_R8G8B8A8_UNORM;
6409 VkImageTiling tiling;
6410 VkFormatProperties format_properties;
6411 vkGetPhysicalDeviceFormatProperties(gpu(), tex_format, &format_properties);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006412 if (format_properties.linearTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
Mike Stroyanb8a61002016-06-20 16:00:28 -06006413 tiling = VK_IMAGE_TILING_LINEAR;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006414 } else if (format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
Mike Stroyanb8a61002016-06-20 16:00:28 -06006415 tiling = VK_IMAGE_TILING_OPTIMAL;
6416 } else {
6417 printf("Device does not support VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT; "
6418 "skipped.\n");
6419 return;
6420 }
6421
Tobin Ehlis559c6382015-11-05 09:52:49 -07006422 static const uint32_t NUM_DESCRIPTOR_TYPES = 5;
6423 VkDescriptorPoolSize ds_type_count[NUM_DESCRIPTOR_TYPES] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006424 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6425 ds_type_count[0].descriptorCount = 10;
6426 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
6427 ds_type_count[1].descriptorCount = 2;
6428 ds_type_count[2].type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
6429 ds_type_count[2].descriptorCount = 2;
6430 ds_type_count[3].type = VK_DESCRIPTOR_TYPE_SAMPLER;
6431 ds_type_count[3].descriptorCount = 5;
6432 // TODO : LunarG ILO driver currently asserts in desc.c w/ INPUT_ATTACHMENT
6433 // type
6434 // ds_type_count[4].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
6435 ds_type_count[4].type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
6436 ds_type_count[4].descriptorCount = 2;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006437
6438 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006439 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6440 ds_pool_ci.pNext = NULL;
6441 ds_pool_ci.maxSets = 5;
6442 ds_pool_ci.poolSizeCount = NUM_DESCRIPTOR_TYPES;
6443 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006444
6445 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006446 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006447 ASSERT_VK_SUCCESS(err);
6448
6449 static const uint32_t MAX_DS_TYPES_IN_LAYOUT = 2;
6450 VkDescriptorSetLayoutBinding dsl_binding[MAX_DS_TYPES_IN_LAYOUT] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006451 dsl_binding[0].binding = 0;
6452 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6453 dsl_binding[0].descriptorCount = 5;
6454 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
6455 dsl_binding[0].pImmutableSamplers = NULL;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006456
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006457 // Create layout identical to set0 layout but w/ different stageFlags
6458 VkDescriptorSetLayoutBinding dsl_fs_stage_only = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006459 dsl_fs_stage_only.binding = 0;
6460 dsl_fs_stage_only.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6461 dsl_fs_stage_only.descriptorCount = 5;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006462 dsl_fs_stage_only.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT; // Different stageFlags to cause error at
6463 // bind time
Karl Schultz6addd812016-02-02 17:17:23 -07006464 dsl_fs_stage_only.pImmutableSamplers = NULL;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006465 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006466 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6467 ds_layout_ci.pNext = NULL;
6468 ds_layout_ci.bindingCount = 1;
6469 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006470 static const uint32_t NUM_LAYOUTS = 4;
6471 VkDescriptorSetLayout ds_layout[NUM_LAYOUTS] = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006472 VkDescriptorSetLayout ds_layout_fs_only = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006473 // Create 4 unique layouts for full pipelineLayout, and 1 special fs-only
6474 // layout for error case
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006475 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[0]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006476 ASSERT_VK_SUCCESS(err);
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07006477 ds_layout_ci.pBindings = &dsl_fs_stage_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006478 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006479 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006480 dsl_binding[0].binding = 0;
6481 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006482 dsl_binding[0].descriptorCount = 2;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07006483 dsl_binding[1].binding = 1;
6484 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
6485 dsl_binding[1].descriptorCount = 2;
6486 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
6487 dsl_binding[1].pImmutableSamplers = NULL;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07006488 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006489 ds_layout_ci.bindingCount = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006490 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[1]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006491 ASSERT_VK_SUCCESS(err);
6492 dsl_binding[0].binding = 0;
6493 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006494 dsl_binding[0].descriptorCount = 5;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006495 ds_layout_ci.bindingCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006496 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[2]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006497 ASSERT_VK_SUCCESS(err);
6498 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006499 dsl_binding[0].descriptorCount = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006500 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[3]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006501 ASSERT_VK_SUCCESS(err);
6502
6503 static const uint32_t NUM_SETS = 4;
6504 VkDescriptorSet descriptorSet[NUM_SETS] = {};
6505 VkDescriptorSetAllocateInfo alloc_info = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006506 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006507 alloc_info.descriptorSetCount = NUM_LAYOUTS;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006508 alloc_info.descriptorPool = ds_pool;
6509 alloc_info.pSetLayouts = ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006510 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptorSet);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006511 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006512 VkDescriptorSet ds0_fs_only = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07006513 alloc_info.descriptorSetCount = 1;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006514 alloc_info.pSetLayouts = &ds_layout_fs_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006515 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &ds0_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006516 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006517
6518 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006519 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6520 pipeline_layout_ci.pNext = NULL;
6521 pipeline_layout_ci.setLayoutCount = NUM_LAYOUTS;
6522 pipeline_layout_ci.pSetLayouts = ds_layout;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006523
6524 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006525 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006526 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006527 // Create pipelineLayout with only one setLayout
6528 pipeline_layout_ci.setLayoutCount = 1;
6529 VkPipelineLayout single_pipe_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006530 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &single_pipe_layout);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006531 ASSERT_VK_SUCCESS(err);
6532 // Create pipelineLayout with 2 descriptor setLayout at index 0
6533 pipeline_layout_ci.pSetLayouts = &ds_layout[3];
6534 VkPipelineLayout pipe_layout_one_desc;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006535 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_one_desc);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006536 ASSERT_VK_SUCCESS(err);
6537 // Create pipelineLayout with 5 SAMPLER descriptor setLayout at index 0
6538 pipeline_layout_ci.pSetLayouts = &ds_layout[2];
6539 VkPipelineLayout pipe_layout_five_samp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006540 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_five_samp);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006541 ASSERT_VK_SUCCESS(err);
6542 // Create pipelineLayout with UB type, but stageFlags for FS only
6543 pipeline_layout_ci.pSetLayouts = &ds_layout_fs_only;
6544 VkPipelineLayout pipe_layout_fs_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006545 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006546 ASSERT_VK_SUCCESS(err);
6547 // Create pipelineLayout w/ incompatible set0 layout, but set1 is fine
6548 VkDescriptorSetLayout pl_bad_s0[2] = {};
6549 pl_bad_s0[0] = ds_layout_fs_only;
6550 pl_bad_s0[1] = ds_layout[1];
6551 pipeline_layout_ci.setLayoutCount = 2;
6552 pipeline_layout_ci.pSetLayouts = pl_bad_s0;
6553 VkPipelineLayout pipe_layout_bad_set0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006554 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_bad_set0);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006555 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006556
6557 // Create a buffer to update the descriptor with
6558 uint32_t qfi = 0;
6559 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006560 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
6561 buffCI.size = 1024;
6562 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
6563 buffCI.queueFamilyIndexCount = 1;
6564 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006565
6566 VkBuffer dyub;
6567 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
6568 ASSERT_VK_SUCCESS(err);
6569 // Correctly update descriptor to avoid "NOT_UPDATED" error
6570 static const uint32_t NUM_BUFFS = 5;
6571 VkDescriptorBufferInfo buffInfo[NUM_BUFFS] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006572 for (uint32_t i = 0; i < NUM_BUFFS; ++i) {
Tobin Ehlis559c6382015-11-05 09:52:49 -07006573 buffInfo[i].buffer = dyub;
6574 buffInfo[i].offset = 0;
6575 buffInfo[i].range = 1024;
6576 }
Karl Schultz6addd812016-02-02 17:17:23 -07006577 VkImage image;
Karl Schultz6addd812016-02-02 17:17:23 -07006578 const int32_t tex_width = 32;
6579 const int32_t tex_height = 32;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006580 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006581 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
6582 image_create_info.pNext = NULL;
6583 image_create_info.imageType = VK_IMAGE_TYPE_2D;
6584 image_create_info.format = tex_format;
6585 image_create_info.extent.width = tex_width;
6586 image_create_info.extent.height = tex_height;
6587 image_create_info.extent.depth = 1;
6588 image_create_info.mipLevels = 1;
6589 image_create_info.arrayLayers = 1;
6590 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyanb8a61002016-06-20 16:00:28 -06006591 image_create_info.tiling = tiling;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006592 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_STORAGE_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -07006593 image_create_info.flags = 0;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006594 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
6595 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006596
Karl Schultz6addd812016-02-02 17:17:23 -07006597 VkMemoryRequirements memReqs;
6598 VkDeviceMemory imageMem;
6599 bool pass;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07006600 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006601 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
6602 memAlloc.pNext = NULL;
6603 memAlloc.allocationSize = 0;
6604 memAlloc.memoryTypeIndex = 0;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07006605 vkGetImageMemoryRequirements(m_device->device(), image, &memReqs);
6606 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006607 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07006608 ASSERT_TRUE(pass);
6609 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &imageMem);
6610 ASSERT_VK_SUCCESS(err);
6611 err = vkBindImageMemory(m_device->device(), image, imageMem, 0);
6612 ASSERT_VK_SUCCESS(err);
6613
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006614 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006615 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
6616 image_view_create_info.image = image;
6617 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
6618 image_view_create_info.format = tex_format;
6619 image_view_create_info.subresourceRange.layerCount = 1;
6620 image_view_create_info.subresourceRange.baseMipLevel = 0;
6621 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006622 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006623
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006624 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006625 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006626 ASSERT_VK_SUCCESS(err);
Tobin Ehlis991d45a2016-01-06 08:48:41 -07006627 VkDescriptorImageInfo imageInfo[4] = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006628 imageInfo[0].imageView = view;
6629 imageInfo[0].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
6630 imageInfo[1].imageView = view;
6631 imageInfo[1].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
Tobin Ehlis991d45a2016-01-06 08:48:41 -07006632 imageInfo[2].imageView = view;
Tobin Ehlisa1fccbc2016-10-10 14:54:43 -06006633 imageInfo[2].imageLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis991d45a2016-01-06 08:48:41 -07006634 imageInfo[3].imageView = view;
Tobin Ehlisa1fccbc2016-10-10 14:54:43 -06006635 imageInfo[3].imageLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006636
6637 static const uint32_t NUM_SET_UPDATES = 3;
6638 VkWriteDescriptorSet descriptor_write[NUM_SET_UPDATES] = {};
6639 descriptor_write[0].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6640 descriptor_write[0].dstSet = descriptorSet[0];
6641 descriptor_write[0].dstBinding = 0;
6642 descriptor_write[0].descriptorCount = 5;
6643 descriptor_write[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6644 descriptor_write[0].pBufferInfo = buffInfo;
6645 descriptor_write[1].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6646 descriptor_write[1].dstSet = descriptorSet[1];
6647 descriptor_write[1].dstBinding = 0;
6648 descriptor_write[1].descriptorCount = 2;
6649 descriptor_write[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
6650 descriptor_write[1].pImageInfo = imageInfo;
6651 descriptor_write[2].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6652 descriptor_write[2].dstSet = descriptorSet[1];
6653 descriptor_write[2].dstBinding = 1;
6654 descriptor_write[2].descriptorCount = 2;
6655 descriptor_write[2].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
Tobin Ehlis991d45a2016-01-06 08:48:41 -07006656 descriptor_write[2].pImageInfo = &imageInfo[2];
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006657
6658 vkUpdateDescriptorSets(m_device->device(), 3, descriptor_write, 0, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006659
Tobin Ehlis88452832015-12-03 09:40:56 -07006660 // Create PSO to be used for draw-time errors below
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006661 char const *vsSource = "#version 450\n"
6662 "\n"
6663 "out gl_PerVertex {\n"
6664 " vec4 gl_Position;\n"
6665 "};\n"
6666 "void main(){\n"
6667 " gl_Position = vec4(1);\n"
6668 "}\n";
6669 char const *fsSource = "#version 450\n"
6670 "\n"
6671 "layout(location=0) out vec4 x;\n"
6672 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
6673 "void main(){\n"
6674 " x = vec4(bar.y);\n"
6675 "}\n";
Tobin Ehlis88452832015-12-03 09:40:56 -07006676 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
6677 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006678 VkPipelineObj pipe(m_device);
6679 pipe.AddShader(&vs);
6680 pipe.AddShader(&fs);
Tobin Ehlis88452832015-12-03 09:40:56 -07006681 pipe.AddColorAttachment();
6682 pipe.CreateVKPipeline(pipe_layout_fs_only, renderPass());
Tobin Ehlis559c6382015-11-05 09:52:49 -07006683
6684 BeginCommandBuffer();
Tobin Ehlis88452832015-12-03 09:40:56 -07006685
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006686 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07006687 // NOTE : I believe LunarG ilo driver has bug (LX#189) that requires binding
6688 // of PSO
6689 // here before binding DSs. Otherwise we assert in cmd_copy_dset_data() of
6690 // cmd_pipeline.c
6691 // due to the fact that cmd_alloc_dset_data() has not been called in
6692 // cmd_bind_graphics_pipeline()
6693 // TODO : Want to cause various binding incompatibility issues here to test
6694 // DrawState
Tobin Ehlis559c6382015-11-05 09:52:49 -07006695 // First cause various verify_layout_compatibility() fails
6696 // Second disturb early and late sets and verify INFO msgs
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006697 // verify_set_layout_compatibility fail cases:
6698 // 1. invalid VkPipelineLayout (layout) passed into vkCmdBindDescriptorSets
Karl Schultzf78bcdd2016-11-30 12:36:01 -07006699 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00981);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006700 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS,
6701 (VkPipelineLayout)((size_t)0xbaadb1be), 0, 1, &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006702 m_errorMonitor->VerifyFound();
6703
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006704 // 2. layoutIndex exceeds # of layouts in layout
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006705 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " attempting to bind set to index 1");
6706 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, single_pipe_layout, 0, 2,
6707 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006708 m_errorMonitor->VerifyFound();
6709
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006710 vkDestroyPipelineLayout(m_device->device(), single_pipe_layout, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07006711 // 3. Pipeline setLayout[0] has 2 descriptors, but set being bound has 5
6712 // descriptors
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006713 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has 2 descriptors, but DescriptorSetLayout ");
6714 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_one_desc, 0, 1,
6715 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006716 m_errorMonitor->VerifyFound();
6717
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006718 vkDestroyPipelineLayout(m_device->device(), pipe_layout_one_desc, NULL);
6719 // 4. same # of descriptors but mismatch in type
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006720 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is type 'VK_DESCRIPTOR_TYPE_SAMPLER' but binding ");
6721 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_five_samp, 0, 1,
6722 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006723 m_errorMonitor->VerifyFound();
6724
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006725 vkDestroyPipelineLayout(m_device->device(), pipe_layout_five_samp, NULL);
6726 // 5. same # of descriptors but mismatch in stageFlags
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006727 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6728 " has stageFlags 16 but binding 0 for DescriptorSetLayout ");
6729 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_fs_only, 0, 1,
6730 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006731 m_errorMonitor->VerifyFound();
6732
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006733 // Cause INFO messages due to disturbing previously bound Sets
6734 // First bind sets 0 & 1
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006735 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
6736 &descriptorSet[0], 0, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006737 // 1. Disturb bound set0 by re-binding set1 w/ updated pipelineLayout
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006738 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, " previously bound as set #0 was disturbed ");
6739 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_bad_set0, 1, 1,
6740 &descriptorSet[1], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006741 m_errorMonitor->VerifyFound();
6742
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006743 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
6744 &descriptorSet[0], 0, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006745 // 2. Disturb set after last bound set
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006746 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, " newly bound as set #0 so set #1 and "
6747 "any subsequent sets were disturbed ");
6748 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_fs_only, 0, 1,
6749 &ds0_fs_only, 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006750 m_errorMonitor->VerifyFound();
6751
Tobin Ehlis10fad692016-07-07 12:00:36 -06006752 // Now that we're done actively using the pipelineLayout that gfx pipeline
6753 // was created with, we should be able to delete it. Do that now to verify
6754 // that validation obeys pipelineLayout lifetime
6755 vkDestroyPipelineLayout(m_device->device(), pipe_layout_fs_only, NULL);
6756
Tobin Ehlis88452832015-12-03 09:40:56 -07006757 // Cause draw-time errors due to PSO incompatibilities
Karl Schultz6addd812016-02-02 17:17:23 -07006758 // 1. Error due to not binding required set (we actually use same code as
6759 // above to disturb set0)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006760 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
6761 &descriptorSet[0], 0, NULL);
6762 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_bad_set0, 1, 1,
6763 &descriptorSet[1], 0, NULL);
6764 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 -07006765 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006766 m_errorMonitor->VerifyFound();
6767
Tobin Ehlis991d45a2016-01-06 08:48:41 -07006768 vkDestroyPipelineLayout(m_device->device(), pipe_layout_bad_set0, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07006769 // 2. Error due to bound set not being compatible with PSO's
6770 // VkPipelineLayout (diff stageFlags in this case)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006771 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
6772 &descriptorSet[0], 0, NULL);
6773 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " bound as set #0 is not compatible with ");
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 Ehlis8fab6562015-12-01 09:57:09 -07006777 // Remaining clean-up
Karl Schultz6addd812016-02-02 17:17:23 -07006778 for (uint32_t i = 0; i < NUM_LAYOUTS; ++i) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006779 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout[i], NULL);
6780 }
6781 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_fs_only, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006782 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006783 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6784 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06006785 vkFreeMemory(m_device->device(), imageMem, NULL);
6786 vkDestroyImage(m_device->device(), image, NULL);
6787 vkDestroyImageView(m_device->device(), view, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006788}
Tobin Ehlis559c6382015-11-05 09:52:49 -07006789
Karl Schultz6addd812016-02-02 17:17:23 -07006790TEST_F(VkLayerTest, NoBeginCommandBuffer) {
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006791
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006792 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6793 "You must call vkBeginCommandBuffer() before this call to ");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006794
6795 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006796 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006797 // Call EndCommandBuffer() w/o calling BeginCommandBuffer()
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006798 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006799
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006800 m_errorMonitor->VerifyFound();
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006801}
6802
Karl Schultz6addd812016-02-02 17:17:23 -07006803TEST_F(VkLayerTest, SecondaryCommandBufferNullRenderpass) {
6804 VkResult err;
6805 VkCommandBuffer draw_cmd;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006806
Karl Schultzf78bcdd2016-11-30 12:36:01 -07006807 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00110);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006808
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006809 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006810
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006811 VkCommandBufferAllocateInfo cmd = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006812 cmd.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06006813 cmd.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006814 cmd.commandPool = m_commandPool;
6815 cmd.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006816 cmd.commandBufferCount = 1;
Cody Northropb4569702015-08-04 17:35:57 -06006817
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006818 err = vkAllocateCommandBuffers(m_device->device(), &cmd, &draw_cmd);
Mike Stroyand1c84a52015-08-18 14:40:24 -06006819 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006820
6821 // Force the failure by not setting the Renderpass and Framebuffer fields
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006822 VkCommandBufferBeginInfo cmd_buf_info = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07006823 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006824 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06006825 cmd_buf_info.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006826 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 -07006827 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006828
6829 // The error should be caught by validation of the BeginCommandBuffer call
6830 vkBeginCommandBuffer(draw_cmd, &cmd_buf_info);
6831
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006832 m_errorMonitor->VerifyFound();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006833 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &draw_cmd);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006834}
6835
Karl Schultz6addd812016-02-02 17:17:23 -07006836TEST_F(VkLayerTest, CommandBufferResetErrors) {
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006837 // Cause error due to Begin while recording CB
6838 // Then cause 2 errors for attempting to reset CB w/o having
6839 // VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT set for the pool from
6840 // which CBs were allocated. Note that this bit is off by default.
Mike Weiblencce7ec72016-10-17 19:33:05 -06006841 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot call Begin on command buffer");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006842
6843 ASSERT_NO_FATAL_FAILURE(InitState());
6844
6845 // Calls AllocateCommandBuffers
6846 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
6847
Karl Schultz6addd812016-02-02 17:17:23 -07006848 // Force the failure by setting the Renderpass and Framebuffer fields with
6849 // (fake) data
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006850 VkCommandBufferBeginInfo cmd_buf_info = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07006851 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006852 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
6853 cmd_buf_info.pNext = NULL;
6854 cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006855 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006856
6857 // Begin CB to transition to recording state
6858 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
6859 // Can't re-begin. This should trigger error
6860 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006861 m_errorMonitor->VerifyFound();
6862
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006863 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to reset command buffer ");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006864 VkCommandBufferResetFlags flags = 0; // Don't care about flags for this test
6865 // Reset attempt will trigger error due to incorrect CommandPool state
6866 vkResetCommandBuffer(commandBuffer.GetBufferHandle(), flags);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006867 m_errorMonitor->VerifyFound();
6868
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006869 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " attempts to implicitly reset cmdBuffer created from ");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006870 // Transition CB to RECORDED state
6871 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
6872 // Now attempting to Begin will implicitly reset, which triggers error
6873 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006874 m_errorMonitor->VerifyFound();
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006875}
6876
Karl Schultz6addd812016-02-02 17:17:23 -07006877TEST_F(VkLayerTest, InvalidPipelineCreateState) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006878 // Attempt to Create Gfx Pipeline w/o a VS
Karl Schultz6addd812016-02-02 17:17:23 -07006879 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006880
Mike Weiblencce7ec72016-10-17 19:33:05 -06006881 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Pipeline CreateInfo State: Vertex Shader required");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006882
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006883 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06006884 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinski209b5292015-09-17 09:44:05 -06006885
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006886 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006887 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6888 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06006889
6890 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006891 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6892 ds_pool_ci.pNext = NULL;
6893 ds_pool_ci.maxSets = 1;
6894 ds_pool_ci.poolSizeCount = 1;
6895 ds_pool_ci.pPoolSizes = &ds_type_count;
Mark Lobodzinski209b5292015-09-17 09:44:05 -06006896
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006897 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006898 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006899 ASSERT_VK_SUCCESS(err);
6900
Tony Barboureb254902015-07-15 12:50:33 -06006901 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006902 dsl_binding.binding = 0;
6903 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6904 dsl_binding.descriptorCount = 1;
6905 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6906 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006907
Tony Barboureb254902015-07-15 12:50:33 -06006908 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006909 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6910 ds_layout_ci.pNext = NULL;
6911 ds_layout_ci.bindingCount = 1;
6912 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06006913
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006914 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006915 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006916 ASSERT_VK_SUCCESS(err);
6917
6918 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006919 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006920 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006921 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06006922 alloc_info.descriptorPool = ds_pool;
6923 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006924 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006925 ASSERT_VK_SUCCESS(err);
6926
Tony Barboureb254902015-07-15 12:50:33 -06006927 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006928 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6929 pipeline_layout_ci.setLayoutCount = 1;
6930 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006931
6932 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006933 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006934 ASSERT_VK_SUCCESS(err);
6935
Tobin Ehlise68360f2015-10-01 11:15:13 -06006936 VkViewport vp = {}; // Just need dummy vp to point to
Karl Schultz6addd812016-02-02 17:17:23 -07006937 VkRect2D sc = {}; // dummy scissor to point to
Tobin Ehlise68360f2015-10-01 11:15:13 -06006938
6939 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006940 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
6941 vp_state_ci.scissorCount = 1;
6942 vp_state_ci.pScissors = &sc;
6943 vp_state_ci.viewportCount = 1;
6944 vp_state_ci.pViewports = &vp;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006945
Karl Schultzdfdb8d42016-03-08 10:30:21 -07006946 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
6947 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
6948 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
6949 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
6950 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
6951 rs_state_ci.depthClampEnable = VK_FALSE;
6952 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
6953 rs_state_ci.depthBiasEnable = VK_FALSE;
6954
Tony Barboureb254902015-07-15 12:50:33 -06006955 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006956 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
6957 gp_ci.pViewportState = &vp_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07006958 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07006959 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
6960 gp_ci.layout = pipeline_layout;
6961 gp_ci.renderPass = renderPass();
Tony Barboureb254902015-07-15 12:50:33 -06006962
6963 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006964 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
6965 pc_ci.initialDataSize = 0;
6966 pc_ci.pInitialData = 0;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006967
6968 VkPipeline pipeline;
Jon Ashburnc669cc62015-07-09 15:02:25 -06006969 VkPipelineCache pipelineCache;
6970
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006971 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Jon Ashburnc669cc62015-07-09 15:02:25 -06006972 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006973 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006974
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006975 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06006976
Chia-I Wuf7458c52015-10-26 21:10:41 +08006977 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
6978 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6979 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6980 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006981}
Tobin Ehlis912df022015-09-17 08:46:18 -06006982/*// TODO : This test should be good, but needs Tess support in compiler to run
6983TEST_F(VkLayerTest, InvalidPatchControlPoints)
6984{
6985 // Attempt to Create Gfx Pipeline w/o a VS
Tobin Ehlis912df022015-09-17 08:46:18 -06006986 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006987
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07006988 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07006989 "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH
6990primitive ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006991
Tobin Ehlis912df022015-09-17 08:46:18 -06006992 ASSERT_NO_FATAL_FAILURE(InitState());
6993 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis912df022015-09-17 08:46:18 -06006994
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006995 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlis912df022015-09-17 08:46:18 -06006996 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08006997 ds_type_count.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06006998
6999 VkDescriptorPoolCreateInfo ds_pool_ci = {};
7000 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7001 ds_pool_ci.pNext = NULL;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007002 ds_pool_ci.poolSizeCount = 1;
7003 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis912df022015-09-17 08:46:18 -06007004
7005 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07007006 err = vkCreateDescriptorPool(m_device->device(),
7007VK_DESCRIPTOR_POOL_USAGE_NON_FREE, 1, &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis912df022015-09-17 08:46:18 -06007008 ASSERT_VK_SUCCESS(err);
7009
7010 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08007011 dsl_binding.binding = 0;
Tobin Ehlis912df022015-09-17 08:46:18 -06007012 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08007013 dsl_binding.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06007014 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7015 dsl_binding.pImmutableSamplers = NULL;
7016
7017 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007018 ds_layout_ci.sType =
7019VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06007020 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007021 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07007022 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis912df022015-09-17 08:46:18 -06007023
7024 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007025 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
7026&ds_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06007027 ASSERT_VK_SUCCESS(err);
7028
7029 VkDescriptorSet descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -07007030 err = vkAllocateDescriptorSets(m_device->device(), ds_pool,
7031VK_DESCRIPTOR_SET_USAGE_NON_FREE, 1, &ds_layout, &descriptorSet);
Tobin Ehlis912df022015-09-17 08:46:18 -06007032 ASSERT_VK_SUCCESS(err);
7033
7034 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007035 pipeline_layout_ci.sType =
7036VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06007037 pipeline_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007038 pipeline_layout_ci.setLayoutCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06007039 pipeline_layout_ci.pSetLayouts = &ds_layout;
7040
7041 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007042 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
7043&pipeline_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06007044 ASSERT_VK_SUCCESS(err);
7045
7046 VkPipelineShaderStageCreateInfo shaderStages[3];
7047 memset(&shaderStages, 0, 3 * sizeof(VkPipelineShaderStageCreateInfo));
7048
Karl Schultz6addd812016-02-02 17:17:23 -07007049 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT,
7050this);
Tobin Ehlis912df022015-09-17 08:46:18 -06007051 // Just using VS txt for Tess shaders as we don't care about functionality
Karl Schultz6addd812016-02-02 17:17:23 -07007052 VkShaderObj
7053tc(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT,
7054this);
7055 VkShaderObj
7056te(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT,
7057this);
Tobin Ehlis912df022015-09-17 08:46:18 -06007058
Karl Schultz6addd812016-02-02 17:17:23 -07007059 shaderStages[0].sType =
7060VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06007061 shaderStages[0].stage = VK_SHADER_STAGE_VERTEX_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06007062 shaderStages[0].shader = vs.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07007063 shaderStages[1].sType =
7064VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06007065 shaderStages[1].stage = VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06007066 shaderStages[1].shader = tc.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07007067 shaderStages[2].sType =
7068VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06007069 shaderStages[2].stage = VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06007070 shaderStages[2].shader = te.handle();
7071
7072 VkPipelineInputAssemblyStateCreateInfo iaCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007073 iaCI.sType =
7074VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
Chia-I Wu515eb8f2015-10-31 00:31:16 +08007075 iaCI.topology = VK_PRIMITIVE_TOPOLOGY_PATCH_LIST;
Tobin Ehlis912df022015-09-17 08:46:18 -06007076
7077 VkPipelineTessellationStateCreateInfo tsCI = {};
7078 tsCI.sType = VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO;
7079 tsCI.patchControlPoints = 0; // This will cause an error
7080
7081 VkGraphicsPipelineCreateInfo gp_ci = {};
7082 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7083 gp_ci.pNext = NULL;
7084 gp_ci.stageCount = 3;
7085 gp_ci.pStages = shaderStages;
7086 gp_ci.pVertexInputState = NULL;
7087 gp_ci.pInputAssemblyState = &iaCI;
7088 gp_ci.pTessellationState = &tsCI;
7089 gp_ci.pViewportState = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007090 gp_ci.pRasterizationState = NULL;
Tobin Ehlis912df022015-09-17 08:46:18 -06007091 gp_ci.pMultisampleState = NULL;
7092 gp_ci.pDepthStencilState = NULL;
7093 gp_ci.pColorBlendState = NULL;
7094 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7095 gp_ci.layout = pipeline_layout;
7096 gp_ci.renderPass = renderPass();
7097
7098 VkPipelineCacheCreateInfo pc_ci = {};
7099 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
7100 pc_ci.pNext = NULL;
7101 pc_ci.initialSize = 0;
7102 pc_ci.initialData = 0;
7103 pc_ci.maxSize = 0;
7104
7105 VkPipeline pipeline;
7106 VkPipelineCache pipelineCache;
7107
Karl Schultz6addd812016-02-02 17:17:23 -07007108 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL,
7109&pipelineCache);
Tobin Ehlis912df022015-09-17 08:46:18 -06007110 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07007111 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
7112&gp_ci, NULL, &pipeline);
Tobin Ehlis912df022015-09-17 08:46:18 -06007113
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007114 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06007115
Chia-I Wuf7458c52015-10-26 21:10:41 +08007116 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7117 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7118 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7119 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis912df022015-09-17 08:46:18 -06007120}
7121*/
Tobin Ehlise68360f2015-10-01 11:15:13 -06007122// Set scissor and viewport counts to different numbers
Karl Schultz6addd812016-02-02 17:17:23 -07007123TEST_F(VkLayerTest, PSOViewportScissorCountMismatch) {
Karl Schultz6addd812016-02-02 17:17:23 -07007124 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007125
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007126 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7127 "Gfx Pipeline viewport count (1) must match scissor count (0).");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007128
Tobin Ehlise68360f2015-10-01 11:15:13 -06007129 ASSERT_NO_FATAL_FAILURE(InitState());
7130 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06007131
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007132 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007133 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7134 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007135
7136 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007137 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7138 ds_pool_ci.maxSets = 1;
7139 ds_pool_ci.poolSizeCount = 1;
7140 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007141
7142 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007143 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007144 ASSERT_VK_SUCCESS(err);
7145
7146 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007147 dsl_binding.binding = 0;
7148 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7149 dsl_binding.descriptorCount = 1;
7150 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007151
7152 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007153 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7154 ds_layout_ci.bindingCount = 1;
7155 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007156
7157 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007158 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007159 ASSERT_VK_SUCCESS(err);
7160
7161 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007162 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007163 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007164 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007165 alloc_info.descriptorPool = ds_pool;
7166 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007167 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007168 ASSERT_VK_SUCCESS(err);
7169
7170 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007171 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7172 pipeline_layout_ci.setLayoutCount = 1;
7173 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007174
7175 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007176 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007177 ASSERT_VK_SUCCESS(err);
7178
7179 VkViewport vp = {}; // Just need dummy vp to point to
7180
7181 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007182 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
7183 vp_state_ci.scissorCount = 0;
7184 vp_state_ci.viewportCount = 1; // Count mismatch should cause error
7185 vp_state_ci.pViewports = &vp;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007186
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007187 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
7188 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7189 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
7190 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
7191 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
7192 rs_state_ci.depthClampEnable = VK_FALSE;
7193 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
7194 rs_state_ci.depthBiasEnable = VK_FALSE;
7195
Cody Northropeb3a6c12015-10-05 14:44:45 -06007196 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07007197 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06007198
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007199 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
7200 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
7201 // but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08007202 shaderStages[0] = vs.GetStageCreateInfo();
7203 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007204
7205 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007206 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7207 gp_ci.stageCount = 2;
7208 gp_ci.pStages = shaderStages;
7209 gp_ci.pViewportState = &vp_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007210 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007211 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7212 gp_ci.layout = pipeline_layout;
7213 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007214
7215 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007216 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007217
7218 VkPipeline pipeline;
7219 VkPipelineCache pipelineCache;
7220
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007221 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007222 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007223 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007224
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007225 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007226
Chia-I Wuf7458c52015-10-26 21:10:41 +08007227 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7228 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7229 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7230 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007231}
Karl Schultz6addd812016-02-02 17:17:23 -07007232// Don't set viewport state in PSO. This is an error b/c we always need this
7233// state
Tobin Ehlisd332f282015-10-02 11:00:56 -06007234// for the counts even if the data is going to be set dynamically.
Karl Schultz6addd812016-02-02 17:17:23 -07007235TEST_F(VkLayerTest, PSOViewportStateNotSet) {
Tobin Ehlise68360f2015-10-01 11:15:13 -06007236 // Attempt to Create Gfx Pipeline w/o a VS
Karl Schultz6addd812016-02-02 17:17:23 -07007237 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007238
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007239 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Gfx Pipeline pViewportState is null. Even if ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007240
Tobin Ehlise68360f2015-10-01 11:15:13 -06007241 ASSERT_NO_FATAL_FAILURE(InitState());
7242 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06007243
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007244 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007245 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7246 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007247
7248 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007249 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7250 ds_pool_ci.maxSets = 1;
7251 ds_pool_ci.poolSizeCount = 1;
7252 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007253
7254 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007255 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007256 ASSERT_VK_SUCCESS(err);
7257
7258 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007259 dsl_binding.binding = 0;
7260 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7261 dsl_binding.descriptorCount = 1;
7262 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007263
7264 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007265 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7266 ds_layout_ci.bindingCount = 1;
7267 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007268
7269 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007270 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007271 ASSERT_VK_SUCCESS(err);
7272
7273 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007274 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007275 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007276 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007277 alloc_info.descriptorPool = ds_pool;
7278 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007279 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007280 ASSERT_VK_SUCCESS(err);
7281
7282 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007283 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7284 pipeline_layout_ci.setLayoutCount = 1;
7285 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007286
7287 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007288 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007289 ASSERT_VK_SUCCESS(err);
7290
7291 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
7292 // Set scissor as dynamic to avoid second error
7293 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007294 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
7295 dyn_state_ci.dynamicStateCount = 1;
7296 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007297
Cody Northropeb3a6c12015-10-05 14:44:45 -06007298 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07007299 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06007300
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007301 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
7302 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
7303 // but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08007304 shaderStages[0] = vs.GetStageCreateInfo();
7305 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007306
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007307 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
7308 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7309 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
7310 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
7311 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
7312 rs_state_ci.depthClampEnable = VK_FALSE;
7313 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
7314 rs_state_ci.depthBiasEnable = VK_FALSE;
7315
Tobin Ehlise68360f2015-10-01 11:15:13 -06007316 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007317 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7318 gp_ci.stageCount = 2;
7319 gp_ci.pStages = shaderStages;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007320 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007321 gp_ci.pViewportState = NULL; // Not setting VP state w/o dynamic vp state
7322 // should cause validation error
7323 gp_ci.pDynamicState = &dyn_state_ci;
7324 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7325 gp_ci.layout = pipeline_layout;
7326 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007327
7328 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007329 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007330
7331 VkPipeline pipeline;
7332 VkPipelineCache pipelineCache;
7333
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007334 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007335 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007336 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007337
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007338 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007339
Chia-I Wuf7458c52015-10-26 21:10:41 +08007340 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7341 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7342 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7343 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007344}
7345// Create PSO w/o non-zero viewportCount but no viewport data
Karl Schultz6addd812016-02-02 17:17:23 -07007346// Then run second test where dynamic scissor count doesn't match PSO scissor
7347// count
7348TEST_F(VkLayerTest, PSOViewportCountWithoutDataAndDynScissorMismatch) {
7349 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007350
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007351 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7352 "Gfx Pipeline viewportCount is 1, but pViewports is NULL. ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007353
Tobin Ehlise68360f2015-10-01 11:15:13 -06007354 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007355
7356 if (!m_device->phy().features().multiViewport) {
7357 printf("Device does not support multiple viewports/scissors; skipped.\n");
7358 return;
7359 }
7360
Tobin Ehlise68360f2015-10-01 11:15:13 -06007361 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06007362
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007363 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007364 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7365 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007366
7367 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007368 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7369 ds_pool_ci.maxSets = 1;
7370 ds_pool_ci.poolSizeCount = 1;
7371 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007372
7373 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007374 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007375 ASSERT_VK_SUCCESS(err);
7376
7377 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007378 dsl_binding.binding = 0;
7379 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7380 dsl_binding.descriptorCount = 1;
7381 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007382
7383 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007384 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7385 ds_layout_ci.bindingCount = 1;
7386 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007387
7388 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007389 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007390 ASSERT_VK_SUCCESS(err);
7391
7392 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007393 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007394 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007395 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007396 alloc_info.descriptorPool = ds_pool;
7397 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007398 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007399 ASSERT_VK_SUCCESS(err);
7400
7401 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007402 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7403 pipeline_layout_ci.setLayoutCount = 1;
7404 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007405
7406 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007407 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007408 ASSERT_VK_SUCCESS(err);
7409
7410 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007411 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
7412 vp_state_ci.viewportCount = 1;
7413 vp_state_ci.pViewports = NULL; // Null vp w/ count of 1 should cause error
7414 vp_state_ci.scissorCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007415 vp_state_ci.pScissors = NULL; // Scissor is dynamic (below) so this won't cause error
Tobin Ehlise68360f2015-10-01 11:15:13 -06007416
7417 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
7418 // Set scissor as dynamic to avoid that error
7419 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007420 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
7421 dyn_state_ci.dynamicStateCount = 1;
7422 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007423
Cody Northropeb3a6c12015-10-05 14:44:45 -06007424 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07007425 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06007426
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007427 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
7428 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
7429 // but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08007430 shaderStages[0] = vs.GetStageCreateInfo();
7431 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007432
Cody Northropf6622dc2015-10-06 10:33:21 -06007433 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7434 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7435 vi_ci.pNext = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007436 vi_ci.vertexBindingDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06007437 vi_ci.pVertexBindingDescriptions = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007438 vi_ci.vertexAttributeDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06007439 vi_ci.pVertexAttributeDescriptions = nullptr;
7440
7441 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7442 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7443 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7444
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007445 VkPipelineRasterizationStateCreateInfo rs_ci = {};
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007446 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Cody Northropf6622dc2015-10-06 10:33:21 -06007447 rs_ci.pNext = nullptr;
7448
Mark Youngc89c6312016-03-31 16:03:20 -06007449 VkPipelineColorBlendAttachmentState att = {};
7450 att.blendEnable = VK_FALSE;
7451 att.colorWriteMask = 0xf;
7452
Cody Northropf6622dc2015-10-06 10:33:21 -06007453 VkPipelineColorBlendStateCreateInfo cb_ci = {};
7454 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
7455 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06007456 cb_ci.attachmentCount = 1;
7457 cb_ci.pAttachments = &att;
Cody Northropf6622dc2015-10-06 10:33:21 -06007458
Tobin Ehlise68360f2015-10-01 11:15:13 -06007459 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007460 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7461 gp_ci.stageCount = 2;
7462 gp_ci.pStages = shaderStages;
7463 gp_ci.pVertexInputState = &vi_ci;
7464 gp_ci.pInputAssemblyState = &ia_ci;
7465 gp_ci.pViewportState = &vp_state_ci;
7466 gp_ci.pRasterizationState = &rs_ci;
7467 gp_ci.pColorBlendState = &cb_ci;
7468 gp_ci.pDynamicState = &dyn_state_ci;
7469 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7470 gp_ci.layout = pipeline_layout;
7471 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007472
7473 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007474 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007475
7476 VkPipeline pipeline;
7477 VkPipelineCache pipelineCache;
7478
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007479 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007480 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007481 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007482
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007483 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007484
Tobin Ehlisd332f282015-10-02 11:00:56 -06007485 // Now hit second fail case where we set scissor w/ different count than PSO
Karl Schultz6addd812016-02-02 17:17:23 -07007486 // First need to successfully create the PSO from above by setting
7487 // pViewports
Mike Weiblen95dd0f92016-10-19 12:28:27 -06007488 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 -07007489
7490 VkViewport vp = {}; // Just need dummy vp to point to
7491 vp_state_ci.pViewports = &vp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007492 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Karl Schultz6addd812016-02-02 17:17:23 -07007493 ASSERT_VK_SUCCESS(err);
7494 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007495 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007496 VkRect2D scissors[1] = {}; // don't care about data
Karl Schultz6addd812016-02-02 17:17:23 -07007497 // Count of 2 doesn't match PSO count of 1
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007498 vkCmdSetScissor(m_commandBuffer->GetBufferHandle(), 1, 1, scissors);
Karl Schultz6addd812016-02-02 17:17:23 -07007499 Draw(1, 0, 0, 0);
7500
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007501 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07007502
7503 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7504 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7505 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7506 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06007507 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07007508}
7509// Create PSO w/o non-zero scissorCount but no scissor data
7510// Then run second test where dynamic viewportCount doesn't match PSO
7511// viewportCount
7512TEST_F(VkLayerTest, PSOScissorCountWithoutDataAndDynViewportMismatch) {
7513 VkResult err;
7514
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007515 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Gfx Pipeline scissorCount is 1, but pScissors is NULL. ");
Karl Schultz6addd812016-02-02 17:17:23 -07007516
7517 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007518
7519 if (!m_device->phy().features().multiViewport) {
7520 printf("Device does not support multiple viewports/scissors; skipped.\n");
7521 return;
7522 }
7523
Karl Schultz6addd812016-02-02 17:17:23 -07007524 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7525
7526 VkDescriptorPoolSize ds_type_count = {};
7527 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7528 ds_type_count.descriptorCount = 1;
7529
7530 VkDescriptorPoolCreateInfo ds_pool_ci = {};
7531 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7532 ds_pool_ci.maxSets = 1;
7533 ds_pool_ci.poolSizeCount = 1;
7534 ds_pool_ci.pPoolSizes = &ds_type_count;
7535
7536 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007537 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Karl Schultz6addd812016-02-02 17:17:23 -07007538 ASSERT_VK_SUCCESS(err);
7539
7540 VkDescriptorSetLayoutBinding dsl_binding = {};
7541 dsl_binding.binding = 0;
7542 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7543 dsl_binding.descriptorCount = 1;
7544 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7545
7546 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
7547 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7548 ds_layout_ci.bindingCount = 1;
7549 ds_layout_ci.pBindings = &dsl_binding;
7550
7551 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007552 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Karl Schultz6addd812016-02-02 17:17:23 -07007553 ASSERT_VK_SUCCESS(err);
7554
7555 VkDescriptorSet descriptorSet;
7556 VkDescriptorSetAllocateInfo alloc_info = {};
7557 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
7558 alloc_info.descriptorSetCount = 1;
7559 alloc_info.descriptorPool = ds_pool;
7560 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007561 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Karl Schultz6addd812016-02-02 17:17:23 -07007562 ASSERT_VK_SUCCESS(err);
7563
7564 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
7565 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7566 pipeline_layout_ci.setLayoutCount = 1;
7567 pipeline_layout_ci.pSetLayouts = &ds_layout;
7568
7569 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007570 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultz6addd812016-02-02 17:17:23 -07007571 ASSERT_VK_SUCCESS(err);
7572
7573 VkPipelineViewportStateCreateInfo vp_state_ci = {};
7574 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
7575 vp_state_ci.scissorCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007576 vp_state_ci.pScissors = NULL; // Null scissor w/ count of 1 should cause error
Karl Schultz6addd812016-02-02 17:17:23 -07007577 vp_state_ci.viewportCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007578 vp_state_ci.pViewports = NULL; // vp is dynamic (below) so this won't cause error
Karl Schultz6addd812016-02-02 17:17:23 -07007579
7580 VkDynamicState vp_state = VK_DYNAMIC_STATE_VIEWPORT;
7581 // Set scissor as dynamic to avoid that error
7582 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
7583 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
7584 dyn_state_ci.dynamicStateCount = 1;
7585 dyn_state_ci.pDynamicStates = &vp_state;
7586
7587 VkPipelineShaderStageCreateInfo shaderStages[2];
7588 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
7589
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007590 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
7591 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
7592 // but add it to be able to run on more devices
Karl Schultz6addd812016-02-02 17:17:23 -07007593 shaderStages[0] = vs.GetStageCreateInfo();
7594 shaderStages[1] = fs.GetStageCreateInfo();
7595
7596 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7597 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7598 vi_ci.pNext = nullptr;
7599 vi_ci.vertexBindingDescriptionCount = 0;
7600 vi_ci.pVertexBindingDescriptions = nullptr;
7601 vi_ci.vertexAttributeDescriptionCount = 0;
7602 vi_ci.pVertexAttributeDescriptions = nullptr;
7603
7604 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7605 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7606 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7607
7608 VkPipelineRasterizationStateCreateInfo rs_ci = {};
7609 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7610 rs_ci.pNext = nullptr;
7611
Mark Youngc89c6312016-03-31 16:03:20 -06007612 VkPipelineColorBlendAttachmentState att = {};
7613 att.blendEnable = VK_FALSE;
7614 att.colorWriteMask = 0xf;
7615
Karl Schultz6addd812016-02-02 17:17:23 -07007616 VkPipelineColorBlendStateCreateInfo cb_ci = {};
7617 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
7618 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06007619 cb_ci.attachmentCount = 1;
7620 cb_ci.pAttachments = &att;
Karl Schultz6addd812016-02-02 17:17:23 -07007621
7622 VkGraphicsPipelineCreateInfo gp_ci = {};
7623 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7624 gp_ci.stageCount = 2;
7625 gp_ci.pStages = shaderStages;
7626 gp_ci.pVertexInputState = &vi_ci;
7627 gp_ci.pInputAssemblyState = &ia_ci;
7628 gp_ci.pViewportState = &vp_state_ci;
7629 gp_ci.pRasterizationState = &rs_ci;
7630 gp_ci.pColorBlendState = &cb_ci;
7631 gp_ci.pDynamicState = &dyn_state_ci;
7632 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7633 gp_ci.layout = pipeline_layout;
7634 gp_ci.renderPass = renderPass();
7635
7636 VkPipelineCacheCreateInfo pc_ci = {};
7637 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
7638
7639 VkPipeline pipeline;
7640 VkPipelineCache pipelineCache;
7641
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007642 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Karl Schultz6addd812016-02-02 17:17:23 -07007643 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007644 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Karl Schultz6addd812016-02-02 17:17:23 -07007645
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007646 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07007647
7648 // Now hit second fail case where we set scissor w/ different count than PSO
7649 // First need to successfully create the PSO from above by setting
7650 // pViewports
Mike Weiblen95dd0f92016-10-19 12:28:27 -06007651 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 -06007652
Tobin Ehlisd332f282015-10-02 11:00:56 -06007653 VkRect2D sc = {}; // Just need dummy vp to point to
7654 vp_state_ci.pScissors = &sc;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007655 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlisd332f282015-10-02 11:00:56 -06007656 ASSERT_VK_SUCCESS(err);
7657 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007658 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007659 VkViewport viewports[1] = {}; // don't care about data
Tobin Ehlisd332f282015-10-02 11:00:56 -06007660 // Count of 2 doesn't match PSO count of 1
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007661 vkCmdSetViewport(m_commandBuffer->GetBufferHandle(), 1, 1, viewports);
Tobin Ehlisd332f282015-10-02 11:00:56 -06007662 Draw(1, 0, 0, 0);
7663
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007664 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007665
Chia-I Wuf7458c52015-10-26 21:10:41 +08007666 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7667 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7668 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7669 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06007670 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007671}
7672
Mark Young7394fdd2016-03-31 14:56:43 -06007673TEST_F(VkLayerTest, PSOLineWidthInvalid) {
7674 VkResult err;
7675
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007676 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to -1");
Mark Young7394fdd2016-03-31 14:56:43 -06007677
7678 ASSERT_NO_FATAL_FAILURE(InitState());
7679 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7680
7681 VkDescriptorPoolSize ds_type_count = {};
7682 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7683 ds_type_count.descriptorCount = 1;
7684
7685 VkDescriptorPoolCreateInfo ds_pool_ci = {};
7686 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7687 ds_pool_ci.maxSets = 1;
7688 ds_pool_ci.poolSizeCount = 1;
7689 ds_pool_ci.pPoolSizes = &ds_type_count;
7690
7691 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007692 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Mark Young7394fdd2016-03-31 14:56:43 -06007693 ASSERT_VK_SUCCESS(err);
7694
7695 VkDescriptorSetLayoutBinding dsl_binding = {};
7696 dsl_binding.binding = 0;
7697 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7698 dsl_binding.descriptorCount = 1;
7699 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7700
7701 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
7702 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7703 ds_layout_ci.bindingCount = 1;
7704 ds_layout_ci.pBindings = &dsl_binding;
7705
7706 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007707 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Young7394fdd2016-03-31 14:56:43 -06007708 ASSERT_VK_SUCCESS(err);
7709
7710 VkDescriptorSet descriptorSet;
7711 VkDescriptorSetAllocateInfo alloc_info = {};
7712 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
7713 alloc_info.descriptorSetCount = 1;
7714 alloc_info.descriptorPool = ds_pool;
7715 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007716 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Young7394fdd2016-03-31 14:56:43 -06007717 ASSERT_VK_SUCCESS(err);
7718
7719 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
7720 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7721 pipeline_layout_ci.setLayoutCount = 1;
7722 pipeline_layout_ci.pSetLayouts = &ds_layout;
7723
7724 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007725 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Mark Young7394fdd2016-03-31 14:56:43 -06007726 ASSERT_VK_SUCCESS(err);
7727
7728 VkPipelineViewportStateCreateInfo vp_state_ci = {};
7729 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
7730 vp_state_ci.scissorCount = 1;
7731 vp_state_ci.pScissors = NULL;
7732 vp_state_ci.viewportCount = 1;
7733 vp_state_ci.pViewports = NULL;
7734
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007735 VkDynamicState dynamic_states[3] = {VK_DYNAMIC_STATE_VIEWPORT, VK_DYNAMIC_STATE_SCISSOR, VK_DYNAMIC_STATE_LINE_WIDTH};
Mark Young7394fdd2016-03-31 14:56:43 -06007736 // Set scissor as dynamic to avoid that error
7737 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
7738 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
7739 dyn_state_ci.dynamicStateCount = 2;
7740 dyn_state_ci.pDynamicStates = dynamic_states;
7741
7742 VkPipelineShaderStageCreateInfo shaderStages[2];
7743 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
7744
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007745 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
7746 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT,
Mark Young7394fdd2016-03-31 14:56:43 -06007747 this); // TODO - We shouldn't need a fragment shader
7748 // but add it to be able to run on more devices
7749 shaderStages[0] = vs.GetStageCreateInfo();
7750 shaderStages[1] = fs.GetStageCreateInfo();
7751
7752 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7753 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7754 vi_ci.pNext = nullptr;
7755 vi_ci.vertexBindingDescriptionCount = 0;
7756 vi_ci.pVertexBindingDescriptions = nullptr;
7757 vi_ci.vertexAttributeDescriptionCount = 0;
7758 vi_ci.pVertexAttributeDescriptions = nullptr;
7759
7760 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7761 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7762 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7763
7764 VkPipelineRasterizationStateCreateInfo rs_ci = {};
7765 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7766 rs_ci.pNext = nullptr;
7767
Mark Young47107952016-05-02 15:59:55 -06007768 // Check too low (line width of -1.0f).
7769 rs_ci.lineWidth = -1.0f;
Mark Young7394fdd2016-03-31 14:56:43 -06007770
7771 VkPipelineColorBlendAttachmentState att = {};
7772 att.blendEnable = VK_FALSE;
7773 att.colorWriteMask = 0xf;
7774
7775 VkPipelineColorBlendStateCreateInfo cb_ci = {};
7776 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
7777 cb_ci.pNext = nullptr;
7778 cb_ci.attachmentCount = 1;
7779 cb_ci.pAttachments = &att;
7780
7781 VkGraphicsPipelineCreateInfo gp_ci = {};
7782 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7783 gp_ci.stageCount = 2;
7784 gp_ci.pStages = shaderStages;
7785 gp_ci.pVertexInputState = &vi_ci;
7786 gp_ci.pInputAssemblyState = &ia_ci;
7787 gp_ci.pViewportState = &vp_state_ci;
7788 gp_ci.pRasterizationState = &rs_ci;
7789 gp_ci.pColorBlendState = &cb_ci;
7790 gp_ci.pDynamicState = &dyn_state_ci;
7791 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7792 gp_ci.layout = pipeline_layout;
7793 gp_ci.renderPass = renderPass();
7794
7795 VkPipelineCacheCreateInfo pc_ci = {};
7796 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
7797
7798 VkPipeline pipeline;
7799 VkPipelineCache pipelineCache;
7800
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007801 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06007802 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007803 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06007804
7805 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06007806 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06007807
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007808 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to 65536");
Mark Young7394fdd2016-03-31 14:56:43 -06007809
7810 // Check too high (line width of 65536.0f).
7811 rs_ci.lineWidth = 65536.0f;
7812
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007813 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06007814 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007815 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06007816
7817 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06007818 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06007819
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007820 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to -1");
Mark Young7394fdd2016-03-31 14:56:43 -06007821
7822 dyn_state_ci.dynamicStateCount = 3;
7823
7824 rs_ci.lineWidth = 1.0f;
7825
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007826 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06007827 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007828 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06007829 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007830 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06007831
7832 // Check too low with dynamic setting.
Mark Young47107952016-05-02 15:59:55 -06007833 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), -1.0f);
Mark Young7394fdd2016-03-31 14:56:43 -06007834 m_errorMonitor->VerifyFound();
7835
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007836 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to 65536");
Mark Young7394fdd2016-03-31 14:56:43 -06007837
7838 // Check too high with dynamic setting.
7839 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), 65536.0f);
7840 m_errorMonitor->VerifyFound();
7841 EndCommandBuffer();
7842
7843 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7844 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7845 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7846 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06007847 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06007848}
7849
Karl Schultz6addd812016-02-02 17:17:23 -07007850TEST_F(VkLayerTest, NullRenderPass) {
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007851 // Bind a NULL RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007852 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7853 "You cannot use a NULL RenderPass object in vkCmdBeginRenderPass()");
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007854
7855 ASSERT_NO_FATAL_FAILURE(InitState());
7856 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007857
Tony Barbourfe3351b2015-07-28 10:17:20 -06007858 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07007859 // Don't care about RenderPass handle b/c error should be flagged before
7860 // that
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007861 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), NULL, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007862
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007863 m_errorMonitor->VerifyFound();
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007864}
7865
Karl Schultz6addd812016-02-02 17:17:23 -07007866TEST_F(VkLayerTest, RenderPassWithinRenderPass) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007867 // Bind a BeginRenderPass within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007868 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7869 "It is invalid to issue this call inside an active render pass");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007870
7871 ASSERT_NO_FATAL_FAILURE(InitState());
7872 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007873
Tony Barbourfe3351b2015-07-28 10:17:20 -06007874 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07007875 // Just create a dummy Renderpass that's non-NULL so we can get to the
7876 // proper error
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007877 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007878
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007879 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06007880}
7881
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06007882TEST_F(VkLayerTest, RenderPassClearOpMismatch) {
7883 TEST_DESCRIPTION("Begin a renderPass where clearValueCount is less than"
7884 "the number of renderPass attachments that use loadOp"
7885 "VK_ATTACHMENT_LOAD_OP_CLEAR.");
7886
7887 ASSERT_NO_FATAL_FAILURE(InitState());
7888 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7889
7890 // Create a renderPass with a single attachment that uses loadOp CLEAR
7891 VkAttachmentReference attach = {};
7892 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
7893 VkSubpassDescription subpass = {};
7894 subpass.inputAttachmentCount = 1;
7895 subpass.pInputAttachments = &attach;
7896 VkRenderPassCreateInfo rpci = {};
7897 rpci.subpassCount = 1;
7898 rpci.pSubpasses = &subpass;
7899 rpci.attachmentCount = 1;
7900 VkAttachmentDescription attach_desc = {};
7901 attach_desc.format = VK_FORMAT_UNDEFINED;
7902 // Set loadOp to CLEAR
7903 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
7904 rpci.pAttachments = &attach_desc;
7905 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
7906 VkRenderPass rp;
7907 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
7908
7909 VkCommandBufferInheritanceInfo hinfo = {};
7910 hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
7911 hinfo.renderPass = VK_NULL_HANDLE;
7912 hinfo.subpass = 0;
7913 hinfo.framebuffer = VK_NULL_HANDLE;
7914 hinfo.occlusionQueryEnable = VK_FALSE;
7915 hinfo.queryFlags = 0;
7916 hinfo.pipelineStatistics = 0;
7917 VkCommandBufferBeginInfo info = {};
7918 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
7919 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
7920 info.pInheritanceInfo = &hinfo;
7921
7922 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
7923 VkRenderPassBeginInfo rp_begin = {};
7924 rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
7925 rp_begin.pNext = NULL;
7926 rp_begin.renderPass = renderPass();
7927 rp_begin.framebuffer = framebuffer();
7928 rp_begin.clearValueCount = 0; // Should be 1
7929
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007930 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has a clearValueCount of 0 but "
7931 "there must be at least 1 entries in "
7932 "pClearValues array to account for ");
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06007933
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007934 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rp_begin, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06007935
7936 m_errorMonitor->VerifyFound();
Mark Lobodzinski5c70ebd2016-06-09 13:45:00 -06007937
7938 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06007939}
7940
Slawomir Cygan0808f392016-11-28 17:53:23 +01007941TEST_F(VkLayerTest, RenderPassClearOpTooManyValues) {
7942 TEST_DESCRIPTION("Begin a renderPass where clearValueCount is greater than"
7943 "the number of renderPass attachments that use loadOp"
7944 "VK_ATTACHMENT_LOAD_OP_CLEAR.");
7945
7946 ASSERT_NO_FATAL_FAILURE(InitState());
7947 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7948
7949 // Create a renderPass with a single attachment that uses loadOp CLEAR
7950 VkAttachmentReference attach = {};
7951 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
7952 VkSubpassDescription subpass = {};
7953 subpass.inputAttachmentCount = 1;
7954 subpass.pInputAttachments = &attach;
7955 VkRenderPassCreateInfo rpci = {};
7956 rpci.subpassCount = 1;
7957 rpci.pSubpasses = &subpass;
7958 rpci.attachmentCount = 1;
7959 VkAttachmentDescription attach_desc = {};
7960 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
7961 // Set loadOp to CLEAR
7962 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
7963 rpci.pAttachments = &attach_desc;
7964 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
7965 VkRenderPass rp;
7966 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
7967
7968 VkCommandBufferBeginInfo info = {};
7969 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
7970 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
7971
7972 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
7973 VkRenderPassBeginInfo rp_begin = {};
7974 rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
7975 rp_begin.pNext = NULL;
7976 rp_begin.renderPass = renderPass();
7977 rp_begin.framebuffer = framebuffer();
7978 rp_begin.clearValueCount = 2; // Should be 1
7979
7980 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, " has a clearValueCount of"
7981 " 2 but only first 1 entries in pClearValues array are used");
7982
7983 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rp_begin, VK_SUBPASS_CONTENTS_INLINE);
7984
7985 m_errorMonitor->VerifyFound();
7986
7987 vkDestroyRenderPass(m_device->device(), rp, NULL);
7988}
7989
7990
Cody Northrop3bb4d962016-05-09 16:15:57 -06007991TEST_F(VkLayerTest, EndCommandBufferWithinRenderPass) {
7992
7993 TEST_DESCRIPTION("End a command buffer with an active render pass");
7994
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007995 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7996 "It is invalid to issue this call inside an active render pass");
Cody Northrop3bb4d962016-05-09 16:15:57 -06007997
7998 ASSERT_NO_FATAL_FAILURE(InitState());
7999 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8000
8001 // The framework's BeginCommandBuffer calls CreateRenderPass
8002 BeginCommandBuffer();
8003
8004 // Call directly into vkEndCommandBuffer instead of the
8005 // the framework's EndCommandBuffer, which inserts a
8006 // vkEndRenderPass
8007 vkEndCommandBuffer(m_commandBuffer->GetBufferHandle());
8008
8009 m_errorMonitor->VerifyFound();
8010
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008011 // TODO: Add test for VK_COMMAND_BUFFER_LEVEL_SECONDARY
8012 // TODO: Add test for VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT
Cody Northrop3bb4d962016-05-09 16:15:57 -06008013}
8014
Karl Schultz6addd812016-02-02 17:17:23 -07008015TEST_F(VkLayerTest, FillBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008016 // Call CmdFillBuffer within an active renderpass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008017 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8018 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008019
8020 ASSERT_NO_FATAL_FAILURE(InitState());
8021 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008022
8023 // Renderpass is started here
8024 BeginCommandBuffer();
8025
8026 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008027 vk_testing::Buffer dstBuffer;
8028 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008029
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008030 m_commandBuffer->FillBuffer(dstBuffer.handle(), 0, 4, 0x11111111);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008031
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008032 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008033}
8034
Karl Schultz6addd812016-02-02 17:17:23 -07008035TEST_F(VkLayerTest, UpdateBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008036 // Call CmdUpdateBuffer within an active renderpass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008037 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8038 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008039
8040 ASSERT_NO_FATAL_FAILURE(InitState());
8041 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008042
8043 // Renderpass is started here
8044 BeginCommandBuffer();
8045
8046 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008047 vk_testing::Buffer dstBuffer;
8048 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008049
Karl Schultz6addd812016-02-02 17:17:23 -07008050 VkDeviceSize dstOffset = 0;
8051 VkDeviceSize dataSize = 1024;
Karl Schultzee344492016-07-11 15:09:57 -06008052 const void *pData = NULL;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008053
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008054 vkCmdUpdateBuffer(m_commandBuffer->GetBufferHandle(), dstBuffer.handle(), dstOffset, dataSize, pData);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008055
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008056 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008057}
8058
Karl Schultz6addd812016-02-02 17:17:23 -07008059TEST_F(VkLayerTest, ClearColorImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008060 // Call CmdClearColorImage within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008061 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8062 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008063
8064 ASSERT_NO_FATAL_FAILURE(InitState());
8065 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008066
8067 // Renderpass is started here
8068 BeginCommandBuffer();
8069
Michael Lentine0a369f62016-02-03 16:51:46 -06008070 VkClearColorValue clear_color;
8071 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
Karl Schultz6addd812016-02-02 17:17:23 -07008072 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
8073 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
8074 const int32_t tex_width = 32;
8075 const int32_t tex_height = 32;
8076 VkImageCreateInfo image_create_info = {};
8077 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
8078 image_create_info.pNext = NULL;
8079 image_create_info.imageType = VK_IMAGE_TYPE_2D;
8080 image_create_info.format = tex_format;
8081 image_create_info.extent.width = tex_width;
8082 image_create_info.extent.height = tex_height;
8083 image_create_info.extent.depth = 1;
8084 image_create_info.mipLevels = 1;
8085 image_create_info.arrayLayers = 1;
8086 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
8087 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
8088 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008089
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008090 vk_testing::Image dstImage;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008091 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008092
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008093 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008094
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008095 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1, &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008096
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008097 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008098}
8099
Karl Schultz6addd812016-02-02 17:17:23 -07008100TEST_F(VkLayerTest, ClearDepthStencilImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008101 // Call CmdClearDepthStencilImage within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008102 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8103 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008104
8105 ASSERT_NO_FATAL_FAILURE(InitState());
8106 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008107
8108 // Renderpass is started here
8109 BeginCommandBuffer();
8110
8111 VkClearDepthStencilValue clear_value = {0};
Dustin Gravesa2e5c942016-02-11 18:28:06 -07008112 VkMemoryPropertyFlags reqs = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07008113 VkImageCreateInfo image_create_info = vk_testing::Image::create_info();
8114 image_create_info.imageType = VK_IMAGE_TYPE_2D;
8115 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
8116 image_create_info.extent.width = 64;
8117 image_create_info.extent.height = 64;
8118 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
8119 image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008120
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008121 vk_testing::Image dstImage;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008122 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008123
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008124 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_DEPTH_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008125
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008126 vkCmdClearDepthStencilImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(),
8127 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, &clear_value, 1, &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008128
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008129 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008130}
8131
Karl Schultz6addd812016-02-02 17:17:23 -07008132TEST_F(VkLayerTest, ClearColorAttachmentsOutsideRenderPass) {
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06008133 // Call CmdClearAttachmentss outside of an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07008134 VkResult err;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008135
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008136 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdClearAttachments(): This call "
8137 "must be issued inside an active "
8138 "render pass");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008139
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008140 ASSERT_NO_FATAL_FAILURE(InitState());
8141 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008142
8143 // Start no RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008144 err = m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008145 ASSERT_VK_SUCCESS(err);
8146
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06008147 VkClearAttachment color_attachment;
8148 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8149 color_attachment.clearValue.color.float32[0] = 0;
8150 color_attachment.clearValue.color.float32[1] = 0;
8151 color_attachment.clearValue.color.float32[2] = 0;
8152 color_attachment.clearValue.color.float32[3] = 0;
8153 color_attachment.colorAttachment = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07008154 VkClearRect clear_rect = {{{0, 0}, {32, 32}}};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008155 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008156
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008157 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008158}
8159
Chris Forbes3b97e932016-09-07 11:29:24 +12008160TEST_F(VkLayerTest, RenderPassExcessiveNextSubpass) {
8161 TEST_DESCRIPTION("Test that an error is produced when CmdNextSubpass is "
8162 "called too many times in a renderpass instance");
8163
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008164 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdNextSubpass(): Attempted to advance "
8165 "beyond final subpass");
Chris Forbes3b97e932016-09-07 11:29:24 +12008166
8167 ASSERT_NO_FATAL_FAILURE(InitState());
8168 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8169
8170 BeginCommandBuffer();
8171
8172 // error here.
8173 vkCmdNextSubpass(m_commandBuffer->GetBufferHandle(), VK_SUBPASS_CONTENTS_INLINE);
8174 m_errorMonitor->VerifyFound();
8175
8176 EndCommandBuffer();
8177}
8178
Chris Forbes6d624702016-09-07 13:57:05 +12008179TEST_F(VkLayerTest, RenderPassEndedBeforeFinalSubpass) {
8180 TEST_DESCRIPTION("Test that an error is produced when CmdEndRenderPass is "
8181 "called before the final subpass has been reached");
8182
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008183 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdEndRenderPass(): Called before reaching "
8184 "final subpass");
Chris Forbes6d624702016-09-07 13:57:05 +12008185
8186 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008187 VkSubpassDescription sd[2] = {{0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr},
8188 {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr}};
Chris Forbes6d624702016-09-07 13:57:05 +12008189
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008190 VkRenderPassCreateInfo rcpi = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 2, sd, 0, nullptr};
Chris Forbes6d624702016-09-07 13:57:05 +12008191
8192 VkRenderPass rp;
8193 VkResult err = vkCreateRenderPass(m_device->device(), &rcpi, nullptr, &rp);
8194 ASSERT_VK_SUCCESS(err);
8195
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008196 VkFramebufferCreateInfo fbci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 0, nullptr, 16, 16, 1};
Chris Forbes6d624702016-09-07 13:57:05 +12008197
8198 VkFramebuffer fb;
8199 err = vkCreateFramebuffer(m_device->device(), &fbci, nullptr, &fb);
8200 ASSERT_VK_SUCCESS(err);
8201
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008202 m_commandBuffer->BeginCommandBuffer(); // no implicit RP begin
Chris Forbes6d624702016-09-07 13:57:05 +12008203
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008204 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 +12008205
8206 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
8207
8208 // Error here.
8209 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
8210 m_errorMonitor->VerifyFound();
8211
8212 // Clean up.
8213 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
8214 vkDestroyRenderPass(m_device->device(), rp, nullptr);
8215}
8216
Karl Schultz9e66a292016-04-21 15:57:51 -06008217TEST_F(VkLayerTest, BufferMemoryBarrierNoBuffer) {
8218 // Try to add a buffer memory barrier with no buffer.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008219 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8220 "required parameter pBufferMemoryBarriers[0].buffer specified as VK_NULL_HANDLE");
Karl Schultz9e66a292016-04-21 15:57:51 -06008221
8222 ASSERT_NO_FATAL_FAILURE(InitState());
8223 BeginCommandBuffer();
8224
8225 VkBufferMemoryBarrier buf_barrier = {};
8226 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
8227 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8228 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
8229 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8230 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8231 buf_barrier.buffer = VK_NULL_HANDLE;
8232 buf_barrier.offset = 0;
8233 buf_barrier.size = VK_WHOLE_SIZE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008234 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8235 nullptr, 1, &buf_barrier, 0, nullptr);
Karl Schultz9e66a292016-04-21 15:57:51 -06008236
8237 m_errorMonitor->VerifyFound();
8238}
8239
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008240TEST_F(VkLayerTest, InvalidBarriers) {
8241 TEST_DESCRIPTION("A variety of ways to get VK_INVALID_BARRIER ");
8242
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008243 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Barriers cannot be set during subpass");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008244
8245 ASSERT_NO_FATAL_FAILURE(InitState());
8246 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8247
8248 VkMemoryBarrier mem_barrier = {};
8249 mem_barrier.sType = VK_STRUCTURE_TYPE_MEMORY_BARRIER;
8250 mem_barrier.pNext = NULL;
8251 mem_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8252 mem_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
8253 BeginCommandBuffer();
8254 // BeginCommandBuffer() starts a render pass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008255 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 1,
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008256 &mem_barrier, 0, nullptr, 0, nullptr);
8257 m_errorMonitor->VerifyFound();
8258
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008259 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Image Layout cannot be transitioned to UNDEFINED");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008260 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008261 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 -06008262 ASSERT_TRUE(image.initialized());
8263 VkImageMemoryBarrier img_barrier = {};
8264 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
8265 img_barrier.pNext = NULL;
8266 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8267 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
8268 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8269 // New layout can't be UNDEFINED
8270 img_barrier.newLayout = VK_IMAGE_LAYOUT_UNDEFINED;
8271 img_barrier.image = image.handle();
8272 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8273 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8274 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8275 img_barrier.subresourceRange.baseArrayLayer = 0;
8276 img_barrier.subresourceRange.baseMipLevel = 0;
8277 img_barrier.subresourceRange.layerCount = 1;
8278 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008279 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8280 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008281 m_errorMonitor->VerifyFound();
8282 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8283
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008284 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Subresource must have the sum of the "
8285 "baseArrayLayer");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008286 // baseArrayLayer + layerCount must be <= image's arrayLayers
8287 img_barrier.subresourceRange.baseArrayLayer = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008288 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8289 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008290 m_errorMonitor->VerifyFound();
8291 img_barrier.subresourceRange.baseArrayLayer = 0;
8292
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008293 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Subresource must have the sum of the baseMipLevel");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008294 // baseMipLevel + levelCount must be <= image's mipLevels
8295 img_barrier.subresourceRange.baseMipLevel = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008296 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8297 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008298 m_errorMonitor->VerifyFound();
8299 img_barrier.subresourceRange.baseMipLevel = 0;
8300
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008301 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 -06008302 vk_testing::Buffer buffer;
Mark Lobodzinskibdf378a2016-12-12 17:11:50 -07008303 VkMemoryPropertyFlags mem_reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
8304 buffer.init_as_src_and_dst(*m_device, 256, mem_reqs);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008305 VkBufferMemoryBarrier buf_barrier = {};
8306 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
8307 buf_barrier.pNext = NULL;
8308 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8309 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
8310 buf_barrier.buffer = buffer.handle();
8311 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8312 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8313 buf_barrier.offset = 0;
8314 buf_barrier.size = VK_WHOLE_SIZE;
8315 // Can't send buffer barrier during a render pass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008316 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8317 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008318 m_errorMonitor->VerifyFound();
8319 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
8320
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008321 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "which is not less than total size");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008322 buf_barrier.offset = 257;
8323 // Offset greater than total size
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008324 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8325 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008326 m_errorMonitor->VerifyFound();
8327 buf_barrier.offset = 0;
8328
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008329 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "whose sum is greater than total size");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008330 buf_barrier.size = 257;
8331 // Size greater than total size
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008332 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8333 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008334 m_errorMonitor->VerifyFound();
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008335
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008336 // Now exercise barrier aspect bit errors, first DS
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06008337 m_errorMonitor->SetDesiredFailureMsg(
8338 VK_DEBUG_REPORT_ERROR_BIT_EXT,
8339 "Combination depth/stencil image formats can have only the VK_IMAGE_ASPECT_DEPTH_BIT and VK_IMAGE_ASPECT_STENCIL_BIT set.");
8340 m_errorMonitor->SetDesiredFailureMsg(
8341 VK_DEBUG_REPORT_ERROR_BIT_EXT,
8342 "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 -06008343 VkDepthStencilObj ds_image(m_device);
8344 ds_image.Init(m_device, 128, 128, VK_FORMAT_D24_UNORM_S8_UINT);
8345 ASSERT_TRUE(ds_image.initialized());
Tobin Ehlis15684a02016-07-21 14:55:26 -06008346 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
8347 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008348 img_barrier.image = ds_image.handle();
Tobin Ehlis15684a02016-07-21 14:55:26 -06008349 // Use of COLOR aspect on DS image is error
8350 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008351 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8352 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008353 m_errorMonitor->VerifyFound();
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008354 // Now test depth-only
8355 VkFormatProperties format_props;
8356
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008357 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_D16_UNORM, &format_props);
8358 if (format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) {
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06008359 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8360 "Depth-only image formats must have the VK_IMAGE_ASPECT_DEPTH_BIT set.");
8361 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8362 "Depth-only image formats can have only the VK_IMAGE_ASPECT_DEPTH_BIT set.");
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008363 VkDepthStencilObj d_image(m_device);
8364 d_image.Init(m_device, 128, 128, VK_FORMAT_D16_UNORM);
8365 ASSERT_TRUE(d_image.initialized());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008366 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
Tobin Ehlis15684a02016-07-21 14:55:26 -06008367 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008368 img_barrier.image = d_image.handle();
Tobin Ehlis15684a02016-07-21 14:55:26 -06008369 // Use of COLOR aspect on depth image is error
8370 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008371 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
8372 0, nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008373 m_errorMonitor->VerifyFound();
8374 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008375 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_S8_UINT, &format_props);
8376 if (format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) {
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008377 // Now test stencil-only
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06008378 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8379 "Stencil-only image formats must have the VK_IMAGE_ASPECT_STENCIL_BIT set.");
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008380 VkDepthStencilObj s_image(m_device);
8381 s_image.Init(m_device, 128, 128, VK_FORMAT_S8_UINT);
8382 ASSERT_TRUE(s_image.initialized());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008383 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
Tobin Ehlis15684a02016-07-21 14:55:26 -06008384 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008385 img_barrier.image = s_image.handle();
Tobin Ehlis15684a02016-07-21 14:55:26 -06008386 // Use of COLOR aspect on depth image is error
8387 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008388 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
8389 0, nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008390 m_errorMonitor->VerifyFound();
8391 }
8392 // Finally test color
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06008393 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8394 "Color image formats must have the VK_IMAGE_ASPECT_COLOR_BIT set.");
8395 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8396 "Color image formats must have ONLY the VK_IMAGE_ASPECT_COLOR_BIT set.");
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008397 VkImageObj c_image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008398 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 -06008399 ASSERT_TRUE(c_image.initialized());
8400 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8401 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
8402 img_barrier.image = c_image.handle();
8403 // Set aspect to depth (non-color)
8404 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008405 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8406 nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008407 m_errorMonitor->VerifyFound();
Mark Lobodzinskibdf378a2016-12-12 17:11:50 -07008408
8409 // Attempt to mismatch barriers/waitEvents calls with incompatible queues
8410
8411 // Create command pool with incompatible queueflags
8412 const std::vector<VkQueueFamilyProperties> queue_props = m_device->queue_props;
8413 uint32_t queue_family_index = UINT32_MAX;
8414 for (uint32_t i = 0; i < queue_props.size(); i++) {
8415 if ((queue_props[i].queueFlags & VK_QUEUE_COMPUTE_BIT) == 0) {
8416 queue_family_index = i;
8417 break;
8418 }
8419 }
8420 if (queue_family_index == UINT32_MAX) {
8421 printf("No non-compute queue found; skipped.\n");
8422 return;
8423 }
8424 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02513);
8425
8426 VkCommandPool command_pool;
8427 VkCommandPoolCreateInfo pool_create_info{};
8428 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
8429 pool_create_info.queueFamilyIndex = queue_family_index;
8430 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
8431 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
8432
8433 // Allocate a command buffer
8434 VkCommandBuffer bad_command_buffer;
8435 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
8436 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
8437 command_buffer_allocate_info.commandPool = command_pool;
8438 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
8439 command_buffer_allocate_info.commandBufferCount = 1;
8440 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &bad_command_buffer));
8441
8442 VkCommandBufferBeginInfo cbbi = {};
8443 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
8444 vkBeginCommandBuffer(bad_command_buffer, &cbbi);
8445 buf_barrier.offset = 0;
8446 buf_barrier.size = VK_WHOLE_SIZE;
8447 vkCmdPipelineBarrier(bad_command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 1,
8448 &buf_barrier, 0, nullptr);
8449 m_errorMonitor->VerifyFound();
8450
8451 if ((queue_props[queue_family_index].queueFlags & VK_QUEUE_GRAPHICS_BIT) == 0) {
8452 vkEndCommandBuffer(bad_command_buffer);
8453 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
8454 printf("The non-compute queue does not support graphics; skipped.\n");
8455 return;
8456 }
8457 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02510);
8458 VkEvent event;
8459 VkEventCreateInfo event_create_info{};
8460 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
8461 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
8462 vkCmdWaitEvents(bad_command_buffer, 1, &event, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, nullptr, 0,
8463 nullptr, 0, nullptr);
8464 m_errorMonitor->VerifyFound();
8465
8466 vkEndCommandBuffer(bad_command_buffer);
8467 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008468}
8469
Tony Barbour18ba25c2016-09-29 13:42:40 -06008470TEST_F(VkLayerTest, LayoutFromPresentWithoutAccessMemoryRead) {
8471 // Transition an image away from PRESENT_SRC_KHR without ACCESS_MEMORY_READ in srcAccessMask
8472
8473 m_errorMonitor->SetDesiredFailureMsg(
8474 VK_DEBUG_REPORT_WARNING_BIT_EXT,
8475 "must have required access bit");
8476 ASSERT_NO_FATAL_FAILURE(InitState());
8477 VkImageObj image(m_device);
Tony Barbour256c80a2016-10-05 13:23:46 -06008478 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 -06008479 ASSERT_TRUE(image.initialized());
8480
8481 VkImageMemoryBarrier barrier = {};
8482 VkImageSubresourceRange range;
8483 barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
8484 barrier.srcAccessMask = 0;
8485 barrier.srcAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
8486 barrier.dstAccessMask = VK_ACCESS_MEMORY_READ_BIT;
8487 barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8488 barrier.newLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
8489 barrier.image = image.handle();
8490 range.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8491 range.baseMipLevel = 0;
8492 range.levelCount = 1;
8493 range.baseArrayLayer = 0;
8494 range.layerCount = 1;
8495 barrier.subresourceRange = range;
8496 VkCommandBufferObj cmdbuf(m_device, m_commandPool);
8497 cmdbuf.BeginCommandBuffer();
8498 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
8499 &barrier);
8500 barrier.oldLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
8501 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
8502 barrier.srcAccessMask = 0;
8503 barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
8504 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
8505 &barrier);
8506
8507 m_errorMonitor->VerifyFound();
8508}
8509
Karl Schultz6addd812016-02-02 17:17:23 -07008510TEST_F(VkLayerTest, IdxBufferAlignmentError) {
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008511 // Bind a BeginRenderPass within an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07008512 VkResult err;
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008513
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008514 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdBindIndexBuffer() offset (0x7) does not fall on ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008515
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008516 ASSERT_NO_FATAL_FAILURE(InitState());
8517 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008518 uint32_t qfi = 0;
8519 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008520 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
8521 buffCI.size = 1024;
8522 buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
8523 buffCI.queueFamilyIndexCount = 1;
8524 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008525
8526 VkBuffer ib;
Chia-I Wuf7458c52015-10-26 21:10:41 +08008527 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008528 ASSERT_VK_SUCCESS(err);
8529
8530 BeginCommandBuffer();
8531 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07008532 // vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
8533 // VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008534 // Should error before calling to driver so don't care about actual data
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008535 vkCmdBindIndexBuffer(m_commandBuffer->GetBufferHandle(), ib, 7, VK_INDEX_TYPE_UINT16);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008536
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008537 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06008538
Chia-I Wuf7458c52015-10-26 21:10:41 +08008539 vkDestroyBuffer(m_device->device(), ib, NULL);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008540}
8541
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07008542TEST_F(VkLayerTest, InvalidQueueFamilyIndex) {
8543 // Create an out-of-range queueFamilyIndex
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008544 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8545 "vkCreateBuffer: pCreateInfo->pQueueFamilyIndices[0] (777) must be one "
8546 "of the indices specified when the device was created, via the "
8547 "VkDeviceQueueCreateInfo structure.");
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07008548
8549 ASSERT_NO_FATAL_FAILURE(InitState());
8550 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8551 VkBufferCreateInfo buffCI = {};
8552 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
8553 buffCI.size = 1024;
8554 buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
8555 buffCI.queueFamilyIndexCount = 1;
8556 // Introduce failure by specifying invalid queue_family_index
8557 uint32_t qfi = 777;
8558 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis24aab042016-03-24 10:54:18 -06008559 buffCI.sharingMode = VK_SHARING_MODE_CONCURRENT; // qfi only matters in CONCURRENT mode
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07008560
8561 VkBuffer ib;
8562 vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
8563
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008564 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06008565 vkDestroyBuffer(m_device->device(), ib, NULL);
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07008566}
8567
Karl Schultz6addd812016-02-02 17:17:23 -07008568TEST_F(VkLayerTest, ExecuteCommandsPrimaryCB) {
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -06008569TEST_DESCRIPTION("Attempt vkCmdExecuteCommands with a primary command buffer"
Tobin Ehlis0c94db02016-07-19 10:49:32 -06008570 " (should only be secondary)");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008571
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06008572 ASSERT_NO_FATAL_FAILURE(InitState());
8573 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06008574
Chris Forbesf29a84f2016-10-06 18:39:28 +13008575 // An empty primary command buffer
8576 VkCommandBufferObj cb(m_device, m_commandPool);
8577 cb.BeginCommandBuffer();
8578 cb.EndCommandBuffer();
Tobin Ehlis0c94db02016-07-19 10:49:32 -06008579
Chris Forbesf29a84f2016-10-06 18:39:28 +13008580 m_commandBuffer->BeginCommandBuffer();
8581 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
8582 VkCommandBuffer handle = cb.handle();
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06008583
Chris Forbesf29a84f2016-10-06 18:39:28 +13008584 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdExecuteCommands() called w/ Primary Cmd Buffer ");
8585 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &handle);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008586 m_errorMonitor->VerifyFound();
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06008587}
8588
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008589TEST_F(VkLayerTest, DSUsageBitsErrors) {
8590 TEST_DESCRIPTION("Attempt to update descriptor sets for images and buffers "
8591 "that do not have correct usage bits sets.");
8592 VkResult err;
8593
8594 ASSERT_NO_FATAL_FAILURE(InitState());
8595 VkDescriptorPoolSize ds_type_count[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
8596 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
8597 ds_type_count[i].type = VkDescriptorType(i);
8598 ds_type_count[i].descriptorCount = 1;
8599 }
8600 VkDescriptorPoolCreateInfo ds_pool_ci = {};
8601 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8602 ds_pool_ci.pNext = NULL;
8603 ds_pool_ci.maxSets = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
8604 ds_pool_ci.poolSizeCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
8605 ds_pool_ci.pPoolSizes = ds_type_count;
8606
8607 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008608 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008609 ASSERT_VK_SUCCESS(err);
8610
8611 // Create 10 layouts where each has a single descriptor of different type
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008612 VkDescriptorSetLayoutBinding dsl_binding[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008613 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
8614 dsl_binding[i].binding = 0;
8615 dsl_binding[i].descriptorType = VkDescriptorType(i);
8616 dsl_binding[i].descriptorCount = 1;
8617 dsl_binding[i].stageFlags = VK_SHADER_STAGE_ALL;
8618 dsl_binding[i].pImmutableSamplers = NULL;
8619 }
8620
8621 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
8622 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8623 ds_layout_ci.pNext = NULL;
8624 ds_layout_ci.bindingCount = 1;
8625 VkDescriptorSetLayout ds_layouts[VK_DESCRIPTOR_TYPE_RANGE_SIZE];
8626 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
8627 ds_layout_ci.pBindings = dsl_binding + i;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008628 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, ds_layouts + i);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008629 ASSERT_VK_SUCCESS(err);
8630 }
8631 VkDescriptorSet descriptor_sets[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
8632 VkDescriptorSetAllocateInfo alloc_info = {};
8633 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
8634 alloc_info.descriptorSetCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
8635 alloc_info.descriptorPool = ds_pool;
8636 alloc_info.pSetLayouts = ds_layouts;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008637 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptor_sets);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008638 ASSERT_VK_SUCCESS(err);
8639
8640 // Create a buffer & bufferView to be used for invalid updates
8641 VkBufferCreateInfo buff_ci = {};
8642 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
8643 // This usage is not valid for any descriptor type
8644 buff_ci.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
8645 buff_ci.size = 256;
8646 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
8647 VkBuffer buffer;
8648 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
8649 ASSERT_VK_SUCCESS(err);
8650
8651 VkBufferViewCreateInfo buff_view_ci = {};
8652 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
8653 buff_view_ci.buffer = buffer;
8654 buff_view_ci.format = VK_FORMAT_R8_UNORM;
8655 buff_view_ci.range = VK_WHOLE_SIZE;
8656 VkBufferView buff_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008657 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buff_view);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008658 ASSERT_VK_SUCCESS(err);
8659
8660 // Create an image to be used for invalid updates
8661 VkImageCreateInfo image_ci = {};
8662 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
8663 image_ci.imageType = VK_IMAGE_TYPE_2D;
8664 image_ci.format = VK_FORMAT_R8G8B8A8_UNORM;
8665 image_ci.extent.width = 64;
8666 image_ci.extent.height = 64;
8667 image_ci.extent.depth = 1;
8668 image_ci.mipLevels = 1;
8669 image_ci.arrayLayers = 1;
8670 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
8671 image_ci.tiling = VK_IMAGE_TILING_LINEAR;
8672 image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
8673 // This usage is not valid for any descriptor type
8674 image_ci.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
8675 image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
8676 VkImage image;
8677 err = vkCreateImage(m_device->device(), &image_ci, NULL, &image);
8678 ASSERT_VK_SUCCESS(err);
8679 // Bind memory to image
8680 VkMemoryRequirements mem_reqs;
8681 VkDeviceMemory image_mem;
8682 bool pass;
8683 VkMemoryAllocateInfo mem_alloc = {};
8684 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
8685 mem_alloc.pNext = NULL;
8686 mem_alloc.allocationSize = 0;
8687 mem_alloc.memoryTypeIndex = 0;
8688 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
8689 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008690 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008691 ASSERT_TRUE(pass);
8692 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
8693 ASSERT_VK_SUCCESS(err);
8694 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
8695 ASSERT_VK_SUCCESS(err);
8696 // Now create view for image
8697 VkImageViewCreateInfo image_view_ci = {};
8698 image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
8699 image_view_ci.image = image;
8700 image_view_ci.format = VK_FORMAT_R8G8B8A8_UNORM;
8701 image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D;
8702 image_view_ci.subresourceRange.layerCount = 1;
8703 image_view_ci.subresourceRange.baseArrayLayer = 0;
8704 image_view_ci.subresourceRange.levelCount = 1;
8705 image_view_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8706 VkImageView image_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008707 err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, &image_view);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008708 ASSERT_VK_SUCCESS(err);
8709
8710 VkDescriptorBufferInfo buff_info = {};
8711 buff_info.buffer = buffer;
8712 VkDescriptorImageInfo img_info = {};
8713 img_info.imageView = image_view;
8714 VkWriteDescriptorSet descriptor_write = {};
8715 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
8716 descriptor_write.dstBinding = 0;
8717 descriptor_write.descriptorCount = 1;
8718 descriptor_write.pTexelBufferView = &buff_view;
8719 descriptor_write.pBufferInfo = &buff_info;
8720 descriptor_write.pImageInfo = &img_info;
8721
8722 // These error messages align with VkDescriptorType struct
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008723 const char *error_msgs[] = {"", // placeholder, no error for SAMPLER descriptor
8724 " does not have VK_IMAGE_USAGE_SAMPLED_BIT set.",
8725 " does not have VK_IMAGE_USAGE_SAMPLED_BIT set.",
8726 " does not have VK_IMAGE_USAGE_STORAGE_BIT set.",
8727 " does not have VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT set.",
8728 " does not have VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT set.",
8729 " does not have VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT set.",
8730 " does not have VK_BUFFER_USAGE_STORAGE_BUFFER_BIT set.",
8731 " does not have VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT set.",
8732 " does not have VK_BUFFER_USAGE_STORAGE_BUFFER_BIT set.",
8733 " does not have VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT set."};
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008734 // Start loop at 1 as SAMPLER desc type has no usage bit error
8735 for (uint32_t i = 1; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
8736 descriptor_write.descriptorType = VkDescriptorType(i);
8737 descriptor_write.dstSet = descriptor_sets[i];
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008738 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, error_msgs[i]);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008739
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008740 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008741
8742 m_errorMonitor->VerifyFound();
8743 vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[i], NULL);
8744 }
8745 vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[0], NULL);
8746 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06008747 vkFreeMemory(m_device->device(), image_mem, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008748 vkDestroyImageView(m_device->device(), image_view, NULL);
8749 vkDestroyBuffer(m_device->device(), buffer, NULL);
8750 vkDestroyBufferView(m_device->device(), buff_view, NULL);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008751 vkFreeDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_TYPE_RANGE_SIZE, descriptor_sets);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008752 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
8753}
8754
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008755TEST_F(VkLayerTest, DSBufferInfoErrors) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008756 TEST_DESCRIPTION("Attempt to update buffer descriptor set that has incorrect "
8757 "parameters in VkDescriptorBufferInfo struct. This includes:\n"
8758 "1. offset value greater than buffer size\n"
8759 "2. range value of 0\n"
8760 "3. range value greater than buffer (size - offset)");
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008761 VkResult err;
8762
8763 ASSERT_NO_FATAL_FAILURE(InitState());
8764 VkDescriptorPoolSize ds_type_count = {};
8765 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8766 ds_type_count.descriptorCount = 1;
8767
8768 VkDescriptorPoolCreateInfo ds_pool_ci = {};
8769 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8770 ds_pool_ci.pNext = NULL;
8771 ds_pool_ci.maxSets = 1;
8772 ds_pool_ci.poolSizeCount = 1;
8773 ds_pool_ci.pPoolSizes = &ds_type_count;
8774
8775 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008776 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008777 ASSERT_VK_SUCCESS(err);
8778
8779 // Create layout with single uniform buffer descriptor
8780 VkDescriptorSetLayoutBinding dsl_binding = {};
8781 dsl_binding.binding = 0;
8782 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8783 dsl_binding.descriptorCount = 1;
8784 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8785 dsl_binding.pImmutableSamplers = NULL;
8786
8787 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
8788 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8789 ds_layout_ci.pNext = NULL;
8790 ds_layout_ci.bindingCount = 1;
8791 ds_layout_ci.pBindings = &dsl_binding;
8792 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008793 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008794 ASSERT_VK_SUCCESS(err);
8795
8796 VkDescriptorSet descriptor_set = {};
8797 VkDescriptorSetAllocateInfo alloc_info = {};
8798 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
8799 alloc_info.descriptorSetCount = 1;
8800 alloc_info.descriptorPool = ds_pool;
8801 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008802 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008803 ASSERT_VK_SUCCESS(err);
8804
8805 // Create a buffer to be used for invalid updates
8806 VkBufferCreateInfo buff_ci = {};
8807 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
8808 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
8809 buff_ci.size = 256;
8810 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
8811 VkBuffer buffer;
8812 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
8813 ASSERT_VK_SUCCESS(err);
8814 // Have to bind memory to buffer before descriptor update
8815 VkMemoryAllocateInfo mem_alloc = {};
8816 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
8817 mem_alloc.pNext = NULL;
8818 mem_alloc.allocationSize = 256;
8819 mem_alloc.memoryTypeIndex = 0;
8820
8821 VkMemoryRequirements mem_reqs;
8822 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008823 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008824 if (!pass) {
8825 vkDestroyBuffer(m_device->device(), buffer, NULL);
8826 return;
8827 }
8828
8829 VkDeviceMemory mem;
8830 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
8831 ASSERT_VK_SUCCESS(err);
8832 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
8833 ASSERT_VK_SUCCESS(err);
8834
8835 VkDescriptorBufferInfo buff_info = {};
8836 buff_info.buffer = buffer;
8837 // First make offset 1 larger than buffer size
8838 buff_info.offset = 257;
8839 buff_info.range = VK_WHOLE_SIZE;
8840 VkWriteDescriptorSet descriptor_write = {};
8841 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
8842 descriptor_write.dstBinding = 0;
8843 descriptor_write.descriptorCount = 1;
8844 descriptor_write.pTexelBufferView = nullptr;
8845 descriptor_write.pBufferInfo = &buff_info;
8846 descriptor_write.pImageInfo = nullptr;
8847
8848 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8849 descriptor_write.dstSet = descriptor_set;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008850 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " offset of 257 is greater than buffer ");
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008851
8852 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8853
8854 m_errorMonitor->VerifyFound();
8855 // Now cause error due to range of 0
8856 buff_info.offset = 0;
8857 buff_info.range = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008858 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8859 " range is not VK_WHOLE_SIZE and is zero, which is not allowed.");
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008860
8861 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8862
8863 m_errorMonitor->VerifyFound();
8864 // Now cause error due to range exceeding buffer size - offset
8865 buff_info.offset = 128;
8866 buff_info.range = 200;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008867 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 -06008868
8869 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8870
8871 m_errorMonitor->VerifyFound();
Mark Lobodzinski4bb54092016-07-06 14:27:19 -06008872 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008873 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8874 vkDestroyBuffer(m_device->device(), buffer, NULL);
8875 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
8876 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
8877}
8878
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008879TEST_F(VkLayerTest, DSAspectBitsErrors) {
8880 // TODO : Initially only catching case where DEPTH & STENCIL aspect bits
8881 // are set, but could expand this test to hit more cases.
8882 TEST_DESCRIPTION("Attempt to update descriptor sets for images "
8883 "that do not have correct aspect bits sets.");
8884 VkResult err;
8885
8886 ASSERT_NO_FATAL_FAILURE(InitState());
8887 VkDescriptorPoolSize ds_type_count = {};
8888 ds_type_count.type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
8889 ds_type_count.descriptorCount = 1;
8890
8891 VkDescriptorPoolCreateInfo ds_pool_ci = {};
8892 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8893 ds_pool_ci.pNext = NULL;
8894 ds_pool_ci.maxSets = 5;
8895 ds_pool_ci.poolSizeCount = 1;
8896 ds_pool_ci.pPoolSizes = &ds_type_count;
8897
8898 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008899 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008900 ASSERT_VK_SUCCESS(err);
8901
8902 VkDescriptorSetLayoutBinding dsl_binding = {};
8903 dsl_binding.binding = 0;
8904 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
8905 dsl_binding.descriptorCount = 1;
8906 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8907 dsl_binding.pImmutableSamplers = NULL;
8908
8909 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
8910 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8911 ds_layout_ci.pNext = NULL;
8912 ds_layout_ci.bindingCount = 1;
8913 ds_layout_ci.pBindings = &dsl_binding;
8914 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008915 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008916 ASSERT_VK_SUCCESS(err);
8917
8918 VkDescriptorSet descriptor_set = {};
8919 VkDescriptorSetAllocateInfo alloc_info = {};
8920 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
8921 alloc_info.descriptorSetCount = 1;
8922 alloc_info.descriptorPool = ds_pool;
8923 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008924 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008925 ASSERT_VK_SUCCESS(err);
8926
8927 // Create an image to be used for invalid updates
8928 VkImageCreateInfo image_ci = {};
8929 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
8930 image_ci.imageType = VK_IMAGE_TYPE_2D;
8931 image_ci.format = VK_FORMAT_D24_UNORM_S8_UINT;
8932 image_ci.extent.width = 64;
8933 image_ci.extent.height = 64;
8934 image_ci.extent.depth = 1;
8935 image_ci.mipLevels = 1;
8936 image_ci.arrayLayers = 1;
8937 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
8938 image_ci.tiling = VK_IMAGE_TILING_LINEAR;
8939 image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
8940 image_ci.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
8941 image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
8942 VkImage image;
8943 err = vkCreateImage(m_device->device(), &image_ci, NULL, &image);
8944 ASSERT_VK_SUCCESS(err);
8945 // Bind memory to image
8946 VkMemoryRequirements mem_reqs;
8947 VkDeviceMemory image_mem;
8948 bool pass;
8949 VkMemoryAllocateInfo mem_alloc = {};
8950 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
8951 mem_alloc.pNext = NULL;
8952 mem_alloc.allocationSize = 0;
8953 mem_alloc.memoryTypeIndex = 0;
8954 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
8955 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008956 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008957 ASSERT_TRUE(pass);
8958 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
8959 ASSERT_VK_SUCCESS(err);
8960 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
8961 ASSERT_VK_SUCCESS(err);
8962 // Now create view for image
8963 VkImageViewCreateInfo image_view_ci = {};
8964 image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
8965 image_view_ci.image = image;
8966 image_view_ci.format = VK_FORMAT_D24_UNORM_S8_UINT;
8967 image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D;
8968 image_view_ci.subresourceRange.layerCount = 1;
8969 image_view_ci.subresourceRange.baseArrayLayer = 0;
8970 image_view_ci.subresourceRange.levelCount = 1;
8971 // Setting both depth & stencil aspect bits is illegal for descriptor
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008972 image_view_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008973
8974 VkImageView image_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008975 err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, &image_view);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008976 ASSERT_VK_SUCCESS(err);
8977
8978 VkDescriptorImageInfo img_info = {};
8979 img_info.imageView = image_view;
8980 VkWriteDescriptorSet descriptor_write = {};
8981 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
8982 descriptor_write.dstBinding = 0;
8983 descriptor_write.descriptorCount = 1;
8984 descriptor_write.pTexelBufferView = NULL;
8985 descriptor_write.pBufferInfo = NULL;
8986 descriptor_write.pImageInfo = &img_info;
8987 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
8988 descriptor_write.dstSet = descriptor_set;
8989 const char *error_msg = " please only set either VK_IMAGE_ASPECT_DEPTH_BIT "
8990 "or VK_IMAGE_ASPECT_STENCIL_BIT ";
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008991 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, error_msg);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008992
8993 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8994
8995 m_errorMonitor->VerifyFound();
8996 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8997 vkDestroyImage(m_device->device(), image, NULL);
8998 vkFreeMemory(m_device->device(), image_mem, NULL);
8999 vkDestroyImageView(m_device->device(), image_view, NULL);
9000 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
9001 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9002}
9003
Karl Schultz6addd812016-02-02 17:17:23 -07009004TEST_F(VkLayerTest, DSTypeMismatch) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009005 // Create DS w/ layout of one type and attempt Update w/ mis-matched type
Karl Schultz6addd812016-02-02 17:17:23 -07009006 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009007
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009008 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9009 " binding #0 with type VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER but update "
9010 "type is VK_DESCRIPTOR_TYPE_SAMPLER");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009011
Tobin Ehlis3b780662015-05-28 12:11:26 -06009012 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07009013 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009014 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009015 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9016 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009017
9018 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009019 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9020 ds_pool_ci.pNext = NULL;
9021 ds_pool_ci.maxSets = 1;
9022 ds_pool_ci.poolSizeCount = 1;
9023 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06009024
Tobin Ehlis3b780662015-05-28 12:11:26 -06009025 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009026 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009027 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -06009028 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009029 dsl_binding.binding = 0;
9030 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9031 dsl_binding.descriptorCount = 1;
9032 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9033 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009034
Tony Barboureb254902015-07-15 12:50:33 -06009035 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009036 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9037 ds_layout_ci.pNext = NULL;
9038 ds_layout_ci.bindingCount = 1;
9039 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06009040
Tobin Ehlis3b780662015-05-28 12:11:26 -06009041 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009042 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009043 ASSERT_VK_SUCCESS(err);
9044
9045 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009046 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009047 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009048 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009049 alloc_info.descriptorPool = ds_pool;
9050 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009051 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009052 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009053
Tobin Ehlis30db8f82016-05-05 08:19:48 -06009054 VkSamplerCreateInfo sampler_ci = {};
9055 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9056 sampler_ci.pNext = NULL;
9057 sampler_ci.magFilter = VK_FILTER_NEAREST;
9058 sampler_ci.minFilter = VK_FILTER_NEAREST;
9059 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9060 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9061 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9062 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9063 sampler_ci.mipLodBias = 1.0;
9064 sampler_ci.anisotropyEnable = VK_FALSE;
9065 sampler_ci.maxAnisotropy = 1;
9066 sampler_ci.compareEnable = VK_FALSE;
9067 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9068 sampler_ci.minLod = 1.0;
9069 sampler_ci.maxLod = 1.0;
9070 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9071 sampler_ci.unnormalizedCoordinates = VK_FALSE;
9072 VkSampler sampler;
9073 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
9074 ASSERT_VK_SUCCESS(err);
9075
9076 VkDescriptorImageInfo info = {};
9077 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009078
9079 VkWriteDescriptorSet descriptor_write;
9080 memset(&descriptor_write, 0, sizeof(descriptor_write));
9081 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009082 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009083 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009084 // This is a mismatched type for the layout which expects BUFFER
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009085 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06009086 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009087
9088 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9089
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009090 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009091
Chia-I Wuf7458c52015-10-26 21:10:41 +08009092 vkDestroySampler(m_device->device(), sampler, NULL);
9093 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9094 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009095}
9096
Karl Schultz6addd812016-02-02 17:17:23 -07009097TEST_F(VkLayerTest, DSUpdateOutOfBounds) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009098 // For overlapping Update, have arrayIndex exceed that of layout
Karl Schultz6addd812016-02-02 17:17:23 -07009099 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009100
Tobin Ehlisf922ef82016-11-30 10:19:14 -07009101 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00938);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009102
Tobin Ehlis3b780662015-05-28 12:11:26 -06009103 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07009104 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009105 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009106 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9107 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009108
9109 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009110 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9111 ds_pool_ci.pNext = NULL;
9112 ds_pool_ci.maxSets = 1;
9113 ds_pool_ci.poolSizeCount = 1;
9114 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06009115
Tobin Ehlis3b780662015-05-28 12:11:26 -06009116 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009117 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009118 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009119
Tony Barboureb254902015-07-15 12:50:33 -06009120 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009121 dsl_binding.binding = 0;
9122 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9123 dsl_binding.descriptorCount = 1;
9124 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9125 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -06009126
9127 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009128 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9129 ds_layout_ci.pNext = NULL;
9130 ds_layout_ci.bindingCount = 1;
9131 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06009132
Tobin Ehlis3b780662015-05-28 12:11:26 -06009133 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009134 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009135 ASSERT_VK_SUCCESS(err);
9136
9137 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009138 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009139 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009140 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009141 alloc_info.descriptorPool = ds_pool;
9142 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009143 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009144 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009145
Tobin Ehlis30db8f82016-05-05 08:19:48 -06009146 // Correctly update descriptor to avoid "NOT_UPDATED" error
9147 VkDescriptorBufferInfo buff_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009148 buff_info.buffer = VkBuffer(0); // Don't care about buffer handle for this test
Tobin Ehlis30db8f82016-05-05 08:19:48 -06009149 buff_info.offset = 0;
9150 buff_info.range = 1024;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009151
9152 VkWriteDescriptorSet descriptor_write;
9153 memset(&descriptor_write, 0, sizeof(descriptor_write));
9154 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009155 descriptor_write.dstSet = descriptorSet;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009156 descriptor_write.dstArrayElement = 1; /* This index out of bounds for the update */
Chia-I Wud50a7d72015-10-26 20:48:51 +08009157 descriptor_write.descriptorCount = 1;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06009158 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9159 descriptor_write.pBufferInfo = &buff_info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009160
9161 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9162
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009163 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009164
Chia-I Wuf7458c52015-10-26 21:10:41 +08009165 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9166 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009167}
9168
Karl Schultz6addd812016-02-02 17:17:23 -07009169TEST_F(VkLayerTest, InvalidDSUpdateIndex) {
Tobin Ehlisc8d352d2016-11-21 10:33:40 -07009170 // Create layout w/ count of 1 and attempt update to that layout w/ binding index 2
Karl Schultz6addd812016-02-02 17:17:23 -07009171 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009172
Tobin Ehlisc8d352d2016-11-21 10:33:40 -07009173 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00936);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009174
Tobin Ehlis3b780662015-05-28 12:11:26 -06009175 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07009176 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009177 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009178 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9179 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009180
9181 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009182 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9183 ds_pool_ci.pNext = NULL;
9184 ds_pool_ci.maxSets = 1;
9185 ds_pool_ci.poolSizeCount = 1;
9186 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06009187
Tobin Ehlis3b780662015-05-28 12:11:26 -06009188 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009189 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009190 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009191
Tony Barboureb254902015-07-15 12:50:33 -06009192 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009193 dsl_binding.binding = 0;
9194 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9195 dsl_binding.descriptorCount = 1;
9196 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9197 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -06009198
9199 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009200 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9201 ds_layout_ci.pNext = NULL;
9202 ds_layout_ci.bindingCount = 1;
9203 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009204 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009205 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009206 ASSERT_VK_SUCCESS(err);
9207
9208 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009209 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009210 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009211 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009212 alloc_info.descriptorPool = ds_pool;
9213 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009214 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009215 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009216
Tony Barboureb254902015-07-15 12:50:33 -06009217 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009218 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9219 sampler_ci.pNext = NULL;
9220 sampler_ci.magFilter = VK_FILTER_NEAREST;
9221 sampler_ci.minFilter = VK_FILTER_NEAREST;
9222 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9223 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9224 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9225 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9226 sampler_ci.mipLodBias = 1.0;
9227 sampler_ci.anisotropyEnable = VK_FALSE;
9228 sampler_ci.maxAnisotropy = 1;
9229 sampler_ci.compareEnable = VK_FALSE;
9230 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9231 sampler_ci.minLod = 1.0;
9232 sampler_ci.maxLod = 1.0;
9233 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9234 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tony Barboureb254902015-07-15 12:50:33 -06009235
Tobin Ehlis3b780662015-05-28 12:11:26 -06009236 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009237 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009238 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009239
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06009240 VkDescriptorImageInfo info = {};
9241 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009242
9243 VkWriteDescriptorSet descriptor_write;
9244 memset(&descriptor_write, 0, sizeof(descriptor_write));
9245 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009246 descriptor_write.dstSet = descriptorSet;
9247 descriptor_write.dstBinding = 2;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009248 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009249 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009250 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06009251 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009252
9253 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9254
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009255 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009256
Chia-I Wuf7458c52015-10-26 21:10:41 +08009257 vkDestroySampler(m_device->device(), sampler, NULL);
9258 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9259 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009260}
9261
Tobin Ehlise202b2d2016-11-21 10:36:16 -07009262TEST_F(VkLayerTest, DSUpdateEmptyBinding) {
9263 // Create layout w/ empty binding and attempt to update it
9264 VkResult err;
9265
9266 ASSERT_NO_FATAL_FAILURE(InitState());
9267
9268 VkDescriptorPoolSize ds_type_count = {};
9269 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
9270 ds_type_count.descriptorCount = 1;
9271
9272 VkDescriptorPoolCreateInfo ds_pool_ci = {};
9273 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9274 ds_pool_ci.pNext = NULL;
9275 ds_pool_ci.maxSets = 1;
9276 ds_pool_ci.poolSizeCount = 1;
9277 ds_pool_ci.pPoolSizes = &ds_type_count;
9278
9279 VkDescriptorPool ds_pool;
9280 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
9281 ASSERT_VK_SUCCESS(err);
9282
9283 VkDescriptorSetLayoutBinding dsl_binding = {};
9284 dsl_binding.binding = 0;
9285 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9286 dsl_binding.descriptorCount = 0;
9287 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9288 dsl_binding.pImmutableSamplers = NULL;
9289
9290 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9291 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9292 ds_layout_ci.pNext = NULL;
9293 ds_layout_ci.bindingCount = 1;
9294 ds_layout_ci.pBindings = &dsl_binding;
9295 VkDescriptorSetLayout ds_layout;
9296 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
9297 ASSERT_VK_SUCCESS(err);
9298
9299 VkDescriptorSet descriptor_set;
9300 VkDescriptorSetAllocateInfo alloc_info = {};
9301 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
9302 alloc_info.descriptorSetCount = 1;
9303 alloc_info.descriptorPool = ds_pool;
9304 alloc_info.pSetLayouts = &ds_layout;
9305 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
9306 ASSERT_VK_SUCCESS(err);
9307
9308 VkSamplerCreateInfo sampler_ci = {};
9309 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9310 sampler_ci.magFilter = VK_FILTER_NEAREST;
9311 sampler_ci.minFilter = VK_FILTER_NEAREST;
9312 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9313 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9314 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9315 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9316 sampler_ci.mipLodBias = 1.0;
9317 sampler_ci.maxAnisotropy = 1;
9318 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9319 sampler_ci.minLod = 1.0;
9320 sampler_ci.maxLod = 1.0;
9321 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9322
9323 VkSampler sampler;
9324 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
9325 ASSERT_VK_SUCCESS(err);
9326
9327 VkDescriptorImageInfo info = {};
9328 info.sampler = sampler;
9329
9330 VkWriteDescriptorSet descriptor_write;
9331 memset(&descriptor_write, 0, sizeof(descriptor_write));
9332 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
9333 descriptor_write.dstSet = descriptor_set;
9334 descriptor_write.dstBinding = 0;
9335 descriptor_write.descriptorCount = 1; // Lie here to avoid parameter_validation error
9336 // This is the wrong type, but empty binding error will be flagged first
9337 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9338 descriptor_write.pImageInfo = &info;
9339
9340 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02348);
9341 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9342 m_errorMonitor->VerifyFound();
9343
9344 vkDestroySampler(m_device->device(), sampler, NULL);
9345 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9346 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9347}
9348
Karl Schultz6addd812016-02-02 17:17:23 -07009349TEST_F(VkLayerTest, InvalidDSUpdateStruct) {
9350 // Call UpdateDS w/ struct type other than valid VK_STRUCTUR_TYPE_UPDATE_*
9351 // types
9352 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009353
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009354 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 -06009355
Tobin Ehlis3b780662015-05-28 12:11:26 -06009356 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski209b5292015-09-17 09:44:05 -06009357
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009358 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009359 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9360 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009361
9362 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009363 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9364 ds_pool_ci.pNext = NULL;
9365 ds_pool_ci.maxSets = 1;
9366 ds_pool_ci.poolSizeCount = 1;
9367 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06009368
Tobin Ehlis3b780662015-05-28 12:11:26 -06009369 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009370 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009371 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -06009372 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009373 dsl_binding.binding = 0;
9374 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9375 dsl_binding.descriptorCount = 1;
9376 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9377 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009378
Tony Barboureb254902015-07-15 12:50:33 -06009379 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009380 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9381 ds_layout_ci.pNext = NULL;
9382 ds_layout_ci.bindingCount = 1;
9383 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06009384
Tobin Ehlis3b780662015-05-28 12:11:26 -06009385 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009386 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009387 ASSERT_VK_SUCCESS(err);
9388
9389 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009390 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009391 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009392 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009393 alloc_info.descriptorPool = ds_pool;
9394 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009395 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009396 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009397
Tony Barboureb254902015-07-15 12:50:33 -06009398 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009399 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9400 sampler_ci.pNext = NULL;
9401 sampler_ci.magFilter = VK_FILTER_NEAREST;
9402 sampler_ci.minFilter = VK_FILTER_NEAREST;
9403 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9404 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9405 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9406 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9407 sampler_ci.mipLodBias = 1.0;
9408 sampler_ci.anisotropyEnable = VK_FALSE;
9409 sampler_ci.maxAnisotropy = 1;
9410 sampler_ci.compareEnable = VK_FALSE;
9411 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9412 sampler_ci.minLod = 1.0;
9413 sampler_ci.maxLod = 1.0;
9414 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9415 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009416 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009417 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009418 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009419
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06009420 VkDescriptorImageInfo info = {};
9421 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009422
9423 VkWriteDescriptorSet descriptor_write;
9424 memset(&descriptor_write, 0, sizeof(descriptor_write));
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009425 descriptor_write.sType = (VkStructureType)0x99999999; /* Intentionally broken struct type */
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009426 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009427 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009428 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009429 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06009430 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009431
9432 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9433
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009434 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009435
Chia-I Wuf7458c52015-10-26 21:10:41 +08009436 vkDestroySampler(m_device->device(), sampler, NULL);
9437 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9438 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009439}
9440
Karl Schultz6addd812016-02-02 17:17:23 -07009441TEST_F(VkLayerTest, SampleDescriptorUpdateError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009442 // Create a single Sampler descriptor and send it an invalid Sampler
Karl Schultz6addd812016-02-02 17:17:23 -07009443 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009444
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009445 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9446 "Attempted write update to sampler descriptor with invalid sampler");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009447
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009448 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07009449 // TODO : Farm Descriptor setup code to helper function(s) to reduce copied
9450 // code
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009451 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009452 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
9453 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009454
9455 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009456 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9457 ds_pool_ci.pNext = NULL;
9458 ds_pool_ci.maxSets = 1;
9459 ds_pool_ci.poolSizeCount = 1;
9460 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009461
9462 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009463 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009464 ASSERT_VK_SUCCESS(err);
9465
9466 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009467 dsl_binding.binding = 0;
9468 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9469 dsl_binding.descriptorCount = 1;
9470 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9471 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009472
9473 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009474 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9475 ds_layout_ci.pNext = NULL;
9476 ds_layout_ci.bindingCount = 1;
9477 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009478 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009479 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009480 ASSERT_VK_SUCCESS(err);
9481
9482 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009483 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009484 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009485 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009486 alloc_info.descriptorPool = ds_pool;
9487 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009488 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009489 ASSERT_VK_SUCCESS(err);
9490
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009491 VkSampler sampler = (VkSampler)((size_t)0xbaadbeef); // Sampler with invalid handle
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009492
9493 VkDescriptorImageInfo descriptor_info;
9494 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
9495 descriptor_info.sampler = sampler;
9496
9497 VkWriteDescriptorSet descriptor_write;
9498 memset(&descriptor_write, 0, sizeof(descriptor_write));
9499 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009500 descriptor_write.dstSet = descriptorSet;
9501 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009502 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009503 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9504 descriptor_write.pImageInfo = &descriptor_info;
9505
9506 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9507
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009508 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009509
Chia-I Wuf7458c52015-10-26 21:10:41 +08009510 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9511 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009512}
9513
Karl Schultz6addd812016-02-02 17:17:23 -07009514TEST_F(VkLayerTest, ImageViewDescriptorUpdateError) {
9515 // Create a single combined Image/Sampler descriptor and send it an invalid
9516 // imageView
9517 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009518
Karl Schultzf78bcdd2016-11-30 12:36:01 -07009519 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00943);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009520
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009521 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009522 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009523 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
9524 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009525
9526 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009527 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9528 ds_pool_ci.pNext = NULL;
9529 ds_pool_ci.maxSets = 1;
9530 ds_pool_ci.poolSizeCount = 1;
9531 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009532
9533 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009534 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009535 ASSERT_VK_SUCCESS(err);
9536
9537 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009538 dsl_binding.binding = 0;
9539 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
9540 dsl_binding.descriptorCount = 1;
9541 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9542 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009543
9544 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009545 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9546 ds_layout_ci.pNext = NULL;
9547 ds_layout_ci.bindingCount = 1;
9548 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009549 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009550 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009551 ASSERT_VK_SUCCESS(err);
9552
9553 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009554 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009555 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009556 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009557 alloc_info.descriptorPool = ds_pool;
9558 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009559 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009560 ASSERT_VK_SUCCESS(err);
9561
9562 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009563 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9564 sampler_ci.pNext = NULL;
9565 sampler_ci.magFilter = VK_FILTER_NEAREST;
9566 sampler_ci.minFilter = VK_FILTER_NEAREST;
9567 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9568 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9569 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9570 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9571 sampler_ci.mipLodBias = 1.0;
9572 sampler_ci.anisotropyEnable = VK_FALSE;
9573 sampler_ci.maxAnisotropy = 1;
9574 sampler_ci.compareEnable = VK_FALSE;
9575 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9576 sampler_ci.minLod = 1.0;
9577 sampler_ci.maxLod = 1.0;
9578 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9579 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009580
9581 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009582 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009583 ASSERT_VK_SUCCESS(err);
9584
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009585 VkImageView view = (VkImageView)((size_t)0xbaadbeef); // invalid imageView object
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009586
9587 VkDescriptorImageInfo descriptor_info;
9588 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
9589 descriptor_info.sampler = sampler;
9590 descriptor_info.imageView = view;
9591
9592 VkWriteDescriptorSet descriptor_write;
9593 memset(&descriptor_write, 0, sizeof(descriptor_write));
9594 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009595 descriptor_write.dstSet = descriptorSet;
9596 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009597 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009598 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
9599 descriptor_write.pImageInfo = &descriptor_info;
9600
9601 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9602
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009603 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009604
Chia-I Wuf7458c52015-10-26 21:10:41 +08009605 vkDestroySampler(m_device->device(), sampler, NULL);
9606 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9607 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009608}
9609
Karl Schultz6addd812016-02-02 17:17:23 -07009610TEST_F(VkLayerTest, CopyDescriptorUpdateErrors) {
9611 // Create DS w/ layout of 2 types, write update 1 and attempt to copy-update
9612 // into the other
9613 VkResult err;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009614
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009615 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " binding #1 with type "
9616 "VK_DESCRIPTOR_TYPE_SAMPLER. Types do "
9617 "not match.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009618
Tobin Ehlis04356f92015-10-27 16:35:27 -06009619 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07009620 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009621 VkDescriptorPoolSize ds_type_count[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009622 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9623 ds_type_count[0].descriptorCount = 1;
9624 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLER;
9625 ds_type_count[1].descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009626
9627 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009628 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9629 ds_pool_ci.pNext = NULL;
9630 ds_pool_ci.maxSets = 1;
9631 ds_pool_ci.poolSizeCount = 2;
9632 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009633
9634 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009635 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis04356f92015-10-27 16:35:27 -06009636 ASSERT_VK_SUCCESS(err);
9637 VkDescriptorSetLayoutBinding dsl_binding[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009638 dsl_binding[0].binding = 0;
9639 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9640 dsl_binding[0].descriptorCount = 1;
9641 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
9642 dsl_binding[0].pImmutableSamplers = NULL;
9643 dsl_binding[1].binding = 1;
9644 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9645 dsl_binding[1].descriptorCount = 1;
9646 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
9647 dsl_binding[1].pImmutableSamplers = NULL;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009648
9649 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009650 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9651 ds_layout_ci.pNext = NULL;
9652 ds_layout_ci.bindingCount = 2;
9653 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009654
9655 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009656 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis04356f92015-10-27 16:35:27 -06009657 ASSERT_VK_SUCCESS(err);
9658
9659 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009660 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009661 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009662 alloc_info.descriptorSetCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009663 alloc_info.descriptorPool = ds_pool;
9664 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009665 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis04356f92015-10-27 16:35:27 -06009666 ASSERT_VK_SUCCESS(err);
9667
9668 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009669 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9670 sampler_ci.pNext = NULL;
9671 sampler_ci.magFilter = VK_FILTER_NEAREST;
9672 sampler_ci.minFilter = VK_FILTER_NEAREST;
9673 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9674 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9675 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9676 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9677 sampler_ci.mipLodBias = 1.0;
9678 sampler_ci.anisotropyEnable = VK_FALSE;
9679 sampler_ci.maxAnisotropy = 1;
9680 sampler_ci.compareEnable = VK_FALSE;
9681 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9682 sampler_ci.minLod = 1.0;
9683 sampler_ci.maxLod = 1.0;
9684 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9685 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009686
9687 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009688 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis04356f92015-10-27 16:35:27 -06009689 ASSERT_VK_SUCCESS(err);
9690
9691 VkDescriptorImageInfo info = {};
9692 info.sampler = sampler;
9693
9694 VkWriteDescriptorSet descriptor_write;
9695 memset(&descriptor_write, 0, sizeof(VkWriteDescriptorSet));
9696 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009697 descriptor_write.dstSet = descriptorSet;
9698 descriptor_write.dstBinding = 1; // SAMPLER binding from layout above
Chia-I Wud50a7d72015-10-26 20:48:51 +08009699 descriptor_write.descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009700 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9701 descriptor_write.pImageInfo = &info;
9702 // This write update should succeed
9703 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9704 // Now perform a copy update that fails due to type mismatch
9705 VkCopyDescriptorSet copy_ds_update;
9706 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
9707 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
9708 copy_ds_update.srcSet = descriptorSet;
Mark Young29927482016-05-04 14:38:51 -06009709 copy_ds_update.srcBinding = 1; // Copy from SAMPLER binding
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009710 copy_ds_update.dstSet = descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -07009711 copy_ds_update.dstBinding = 0; // ERROR : copy to UNIFORM binding
Chia-I Wud50a7d72015-10-26 20:48:51 +08009712 copy_ds_update.descriptorCount = 1; // copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -06009713 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
9714
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009715 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -06009716 // Now perform a copy update that fails due to binding out of bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009717 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 -06009718 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
9719 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
9720 copy_ds_update.srcSet = descriptorSet;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009721 copy_ds_update.srcBinding = 3; // ERROR : Invalid binding for matching layout
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009722 copy_ds_update.dstSet = descriptorSet;
9723 copy_ds_update.dstBinding = 0;
Mark Young29927482016-05-04 14:38:51 -06009724 copy_ds_update.descriptorCount = 1; // Copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -06009725 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
9726
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009727 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009728
Tobin Ehlis04356f92015-10-27 16:35:27 -06009729 // Now perform a copy update that fails due to binding out of bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009730 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " binding#1 with offset index of 1 plus "
9731 "update array offset of 0 and update of "
9732 "5 descriptors oversteps total number "
9733 "of descriptors in set: 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009734
Tobin Ehlis04356f92015-10-27 16:35:27 -06009735 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
9736 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
9737 copy_ds_update.srcSet = descriptorSet;
9738 copy_ds_update.srcBinding = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009739 copy_ds_update.dstSet = descriptorSet;
9740 copy_ds_update.dstBinding = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009741 copy_ds_update.descriptorCount = 5; // ERROR copy 5 descriptors (out of bounds for layout)
Tobin Ehlis04356f92015-10-27 16:35:27 -06009742 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
9743
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009744 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -06009745
Chia-I Wuf7458c52015-10-26 21:10:41 +08009746 vkDestroySampler(m_device->device(), sampler, NULL);
9747 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9748 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis04356f92015-10-27 16:35:27 -06009749}
9750
Karl Schultz6addd812016-02-02 17:17:23 -07009751TEST_F(VkLayerTest, NumSamplesMismatch) {
9752 // Create CommandBuffer where MSAA samples doesn't match RenderPass
9753 // sampleCount
9754 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009755
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009756 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Num samples mismatch! ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009757
Tobin Ehlis3b780662015-05-28 12:11:26 -06009758 ASSERT_NO_FATAL_FAILURE(InitState());
9759 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009760 VkDescriptorPoolSize ds_type_count = {};
Tony Barboureb254902015-07-15 12:50:33 -06009761 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009762 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009763
9764 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009765 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9766 ds_pool_ci.pNext = NULL;
9767 ds_pool_ci.maxSets = 1;
9768 ds_pool_ci.poolSizeCount = 1;
9769 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06009770
Tobin Ehlis3b780662015-05-28 12:11:26 -06009771 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009772 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009773 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009774
Tony Barboureb254902015-07-15 12:50:33 -06009775 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08009776 dsl_binding.binding = 0;
Tony Barboureb254902015-07-15 12:50:33 -06009777 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08009778 dsl_binding.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009779 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9780 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009781
Tony Barboureb254902015-07-15 12:50:33 -06009782 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9783 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9784 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009785 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07009786 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06009787
Tobin Ehlis3b780662015-05-28 12:11:26 -06009788 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009789 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009790 ASSERT_VK_SUCCESS(err);
9791
9792 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009793 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009794 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009795 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009796 alloc_info.descriptorPool = ds_pool;
9797 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009798 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009799 ASSERT_VK_SUCCESS(err);
9800
Tony Barboureb254902015-07-15 12:50:33 -06009801 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009802 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07009803 pipe_ms_state_ci.pNext = NULL;
9804 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
9805 pipe_ms_state_ci.sampleShadingEnable = 0;
9806 pipe_ms_state_ci.minSampleShading = 1.0;
9807 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009808
Tony Barboureb254902015-07-15 12:50:33 -06009809 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009810 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9811 pipeline_layout_ci.pNext = NULL;
9812 pipeline_layout_ci.setLayoutCount = 1;
9813 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009814
9815 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009816 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009817 ASSERT_VK_SUCCESS(err);
9818
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009819 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
9820 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
9821 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -06009822 VkPipelineObj pipe(m_device);
9823 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06009824 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -06009825 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -06009826 pipe.SetMSAA(&pipe_ms_state_ci);
9827 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tobin Ehlis3b780662015-05-28 12:11:26 -06009828
Tony Barbourfe3351b2015-07-28 10:17:20 -06009829 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009830 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis3b780662015-05-28 12:11:26 -06009831
Mark Young29927482016-05-04 14:38:51 -06009832 // Render triangle (the error should trigger on the attempt to draw).
9833 Draw(3, 1, 0, 0);
9834
9835 // Finalize recording of the command buffer
9836 EndCommandBuffer();
9837
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009838 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009839
Chia-I Wuf7458c52015-10-26 21:10:41 +08009840 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9841 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9842 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009843}
Mark Young29927482016-05-04 14:38:51 -06009844
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009845TEST_F(VkLayerTest, RenderPassIncompatible) {
9846 TEST_DESCRIPTION("Hit RenderPass incompatible cases. "
9847 "Initial case is drawing with an active renderpass that's "
Mike Weiblencce7ec72016-10-17 19:33:05 -06009848 "not compatible with the bound pipeline state object's creation renderpass");
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009849 VkResult err;
9850
9851 ASSERT_NO_FATAL_FAILURE(InitState());
9852 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9853
9854 VkDescriptorSetLayoutBinding dsl_binding = {};
9855 dsl_binding.binding = 0;
9856 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9857 dsl_binding.descriptorCount = 1;
9858 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9859 dsl_binding.pImmutableSamplers = NULL;
9860
9861 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9862 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9863 ds_layout_ci.pNext = NULL;
9864 ds_layout_ci.bindingCount = 1;
9865 ds_layout_ci.pBindings = &dsl_binding;
9866
9867 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009868 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009869 ASSERT_VK_SUCCESS(err);
9870
9871 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
9872 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9873 pipeline_layout_ci.pNext = NULL;
9874 pipeline_layout_ci.setLayoutCount = 1;
9875 pipeline_layout_ci.pSetLayouts = &ds_layout;
9876
9877 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009878 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009879 ASSERT_VK_SUCCESS(err);
9880
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009881 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
9882 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
9883 // but add it to be able to run on more devices
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009884 // Create a renderpass that will be incompatible with default renderpass
9885 VkAttachmentReference attach = {};
9886 attach.layout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
9887 VkAttachmentReference color_att = {};
9888 color_att.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
9889 VkSubpassDescription subpass = {};
9890 subpass.inputAttachmentCount = 1;
9891 subpass.pInputAttachments = &attach;
9892 subpass.colorAttachmentCount = 1;
9893 subpass.pColorAttachments = &color_att;
9894 VkRenderPassCreateInfo rpci = {};
9895 rpci.subpassCount = 1;
9896 rpci.pSubpasses = &subpass;
9897 rpci.attachmentCount = 1;
9898 VkAttachmentDescription attach_desc = {};
9899 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
Cody Northropbd16af12016-06-21 09:25:48 -06009900 // Format incompatible with PSO RP color attach format B8G8R8A8_UNORM
9901 attach_desc.format = VK_FORMAT_R8G8B8A8_UNORM;
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009902 rpci.pAttachments = &attach_desc;
9903 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
9904 VkRenderPass rp;
9905 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
9906 VkPipelineObj pipe(m_device);
9907 pipe.AddShader(&vs);
9908 pipe.AddShader(&fs);
9909 pipe.AddColorAttachment();
9910 VkViewport view_port = {};
9911 m_viewports.push_back(view_port);
9912 pipe.SetViewport(m_viewports);
9913 VkRect2D rect = {};
9914 m_scissors.push_back(rect);
9915 pipe.SetScissor(m_scissors);
9916 pipe.CreateVKPipeline(pipeline_layout, renderPass());
9917
9918 VkCommandBufferInheritanceInfo cbii = {};
9919 cbii.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
9920 cbii.renderPass = rp;
9921 cbii.subpass = 0;
9922 VkCommandBufferBeginInfo cbbi = {};
9923 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
9924 cbbi.pInheritanceInfo = &cbii;
9925 vkBeginCommandBuffer(m_commandBuffer->handle(), &cbbi);
9926 VkRenderPassBeginInfo rpbi = {};
9927 rpbi.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
9928 rpbi.framebuffer = m_framebuffer;
9929 rpbi.renderPass = rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009930 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
9931 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009932
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009933 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is incompatible w/ gfx pipeline ");
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009934 // Render triangle (the error should trigger on the attempt to draw).
9935 Draw(3, 1, 0, 0);
9936
9937 // Finalize recording of the command buffer
9938 EndCommandBuffer();
9939
9940 m_errorMonitor->VerifyFound();
9941
9942 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9943 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9944 vkDestroyRenderPass(m_device->device(), rp, NULL);
9945}
9946
Mark Youngc89c6312016-03-31 16:03:20 -06009947TEST_F(VkLayerTest, NumBlendAttachMismatch) {
9948 // Create Pipeline where the number of blend attachments doesn't match the
9949 // number of color attachments. In this case, we don't add any color
9950 // blend attachments even though we have a color attachment.
9951 VkResult err;
9952
9953 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009954 "Render pass subpass 0 mismatch with blending state defined and blend state attachment");
Mark Youngc89c6312016-03-31 16:03:20 -06009955
9956 ASSERT_NO_FATAL_FAILURE(InitState());
9957 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9958 VkDescriptorPoolSize ds_type_count = {};
9959 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9960 ds_type_count.descriptorCount = 1;
9961
9962 VkDescriptorPoolCreateInfo ds_pool_ci = {};
9963 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9964 ds_pool_ci.pNext = NULL;
9965 ds_pool_ci.maxSets = 1;
9966 ds_pool_ci.poolSizeCount = 1;
9967 ds_pool_ci.pPoolSizes = &ds_type_count;
9968
9969 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009970 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Mark Youngc89c6312016-03-31 16:03:20 -06009971 ASSERT_VK_SUCCESS(err);
9972
9973 VkDescriptorSetLayoutBinding dsl_binding = {};
9974 dsl_binding.binding = 0;
9975 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9976 dsl_binding.descriptorCount = 1;
9977 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9978 dsl_binding.pImmutableSamplers = NULL;
9979
9980 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9981 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9982 ds_layout_ci.pNext = NULL;
9983 ds_layout_ci.bindingCount = 1;
9984 ds_layout_ci.pBindings = &dsl_binding;
9985
9986 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009987 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Youngc89c6312016-03-31 16:03:20 -06009988 ASSERT_VK_SUCCESS(err);
9989
9990 VkDescriptorSet descriptorSet;
9991 VkDescriptorSetAllocateInfo alloc_info = {};
9992 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
9993 alloc_info.descriptorSetCount = 1;
9994 alloc_info.descriptorPool = ds_pool;
9995 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009996 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Youngc89c6312016-03-31 16:03:20 -06009997 ASSERT_VK_SUCCESS(err);
9998
9999 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010000 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Mark Youngc89c6312016-03-31 16:03:20 -060010001 pipe_ms_state_ci.pNext = NULL;
10002 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
10003 pipe_ms_state_ci.sampleShadingEnable = 0;
10004 pipe_ms_state_ci.minSampleShading = 1.0;
10005 pipe_ms_state_ci.pSampleMask = NULL;
10006
10007 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
10008 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10009 pipeline_layout_ci.pNext = NULL;
10010 pipeline_layout_ci.setLayoutCount = 1;
10011 pipeline_layout_ci.pSetLayouts = &ds_layout;
10012
10013 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010014 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Mark Youngc89c6312016-03-31 16:03:20 -060010015 ASSERT_VK_SUCCESS(err);
10016
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010017 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
10018 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
10019 // but add it to be able to run on more devices
Mark Youngc89c6312016-03-31 16:03:20 -060010020 VkPipelineObj pipe(m_device);
10021 pipe.AddShader(&vs);
10022 pipe.AddShader(&fs);
10023 pipe.SetMSAA(&pipe_ms_state_ci);
10024 pipe.CreateVKPipeline(pipeline_layout, renderPass());
10025
10026 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010027 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Mark Youngc89c6312016-03-31 16:03:20 -060010028
Mark Young29927482016-05-04 14:38:51 -060010029 // Render triangle (the error should trigger on the attempt to draw).
10030 Draw(3, 1, 0, 0);
10031
10032 // Finalize recording of the command buffer
10033 EndCommandBuffer();
10034
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010035 m_errorMonitor->VerifyFound();
Mark Youngc89c6312016-03-31 16:03:20 -060010036
10037 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10038 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10039 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
10040}
Mark Young29927482016-05-04 14:38:51 -060010041
Mark Muellerd4914412016-06-13 17:52:06 -060010042TEST_F(VkLayerTest, MissingClearAttachment) {
10043 TEST_DESCRIPTION("Points to a wrong colorAttachment index in a VkClearAttachment "
10044 "structure passed to vkCmdClearAttachments");
Cody Northropc31a84f2016-08-22 10:41:47 -060010045 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesda6ae6f2016-09-09 14:36:33 +120010046 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbesfa79fc72016-11-01 10:18:12 +130010047 "vkCmdClearAttachments() color attachment index 1 out of range for active subpass 0");
Mark Muellerd4914412016-06-13 17:52:06 -060010048
10049 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailCmdClearAttachments);
10050 m_errorMonitor->VerifyFound();
10051}
10052
Karl Schultz6addd812016-02-02 17:17:23 -070010053TEST_F(VkLayerTest, ClearCmdNoDraw) {
10054 // Create CommandBuffer where we add ClearCmd for FB Color attachment prior
10055 // to issuing a Draw
10056 VkResult err;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010057
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010058 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Mike Weiblencce7ec72016-10-17 19:33:05 -060010059 "vkCmdClearAttachments() issued on command buffer object ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010060
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010061 ASSERT_NO_FATAL_FAILURE(InitState());
10062 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -060010063
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010064 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010065 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10066 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010067
10068 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010069 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10070 ds_pool_ci.pNext = NULL;
10071 ds_pool_ci.maxSets = 1;
10072 ds_pool_ci.poolSizeCount = 1;
10073 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060010074
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010075 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010076 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010077 ASSERT_VK_SUCCESS(err);
10078
Tony Barboureb254902015-07-15 12:50:33 -060010079 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010080 dsl_binding.binding = 0;
10081 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10082 dsl_binding.descriptorCount = 1;
10083 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10084 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010085
Tony Barboureb254902015-07-15 12:50:33 -060010086 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010087 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10088 ds_layout_ci.pNext = NULL;
10089 ds_layout_ci.bindingCount = 1;
10090 ds_layout_ci.pBindings = &dsl_binding;
Mark Lobodzinski209b5292015-09-17 09:44:05 -060010091
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010092 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010093 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010094 ASSERT_VK_SUCCESS(err);
10095
10096 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010097 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010098 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010099 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060010100 alloc_info.descriptorPool = ds_pool;
10101 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010102 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010103 ASSERT_VK_SUCCESS(err);
10104
Tony Barboureb254902015-07-15 12:50:33 -060010105 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010106 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070010107 pipe_ms_state_ci.pNext = NULL;
10108 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
10109 pipe_ms_state_ci.sampleShadingEnable = 0;
10110 pipe_ms_state_ci.minSampleShading = 1.0;
10111 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010112
Tony Barboureb254902015-07-15 12:50:33 -060010113 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010114 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10115 pipeline_layout_ci.pNext = NULL;
10116 pipeline_layout_ci.setLayoutCount = 1;
10117 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010118
10119 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010120 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010121 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski209b5292015-09-17 09:44:05 -060010122
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010123 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -060010124 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -070010125 // on more devices
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010126 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010127
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010128 VkPipelineObj pipe(m_device);
10129 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -060010130 pipe.AddShader(&fs);
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010131 pipe.SetMSAA(&pipe_ms_state_ci);
10132 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -060010133
10134 BeginCommandBuffer();
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010135
Karl Schultz6addd812016-02-02 17:17:23 -070010136 // Main thing we care about for this test is that the VkImage obj we're
10137 // clearing matches Color Attachment of FB
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010138 // Also pass down other dummy params to keep driver and paramchecker happy
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -060010139 VkClearAttachment color_attachment;
10140 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10141 color_attachment.clearValue.color.float32[0] = 1.0;
10142 color_attachment.clearValue.color.float32[1] = 1.0;
10143 color_attachment.clearValue.color.float32[2] = 1.0;
10144 color_attachment.clearValue.color.float32[3] = 1.0;
10145 color_attachment.colorAttachment = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010146 VkClearRect clear_rect = {{{0, 0}, {(uint32_t)m_width, (uint32_t)m_height}}};
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010147
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010148 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010149
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010150 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010151
Chia-I Wuf7458c52015-10-26 21:10:41 +080010152 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10153 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10154 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010155}
10156
Karl Schultz6addd812016-02-02 17:17:23 -070010157TEST_F(VkLayerTest, VtxBufferBadIndex) {
10158 VkResult err;
Tobin Ehlis502480b2015-06-24 15:53:07 -060010159
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010160 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10161 "but no vertex buffers are attached to this Pipeline State Object");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010162
Tobin Ehlis502480b2015-06-24 15:53:07 -060010163 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisd332f282015-10-02 11:00:56 -060010164 ASSERT_NO_FATAL_FAILURE(InitViewport());
Tobin Ehlis502480b2015-06-24 15:53:07 -060010165 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -060010166
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010167 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010168 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10169 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010170
10171 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010172 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10173 ds_pool_ci.pNext = NULL;
10174 ds_pool_ci.maxSets = 1;
10175 ds_pool_ci.poolSizeCount = 1;
10176 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060010177
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -060010178 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010179 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis502480b2015-06-24 15:53:07 -060010180 ASSERT_VK_SUCCESS(err);
10181
Tony Barboureb254902015-07-15 12:50:33 -060010182 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010183 dsl_binding.binding = 0;
10184 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10185 dsl_binding.descriptorCount = 1;
10186 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10187 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -060010188
Tony Barboureb254902015-07-15 12:50:33 -060010189 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010190 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10191 ds_layout_ci.pNext = NULL;
10192 ds_layout_ci.bindingCount = 1;
10193 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060010194
Tobin Ehlis502480b2015-06-24 15:53:07 -060010195 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010196 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -060010197 ASSERT_VK_SUCCESS(err);
10198
10199 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010200 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010201 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010202 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060010203 alloc_info.descriptorPool = ds_pool;
10204 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010205 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis502480b2015-06-24 15:53:07 -060010206 ASSERT_VK_SUCCESS(err);
10207
Tony Barboureb254902015-07-15 12:50:33 -060010208 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010209 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070010210 pipe_ms_state_ci.pNext = NULL;
10211 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
10212 pipe_ms_state_ci.sampleShadingEnable = 0;
10213 pipe_ms_state_ci.minSampleShading = 1.0;
10214 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -060010215
Tony Barboureb254902015-07-15 12:50:33 -060010216 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010217 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10218 pipeline_layout_ci.pNext = NULL;
10219 pipeline_layout_ci.setLayoutCount = 1;
10220 pipeline_layout_ci.pSetLayouts = &ds_layout;
10221 VkPipelineLayout pipeline_layout;
Tobin Ehlis502480b2015-06-24 15:53:07 -060010222
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010223 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -060010224 ASSERT_VK_SUCCESS(err);
10225
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010226 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
10227 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
10228 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010229 VkPipelineObj pipe(m_device);
10230 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -060010231 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -060010232 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010233 pipe.SetMSAA(&pipe_ms_state_ci);
Tobin Ehlisd332f282015-10-02 11:00:56 -060010234 pipe.SetViewport(m_viewports);
10235 pipe.SetScissor(m_scissors);
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010236 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -060010237
10238 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010239 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisf7bf4502015-09-09 15:12:35 -060010240 // Don't care about actual data, just need to get to draw to flag error
10241 static const float vbo_data[3] = {1.f, 0.f, 1.f};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010242 VkConstantBufferObj vbo(m_device, sizeof(vbo_data), sizeof(float), (const void *)&vbo_data);
Tobin Ehlisf7bf4502015-09-09 15:12:35 -060010243 BindVertexBuffer(&vbo, (VkDeviceSize)0, 1); // VBO idx 1, but no VBO in PSO
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -060010244 Draw(1, 0, 0, 0);
Tobin Ehlis502480b2015-06-24 15:53:07 -060010245
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010246 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010247
Chia-I Wuf7458c52015-10-26 21:10:41 +080010248 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10249 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10250 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis502480b2015-06-24 15:53:07 -060010251}
Mark Muellerdfe37552016-07-07 14:47:42 -060010252
Mark Mueller2ee294f2016-08-04 12:59:48 -060010253TEST_F(VkLayerTest, MismatchCountQueueCreateRequestedFeature) {
10254 TEST_DESCRIPTION("Use an invalid count in a vkEnumeratePhysicalDevices call."
10255 "Use invalid Queue Family Index in vkCreateDevice");
Cody Northropc31a84f2016-08-22 10:41:47 -060010256 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Mueller2ee294f2016-08-04 12:59:48 -060010257
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010258 const char *mismatch_count_message = "Call to vkEnumeratePhysicalDevices() "
10259 "w/ pPhysicalDeviceCount value ";
Mark Mueller2ee294f2016-08-04 12:59:48 -060010260
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010261 const char *invalid_queueFamilyIndex_message = "Invalid queue create request in vkCreateDevice(). Invalid "
10262 "queueFamilyIndex ";
Mark Mueller2ee294f2016-08-04 12:59:48 -060010263
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010264 const char *unavailable_feature_message = "While calling vkCreateDevice(), requesting feature #";
Mark Mueller2ee294f2016-08-04 12:59:48 -060010265
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010266 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, mismatch_count_message);
Mark Mueller880fce52016-08-17 15:23:23 -060010267 // The following test fails with recent NVidia drivers.
10268 // By the time core_validation is reached, the NVidia
10269 // driver has sanitized the invalid condition and core_validation
10270 // is not introduced to the failure condition. This is not the case
10271 // with AMD and Mesa drivers. Futher investigation is required
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010272 // uint32_t count = static_cast<uint32_t>(~0);
10273 // VkPhysicalDevice physical_device;
10274 // vkEnumeratePhysicalDevices(instance(), &count, &physical_device);
10275 // m_errorMonitor->VerifyFound();
Mark Mueller2ee294f2016-08-04 12:59:48 -060010276
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010277 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_queueFamilyIndex_message);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010278 float queue_priority = 0.0;
10279
10280 VkDeviceQueueCreateInfo queue_create_info = {};
10281 queue_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
10282 queue_create_info.queueCount = 1;
10283 queue_create_info.pQueuePriorities = &queue_priority;
10284 queue_create_info.queueFamilyIndex = static_cast<uint32_t>(~0);
10285
10286 VkPhysicalDeviceFeatures features = m_device->phy().features();
10287 VkDevice testDevice;
10288 VkDeviceCreateInfo device_create_info = {};
10289 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
10290 device_create_info.queueCreateInfoCount = 1;
10291 device_create_info.pQueueCreateInfos = &queue_create_info;
10292 device_create_info.pEnabledFeatures = &features;
10293 vkCreateDevice(gpu(), &device_create_info, nullptr, &testDevice);
10294 m_errorMonitor->VerifyFound();
10295
10296 queue_create_info.queueFamilyIndex = 1;
10297
10298 unsigned feature_count = sizeof(VkPhysicalDeviceFeatures) / sizeof(VkBool32);
10299 VkBool32 *feature_array = reinterpret_cast<VkBool32 *>(&features);
10300 for (unsigned i = 0; i < feature_count; i++) {
10301 if (VK_FALSE == feature_array[i]) {
10302 feature_array[i] = VK_TRUE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010303 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, unavailable_feature_message);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010304 device_create_info.pEnabledFeatures = &features;
10305 vkCreateDevice(gpu(), &device_create_info, nullptr, &testDevice);
10306 m_errorMonitor->VerifyFound();
10307 break;
10308 }
10309 }
10310}
10311
Tobin Ehlis16edf082016-11-21 12:33:49 -070010312TEST_F(VkLayerTest, InvalidQueryPoolCreate) {
10313 TEST_DESCRIPTION("Attempt to create a query pool for PIPELINE_STATISTICS without enabling pipeline stats for the device.");
10314
10315 ASSERT_NO_FATAL_FAILURE(InitState());
10316
10317 const std::vector<VkQueueFamilyProperties> queue_props = m_device->queue_props;
10318 std::vector<VkDeviceQueueCreateInfo> queue_info;
10319 queue_info.reserve(queue_props.size());
10320 std::vector<std::vector<float>> queue_priorities;
10321 for (uint32_t i = 0; i < (uint32_t)queue_props.size(); i++) {
10322 VkDeviceQueueCreateInfo qi{};
10323 qi.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
10324 qi.queueFamilyIndex = i;
10325 qi.queueCount = queue_props[i].queueCount;
10326 queue_priorities.emplace_back(qi.queueCount, 0.0f);
10327 qi.pQueuePriorities = queue_priorities[i].data();
10328 queue_info.push_back(qi);
10329 }
10330
10331 std::vector<const char *> device_extension_names;
10332
10333 VkDevice local_device;
10334 VkDeviceCreateInfo device_create_info = {};
10335 auto features = m_device->phy().features();
10336 // Intentionally disable pipeline stats
10337 features.pipelineStatisticsQuery = VK_FALSE;
10338 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
10339 device_create_info.pNext = NULL;
10340 device_create_info.queueCreateInfoCount = queue_info.size();
10341 device_create_info.pQueueCreateInfos = queue_info.data();
10342 device_create_info.enabledLayerCount = 0;
10343 device_create_info.ppEnabledLayerNames = NULL;
10344 device_create_info.pEnabledFeatures = &features;
10345 VkResult err = vkCreateDevice(gpu(), &device_create_info, nullptr, &local_device);
10346 ASSERT_VK_SUCCESS(err);
10347
10348 VkQueryPoolCreateInfo qpci{};
10349 qpci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
10350 qpci.queryType = VK_QUERY_TYPE_PIPELINE_STATISTICS;
10351 qpci.queryCount = 1;
10352 VkQueryPool query_pool;
10353
10354 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01006);
10355 vkCreateQueryPool(local_device, &qpci, nullptr, &query_pool);
10356 m_errorMonitor->VerifyFound();
10357
10358 vkDestroyDevice(local_device, nullptr);
10359}
10360
Mark Mueller2ee294f2016-08-04 12:59:48 -060010361TEST_F(VkLayerTest, InvalidQueueIndexInvalidQuery) {
10362 TEST_DESCRIPTION("Use an invalid queue index in a vkCmdWaitEvents call."
10363 "End a command buffer with a query still in progress.");
10364
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010365 const char *invalid_queue_index = "was created with sharingMode of VK_SHARING_MODE_EXCLUSIVE. If one "
10366 "of src- or dstQueueFamilyIndex is VK_QUEUE_FAMILY_IGNORED, both "
10367 "must be.";
Mark Mueller2ee294f2016-08-04 12:59:48 -060010368
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010369 const char *invalid_query = "Ending command buffer with in progress query: queryPool 0x";
Mark Mueller2ee294f2016-08-04 12:59:48 -060010370
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010371 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_queue_index);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010372
10373 ASSERT_NO_FATAL_FAILURE(InitState());
10374
10375 VkEvent event;
10376 VkEventCreateInfo event_create_info{};
10377 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
10378 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
10379
Mark Mueller2ee294f2016-08-04 12:59:48 -060010380 VkQueue queue = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010381 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010382
10383 BeginCommandBuffer();
10384
10385 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010386 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 -060010387 ASSERT_TRUE(image.initialized());
10388 VkImageMemoryBarrier img_barrier = {};
10389 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
10390 img_barrier.pNext = NULL;
10391 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
10392 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
10393 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
10394 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
10395 img_barrier.image = image.handle();
10396 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
Mark Lobodzinski2a74c5c2016-08-17 13:26:28 -060010397
10398 // QueueFamilyIndex must be VK_QUEUE_FAMILY_IGNORED, this verifies
10399 // that layer validation catches the case when it is not.
10400 img_barrier.dstQueueFamilyIndex = 0;
Mark Mueller2ee294f2016-08-04 12:59:48 -060010401 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10402 img_barrier.subresourceRange.baseArrayLayer = 0;
10403 img_barrier.subresourceRange.baseMipLevel = 0;
10404 img_barrier.subresourceRange.layerCount = 1;
10405 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010406 vkCmdWaitEvents(m_commandBuffer->handle(), 1, &event, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0,
10407 nullptr, 0, nullptr, 1, &img_barrier);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010408 m_errorMonitor->VerifyFound();
10409
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010410 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_query);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010411
10412 VkQueryPool query_pool;
10413 VkQueryPoolCreateInfo query_pool_create_info = {};
10414 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
10415 query_pool_create_info.queryType = VK_QUERY_TYPE_OCCLUSION;
10416 query_pool_create_info.queryCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010417 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010418
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010419 vkCmdResetQueryPool(m_commandBuffer->handle(), query_pool, 0 /*startQuery*/, 1 /*queryCount*/);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010420 vkCmdBeginQuery(m_commandBuffer->handle(), query_pool, 0, 0);
10421
10422 vkEndCommandBuffer(m_commandBuffer->handle());
10423 m_errorMonitor->VerifyFound();
10424
10425 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
10426 vkDestroyEvent(m_device->device(), event, nullptr);
10427}
10428
Mark Muellerdfe37552016-07-07 14:47:42 -060010429TEST_F(VkLayerTest, VertexBufferInvalid) {
10430 TEST_DESCRIPTION("Submit a command buffer using deleted vertex buffer, "
10431 "delete a buffer twice, use an invalid offset for each "
10432 "buffer type, and attempt to bind a null buffer");
10433
10434 const char *deleted_buffer_in_command_buffer = "Cannot submit cmd buffer "
10435 "using deleted buffer ";
Mark Muellerdfe37552016-07-07 14:47:42 -060010436 const char *invalid_offset_message = "vkBindBufferMemory(): "
10437 "memoryOffset is 0x";
10438 const char *invalid_storage_buffer_offset_message = "vkBindBufferMemory(): "
10439 "storage memoryOffset "
10440 "is 0x";
10441 const char *invalid_texel_buffer_offset_message = "vkBindBufferMemory(): "
10442 "texel memoryOffset "
10443 "is 0x";
10444 const char *invalid_uniform_buffer_offset_message = "vkBindBufferMemory(): "
10445 "uniform memoryOffset "
10446 "is 0x";
Mark Muellerdfe37552016-07-07 14:47:42 -060010447
10448 ASSERT_NO_FATAL_FAILURE(InitState());
10449 ASSERT_NO_FATAL_FAILURE(InitViewport());
10450 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10451
10452 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010453 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Mark Muellerdfe37552016-07-07 14:47:42 -060010454 pipe_ms_state_ci.pNext = NULL;
10455 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
10456 pipe_ms_state_ci.sampleShadingEnable = 0;
10457 pipe_ms_state_ci.minSampleShading = 1.0;
10458 pipe_ms_state_ci.pSampleMask = nullptr;
10459
10460 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
10461 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10462 VkPipelineLayout pipeline_layout;
10463
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010464 VkResult err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, nullptr, &pipeline_layout);
Mark Muellerdfe37552016-07-07 14:47:42 -060010465 ASSERT_VK_SUCCESS(err);
10466
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010467 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
10468 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Muellerdfe37552016-07-07 14:47:42 -060010469 VkPipelineObj pipe(m_device);
10470 pipe.AddShader(&vs);
10471 pipe.AddShader(&fs);
10472 pipe.AddColorAttachment();
10473 pipe.SetMSAA(&pipe_ms_state_ci);
10474 pipe.SetViewport(m_viewports);
10475 pipe.SetScissor(m_scissors);
10476 pipe.CreateVKPipeline(pipeline_layout, renderPass());
10477
10478 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010479 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Mark Muellerdfe37552016-07-07 14:47:42 -060010480
10481 {
10482 // Create and bind a vertex buffer in a reduced scope, which will cause
10483 // it to be deleted upon leaving this scope
10484 const float vbo_data[3] = {1.f, 0.f, 1.f};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010485 VkVerticesObj draw_verticies(m_device, 1, 1, sizeof(vbo_data), 3, vbo_data);
Mark Muellerdfe37552016-07-07 14:47:42 -060010486 draw_verticies.BindVertexBuffers(m_commandBuffer->handle());
10487 draw_verticies.AddVertexInputToPipe(pipe);
10488 }
10489
10490 Draw(1, 0, 0, 0);
10491
10492 EndCommandBuffer();
10493
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010494 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, deleted_buffer_in_command_buffer);
Mark Muellerdfe37552016-07-07 14:47:42 -060010495 QueueCommandBuffer(false);
10496 m_errorMonitor->VerifyFound();
10497
10498 {
10499 // Create and bind a vertex buffer in a reduced scope, and delete it
10500 // twice, the second through the destructor
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010501 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eDoubleDelete);
Karl Schultzf78bcdd2016-11-30 12:36:01 -070010502 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00680);
Mark Muellerdfe37552016-07-07 14:47:42 -060010503 buffer_test.TestDoubleDestroy();
10504 }
10505 m_errorMonitor->VerifyFound();
10506
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010507 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidMemoryOffset)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060010508 // Create and bind a memory buffer with an invalid offset.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010509 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_offset_message);
10510 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT, VkBufferTest::eInvalidMemoryOffset);
10511 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010512 m_errorMonitor->VerifyFound();
10513 }
10514
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010515 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset,
10516 VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060010517 // Create and bind a memory buffer with an invalid offset again,
10518 // but look for a texel buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010519 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_texel_buffer_offset_message);
10520 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
10521 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010522 m_errorMonitor->VerifyFound();
10523 }
10524
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010525 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060010526 // Create and bind a memory buffer with an invalid offset again, but
10527 // look for a uniform buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010528 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_uniform_buffer_offset_message);
10529 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
10530 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010531 m_errorMonitor->VerifyFound();
10532 }
10533
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010534 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060010535 // Create and bind a memory buffer with an invalid offset again, but
10536 // look for a storage buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010537 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_storage_buffer_offset_message);
10538 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
10539 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010540 m_errorMonitor->VerifyFound();
10541 }
10542
10543 {
10544 // Attempt to bind a null buffer.
Karl Schultzf78bcdd2016-11-30 12:36:01 -070010545 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00799);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010546 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eBindNullBuffer);
10547 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010548 m_errorMonitor->VerifyFound();
10549 }
10550
10551 {
10552 // Attempt to use an invalid handle to delete a buffer.
Karl Schultzf78bcdd2016-11-30 12:36:01 -070010553 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00622);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010554 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eFreeInvalidHandle);
10555 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010556 }
10557 m_errorMonitor->VerifyFound();
10558
10559 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10560}
10561
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010562// INVALID_IMAGE_LAYOUT tests (one other case is hit by MapMemWithoutHostVisibleBit and not here)
10563TEST_F(VkLayerTest, InvalidImageLayout) {
10564 TEST_DESCRIPTION("Hit all possible validation checks associated with the "
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010565 "DRAWSTATE_INVALID_IMAGE_LAYOUT enum. Generally these involve having"
10566 "images in the wrong layout when they're copied or transitioned.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010567 // 3 in ValidateCmdBufImageLayouts
10568 // * -1 Attempt to submit cmd buf w/ deleted image
10569 // * -2 Cmd buf submit of image w/ layout not matching first use w/ subresource
10570 // * -3 Cmd buf submit of image w/ layout not matching first use w/o subresource
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010571
10572 ASSERT_NO_FATAL_FAILURE(InitState());
10573 // Create src & dst images to use for copy operations
10574 VkImage src_image;
10575 VkImage dst_image;
Cort3b021012016-12-07 12:00:57 -080010576 VkImage depth_image;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010577
10578 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
10579 const int32_t tex_width = 32;
10580 const int32_t tex_height = 32;
10581
10582 VkImageCreateInfo image_create_info = {};
10583 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
10584 image_create_info.pNext = NULL;
10585 image_create_info.imageType = VK_IMAGE_TYPE_2D;
10586 image_create_info.format = tex_format;
10587 image_create_info.extent.width = tex_width;
10588 image_create_info.extent.height = tex_height;
10589 image_create_info.extent.depth = 1;
10590 image_create_info.mipLevels = 1;
10591 image_create_info.arrayLayers = 4;
10592 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
10593 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
10594 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Cort3b021012016-12-07 12:00:57 -080010595 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010596 image_create_info.flags = 0;
10597
10598 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &src_image);
10599 ASSERT_VK_SUCCESS(err);
Cort3b021012016-12-07 12:00:57 -080010600 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010601 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dst_image);
10602 ASSERT_VK_SUCCESS(err);
Cort3b021012016-12-07 12:00:57 -080010603 image_create_info.format = VK_FORMAT_D32_SFLOAT;
10604 image_create_info.usage |= VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
10605 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &depth_image);
10606 ASSERT_VK_SUCCESS(err);
10607
10608 // Allocate memory
10609 VkMemoryRequirements img_mem_reqs = {};
Cort530cf382016-12-08 09:59:47 -080010610 VkMemoryAllocateInfo mem_alloc = {};
Cort3b021012016-12-07 12:00:57 -080010611 VkDeviceMemory src_image_mem, dst_image_mem, depth_image_mem;
Cort530cf382016-12-08 09:59:47 -080010612 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
10613 mem_alloc.pNext = NULL;
10614 mem_alloc.allocationSize = 0;
10615 mem_alloc.memoryTypeIndex = 0;
Cort3b021012016-12-07 12:00:57 -080010616
10617 vkGetImageMemoryRequirements(m_device->device(), src_image, &img_mem_reqs);
Cort530cf382016-12-08 09:59:47 -080010618 mem_alloc.allocationSize = img_mem_reqs.size;
10619 bool pass = m_device->phy().set_memory_type(img_mem_reqs.memoryTypeBits, &mem_alloc, 0);
Cort3b021012016-12-07 12:00:57 -080010620 ASSERT_TRUE(pass);
Cort530cf382016-12-08 09:59:47 -080010621 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &src_image_mem);
Cort3b021012016-12-07 12:00:57 -080010622 ASSERT_VK_SUCCESS(err);
10623
10624 vkGetImageMemoryRequirements(m_device->device(), dst_image, &img_mem_reqs);
Cort530cf382016-12-08 09:59:47 -080010625 mem_alloc.allocationSize = img_mem_reqs.size;
10626 pass = m_device->phy().set_memory_type(img_mem_reqs.memoryTypeBits, &mem_alloc, 0);
Cort3b021012016-12-07 12:00:57 -080010627 ASSERT_VK_SUCCESS(err);
Cort530cf382016-12-08 09:59:47 -080010628 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &dst_image_mem);
Cort3b021012016-12-07 12:00:57 -080010629 ASSERT_VK_SUCCESS(err);
10630
10631 vkGetImageMemoryRequirements(m_device->device(), depth_image, &img_mem_reqs);
Cort530cf382016-12-08 09:59:47 -080010632 mem_alloc.allocationSize = img_mem_reqs.size;
10633 pass = m_device->phy().set_memory_type(img_mem_reqs.memoryTypeBits, &mem_alloc, 0);
Cort3b021012016-12-07 12:00:57 -080010634 ASSERT_VK_SUCCESS(err);
Cort530cf382016-12-08 09:59:47 -080010635 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &depth_image_mem);
Cort3b021012016-12-07 12:00:57 -080010636 ASSERT_VK_SUCCESS(err);
10637
10638 err = vkBindImageMemory(m_device->device(), src_image, src_image_mem, 0);
10639 ASSERT_VK_SUCCESS(err);
10640 err = vkBindImageMemory(m_device->device(), dst_image, dst_image_mem, 0);
10641 ASSERT_VK_SUCCESS(err);
10642 err = vkBindImageMemory(m_device->device(), depth_image, depth_image_mem, 0);
10643 ASSERT_VK_SUCCESS(err);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010644
10645 BeginCommandBuffer();
Cort530cf382016-12-08 09:59:47 -080010646 VkImageCopy copy_region;
10647 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10648 copy_region.srcSubresource.mipLevel = 0;
10649 copy_region.srcSubresource.baseArrayLayer = 0;
10650 copy_region.srcSubresource.layerCount = 1;
10651 copy_region.srcOffset.x = 0;
10652 copy_region.srcOffset.y = 0;
10653 copy_region.srcOffset.z = 0;
10654 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10655 copy_region.dstSubresource.mipLevel = 0;
10656 copy_region.dstSubresource.baseArrayLayer = 0;
10657 copy_region.dstSubresource.layerCount = 1;
10658 copy_region.dstOffset.x = 0;
10659 copy_region.dstOffset.y = 0;
10660 copy_region.dstOffset.z = 0;
10661 copy_region.extent.width = 1;
10662 copy_region.extent.height = 1;
10663 copy_region.extent.depth = 1;
10664
10665 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10666 "Layout for input image should be TRANSFER_SRC_OPTIMAL instead of GENERAL.");
10667 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 -060010668 m_errorMonitor->VerifyFound();
10669 // Now cause error due to src image layout changing
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010670 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot copy from an image whose source layout is "
10671 "VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current "
10672 "layout VK_IMAGE_LAYOUT_GENERAL.");
Cort530cf382016-12-08 09:59:47 -080010673 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 -060010674 m_errorMonitor->VerifyFound();
10675 // Final src error is due to bad layout type
10676 m_errorMonitor->SetDesiredFailureMsg(
10677 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10678 "Layout for input image is VK_IMAGE_LAYOUT_UNDEFINED but can only be TRANSFER_SRC_OPTIMAL or GENERAL.");
Cort530cf382016-12-08 09:59:47 -080010679 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 -060010680 m_errorMonitor->VerifyFound();
10681 // Now verify same checks for dst
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010682 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10683 "Layout for output image should be TRANSFER_DST_OPTIMAL instead of GENERAL.");
Cort530cf382016-12-08 09:59:47 -080010684 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 -060010685 m_errorMonitor->VerifyFound();
10686 // Now cause error due to src image layout changing
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010687 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot copy from an image whose dest layout is "
10688 "VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current "
10689 "layout VK_IMAGE_LAYOUT_GENERAL.");
Cort530cf382016-12-08 09:59:47 -080010690 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 -060010691 m_errorMonitor->VerifyFound();
10692 m_errorMonitor->SetDesiredFailureMsg(
10693 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10694 "Layout for output image is VK_IMAGE_LAYOUT_UNDEFINED but can only be TRANSFER_DST_OPTIMAL or GENERAL.");
Cort530cf382016-12-08 09:59:47 -080010695 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 -060010696 m_errorMonitor->VerifyFound();
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010010697
Cort3b021012016-12-07 12:00:57 -080010698 // Convert dst and depth images to TRANSFER_DST for subsequent tests
10699 VkImageMemoryBarrier transfer_dst_image_barrier[1] = {};
10700 transfer_dst_image_barrier[0].sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
10701 transfer_dst_image_barrier[0].oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
10702 transfer_dst_image_barrier[0].newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
10703 transfer_dst_image_barrier[0].srcAccessMask = 0;
10704 transfer_dst_image_barrier[0].dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
10705 transfer_dst_image_barrier[0].image = dst_image;
10706 transfer_dst_image_barrier[0].subresourceRange.layerCount = image_create_info.arrayLayers;
10707 transfer_dst_image_barrier[0].subresourceRange.levelCount = image_create_info.mipLevels;
10708 transfer_dst_image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10709 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
10710 NULL, 0, NULL, 1, transfer_dst_image_barrier);
10711 transfer_dst_image_barrier[0].image = depth_image;
10712 transfer_dst_image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
10713 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
10714 NULL, 0, NULL, 1, transfer_dst_image_barrier);
10715
10716 // Cause errors due to clearing with invalid image layouts
Cort530cf382016-12-08 09:59:47 -080010717 VkClearColorValue color_clear_value = {};
10718 VkImageSubresourceRange clear_range;
10719 clear_range.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10720 clear_range.baseMipLevel = 0;
10721 clear_range.baseArrayLayer = 0;
10722 clear_range.layerCount = 1;
10723 clear_range.levelCount = 1;
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010010724
Cort3b021012016-12-07 12:00:57 -080010725 // Fail due to explicitly prohibited layout for color clear (only GENERAL and TRANSFER_DST are permitted).
10726 // Since the image is currently not in UNDEFINED layout, this will emit two errors.
10727 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01086);
10728 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01085);
Cort530cf382016-12-08 09:59:47 -080010729 m_commandBuffer->ClearColorImage(dst_image, VK_IMAGE_LAYOUT_UNDEFINED, &color_clear_value, 1, &clear_range);
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010010730 m_errorMonitor->VerifyFound();
Cort3b021012016-12-07 12:00:57 -080010731 // Fail due to provided layout not matching actual current layout for color clear.
10732 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01085);
Cort530cf382016-12-08 09:59:47 -080010733 m_commandBuffer->ClearColorImage(dst_image, VK_IMAGE_LAYOUT_GENERAL, &color_clear_value, 1, &clear_range);
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010010734 m_errorMonitor->VerifyFound();
Cort3b021012016-12-07 12:00:57 -080010735
Cort530cf382016-12-08 09:59:47 -080010736 VkClearDepthStencilValue depth_clear_value = {};
10737 clear_range.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
Cort3b021012016-12-07 12:00:57 -080010738
10739 // Fail due to explicitly prohibited layout for depth clear (only GENERAL and TRANSFER_DST are permitted).
10740 // Since the image is currently not in UNDEFINED layout, this will emit two errors.
10741 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01101);
10742 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01100);
Cort530cf382016-12-08 09:59:47 -080010743 m_commandBuffer->ClearDepthStencilImage(depth_image, VK_IMAGE_LAYOUT_UNDEFINED, &depth_clear_value, 1, &clear_range);
Cort3b021012016-12-07 12:00:57 -080010744 m_errorMonitor->VerifyFound();
10745 // Fail due to provided layout not matching actual current layout for depth clear.
10746 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01100);
Cort530cf382016-12-08 09:59:47 -080010747 m_commandBuffer->ClearDepthStencilImage(depth_image, VK_IMAGE_LAYOUT_GENERAL, &depth_clear_value, 1, &clear_range);
Cort3b021012016-12-07 12:00:57 -080010748 m_errorMonitor->VerifyFound();
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010010749
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010750 // Now cause error due to bad image layout transition in PipelineBarrier
10751 VkImageMemoryBarrier image_barrier[1] = {};
Cort3b021012016-12-07 12:00:57 -080010752 image_barrier[0].sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010753 image_barrier[0].oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
Cort3b021012016-12-07 12:00:57 -080010754 image_barrier[0].newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010755 image_barrier[0].image = src_image;
Cort3b021012016-12-07 12:00:57 -080010756 image_barrier[0].subresourceRange.layerCount = image_create_info.arrayLayers;
10757 image_barrier[0].subresourceRange.levelCount = image_create_info.mipLevels;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010758 image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010759 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "You cannot transition the layout from "
10760 "VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL when "
10761 "current layout is VK_IMAGE_LAYOUT_GENERAL.");
10762 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
10763 NULL, 0, NULL, 1, image_barrier);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010764 m_errorMonitor->VerifyFound();
10765
10766 // Finally some layout errors at RenderPass create time
10767 // Just hacking in specific state to get to the errors we want so don't copy this unless you know what you're doing.
10768 VkAttachmentReference attach = {};
10769 // perf warning for GENERAL layout w/ non-DS input attachment
10770 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
10771 VkSubpassDescription subpass = {};
10772 subpass.inputAttachmentCount = 1;
10773 subpass.pInputAttachments = &attach;
10774 VkRenderPassCreateInfo rpci = {};
10775 rpci.subpassCount = 1;
10776 rpci.pSubpasses = &subpass;
10777 rpci.attachmentCount = 1;
10778 VkAttachmentDescription attach_desc = {};
10779 attach_desc.format = VK_FORMAT_UNDEFINED;
10780 rpci.pAttachments = &attach_desc;
Tobin Ehlis1efce022016-05-11 10:40:34 -060010781 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010782 VkRenderPass rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010783 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10784 "Layout for input attachment is GENERAL but should be READ_ONLY_OPTIMAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010785 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10786 m_errorMonitor->VerifyFound();
10787 // error w/ non-general layout
10788 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
10789
10790 m_errorMonitor->SetDesiredFailureMsg(
10791 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10792 "Layout for input attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be READ_ONLY_OPTIMAL or GENERAL.");
10793 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10794 m_errorMonitor->VerifyFound();
10795 subpass.inputAttachmentCount = 0;
10796 subpass.colorAttachmentCount = 1;
10797 subpass.pColorAttachments = &attach;
10798 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
10799 // perf warning for GENERAL layout on color attachment
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010800 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10801 "Layout for color attachment is GENERAL but should be COLOR_ATTACHMENT_OPTIMAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010802 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10803 m_errorMonitor->VerifyFound();
10804 // error w/ non-color opt or GENERAL layout for color attachment
10805 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
10806 m_errorMonitor->SetDesiredFailureMsg(
10807 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10808 "Layout for color attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be COLOR_ATTACHMENT_OPTIMAL or GENERAL.");
10809 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10810 m_errorMonitor->VerifyFound();
10811 subpass.colorAttachmentCount = 0;
10812 subpass.pDepthStencilAttachment = &attach;
10813 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
10814 // perf warning for GENERAL layout on DS attachment
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010815 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10816 "GENERAL layout for depth attachment may not give optimal performance.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010817 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10818 m_errorMonitor->VerifyFound();
10819 // error w/ non-ds opt or GENERAL layout for color attachment
10820 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010821 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10822 "Layout for depth attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be "
10823 "DEPTH_STENCIL_ATTACHMENT_OPTIMAL, DEPTH_STENCIL_READ_ONLY_OPTIMAL or GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010824 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10825 m_errorMonitor->VerifyFound();
Tobin Ehlis1efce022016-05-11 10:40:34 -060010826 // For this error we need a valid renderpass so create default one
10827 attach.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
10828 attach.attachment = 0;
10829 attach_desc.format = VK_FORMAT_D24_UNORM_S8_UINT;
10830 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
10831 attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
10832 attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
10833 attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
10834 // Can't do a CLEAR load on READ_ONLY initialLayout
10835 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
10836 attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
10837 attach_desc.finalLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010838 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " with invalid first layout "
10839 "VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_"
10840 "ONLY_OPTIMAL");
Tobin Ehlis1efce022016-05-11 10:40:34 -060010841 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10842 m_errorMonitor->VerifyFound();
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010843
Cort3b021012016-12-07 12:00:57 -080010844 vkFreeMemory(m_device->device(), src_image_mem, NULL);
10845 vkFreeMemory(m_device->device(), dst_image_mem, NULL);
10846 vkFreeMemory(m_device->device(), depth_image_mem, NULL);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010847 vkDestroyImage(m_device->device(), src_image, NULL);
10848 vkDestroyImage(m_device->device(), dst_image, NULL);
Cort3b021012016-12-07 12:00:57 -080010849 vkDestroyImage(m_device->device(), depth_image, NULL);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010850}
Tobin Ehlisd8d89182016-07-18 20:13:11 -060010851
Tobin Ehlise0936662016-10-11 08:10:51 -060010852TEST_F(VkLayerTest, InvalidStorageImageLayout) {
10853 TEST_DESCRIPTION("Attempt to update a STORAGE_IMAGE descriptor w/o GENERAL layout.");
10854 VkResult err;
10855
10856 ASSERT_NO_FATAL_FAILURE(InitState());
10857
10858 const VkFormat tex_format = VK_FORMAT_R8G8B8A8_UNORM;
10859 VkImageTiling tiling;
10860 VkFormatProperties format_properties;
10861 vkGetPhysicalDeviceFormatProperties(gpu(), tex_format, &format_properties);
10862 if (format_properties.linearTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
10863 tiling = VK_IMAGE_TILING_LINEAR;
10864 } else if (format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
10865 tiling = VK_IMAGE_TILING_OPTIMAL;
10866 } else {
10867 printf("Device does not support VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT; "
10868 "skipped.\n");
10869 return;
10870 }
10871
10872 VkDescriptorPoolSize ds_type = {};
10873 ds_type.type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
10874 ds_type.descriptorCount = 1;
10875
10876 VkDescriptorPoolCreateInfo ds_pool_ci = {};
10877 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10878 ds_pool_ci.maxSets = 1;
10879 ds_pool_ci.poolSizeCount = 1;
10880 ds_pool_ci.pPoolSizes = &ds_type;
10881 ds_pool_ci.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
10882
10883 VkDescriptorPool ds_pool;
10884 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
10885 ASSERT_VK_SUCCESS(err);
10886
10887 VkDescriptorSetLayoutBinding dsl_binding = {};
10888 dsl_binding.binding = 0;
10889 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
10890 dsl_binding.descriptorCount = 1;
10891 dsl_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
10892 dsl_binding.pImmutableSamplers = NULL;
10893
10894 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10895 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10896 ds_layout_ci.pNext = NULL;
10897 ds_layout_ci.bindingCount = 1;
10898 ds_layout_ci.pBindings = &dsl_binding;
10899
10900 VkDescriptorSetLayout ds_layout;
10901 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
10902 ASSERT_VK_SUCCESS(err);
10903
10904 VkDescriptorSetAllocateInfo alloc_info = {};
10905 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
10906 alloc_info.descriptorSetCount = 1;
10907 alloc_info.descriptorPool = ds_pool;
10908 alloc_info.pSetLayouts = &ds_layout;
10909 VkDescriptorSet descriptor_set;
10910 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
10911 ASSERT_VK_SUCCESS(err);
10912
10913 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
10914 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10915 pipeline_layout_ci.pNext = NULL;
10916 pipeline_layout_ci.setLayoutCount = 1;
10917 pipeline_layout_ci.pSetLayouts = &ds_layout;
10918 VkPipelineLayout pipeline_layout;
10919 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
10920 ASSERT_VK_SUCCESS(err);
10921
10922 VkImageObj image(m_device);
10923 image.init(32, 32, tex_format, VK_IMAGE_USAGE_STORAGE_BIT, tiling, 0);
10924 ASSERT_TRUE(image.initialized());
10925 VkImageView view = image.targetView(tex_format);
10926
10927 VkDescriptorImageInfo image_info = {};
10928 image_info.imageView = view;
10929 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
10930
10931 VkWriteDescriptorSet descriptor_write = {};
10932 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
10933 descriptor_write.dstSet = descriptor_set;
10934 descriptor_write.dstBinding = 0;
10935 descriptor_write.descriptorCount = 1;
10936 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
10937 descriptor_write.pImageInfo = &image_info;
10938
10939 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10940 " of VK_DESCRIPTOR_TYPE_STORAGE_IMAGE type is being updated with layout "
10941 "VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL but according to spec ");
10942 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10943 m_errorMonitor->VerifyFound();
10944
10945 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10946 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10947 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
10948 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
10949}
10950
Mark Mueller93b938f2016-08-18 10:27:40 -060010951TEST_F(VkLayerTest, SimultaneousUse) {
10952 TEST_DESCRIPTION("Use vkCmdExecuteCommands with invalid state "
10953 "in primary and secondary command buffers.");
10954
10955 ASSERT_NO_FATAL_FAILURE(InitState());
10956 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10957
Mike Weiblen95dd0f92016-10-19 12:28:27 -060010958 const char *simultaneous_use_message1 = "without VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set!";
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010959 const char *simultaneous_use_message2 = "does not have VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set and "
10960 "will cause primary command buffer";
Mark Mueller93b938f2016-08-18 10:27:40 -060010961
10962 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010963 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Mueller93b938f2016-08-18 10:27:40 -060010964 command_buffer_allocate_info.commandPool = m_commandPool;
10965 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
10966 command_buffer_allocate_info.commandBufferCount = 1;
10967
10968 VkCommandBuffer secondary_command_buffer;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010969 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer));
Mark Mueller93b938f2016-08-18 10:27:40 -060010970 VkCommandBufferBeginInfo command_buffer_begin_info = {};
10971 VkCommandBufferInheritanceInfo command_buffer_inheritance_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010972 command_buffer_inheritance_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
Mark Mueller93b938f2016-08-18 10:27:40 -060010973 command_buffer_inheritance_info.renderPass = m_renderPass;
10974 command_buffer_inheritance_info.framebuffer = m_framebuffer;
10975 command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010976 command_buffer_begin_info.flags =
10977 VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT | VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT;
Mark Mueller93b938f2016-08-18 10:27:40 -060010978 command_buffer_begin_info.pInheritanceInfo = &command_buffer_inheritance_info;
10979
10980 vkBeginCommandBuffer(secondary_command_buffer, &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010981 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
10982 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller4042b652016-09-05 22:52:21 -060010983 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
Mark Mueller93b938f2016-08-18 10:27:40 -060010984 vkEndCommandBuffer(secondary_command_buffer);
10985
Mark Mueller93b938f2016-08-18 10:27:40 -060010986 VkSubmitInfo submit_info = {};
10987 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
10988 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010989 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Mueller4042b652016-09-05 22:52:21 -060010990 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Mueller93b938f2016-08-18 10:27:40 -060010991
Mark Mueller4042b652016-09-05 22:52:21 -060010992 vkBeginCommandBuffer(m_commandBuffer->handle(), &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010993 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
10994 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, simultaneous_use_message1);
10995 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller93b938f2016-08-18 10:27:40 -060010996 m_errorMonitor->VerifyFound();
Mark Mueller4042b652016-09-05 22:52:21 -060010997 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
10998 vkEndCommandBuffer(m_commandBuffer->handle());
Mark Mueller93b938f2016-08-18 10:27:40 -060010999
11000 m_errorMonitor->SetDesiredFailureMsg(0, "");
Mark Mueller93b938f2016-08-18 10:27:40 -060011001 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11002
Mark Mueller4042b652016-09-05 22:52:21 -060011003 command_buffer_begin_info.flags = VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT;
Mark Mueller93b938f2016-08-18 10:27:40 -060011004 vkBeginCommandBuffer(m_commandBuffer->handle(), &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011005 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
Mark Mueller4042b652016-09-05 22:52:21 -060011006
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011007 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, simultaneous_use_message2);
11008 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller93b938f2016-08-18 10:27:40 -060011009 m_errorMonitor->VerifyFound();
Mark Mueller4042b652016-09-05 22:52:21 -060011010 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
11011 vkEndCommandBuffer(m_commandBuffer->handle());
Mark Mueller93b938f2016-08-18 10:27:40 -060011012}
11013
Mark Mueller917f6bc2016-08-30 10:57:19 -060011014TEST_F(VkLayerTest, InUseDestroyedSignaled) {
11015 TEST_DESCRIPTION("Use vkCmdExecuteCommands with invalid state "
11016 "in primary and secondary command buffers. "
Mark Muellerc8d441e2016-08-23 17:36:00 -060011017 "Delete objects that are inuse. Call VkQueueSubmit "
11018 "with an event that has been deleted.");
Mark Mueller917f6bc2016-08-30 10:57:19 -060011019
11020 ASSERT_NO_FATAL_FAILURE(InitState());
11021 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11022
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011023 const char *submit_with_deleted_event_message = "Cannot submit cmd buffer using deleted event 0x";
11024 const char *cannot_delete_event_message = "Cannot delete event 0x";
11025 const char *cannot_delete_semaphore_message = "Cannot delete semaphore 0x";
11026 const char *cannot_destroy_fence_message = "Fence 0x";
Mark Mueller917f6bc2016-08-30 10:57:19 -060011027
11028 BeginCommandBuffer();
11029
11030 VkEvent event;
11031 VkEventCreateInfo event_create_info = {};
11032 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
11033 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011034 vkCmdSetEvent(m_commandBuffer->handle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Mark Mueller917f6bc2016-08-30 10:57:19 -060011035
Mark Muellerc8d441e2016-08-23 17:36:00 -060011036 EndCommandBuffer();
11037 vkDestroyEvent(m_device->device(), event, nullptr);
11038
11039 VkSubmitInfo submit_info = {};
11040 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11041 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011042 submit_info.pCommandBuffers = &m_commandBuffer->handle();
11043 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, submit_with_deleted_event_message);
Mark Muellerc8d441e2016-08-23 17:36:00 -060011044 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11045 m_errorMonitor->VerifyFound();
11046
11047 m_errorMonitor->SetDesiredFailureMsg(0, "");
11048 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
11049
11050 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
11051
Mark Mueller917f6bc2016-08-30 10:57:19 -060011052 VkSemaphoreCreateInfo semaphore_create_info = {};
11053 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
11054 VkSemaphore semaphore;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011055 ASSERT_VK_SUCCESS(vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore));
Mark Mueller917f6bc2016-08-30 10:57:19 -060011056 VkFenceCreateInfo fence_create_info = {};
11057 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
11058 VkFence fence;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011059 ASSERT_VK_SUCCESS(vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence));
Mark Mueller917f6bc2016-08-30 10:57:19 -060011060
11061 VkDescriptorPoolSize descriptor_pool_type_count = {};
Mark Mueller4042b652016-09-05 22:52:21 -060011062 descriptor_pool_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Mark Mueller917f6bc2016-08-30 10:57:19 -060011063 descriptor_pool_type_count.descriptorCount = 1;
11064
11065 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
11066 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11067 descriptor_pool_create_info.maxSets = 1;
11068 descriptor_pool_create_info.poolSizeCount = 1;
11069 descriptor_pool_create_info.pPoolSizes = &descriptor_pool_type_count;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011070 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
Mark Mueller917f6bc2016-08-30 10:57:19 -060011071
11072 VkDescriptorPool descriptorset_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011073 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
Mark Mueller917f6bc2016-08-30 10:57:19 -060011074
11075 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
Mark Mueller4042b652016-09-05 22:52:21 -060011076 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Mark Mueller917f6bc2016-08-30 10:57:19 -060011077 descriptorset_layout_binding.descriptorCount = 1;
11078 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_ALL;
11079
11080 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011081 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060011082 descriptorset_layout_create_info.bindingCount = 1;
11083 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
11084
11085 VkDescriptorSetLayout descriptorset_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011086 ASSERT_VK_SUCCESS(
11087 vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
Mark Mueller917f6bc2016-08-30 10:57:19 -060011088
11089 VkDescriptorSet descriptorset;
11090 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011091 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060011092 descriptorset_allocate_info.descriptorSetCount = 1;
11093 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
11094 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011095 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
Mark Mueller917f6bc2016-08-30 10:57:19 -060011096
Mark Mueller4042b652016-09-05 22:52:21 -060011097 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
11098
11099 VkDescriptorBufferInfo buffer_info = {};
11100 buffer_info.buffer = buffer_test.GetBuffer();
11101 buffer_info.offset = 0;
11102 buffer_info.range = 1024;
11103
11104 VkWriteDescriptorSet write_descriptor_set = {};
11105 write_descriptor_set.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
11106 write_descriptor_set.dstSet = descriptorset;
11107 write_descriptor_set.descriptorCount = 1;
11108 write_descriptor_set.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11109 write_descriptor_set.pBufferInfo = &buffer_info;
11110
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011111 vkUpdateDescriptorSets(m_device->device(), 1, &write_descriptor_set, 0, nullptr);
Mark Mueller4042b652016-09-05 22:52:21 -060011112
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011113 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
11114 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Mueller917f6bc2016-08-30 10:57:19 -060011115
11116 VkPipelineObj pipe(m_device);
11117 pipe.AddColorAttachment();
11118 pipe.AddShader(&vs);
11119 pipe.AddShader(&fs);
11120
11121 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011122 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060011123 pipeline_layout_create_info.setLayoutCount = 1;
11124 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
11125
11126 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011127 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
Mark Mueller917f6bc2016-08-30 10:57:19 -060011128
11129 pipe.CreateVKPipeline(pipeline_layout, m_renderPass);
11130
Mark Muellerc8d441e2016-08-23 17:36:00 -060011131 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011132 vkCmdSetEvent(m_commandBuffer->handle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Mark Muellerc8d441e2016-08-23 17:36:00 -060011133
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011134 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
11135 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
11136 &descriptorset, 0, NULL);
Mark Mueller917f6bc2016-08-30 10:57:19 -060011137
Mark Muellerc8d441e2016-08-23 17:36:00 -060011138 EndCommandBuffer();
Mark Mueller917f6bc2016-08-30 10:57:19 -060011139
Mark Mueller917f6bc2016-08-30 10:57:19 -060011140 submit_info.signalSemaphoreCount = 1;
11141 submit_info.pSignalSemaphores = &semaphore;
11142 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
Mark Muellerc8d441e2016-08-23 17:36:00 -060011143
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011144 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, cannot_delete_event_message);
Mark Mueller917f6bc2016-08-30 10:57:19 -060011145 vkDestroyEvent(m_device->device(), event, nullptr);
11146 m_errorMonitor->VerifyFound();
11147
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011148 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, cannot_delete_semaphore_message);
Mark Mueller917f6bc2016-08-30 10:57:19 -060011149 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
11150 m_errorMonitor->VerifyFound();
11151
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011152 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, cannot_destroy_fence_message);
Mark Mueller917f6bc2016-08-30 10:57:19 -060011153 vkDestroyFence(m_device->device(), fence, nullptr);
11154 m_errorMonitor->VerifyFound();
11155
Tobin Ehlis122207b2016-09-01 08:50:06 -070011156 vkQueueWaitIdle(m_device->m_queue);
Mark Mueller917f6bc2016-08-30 10:57:19 -060011157 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
11158 vkDestroyFence(m_device->device(), fence, nullptr);
11159 vkDestroyEvent(m_device->device(), event, nullptr);
11160 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011161 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
Mark Mueller917f6bc2016-08-30 10:57:19 -060011162 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
11163}
11164
Tobin Ehlis2adda372016-09-01 08:51:06 -070011165TEST_F(VkLayerTest, QueryPoolInUseDestroyedSignaled) {
11166 TEST_DESCRIPTION("Delete in-use query pool.");
11167
11168 ASSERT_NO_FATAL_FAILURE(InitState());
11169 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11170
11171 VkQueryPool query_pool;
11172 VkQueryPoolCreateInfo query_pool_ci{};
11173 query_pool_ci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
11174 query_pool_ci.queryType = VK_QUERY_TYPE_TIMESTAMP;
11175 query_pool_ci.queryCount = 1;
11176 vkCreateQueryPool(m_device->device(), &query_pool_ci, nullptr, &query_pool);
11177 BeginCommandBuffer();
11178 // Reset query pool to create binding with cmd buffer
11179 vkCmdResetQueryPool(m_commandBuffer->handle(), query_pool, 0, 1);
11180
11181 EndCommandBuffer();
11182
11183 VkSubmitInfo submit_info = {};
11184 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11185 submit_info.commandBufferCount = 1;
11186 submit_info.pCommandBuffers = &m_commandBuffer->handle();
11187 // Submit cmd buffer and then destroy query pool while in-flight
11188 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11189
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011190 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete query pool 0x");
Tobin Ehlis2adda372016-09-01 08:51:06 -070011191 vkDestroyQueryPool(m_device->handle(), query_pool, NULL);
11192 m_errorMonitor->VerifyFound();
11193
11194 vkQueueWaitIdle(m_device->m_queue);
11195 // Now that cmd buffer done we can safely destroy query_pool
11196 vkDestroyQueryPool(m_device->handle(), query_pool, NULL);
11197}
11198
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060011199TEST_F(VkLayerTest, PipelineInUseDestroyedSignaled) {
11200 TEST_DESCRIPTION("Delete in-use pipeline.");
11201
11202 ASSERT_NO_FATAL_FAILURE(InitState());
11203 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11204
11205 // Empty pipeline layout used for binding PSO
11206 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11207 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11208 pipeline_layout_ci.setLayoutCount = 0;
11209 pipeline_layout_ci.pSetLayouts = NULL;
11210
11211 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011212 VkResult err = vkCreatePipelineLayout(m_device->handle(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060011213 ASSERT_VK_SUCCESS(err);
11214
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011215 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete pipeline 0x");
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060011216 // Create PSO to be used for draw-time errors below
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011217 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
11218 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060011219 // Store pipeline handle so we can actually delete it before test finishes
11220 VkPipeline delete_this_pipeline;
11221 { // Scope pipeline so it will be auto-deleted
11222 VkPipelineObj pipe(m_device);
11223 pipe.AddShader(&vs);
11224 pipe.AddShader(&fs);
11225 pipe.AddColorAttachment();
11226 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11227 delete_this_pipeline = pipe.handle();
11228
11229 BeginCommandBuffer();
11230 // Bind pipeline to cmd buffer
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011231 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060011232
11233 EndCommandBuffer();
11234
11235 VkSubmitInfo submit_info = {};
11236 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11237 submit_info.commandBufferCount = 1;
11238 submit_info.pCommandBuffers = &m_commandBuffer->handle();
11239 // Submit cmd buffer and then pipeline destroyed while in-flight
11240 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11241 } // Pipeline deletion triggered here
11242 m_errorMonitor->VerifyFound();
11243 // Make sure queue finished and then actually delete pipeline
11244 vkQueueWaitIdle(m_device->m_queue);
11245 vkDestroyPipeline(m_device->handle(), delete_this_pipeline, nullptr);
11246 vkDestroyPipelineLayout(m_device->handle(), pipeline_layout, nullptr);
11247}
11248
Tobin Ehlis7d965da2016-09-19 16:15:45 -060011249TEST_F(VkLayerTest, ImageViewInUseDestroyedSignaled) {
11250 TEST_DESCRIPTION("Delete in-use imageView.");
11251
11252 ASSERT_NO_FATAL_FAILURE(InitState());
11253 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11254
11255 VkDescriptorPoolSize ds_type_count;
11256 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11257 ds_type_count.descriptorCount = 1;
11258
11259 VkDescriptorPoolCreateInfo ds_pool_ci = {};
11260 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11261 ds_pool_ci.maxSets = 1;
11262 ds_pool_ci.poolSizeCount = 1;
11263 ds_pool_ci.pPoolSizes = &ds_type_count;
11264
11265 VkDescriptorPool ds_pool;
11266 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
11267 ASSERT_VK_SUCCESS(err);
11268
11269 VkSamplerCreateInfo sampler_ci = {};
11270 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
11271 sampler_ci.pNext = NULL;
11272 sampler_ci.magFilter = VK_FILTER_NEAREST;
11273 sampler_ci.minFilter = VK_FILTER_NEAREST;
11274 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
11275 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11276 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11277 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11278 sampler_ci.mipLodBias = 1.0;
11279 sampler_ci.anisotropyEnable = VK_FALSE;
11280 sampler_ci.maxAnisotropy = 1;
11281 sampler_ci.compareEnable = VK_FALSE;
11282 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
11283 sampler_ci.minLod = 1.0;
11284 sampler_ci.maxLod = 1.0;
11285 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
11286 sampler_ci.unnormalizedCoordinates = VK_FALSE;
11287 VkSampler sampler;
11288
11289 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
11290 ASSERT_VK_SUCCESS(err);
11291
11292 VkDescriptorSetLayoutBinding layout_binding;
11293 layout_binding.binding = 0;
11294 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11295 layout_binding.descriptorCount = 1;
11296 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
11297 layout_binding.pImmutableSamplers = NULL;
11298
11299 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11300 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11301 ds_layout_ci.bindingCount = 1;
11302 ds_layout_ci.pBindings = &layout_binding;
11303 VkDescriptorSetLayout ds_layout;
11304 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
11305 ASSERT_VK_SUCCESS(err);
11306
11307 VkDescriptorSetAllocateInfo alloc_info = {};
11308 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11309 alloc_info.descriptorSetCount = 1;
11310 alloc_info.descriptorPool = ds_pool;
11311 alloc_info.pSetLayouts = &ds_layout;
11312 VkDescriptorSet descriptor_set;
11313 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
11314 ASSERT_VK_SUCCESS(err);
11315
11316 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11317 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11318 pipeline_layout_ci.pNext = NULL;
11319 pipeline_layout_ci.setLayoutCount = 1;
11320 pipeline_layout_ci.pSetLayouts = &ds_layout;
11321
11322 VkPipelineLayout pipeline_layout;
11323 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
11324 ASSERT_VK_SUCCESS(err);
11325
11326 VkImageObj image(m_device);
11327 image.init(128, 128, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
11328 ASSERT_TRUE(image.initialized());
11329
11330 VkImageView view;
11331 VkImageViewCreateInfo ivci = {};
11332 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
11333 ivci.image = image.handle();
11334 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
11335 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
11336 ivci.subresourceRange.layerCount = 1;
11337 ivci.subresourceRange.baseMipLevel = 0;
11338 ivci.subresourceRange.levelCount = 1;
11339 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11340
11341 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
11342 ASSERT_VK_SUCCESS(err);
11343
11344 VkDescriptorImageInfo image_info{};
11345 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
11346 image_info.imageView = view;
11347 image_info.sampler = sampler;
11348
11349 VkWriteDescriptorSet descriptor_write = {};
11350 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
11351 descriptor_write.dstSet = descriptor_set;
11352 descriptor_write.dstBinding = 0;
11353 descriptor_write.descriptorCount = 1;
11354 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11355 descriptor_write.pImageInfo = &image_info;
11356
11357 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11358
11359 // Create PSO to use the sampler
11360 char const *vsSource = "#version 450\n"
11361 "\n"
11362 "out gl_PerVertex { \n"
11363 " vec4 gl_Position;\n"
11364 "};\n"
11365 "void main(){\n"
11366 " gl_Position = vec4(1);\n"
11367 "}\n";
11368 char const *fsSource = "#version 450\n"
11369 "\n"
11370 "layout(set=0, binding=0) uniform sampler2D s;\n"
11371 "layout(location=0) out vec4 x;\n"
11372 "void main(){\n"
11373 " x = texture(s, vec2(1));\n"
11374 "}\n";
11375 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
11376 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
11377 VkPipelineObj pipe(m_device);
11378 pipe.AddShader(&vs);
11379 pipe.AddShader(&fs);
11380 pipe.AddColorAttachment();
11381 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11382
11383 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete image view 0x");
11384
11385 BeginCommandBuffer();
11386 // Bind pipeline to cmd buffer
11387 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
11388 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
11389 &descriptor_set, 0, nullptr);
11390 Draw(1, 0, 0, 0);
11391 EndCommandBuffer();
11392 // Submit cmd buffer then destroy sampler
11393 VkSubmitInfo submit_info = {};
11394 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11395 submit_info.commandBufferCount = 1;
11396 submit_info.pCommandBuffers = &m_commandBuffer->handle();
11397 // Submit cmd buffer and then destroy imageView while in-flight
11398 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11399
11400 vkDestroyImageView(m_device->device(), view, nullptr);
11401 m_errorMonitor->VerifyFound();
11402 vkQueueWaitIdle(m_device->m_queue);
11403 // Now we can actually destroy imageView
11404 vkDestroyImageView(m_device->device(), view, NULL);
11405 vkDestroySampler(m_device->device(), sampler, nullptr);
11406 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11407 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11408 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
11409}
11410
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060011411TEST_F(VkLayerTest, BufferViewInUseDestroyedSignaled) {
11412 TEST_DESCRIPTION("Delete in-use bufferView.");
11413
11414 ASSERT_NO_FATAL_FAILURE(InitState());
11415 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11416
11417 VkDescriptorPoolSize ds_type_count;
11418 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
11419 ds_type_count.descriptorCount = 1;
11420
11421 VkDescriptorPoolCreateInfo ds_pool_ci = {};
11422 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11423 ds_pool_ci.maxSets = 1;
11424 ds_pool_ci.poolSizeCount = 1;
11425 ds_pool_ci.pPoolSizes = &ds_type_count;
11426
11427 VkDescriptorPool ds_pool;
11428 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
11429 ASSERT_VK_SUCCESS(err);
11430
11431 VkDescriptorSetLayoutBinding layout_binding;
11432 layout_binding.binding = 0;
11433 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
11434 layout_binding.descriptorCount = 1;
11435 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
11436 layout_binding.pImmutableSamplers = NULL;
11437
11438 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11439 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11440 ds_layout_ci.bindingCount = 1;
11441 ds_layout_ci.pBindings = &layout_binding;
11442 VkDescriptorSetLayout ds_layout;
11443 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
11444 ASSERT_VK_SUCCESS(err);
11445
11446 VkDescriptorSetAllocateInfo alloc_info = {};
11447 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11448 alloc_info.descriptorSetCount = 1;
11449 alloc_info.descriptorPool = ds_pool;
11450 alloc_info.pSetLayouts = &ds_layout;
11451 VkDescriptorSet descriptor_set;
11452 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
11453 ASSERT_VK_SUCCESS(err);
11454
11455 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11456 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11457 pipeline_layout_ci.pNext = NULL;
11458 pipeline_layout_ci.setLayoutCount = 1;
11459 pipeline_layout_ci.pSetLayouts = &ds_layout;
11460
11461 VkPipelineLayout pipeline_layout;
11462 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
11463 ASSERT_VK_SUCCESS(err);
11464
11465 VkBuffer buffer;
11466 uint32_t queue_family_index = 0;
11467 VkBufferCreateInfo buffer_create_info = {};
11468 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
11469 buffer_create_info.size = 1024;
11470 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
11471 buffer_create_info.queueFamilyIndexCount = 1;
11472 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
11473
11474 err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
11475 ASSERT_VK_SUCCESS(err);
11476
11477 VkMemoryRequirements memory_reqs;
11478 VkDeviceMemory buffer_memory;
11479
11480 VkMemoryAllocateInfo memory_info = {};
11481 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
11482 memory_info.allocationSize = 0;
11483 memory_info.memoryTypeIndex = 0;
11484
11485 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
11486 memory_info.allocationSize = memory_reqs.size;
11487 bool pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
11488 ASSERT_TRUE(pass);
11489
11490 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
11491 ASSERT_VK_SUCCESS(err);
11492 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
11493 ASSERT_VK_SUCCESS(err);
11494
11495 VkBufferView view;
11496 VkBufferViewCreateInfo bvci = {};
11497 bvci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
11498 bvci.buffer = buffer;
11499 bvci.format = VK_FORMAT_R8_UNORM;
11500 bvci.range = VK_WHOLE_SIZE;
11501
11502 err = vkCreateBufferView(m_device->device(), &bvci, NULL, &view);
11503 ASSERT_VK_SUCCESS(err);
11504
11505 VkWriteDescriptorSet descriptor_write = {};
11506 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
11507 descriptor_write.dstSet = descriptor_set;
11508 descriptor_write.dstBinding = 0;
11509 descriptor_write.descriptorCount = 1;
11510 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
11511 descriptor_write.pTexelBufferView = &view;
11512
11513 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11514
11515 char const *vsSource = "#version 450\n"
11516 "\n"
11517 "out gl_PerVertex { \n"
11518 " vec4 gl_Position;\n"
11519 "};\n"
11520 "void main(){\n"
11521 " gl_Position = vec4(1);\n"
11522 "}\n";
11523 char const *fsSource = "#version 450\n"
11524 "\n"
11525 "layout(set=0, binding=0, r8) uniform imageBuffer s;\n"
11526 "layout(location=0) out vec4 x;\n"
11527 "void main(){\n"
11528 " x = imageLoad(s, 0);\n"
11529 "}\n";
11530 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
11531 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
11532 VkPipelineObj pipe(m_device);
11533 pipe.AddShader(&vs);
11534 pipe.AddShader(&fs);
11535 pipe.AddColorAttachment();
11536 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11537
11538 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete buffer view 0x");
11539
11540 BeginCommandBuffer();
11541 VkViewport viewport = {0, 0, 16, 16, 0, 1};
11542 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
11543 VkRect2D scissor = {{0, 0}, {16, 16}};
11544 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
11545 // Bind pipeline to cmd buffer
11546 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
11547 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
11548 &descriptor_set, 0, nullptr);
11549 Draw(1, 0, 0, 0);
11550 EndCommandBuffer();
11551
11552 VkSubmitInfo submit_info = {};
11553 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11554 submit_info.commandBufferCount = 1;
11555 submit_info.pCommandBuffers = &m_commandBuffer->handle();
11556 // Submit cmd buffer and then destroy bufferView while in-flight
11557 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11558
11559 vkDestroyBufferView(m_device->device(), view, nullptr);
11560 m_errorMonitor->VerifyFound();
11561 vkQueueWaitIdle(m_device->m_queue);
11562 // Now we can actually destroy bufferView
11563 vkDestroyBufferView(m_device->device(), view, NULL);
11564 vkDestroyBuffer(m_device->device(), buffer, NULL);
11565 vkFreeMemory(m_device->device(), buffer_memory, NULL);
11566 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11567 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11568 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
11569}
11570
Tobin Ehlis209532e2016-09-07 13:52:18 -060011571TEST_F(VkLayerTest, SamplerInUseDestroyedSignaled) {
11572 TEST_DESCRIPTION("Delete in-use sampler.");
11573
11574 ASSERT_NO_FATAL_FAILURE(InitState());
11575 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11576
11577 VkDescriptorPoolSize ds_type_count;
11578 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11579 ds_type_count.descriptorCount = 1;
11580
11581 VkDescriptorPoolCreateInfo ds_pool_ci = {};
11582 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11583 ds_pool_ci.maxSets = 1;
11584 ds_pool_ci.poolSizeCount = 1;
11585 ds_pool_ci.pPoolSizes = &ds_type_count;
11586
11587 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011588 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis209532e2016-09-07 13:52:18 -060011589 ASSERT_VK_SUCCESS(err);
11590
11591 VkSamplerCreateInfo sampler_ci = {};
11592 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
11593 sampler_ci.pNext = NULL;
11594 sampler_ci.magFilter = VK_FILTER_NEAREST;
11595 sampler_ci.minFilter = VK_FILTER_NEAREST;
11596 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
11597 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11598 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11599 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11600 sampler_ci.mipLodBias = 1.0;
11601 sampler_ci.anisotropyEnable = VK_FALSE;
11602 sampler_ci.maxAnisotropy = 1;
11603 sampler_ci.compareEnable = VK_FALSE;
11604 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
11605 sampler_ci.minLod = 1.0;
11606 sampler_ci.maxLod = 1.0;
11607 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
11608 sampler_ci.unnormalizedCoordinates = VK_FALSE;
11609 VkSampler sampler;
11610
11611 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
11612 ASSERT_VK_SUCCESS(err);
11613
11614 VkDescriptorSetLayoutBinding layout_binding;
11615 layout_binding.binding = 0;
Tobin Ehlis94fc0ad2016-09-19 16:23:01 -060011616 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
Tobin Ehlis209532e2016-09-07 13:52:18 -060011617 layout_binding.descriptorCount = 1;
11618 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
11619 layout_binding.pImmutableSamplers = NULL;
11620
11621 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11622 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11623 ds_layout_ci.bindingCount = 1;
11624 ds_layout_ci.pBindings = &layout_binding;
11625 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011626 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis209532e2016-09-07 13:52:18 -060011627 ASSERT_VK_SUCCESS(err);
11628
11629 VkDescriptorSetAllocateInfo alloc_info = {};
11630 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11631 alloc_info.descriptorSetCount = 1;
11632 alloc_info.descriptorPool = ds_pool;
11633 alloc_info.pSetLayouts = &ds_layout;
11634 VkDescriptorSet descriptor_set;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011635 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis209532e2016-09-07 13:52:18 -060011636 ASSERT_VK_SUCCESS(err);
11637
11638 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11639 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11640 pipeline_layout_ci.pNext = NULL;
11641 pipeline_layout_ci.setLayoutCount = 1;
11642 pipeline_layout_ci.pSetLayouts = &ds_layout;
11643
11644 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011645 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis209532e2016-09-07 13:52:18 -060011646 ASSERT_VK_SUCCESS(err);
11647
11648 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011649 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 -060011650 ASSERT_TRUE(image.initialized());
11651
11652 VkImageView view;
11653 VkImageViewCreateInfo ivci = {};
11654 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
11655 ivci.image = image.handle();
11656 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
11657 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
11658 ivci.subresourceRange.layerCount = 1;
11659 ivci.subresourceRange.baseMipLevel = 0;
11660 ivci.subresourceRange.levelCount = 1;
11661 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11662
11663 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
11664 ASSERT_VK_SUCCESS(err);
11665
11666 VkDescriptorImageInfo image_info{};
11667 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
11668 image_info.imageView = view;
11669 image_info.sampler = sampler;
11670
11671 VkWriteDescriptorSet descriptor_write = {};
11672 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
11673 descriptor_write.dstSet = descriptor_set;
11674 descriptor_write.dstBinding = 0;
11675 descriptor_write.descriptorCount = 1;
11676 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11677 descriptor_write.pImageInfo = &image_info;
11678
11679 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11680
11681 // Create PSO to use the sampler
11682 char const *vsSource = "#version 450\n"
11683 "\n"
11684 "out gl_PerVertex { \n"
11685 " vec4 gl_Position;\n"
11686 "};\n"
11687 "void main(){\n"
11688 " gl_Position = vec4(1);\n"
11689 "}\n";
11690 char const *fsSource = "#version 450\n"
11691 "\n"
11692 "layout(set=0, binding=0) uniform sampler2D s;\n"
11693 "layout(location=0) out vec4 x;\n"
11694 "void main(){\n"
11695 " x = texture(s, vec2(1));\n"
11696 "}\n";
11697 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
11698 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
11699 VkPipelineObj pipe(m_device);
11700 pipe.AddShader(&vs);
11701 pipe.AddShader(&fs);
11702 pipe.AddColorAttachment();
11703 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11704
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011705 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete sampler 0x");
Tobin Ehlis209532e2016-09-07 13:52:18 -060011706
11707 BeginCommandBuffer();
11708 // Bind pipeline to cmd buffer
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011709 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
11710 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
11711 &descriptor_set, 0, nullptr);
Tobin Ehlis209532e2016-09-07 13:52:18 -060011712 Draw(1, 0, 0, 0);
11713 EndCommandBuffer();
11714 // Submit cmd buffer then destroy sampler
11715 VkSubmitInfo submit_info = {};
11716 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11717 submit_info.commandBufferCount = 1;
11718 submit_info.pCommandBuffers = &m_commandBuffer->handle();
11719 // Submit cmd buffer and then destroy sampler while in-flight
11720 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11721
11722 vkDestroySampler(m_device->device(), sampler, nullptr);
11723 m_errorMonitor->VerifyFound();
11724 vkQueueWaitIdle(m_device->m_queue);
11725 // Now we can actually destroy sampler
11726 vkDestroySampler(m_device->device(), sampler, nullptr);
11727 vkDestroyImageView(m_device->device(), view, NULL);
11728 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11729 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11730 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
11731}
11732
Mark Mueller1cd9f412016-08-25 13:23:52 -060011733TEST_F(VkLayerTest, QueueForwardProgressFenceWait) {
Mark Mueller96a56d52016-08-24 10:28:05 -060011734 TEST_DESCRIPTION("Call VkQueueSubmit with a semaphore that is already "
Mark Mueller1cd9f412016-08-25 13:23:52 -060011735 "signaled but not waited on by the queue. Wait on a "
11736 "fence that has not yet been submitted to a queue.");
Mark Mueller96a56d52016-08-24 10:28:05 -060011737
11738 ASSERT_NO_FATAL_FAILURE(InitState());
11739 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11740
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011741 const char *queue_forward_progress_message = " that has already been signaled but not waited on by queue 0x";
11742 const char *invalid_fence_wait_message = " which has not been submitted on a Queue or during "
11743 "acquire next image.";
Mark Mueller96a56d52016-08-24 10:28:05 -060011744
11745 BeginCommandBuffer();
11746 EndCommandBuffer();
11747
11748 VkSemaphoreCreateInfo semaphore_create_info = {};
11749 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
11750 VkSemaphore semaphore;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011751 ASSERT_VK_SUCCESS(vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore));
Mark Mueller96a56d52016-08-24 10:28:05 -060011752 VkSubmitInfo submit_info = {};
11753 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11754 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011755 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Mueller96a56d52016-08-24 10:28:05 -060011756 submit_info.signalSemaphoreCount = 1;
11757 submit_info.pSignalSemaphores = &semaphore;
11758 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11759 m_errorMonitor->SetDesiredFailureMsg(0, "");
11760 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
11761 BeginCommandBuffer();
11762 EndCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011763 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, queue_forward_progress_message);
Mark Mueller96a56d52016-08-24 10:28:05 -060011764 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11765 m_errorMonitor->VerifyFound();
11766
Mark Mueller1cd9f412016-08-25 13:23:52 -060011767 VkFenceCreateInfo fence_create_info = {};
11768 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
11769 VkFence fence;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011770 ASSERT_VK_SUCCESS(vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence));
Mark Mueller1cd9f412016-08-25 13:23:52 -060011771
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011772 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, invalid_fence_wait_message);
Mark Mueller1cd9f412016-08-25 13:23:52 -060011773 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
11774 m_errorMonitor->VerifyFound();
11775
Mark Mueller4042b652016-09-05 22:52:21 -060011776 vkDeviceWaitIdle(m_device->device());
Mark Mueller1cd9f412016-08-25 13:23:52 -060011777 vkDestroyFence(m_device->device(), fence, nullptr);
Mark Mueller96a56d52016-08-24 10:28:05 -060011778 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
11779}
11780
Tobin Ehlis4af23302016-07-19 10:50:30 -060011781TEST_F(VkLayerTest, FramebufferIncompatible) {
11782 TEST_DESCRIPTION("Bind a secondary command buffer with with a framebuffer "
11783 "that does not match the framebuffer for the active "
11784 "renderpass.");
11785 ASSERT_NO_FATAL_FAILURE(InitState());
11786 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11787
11788 // A renderpass with one color attachment.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011789 VkAttachmentDescription attachment = {0,
11790 VK_FORMAT_B8G8R8A8_UNORM,
11791 VK_SAMPLE_COUNT_1_BIT,
11792 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
11793 VK_ATTACHMENT_STORE_OP_STORE,
11794 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
11795 VK_ATTACHMENT_STORE_OP_DONT_CARE,
11796 VK_IMAGE_LAYOUT_UNDEFINED,
11797 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis4af23302016-07-19 10:50:30 -060011798
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011799 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis4af23302016-07-19 10:50:30 -060011800
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011801 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Tobin Ehlis4af23302016-07-19 10:50:30 -060011802
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011803 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
Tobin Ehlis4af23302016-07-19 10:50:30 -060011804
11805 VkRenderPass rp;
11806 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
11807 ASSERT_VK_SUCCESS(err);
11808
11809 // A compatible framebuffer.
11810 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011811 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 -060011812 ASSERT_TRUE(image.initialized());
11813
11814 VkImageViewCreateInfo ivci = {
11815 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
11816 nullptr,
11817 0,
11818 image.handle(),
11819 VK_IMAGE_VIEW_TYPE_2D,
11820 VK_FORMAT_B8G8R8A8_UNORM,
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011821 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
11822 VK_COMPONENT_SWIZZLE_IDENTITY},
Tobin Ehlis4af23302016-07-19 10:50:30 -060011823 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
11824 };
11825 VkImageView view;
11826 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
11827 ASSERT_VK_SUCCESS(err);
11828
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011829 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Tobin Ehlis4af23302016-07-19 10:50:30 -060011830 VkFramebuffer fb;
11831 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
11832 ASSERT_VK_SUCCESS(err);
11833
11834 VkCommandBufferAllocateInfo cbai = {};
11835 cbai.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
11836 cbai.commandPool = m_commandPool;
11837 cbai.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
11838 cbai.commandBufferCount = 1;
11839
11840 VkCommandBuffer sec_cb;
11841 err = vkAllocateCommandBuffers(m_device->device(), &cbai, &sec_cb);
11842 ASSERT_VK_SUCCESS(err);
11843 VkCommandBufferBeginInfo cbbi = {};
11844 VkCommandBufferInheritanceInfo cbii = {};
Chris Forbes98420382016-11-28 17:56:51 +130011845 cbii.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
Tobin Ehlis4af23302016-07-19 10:50:30 -060011846 cbii.renderPass = renderPass();
11847 cbii.framebuffer = fb;
11848 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
11849 cbbi.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011850 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 -060011851 cbbi.pInheritanceInfo = &cbii;
11852 vkBeginCommandBuffer(sec_cb, &cbbi);
11853 vkEndCommandBuffer(sec_cb);
11854
Chris Forbes3400bc52016-09-13 18:10:34 +120011855 VkCommandBufferBeginInfo cbbi2 = {
11856 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr,
11857 0, nullptr
11858 };
11859 vkBeginCommandBuffer(m_commandBuffer->GetBufferHandle(), &cbbi2);
11860 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
Tobin Ehlis4af23302016-07-19 10:50:30 -060011861
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011862 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mike Weiblencce7ec72016-10-17 19:33:05 -060011863 " that is not the same as the primary command buffer's current active framebuffer ");
Tobin Ehlis4af23302016-07-19 10:50:30 -060011864 vkCmdExecuteCommands(m_commandBuffer->GetBufferHandle(), 1, &sec_cb);
11865 m_errorMonitor->VerifyFound();
11866 // Cleanup
11867 vkDestroyImageView(m_device->device(), view, NULL);
11868 vkDestroyRenderPass(m_device->device(), rp, NULL);
11869 vkDestroyFramebuffer(m_device->device(), fb, NULL);
11870}
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011871
11872TEST_F(VkLayerTest, ColorBlendLogicOpTests) {
11873 TEST_DESCRIPTION("If logicOp is available on the device, set it to an "
11874 "invalid value. If logicOp is not available, attempt to "
11875 "use it and verify that we see the correct error.");
11876 ASSERT_NO_FATAL_FAILURE(InitState());
11877 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11878
11879 auto features = m_device->phy().features();
11880 // Set the expected error depending on whether or not logicOp available
11881 if (VK_FALSE == features.logicOp) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011882 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "If logic operations feature not "
11883 "enabled, logicOpEnable must be "
11884 "VK_FALSE");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011885 } else {
Chris Forbes34797bc2016-10-03 15:28:49 +130011886 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "pColorBlendState->logicOp (16)");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011887 }
11888 // Create a pipeline using logicOp
11889 VkResult err;
11890
11891 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11892 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11893
11894 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011895 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011896 ASSERT_VK_SUCCESS(err);
11897
11898 VkPipelineViewportStateCreateInfo vp_state_ci = {};
11899 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
11900 vp_state_ci.viewportCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011901 VkViewport vp = {}; // Just need dummy vp to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011902 vp_state_ci.pViewports = &vp;
11903 vp_state_ci.scissorCount = 1;
11904 VkRect2D scissors = {}; // Dummy scissors to point to
11905 vp_state_ci.pScissors = &scissors;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011906
11907 VkPipelineShaderStageCreateInfo shaderStages[2];
11908 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
11909
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011910 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
11911 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011912 shaderStages[0] = vs.GetStageCreateInfo();
11913 shaderStages[1] = fs.GetStageCreateInfo();
11914
11915 VkPipelineVertexInputStateCreateInfo vi_ci = {};
11916 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
11917
11918 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
11919 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
11920 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
11921
11922 VkPipelineRasterizationStateCreateInfo rs_ci = {};
11923 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Chris Forbes14088512016-10-03 14:28:00 +130011924 rs_ci.lineWidth = 1.0f;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011925
11926 VkPipelineColorBlendAttachmentState att = {};
11927 att.blendEnable = VK_FALSE;
11928 att.colorWriteMask = 0xf;
11929
11930 VkPipelineColorBlendStateCreateInfo cb_ci = {};
11931 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
11932 // Enable logicOp & set logicOp to value 1 beyond allowed entries
11933 cb_ci.logicOpEnable = VK_TRUE;
11934 cb_ci.logicOp = VK_LOGIC_OP_RANGE_SIZE; // This should cause an error
11935 cb_ci.attachmentCount = 1;
11936 cb_ci.pAttachments = &att;
11937
Chris Forbes8aeacbf2016-10-03 14:25:08 +130011938 VkPipelineMultisampleStateCreateInfo ms_ci = {};
11939 ms_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
11940 ms_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
11941
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011942 VkGraphicsPipelineCreateInfo gp_ci = {};
11943 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
11944 gp_ci.stageCount = 2;
11945 gp_ci.pStages = shaderStages;
11946 gp_ci.pVertexInputState = &vi_ci;
11947 gp_ci.pInputAssemblyState = &ia_ci;
11948 gp_ci.pViewportState = &vp_state_ci;
11949 gp_ci.pRasterizationState = &rs_ci;
11950 gp_ci.pColorBlendState = &cb_ci;
Chris Forbes8aeacbf2016-10-03 14:25:08 +130011951 gp_ci.pMultisampleState = &ms_ci;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011952 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
11953 gp_ci.layout = pipeline_layout;
11954 gp_ci.renderPass = renderPass();
11955
11956 VkPipelineCacheCreateInfo pc_ci = {};
11957 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
11958
11959 VkPipeline pipeline;
11960 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011961 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011962 ASSERT_VK_SUCCESS(err);
11963
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011964 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011965 m_errorMonitor->VerifyFound();
11966 if (VK_SUCCESS == err) {
11967 vkDestroyPipeline(m_device->device(), pipeline, NULL);
11968 }
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011969 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
11970 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11971}
Mark Lobodzinski209b5292015-09-17 09:44:05 -060011972#endif // DRAW_STATE_TESTS
11973
Tobin Ehlis0788f522015-05-26 16:11:58 -060011974#if THREADING_TESTS
Mike Stroyanaccf7692015-05-12 16:00:45 -060011975#if GTEST_IS_THREADSAFE
11976struct thread_data_struct {
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011977 VkCommandBuffer commandBuffer;
Mike Stroyanaccf7692015-05-12 16:00:45 -060011978 VkEvent event;
11979 bool bailout;
11980};
11981
Karl Schultz6addd812016-02-02 17:17:23 -070011982extern "C" void *AddToCommandBuffer(void *arg) {
11983 struct thread_data_struct *data = (struct thread_data_struct *)arg;
Mike Stroyanaccf7692015-05-12 16:00:45 -060011984
Mike Stroyana6d14942016-07-13 15:10:05 -060011985 for (int i = 0; i < 80000; i++) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011986 vkCmdSetEvent(data->commandBuffer, data->event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Mike Stroyanaccf7692015-05-12 16:00:45 -060011987 if (data->bailout) {
11988 break;
11989 }
11990 }
11991 return NULL;
11992}
11993
Karl Schultz6addd812016-02-02 17:17:23 -070011994TEST_F(VkLayerTest, ThreadCommandBufferCollision) {
Mike Stroyan4268d1f2015-07-13 14:45:35 -060011995 test_platform_thread thread;
Mike Stroyanaccf7692015-05-12 16:00:45 -060011996
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011997 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "THREADING ERROR");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011998
Mike Stroyanaccf7692015-05-12 16:00:45 -060011999 ASSERT_NO_FATAL_FAILURE(InitState());
12000 ASSERT_NO_FATAL_FAILURE(InitViewport());
12001 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12002
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012003 // Calls AllocateCommandBuffers
12004 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Mark Lobodzinski5495d132015-09-30 16:19:16 -060012005
12006 // Avoid creating RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012007 commandBuffer.BeginCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -060012008
12009 VkEventCreateInfo event_info;
12010 VkEvent event;
Mike Stroyanaccf7692015-05-12 16:00:45 -060012011 VkResult err;
12012
12013 memset(&event_info, 0, sizeof(event_info));
12014 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
12015
Chia-I Wuf7458c52015-10-26 21:10:41 +080012016 err = vkCreateEvent(device(), &event_info, NULL, &event);
Mike Stroyanaccf7692015-05-12 16:00:45 -060012017 ASSERT_VK_SUCCESS(err);
12018
Mike Stroyanaccf7692015-05-12 16:00:45 -060012019 err = vkResetEvent(device(), event);
12020 ASSERT_VK_SUCCESS(err);
12021
12022 struct thread_data_struct data;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012023 data.commandBuffer = commandBuffer.GetBufferHandle();
Mike Stroyanaccf7692015-05-12 16:00:45 -060012024 data.event = event;
12025 data.bailout = false;
12026 m_errorMonitor->SetBailout(&data.bailout);
Mike Stroyana6d14942016-07-13 15:10:05 -060012027
12028 // First do some correct operations using multiple threads.
12029 // Add many entries to command buffer from another thread.
12030 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
12031 // Make non-conflicting calls from this thread at the same time.
12032 for (int i = 0; i < 80000; i++) {
Mike Stroyand6343902016-07-14 08:56:16 -060012033 uint32_t count;
12034 vkEnumeratePhysicalDevices(instance(), &count, NULL);
Mike Stroyana6d14942016-07-13 15:10:05 -060012035 }
12036 test_platform_thread_join(thread, NULL);
12037
12038 // Then do some incorrect operations using multiple threads.
Mike Stroyanaccf7692015-05-12 16:00:45 -060012039 // Add many entries to command buffer from another thread.
Mike Stroyan4268d1f2015-07-13 14:45:35 -060012040 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
Mike Stroyanaccf7692015-05-12 16:00:45 -060012041 // Add many entries to command buffer from this thread at the same time.
12042 AddToCommandBuffer(&data);
Mark Lobodzinski5495d132015-09-30 16:19:16 -060012043
Mike Stroyan4268d1f2015-07-13 14:45:35 -060012044 test_platform_thread_join(thread, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012045 commandBuffer.EndCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -060012046
Mike Stroyan10b8cb72016-01-22 15:22:03 -070012047 m_errorMonitor->SetBailout(NULL);
12048
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012049 m_errorMonitor->VerifyFound();
Mike Stroyanaccf7692015-05-12 16:00:45 -060012050
Chia-I Wuf7458c52015-10-26 21:10:41 +080012051 vkDestroyEvent(device(), event, NULL);
Mike Stroyanaccf7692015-05-12 16:00:45 -060012052}
Mark Lobodzinski209b5292015-09-17 09:44:05 -060012053#endif // GTEST_IS_THREADSAFE
12054#endif // THREADING_TESTS
12055
Chris Forbes9f7ff632015-05-25 11:13:08 +120012056#if SHADER_CHECKER_TESTS
Karl Schultz6addd812016-02-02 17:17:23 -070012057TEST_F(VkLayerTest, InvalidSPIRVCodeSize) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012058 TEST_DESCRIPTION("Test that an error is produced for a spirv module "
12059 "with an impossible code size");
12060
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012061 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012062
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012063 ASSERT_NO_FATAL_FAILURE(InitState());
12064 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12065
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012066 VkShaderModule module;
12067 VkShaderModuleCreateInfo moduleCreateInfo;
12068 struct icd_spv_header spv;
12069
12070 spv.magic = ICD_SPV_MAGIC;
12071 spv.version = ICD_SPV_VERSION;
12072 spv.gen_magic = 0;
12073
12074 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
12075 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -070012076 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012077 moduleCreateInfo.codeSize = 4;
12078 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080012079 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012080
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012081 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012082}
12083
Karl Schultz6addd812016-02-02 17:17:23 -070012084TEST_F(VkLayerTest, InvalidSPIRVMagic) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012085 TEST_DESCRIPTION("Test that an error is produced for a spirv module "
12086 "with a bad magic number");
12087
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012088 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid SPIR-V magic number");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012089
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012090 ASSERT_NO_FATAL_FAILURE(InitState());
12091 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12092
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012093 VkShaderModule module;
12094 VkShaderModuleCreateInfo moduleCreateInfo;
12095 struct icd_spv_header spv;
12096
12097 spv.magic = ~ICD_SPV_MAGIC;
12098 spv.version = ICD_SPV_VERSION;
12099 spv.gen_magic = 0;
12100
12101 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
12102 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -070012103 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012104 moduleCreateInfo.codeSize = sizeof(spv) + 10;
12105 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080012106 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012107
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012108 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012109}
12110
Chris Forbesb4afd0f2016-04-04 10:48:35 +120012111#if 0
12112// Not currently covered by SPIRV-Tools validator
Karl Schultz6addd812016-02-02 17:17:23 -070012113TEST_F(VkLayerTest, InvalidSPIRVVersion) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -070012114 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbesb4afd0f2016-04-04 10:48:35 +120012115 "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012116
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012117 ASSERT_NO_FATAL_FAILURE(InitState());
12118 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12119
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012120 VkShaderModule module;
12121 VkShaderModuleCreateInfo moduleCreateInfo;
12122 struct icd_spv_header spv;
12123
12124 spv.magic = ICD_SPV_MAGIC;
12125 spv.version = ~ICD_SPV_VERSION;
12126 spv.gen_magic = 0;
12127
12128 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
12129 moduleCreateInfo.pNext = NULL;
12130
Karl Schultz6addd812016-02-02 17:17:23 -070012131 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012132 moduleCreateInfo.codeSize = sizeof(spv) + 10;
12133 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080012134 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012135
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012136 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012137}
Chris Forbesb4afd0f2016-04-04 10:48:35 +120012138#endif
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012139
Karl Schultz6addd812016-02-02 17:17:23 -070012140TEST_F(VkLayerTest, CreatePipelineVertexOutputNotConsumed) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012141 TEST_DESCRIPTION("Test that a warning is produced for a vertex output that "
12142 "is not consumed by the fragment stage");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012143 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "not consumed by fragment shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012144
Chris Forbes9f7ff632015-05-25 11:13:08 +120012145 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060012146 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes9f7ff632015-05-25 11:13:08 +120012147
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012148 char const *vsSource = "#version 450\n"
12149 "\n"
12150 "layout(location=0) out float x;\n"
12151 "out gl_PerVertex {\n"
12152 " vec4 gl_Position;\n"
12153 "};\n"
12154 "void main(){\n"
12155 " gl_Position = vec4(1);\n"
12156 " x = 0;\n"
12157 "}\n";
12158 char const *fsSource = "#version 450\n"
12159 "\n"
12160 "layout(location=0) out vec4 color;\n"
12161 "void main(){\n"
12162 " color = vec4(1);\n"
12163 "}\n";
Chris Forbes9f7ff632015-05-25 11:13:08 +120012164
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012165 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12166 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes9f7ff632015-05-25 11:13:08 +120012167
12168 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080012169 pipe.AddColorAttachment();
Chris Forbes9f7ff632015-05-25 11:13:08 +120012170 pipe.AddShader(&vs);
12171 pipe.AddShader(&fs);
12172
Chris Forbes9f7ff632015-05-25 11:13:08 +120012173 VkDescriptorSetObj descriptorSet(m_device);
12174 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012175 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes9f7ff632015-05-25 11:13:08 +120012176
Tony Barbour5781e8f2015-08-04 16:23:11 -060012177 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes9f7ff632015-05-25 11:13:08 +120012178
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012179 m_errorMonitor->VerifyFound();
Chris Forbes9f7ff632015-05-25 11:13:08 +120012180}
Chris Forbes9f7ff632015-05-25 11:13:08 +120012181
Mark Mueller098c9cb2016-09-08 09:01:57 -060012182TEST_F(VkLayerTest, CreatePipelineCheckShaderBadSpecialization) {
12183 TEST_DESCRIPTION("Challenge core_validation with shader validation issues related to vkCreateGraphicsPipelines.");
12184
12185 ASSERT_NO_FATAL_FAILURE(InitState());
12186 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12187
12188 const char *bad_specialization_message =
12189 "Specialization entry 0 (for constant id 0) references memory outside provided specialization data ";
12190
12191 char const *vsSource =
12192 "#version 450\n"
12193 "\n"
12194 "out gl_PerVertex {\n"
12195 " vec4 gl_Position;\n"
12196 "};\n"
12197 "void main(){\n"
12198 " gl_Position = vec4(1);\n"
12199 "}\n";
12200
12201 char const *fsSource =
12202 "#version 450\n"
12203 "\n"
12204 "layout (constant_id = 0) const float r = 0.0f;\n"
12205 "layout(location = 0) out vec4 uFragColor;\n"
12206 "void main(){\n"
12207 " uFragColor = vec4(r,1,0,1);\n"
12208 "}\n";
12209
12210 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12211 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12212
12213 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
12214 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12215
12216 VkPipelineLayout pipeline_layout;
12217 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
12218
12219 VkPipelineViewportStateCreateInfo vp_state_create_info = {};
12220 vp_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
12221 vp_state_create_info.viewportCount = 1;
12222 VkViewport viewport = {};
12223 vp_state_create_info.pViewports = &viewport;
12224 vp_state_create_info.scissorCount = 1;
12225 VkRect2D scissors = {};
12226 vp_state_create_info.pScissors = &scissors;
12227
12228 VkDynamicState scissor_state = VK_DYNAMIC_STATE_SCISSOR;
12229
12230 VkPipelineDynamicStateCreateInfo pipeline_dynamic_state_create_info = {};
12231 pipeline_dynamic_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
12232 pipeline_dynamic_state_create_info.dynamicStateCount = 1;
12233 pipeline_dynamic_state_create_info.pDynamicStates = &scissor_state;
12234
12235 VkPipelineShaderStageCreateInfo shader_stage_create_info[2] = {
12236 vs.GetStageCreateInfo(),
12237 fs.GetStageCreateInfo()
12238 };
12239
12240 VkPipelineVertexInputStateCreateInfo vertex_input_create_info = {};
12241 vertex_input_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
12242
12243 VkPipelineInputAssemblyStateCreateInfo input_assembly_create_info = {};
12244 input_assembly_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
12245 input_assembly_create_info.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
12246
12247 VkPipelineRasterizationStateCreateInfo rasterization_state_create_info = {};
12248 rasterization_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
12249 rasterization_state_create_info.pNext = nullptr;
12250 rasterization_state_create_info.lineWidth = 1.0f;
12251 rasterization_state_create_info.rasterizerDiscardEnable = true;
12252
12253 VkPipelineColorBlendAttachmentState color_blend_attachment_state = {};
12254 color_blend_attachment_state.blendEnable = VK_FALSE;
12255 color_blend_attachment_state.colorWriteMask = 0xf;
12256
12257 VkPipelineColorBlendStateCreateInfo color_blend_state_create_info = {};
12258 color_blend_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
12259 color_blend_state_create_info.attachmentCount = 1;
12260 color_blend_state_create_info.pAttachments = &color_blend_attachment_state;
12261
12262 VkGraphicsPipelineCreateInfo graphicspipe_create_info = {};
12263 graphicspipe_create_info.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
12264 graphicspipe_create_info.stageCount = 2;
12265 graphicspipe_create_info.pStages = shader_stage_create_info;
12266 graphicspipe_create_info.pVertexInputState = &vertex_input_create_info;
12267 graphicspipe_create_info.pInputAssemblyState = &input_assembly_create_info;
12268 graphicspipe_create_info.pViewportState = &vp_state_create_info;
12269 graphicspipe_create_info.pRasterizationState = &rasterization_state_create_info;
12270 graphicspipe_create_info.pColorBlendState = &color_blend_state_create_info;
12271 graphicspipe_create_info.pDynamicState = &pipeline_dynamic_state_create_info;
12272 graphicspipe_create_info.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
12273 graphicspipe_create_info.layout = pipeline_layout;
12274 graphicspipe_create_info.renderPass = renderPass();
12275
12276 VkPipelineCacheCreateInfo pipeline_cache_create_info = {};
12277 pipeline_cache_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
12278
12279 VkPipelineCache pipelineCache;
12280 ASSERT_VK_SUCCESS(vkCreatePipelineCache(m_device->device(), &pipeline_cache_create_info, nullptr, &pipelineCache));
12281
12282 // This structure maps constant ids to data locations.
12283 const VkSpecializationMapEntry entry =
12284 // id, offset, size
12285 {0, 4, sizeof(uint32_t)}; // Challenge core validation by using a bogus offset.
12286
12287 uint32_t data = 1;
12288
12289 // Set up the info describing spec map and data
12290 const VkSpecializationInfo specialization_info = {
12291 1,
12292 &entry,
12293 1 * sizeof(float),
12294 &data,
12295 };
12296 shader_stage_create_info[0].pSpecializationInfo = &specialization_info;
12297
12298 VkPipeline pipeline;
12299 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bad_specialization_message);
12300 vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &graphicspipe_create_info, nullptr, &pipeline);
12301 m_errorMonitor->VerifyFound();
12302
12303 vkDestroyPipelineCache(m_device->device(), pipelineCache, nullptr);
12304 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
12305}
12306
12307TEST_F(VkLayerTest, CreatePipelineCheckShaderDescriptorTypeMismatch) {
12308 TEST_DESCRIPTION("Challenge core_validation with shader validation issues related to vkCreateGraphicsPipelines.");
12309
12310 ASSERT_NO_FATAL_FAILURE(InitState());
12311 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12312
12313 const char *descriptor_type_mismatch_message = "Type mismatch on descriptor slot 0.0 (used as type ";
12314
12315 VkDescriptorPoolSize descriptor_pool_type_count[2] = {};
12316 descriptor_pool_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
12317 descriptor_pool_type_count[0].descriptorCount = 1;
12318 descriptor_pool_type_count[1].type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
12319 descriptor_pool_type_count[1].descriptorCount = 1;
12320
12321 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
12322 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12323 descriptor_pool_create_info.maxSets = 1;
12324 descriptor_pool_create_info.poolSizeCount = 2;
12325 descriptor_pool_create_info.pPoolSizes = descriptor_pool_type_count;
12326 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
12327
12328 VkDescriptorPool descriptorset_pool;
12329 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
12330
12331 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
12332 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
12333 descriptorset_layout_binding.descriptorCount = 1;
12334 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_ALL;
12335
12336 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
12337 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
12338 descriptorset_layout_create_info.bindingCount = 1;
12339 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
12340
12341 VkDescriptorSetLayout descriptorset_layout;
12342 ASSERT_VK_SUCCESS(vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
12343
12344 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
12345 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
12346 descriptorset_allocate_info.descriptorSetCount = 1;
12347 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
12348 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
12349 VkDescriptorSet descriptorset;
12350 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
12351
12352 // Challenge core_validation with a non uniform buffer type.
12353 VkBufferTest storage_buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT);
12354
Mark Mueller098c9cb2016-09-08 09:01:57 -060012355 char const *vsSource =
12356 "#version 450\n"
12357 "\n"
12358 "layout (std140, set = 0, binding = 0) uniform buf {\n"
12359 " mat4 mvp;\n"
12360 "} ubuf;\n"
12361 "out gl_PerVertex {\n"
12362 " vec4 gl_Position;\n"
12363 "};\n"
12364 "void main(){\n"
12365 " gl_Position = ubuf.mvp * vec4(1);\n"
12366 "}\n";
12367
12368 char const *fsSource =
12369 "#version 450\n"
12370 "\n"
12371 "layout(location = 0) out vec4 uFragColor;\n"
12372 "void main(){\n"
12373 " uFragColor = vec4(0,1,0,1);\n"
12374 "}\n";
12375
12376 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12377 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12378
12379 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
12380 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12381 pipeline_layout_create_info.setLayoutCount = 1;
12382 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
12383
12384 VkPipelineLayout pipeline_layout;
12385 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
12386
12387 VkPipelineObj pipe(m_device);
12388 pipe.AddColorAttachment();
12389 pipe.AddShader(&vs);
12390 pipe.AddShader(&fs);
12391
12392 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, descriptor_type_mismatch_message);
12393 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12394 m_errorMonitor->VerifyFound();
12395
12396 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
12397 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
12398 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
12399}
12400
12401TEST_F(VkLayerTest, CreatePipelineCheckShaderDescriptorNotAccessible) {
12402 TEST_DESCRIPTION(
12403 "Create a pipeline in which a descriptor used by a shader stage does not include that stage in its stageFlags.");
12404
12405 ASSERT_NO_FATAL_FAILURE(InitState());
12406 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12407
12408 const char *descriptor_not_accessible_message = "Shader uses descriptor slot 0.0 (used as type ";
12409
12410 VkDescriptorPoolSize descriptor_pool_type_count = {};
12411 descriptor_pool_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
12412 descriptor_pool_type_count.descriptorCount = 1;
12413
12414 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
12415 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12416 descriptor_pool_create_info.maxSets = 1;
12417 descriptor_pool_create_info.poolSizeCount = 1;
12418 descriptor_pool_create_info.pPoolSizes = &descriptor_pool_type_count;
12419 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
12420
12421 VkDescriptorPool descriptorset_pool;
12422 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
12423
12424 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
12425 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
12426 descriptorset_layout_binding.descriptorCount = 1;
12427 // Intentionally make the uniform buffer inaccessible to the vertex shader to challenge core_validation
12428 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
12429
12430 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
12431 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
12432 descriptorset_layout_create_info.bindingCount = 1;
12433 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
12434
12435 VkDescriptorSetLayout descriptorset_layout;
12436 ASSERT_VK_SUCCESS(vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info,
12437 nullptr, &descriptorset_layout));
12438
12439 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
12440 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
12441 descriptorset_allocate_info.descriptorSetCount = 1;
12442 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
12443 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
12444 VkDescriptorSet descriptorset;
12445 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
12446
12447 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
12448
Mark Mueller098c9cb2016-09-08 09:01:57 -060012449 char const *vsSource =
12450 "#version 450\n"
12451 "\n"
12452 "layout (std140, set = 0, binding = 0) uniform buf {\n"
12453 " mat4 mvp;\n"
12454 "} ubuf;\n"
12455 "out gl_PerVertex {\n"
12456 " vec4 gl_Position;\n"
12457 "};\n"
12458 "void main(){\n"
12459 " gl_Position = ubuf.mvp * vec4(1);\n"
12460 "}\n";
12461
12462 char const *fsSource =
12463 "#version 450\n"
12464 "\n"
12465 "layout(location = 0) out vec4 uFragColor;\n"
12466 "void main(){\n"
12467 " uFragColor = vec4(0,1,0,1);\n"
12468 "}\n";
12469
12470 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12471 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12472
12473 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
12474 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12475 pipeline_layout_create_info.setLayoutCount = 1;
12476 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
12477
12478 VkPipelineLayout pipeline_layout;
12479 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
12480
12481 VkPipelineObj pipe(m_device);
12482 pipe.AddColorAttachment();
12483 pipe.AddShader(&vs);
12484 pipe.AddShader(&fs);
12485
12486 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, descriptor_not_accessible_message);
12487 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12488 m_errorMonitor->VerifyFound();
12489
12490 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
12491 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
12492 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
12493}
12494
12495TEST_F(VkLayerTest, CreatePipelineCheckShaderPushConstantNotAccessible) {
12496 TEST_DESCRIPTION("Create a graphics pipleine in which a push constant range containing a push constant block member is not "
12497 "accessible from the current shader stage.");
12498
12499 ASSERT_NO_FATAL_FAILURE(InitState());
12500 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12501
12502 const char *push_constant_not_accessible_message =
12503 "Push constant range covering variable starting at offset 0 not accessible from stage VK_SHADER_STAGE_VERTEX_BIT";
12504
12505 char const *vsSource =
12506 "#version 450\n"
12507 "\n"
12508 "layout(push_constant, std430) uniform foo { float x; } consts;\n"
12509 "out gl_PerVertex {\n"
12510 " vec4 gl_Position;\n"
12511 "};\n"
12512 "void main(){\n"
12513 " gl_Position = vec4(consts.x);\n"
12514 "}\n";
12515
12516 char const *fsSource =
12517 "#version 450\n"
12518 "\n"
12519 "layout(location = 0) out vec4 uFragColor;\n"
12520 "void main(){\n"
12521 " uFragColor = vec4(0,1,0,1);\n"
12522 "}\n";
12523
12524 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12525 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12526
12527 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
12528 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12529
12530 // Set up a push constant range
12531 VkPushConstantRange push_constant_ranges = {};
12532 // Set to the wrong stage to challenge core_validation
12533 push_constant_ranges.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
12534 push_constant_ranges.size = 4;
12535
12536 pipeline_layout_create_info.pPushConstantRanges = &push_constant_ranges;
12537 pipeline_layout_create_info.pushConstantRangeCount = 1;
12538
12539 VkPipelineLayout pipeline_layout;
12540 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
12541
12542 VkPipelineObj pipe(m_device);
12543 pipe.AddColorAttachment();
12544 pipe.AddShader(&vs);
12545 pipe.AddShader(&fs);
12546
12547 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, push_constant_not_accessible_message);
12548 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12549 m_errorMonitor->VerifyFound();
12550
12551 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
12552}
12553
12554TEST_F(VkLayerTest, CreatePipelineCheckShaderNotEnabled) {
12555 TEST_DESCRIPTION(
12556 "Create a graphics pipeline in which a capability declared by the shader requires a feature not enabled on the device.");
12557
12558 ASSERT_NO_FATAL_FAILURE(InitState());
12559 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12560
12561 const char *feature_not_enabled_message =
12562 "Shader requires VkPhysicalDeviceFeatures::shaderFloat64 but is not enabled on the device";
12563
12564 // Some awkward steps are required to test with custom device features.
12565 std::vector<const char *> device_extension_names;
12566 auto features = m_device->phy().features();
12567 // Disable support for 64 bit floats
12568 features.shaderFloat64 = false;
12569 // The sacrificial device object
12570 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
12571
12572 char const *vsSource = "#version 450\n"
12573 "\n"
12574 "out gl_PerVertex {\n"
12575 " vec4 gl_Position;\n"
12576 "};\n"
12577 "void main(){\n"
12578 " gl_Position = vec4(1);\n"
12579 "}\n";
12580 char const *fsSource = "#version 450\n"
12581 "\n"
12582 "layout(location=0) out vec4 color;\n"
12583 "void main(){\n"
12584 " dvec4 green = vec4(0.0, 1.0, 0.0, 1.0);\n"
12585 " color = vec4(green);\n"
12586 "}\n";
12587
12588 VkShaderObj vs(&test_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12589 VkShaderObj fs(&test_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12590
12591 VkRenderpassObj render_pass(&test_device);
Mark Mueller098c9cb2016-09-08 09:01:57 -060012592
12593 VkPipelineObj pipe(&test_device);
12594 pipe.AddColorAttachment();
12595 pipe.AddShader(&vs);
12596 pipe.AddShader(&fs);
12597
12598 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
12599 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12600 VkPipelineLayout pipeline_layout;
12601 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(test_device.device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
12602
12603 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, feature_not_enabled_message);
12604 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
12605 m_errorMonitor->VerifyFound();
12606
12607 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, nullptr);
12608}
12609
12610TEST_F(VkLayerTest, CreatePipelineCheckShaderBadCapability) {
12611 TEST_DESCRIPTION("Create a graphics pipeline in which a capability declared by the shader is not supported by Vulkan shaders.");
12612
12613 ASSERT_NO_FATAL_FAILURE(InitState());
12614 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12615
12616 const char *bad_capability_message = "Shader declares capability 53, not supported in Vulkan.";
12617
12618 char const *vsSource = "#version 450\n"
12619 "\n"
12620 "out gl_PerVertex {\n"
12621 " vec4 gl_Position;\n"
12622 "};\n"
12623 "layout(xfb_buffer = 1) out;"
12624 "void main(){\n"
12625 " gl_Position = vec4(1);\n"
12626 "}\n";
12627 char const *fsSource = "#version 450\n"
12628 "\n"
12629 "layout(location=0) out vec4 color;\n"
12630 "void main(){\n"
12631 " dvec4 green = vec4(0.0, 1.0, 0.0, 1.0);\n"
12632 " color = vec4(green);\n"
12633 "}\n";
12634
12635 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12636 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12637
12638 VkPipelineObj pipe(m_device);
12639 pipe.AddColorAttachment();
12640 pipe.AddShader(&vs);
12641 pipe.AddShader(&fs);
12642
12643 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
12644 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12645 VkPipelineLayout pipeline_layout;
12646 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
12647
12648 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bad_capability_message);
12649 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12650 m_errorMonitor->VerifyFound();
12651
12652 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
12653}
12654
Karl Schultz6addd812016-02-02 17:17:23 -070012655TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvided) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012656 TEST_DESCRIPTION("Test that an error is produced for a fragment shader input "
12657 "which is not present in the outputs of the previous stage");
12658
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012659 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not written by vertex shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012660
Chris Forbes59cb88d2015-05-25 11:13:13 +120012661 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060012662 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes59cb88d2015-05-25 11:13:13 +120012663
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012664 char const *vsSource = "#version 450\n"
12665 "\n"
12666 "out gl_PerVertex {\n"
12667 " vec4 gl_Position;\n"
12668 "};\n"
12669 "void main(){\n"
12670 " gl_Position = vec4(1);\n"
12671 "}\n";
12672 char const *fsSource = "#version 450\n"
12673 "\n"
12674 "layout(location=0) in float x;\n"
12675 "layout(location=0) out vec4 color;\n"
12676 "void main(){\n"
12677 " color = vec4(x);\n"
12678 "}\n";
Chris Forbes59cb88d2015-05-25 11:13:13 +120012679
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012680 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12681 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes59cb88d2015-05-25 11:13:13 +120012682
12683 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080012684 pipe.AddColorAttachment();
Chris Forbes59cb88d2015-05-25 11:13:13 +120012685 pipe.AddShader(&vs);
12686 pipe.AddShader(&fs);
12687
Chris Forbes59cb88d2015-05-25 11:13:13 +120012688 VkDescriptorSetObj descriptorSet(m_device);
12689 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012690 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes59cb88d2015-05-25 11:13:13 +120012691
Tony Barbour5781e8f2015-08-04 16:23:11 -060012692 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes59cb88d2015-05-25 11:13:13 +120012693
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012694 m_errorMonitor->VerifyFound();
Chris Forbes59cb88d2015-05-25 11:13:13 +120012695}
12696
Karl Schultz6addd812016-02-02 17:17:23 -070012697TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvidedInBlock) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012698 TEST_DESCRIPTION("Test that an error is produced for a fragment shader input "
12699 "within an interace block, which is not present in the outputs "
12700 "of the previous stage.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012701 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not written by vertex shader");
Chris Forbesa3e85f62016-01-15 14:53:11 +130012702
12703 ASSERT_NO_FATAL_FAILURE(InitState());
12704 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12705
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012706 char const *vsSource = "#version 450\n"
12707 "\n"
12708 "out gl_PerVertex {\n"
12709 " vec4 gl_Position;\n"
12710 "};\n"
12711 "void main(){\n"
12712 " gl_Position = vec4(1);\n"
12713 "}\n";
12714 char const *fsSource = "#version 450\n"
12715 "\n"
12716 "in block { layout(location=0) float x; } ins;\n"
12717 "layout(location=0) out vec4 color;\n"
12718 "void main(){\n"
12719 " color = vec4(ins.x);\n"
12720 "}\n";
Chris Forbesa3e85f62016-01-15 14:53:11 +130012721
12722 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12723 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12724
12725 VkPipelineObj pipe(m_device);
12726 pipe.AddColorAttachment();
12727 pipe.AddShader(&vs);
12728 pipe.AddShader(&fs);
12729
12730 VkDescriptorSetObj descriptorSet(m_device);
12731 descriptorSet.AppendDummy();
12732 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12733
12734 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12735
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012736 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +130012737}
12738
Karl Schultz6addd812016-02-02 17:17:23 -070012739TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchArraySize) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012740 TEST_DESCRIPTION("Test that an error is produced for mismatched array sizes "
Mike Weiblencce7ec72016-10-17 19:33:05 -060012741 "across the vertex->fragment shader interface");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012742 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0.0: 'ptr to "
12743 "output arr[2] of float32' vs 'ptr to "
12744 "input arr[3] of float32'");
Chris Forbes0036fd12016-01-26 14:19:49 +130012745
12746 ASSERT_NO_FATAL_FAILURE(InitState());
12747 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12748
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012749 char const *vsSource = "#version 450\n"
12750 "\n"
12751 "layout(location=0) out float x[2];\n"
12752 "out gl_PerVertex {\n"
12753 " vec4 gl_Position;\n"
12754 "};\n"
12755 "void main(){\n"
12756 " x[0] = 0; x[1] = 0;\n"
12757 " gl_Position = vec4(1);\n"
12758 "}\n";
12759 char const *fsSource = "#version 450\n"
12760 "\n"
12761 "layout(location=0) in float x[3];\n"
12762 "layout(location=0) out vec4 color;\n"
12763 "void main(){\n"
12764 " color = vec4(x[0] + x[1] + x[2]);\n"
12765 "}\n";
Chris Forbes0036fd12016-01-26 14:19:49 +130012766
12767 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12768 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12769
12770 VkPipelineObj pipe(m_device);
12771 pipe.AddColorAttachment();
12772 pipe.AddShader(&vs);
12773 pipe.AddShader(&fs);
12774
12775 VkDescriptorSetObj descriptorSet(m_device);
12776 descriptorSet.AppendDummy();
12777 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12778
12779 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12780
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012781 m_errorMonitor->VerifyFound();
Chris Forbes0036fd12016-01-26 14:19:49 +130012782}
12783
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060012784
Karl Schultz6addd812016-02-02 17:17:23 -070012785TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012786 TEST_DESCRIPTION("Test that an error is produced for mismatched types across "
Mike Weiblencce7ec72016-10-17 19:33:05 -060012787 "the vertex->fragment shader interface");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012788 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012789
Chris Forbesb56af562015-05-25 11:13:17 +120012790 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060012791 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesb56af562015-05-25 11:13:17 +120012792
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012793 char const *vsSource = "#version 450\n"
12794 "\n"
12795 "layout(location=0) out int x;\n"
12796 "out gl_PerVertex {\n"
12797 " vec4 gl_Position;\n"
12798 "};\n"
12799 "void main(){\n"
12800 " x = 0;\n"
12801 " gl_Position = vec4(1);\n"
12802 "}\n";
12803 char const *fsSource = "#version 450\n"
12804 "\n"
12805 "layout(location=0) in float x;\n" /* VS writes int */
12806 "layout(location=0) out vec4 color;\n"
12807 "void main(){\n"
12808 " color = vec4(x);\n"
12809 "}\n";
Chris Forbesb56af562015-05-25 11:13:17 +120012810
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012811 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12812 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesb56af562015-05-25 11:13:17 +120012813
12814 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080012815 pipe.AddColorAttachment();
Chris Forbesb56af562015-05-25 11:13:17 +120012816 pipe.AddShader(&vs);
12817 pipe.AddShader(&fs);
12818
Chris Forbesb56af562015-05-25 11:13:17 +120012819 VkDescriptorSetObj descriptorSet(m_device);
12820 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012821 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesb56af562015-05-25 11:13:17 +120012822
Tony Barbour5781e8f2015-08-04 16:23:11 -060012823 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesb56af562015-05-25 11:13:17 +120012824
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012825 m_errorMonitor->VerifyFound();
Chris Forbesb56af562015-05-25 11:13:17 +120012826}
12827
Karl Schultz6addd812016-02-02 17:17:23 -070012828TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchInBlock) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012829 TEST_DESCRIPTION("Test that an error is produced for mismatched types across "
Mike Weiblencce7ec72016-10-17 19:33:05 -060012830 "the vertex->fragment shader interface, when the variable is contained within "
Chris Forbes1cc79542016-07-20 11:13:44 +120012831 "an interface block");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012832 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0");
Chris Forbesa3e85f62016-01-15 14:53:11 +130012833
12834 ASSERT_NO_FATAL_FAILURE(InitState());
12835 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12836
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012837 char const *vsSource = "#version 450\n"
12838 "\n"
12839 "out block { layout(location=0) int x; } outs;\n"
12840 "out gl_PerVertex {\n"
12841 " vec4 gl_Position;\n"
12842 "};\n"
12843 "void main(){\n"
12844 " outs.x = 0;\n"
12845 " gl_Position = vec4(1);\n"
12846 "}\n";
12847 char const *fsSource = "#version 450\n"
12848 "\n"
12849 "in block { layout(location=0) float x; } ins;\n" /* VS writes int */
12850 "layout(location=0) out vec4 color;\n"
12851 "void main(){\n"
12852 " color = vec4(ins.x);\n"
12853 "}\n";
Chris Forbesa3e85f62016-01-15 14:53:11 +130012854
12855 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12856 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12857
12858 VkPipelineObj pipe(m_device);
12859 pipe.AddColorAttachment();
12860 pipe.AddShader(&vs);
12861 pipe.AddShader(&fs);
12862
12863 VkDescriptorSetObj descriptorSet(m_device);
12864 descriptorSet.AppendDummy();
12865 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12866
12867 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12868
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012869 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +130012870}
12871
12872TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByLocation) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012873 TEST_DESCRIPTION("Test that an error is produced for location mismatches across "
Mike Weiblencce7ec72016-10-17 19:33:05 -060012874 "the vertex->fragment shader interface; This should manifest as a not-written/not-consumed "
Chris Forbes1cc79542016-07-20 11:13:44 +120012875 "pair, but flushes out broken walking of the interfaces");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012876 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 +130012877
12878 ASSERT_NO_FATAL_FAILURE(InitState());
12879 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12880
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012881 char const *vsSource = "#version 450\n"
12882 "\n"
12883 "out block { layout(location=1) float x; } outs;\n"
12884 "out gl_PerVertex {\n"
12885 " vec4 gl_Position;\n"
12886 "};\n"
12887 "void main(){\n"
12888 " outs.x = 0;\n"
12889 " gl_Position = vec4(1);\n"
12890 "}\n";
12891 char const *fsSource = "#version 450\n"
12892 "\n"
12893 "in block { layout(location=0) float x; } ins;\n"
12894 "layout(location=0) out vec4 color;\n"
12895 "void main(){\n"
12896 " color = vec4(ins.x);\n"
12897 "}\n";
Chris Forbese9928822016-02-17 14:44:52 +130012898
12899 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12900 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12901
12902 VkPipelineObj pipe(m_device);
12903 pipe.AddColorAttachment();
12904 pipe.AddShader(&vs);
12905 pipe.AddShader(&fs);
12906
12907 VkDescriptorSetObj descriptorSet(m_device);
12908 descriptorSet.AppendDummy();
12909 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12910
12911 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12912
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012913 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +130012914}
12915
12916TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByComponent) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012917 TEST_DESCRIPTION("Test that an error is produced for component mismatches across the "
Mike Weiblencce7ec72016-10-17 19:33:05 -060012918 "vertex->fragment shader interface. It's not enough to have the same set of locations in "
Chris Forbes1cc79542016-07-20 11:13:44 +120012919 "use; matching is defined in terms of spirv variables.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012920 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 +130012921
12922 ASSERT_NO_FATAL_FAILURE(InitState());
12923 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12924
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012925 char const *vsSource = "#version 450\n"
12926 "\n"
12927 "out block { layout(location=0, component=0) float x; } outs;\n"
12928 "out gl_PerVertex {\n"
12929 " vec4 gl_Position;\n"
12930 "};\n"
12931 "void main(){\n"
12932 " outs.x = 0;\n"
12933 " gl_Position = vec4(1);\n"
12934 "}\n";
12935 char const *fsSource = "#version 450\n"
12936 "\n"
12937 "in block { layout(location=0, component=1) float x; } ins;\n"
12938 "layout(location=0) out vec4 color;\n"
12939 "void main(){\n"
12940 " color = vec4(ins.x);\n"
12941 "}\n";
Chris Forbese9928822016-02-17 14:44:52 +130012942
12943 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12944 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12945
12946 VkPipelineObj pipe(m_device);
12947 pipe.AddColorAttachment();
12948 pipe.AddShader(&vs);
12949 pipe.AddShader(&fs);
12950
12951 VkDescriptorSetObj descriptorSet(m_device);
12952 descriptorSet.AppendDummy();
12953 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12954
12955 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12956
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012957 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +130012958}
12959
Chris Forbes1f3b0152016-11-30 12:48:40 +130012960TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByPrecision) {
12961 TEST_DESCRIPTION("Test that the RelaxedPrecision decoration is validated to match");
12962
12963 ASSERT_NO_FATAL_FAILURE(InitState());
12964 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12965
12966 char const *vsSource = "#version 450\n"
12967 "layout(location=0) out mediump float x;\n"
12968 "void main() { gl_Position = vec4(0); x = 1.0; }\n";
12969 char const *fsSource = "#version 450\n"
12970 "layout(location=0) in highp float x;\n"
12971 "layout(location=0) out vec4 color;\n"
12972 "void main() { color = vec4(x); }\n";
12973
12974 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12975 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12976
12977 VkPipelineObj pipe(m_device);
12978 pipe.AddColorAttachment();
12979 pipe.AddShader(&vs);
12980 pipe.AddShader(&fs);
12981
12982 VkDescriptorSetObj descriptorSet(m_device);
12983 descriptorSet.AppendDummy();
12984 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12985
12986 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "differ in precision");
12987
12988 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12989
12990 m_errorMonitor->VerifyFound();
12991}
12992
Chris Forbes870a39e2016-11-30 12:55:56 +130012993TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByPrecisionBlock) {
12994 TEST_DESCRIPTION("Test that the RelaxedPrecision decoration is validated to match");
12995
12996 ASSERT_NO_FATAL_FAILURE(InitState());
12997 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12998
12999 char const *vsSource = "#version 450\n"
13000 "out block { layout(location=0) mediump float x; };\n"
13001 "void main() { gl_Position = vec4(0); x = 1.0; }\n";
13002 char const *fsSource = "#version 450\n"
13003 "in block { layout(location=0) highp float x; };\n"
13004 "layout(location=0) out vec4 color;\n"
13005 "void main() { color = vec4(x); }\n";
13006
13007 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13008 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13009
13010 VkPipelineObj pipe(m_device);
13011 pipe.AddColorAttachment();
13012 pipe.AddShader(&vs);
13013 pipe.AddShader(&fs);
13014
13015 VkDescriptorSetObj descriptorSet(m_device);
13016 descriptorSet.AppendDummy();
13017 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13018
13019 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "differ in precision");
13020
13021 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13022
13023 m_errorMonitor->VerifyFound();
13024}
13025
Karl Schultz6addd812016-02-02 17:17:23 -070013026TEST_F(VkLayerTest, CreatePipelineAttribNotConsumed) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013027 TEST_DESCRIPTION("Test that a warning is produced for a vertex attribute which is "
13028 "not consumed by the vertex shader");
Mike Weiblencce7ec72016-10-17 19:33:05 -060013029 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "location 0 not consumed by vertex shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013030
Chris Forbesde136e02015-05-25 11:13:28 +120013031 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013032 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesde136e02015-05-25 11:13:28 +120013033
13034 VkVertexInputBindingDescription input_binding;
13035 memset(&input_binding, 0, sizeof(input_binding));
13036
13037 VkVertexInputAttributeDescription input_attrib;
13038 memset(&input_attrib, 0, sizeof(input_attrib));
13039 input_attrib.format = VK_FORMAT_R32_SFLOAT;
13040
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013041 char const *vsSource = "#version 450\n"
13042 "\n"
13043 "out gl_PerVertex {\n"
13044 " vec4 gl_Position;\n"
13045 "};\n"
13046 "void main(){\n"
13047 " gl_Position = vec4(1);\n"
13048 "}\n";
13049 char const *fsSource = "#version 450\n"
13050 "\n"
13051 "layout(location=0) out vec4 color;\n"
13052 "void main(){\n"
13053 " color = vec4(1);\n"
13054 "}\n";
Chris Forbesde136e02015-05-25 11:13:28 +120013055
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013056 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13057 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesde136e02015-05-25 11:13:28 +120013058
13059 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013060 pipe.AddColorAttachment();
Chris Forbesde136e02015-05-25 11:13:28 +120013061 pipe.AddShader(&vs);
13062 pipe.AddShader(&fs);
13063
13064 pipe.AddVertexInputBindings(&input_binding, 1);
13065 pipe.AddVertexInputAttribs(&input_attrib, 1);
13066
Chris Forbesde136e02015-05-25 11:13:28 +120013067 VkDescriptorSetObj descriptorSet(m_device);
13068 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013069 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesde136e02015-05-25 11:13:28 +120013070
Tony Barbour5781e8f2015-08-04 16:23:11 -060013071 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesde136e02015-05-25 11:13:28 +120013072
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013073 m_errorMonitor->VerifyFound();
Chris Forbesde136e02015-05-25 11:13:28 +120013074}
13075
Karl Schultz6addd812016-02-02 17:17:23 -070013076TEST_F(VkLayerTest, CreatePipelineAttribLocationMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013077 TEST_DESCRIPTION("Test that a warning is produced for a location mismatch on "
13078 "vertex attributes. This flushes out bad behavior in the interface walker");
Mike Weiblencce7ec72016-10-17 19:33:05 -060013079 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "location 0 not consumed by vertex shader");
Chris Forbes7d83cd52016-01-15 11:32:03 +130013080
13081 ASSERT_NO_FATAL_FAILURE(InitState());
13082 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13083
13084 VkVertexInputBindingDescription input_binding;
13085 memset(&input_binding, 0, sizeof(input_binding));
13086
13087 VkVertexInputAttributeDescription input_attrib;
13088 memset(&input_attrib, 0, sizeof(input_attrib));
13089 input_attrib.format = VK_FORMAT_R32_SFLOAT;
13090
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013091 char const *vsSource = "#version 450\n"
13092 "\n"
13093 "layout(location=1) in float x;\n"
13094 "out gl_PerVertex {\n"
13095 " vec4 gl_Position;\n"
13096 "};\n"
13097 "void main(){\n"
13098 " gl_Position = vec4(x);\n"
13099 "}\n";
13100 char const *fsSource = "#version 450\n"
13101 "\n"
13102 "layout(location=0) out vec4 color;\n"
13103 "void main(){\n"
13104 " color = vec4(1);\n"
13105 "}\n";
Chris Forbes7d83cd52016-01-15 11:32:03 +130013106
13107 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13108 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13109
13110 VkPipelineObj pipe(m_device);
13111 pipe.AddColorAttachment();
13112 pipe.AddShader(&vs);
13113 pipe.AddShader(&fs);
13114
13115 pipe.AddVertexInputBindings(&input_binding, 1);
13116 pipe.AddVertexInputAttribs(&input_attrib, 1);
13117
13118 VkDescriptorSetObj descriptorSet(m_device);
13119 descriptorSet.AppendDummy();
13120 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13121
13122 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13123
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013124 m_errorMonitor->VerifyFound();
Chris Forbes7d83cd52016-01-15 11:32:03 +130013125}
13126
Karl Schultz6addd812016-02-02 17:17:23 -070013127TEST_F(VkLayerTest, CreatePipelineAttribNotProvided) {
Mike Weiblen15bd38e2016-10-03 19:19:41 -060013128 TEST_DESCRIPTION("Test that an error is produced for a vertex shader input which is not "
Chris Forbes1cc79542016-07-20 11:13:44 +120013129 "provided by a vertex attribute");
Mike Weiblen15bd38e2016-10-03 19:19:41 -060013130 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 -060013131
Chris Forbes62e8e502015-05-25 11:13:29 +120013132 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013133 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes62e8e502015-05-25 11:13:29 +120013134
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013135 char const *vsSource = "#version 450\n"
13136 "\n"
13137 "layout(location=0) in vec4 x;\n" /* not provided */
13138 "out gl_PerVertex {\n"
13139 " vec4 gl_Position;\n"
13140 "};\n"
13141 "void main(){\n"
13142 " gl_Position = x;\n"
13143 "}\n";
13144 char const *fsSource = "#version 450\n"
13145 "\n"
13146 "layout(location=0) out vec4 color;\n"
13147 "void main(){\n"
13148 " color = vec4(1);\n"
13149 "}\n";
Chris Forbes62e8e502015-05-25 11:13:29 +120013150
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013151 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13152 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes62e8e502015-05-25 11:13:29 +120013153
13154 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013155 pipe.AddColorAttachment();
Chris Forbes62e8e502015-05-25 11:13:29 +120013156 pipe.AddShader(&vs);
13157 pipe.AddShader(&fs);
13158
Chris Forbes62e8e502015-05-25 11:13:29 +120013159 VkDescriptorSetObj descriptorSet(m_device);
13160 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013161 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes62e8e502015-05-25 11:13:29 +120013162
Tony Barbour5781e8f2015-08-04 16:23:11 -060013163 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes62e8e502015-05-25 11:13:29 +120013164
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013165 m_errorMonitor->VerifyFound();
Chris Forbes62e8e502015-05-25 11:13:29 +120013166}
13167
Karl Schultz6addd812016-02-02 17:17:23 -070013168TEST_F(VkLayerTest, CreatePipelineAttribTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013169 TEST_DESCRIPTION("Test that an error is produced for a mismatch between the "
13170 "fundamental type (float/int/uint) of an attribute and the "
Mike Weiblen15bd38e2016-10-03 19:19:41 -060013171 "vertex shader input that consumes it");
13172 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 -060013173
Chris Forbesc97d98e2015-05-25 11:13:31 +120013174 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013175 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesc97d98e2015-05-25 11:13:31 +120013176
13177 VkVertexInputBindingDescription input_binding;
13178 memset(&input_binding, 0, sizeof(input_binding));
13179
13180 VkVertexInputAttributeDescription input_attrib;
13181 memset(&input_attrib, 0, sizeof(input_attrib));
13182 input_attrib.format = VK_FORMAT_R32_SFLOAT;
13183
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013184 char const *vsSource = "#version 450\n"
13185 "\n"
13186 "layout(location=0) in int x;\n" /* attrib provided float */
13187 "out gl_PerVertex {\n"
13188 " vec4 gl_Position;\n"
13189 "};\n"
13190 "void main(){\n"
13191 " gl_Position = vec4(x);\n"
13192 "}\n";
13193 char const *fsSource = "#version 450\n"
13194 "\n"
13195 "layout(location=0) out vec4 color;\n"
13196 "void main(){\n"
13197 " color = vec4(1);\n"
13198 "}\n";
Chris Forbesc97d98e2015-05-25 11:13:31 +120013199
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013200 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13201 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesc97d98e2015-05-25 11:13:31 +120013202
13203 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013204 pipe.AddColorAttachment();
Chris Forbesc97d98e2015-05-25 11:13:31 +120013205 pipe.AddShader(&vs);
13206 pipe.AddShader(&fs);
13207
13208 pipe.AddVertexInputBindings(&input_binding, 1);
13209 pipe.AddVertexInputAttribs(&input_attrib, 1);
13210
Chris Forbesc97d98e2015-05-25 11:13:31 +120013211 VkDescriptorSetObj descriptorSet(m_device);
13212 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013213 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesc97d98e2015-05-25 11:13:31 +120013214
Tony Barbour5781e8f2015-08-04 16:23:11 -060013215 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesc97d98e2015-05-25 11:13:31 +120013216
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013217 m_errorMonitor->VerifyFound();
Chris Forbesc97d98e2015-05-25 11:13:31 +120013218}
13219
Chris Forbesc68b43c2016-04-06 11:18:47 +120013220TEST_F(VkLayerTest, CreatePipelineDuplicateStage) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013221 TEST_DESCRIPTION("Test that an error is produced for a pipeline containing multiple "
13222 "shaders for the same stage");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013223 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13224 "Multiple shaders provided for stage VK_SHADER_STAGE_VERTEX_BIT");
Chris Forbesc68b43c2016-04-06 11:18:47 +120013225
13226 ASSERT_NO_FATAL_FAILURE(InitState());
13227 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13228
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013229 char const *vsSource = "#version 450\n"
13230 "\n"
13231 "out gl_PerVertex {\n"
13232 " vec4 gl_Position;\n"
13233 "};\n"
13234 "void main(){\n"
13235 " gl_Position = vec4(1);\n"
13236 "}\n";
13237 char const *fsSource = "#version 450\n"
13238 "\n"
13239 "layout(location=0) out vec4 color;\n"
13240 "void main(){\n"
13241 " color = vec4(1);\n"
13242 "}\n";
Chris Forbesc68b43c2016-04-06 11:18:47 +120013243
13244 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13245 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13246
13247 VkPipelineObj pipe(m_device);
13248 pipe.AddColorAttachment();
13249 pipe.AddShader(&vs);
Mike Weiblencce7ec72016-10-17 19:33:05 -060013250 pipe.AddShader(&vs); // intentionally duplicate vertex shader attachment
Chris Forbesc68b43c2016-04-06 11:18:47 +120013251 pipe.AddShader(&fs);
13252
13253 VkDescriptorSetObj descriptorSet(m_device);
13254 descriptorSet.AppendDummy();
13255 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13256
13257 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13258
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013259 m_errorMonitor->VerifyFound();
Chris Forbesc68b43c2016-04-06 11:18:47 +120013260}
13261
Chris Forbes82ff92a2016-09-09 10:50:24 +120013262TEST_F(VkLayerTest, CreatePipelineMissingEntrypoint) {
13263 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13264 "No entrypoint found named `foo`");
13265
13266 ASSERT_NO_FATAL_FAILURE(InitState());
13267 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13268
13269 char const *vsSource = "#version 450\n"
13270 "out gl_PerVertex {\n"
13271 " vec4 gl_Position;\n"
13272 "};\n"
13273 "void main(){\n"
13274 " gl_Position = vec4(0);\n"
13275 "}\n";
13276 char const *fsSource = "#version 450\n"
13277 "\n"
13278 "layout(location=0) out vec4 color;\n"
13279 "void main(){\n"
13280 " color = vec4(1);\n"
13281 "}\n";
13282
13283 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13284 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this, "foo");
13285
13286 VkPipelineObj pipe(m_device);
13287 pipe.AddColorAttachment();
13288 pipe.AddShader(&vs);
13289 pipe.AddShader(&fs);
13290
13291 VkDescriptorSetObj descriptorSet(m_device);
13292 descriptorSet.AppendDummy();
13293 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13294
13295 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13296
13297 m_errorMonitor->VerifyFound();
13298}
13299
Chris Forbesae9d8cd2016-09-13 16:32:57 +120013300TEST_F(VkLayerTest, CreatePipelineDepthStencilRequired) {
13301 m_errorMonitor->SetDesiredFailureMsg(
13302 VK_DEBUG_REPORT_ERROR_BIT_EXT,
13303 "pDepthStencilState is NULL when rasterization is enabled and subpass "
13304 "uses a depth/stencil attachment");
13305
13306 ASSERT_NO_FATAL_FAILURE(InitState());
13307 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13308
13309 char const *vsSource = "#version 450\n"
13310 "void main(){ gl_Position = vec4(0); }\n";
13311 char const *fsSource = "#version 450\n"
13312 "\n"
13313 "layout(location=0) out vec4 color;\n"
13314 "void main(){\n"
13315 " color = vec4(1);\n"
13316 "}\n";
13317
13318 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13319 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13320
13321 VkPipelineObj pipe(m_device);
13322 pipe.AddColorAttachment();
13323 pipe.AddShader(&vs);
13324 pipe.AddShader(&fs);
13325
13326 VkDescriptorSetObj descriptorSet(m_device);
13327 descriptorSet.AppendDummy();
13328 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13329
13330 VkAttachmentDescription attachments[] = {
13331 { 0, VK_FORMAT_B8G8R8A8_UNORM, VK_SAMPLE_COUNT_1_BIT,
13332 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
13333 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
13334 VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
13335 },
13336 { 0, VK_FORMAT_D16_UNORM, VK_SAMPLE_COUNT_1_BIT,
13337 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
13338 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
13339 VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
13340 },
13341 };
13342 VkAttachmentReference refs[] = {
13343 { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL },
13344 { 1, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL },
13345 };
13346 VkSubpassDescription subpass = {
13347 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr,
13348 1, &refs[0], nullptr, &refs[1],
13349 0, nullptr
13350 };
13351 VkRenderPassCreateInfo rpci = {
13352 VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr,
13353 0, 2, attachments, 1, &subpass, 0, nullptr
13354 };
13355 VkRenderPass rp;
13356 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
13357 ASSERT_VK_SUCCESS(err);
13358
13359 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), rp);
13360
13361 m_errorMonitor->VerifyFound();
13362
13363 vkDestroyRenderPass(m_device->device(), rp, nullptr);
13364}
13365
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013366TEST_F(VkLayerTest, CreatePipelineTessPatchDecorationMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013367 TEST_DESCRIPTION("Test that an error is produced for a variable output from "
13368 "the TCS without the patch decoration, but consumed in the TES "
13369 "with the decoration.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013370 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is per-vertex in tessellation control shader stage "
13371 "but per-patch in tessellation evaluation shader stage");
Chris Forbesa0193bc2016-04-04 19:19:47 +120013372
13373 ASSERT_NO_FATAL_FAILURE(InitState());
13374 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13375
Chris Forbesc1e852d2016-04-04 19:26:42 +120013376 if (!m_device->phy().features().tessellationShader) {
13377 printf("Device does not support tessellation shaders; skipped.\n");
13378 return;
13379 }
13380
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013381 char const *vsSource = "#version 450\n"
13382 "void main(){}\n";
13383 char const *tcsSource = "#version 450\n"
13384 "layout(location=0) out int x[];\n"
13385 "layout(vertices=3) out;\n"
13386 "void main(){\n"
13387 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
13388 " gl_TessLevelInner[0] = 1;\n"
13389 " x[gl_InvocationID] = gl_InvocationID;\n"
13390 "}\n";
13391 char const *tesSource = "#version 450\n"
13392 "layout(triangles, equal_spacing, cw) in;\n"
13393 "layout(location=0) patch in int x;\n"
13394 "out gl_PerVertex { vec4 gl_Position; };\n"
13395 "void main(){\n"
13396 " gl_Position.xyz = gl_TessCoord;\n"
13397 " gl_Position.w = x;\n"
13398 "}\n";
13399 char const *fsSource = "#version 450\n"
13400 "layout(location=0) out vec4 color;\n"
13401 "void main(){\n"
13402 " color = vec4(1);\n"
13403 "}\n";
Chris Forbesa0193bc2016-04-04 19:19:47 +120013404
13405 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13406 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
13407 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
13408 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13409
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013410 VkPipelineInputAssemblyStateCreateInfo iasci{VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, nullptr, 0,
13411 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, VK_FALSE};
Chris Forbesa0193bc2016-04-04 19:19:47 +120013412
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013413 VkPipelineTessellationStateCreateInfo tsci{VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, nullptr, 0, 3};
Chris Forbesa0193bc2016-04-04 19:19:47 +120013414
13415 VkPipelineObj pipe(m_device);
13416 pipe.SetInputAssembly(&iasci);
13417 pipe.SetTessellation(&tsci);
13418 pipe.AddColorAttachment();
13419 pipe.AddShader(&vs);
13420 pipe.AddShader(&tcs);
13421 pipe.AddShader(&tes);
13422 pipe.AddShader(&fs);
13423
13424 VkDescriptorSetObj descriptorSet(m_device);
13425 descriptorSet.AppendDummy();
13426 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13427
13428 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13429
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013430 m_errorMonitor->VerifyFound();
Chris Forbesa0193bc2016-04-04 19:19:47 +120013431}
13432
Karl Schultz6addd812016-02-02 17:17:23 -070013433TEST_F(VkLayerTest, CreatePipelineAttribBindingConflict) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013434 TEST_DESCRIPTION("Test that an error is produced for a vertex attribute setup where multiple "
13435 "bindings provide the same location");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013436 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13437 "Duplicate vertex input binding descriptions for binding 0");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013438
Chris Forbes280ba2c2015-06-12 11:16:41 +120013439 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013440 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes280ba2c2015-06-12 11:16:41 +120013441
13442 /* Two binding descriptions for binding 0 */
13443 VkVertexInputBindingDescription input_bindings[2];
13444 memset(input_bindings, 0, sizeof(input_bindings));
13445
13446 VkVertexInputAttributeDescription input_attrib;
13447 memset(&input_attrib, 0, sizeof(input_attrib));
13448 input_attrib.format = VK_FORMAT_R32_SFLOAT;
13449
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013450 char const *vsSource = "#version 450\n"
13451 "\n"
13452 "layout(location=0) in float x;\n" /* attrib provided float */
13453 "out gl_PerVertex {\n"
13454 " vec4 gl_Position;\n"
13455 "};\n"
13456 "void main(){\n"
13457 " gl_Position = vec4(x);\n"
13458 "}\n";
13459 char const *fsSource = "#version 450\n"
13460 "\n"
13461 "layout(location=0) out vec4 color;\n"
13462 "void main(){\n"
13463 " color = vec4(1);\n"
13464 "}\n";
Chris Forbes280ba2c2015-06-12 11:16:41 +120013465
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013466 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13467 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes280ba2c2015-06-12 11:16:41 +120013468
13469 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013470 pipe.AddColorAttachment();
Chris Forbes280ba2c2015-06-12 11:16:41 +120013471 pipe.AddShader(&vs);
13472 pipe.AddShader(&fs);
13473
13474 pipe.AddVertexInputBindings(input_bindings, 2);
13475 pipe.AddVertexInputAttribs(&input_attrib, 1);
13476
Chris Forbes280ba2c2015-06-12 11:16:41 +120013477 VkDescriptorSetObj descriptorSet(m_device);
13478 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013479 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes280ba2c2015-06-12 11:16:41 +120013480
Tony Barbour5781e8f2015-08-04 16:23:11 -060013481 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes280ba2c2015-06-12 11:16:41 +120013482
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013483 m_errorMonitor->VerifyFound();
Chris Forbes280ba2c2015-06-12 11:16:41 +120013484}
Chris Forbes8f68b562015-05-25 11:13:32 +120013485
Karl Schultz6addd812016-02-02 17:17:23 -070013486TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotWritten) {
Mike Weiblencce7ec72016-10-17 19:33:05 -060013487 TEST_DESCRIPTION("Test that an error is produced for a fragment shader which does not "
Chris Forbes1cc79542016-07-20 11:13:44 +120013488 "provide an output for one of the pipeline's color attachments");
Mike Weiblencce7ec72016-10-17 19:33:05 -060013489 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attachment 0 not written by fragment shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013490
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013491 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013492
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013493 char const *vsSource = "#version 450\n"
13494 "\n"
13495 "out gl_PerVertex {\n"
13496 " vec4 gl_Position;\n"
13497 "};\n"
13498 "void main(){\n"
13499 " gl_Position = vec4(1);\n"
13500 "}\n";
13501 char const *fsSource = "#version 450\n"
13502 "\n"
13503 "void main(){\n"
13504 "}\n";
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013505
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013506 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13507 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013508
13509 VkPipelineObj pipe(m_device);
13510 pipe.AddShader(&vs);
13511 pipe.AddShader(&fs);
13512
Chia-I Wu08accc62015-07-07 11:50:03 +080013513 /* set up CB 0, not written */
13514 pipe.AddColorAttachment();
13515 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013516
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013517 VkDescriptorSetObj descriptorSet(m_device);
13518 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013519 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013520
Tony Barbour5781e8f2015-08-04 16:23:11 -060013521 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013522
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013523 m_errorMonitor->VerifyFound();
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013524}
13525
Karl Schultz6addd812016-02-02 17:17:23 -070013526TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotConsumed) {
Mike Weiblencce7ec72016-10-17 19:33:05 -060013527 TEST_DESCRIPTION("Test that a warning is produced for a fragment shader which provides a spurious "
Chris Forbes1cc79542016-07-20 11:13:44 +120013528 "output with no matching attachment");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013529 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
Mike Weiblencce7ec72016-10-17 19:33:05 -060013530 "fragment shader writes to output location 1 with no matching attachment");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013531
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013532 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013533
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013534 char const *vsSource = "#version 450\n"
13535 "\n"
13536 "out gl_PerVertex {\n"
13537 " vec4 gl_Position;\n"
13538 "};\n"
13539 "void main(){\n"
13540 " gl_Position = vec4(1);\n"
13541 "}\n";
13542 char const *fsSource = "#version 450\n"
13543 "\n"
13544 "layout(location=0) out vec4 x;\n"
13545 "layout(location=1) out vec4 y;\n" /* no matching attachment for this */
13546 "void main(){\n"
13547 " x = vec4(1);\n"
13548 " y = vec4(1);\n"
13549 "}\n";
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013550
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013551 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13552 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013553
13554 VkPipelineObj pipe(m_device);
13555 pipe.AddShader(&vs);
13556 pipe.AddShader(&fs);
13557
Chia-I Wu08accc62015-07-07 11:50:03 +080013558 /* set up CB 0, not written */
13559 pipe.AddColorAttachment();
13560 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013561 /* FS writes CB 1, but we don't configure it */
13562
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013563 VkDescriptorSetObj descriptorSet(m_device);
13564 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013565 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013566
Tony Barbour5781e8f2015-08-04 16:23:11 -060013567 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013568
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013569 m_errorMonitor->VerifyFound();
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013570}
13571
Karl Schultz6addd812016-02-02 17:17:23 -070013572TEST_F(VkLayerTest, CreatePipelineFragmentOutputTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013573 TEST_DESCRIPTION("Test that an error is produced for a mismatch between the fundamental "
Mike Weiblencce7ec72016-10-17 19:33:05 -060013574 "type of an fragment shader output variable, and the format of the corresponding attachment");
13575 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "does not match fragment shader output type");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013576
Chris Forbesa36d69e2015-05-25 11:13:44 +120013577 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesa36d69e2015-05-25 11:13:44 +120013578
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013579 char const *vsSource = "#version 450\n"
13580 "\n"
13581 "out gl_PerVertex {\n"
13582 " vec4 gl_Position;\n"
13583 "};\n"
13584 "void main(){\n"
13585 " gl_Position = vec4(1);\n"
13586 "}\n";
13587 char const *fsSource = "#version 450\n"
13588 "\n"
13589 "layout(location=0) out ivec4 x;\n" /* not UNORM */
13590 "void main(){\n"
13591 " x = ivec4(1);\n"
13592 "}\n";
Chris Forbesa36d69e2015-05-25 11:13:44 +120013593
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013594 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13595 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesa36d69e2015-05-25 11:13:44 +120013596
13597 VkPipelineObj pipe(m_device);
13598 pipe.AddShader(&vs);
13599 pipe.AddShader(&fs);
13600
Chia-I Wu08accc62015-07-07 11:50:03 +080013601 /* set up CB 0; type is UNORM by default */
13602 pipe.AddColorAttachment();
13603 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesa36d69e2015-05-25 11:13:44 +120013604
Chris Forbesa36d69e2015-05-25 11:13:44 +120013605 VkDescriptorSetObj descriptorSet(m_device);
13606 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013607 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesa36d69e2015-05-25 11:13:44 +120013608
Tony Barbour5781e8f2015-08-04 16:23:11 -060013609 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesa36d69e2015-05-25 11:13:44 +120013610
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013611 m_errorMonitor->VerifyFound();
Chris Forbesa36d69e2015-05-25 11:13:44 +120013612}
Chris Forbes7b1b8932015-06-05 14:43:36 +120013613
Karl Schultz6addd812016-02-02 17:17:23 -070013614TEST_F(VkLayerTest, CreatePipelineUniformBlockNotProvided) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013615 TEST_DESCRIPTION("Test that an error is produced for a shader consuming a uniform "
13616 "block which has no corresponding binding in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013617 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not declared in pipeline layout");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013618
Chris Forbes556c76c2015-08-14 12:04:59 +120013619 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes556c76c2015-08-14 12:04:59 +120013620
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013621 char const *vsSource = "#version 450\n"
13622 "\n"
13623 "out gl_PerVertex {\n"
13624 " vec4 gl_Position;\n"
13625 "};\n"
13626 "void main(){\n"
13627 " gl_Position = vec4(1);\n"
13628 "}\n";
13629 char const *fsSource = "#version 450\n"
13630 "\n"
13631 "layout(location=0) out vec4 x;\n"
13632 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
13633 "void main(){\n"
13634 " x = vec4(bar.y);\n"
13635 "}\n";
Chris Forbes556c76c2015-08-14 12:04:59 +120013636
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013637 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13638 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes556c76c2015-08-14 12:04:59 +120013639
Chris Forbes556c76c2015-08-14 12:04:59 +120013640 VkPipelineObj pipe(m_device);
13641 pipe.AddShader(&vs);
13642 pipe.AddShader(&fs);
13643
13644 /* set up CB 0; type is UNORM by default */
13645 pipe.AddColorAttachment();
13646 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13647
13648 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013649 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes556c76c2015-08-14 12:04:59 +120013650
13651 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13652
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013653 m_errorMonitor->VerifyFound();
Chris Forbes556c76c2015-08-14 12:04:59 +120013654}
13655
Chris Forbes5c59e902016-02-26 16:56:09 +130013656TEST_F(VkLayerTest, CreatePipelinePushConstantsNotInLayout) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013657 TEST_DESCRIPTION("Test that an error is produced for a shader consuming push constants "
13658 "which are not provided in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013659 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not declared in layout");
Chris Forbes5c59e902016-02-26 16:56:09 +130013660
13661 ASSERT_NO_FATAL_FAILURE(InitState());
13662
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013663 char const *vsSource = "#version 450\n"
13664 "\n"
13665 "layout(push_constant, std430) uniform foo { float x; } consts;\n"
13666 "out gl_PerVertex {\n"
13667 " vec4 gl_Position;\n"
13668 "};\n"
13669 "void main(){\n"
13670 " gl_Position = vec4(consts.x);\n"
13671 "}\n";
13672 char const *fsSource = "#version 450\n"
13673 "\n"
13674 "layout(location=0) out vec4 x;\n"
13675 "void main(){\n"
13676 " x = vec4(1);\n"
13677 "}\n";
Chris Forbes5c59e902016-02-26 16:56:09 +130013678
13679 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13680 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13681
13682 VkPipelineObj pipe(m_device);
13683 pipe.AddShader(&vs);
13684 pipe.AddShader(&fs);
13685
13686 /* set up CB 0; type is UNORM by default */
13687 pipe.AddColorAttachment();
13688 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13689
13690 VkDescriptorSetObj descriptorSet(m_device);
13691 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13692
13693 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13694
13695 /* should have generated an error -- no push constant ranges provided! */
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013696 m_errorMonitor->VerifyFound();
Chris Forbes5c59e902016-02-26 16:56:09 +130013697}
13698
Chris Forbes3fb17902016-08-22 14:57:55 +120013699TEST_F(VkLayerTest, CreatePipelineInputAttachmentMissing) {
13700 TEST_DESCRIPTION("Test that an error is produced for a shader consuming an input attachment "
13701 "which is not included in the subpass description");
13702 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13703 "consumes input attachment index 0 but not provided in subpass");
13704
13705 ASSERT_NO_FATAL_FAILURE(InitState());
13706
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013707 char const *vsSource = "#version 450\n"
13708 "\n"
13709 "out gl_PerVertex {\n"
13710 " vec4 gl_Position;\n"
13711 "};\n"
13712 "void main(){\n"
13713 " gl_Position = vec4(1);\n"
13714 "}\n";
13715 char const *fsSource = "#version 450\n"
13716 "\n"
13717 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
13718 "layout(location=0) out vec4 color;\n"
13719 "void main() {\n"
13720 " color = subpassLoad(x);\n"
13721 "}\n";
Chris Forbes3fb17902016-08-22 14:57:55 +120013722
13723 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13724 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13725
13726 VkPipelineObj pipe(m_device);
13727 pipe.AddShader(&vs);
13728 pipe.AddShader(&fs);
13729 pipe.AddColorAttachment();
13730 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13731
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013732 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
13733 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes3fb17902016-08-22 14:57:55 +120013734 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013735 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes3fb17902016-08-22 14:57:55 +120013736 ASSERT_VK_SUCCESS(err);
13737
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013738 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes3fb17902016-08-22 14:57:55 +120013739 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013740 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes3fb17902016-08-22 14:57:55 +120013741 ASSERT_VK_SUCCESS(err);
13742
13743 // error here.
13744 pipe.CreateVKPipeline(pl, renderPass());
13745
13746 m_errorMonitor->VerifyFound();
13747
13748 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
13749 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
13750}
13751
Chris Forbes5a9a0472016-08-22 16:02:09 +120013752TEST_F(VkLayerTest, CreatePipelineInputAttachmentTypeMismatch) {
13753 TEST_DESCRIPTION("Test that an error is produced for a shader consuming an input attachment "
13754 "with a format having a different fundamental type");
13755 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13756 "input attachment 0 format of VK_FORMAT_R8G8B8A8_UINT does not match");
13757
13758 ASSERT_NO_FATAL_FAILURE(InitState());
13759
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013760 char const *vsSource = "#version 450\n"
13761 "\n"
13762 "out gl_PerVertex {\n"
13763 " vec4 gl_Position;\n"
13764 "};\n"
13765 "void main(){\n"
13766 " gl_Position = vec4(1);\n"
13767 "}\n";
13768 char const *fsSource = "#version 450\n"
13769 "\n"
13770 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
13771 "layout(location=0) out vec4 color;\n"
13772 "void main() {\n"
13773 " color = subpassLoad(x);\n"
13774 "}\n";
Chris Forbes5a9a0472016-08-22 16:02:09 +120013775
13776 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13777 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13778
13779 VkPipelineObj pipe(m_device);
13780 pipe.AddShader(&vs);
13781 pipe.AddShader(&fs);
13782 pipe.AddColorAttachment();
13783 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13784
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013785 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
13786 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes5a9a0472016-08-22 16:02:09 +120013787 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013788 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes5a9a0472016-08-22 16:02:09 +120013789 ASSERT_VK_SUCCESS(err);
13790
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013791 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120013792 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013793 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes5a9a0472016-08-22 16:02:09 +120013794 ASSERT_VK_SUCCESS(err);
13795
13796 VkAttachmentDescription descs[2] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013797 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
13798 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
13799 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
13800 {0, VK_FORMAT_R8G8B8A8_UINT, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
13801 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 +120013802 };
13803 VkAttachmentReference color = {
13804 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
13805 };
13806 VkAttachmentReference input = {
13807 1, VK_IMAGE_LAYOUT_GENERAL,
13808 };
13809
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013810 VkSubpassDescription sd = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 1, &input, 1, &color, nullptr, nullptr, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120013811
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013812 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, descs, 1, &sd, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120013813 VkRenderPass rp;
13814 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
13815 ASSERT_VK_SUCCESS(err);
13816
13817 // error here.
13818 pipe.CreateVKPipeline(pl, rp);
13819
13820 m_errorMonitor->VerifyFound();
13821
13822 vkDestroyRenderPass(m_device->device(), rp, nullptr);
13823 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
13824 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
13825}
13826
Chris Forbes541f7b02016-08-22 15:30:27 +120013827TEST_F(VkLayerTest, CreatePipelineInputAttachmentMissingArray) {
13828 TEST_DESCRIPTION("Test that an error is produced for a shader consuming an input attachment "
13829 "which is not included in the subpass description -- array case");
13830 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13831 "consumes input attachment index 1 but not provided in subpass");
13832
13833 ASSERT_NO_FATAL_FAILURE(InitState());
13834
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013835 char const *vsSource = "#version 450\n"
13836 "\n"
13837 "out gl_PerVertex {\n"
13838 " vec4 gl_Position;\n"
13839 "};\n"
13840 "void main(){\n"
13841 " gl_Position = vec4(1);\n"
13842 "}\n";
13843 char const *fsSource = "#version 450\n"
13844 "\n"
13845 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput xs[2];\n"
13846 "layout(location=0) out vec4 color;\n"
13847 "void main() {\n"
13848 " color = subpassLoad(xs[1]);\n"
13849 "}\n";
Chris Forbes541f7b02016-08-22 15:30:27 +120013850
13851 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13852 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13853
13854 VkPipelineObj pipe(m_device);
13855 pipe.AddShader(&vs);
13856 pipe.AddShader(&fs);
13857 pipe.AddColorAttachment();
13858 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13859
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013860 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 2, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
13861 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes541f7b02016-08-22 15:30:27 +120013862 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013863 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes541f7b02016-08-22 15:30:27 +120013864 ASSERT_VK_SUCCESS(err);
13865
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013866 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes541f7b02016-08-22 15:30:27 +120013867 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013868 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes541f7b02016-08-22 15:30:27 +120013869 ASSERT_VK_SUCCESS(err);
13870
13871 // error here.
13872 pipe.CreateVKPipeline(pl, renderPass());
13873
13874 m_errorMonitor->VerifyFound();
13875
13876 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
13877 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
13878}
13879
Chris Forbes10eb9ae2016-05-31 16:09:42 +120013880TEST_F(VkLayerTest, CreateComputePipelineMissingDescriptor) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013881 TEST_DESCRIPTION("Test that an error is produced for a compute pipeline consuming a "
13882 "descriptor which is not provided in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013883 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Shader uses descriptor slot 0.0");
Chris Forbes10eb9ae2016-05-31 16:09:42 +120013884
13885 ASSERT_NO_FATAL_FAILURE(InitState());
13886
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013887 char const *csSource = "#version 450\n"
13888 "\n"
13889 "layout(local_size_x=1) in;\n"
13890 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
13891 "void main(){\n"
13892 " x = vec4(1);\n"
13893 "}\n";
Chris Forbes10eb9ae2016-05-31 16:09:42 +120013894
13895 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
13896
13897 VkDescriptorSetObj descriptorSet(m_device);
13898 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13899
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013900 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
13901 nullptr,
13902 0,
13903 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
13904 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
13905 descriptorSet.GetPipelineLayout(),
13906 VK_NULL_HANDLE,
13907 -1};
Chris Forbes10eb9ae2016-05-31 16:09:42 +120013908
13909 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013910 VkResult err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes10eb9ae2016-05-31 16:09:42 +120013911
13912 m_errorMonitor->VerifyFound();
13913
13914 if (err == VK_SUCCESS) {
13915 vkDestroyPipeline(m_device->device(), pipe, nullptr);
13916 }
13917}
13918
Chris Forbes22a9b092016-07-19 14:34:05 +120013919TEST_F(VkLayerTest, CreateComputePipelineDescriptorTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013920 TEST_DESCRIPTION("Test that an error is produced for a pipeline consuming a "
13921 "descriptor-backed resource of a mismatched type");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013922 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13923 "but descriptor of type VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER");
Chris Forbes22a9b092016-07-19 14:34:05 +120013924
13925 ASSERT_NO_FATAL_FAILURE(InitState());
13926
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013927 VkDescriptorSetLayoutBinding binding = {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr};
13928 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &binding};
Chris Forbes22a9b092016-07-19 14:34:05 +120013929 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013930 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes22a9b092016-07-19 14:34:05 +120013931 ASSERT_VK_SUCCESS(err);
13932
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013933 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes22a9b092016-07-19 14:34:05 +120013934 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013935 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes22a9b092016-07-19 14:34:05 +120013936 ASSERT_VK_SUCCESS(err);
13937
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013938 char const *csSource = "#version 450\n"
13939 "\n"
13940 "layout(local_size_x=1) in;\n"
13941 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
13942 "void main() {\n"
13943 " x.x = 1.0f;\n"
13944 "}\n";
Chris Forbes22a9b092016-07-19 14:34:05 +120013945 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
13946
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013947 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
13948 nullptr,
13949 0,
13950 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
13951 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
13952 pl,
13953 VK_NULL_HANDLE,
13954 -1};
Chris Forbes22a9b092016-07-19 14:34:05 +120013955
13956 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013957 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes22a9b092016-07-19 14:34:05 +120013958
13959 m_errorMonitor->VerifyFound();
13960
13961 if (err == VK_SUCCESS) {
13962 vkDestroyPipeline(m_device->device(), pipe, nullptr);
13963 }
13964
13965 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
13966 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
13967}
13968
Chris Forbes50020592016-07-27 13:52:41 +120013969TEST_F(VkLayerTest, DrawTimeImageViewTypeMismatchWithPipeline) {
13970 TEST_DESCRIPTION("Test that an error is produced when an image view type "
13971 "does not match the dimensionality declared in the shader");
13972
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013973 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 +120013974
13975 ASSERT_NO_FATAL_FAILURE(InitState());
13976 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13977
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013978 char const *vsSource = "#version 450\n"
13979 "\n"
13980 "out gl_PerVertex { vec4 gl_Position; };\n"
13981 "void main() { gl_Position = vec4(0); }\n";
13982 char const *fsSource = "#version 450\n"
13983 "\n"
13984 "layout(set=0, binding=0) uniform sampler3D s;\n"
13985 "layout(location=0) out vec4 color;\n"
13986 "void main() {\n"
13987 " color = texture(s, vec3(0));\n"
13988 "}\n";
Chris Forbes50020592016-07-27 13:52:41 +120013989 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13990 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13991
13992 VkPipelineObj pipe(m_device);
13993 pipe.AddShader(&vs);
13994 pipe.AddShader(&fs);
13995 pipe.AddColorAttachment();
13996
13997 VkTextureObj texture(m_device, nullptr);
13998 VkSamplerObj sampler(m_device);
13999
14000 VkDescriptorSetObj descriptorSet(m_device);
14001 descriptorSet.AppendSamplerTexture(&sampler, &texture);
14002 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14003
14004 VkResult err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14005 ASSERT_VK_SUCCESS(err);
14006
14007 BeginCommandBuffer();
14008
14009 m_commandBuffer->BindPipeline(pipe);
14010 m_commandBuffer->BindDescriptorSet(descriptorSet);
14011
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014012 VkViewport viewport = {0, 0, 16, 16, 0, 1};
Chris Forbes50020592016-07-27 13:52:41 +120014013 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014014 VkRect2D scissor = {{0, 0}, {16, 16}};
Chris Forbes50020592016-07-27 13:52:41 +120014015 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
14016
14017 // error produced here.
14018 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
14019
14020 m_errorMonitor->VerifyFound();
14021
14022 EndCommandBuffer();
14023}
14024
Chris Forbes5533bfc2016-07-27 14:12:34 +120014025TEST_F(VkLayerTest, DrawTimeImageMultisampleMismatchWithPipeline) {
14026 TEST_DESCRIPTION("Test that an error is produced when a multisampled images "
14027 "are consumed via singlesample images types in the shader, or vice versa.");
14028
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014029 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "requires bound image to have multiple samples");
Chris Forbes5533bfc2016-07-27 14:12:34 +120014030
14031 ASSERT_NO_FATAL_FAILURE(InitState());
14032 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14033
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014034 char const *vsSource = "#version 450\n"
14035 "\n"
14036 "out gl_PerVertex { vec4 gl_Position; };\n"
14037 "void main() { gl_Position = vec4(0); }\n";
14038 char const *fsSource = "#version 450\n"
14039 "\n"
14040 "layout(set=0, binding=0) uniform sampler2DMS s;\n"
14041 "layout(location=0) out vec4 color;\n"
14042 "void main() {\n"
14043 " color = texelFetch(s, ivec2(0), 0);\n"
14044 "}\n";
Chris Forbes5533bfc2016-07-27 14:12:34 +120014045 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14046 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14047
14048 VkPipelineObj pipe(m_device);
14049 pipe.AddShader(&vs);
14050 pipe.AddShader(&fs);
14051 pipe.AddColorAttachment();
14052
14053 VkTextureObj texture(m_device, nullptr);
14054 VkSamplerObj sampler(m_device);
14055
14056 VkDescriptorSetObj descriptorSet(m_device);
14057 descriptorSet.AppendSamplerTexture(&sampler, &texture);
14058 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14059
14060 VkResult err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14061 ASSERT_VK_SUCCESS(err);
14062
14063 BeginCommandBuffer();
14064
14065 m_commandBuffer->BindPipeline(pipe);
14066 m_commandBuffer->BindDescriptorSet(descriptorSet);
14067
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014068 VkViewport viewport = {0, 0, 16, 16, 0, 1};
Chris Forbes5533bfc2016-07-27 14:12:34 +120014069 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014070 VkRect2D scissor = {{0, 0}, {16, 16}};
Chris Forbes5533bfc2016-07-27 14:12:34 +120014071 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
14072
14073 // error produced here.
14074 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
14075
14076 m_errorMonitor->VerifyFound();
14077
14078 EndCommandBuffer();
14079}
14080
Mark Lobodzinski209b5292015-09-17 09:44:05 -060014081#endif // SHADER_CHECKER_TESTS
14082
14083#if DEVICE_LIMITS_TESTS
Mark Youngc48c4c12016-04-11 14:26:49 -060014084TEST_F(VkLayerTest, CreateImageLimitsViolationMaxWidth) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014085 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "CreateImage extents exceed allowable limits for format");
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060014086
14087 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060014088
14089 // Create an image
14090 VkImage image;
14091
Karl Schultz6addd812016-02-02 17:17:23 -070014092 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
14093 const int32_t tex_width = 32;
14094 const int32_t tex_height = 32;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060014095
14096 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014097 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14098 image_create_info.pNext = NULL;
14099 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14100 image_create_info.format = tex_format;
14101 image_create_info.extent.width = tex_width;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060014102 image_create_info.extent.height = tex_height;
Karl Schultz6addd812016-02-02 17:17:23 -070014103 image_create_info.extent.depth = 1;
14104 image_create_info.mipLevels = 1;
14105 image_create_info.arrayLayers = 1;
14106 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14107 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
14108 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
14109 image_create_info.flags = 0;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060014110
14111 // Introduce error by sending down a bogus width extent
14112 image_create_info.extent.width = 65536;
Chia-I Wuf7458c52015-10-26 21:10:41 +080014113 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060014114
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014115 m_errorMonitor->VerifyFound();
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060014116}
14117
Mark Youngc48c4c12016-04-11 14:26:49 -060014118TEST_F(VkLayerTest, CreateImageLimitsViolationMinWidth) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014119 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14120 "CreateImage extents is 0 for at least one required dimension");
Mark Youngc48c4c12016-04-11 14:26:49 -060014121
14122 ASSERT_NO_FATAL_FAILURE(InitState());
14123
14124 // Create an image
14125 VkImage image;
14126
14127 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
14128 const int32_t tex_width = 32;
14129 const int32_t tex_height = 32;
14130
14131 VkImageCreateInfo image_create_info = {};
14132 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14133 image_create_info.pNext = NULL;
14134 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14135 image_create_info.format = tex_format;
14136 image_create_info.extent.width = tex_width;
14137 image_create_info.extent.height = tex_height;
14138 image_create_info.extent.depth = 1;
14139 image_create_info.mipLevels = 1;
14140 image_create_info.arrayLayers = 1;
14141 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14142 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
14143 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
14144 image_create_info.flags = 0;
14145
14146 // Introduce error by sending down a bogus width extent
14147 image_create_info.extent.width = 0;
14148 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
14149
14150 m_errorMonitor->VerifyFound();
14151}
Mark Lobodzinski209b5292015-09-17 09:44:05 -060014152#endif // DEVICE_LIMITS_TESTS
Chris Forbesa36d69e2015-05-25 11:13:44 +120014153
Tobin Ehliscde08892015-09-22 10:11:37 -060014154#if IMAGE_TESTS
Mark Lobodzinski66e5eab2016-11-15 13:30:38 -070014155
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060014156TEST_F(VkLayerTest, AttachmentDescriptionUndefinedFormat) {
14157 TEST_DESCRIPTION("Create a render pass with an attachment description "
14158 "format set to VK_FORMAT_UNDEFINED");
14159
14160 ASSERT_NO_FATAL_FAILURE(InitState());
14161 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14162
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014163 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "format is VK_FORMAT_UNDEFINED");
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060014164
14165 VkAttachmentReference color_attach = {};
14166 color_attach.layout = VK_IMAGE_LAYOUT_GENERAL;
14167 color_attach.attachment = 0;
14168 VkSubpassDescription subpass = {};
14169 subpass.colorAttachmentCount = 1;
14170 subpass.pColorAttachments = &color_attach;
14171
14172 VkRenderPassCreateInfo rpci = {};
14173 rpci.subpassCount = 1;
14174 rpci.pSubpasses = &subpass;
14175 rpci.attachmentCount = 1;
14176 VkAttachmentDescription attach_desc = {};
14177 attach_desc.format = VK_FORMAT_UNDEFINED;
14178 rpci.pAttachments = &attach_desc;
14179 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
14180 VkRenderPass rp;
14181 VkResult result = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
14182
14183 m_errorMonitor->VerifyFound();
14184
14185 if (result == VK_SUCCESS) {
14186 vkDestroyRenderPass(m_device->device(), rp, NULL);
14187 }
14188}
14189
Karl Schultz6addd812016-02-02 17:17:23 -070014190TEST_F(VkLayerTest, InvalidImageView) {
14191 VkResult err;
Tobin Ehliscde08892015-09-22 10:11:37 -060014192
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014193 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with baseMipLevel 10 ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014194
Tobin Ehliscde08892015-09-22 10:11:37 -060014195 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehliscde08892015-09-22 10:11:37 -060014196
Mike Stroyana3082432015-09-25 13:39:21 -060014197 // Create an image and try to create a view with bad baseMipLevel
Karl Schultz6addd812016-02-02 17:17:23 -070014198 VkImage image;
Tobin Ehliscde08892015-09-22 10:11:37 -060014199
Karl Schultz6addd812016-02-02 17:17:23 -070014200 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
14201 const int32_t tex_width = 32;
14202 const int32_t tex_height = 32;
Tobin Ehliscde08892015-09-22 10:11:37 -060014203
14204 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014205 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14206 image_create_info.pNext = NULL;
14207 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14208 image_create_info.format = tex_format;
14209 image_create_info.extent.width = tex_width;
14210 image_create_info.extent.height = tex_height;
14211 image_create_info.extent.depth = 1;
14212 image_create_info.mipLevels = 1;
14213 image_create_info.arrayLayers = 1;
14214 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14215 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
14216 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
14217 image_create_info.flags = 0;
Tobin Ehliscde08892015-09-22 10:11:37 -060014218
Chia-I Wuf7458c52015-10-26 21:10:41 +080014219 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehliscde08892015-09-22 10:11:37 -060014220 ASSERT_VK_SUCCESS(err);
14221
14222 VkImageViewCreateInfo image_view_create_info = {};
Chris Forbes53bef902016-11-28 17:53:04 +130014223 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070014224 image_view_create_info.image = image;
14225 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
14226 image_view_create_info.format = tex_format;
14227 image_view_create_info.subresourceRange.layerCount = 1;
14228 image_view_create_info.subresourceRange.baseMipLevel = 10; // cause an error
14229 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014230 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehliscde08892015-09-22 10:11:37 -060014231
14232 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014233 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehliscde08892015-09-22 10:11:37 -060014234
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014235 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -060014236 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehliscde08892015-09-22 10:11:37 -060014237}
Mike Stroyana3082432015-09-25 13:39:21 -060014238
Mark Youngd339ba32016-05-30 13:28:35 -060014239TEST_F(VkLayerTest, CreateImageViewNoMemoryBoundToImage) {
14240 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -060014241 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -060014242 " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Mark Youngd339ba32016-05-30 13:28:35 -060014243
14244 ASSERT_NO_FATAL_FAILURE(InitState());
14245
14246 // Create an image and try to create a view with no memory backing the image
14247 VkImage image;
14248
14249 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
14250 const int32_t tex_width = 32;
14251 const int32_t tex_height = 32;
14252
14253 VkImageCreateInfo image_create_info = {};
14254 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14255 image_create_info.pNext = NULL;
14256 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14257 image_create_info.format = tex_format;
14258 image_create_info.extent.width = tex_width;
14259 image_create_info.extent.height = tex_height;
14260 image_create_info.extent.depth = 1;
14261 image_create_info.mipLevels = 1;
14262 image_create_info.arrayLayers = 1;
14263 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14264 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
14265 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
14266 image_create_info.flags = 0;
14267
14268 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
14269 ASSERT_VK_SUCCESS(err);
14270
14271 VkImageViewCreateInfo image_view_create_info = {};
Chris Forbes53bef902016-11-28 17:53:04 +130014272 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Mark Youngd339ba32016-05-30 13:28:35 -060014273 image_view_create_info.image = image;
14274 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
14275 image_view_create_info.format = tex_format;
14276 image_view_create_info.subresourceRange.layerCount = 1;
14277 image_view_create_info.subresourceRange.baseMipLevel = 0;
14278 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014279 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Youngd339ba32016-05-30 13:28:35 -060014280
14281 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014282 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Youngd339ba32016-05-30 13:28:35 -060014283
14284 m_errorMonitor->VerifyFound();
14285 vkDestroyImage(m_device->device(), image, NULL);
14286 // If last error is success, it still created the view, so delete it.
14287 if (err == VK_SUCCESS) {
14288 vkDestroyImageView(m_device->device(), view, NULL);
14289 }
Mark Youngd339ba32016-05-30 13:28:35 -060014290}
14291
Karl Schultz6addd812016-02-02 17:17:23 -070014292TEST_F(VkLayerTest, InvalidImageViewAspect) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014293 TEST_DESCRIPTION("Create an image and try to create a view with an invalid aspectMask");
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060014294 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView(): Color image "
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014295 "formats must have ONLY the "
14296 "VK_IMAGE_ASPECT_COLOR_BIT set");
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060014297 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14298 "Color image formats must have the VK_IMAGE_ASPECT_COLOR_BIT set.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014299
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060014300 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060014301
Karl Schultz6addd812016-02-02 17:17:23 -070014302 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060014303 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014304 image.init(32, 32, tex_format, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_LINEAR, 0);
Tobin Ehlis1f567a22016-05-25 16:15:18 -060014305 ASSERT_TRUE(image.initialized());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060014306
14307 VkImageViewCreateInfo image_view_create_info = {};
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060014308 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060014309 image_view_create_info.image = image.handle();
Karl Schultz6addd812016-02-02 17:17:23 -070014310 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
14311 image_view_create_info.format = tex_format;
14312 image_view_create_info.subresourceRange.baseMipLevel = 0;
14313 image_view_create_info.subresourceRange.levelCount = 1;
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060014314 image_view_create_info.subresourceRange.layerCount = 1;
Karl Schultz6addd812016-02-02 17:17:23 -070014315 // Cause an error by setting an invalid image aspect
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014316 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060014317
14318 VkImageView view;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060014319 vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060014320
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014321 m_errorMonitor->VerifyFound();
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060014322}
14323
Mark Lobodzinskidb117632016-03-31 10:45:56 -060014324TEST_F(VkLayerTest, CopyImageLayerCountMismatch) {
Karl Schultz6addd812016-02-02 17:17:23 -070014325 VkResult err;
14326 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060014327
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014328 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14329 "vkCmdCopyImage: number of layers in source and destination subresources for pRegions");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014330
Mike Stroyana3082432015-09-25 13:39:21 -060014331 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060014332
14333 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070014334 VkImage srcImage;
14335 VkImage dstImage;
14336 VkDeviceMemory srcMem;
14337 VkDeviceMemory destMem;
14338 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060014339
14340 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014341 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14342 image_create_info.pNext = NULL;
14343 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14344 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
14345 image_create_info.extent.width = 32;
14346 image_create_info.extent.height = 32;
14347 image_create_info.extent.depth = 1;
14348 image_create_info.mipLevels = 1;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060014349 image_create_info.arrayLayers = 4;
Karl Schultz6addd812016-02-02 17:17:23 -070014350 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14351 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
14352 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
14353 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014354
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014355 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014356 ASSERT_VK_SUCCESS(err);
14357
Mark Lobodzinski867787a2016-10-14 11:49:55 -060014358 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014359 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014360 ASSERT_VK_SUCCESS(err);
14361
14362 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014363 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014364 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
14365 memAlloc.pNext = NULL;
14366 memAlloc.allocationSize = 0;
14367 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014368
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060014369 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014370 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014371 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014372 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014373 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014374 ASSERT_VK_SUCCESS(err);
14375
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014376 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014377 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014378 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060014379 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014380 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014381 ASSERT_VK_SUCCESS(err);
14382
14383 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
14384 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014385 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060014386 ASSERT_VK_SUCCESS(err);
14387
14388 BeginCommandBuffer();
14389 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014390 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014391 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060014392 copyRegion.srcSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060014393 copyRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060014394 copyRegion.srcOffset.x = 0;
14395 copyRegion.srcOffset.y = 0;
14396 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014397 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014398 copyRegion.dstSubresource.mipLevel = 0;
14399 copyRegion.dstSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060014400 // Introduce failure by forcing the dst layerCount to differ from src
14401 copyRegion.dstSubresource.layerCount = 3;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014402 copyRegion.dstOffset.x = 0;
14403 copyRegion.dstOffset.y = 0;
14404 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014405 copyRegion.extent.width = 1;
14406 copyRegion.extent.height = 1;
14407 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014408 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060014409 EndCommandBuffer();
14410
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014411 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060014412
Chia-I Wuf7458c52015-10-26 21:10:41 +080014413 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014414 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080014415 vkFreeMemory(m_device->device(), srcMem, NULL);
14416 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060014417}
14418
Tony Barbourd6673642016-05-05 14:46:39 -060014419TEST_F(VkLayerTest, ImageLayerUnsupportedFormat) {
14420
14421 TEST_DESCRIPTION("Creating images with unsuported formats ");
14422
14423 ASSERT_NO_FATAL_FAILURE(InitState());
14424 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14425 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014426 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 -060014427 VK_IMAGE_TILING_OPTIMAL, 0);
14428 ASSERT_TRUE(image.initialized());
14429
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014430 // Create image with unsupported format - Expect FORMAT_UNSUPPORTED
Chris Forbesf4d8e332016-11-28 17:51:10 +130014431 VkImageCreateInfo image_create_info = {};
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014432 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014433 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14434 image_create_info.format = VK_FORMAT_UNDEFINED;
14435 image_create_info.extent.width = 32;
14436 image_create_info.extent.height = 32;
14437 image_create_info.extent.depth = 1;
14438 image_create_info.mipLevels = 1;
14439 image_create_info.arrayLayers = 1;
14440 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14441 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
14442 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014443
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014444 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14445 "vkCreateImage: VkFormat for image must not be VK_FORMAT_UNDEFINED");
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014446
14447 VkImage localImage;
14448 vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage);
14449 m_errorMonitor->VerifyFound();
14450
Tony Barbourd6673642016-05-05 14:46:39 -060014451 VkFormat unsupported = VK_FORMAT_UNDEFINED;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014452 // Look for a format that is COMPLETELY unsupported with this hardware
Tony Barbourd6673642016-05-05 14:46:39 -060014453 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
14454 VkFormat format = static_cast<VkFormat>(f);
14455 VkFormatProperties fProps = m_device->format_properties(format);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014456 if (format != VK_FORMAT_UNDEFINED && fProps.linearTilingFeatures == 0 && fProps.optimalTilingFeatures == 0) {
Tony Barbourd6673642016-05-05 14:46:39 -060014457 unsupported = format;
14458 break;
14459 }
14460 }
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014461
Tony Barbourd6673642016-05-05 14:46:39 -060014462 if (unsupported != VK_FORMAT_UNDEFINED) {
Tony Barbourd6673642016-05-05 14:46:39 -060014463 image_create_info.format = unsupported;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014464 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is an unsupported format");
Tony Barbourd6673642016-05-05 14:46:39 -060014465
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014466 vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage);
Tony Barbourd6673642016-05-05 14:46:39 -060014467 m_errorMonitor->VerifyFound();
14468 }
14469}
14470
14471TEST_F(VkLayerTest, ImageLayerViewTests) {
14472 VkResult ret;
14473 TEST_DESCRIPTION("Passing bad parameters to CreateImageView");
14474
14475 ASSERT_NO_FATAL_FAILURE(InitState());
14476
14477 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014478 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 -060014479 VK_IMAGE_TILING_OPTIMAL, 0);
14480 ASSERT_TRUE(image.initialized());
14481
14482 VkImageView imgView;
14483 VkImageViewCreateInfo imgViewInfo = {};
14484 imgViewInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
14485 imgViewInfo.image = image.handle();
14486 imgViewInfo.viewType = VK_IMAGE_VIEW_TYPE_2D;
14487 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
14488 imgViewInfo.subresourceRange.layerCount = 1;
14489 imgViewInfo.subresourceRange.baseMipLevel = 0;
14490 imgViewInfo.subresourceRange.levelCount = 1;
14491 imgViewInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14492
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014493 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with baseMipLevel");
Tony Barbourd6673642016-05-05 14:46:39 -060014494 // View can't have baseMipLevel >= image's mipLevels - Expect
14495 // VIEW_CREATE_ERROR
14496 imgViewInfo.subresourceRange.baseMipLevel = 1;
14497 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14498 m_errorMonitor->VerifyFound();
14499 imgViewInfo.subresourceRange.baseMipLevel = 0;
14500
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014501 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with baseArrayLayer");
Tony Barbourd6673642016-05-05 14:46:39 -060014502 // View can't have baseArrayLayer >= image's arraySize - Expect
14503 // VIEW_CREATE_ERROR
14504 imgViewInfo.subresourceRange.baseArrayLayer = 1;
14505 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14506 m_errorMonitor->VerifyFound();
14507 imgViewInfo.subresourceRange.baseArrayLayer = 0;
14508
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014509 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with 0 in "
14510 "pCreateInfo->subresourceRange."
14511 "levelCount");
Tony Barbourd6673642016-05-05 14:46:39 -060014512 // View's levelCount can't be 0 - Expect VIEW_CREATE_ERROR
14513 imgViewInfo.subresourceRange.levelCount = 0;
14514 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14515 m_errorMonitor->VerifyFound();
14516 imgViewInfo.subresourceRange.levelCount = 1;
14517
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014518 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with 0 in "
14519 "pCreateInfo->subresourceRange."
14520 "layerCount");
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060014521 m_errorMonitor->SetDesiredFailureMsg(
14522 VK_DEBUG_REPORT_ERROR_BIT_EXT,
14523 "if pCreateInfo->viewType is VK_IMAGE_TYPE_2D, pCreateInfo->subresourceRange.layerCount must be 1");
Tony Barbourd6673642016-05-05 14:46:39 -060014524 // View's layerCount can't be 0 - Expect VIEW_CREATE_ERROR
14525 imgViewInfo.subresourceRange.layerCount = 0;
14526 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14527 m_errorMonitor->VerifyFound();
14528 imgViewInfo.subresourceRange.layerCount = 1;
14529
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014530 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "but both must be color formats");
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060014531 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Formats MUST be IDENTICAL unless "
14532 "VK_IMAGE_CREATE_MUTABLE_FORMAT BIT "
14533 "was set on image creation.");
Tony Barbourd6673642016-05-05 14:46:39 -060014534 // Can't use depth format for view into color image - Expect INVALID_FORMAT
14535 imgViewInfo.format = VK_FORMAT_D24_UNORM_S8_UINT;
14536 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14537 m_errorMonitor->VerifyFound();
14538 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
14539
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014540 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Formats MUST be IDENTICAL unless "
14541 "VK_IMAGE_CREATE_MUTABLE_FORMAT BIT "
14542 "was set on image creation.");
Tony Barbourd6673642016-05-05 14:46:39 -060014543 // Same compatibility class but no MUTABLE_FORMAT bit - Expect
14544 // VIEW_CREATE_ERROR
14545 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UINT;
14546 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14547 m_errorMonitor->VerifyFound();
14548 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
14549
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014550 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "can support ImageViews with "
14551 "differing formats but they must be "
14552 "in the same compatibility class.");
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060014553 // TODO: Update framework to easily passing mutable flag into ImageObj init
14554 // For now just allowing image for this one test to not have memory bound
14555 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14556 " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Tony Barbourd6673642016-05-05 14:46:39 -060014557 // Have MUTABLE_FORMAT bit but not in same compatibility class - Expect
14558 // VIEW_CREATE_ERROR
14559 VkImageCreateInfo mutImgInfo = image.create_info();
14560 VkImage mutImage;
14561 mutImgInfo.format = VK_FORMAT_R8_UINT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014562 assert(m_device->format_properties(VK_FORMAT_R8_UINT).optimalTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT);
Tony Barbourd6673642016-05-05 14:46:39 -060014563 mutImgInfo.flags = VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT;
14564 mutImgInfo.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
14565 ret = vkCreateImage(m_device->handle(), &mutImgInfo, NULL, &mutImage);
14566 ASSERT_VK_SUCCESS(ret);
14567 imgViewInfo.image = mutImage;
14568 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14569 m_errorMonitor->VerifyFound();
14570 imgViewInfo.image = image.handle();
14571 vkDestroyImage(m_device->handle(), mutImage, NULL);
14572}
14573
14574TEST_F(VkLayerTest, MiscImageLayerTests) {
14575
14576 TEST_DESCRIPTION("Image layer tests that don't belong elsewhare");
14577
14578 ASSERT_NO_FATAL_FAILURE(InitState());
14579
14580 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014581 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 -060014582 VK_IMAGE_TILING_OPTIMAL, 0);
14583 ASSERT_TRUE(image.initialized());
14584
Tony Barbourd6673642016-05-05 14:46:39 -060014585 vk_testing::Buffer buffer;
14586 VkMemoryPropertyFlags reqs = 0;
14587 buffer.init_as_src(*m_device, 128 * 128 * 4, reqs);
14588 VkBufferImageCopy region = {};
14589 region.bufferRowLength = 128;
14590 region.bufferImageHeight = 128;
14591 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14592 // layerCount can't be 0 - Expect MISMATCHED_IMAGE_ASPECT
Mark Lobodzinski3702e932016-11-22 11:40:48 -070014593 region.imageSubresource.layerCount = 1;
Tony Barbourd6673642016-05-05 14:46:39 -060014594 region.imageExtent.height = 4;
14595 region.imageExtent.width = 4;
14596 region.imageExtent.depth = 1;
14597 m_commandBuffer->BeginCommandBuffer();
Tony Barbourd6673642016-05-05 14:46:39 -060014598
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070014599 // Image must have offset.z of 0 and extent.depth of 1
14600 // Introduce failure by setting imageExtent.depth to 0
14601 region.imageExtent.depth = 0;
14602 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01269);
14603 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
14604 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
14605 m_errorMonitor->VerifyFound();
14606
14607 region.imageExtent.depth = 1;
14608
14609 // Image must have offset.z of 0 and extent.depth of 1
14610 // Introduce failure by setting imageOffset.z to 4
14611 region.imageOffset.z = 4;
14612 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01269);
14613 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
14614 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
14615 m_errorMonitor->VerifyFound();
14616
14617 region.imageOffset.z = 0;
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060014618 // BufferOffset must be a multiple of the calling command's VkImage parameter's texel size
14619 // Introduce failure by setting bufferOffset to 1 and 1/2 texels
14620 region.bufferOffset = 6;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070014621 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01263);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014622 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
14623 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060014624 m_errorMonitor->VerifyFound();
14625
14626 // BufferOffset must be a multiple of 4
14627 // Introduce failure by setting bufferOffset to a value not divisible by 4
14628 region.bufferOffset = 6;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070014629 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01264);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014630 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
14631 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060014632 m_errorMonitor->VerifyFound();
14633
14634 // BufferRowLength must be 0, or greater than or equal to the width member of imageExtent
14635 region.bufferOffset = 0;
14636 region.imageExtent.height = 128;
14637 region.imageExtent.width = 128;
14638 // Introduce failure by setting bufferRowLength > 0 but less than width
14639 region.bufferRowLength = 64;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070014640 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01265);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014641 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
14642 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060014643 m_errorMonitor->VerifyFound();
14644
14645 // BufferImageHeight must be 0, or greater than or equal to the height member of imageExtent
14646 region.bufferRowLength = 128;
14647 // Introduce failure by setting bufferRowHeight > 0 but less than height
14648 region.bufferImageHeight = 64;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070014649 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01266);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014650 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
14651 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060014652 m_errorMonitor->VerifyFound();
14653
14654 region.bufferImageHeight = 128;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014655 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14656 "If the format of srcImage is a depth, stencil, depth stencil or "
14657 "integer-based format then filter must be VK_FILTER_NEAREST");
Tony Barbourd6673642016-05-05 14:46:39 -060014658 // Expect INVALID_FILTER
14659 VkImageObj intImage1(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014660 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 -060014661 VkImageObj intImage2(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014662 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 -060014663 VkImageBlit blitRegion = {};
14664 blitRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14665 blitRegion.srcSubresource.baseArrayLayer = 0;
14666 blitRegion.srcSubresource.layerCount = 1;
14667 blitRegion.srcSubresource.mipLevel = 0;
14668 blitRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14669 blitRegion.dstSubresource.baseArrayLayer = 0;
14670 blitRegion.dstSubresource.layerCount = 1;
14671 blitRegion.dstSubresource.mipLevel = 0;
14672
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014673 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), intImage1.handle(), intImage1.layout(), intImage2.handle(),
14674 intImage2.layout(), 16, &blitRegion, VK_FILTER_LINEAR);
Tony Barbourd6673642016-05-05 14:46:39 -060014675 m_errorMonitor->VerifyFound();
14676
Mark Lobodzinskib02ea642016-08-17 13:03:57 -060014677 // Look for NULL-blit warning
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014678 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "Offsets specify a zero-volume area.");
14679 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), intImage1.handle(), intImage1.layout(), intImage2.handle(),
14680 intImage2.layout(), 1, &blitRegion, VK_FILTER_LINEAR);
Mark Lobodzinskib02ea642016-08-17 13:03:57 -060014681 m_errorMonitor->VerifyFound();
14682
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014683 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with 0 in ppMemoryBarriers");
Tony Barbourd6673642016-05-05 14:46:39 -060014684 VkImageMemoryBarrier img_barrier;
14685 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
14686 img_barrier.pNext = NULL;
14687 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
14688 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
14689 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
14690 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
14691 img_barrier.image = image.handle();
14692 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
14693 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
14694 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14695 img_barrier.subresourceRange.baseArrayLayer = 0;
14696 img_barrier.subresourceRange.baseMipLevel = 0;
14697 // layerCount should not be 0 - Expect INVALID_IMAGE_RESOURCE
14698 img_barrier.subresourceRange.layerCount = 0;
14699 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014700 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
14701 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbourd6673642016-05-05 14:46:39 -060014702 m_errorMonitor->VerifyFound();
14703 img_barrier.subresourceRange.layerCount = 1;
14704}
14705
14706TEST_F(VkLayerTest, ImageFormatLimits) {
14707
14708 TEST_DESCRIPTION("Exceed the limits of image format ");
14709
Cody Northropc31a84f2016-08-22 10:41:47 -060014710 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014711 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "CreateImage extents exceed allowable limits for format");
Tony Barbourd6673642016-05-05 14:46:39 -060014712 VkImageCreateInfo image_create_info = {};
14713 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14714 image_create_info.pNext = NULL;
14715 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14716 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
14717 image_create_info.extent.width = 32;
14718 image_create_info.extent.height = 32;
14719 image_create_info.extent.depth = 1;
14720 image_create_info.mipLevels = 1;
14721 image_create_info.arrayLayers = 1;
14722 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14723 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
14724 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
14725 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
14726 image_create_info.flags = 0;
14727
14728 VkImage nullImg;
14729 VkImageFormatProperties imgFmtProps;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014730 vkGetPhysicalDeviceImageFormatProperties(gpu(), image_create_info.format, image_create_info.imageType, image_create_info.tiling,
14731 image_create_info.usage, image_create_info.flags, &imgFmtProps);
Tony Barbourd6673642016-05-05 14:46:39 -060014732 image_create_info.extent.depth = imgFmtProps.maxExtent.depth + 1;
14733 // Expect INVALID_FORMAT_LIMITS_VIOLATION
14734 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
14735 m_errorMonitor->VerifyFound();
14736 image_create_info.extent.depth = 1;
14737
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014738 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "exceeds allowable maximum supported by format of");
Tony Barbourd6673642016-05-05 14:46:39 -060014739 image_create_info.mipLevels = imgFmtProps.maxMipLevels + 1;
14740 // Expect INVALID_FORMAT_LIMITS_VIOLATION
14741 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
14742 m_errorMonitor->VerifyFound();
14743 image_create_info.mipLevels = 1;
14744
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014745 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "exceeds allowable maximum supported by format of");
Tony Barbourd6673642016-05-05 14:46:39 -060014746 image_create_info.arrayLayers = imgFmtProps.maxArrayLayers + 1;
14747 // Expect INVALID_FORMAT_LIMITS_VIOLATION
14748 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
14749 m_errorMonitor->VerifyFound();
14750 image_create_info.arrayLayers = 1;
14751
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014752 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is not supported by format");
Tony Barbourd6673642016-05-05 14:46:39 -060014753 int samples = imgFmtProps.sampleCounts >> 1;
14754 image_create_info.samples = (VkSampleCountFlagBits)samples;
14755 // Expect INVALID_FORMAT_LIMITS_VIOLATION
14756 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
14757 m_errorMonitor->VerifyFound();
14758 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14759
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014760 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "pCreateInfo->initialLayout, must be "
14761 "VK_IMAGE_LAYOUT_UNDEFINED or "
14762 "VK_IMAGE_LAYOUT_PREINITIALIZED");
Tony Barbourd6673642016-05-05 14:46:39 -060014763 image_create_info.initialLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
14764 // Expect INVALID_LAYOUT
14765 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
14766 m_errorMonitor->VerifyFound();
14767 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
14768}
14769
Mark Lobodzinskicea14992016-10-14 10:59:42 -060014770TEST_F(VkLayerTest, CopyImageSrcSizeExceeded) {
14771
14772 // Image copy with source region specified greater than src image size
Mark Lobodzinski629d47b2016-10-18 13:34:58 -060014773 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01175);
Mark Lobodzinskicea14992016-10-14 10:59:42 -060014774
14775 ASSERT_NO_FATAL_FAILURE(InitState());
14776
14777 VkImageObj src_image(m_device);
14778 src_image.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_LINEAR, 0);
14779 VkImageObj dst_image(m_device);
14780 dst_image.init(64, 64, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
14781
14782 BeginCommandBuffer();
14783 VkImageCopy copy_region;
14784 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14785 copy_region.srcSubresource.mipLevel = 0;
14786 copy_region.srcSubresource.baseArrayLayer = 0;
14787 copy_region.srcSubresource.layerCount = 0;
14788 copy_region.srcOffset.x = 0;
14789 copy_region.srcOffset.y = 0;
14790 copy_region.srcOffset.z = 0;
14791 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14792 copy_region.dstSubresource.mipLevel = 0;
14793 copy_region.dstSubresource.baseArrayLayer = 0;
14794 copy_region.dstSubresource.layerCount = 0;
14795 copy_region.dstOffset.x = 0;
14796 copy_region.dstOffset.y = 0;
14797 copy_region.dstOffset.z = 0;
14798 copy_region.extent.width = 64;
14799 copy_region.extent.height = 64;
14800 copy_region.extent.depth = 1;
14801 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
14802 &copy_region);
14803 EndCommandBuffer();
14804
14805 m_errorMonitor->VerifyFound();
14806}
14807
14808TEST_F(VkLayerTest, CopyImageDstSizeExceeded) {
14809
14810 // Image copy with dest region specified greater than dest image size
Mark Lobodzinski629d47b2016-10-18 13:34:58 -060014811 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01176);
Mark Lobodzinskicea14992016-10-14 10:59:42 -060014812
14813 ASSERT_NO_FATAL_FAILURE(InitState());
14814
14815 VkImageObj src_image(m_device);
14816 src_image.init(64, 64, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_LINEAR, 0);
14817 VkImageObj dst_image(m_device);
14818 dst_image.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
14819
14820 BeginCommandBuffer();
14821 VkImageCopy copy_region;
14822 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14823 copy_region.srcSubresource.mipLevel = 0;
14824 copy_region.srcSubresource.baseArrayLayer = 0;
14825 copy_region.srcSubresource.layerCount = 0;
14826 copy_region.srcOffset.x = 0;
14827 copy_region.srcOffset.y = 0;
14828 copy_region.srcOffset.z = 0;
14829 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14830 copy_region.dstSubresource.mipLevel = 0;
14831 copy_region.dstSubresource.baseArrayLayer = 0;
14832 copy_region.dstSubresource.layerCount = 0;
14833 copy_region.dstOffset.x = 0;
14834 copy_region.dstOffset.y = 0;
14835 copy_region.dstOffset.z = 0;
14836 copy_region.extent.width = 64;
14837 copy_region.extent.height = 64;
14838 copy_region.extent.depth = 1;
14839 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
14840 &copy_region);
14841 EndCommandBuffer();
14842
14843 m_errorMonitor->VerifyFound();
14844}
14845
Karl Schultz6addd812016-02-02 17:17:23 -070014846TEST_F(VkLayerTest, CopyImageFormatSizeMismatch) {
Karl Schultzbdb75952016-04-19 11:36:49 -060014847 VkResult err;
14848 bool pass;
14849
14850 // Create color images with different format sizes and try to copy between them
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014851 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14852 "vkCmdCopyImage called with unmatched source and dest image format sizes");
Karl Schultzbdb75952016-04-19 11:36:49 -060014853
14854 ASSERT_NO_FATAL_FAILURE(InitState());
14855
14856 // Create two images of different types and try to copy between them
14857 VkImage srcImage;
14858 VkImage dstImage;
14859 VkDeviceMemory srcMem;
14860 VkDeviceMemory destMem;
14861 VkMemoryRequirements memReqs;
14862
14863 VkImageCreateInfo image_create_info = {};
14864 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14865 image_create_info.pNext = NULL;
14866 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14867 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
14868 image_create_info.extent.width = 32;
14869 image_create_info.extent.height = 32;
14870 image_create_info.extent.depth = 1;
14871 image_create_info.mipLevels = 1;
14872 image_create_info.arrayLayers = 1;
14873 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14874 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
14875 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
14876 image_create_info.flags = 0;
14877
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014878 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Karl Schultzbdb75952016-04-19 11:36:49 -060014879 ASSERT_VK_SUCCESS(err);
14880
14881 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
14882 // Introduce failure by creating second image with a different-sized format.
14883 image_create_info.format = VK_FORMAT_R5G5B5A1_UNORM_PACK16;
14884
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014885 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Karl Schultzbdb75952016-04-19 11:36:49 -060014886 ASSERT_VK_SUCCESS(err);
14887
14888 // Allocate memory
14889 VkMemoryAllocateInfo memAlloc = {};
14890 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
14891 memAlloc.pNext = NULL;
14892 memAlloc.allocationSize = 0;
14893 memAlloc.memoryTypeIndex = 0;
14894
14895 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
14896 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014897 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -060014898 ASSERT_TRUE(pass);
14899 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
14900 ASSERT_VK_SUCCESS(err);
14901
14902 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
14903 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014904 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -060014905 ASSERT_TRUE(pass);
14906 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
14907 ASSERT_VK_SUCCESS(err);
14908
14909 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
14910 ASSERT_VK_SUCCESS(err);
14911 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
14912 ASSERT_VK_SUCCESS(err);
14913
14914 BeginCommandBuffer();
14915 VkImageCopy copyRegion;
14916 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14917 copyRegion.srcSubresource.mipLevel = 0;
14918 copyRegion.srcSubresource.baseArrayLayer = 0;
14919 copyRegion.srcSubresource.layerCount = 0;
14920 copyRegion.srcOffset.x = 0;
14921 copyRegion.srcOffset.y = 0;
14922 copyRegion.srcOffset.z = 0;
14923 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14924 copyRegion.dstSubresource.mipLevel = 0;
14925 copyRegion.dstSubresource.baseArrayLayer = 0;
14926 copyRegion.dstSubresource.layerCount = 0;
14927 copyRegion.dstOffset.x = 0;
14928 copyRegion.dstOffset.y = 0;
14929 copyRegion.dstOffset.z = 0;
14930 copyRegion.extent.width = 1;
14931 copyRegion.extent.height = 1;
14932 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014933 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Karl Schultzbdb75952016-04-19 11:36:49 -060014934 EndCommandBuffer();
14935
14936 m_errorMonitor->VerifyFound();
14937
14938 vkDestroyImage(m_device->device(), srcImage, NULL);
14939 vkDestroyImage(m_device->device(), dstImage, NULL);
14940 vkFreeMemory(m_device->device(), srcMem, NULL);
14941 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060014942}
14943
Karl Schultz6addd812016-02-02 17:17:23 -070014944TEST_F(VkLayerTest, CopyImageDepthStencilFormatMismatch) {
14945 VkResult err;
14946 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060014947
Mark Lobodzinskidb117632016-03-31 10:45:56 -060014948 // Create a color image and a depth/stencil image and try to copy between them
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014949 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14950 "vkCmdCopyImage called with unmatched source and dest image depth");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014951
Mike Stroyana3082432015-09-25 13:39:21 -060014952 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060014953
14954 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070014955 VkImage srcImage;
14956 VkImage dstImage;
14957 VkDeviceMemory srcMem;
14958 VkDeviceMemory destMem;
14959 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060014960
14961 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014962 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14963 image_create_info.pNext = NULL;
14964 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14965 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
14966 image_create_info.extent.width = 32;
14967 image_create_info.extent.height = 32;
14968 image_create_info.extent.depth = 1;
14969 image_create_info.mipLevels = 1;
14970 image_create_info.arrayLayers = 1;
14971 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14972 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
14973 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
14974 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014975
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014976 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014977 ASSERT_VK_SUCCESS(err);
14978
Karl Schultzbdb75952016-04-19 11:36:49 -060014979 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
14980
Mark Lobodzinskidb117632016-03-31 10:45:56 -060014981 // Introduce failure by creating second image with a depth/stencil format
Karl Schultz6addd812016-02-02 17:17:23 -070014982 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060014983 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
Mark Lobodzinski867787a2016-10-14 11:49:55 -060014984 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014985
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014986 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014987 ASSERT_VK_SUCCESS(err);
14988
14989 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014990 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014991 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
14992 memAlloc.pNext = NULL;
14993 memAlloc.allocationSize = 0;
14994 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014995
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060014996 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014997 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014998 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014999 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015000 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015001 ASSERT_VK_SUCCESS(err);
15002
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015003 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015004 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015005 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015006 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015007 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015008 ASSERT_VK_SUCCESS(err);
15009
15010 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
15011 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015012 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060015013 ASSERT_VK_SUCCESS(err);
15014
15015 BeginCommandBuffer();
15016 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015017 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015018 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060015019 copyRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015020 copyRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015021 copyRegion.srcOffset.x = 0;
15022 copyRegion.srcOffset.y = 0;
15023 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015024 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015025 copyRegion.dstSubresource.mipLevel = 0;
15026 copyRegion.dstSubresource.baseArrayLayer = 0;
15027 copyRegion.dstSubresource.layerCount = 0;
15028 copyRegion.dstOffset.x = 0;
15029 copyRegion.dstOffset.y = 0;
15030 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015031 copyRegion.extent.width = 1;
15032 copyRegion.extent.height = 1;
15033 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015034 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060015035 EndCommandBuffer();
15036
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015037 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060015038
Chia-I Wuf7458c52015-10-26 21:10:41 +080015039 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015040 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080015041 vkFreeMemory(m_device->device(), srcMem, NULL);
15042 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060015043}
15044
Karl Schultz6addd812016-02-02 17:17:23 -070015045TEST_F(VkLayerTest, ResolveImageLowSampleCount) {
15046 VkResult err;
15047 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060015048
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015049 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15050 "vkCmdResolveImage called with source sample count less than 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015051
Mike Stroyana3082432015-09-25 13:39:21 -060015052 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060015053
15054 // Create two images of sample count 1 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070015055 VkImage srcImage;
15056 VkImage dstImage;
15057 VkDeviceMemory srcMem;
15058 VkDeviceMemory destMem;
15059 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060015060
15061 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015062 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15063 image_create_info.pNext = NULL;
15064 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15065 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
15066 image_create_info.extent.width = 32;
15067 image_create_info.extent.height = 1;
15068 image_create_info.extent.depth = 1;
15069 image_create_info.mipLevels = 1;
15070 image_create_info.arrayLayers = 1;
15071 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15072 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15073 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
15074 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015075
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015076 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015077 ASSERT_VK_SUCCESS(err);
15078
Karl Schultz6addd812016-02-02 17:17:23 -070015079 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015080
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015081 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015082 ASSERT_VK_SUCCESS(err);
15083
15084 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015085 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015086 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15087 memAlloc.pNext = NULL;
15088 memAlloc.allocationSize = 0;
15089 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015090
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060015091 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015092 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015093 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015094 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015095 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015096 ASSERT_VK_SUCCESS(err);
15097
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015098 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015099 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015100 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015101 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015102 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015103 ASSERT_VK_SUCCESS(err);
15104
15105 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
15106 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015107 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060015108 ASSERT_VK_SUCCESS(err);
15109
15110 BeginCommandBuffer();
15111 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070015112 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
15113 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060015114 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015115 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015116 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060015117 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130015118 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060015119 resolveRegion.srcOffset.x = 0;
15120 resolveRegion.srcOffset.y = 0;
15121 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015122 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015123 resolveRegion.dstSubresource.mipLevel = 0;
15124 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130015125 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015126 resolveRegion.dstOffset.x = 0;
15127 resolveRegion.dstOffset.y = 0;
15128 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015129 resolveRegion.extent.width = 1;
15130 resolveRegion.extent.height = 1;
15131 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015132 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060015133 EndCommandBuffer();
15134
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015135 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060015136
Chia-I Wuf7458c52015-10-26 21:10:41 +080015137 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015138 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080015139 vkFreeMemory(m_device->device(), srcMem, NULL);
15140 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060015141}
15142
Karl Schultz6addd812016-02-02 17:17:23 -070015143TEST_F(VkLayerTest, ResolveImageHighSampleCount) {
15144 VkResult err;
15145 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060015146
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015147 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15148 "vkCmdResolveImage called with dest sample count greater than 1.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015149
Mike Stroyana3082432015-09-25 13:39:21 -060015150 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060015151
Chris Forbesa7530692016-05-08 12:35:39 +120015152 // Create two images of sample count 4 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070015153 VkImage srcImage;
15154 VkImage dstImage;
15155 VkDeviceMemory srcMem;
15156 VkDeviceMemory destMem;
15157 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060015158
15159 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015160 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15161 image_create_info.pNext = NULL;
15162 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15163 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
15164 image_create_info.extent.width = 32;
15165 image_create_info.extent.height = 1;
15166 image_create_info.extent.depth = 1;
15167 image_create_info.mipLevels = 1;
15168 image_create_info.arrayLayers = 1;
Chris Forbesa7530692016-05-08 12:35:39 +120015169 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070015170 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15171 // Note: Some implementations expect color attachment usage for any
15172 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015173 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070015174 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015175
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015176 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015177 ASSERT_VK_SUCCESS(err);
15178
Karl Schultz6addd812016-02-02 17:17:23 -070015179 // Note: Some implementations expect color attachment usage for any
15180 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015181 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015182
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015183 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015184 ASSERT_VK_SUCCESS(err);
15185
15186 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015187 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015188 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15189 memAlloc.pNext = NULL;
15190 memAlloc.allocationSize = 0;
15191 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015192
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060015193 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015194 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015195 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015196 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015197 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015198 ASSERT_VK_SUCCESS(err);
15199
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015200 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015201 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015202 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015203 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015204 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015205 ASSERT_VK_SUCCESS(err);
15206
15207 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
15208 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015209 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060015210 ASSERT_VK_SUCCESS(err);
15211
15212 BeginCommandBuffer();
15213 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070015214 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
15215 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060015216 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015217 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015218 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060015219 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130015220 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060015221 resolveRegion.srcOffset.x = 0;
15222 resolveRegion.srcOffset.y = 0;
15223 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015224 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015225 resolveRegion.dstSubresource.mipLevel = 0;
15226 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130015227 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015228 resolveRegion.dstOffset.x = 0;
15229 resolveRegion.dstOffset.y = 0;
15230 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015231 resolveRegion.extent.width = 1;
15232 resolveRegion.extent.height = 1;
15233 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015234 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060015235 EndCommandBuffer();
15236
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015237 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060015238
Chia-I Wuf7458c52015-10-26 21:10:41 +080015239 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015240 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080015241 vkFreeMemory(m_device->device(), srcMem, NULL);
15242 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060015243}
15244
Karl Schultz6addd812016-02-02 17:17:23 -070015245TEST_F(VkLayerTest, ResolveImageFormatMismatch) {
15246 VkResult err;
15247 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060015248
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015249 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15250 "vkCmdResolveImage called with unmatched source and dest formats.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015251
Mike Stroyana3082432015-09-25 13:39:21 -060015252 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060015253
15254 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070015255 VkImage srcImage;
15256 VkImage dstImage;
15257 VkDeviceMemory srcMem;
15258 VkDeviceMemory destMem;
15259 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060015260
15261 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015262 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15263 image_create_info.pNext = NULL;
15264 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15265 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
15266 image_create_info.extent.width = 32;
15267 image_create_info.extent.height = 1;
15268 image_create_info.extent.depth = 1;
15269 image_create_info.mipLevels = 1;
15270 image_create_info.arrayLayers = 1;
15271 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
15272 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15273 // Note: Some implementations expect color attachment usage for any
15274 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015275 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070015276 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015277
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015278 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015279 ASSERT_VK_SUCCESS(err);
15280
Karl Schultz6addd812016-02-02 17:17:23 -070015281 // Set format to something other than source image
15282 image_create_info.format = VK_FORMAT_R32_SFLOAT;
15283 // Note: Some implementations expect color attachment usage for any
15284 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015285 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070015286 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015287
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015288 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015289 ASSERT_VK_SUCCESS(err);
15290
15291 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015292 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015293 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15294 memAlloc.pNext = NULL;
15295 memAlloc.allocationSize = 0;
15296 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015297
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060015298 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015299 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015300 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015301 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015302 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015303 ASSERT_VK_SUCCESS(err);
15304
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015305 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015306 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015307 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015308 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015309 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015310 ASSERT_VK_SUCCESS(err);
15311
15312 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
15313 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015314 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060015315 ASSERT_VK_SUCCESS(err);
15316
15317 BeginCommandBuffer();
15318 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070015319 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
15320 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060015321 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015322 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015323 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060015324 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130015325 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060015326 resolveRegion.srcOffset.x = 0;
15327 resolveRegion.srcOffset.y = 0;
15328 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015329 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015330 resolveRegion.dstSubresource.mipLevel = 0;
15331 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130015332 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015333 resolveRegion.dstOffset.x = 0;
15334 resolveRegion.dstOffset.y = 0;
15335 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015336 resolveRegion.extent.width = 1;
15337 resolveRegion.extent.height = 1;
15338 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015339 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060015340 EndCommandBuffer();
15341
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015342 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060015343
Chia-I Wuf7458c52015-10-26 21:10:41 +080015344 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015345 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080015346 vkFreeMemory(m_device->device(), srcMem, NULL);
15347 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060015348}
15349
Karl Schultz6addd812016-02-02 17:17:23 -070015350TEST_F(VkLayerTest, ResolveImageTypeMismatch) {
15351 VkResult err;
15352 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060015353
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015354 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15355 "vkCmdResolveImage called with unmatched source and dest image types.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015356
Mike Stroyana3082432015-09-25 13:39:21 -060015357 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060015358
15359 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070015360 VkImage srcImage;
15361 VkImage dstImage;
15362 VkDeviceMemory srcMem;
15363 VkDeviceMemory destMem;
15364 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060015365
15366 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015367 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15368 image_create_info.pNext = NULL;
15369 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15370 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
15371 image_create_info.extent.width = 32;
15372 image_create_info.extent.height = 1;
15373 image_create_info.extent.depth = 1;
15374 image_create_info.mipLevels = 1;
15375 image_create_info.arrayLayers = 1;
15376 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
15377 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15378 // Note: Some implementations expect color attachment usage for any
15379 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015380 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070015381 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015382
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015383 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015384 ASSERT_VK_SUCCESS(err);
15385
Karl Schultz6addd812016-02-02 17:17:23 -070015386 image_create_info.imageType = VK_IMAGE_TYPE_1D;
15387 // Note: Some implementations expect color attachment usage for any
15388 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015389 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070015390 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015391
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015392 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015393 ASSERT_VK_SUCCESS(err);
15394
15395 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015396 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015397 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15398 memAlloc.pNext = NULL;
15399 memAlloc.allocationSize = 0;
15400 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015401
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060015402 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015403 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015404 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015405 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015406 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015407 ASSERT_VK_SUCCESS(err);
15408
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015409 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015410 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015411 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015412 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015413 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015414 ASSERT_VK_SUCCESS(err);
15415
15416 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
15417 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015418 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060015419 ASSERT_VK_SUCCESS(err);
15420
15421 BeginCommandBuffer();
15422 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070015423 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
15424 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060015425 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015426 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015427 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060015428 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130015429 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060015430 resolveRegion.srcOffset.x = 0;
15431 resolveRegion.srcOffset.y = 0;
15432 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015433 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015434 resolveRegion.dstSubresource.mipLevel = 0;
15435 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130015436 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015437 resolveRegion.dstOffset.x = 0;
15438 resolveRegion.dstOffset.y = 0;
15439 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015440 resolveRegion.extent.width = 1;
15441 resolveRegion.extent.height = 1;
15442 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015443 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060015444 EndCommandBuffer();
15445
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015446 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060015447
Chia-I Wuf7458c52015-10-26 21:10:41 +080015448 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015449 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080015450 vkFreeMemory(m_device->device(), srcMem, NULL);
15451 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060015452}
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015453
Karl Schultz6addd812016-02-02 17:17:23 -070015454TEST_F(VkLayerTest, DepthStencilImageViewWithColorAspectBitError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015455 // Create a single Image descriptor and cause it to first hit an error due
Karl Schultz6addd812016-02-02 17:17:23 -070015456 // to using a DS format, then cause it to hit error due to COLOR_BIT not
15457 // set in aspect
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015458 // The image format check comes 2nd in validation so we trigger it first,
15459 // then when we cause aspect fail next, bad format check will be preempted
Karl Schultz6addd812016-02-02 17:17:23 -070015460 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015461
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015462 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15463 "Combination depth/stencil image formats can have only the ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015464
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015465 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015466
Chia-I Wu1b99bb22015-10-27 19:25:11 +080015467 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015468 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
15469 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015470
15471 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015472 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
15473 ds_pool_ci.pNext = NULL;
15474 ds_pool_ci.maxSets = 1;
15475 ds_pool_ci.poolSizeCount = 1;
15476 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015477
15478 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015479 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015480 ASSERT_VK_SUCCESS(err);
15481
15482 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015483 dsl_binding.binding = 0;
15484 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
15485 dsl_binding.descriptorCount = 1;
15486 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
15487 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015488
15489 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015490 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
15491 ds_layout_ci.pNext = NULL;
15492 ds_layout_ci.bindingCount = 1;
15493 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015494 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015495 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015496 ASSERT_VK_SUCCESS(err);
15497
15498 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015499 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080015500 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070015501 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015502 alloc_info.descriptorPool = ds_pool;
15503 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015504 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015505 ASSERT_VK_SUCCESS(err);
15506
Karl Schultz6addd812016-02-02 17:17:23 -070015507 VkImage image_bad;
15508 VkImage image_good;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015509 // One bad format and one good format for Color attachment
Tobin Ehlis269f0322016-05-25 16:24:21 -060015510 const VkFormat tex_format_bad = VK_FORMAT_D24_UNORM_S8_UINT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015511 const VkFormat tex_format_good = VK_FORMAT_B8G8R8A8_UNORM;
Karl Schultz6addd812016-02-02 17:17:23 -070015512 const int32_t tex_width = 32;
15513 const int32_t tex_height = 32;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015514
15515 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015516 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15517 image_create_info.pNext = NULL;
15518 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15519 image_create_info.format = tex_format_bad;
15520 image_create_info.extent.width = tex_width;
15521 image_create_info.extent.height = tex_height;
15522 image_create_info.extent.depth = 1;
15523 image_create_info.mipLevels = 1;
15524 image_create_info.arrayLayers = 1;
15525 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15526 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015527 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070015528 image_create_info.flags = 0;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015529
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015530 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_bad);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015531 ASSERT_VK_SUCCESS(err);
15532 image_create_info.format = tex_format_good;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015533 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
15534 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_good);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015535 ASSERT_VK_SUCCESS(err);
15536
15537 VkImageViewCreateInfo image_view_create_info = {};
Chris Forbes53bef902016-11-28 17:53:04 +130015538 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070015539 image_view_create_info.image = image_bad;
15540 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
15541 image_view_create_info.format = tex_format_bad;
15542 image_view_create_info.subresourceRange.baseArrayLayer = 0;
15543 image_view_create_info.subresourceRange.baseMipLevel = 0;
15544 image_view_create_info.subresourceRange.layerCount = 1;
15545 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015546 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015547
15548 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015549 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015550
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015551 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015552
Chia-I Wuf7458c52015-10-26 21:10:41 +080015553 vkDestroyImage(m_device->device(), image_bad, NULL);
15554 vkDestroyImage(m_device->device(), image_good, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080015555 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
15556 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015557}
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015558
15559TEST_F(VkLayerTest, ClearImageErrors) {
15560 TEST_DESCRIPTION("Call ClearColorImage w/ a depth|stencil image and "
15561 "ClearDepthStencilImage with a color image.");
15562
15563 ASSERT_NO_FATAL_FAILURE(InitState());
15564 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15565
15566 // Renderpass is started here so end it as Clear cmds can't be in renderpass
15567 BeginCommandBuffer();
15568 m_commandBuffer->EndRenderPass();
15569
15570 // Color image
15571 VkClearColorValue clear_color;
15572 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
15573 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
15574 const VkFormat color_format = VK_FORMAT_B8G8R8A8_UNORM;
15575 const int32_t img_width = 32;
15576 const int32_t img_height = 32;
15577 VkImageCreateInfo image_create_info = {};
15578 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15579 image_create_info.pNext = NULL;
15580 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15581 image_create_info.format = color_format;
15582 image_create_info.extent.width = img_width;
15583 image_create_info.extent.height = img_height;
15584 image_create_info.extent.depth = 1;
15585 image_create_info.mipLevels = 1;
15586 image_create_info.arrayLayers = 1;
15587 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15588 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15589 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
15590
15591 vk_testing::Image color_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015592 color_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015593
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015594 const VkImageSubresourceRange color_range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015595
15596 // Depth/Stencil image
15597 VkClearDepthStencilValue clear_value = {0};
15598 reqs = 0; // don't need HOST_VISIBLE DS image
15599 VkImageCreateInfo ds_image_create_info = vk_testing::Image::create_info();
15600 ds_image_create_info.imageType = VK_IMAGE_TYPE_2D;
15601 ds_image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
15602 ds_image_create_info.extent.width = 64;
15603 ds_image_create_info.extent.height = 64;
15604 ds_image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15605 ds_image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
15606
15607 vk_testing::Image ds_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015608 ds_image.init(*m_device, (const VkImageCreateInfo &)ds_image_create_info, reqs);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015609
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015610 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 -060015611
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015612 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdClearColorImage called with depth/stencil image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015613
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015614 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), ds_image.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015615 &color_range);
15616
15617 m_errorMonitor->VerifyFound();
15618
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015619 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdClearColorImage called with "
15620 "image created without "
15621 "VK_IMAGE_USAGE_TRANSFER_DST_BIT");
Tony Barbour26434b92016-06-02 09:43:50 -060015622
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015623 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), ds_image.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
Tony Barbour26434b92016-06-02 09:43:50 -060015624 &color_range);
15625
15626 m_errorMonitor->VerifyFound();
15627
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015628 // Call CmdClearDepthStencilImage with color image
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015629 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15630 "vkCmdClearDepthStencilImage called without a depth/stencil image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015631
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015632 vkCmdClearDepthStencilImage(m_commandBuffer->GetBufferHandle(), color_image.handle(),
15633 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, &clear_value, 1, &ds_range);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015634
15635 m_errorMonitor->VerifyFound();
15636}
Tobin Ehliscde08892015-09-22 10:11:37 -060015637#endif // IMAGE_TESTS
15638
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060015639
15640// WSI Enabled Tests
15641//
Chris Forbes09368e42016-10-13 11:59:22 +130015642#if 0
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060015643TEST_F(VkWsiEnabledLayerTest, TestEnabledWsi) {
15644
15645#if defined(VK_USE_PLATFORM_XCB_KHR)
15646 VkSurfaceKHR surface = VK_NULL_HANDLE;
15647
15648 VkResult err;
15649 bool pass;
15650 VkSwapchainKHR swapchain = VK_NULL_HANDLE;
15651 VkSwapchainCreateInfoKHR swapchain_create_info = {};
15652 // uint32_t swapchain_image_count = 0;
15653 // VkImage swapchain_images[1] = {VK_NULL_HANDLE};
15654 // uint32_t image_index = 0;
15655 // VkPresentInfoKHR present_info = {};
15656
15657 ASSERT_NO_FATAL_FAILURE(InitState());
15658
15659 // Use the create function from one of the VK_KHR_*_surface extension in
15660 // order to create a surface, testing all known errors in the process,
15661 // before successfully creating a surface:
15662 // First, try to create a surface without a VkXcbSurfaceCreateInfoKHR:
15663 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pCreateInfo specified as NULL");
15664 err = vkCreateXcbSurfaceKHR(instance(), NULL, NULL, &surface);
15665 pass = (err != VK_SUCCESS);
15666 ASSERT_TRUE(pass);
15667 m_errorMonitor->VerifyFound();
15668
15669 // Next, try to create a surface with the wrong
15670 // VkXcbSurfaceCreateInfoKHR::sType:
15671 VkXcbSurfaceCreateInfoKHR xcb_create_info = {};
15672 xcb_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
15673 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pCreateInfo->sType must be");
15674 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
15675 pass = (err != VK_SUCCESS);
15676 ASSERT_TRUE(pass);
15677 m_errorMonitor->VerifyFound();
15678
15679 // Create a native window, and then correctly create a surface:
15680 xcb_connection_t *connection;
15681 xcb_screen_t *screen;
15682 xcb_window_t xcb_window;
15683 xcb_intern_atom_reply_t *atom_wm_delete_window;
15684
15685 const xcb_setup_t *setup;
15686 xcb_screen_iterator_t iter;
15687 int scr;
15688 uint32_t value_mask, value_list[32];
15689 int width = 1;
15690 int height = 1;
15691
15692 connection = xcb_connect(NULL, &scr);
15693 ASSERT_TRUE(connection != NULL);
15694 setup = xcb_get_setup(connection);
15695 iter = xcb_setup_roots_iterator(setup);
15696 while (scr-- > 0)
15697 xcb_screen_next(&iter);
15698 screen = iter.data;
15699
15700 xcb_window = xcb_generate_id(connection);
15701
15702 value_mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK;
15703 value_list[0] = screen->black_pixel;
15704 value_list[1] = XCB_EVENT_MASK_KEY_RELEASE | XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_STRUCTURE_NOTIFY;
15705
15706 xcb_create_window(connection, XCB_COPY_FROM_PARENT, xcb_window, screen->root, 0, 0, width, height, 0,
15707 XCB_WINDOW_CLASS_INPUT_OUTPUT, screen->root_visual, value_mask, value_list);
15708
15709 /* Magic code that will send notification when window is destroyed */
15710 xcb_intern_atom_cookie_t cookie = xcb_intern_atom(connection, 1, 12, "WM_PROTOCOLS");
15711 xcb_intern_atom_reply_t *reply = xcb_intern_atom_reply(connection, cookie, 0);
15712
15713 xcb_intern_atom_cookie_t cookie2 = xcb_intern_atom(connection, 0, 16, "WM_DELETE_WINDOW");
15714 atom_wm_delete_window = xcb_intern_atom_reply(connection, cookie2, 0);
15715 xcb_change_property(connection, XCB_PROP_MODE_REPLACE, xcb_window, (*reply).atom, 4, 32, 1, &(*atom_wm_delete_window).atom);
15716 free(reply);
15717
15718 xcb_map_window(connection, xcb_window);
15719
15720 // Force the x/y coordinates to 100,100 results are identical in consecutive
15721 // runs
15722 const uint32_t coords[] = { 100, 100 };
15723 xcb_configure_window(connection, xcb_window, XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y, coords);
15724
15725 // Finally, try to correctly create a surface:
15726 xcb_create_info.sType = VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR;
15727 xcb_create_info.pNext = NULL;
15728 xcb_create_info.flags = 0;
15729 xcb_create_info.connection = connection;
15730 xcb_create_info.window = xcb_window;
15731 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
15732 pass = (err == VK_SUCCESS);
15733 ASSERT_TRUE(pass);
15734
15735 // Check if surface supports presentation:
15736
15737 // 1st, do so without having queried the queue families:
15738 VkBool32 supported = false;
15739 // TODO: Get the following error to come out:
15740 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15741 "called before calling the vkGetPhysicalDeviceQueueFamilyProperties "
15742 "function");
15743 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
15744 pass = (err != VK_SUCCESS);
15745 // ASSERT_TRUE(pass);
15746 // m_errorMonitor->VerifyFound();
15747
15748 // Next, query a queue family index that's too large:
15749 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with a queueFamilyIndex that is too large");
15750 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 100000, surface, &supported);
15751 pass = (err != VK_SUCCESS);
15752 ASSERT_TRUE(pass);
15753 m_errorMonitor->VerifyFound();
15754
15755 // Finally, do so correctly:
15756 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
15757 // SUPPORTED
15758 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
15759 pass = (err == VK_SUCCESS);
15760 ASSERT_TRUE(pass);
15761
15762 // Before proceeding, try to create a swapchain without having called
15763 // vkGetPhysicalDeviceSurfaceCapabilitiesKHR():
15764 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
15765 swapchain_create_info.pNext = NULL;
15766 swapchain_create_info.flags = 0;
15767 swapchain_create_info.imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
15768 swapchain_create_info.surface = surface;
15769 swapchain_create_info.imageArrayLayers = 1;
15770 swapchain_create_info.preTransform = VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR;
15771 swapchain_create_info.compositeAlpha = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR;
15772 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15773 "called before calling vkGetPhysicalDeviceSurfaceCapabilitiesKHR().");
15774 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
15775 pass = (err != VK_SUCCESS);
15776 ASSERT_TRUE(pass);
15777 m_errorMonitor->VerifyFound();
15778
15779 // Get the surface capabilities:
15780 VkSurfaceCapabilitiesKHR surface_capabilities;
15781
15782 // Do so correctly (only error logged by this entrypoint is if the
15783 // extension isn't enabled):
15784 err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), surface, &surface_capabilities);
15785 pass = (err == VK_SUCCESS);
15786 ASSERT_TRUE(pass);
15787
15788 // Get the surface formats:
15789 uint32_t surface_format_count;
15790
15791 // First, try without a pointer to surface_format_count:
15792 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pSurfaceFormatCount "
15793 "specified as NULL");
15794 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, NULL, NULL);
15795 pass = (err == VK_SUCCESS);
15796 ASSERT_TRUE(pass);
15797 m_errorMonitor->VerifyFound();
15798
15799 // Next, call with a non-NULL pSurfaceFormats, even though we haven't
15800 // correctly done a 1st try (to get the count):
15801 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "but no prior positive value has been seen for");
15802 surface_format_count = 0;
15803 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, (VkSurfaceFormatKHR *)&surface_format_count);
15804 pass = (err == VK_SUCCESS);
15805 ASSERT_TRUE(pass);
15806 m_errorMonitor->VerifyFound();
15807
15808 // Next, correctly do a 1st try (with a NULL pointer to surface_formats):
15809 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, NULL);
15810 pass = (err == VK_SUCCESS);
15811 ASSERT_TRUE(pass);
15812
15813 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
15814 VkSurfaceFormatKHR *surface_formats = (VkSurfaceFormatKHR *)malloc(surface_format_count * sizeof(VkSurfaceFormatKHR));
15815
15816 // Next, do a 2nd try with surface_format_count being set too high:
15817 surface_format_count += 5;
15818 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is greater than the value");
15819 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, surface_formats);
15820 pass = (err == VK_SUCCESS);
15821 ASSERT_TRUE(pass);
15822 m_errorMonitor->VerifyFound();
15823
15824 // Finally, do a correct 1st and 2nd try:
15825 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, NULL);
15826 pass = (err == VK_SUCCESS);
15827 ASSERT_TRUE(pass);
15828 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, surface_formats);
15829 pass = (err == VK_SUCCESS);
15830 ASSERT_TRUE(pass);
15831
15832 // Get the surface present modes:
15833 uint32_t surface_present_mode_count;
15834
15835 // First, try without a pointer to surface_format_count:
15836 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pPresentModeCount "
15837 "specified as NULL");
15838
15839 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, NULL, NULL);
15840 pass = (err == VK_SUCCESS);
15841 ASSERT_TRUE(pass);
15842 m_errorMonitor->VerifyFound();
15843
15844 // Next, call with a non-NULL VkPresentModeKHR, even though we haven't
15845 // correctly done a 1st try (to get the count):
15846 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "but no prior positive value has been seen for");
15847 surface_present_mode_count = 0;
15848 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count,
15849 (VkPresentModeKHR *)&surface_present_mode_count);
15850 pass = (err == VK_SUCCESS);
15851 ASSERT_TRUE(pass);
15852 m_errorMonitor->VerifyFound();
15853
15854 // Next, correctly do a 1st try (with a NULL pointer to surface_formats):
15855 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, NULL);
15856 pass = (err == VK_SUCCESS);
15857 ASSERT_TRUE(pass);
15858
15859 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
15860 VkPresentModeKHR *surface_present_modes = (VkPresentModeKHR *)malloc(surface_present_mode_count * sizeof(VkPresentModeKHR));
15861
15862 // Next, do a 2nd try with surface_format_count being set too high:
15863 surface_present_mode_count += 5;
15864 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is greater than the value");
15865 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, surface_present_modes);
15866 pass = (err == VK_SUCCESS);
15867 ASSERT_TRUE(pass);
15868 m_errorMonitor->VerifyFound();
15869
15870 // Finally, do a correct 1st and 2nd try:
15871 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, NULL);
15872 pass = (err == VK_SUCCESS);
15873 ASSERT_TRUE(pass);
15874 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, surface_present_modes);
15875 pass = (err == VK_SUCCESS);
15876 ASSERT_TRUE(pass);
15877
15878 // Create a swapchain:
15879
15880 // First, try without a pointer to swapchain_create_info:
15881 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pCreateInfo "
15882 "specified as NULL");
15883
15884 err = vkCreateSwapchainKHR(m_device->device(), NULL, NULL, &swapchain);
15885 pass = (err != VK_SUCCESS);
15886 ASSERT_TRUE(pass);
15887 m_errorMonitor->VerifyFound();
15888
15889 // Next, call with a non-NULL swapchain_create_info, that has the wrong
15890 // sType:
15891 swapchain_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
15892 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pCreateInfo->sType must be");
15893
15894 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
15895 pass = (err != VK_SUCCESS);
15896 ASSERT_TRUE(pass);
15897 m_errorMonitor->VerifyFound();
15898
15899 // Next, call with a NULL swapchain pointer:
15900 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
15901 swapchain_create_info.pNext = NULL;
15902 swapchain_create_info.flags = 0;
15903 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pSwapchain "
15904 "specified as NULL");
15905
15906 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, NULL);
15907 pass = (err != VK_SUCCESS);
15908 ASSERT_TRUE(pass);
15909 m_errorMonitor->VerifyFound();
15910
15911 // TODO: Enhance swapchain layer so that
15912 // swapchain_create_info.queueFamilyIndexCount is checked against something?
15913
15914 // Next, call with a queue family index that's too large:
15915 uint32_t queueFamilyIndex[2] = { 100000, 0 };
15916 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
15917 swapchain_create_info.queueFamilyIndexCount = 2;
15918 swapchain_create_info.pQueueFamilyIndices = queueFamilyIndex;
15919 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with a queueFamilyIndex that is too large");
15920 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
15921 pass = (err != VK_SUCCESS);
15922 ASSERT_TRUE(pass);
15923 m_errorMonitor->VerifyFound();
15924
15925 // Next, call a queueFamilyIndexCount that's too small for CONCURRENT:
15926 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
15927 swapchain_create_info.queueFamilyIndexCount = 1;
15928 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15929 "but with a bad value(s) for pCreateInfo->queueFamilyIndexCount or "
15930 "pCreateInfo->pQueueFamilyIndices).");
15931 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
15932 pass = (err != VK_SUCCESS);
15933 ASSERT_TRUE(pass);
15934 m_errorMonitor->VerifyFound();
15935
15936 // Next, call with an invalid imageSharingMode:
15937 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_MAX_ENUM;
15938 swapchain_create_info.queueFamilyIndexCount = 1;
15939 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15940 "called with a non-supported pCreateInfo->imageSharingMode (i.e.");
15941 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
15942 pass = (err != VK_SUCCESS);
15943 ASSERT_TRUE(pass);
15944 m_errorMonitor->VerifyFound();
15945 // Fix for the future:
15946 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
15947 // SUPPORTED
15948 swapchain_create_info.queueFamilyIndexCount = 0;
15949 queueFamilyIndex[0] = 0;
15950 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE;
15951
15952 // TODO: CONTINUE TESTING VALIDATION OF vkCreateSwapchainKHR() ...
15953 // Get the images from a swapchain:
15954 // Acquire an image from a swapchain:
15955 // Present an image to a swapchain:
15956 // Destroy the swapchain:
15957
15958 // TODOs:
15959 //
15960 // - Try destroying the device without first destroying the swapchain
15961 //
15962 // - Try destroying the device without first destroying the surface
15963 //
15964 // - Try destroying the surface without first destroying the swapchain
15965
15966 // Destroy the surface:
15967 vkDestroySurfaceKHR(instance(), surface, NULL);
15968
15969 // Tear down the window:
15970 xcb_destroy_window(connection, xcb_window);
15971 xcb_disconnect(connection);
15972
15973#else // VK_USE_PLATFORM_XCB_KHR
15974 return;
15975#endif // VK_USE_PLATFORM_XCB_KHR
15976}
Chris Forbes09368e42016-10-13 11:59:22 +130015977#endif
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060015978
15979//
15980// POSITIVE VALIDATION TESTS
15981//
15982// These tests do not expect to encounter ANY validation errors pass only if this is true
15983
Tobin Ehlise0006882016-11-03 10:14:28 -060015984TEST_F(VkPositiveLayerTest, SecondaryCommandBufferImageLayoutTransitions) {
15985 TEST_DESCRIPTION("Perform an image layout transition in a secondary command buffer followed "
15986 "by a transition in the primary.");
15987 VkResult err;
15988 m_errorMonitor->ExpectSuccess();
15989 ASSERT_NO_FATAL_FAILURE(InitState());
15990 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15991 // Allocate a secondary and primary cmd buffer
15992 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
15993 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
15994 command_buffer_allocate_info.commandPool = m_commandPool;
15995 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
15996 command_buffer_allocate_info.commandBufferCount = 1;
15997
15998 VkCommandBuffer secondary_command_buffer;
15999 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer));
16000 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
16001 VkCommandBuffer primary_command_buffer;
16002 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &primary_command_buffer));
16003 VkCommandBufferBeginInfo command_buffer_begin_info = {};
16004 VkCommandBufferInheritanceInfo command_buffer_inheritance_info = {};
16005 command_buffer_inheritance_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
16006 command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
16007 command_buffer_begin_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
16008 command_buffer_begin_info.pInheritanceInfo = &command_buffer_inheritance_info;
16009
16010 err = vkBeginCommandBuffer(secondary_command_buffer, &command_buffer_begin_info);
16011 ASSERT_VK_SUCCESS(err);
16012 VkImageObj image(m_device);
16013 image.init(128, 128, VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
16014 ASSERT_TRUE(image.initialized());
16015 VkImageMemoryBarrier img_barrier = {};
16016 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
16017 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
16018 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
16019 img_barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
16020 img_barrier.newLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
16021 img_barrier.image = image.handle();
16022 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
16023 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
16024 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
16025 img_barrier.subresourceRange.baseArrayLayer = 0;
16026 img_barrier.subresourceRange.baseMipLevel = 0;
16027 img_barrier.subresourceRange.layerCount = 1;
16028 img_barrier.subresourceRange.levelCount = 1;
16029 vkCmdPipelineBarrier(secondary_command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr,
16030 0, nullptr, 1, &img_barrier);
16031 err = vkEndCommandBuffer(secondary_command_buffer);
16032 ASSERT_VK_SUCCESS(err);
16033
16034 // Now update primary cmd buffer to execute secondary and transitions image
16035 command_buffer_begin_info.pInheritanceInfo = nullptr;
16036 err = vkBeginCommandBuffer(primary_command_buffer, &command_buffer_begin_info);
16037 ASSERT_VK_SUCCESS(err);
16038 vkCmdExecuteCommands(primary_command_buffer, 1, &secondary_command_buffer);
16039 VkImageMemoryBarrier img_barrier2 = {};
16040 img_barrier2.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
16041 img_barrier2.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
16042 img_barrier2.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
16043 img_barrier2.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
16044 img_barrier2.newLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
16045 img_barrier2.image = image.handle();
16046 img_barrier2.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
16047 img_barrier2.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
16048 img_barrier2.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
16049 img_barrier2.subresourceRange.baseArrayLayer = 0;
16050 img_barrier2.subresourceRange.baseMipLevel = 0;
16051 img_barrier2.subresourceRange.layerCount = 1;
16052 img_barrier2.subresourceRange.levelCount = 1;
16053 vkCmdPipelineBarrier(primary_command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0,
16054 nullptr, 1, &img_barrier2);
16055 err = vkEndCommandBuffer(primary_command_buffer);
16056 ASSERT_VK_SUCCESS(err);
16057 VkSubmitInfo submit_info = {};
16058 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
16059 submit_info.commandBufferCount = 1;
16060 submit_info.pCommandBuffers = &primary_command_buffer;
16061 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
16062 ASSERT_VK_SUCCESS(err);
16063 m_errorMonitor->VerifyNotFound();
16064 err = vkDeviceWaitIdle(m_device->device());
16065 ASSERT_VK_SUCCESS(err);
16066 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &secondary_command_buffer);
16067 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &primary_command_buffer);
16068}
16069
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016070// This is a positive test. No failures are expected.
16071TEST_F(VkPositiveLayerTest, IgnoreUnrelatedDescriptor) {
16072 TEST_DESCRIPTION("Ensure that the vkUpdateDescriptorSets validation code "
16073 "is ignoring VkWriteDescriptorSet members that are not "
16074 "related to the descriptor type specified by "
16075 "VkWriteDescriptorSet::descriptorType. Correct "
16076 "validation behavior will result in the test running to "
16077 "completion without validation errors.");
16078
16079 const uintptr_t invalid_ptr = 0xcdcdcdcd;
16080
16081 ASSERT_NO_FATAL_FAILURE(InitState());
16082
16083 // Image Case
16084 {
16085 m_errorMonitor->ExpectSuccess();
16086
16087 VkImage image;
16088 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
16089 const int32_t tex_width = 32;
16090 const int32_t tex_height = 32;
16091 VkImageCreateInfo image_create_info = {};
16092 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16093 image_create_info.pNext = NULL;
16094 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16095 image_create_info.format = tex_format;
16096 image_create_info.extent.width = tex_width;
16097 image_create_info.extent.height = tex_height;
16098 image_create_info.extent.depth = 1;
16099 image_create_info.mipLevels = 1;
16100 image_create_info.arrayLayers = 1;
16101 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16102 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
16103 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
16104 image_create_info.flags = 0;
16105 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
16106 ASSERT_VK_SUCCESS(err);
16107
16108 VkMemoryRequirements memory_reqs;
16109 VkDeviceMemory image_memory;
16110 bool pass;
16111 VkMemoryAllocateInfo memory_info = {};
16112 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16113 memory_info.pNext = NULL;
16114 memory_info.allocationSize = 0;
16115 memory_info.memoryTypeIndex = 0;
16116 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
16117 memory_info.allocationSize = memory_reqs.size;
16118 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
16119 ASSERT_TRUE(pass);
16120 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
16121 ASSERT_VK_SUCCESS(err);
16122 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
16123 ASSERT_VK_SUCCESS(err);
16124
16125 VkImageViewCreateInfo image_view_create_info = {};
16126 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
16127 image_view_create_info.image = image;
16128 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
16129 image_view_create_info.format = tex_format;
16130 image_view_create_info.subresourceRange.layerCount = 1;
16131 image_view_create_info.subresourceRange.baseMipLevel = 0;
16132 image_view_create_info.subresourceRange.levelCount = 1;
16133 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16134
16135 VkImageView view;
16136 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
16137 ASSERT_VK_SUCCESS(err);
16138
16139 VkDescriptorPoolSize ds_type_count = {};
16140 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
16141 ds_type_count.descriptorCount = 1;
16142
16143 VkDescriptorPoolCreateInfo ds_pool_ci = {};
16144 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
16145 ds_pool_ci.pNext = NULL;
16146 ds_pool_ci.maxSets = 1;
16147 ds_pool_ci.poolSizeCount = 1;
16148 ds_pool_ci.pPoolSizes = &ds_type_count;
16149
16150 VkDescriptorPool ds_pool;
16151 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
16152 ASSERT_VK_SUCCESS(err);
16153
16154 VkDescriptorSetLayoutBinding dsl_binding = {};
16155 dsl_binding.binding = 0;
16156 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
16157 dsl_binding.descriptorCount = 1;
16158 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
16159 dsl_binding.pImmutableSamplers = NULL;
16160
16161 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
16162 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
16163 ds_layout_ci.pNext = NULL;
16164 ds_layout_ci.bindingCount = 1;
16165 ds_layout_ci.pBindings = &dsl_binding;
16166 VkDescriptorSetLayout ds_layout;
16167 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
16168 ASSERT_VK_SUCCESS(err);
16169
16170 VkDescriptorSet descriptor_set;
16171 VkDescriptorSetAllocateInfo alloc_info = {};
16172 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
16173 alloc_info.descriptorSetCount = 1;
16174 alloc_info.descriptorPool = ds_pool;
16175 alloc_info.pSetLayouts = &ds_layout;
16176 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
16177 ASSERT_VK_SUCCESS(err);
16178
16179 VkDescriptorImageInfo image_info = {};
16180 image_info.imageView = view;
16181 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
16182
16183 VkWriteDescriptorSet descriptor_write;
16184 memset(&descriptor_write, 0, sizeof(descriptor_write));
16185 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
16186 descriptor_write.dstSet = descriptor_set;
16187 descriptor_write.dstBinding = 0;
16188 descriptor_write.descriptorCount = 1;
16189 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
16190 descriptor_write.pImageInfo = &image_info;
16191
16192 // Set pBufferInfo and pTexelBufferView to invalid values, which should
16193 // be
16194 // ignored for descriptorType == VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE.
16195 // This will most likely produce a crash if the parameter_validation
16196 // layer
16197 // does not correctly ignore pBufferInfo.
16198 descriptor_write.pBufferInfo = reinterpret_cast<const VkDescriptorBufferInfo *>(invalid_ptr);
16199 descriptor_write.pTexelBufferView = reinterpret_cast<const VkBufferView *>(invalid_ptr);
16200
16201 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
16202
16203 m_errorMonitor->VerifyNotFound();
16204
16205 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
16206 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
16207 vkDestroyImageView(m_device->device(), view, NULL);
16208 vkDestroyImage(m_device->device(), image, NULL);
16209 vkFreeMemory(m_device->device(), image_memory, NULL);
16210 }
16211
16212 // Buffer Case
16213 {
16214 m_errorMonitor->ExpectSuccess();
16215
16216 VkBuffer buffer;
16217 uint32_t queue_family_index = 0;
16218 VkBufferCreateInfo buffer_create_info = {};
16219 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
16220 buffer_create_info.size = 1024;
16221 buffer_create_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
16222 buffer_create_info.queueFamilyIndexCount = 1;
16223 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
16224
16225 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
16226 ASSERT_VK_SUCCESS(err);
16227
16228 VkMemoryRequirements memory_reqs;
16229 VkDeviceMemory buffer_memory;
16230 bool pass;
16231 VkMemoryAllocateInfo memory_info = {};
16232 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16233 memory_info.pNext = NULL;
16234 memory_info.allocationSize = 0;
16235 memory_info.memoryTypeIndex = 0;
16236
16237 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
16238 memory_info.allocationSize = memory_reqs.size;
16239 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
16240 ASSERT_TRUE(pass);
16241
16242 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
16243 ASSERT_VK_SUCCESS(err);
16244 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
16245 ASSERT_VK_SUCCESS(err);
16246
16247 VkDescriptorPoolSize ds_type_count = {};
16248 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16249 ds_type_count.descriptorCount = 1;
16250
16251 VkDescriptorPoolCreateInfo ds_pool_ci = {};
16252 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
16253 ds_pool_ci.pNext = NULL;
16254 ds_pool_ci.maxSets = 1;
16255 ds_pool_ci.poolSizeCount = 1;
16256 ds_pool_ci.pPoolSizes = &ds_type_count;
16257
16258 VkDescriptorPool ds_pool;
16259 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
16260 ASSERT_VK_SUCCESS(err);
16261
16262 VkDescriptorSetLayoutBinding dsl_binding = {};
16263 dsl_binding.binding = 0;
16264 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16265 dsl_binding.descriptorCount = 1;
16266 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
16267 dsl_binding.pImmutableSamplers = NULL;
16268
16269 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
16270 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
16271 ds_layout_ci.pNext = NULL;
16272 ds_layout_ci.bindingCount = 1;
16273 ds_layout_ci.pBindings = &dsl_binding;
16274 VkDescriptorSetLayout ds_layout;
16275 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
16276 ASSERT_VK_SUCCESS(err);
16277
16278 VkDescriptorSet descriptor_set;
16279 VkDescriptorSetAllocateInfo alloc_info = {};
16280 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
16281 alloc_info.descriptorSetCount = 1;
16282 alloc_info.descriptorPool = ds_pool;
16283 alloc_info.pSetLayouts = &ds_layout;
16284 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
16285 ASSERT_VK_SUCCESS(err);
16286
16287 VkDescriptorBufferInfo buffer_info = {};
16288 buffer_info.buffer = buffer;
16289 buffer_info.offset = 0;
16290 buffer_info.range = 1024;
16291
16292 VkWriteDescriptorSet descriptor_write;
16293 memset(&descriptor_write, 0, sizeof(descriptor_write));
16294 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
16295 descriptor_write.dstSet = descriptor_set;
16296 descriptor_write.dstBinding = 0;
16297 descriptor_write.descriptorCount = 1;
16298 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16299 descriptor_write.pBufferInfo = &buffer_info;
16300
16301 // Set pImageInfo and pTexelBufferView to invalid values, which should
16302 // be
16303 // ignored for descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER.
16304 // This will most likely produce a crash if the parameter_validation
16305 // layer
16306 // does not correctly ignore pImageInfo.
16307 descriptor_write.pImageInfo = reinterpret_cast<const VkDescriptorImageInfo *>(invalid_ptr);
16308 descriptor_write.pTexelBufferView = reinterpret_cast<const VkBufferView *>(invalid_ptr);
16309
16310 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
16311
16312 m_errorMonitor->VerifyNotFound();
16313
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016314 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
16315 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
16316 vkDestroyBuffer(m_device->device(), buffer, NULL);
16317 vkFreeMemory(m_device->device(), buffer_memory, NULL);
16318 }
16319
16320 // Texel Buffer Case
16321 {
16322 m_errorMonitor->ExpectSuccess();
16323
16324 VkBuffer buffer;
16325 uint32_t queue_family_index = 0;
16326 VkBufferCreateInfo buffer_create_info = {};
16327 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
16328 buffer_create_info.size = 1024;
16329 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
16330 buffer_create_info.queueFamilyIndexCount = 1;
16331 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
16332
16333 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
16334 ASSERT_VK_SUCCESS(err);
16335
16336 VkMemoryRequirements memory_reqs;
16337 VkDeviceMemory buffer_memory;
16338 bool pass;
16339 VkMemoryAllocateInfo memory_info = {};
16340 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16341 memory_info.pNext = NULL;
16342 memory_info.allocationSize = 0;
16343 memory_info.memoryTypeIndex = 0;
16344
16345 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
16346 memory_info.allocationSize = memory_reqs.size;
16347 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
16348 ASSERT_TRUE(pass);
16349
16350 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
16351 ASSERT_VK_SUCCESS(err);
16352 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
16353 ASSERT_VK_SUCCESS(err);
16354
16355 VkBufferViewCreateInfo buff_view_ci = {};
16356 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
16357 buff_view_ci.buffer = buffer;
16358 buff_view_ci.format = VK_FORMAT_R8_UNORM;
16359 buff_view_ci.range = VK_WHOLE_SIZE;
16360 VkBufferView buffer_view;
16361 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buffer_view);
16362
16363 VkDescriptorPoolSize ds_type_count = {};
16364 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
16365 ds_type_count.descriptorCount = 1;
16366
16367 VkDescriptorPoolCreateInfo ds_pool_ci = {};
16368 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
16369 ds_pool_ci.pNext = NULL;
16370 ds_pool_ci.maxSets = 1;
16371 ds_pool_ci.poolSizeCount = 1;
16372 ds_pool_ci.pPoolSizes = &ds_type_count;
16373
16374 VkDescriptorPool ds_pool;
16375 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
16376 ASSERT_VK_SUCCESS(err);
16377
16378 VkDescriptorSetLayoutBinding dsl_binding = {};
16379 dsl_binding.binding = 0;
16380 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
16381 dsl_binding.descriptorCount = 1;
16382 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
16383 dsl_binding.pImmutableSamplers = NULL;
16384
16385 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
16386 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
16387 ds_layout_ci.pNext = NULL;
16388 ds_layout_ci.bindingCount = 1;
16389 ds_layout_ci.pBindings = &dsl_binding;
16390 VkDescriptorSetLayout ds_layout;
16391 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
16392 ASSERT_VK_SUCCESS(err);
16393
16394 VkDescriptorSet descriptor_set;
16395 VkDescriptorSetAllocateInfo alloc_info = {};
16396 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
16397 alloc_info.descriptorSetCount = 1;
16398 alloc_info.descriptorPool = ds_pool;
16399 alloc_info.pSetLayouts = &ds_layout;
16400 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
16401 ASSERT_VK_SUCCESS(err);
16402
16403 VkWriteDescriptorSet descriptor_write;
16404 memset(&descriptor_write, 0, sizeof(descriptor_write));
16405 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
16406 descriptor_write.dstSet = descriptor_set;
16407 descriptor_write.dstBinding = 0;
16408 descriptor_write.descriptorCount = 1;
16409 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
16410 descriptor_write.pTexelBufferView = &buffer_view;
16411
16412 // Set pImageInfo and pBufferInfo to invalid values, which should be
16413 // ignored for descriptorType ==
16414 // VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER.
16415 // This will most likely produce a crash if the parameter_validation
16416 // layer
16417 // does not correctly ignore pImageInfo and pBufferInfo.
16418 descriptor_write.pImageInfo = reinterpret_cast<const VkDescriptorImageInfo *>(invalid_ptr);
16419 descriptor_write.pBufferInfo = reinterpret_cast<const VkDescriptorBufferInfo *>(invalid_ptr);
16420
16421 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
16422
16423 m_errorMonitor->VerifyNotFound();
16424
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016425 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
16426 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
16427 vkDestroyBufferView(m_device->device(), buffer_view, NULL);
16428 vkDestroyBuffer(m_device->device(), buffer, NULL);
16429 vkFreeMemory(m_device->device(), buffer_memory, NULL);
16430 }
16431}
16432
Tobin Ehlisf7428442016-10-25 07:58:24 -060016433TEST_F(VkLayerTest, DuplicateDescriptorBinding) {
16434 TEST_DESCRIPTION("Create a descriptor set layout with a duplicate binding number.");
16435
16436 ASSERT_NO_FATAL_FAILURE(InitState());
16437 // Create layout where two binding #s are "1"
16438 static const uint32_t NUM_BINDINGS = 3;
16439 VkDescriptorSetLayoutBinding dsl_binding[NUM_BINDINGS] = {};
16440 dsl_binding[0].binding = 1;
16441 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16442 dsl_binding[0].descriptorCount = 1;
16443 dsl_binding[0].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
16444 dsl_binding[0].pImmutableSamplers = NULL;
16445 dsl_binding[1].binding = 0;
16446 dsl_binding[1].descriptorCount = 1;
16447 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16448 dsl_binding[1].descriptorCount = 1;
16449 dsl_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
16450 dsl_binding[1].pImmutableSamplers = NULL;
16451 dsl_binding[2].binding = 1; // Duplicate binding should cause error
16452 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16453 dsl_binding[2].descriptorCount = 1;
16454 dsl_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
16455 dsl_binding[2].pImmutableSamplers = NULL;
16456
16457 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
16458 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
16459 ds_layout_ci.pNext = NULL;
16460 ds_layout_ci.bindingCount = NUM_BINDINGS;
16461 ds_layout_ci.pBindings = dsl_binding;
16462 VkDescriptorSetLayout ds_layout;
16463 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02345);
16464 vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
16465 m_errorMonitor->VerifyFound();
16466}
16467
Mike Weiblen9a0f55d2016-10-31 22:35:00 -060016468TEST_F(VkLayerTest, ViewportAndScissorBoundsChecking) {
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060016469 TEST_DESCRIPTION("Verify errors are detected on misuse of SetViewport and SetScissor.");
16470
16471 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060016472
16473 BeginCommandBuffer();
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060016474
Mike Weiblen9a0f55d2016-10-31 22:35:00 -060016475 const VkPhysicalDeviceLimits &limits = m_device->props.limits;
16476
16477 {
16478 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01448);
16479 VkViewport viewport = {0, 0, static_cast<float>(limits.maxViewportDimensions[0] + 1), 16, 0, 1};
16480 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
16481 m_errorMonitor->VerifyFound();
16482 }
16483
16484 {
16485 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01449);
16486 VkViewport viewport = {0, 0, 16, static_cast<float>(limits.maxViewportDimensions[1] + 1), 0, 1};
16487 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
16488 m_errorMonitor->VerifyFound();
16489 }
16490
16491 {
16492 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01450);
16493 VkViewport viewport = {limits.viewportBoundsRange[0] - 1, 0, 16, 16, 0, 1};
16494 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
16495 m_errorMonitor->VerifyFound();
16496 }
16497
16498 {
16499 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01450);
16500 VkViewport viewport = {0, limits.viewportBoundsRange[0] - 1, 16, 16, 0, 1};
16501 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
16502 m_errorMonitor->VerifyFound();
16503 }
16504
16505 {
16506 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01451);
16507 VkViewport viewport = {limits.viewportBoundsRange[1], 0, 16, 16, 0, 1};
16508 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
16509 m_errorMonitor->VerifyFound();
16510 }
16511
16512 {
16513 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01452);
16514 VkViewport viewport = {0, limits.viewportBoundsRange[1], 16, 16, 0, 1};
16515 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
16516 m_errorMonitor->VerifyFound();
16517 }
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060016518
16519 {
16520 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01489);
16521 VkRect2D scissor = {{-1, 0}, {16, 16}};
16522 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
16523 m_errorMonitor->VerifyFound();
16524 }
16525
16526 {
16527 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01489);
16528 VkRect2D scissor = {{0, -2}, {16, 16}};
16529 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
16530 m_errorMonitor->VerifyFound();
16531 }
16532
16533 {
16534 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01490);
16535 VkRect2D scissor = {{100, 100}, {INT_MAX, 16}};
16536 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
16537 m_errorMonitor->VerifyFound();
16538 }
16539
16540 {
16541 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01491);
16542 VkRect2D scissor = {{100, 100}, {16, INT_MAX}};
16543 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
16544 m_errorMonitor->VerifyFound();
16545 }
16546
16547 EndCommandBuffer();
16548}
16549
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016550// This is a positive test. No failures are expected.
16551TEST_F(VkPositiveLayerTest, EmptyDescriptorUpdateTest) {
16552 TEST_DESCRIPTION("Update last descriptor in a set that includes an empty binding");
16553 VkResult err;
16554
16555 ASSERT_NO_FATAL_FAILURE(InitState());
16556 m_errorMonitor->ExpectSuccess();
16557 VkDescriptorPoolSize ds_type_count = {};
16558 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16559 ds_type_count.descriptorCount = 2;
16560
16561 VkDescriptorPoolCreateInfo ds_pool_ci = {};
16562 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
16563 ds_pool_ci.pNext = NULL;
16564 ds_pool_ci.maxSets = 1;
16565 ds_pool_ci.poolSizeCount = 1;
16566 ds_pool_ci.pPoolSizes = &ds_type_count;
16567
16568 VkDescriptorPool ds_pool;
16569 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
16570 ASSERT_VK_SUCCESS(err);
16571
16572 // Create layout with two uniform buffer descriptors w/ empty binding between them
16573 static const uint32_t NUM_BINDINGS = 3;
16574 VkDescriptorSetLayoutBinding dsl_binding[NUM_BINDINGS] = {};
16575 dsl_binding[0].binding = 0;
16576 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16577 dsl_binding[0].descriptorCount = 1;
16578 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
16579 dsl_binding[0].pImmutableSamplers = NULL;
16580 dsl_binding[1].binding = 1;
16581 dsl_binding[1].descriptorCount = 0; // empty binding
16582 dsl_binding[2].binding = 2;
16583 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16584 dsl_binding[2].descriptorCount = 1;
16585 dsl_binding[2].stageFlags = VK_SHADER_STAGE_ALL;
16586 dsl_binding[2].pImmutableSamplers = NULL;
16587
16588 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
16589 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
16590 ds_layout_ci.pNext = NULL;
16591 ds_layout_ci.bindingCount = NUM_BINDINGS;
16592 ds_layout_ci.pBindings = dsl_binding;
16593 VkDescriptorSetLayout ds_layout;
16594 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
16595 ASSERT_VK_SUCCESS(err);
16596
16597 VkDescriptorSet descriptor_set = {};
16598 VkDescriptorSetAllocateInfo alloc_info = {};
16599 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
16600 alloc_info.descriptorSetCount = 1;
16601 alloc_info.descriptorPool = ds_pool;
16602 alloc_info.pSetLayouts = &ds_layout;
16603 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
16604 ASSERT_VK_SUCCESS(err);
16605
16606 // Create a buffer to be used for update
16607 VkBufferCreateInfo buff_ci = {};
16608 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
16609 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
16610 buff_ci.size = 256;
16611 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
16612 VkBuffer buffer;
16613 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
16614 ASSERT_VK_SUCCESS(err);
16615 // Have to bind memory to buffer before descriptor update
16616 VkMemoryAllocateInfo mem_alloc = {};
16617 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16618 mem_alloc.pNext = NULL;
16619 mem_alloc.allocationSize = 512; // one allocation for both buffers
16620 mem_alloc.memoryTypeIndex = 0;
16621
16622 VkMemoryRequirements mem_reqs;
16623 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
16624 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
16625 if (!pass) {
16626 vkDestroyBuffer(m_device->device(), buffer, NULL);
16627 return;
16628 }
16629
16630 VkDeviceMemory mem;
16631 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
16632 ASSERT_VK_SUCCESS(err);
16633 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
16634 ASSERT_VK_SUCCESS(err);
16635
16636 // Only update the descriptor at binding 2
16637 VkDescriptorBufferInfo buff_info = {};
16638 buff_info.buffer = buffer;
16639 buff_info.offset = 0;
16640 buff_info.range = VK_WHOLE_SIZE;
16641 VkWriteDescriptorSet descriptor_write = {};
16642 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
16643 descriptor_write.dstBinding = 2;
16644 descriptor_write.descriptorCount = 1;
16645 descriptor_write.pTexelBufferView = nullptr;
16646 descriptor_write.pBufferInfo = &buff_info;
16647 descriptor_write.pImageInfo = nullptr;
16648 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16649 descriptor_write.dstSet = descriptor_set;
16650
16651 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
16652
16653 m_errorMonitor->VerifyNotFound();
16654 // Cleanup
16655 vkFreeMemory(m_device->device(), mem, NULL);
16656 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
16657 vkDestroyBuffer(m_device->device(), buffer, NULL);
16658 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
16659}
16660
16661// This is a positive test. No failures are expected.
16662TEST_F(VkPositiveLayerTest, TestAliasedMemoryTracking) {
16663 VkResult err;
16664 bool pass;
16665
16666 TEST_DESCRIPTION("Create a buffer, allocate memory, bind memory, destroy "
16667 "the buffer, create an image, and bind the same memory to "
16668 "it");
16669
16670 m_errorMonitor->ExpectSuccess();
16671
16672 ASSERT_NO_FATAL_FAILURE(InitState());
16673
16674 VkBuffer buffer;
16675 VkImage image;
16676 VkDeviceMemory mem;
16677 VkMemoryRequirements mem_reqs;
16678
16679 VkBufferCreateInfo buf_info = {};
16680 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
16681 buf_info.pNext = NULL;
16682 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
16683 buf_info.size = 256;
16684 buf_info.queueFamilyIndexCount = 0;
16685 buf_info.pQueueFamilyIndices = NULL;
16686 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
16687 buf_info.flags = 0;
16688 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
16689 ASSERT_VK_SUCCESS(err);
16690
16691 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
16692
16693 VkMemoryAllocateInfo alloc_info = {};
16694 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16695 alloc_info.pNext = NULL;
16696 alloc_info.memoryTypeIndex = 0;
16697
16698 // Ensure memory is big enough for both bindings
16699 alloc_info.allocationSize = 0x10000;
16700
16701 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
16702 if (!pass) {
16703 vkDestroyBuffer(m_device->device(), buffer, NULL);
16704 return;
16705 }
16706
16707 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
16708 ASSERT_VK_SUCCESS(err);
16709
16710 uint8_t *pData;
16711 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
16712 ASSERT_VK_SUCCESS(err);
16713
16714 memset(pData, 0xCADECADE, static_cast<size_t>(mem_reqs.size));
16715
16716 vkUnmapMemory(m_device->device(), mem);
16717
16718 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
16719 ASSERT_VK_SUCCESS(err);
16720
16721 // NOW, destroy the buffer. Obviously, the resource no longer occupies this
16722 // memory. In fact, it was never used by the GPU.
16723 // Just be be sure, wait for idle.
16724 vkDestroyBuffer(m_device->device(), buffer, NULL);
16725 vkDeviceWaitIdle(m_device->device());
16726
16727 VkImageCreateInfo image_create_info = {};
16728 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16729 image_create_info.pNext = NULL;
16730 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16731 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
16732 image_create_info.extent.width = 64;
16733 image_create_info.extent.height = 64;
16734 image_create_info.extent.depth = 1;
16735 image_create_info.mipLevels = 1;
16736 image_create_info.arrayLayers = 1;
16737 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16738 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
16739 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
16740 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
16741 image_create_info.queueFamilyIndexCount = 0;
16742 image_create_info.pQueueFamilyIndices = NULL;
16743 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
16744 image_create_info.flags = 0;
16745
16746 VkMemoryAllocateInfo mem_alloc = {};
16747 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16748 mem_alloc.pNext = NULL;
16749 mem_alloc.allocationSize = 0;
16750 mem_alloc.memoryTypeIndex = 0;
16751
16752 /* Create a mappable image. It will be the texture if linear images are ok
16753 * to be textures or it will be the staging image if they are not.
16754 */
16755 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
16756 ASSERT_VK_SUCCESS(err);
16757
16758 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
16759
16760 mem_alloc.allocationSize = mem_reqs.size;
16761
16762 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
16763 if (!pass) {
16764 vkDestroyImage(m_device->device(), image, NULL);
16765 return;
16766 }
16767
16768 // VALIDATION FAILURE:
16769 err = vkBindImageMemory(m_device->device(), image, mem, 0);
16770 ASSERT_VK_SUCCESS(err);
16771
16772 m_errorMonitor->VerifyNotFound();
16773
16774 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016775 vkDestroyImage(m_device->device(), image, NULL);
16776}
16777
Tobin Ehlis953e8392016-11-17 10:54:13 -070016778TEST_F(VkPositiveLayerTest, DynamicOffsetWithInactiveBinding) {
16779 // Create a descriptorSet w/ dynamic descriptors where 1 binding is inactive
16780 // We previously had a bug where dynamic offset of inactive bindings was still being used
16781 VkResult err;
16782 m_errorMonitor->ExpectSuccess();
16783
16784 ASSERT_NO_FATAL_FAILURE(InitState());
16785 ASSERT_NO_FATAL_FAILURE(InitViewport());
16786 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
16787
16788 VkDescriptorPoolSize ds_type_count = {};
16789 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
16790 ds_type_count.descriptorCount = 3;
16791
16792 VkDescriptorPoolCreateInfo ds_pool_ci = {};
16793 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
16794 ds_pool_ci.pNext = NULL;
16795 ds_pool_ci.maxSets = 1;
16796 ds_pool_ci.poolSizeCount = 1;
16797 ds_pool_ci.pPoolSizes = &ds_type_count;
16798
16799 VkDescriptorPool ds_pool;
16800 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
16801 ASSERT_VK_SUCCESS(err);
16802
16803 const uint32_t BINDING_COUNT = 3;
16804 VkDescriptorSetLayoutBinding dsl_binding[BINDING_COUNT] = {};
Tobin Ehlis0050fba2016-11-30 10:22:02 -070016805 dsl_binding[0].binding = 2;
Tobin Ehlis953e8392016-11-17 10:54:13 -070016806 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
16807 dsl_binding[0].descriptorCount = 1;
16808 dsl_binding[0].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
16809 dsl_binding[0].pImmutableSamplers = NULL;
Tobin Ehlis0050fba2016-11-30 10:22:02 -070016810 dsl_binding[1].binding = 0;
Tobin Ehlis953e8392016-11-17 10:54:13 -070016811 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
16812 dsl_binding[1].descriptorCount = 1;
16813 dsl_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
16814 dsl_binding[1].pImmutableSamplers = NULL;
Tobin Ehlis0050fba2016-11-30 10:22:02 -070016815 dsl_binding[2].binding = 1;
Tobin Ehlis953e8392016-11-17 10:54:13 -070016816 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
16817 dsl_binding[2].descriptorCount = 1;
16818 dsl_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
16819 dsl_binding[2].pImmutableSamplers = NULL;
16820
16821 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
16822 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
16823 ds_layout_ci.pNext = NULL;
16824 ds_layout_ci.bindingCount = BINDING_COUNT;
16825 ds_layout_ci.pBindings = dsl_binding;
16826 VkDescriptorSetLayout ds_layout;
16827 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
16828 ASSERT_VK_SUCCESS(err);
16829
16830 VkDescriptorSet descriptor_set;
16831 VkDescriptorSetAllocateInfo alloc_info = {};
16832 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
16833 alloc_info.descriptorSetCount = 1;
16834 alloc_info.descriptorPool = ds_pool;
16835 alloc_info.pSetLayouts = &ds_layout;
16836 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
16837 ASSERT_VK_SUCCESS(err);
16838
16839 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
16840 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
16841 pipeline_layout_ci.pNext = NULL;
16842 pipeline_layout_ci.setLayoutCount = 1;
16843 pipeline_layout_ci.pSetLayouts = &ds_layout;
16844
16845 VkPipelineLayout pipeline_layout;
16846 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
16847 ASSERT_VK_SUCCESS(err);
16848
16849 // Create two buffers to update the descriptors with
16850 // The first will be 2k and used for bindings 0 & 1, the second is 1k for binding 2
16851 uint32_t qfi = 0;
16852 VkBufferCreateInfo buffCI = {};
16853 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
16854 buffCI.size = 2048;
16855 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
16856 buffCI.queueFamilyIndexCount = 1;
16857 buffCI.pQueueFamilyIndices = &qfi;
16858
16859 VkBuffer dyub1;
16860 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub1);
16861 ASSERT_VK_SUCCESS(err);
16862 // buffer2
16863 buffCI.size = 1024;
16864 VkBuffer dyub2;
16865 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub2);
16866 ASSERT_VK_SUCCESS(err);
16867 // Allocate memory and bind to buffers
16868 VkMemoryAllocateInfo mem_alloc[2] = {};
16869 mem_alloc[0].sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16870 mem_alloc[0].pNext = NULL;
16871 mem_alloc[0].memoryTypeIndex = 0;
16872 mem_alloc[1].sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16873 mem_alloc[1].pNext = NULL;
16874 mem_alloc[1].memoryTypeIndex = 0;
16875
16876 VkMemoryRequirements mem_reqs1;
16877 vkGetBufferMemoryRequirements(m_device->device(), dyub1, &mem_reqs1);
16878 VkMemoryRequirements mem_reqs2;
16879 vkGetBufferMemoryRequirements(m_device->device(), dyub2, &mem_reqs2);
16880 mem_alloc[0].allocationSize = mem_reqs1.size;
16881 bool pass = m_device->phy().set_memory_type(mem_reqs1.memoryTypeBits, &mem_alloc[0], 0);
16882 mem_alloc[1].allocationSize = mem_reqs2.size;
16883 pass &= m_device->phy().set_memory_type(mem_reqs2.memoryTypeBits, &mem_alloc[1], 0);
16884 if (!pass) {
16885 vkDestroyBuffer(m_device->device(), dyub1, NULL);
16886 vkDestroyBuffer(m_device->device(), dyub2, NULL);
16887 return;
16888 }
16889
16890 VkDeviceMemory mem1;
16891 err = vkAllocateMemory(m_device->device(), &mem_alloc[0], NULL, &mem1);
16892 ASSERT_VK_SUCCESS(err);
16893 err = vkBindBufferMemory(m_device->device(), dyub1, mem1, 0);
16894 ASSERT_VK_SUCCESS(err);
16895 VkDeviceMemory mem2;
16896 err = vkAllocateMemory(m_device->device(), &mem_alloc[1], NULL, &mem2);
16897 ASSERT_VK_SUCCESS(err);
16898 err = vkBindBufferMemory(m_device->device(), dyub2, mem2, 0);
16899 ASSERT_VK_SUCCESS(err);
16900 // Update descriptors
16901 VkDescriptorBufferInfo buff_info[BINDING_COUNT] = {};
16902 buff_info[0].buffer = dyub1;
16903 buff_info[0].offset = 0;
16904 buff_info[0].range = 256;
16905 buff_info[1].buffer = dyub1;
16906 buff_info[1].offset = 256;
16907 buff_info[1].range = 512;
16908 buff_info[2].buffer = dyub2;
16909 buff_info[2].offset = 0;
16910 buff_info[2].range = 512;
16911
16912 VkWriteDescriptorSet descriptor_write;
16913 memset(&descriptor_write, 0, sizeof(descriptor_write));
16914 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
16915 descriptor_write.dstSet = descriptor_set;
16916 descriptor_write.dstBinding = 0;
16917 descriptor_write.descriptorCount = BINDING_COUNT;
16918 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
16919 descriptor_write.pBufferInfo = buff_info;
16920
16921 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
16922
16923 BeginCommandBuffer();
16924
16925 // Create PSO to be used for draw-time errors below
16926 char const *vsSource = "#version 450\n"
16927 "\n"
16928 "out gl_PerVertex { \n"
16929 " vec4 gl_Position;\n"
16930 "};\n"
16931 "void main(){\n"
16932 " gl_Position = vec4(1);\n"
16933 "}\n";
16934 char const *fsSource = "#version 450\n"
16935 "\n"
16936 "layout(location=0) out vec4 x;\n"
16937 "layout(set=0) layout(binding=0) uniform foo1 { int x; int y; } bar1;\n"
16938 "layout(set=0) layout(binding=2) uniform foo2 { int x; int y; } bar2;\n"
16939 "void main(){\n"
16940 " x = vec4(bar1.y) + vec4(bar2.y);\n"
16941 "}\n";
16942 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
16943 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
16944 VkPipelineObj pipe(m_device);
16945 pipe.SetViewport(m_viewports);
16946 pipe.SetScissor(m_scissors);
16947 pipe.AddShader(&vs);
16948 pipe.AddShader(&fs);
16949 pipe.AddColorAttachment();
16950 pipe.CreateVKPipeline(pipeline_layout, renderPass());
16951
16952 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
16953 // This update should succeed, but offset of inactive binding 1 oversteps binding 2 buffer size
16954 // we used to have a bug in this case.
16955 uint32_t dyn_off[BINDING_COUNT] = {0, 1024, 256};
16956 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
16957 &descriptor_set, BINDING_COUNT, dyn_off);
16958 Draw(1, 0, 0, 0);
16959 m_errorMonitor->VerifyNotFound();
16960
16961 vkDestroyBuffer(m_device->device(), dyub1, NULL);
16962 vkDestroyBuffer(m_device->device(), dyub2, NULL);
16963 vkFreeMemory(m_device->device(), mem1, NULL);
16964 vkFreeMemory(m_device->device(), mem2, NULL);
16965
16966 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
16967 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
16968 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
16969}
16970
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016971TEST_F(VkPositiveLayerTest, NonCoherentMemoryMapping) {
16972
16973 TEST_DESCRIPTION("Ensure that validations handling of non-coherent memory "
16974 "mapping while using VK_WHOLE_SIZE does not cause access "
16975 "violations");
16976 VkResult err;
16977 uint8_t *pData;
16978 ASSERT_NO_FATAL_FAILURE(InitState());
16979
16980 VkDeviceMemory mem;
16981 VkMemoryRequirements mem_reqs;
16982 mem_reqs.memoryTypeBits = 0xFFFFFFFF;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070016983 const VkDeviceSize atom_size = m_device->props.limits.nonCoherentAtomSize;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016984 VkMemoryAllocateInfo alloc_info = {};
16985 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16986 alloc_info.pNext = NULL;
16987 alloc_info.memoryTypeIndex = 0;
16988
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070016989 static const VkDeviceSize allocation_size = 32 * atom_size;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016990 alloc_info.allocationSize = allocation_size;
16991
16992 // Find a memory configurations WITHOUT a COHERENT bit, otherwise exit
16993 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT,
16994 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
16995 if (!pass) {
16996 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info,
16997 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT,
16998 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
16999 if (!pass) {
17000 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info,
17001 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT |
17002 VK_MEMORY_PROPERTY_HOST_CACHED_BIT,
17003 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
17004 if (!pass) {
17005 return;
17006 }
17007 }
17008 }
17009
17010 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
17011 ASSERT_VK_SUCCESS(err);
17012
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017013 // Map/Flush/Invalidate using WHOLE_SIZE and zero offsets and entire mapped range
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017014 m_errorMonitor->ExpectSuccess();
17015 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, (void **)&pData);
17016 ASSERT_VK_SUCCESS(err);
17017 VkMappedMemoryRange mmr = {};
17018 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
17019 mmr.memory = mem;
17020 mmr.offset = 0;
17021 mmr.size = VK_WHOLE_SIZE;
17022 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
17023 ASSERT_VK_SUCCESS(err);
17024 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
17025 ASSERT_VK_SUCCESS(err);
17026 m_errorMonitor->VerifyNotFound();
17027 vkUnmapMemory(m_device->device(), mem);
17028
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017029 // Map/Flush/Invalidate using WHOLE_SIZE and an offset and entire mapped range
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017030 m_errorMonitor->ExpectSuccess();
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017031 err = vkMapMemory(m_device->device(), mem, 5 * atom_size, VK_WHOLE_SIZE, 0, (void **)&pData);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017032 ASSERT_VK_SUCCESS(err);
17033 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
17034 mmr.memory = mem;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017035 mmr.offset = 6 * atom_size;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017036 mmr.size = VK_WHOLE_SIZE;
17037 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
17038 ASSERT_VK_SUCCESS(err);
17039 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
17040 ASSERT_VK_SUCCESS(err);
17041 m_errorMonitor->VerifyNotFound();
17042 vkUnmapMemory(m_device->device(), mem);
17043
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017044 // Map with offset and size
17045 // Flush/Invalidate subrange of mapped area with offset and size
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017046 m_errorMonitor->ExpectSuccess();
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017047 err = vkMapMemory(m_device->device(), mem, 3 * atom_size, 9 * atom_size, 0, (void **)&pData);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017048 ASSERT_VK_SUCCESS(err);
17049 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
17050 mmr.memory = mem;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017051 mmr.offset = 4 * atom_size;
17052 mmr.size = 2 * atom_size;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017053 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
17054 ASSERT_VK_SUCCESS(err);
17055 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
17056 ASSERT_VK_SUCCESS(err);
17057 m_errorMonitor->VerifyNotFound();
17058 vkUnmapMemory(m_device->device(), mem);
17059
17060 // Map without offset and flush WHOLE_SIZE with two separate offsets
17061 m_errorMonitor->ExpectSuccess();
17062 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, (void **)&pData);
17063 ASSERT_VK_SUCCESS(err);
17064 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
17065 mmr.memory = mem;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017066 mmr.offset = allocation_size - (4 * atom_size);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017067 mmr.size = VK_WHOLE_SIZE;
17068 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
17069 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017070 mmr.offset = allocation_size - (6 * atom_size);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017071 mmr.size = VK_WHOLE_SIZE;
17072 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
17073 ASSERT_VK_SUCCESS(err);
17074 m_errorMonitor->VerifyNotFound();
17075 vkUnmapMemory(m_device->device(), mem);
17076
17077 vkFreeMemory(m_device->device(), mem, NULL);
17078}
17079
17080// This is a positive test. We used to expect error in this case but spec now allows it
17081TEST_F(VkPositiveLayerTest, ResetUnsignaledFence) {
17082 m_errorMonitor->ExpectSuccess();
17083 vk_testing::Fence testFence;
17084 VkFenceCreateInfo fenceInfo = {};
17085 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
17086 fenceInfo.pNext = NULL;
17087
17088 ASSERT_NO_FATAL_FAILURE(InitState());
17089 testFence.init(*m_device, fenceInfo);
17090 VkFence fences[1] = { testFence.handle() };
17091 VkResult result = vkResetFences(m_device->device(), 1, fences);
17092 ASSERT_VK_SUCCESS(result);
17093
17094 m_errorMonitor->VerifyNotFound();
17095}
17096
17097TEST_F(VkPositiveLayerTest, CommandBufferSimultaneousUseSync) {
17098 m_errorMonitor->ExpectSuccess();
17099
17100 ASSERT_NO_FATAL_FAILURE(InitState());
17101 VkResult err;
17102
17103 // Record (empty!) command buffer that can be submitted multiple times
17104 // simultaneously.
17105 VkCommandBufferBeginInfo cbbi = { VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr,
17106 VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT, nullptr };
17107 m_commandBuffer->BeginCommandBuffer(&cbbi);
17108 m_commandBuffer->EndCommandBuffer();
17109
17110 VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
17111 VkFence fence;
17112 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
17113 ASSERT_VK_SUCCESS(err);
17114
17115 VkSemaphoreCreateInfo sci = { VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0 };
17116 VkSemaphore s1, s2;
17117 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s1);
17118 ASSERT_VK_SUCCESS(err);
17119 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s2);
17120 ASSERT_VK_SUCCESS(err);
17121
17122 // Submit CB once signaling s1, with fence so we can roll forward to its retirement.
17123 VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 1, &m_commandBuffer->handle(), 1, &s1 };
17124 err = vkQueueSubmit(m_device->m_queue, 1, &si, fence);
17125 ASSERT_VK_SUCCESS(err);
17126
17127 // Submit CB again, signaling s2.
17128 si.pSignalSemaphores = &s2;
17129 err = vkQueueSubmit(m_device->m_queue, 1, &si, VK_NULL_HANDLE);
17130 ASSERT_VK_SUCCESS(err);
17131
17132 // Wait for fence.
17133 err = vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
17134 ASSERT_VK_SUCCESS(err);
17135
17136 // CB is still in flight from second submission, but semaphore s1 is no
17137 // longer in flight. delete it.
17138 vkDestroySemaphore(m_device->device(), s1, nullptr);
17139
17140 m_errorMonitor->VerifyNotFound();
17141
17142 // Force device idle and clean up remaining objects
17143 vkDeviceWaitIdle(m_device->device());
17144 vkDestroySemaphore(m_device->device(), s2, nullptr);
17145 vkDestroyFence(m_device->device(), fence, nullptr);
17146}
17147
17148TEST_F(VkPositiveLayerTest, FenceCreateSignaledWaitHandling) {
17149 m_errorMonitor->ExpectSuccess();
17150
17151 ASSERT_NO_FATAL_FAILURE(InitState());
17152 VkResult err;
17153
17154 // A fence created signaled
17155 VkFenceCreateInfo fci1 = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, VK_FENCE_CREATE_SIGNALED_BIT };
17156 VkFence f1;
17157 err = vkCreateFence(m_device->device(), &fci1, nullptr, &f1);
17158 ASSERT_VK_SUCCESS(err);
17159
17160 // A fence created not
17161 VkFenceCreateInfo fci2 = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
17162 VkFence f2;
17163 err = vkCreateFence(m_device->device(), &fci2, nullptr, &f2);
17164 ASSERT_VK_SUCCESS(err);
17165
17166 // Submit the unsignaled fence
17167 VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 0, nullptr, 0, nullptr };
17168 err = vkQueueSubmit(m_device->m_queue, 1, &si, f2);
17169
17170 // Wait on both fences, with signaled first.
17171 VkFence fences[] = { f1, f2 };
17172 vkWaitForFences(m_device->device(), 2, fences, VK_TRUE, UINT64_MAX);
17173
17174 // Should have both retired!
17175 vkDestroyFence(m_device->device(), f1, nullptr);
17176 vkDestroyFence(m_device->device(), f2, nullptr);
17177
17178 m_errorMonitor->VerifyNotFound();
17179}
17180
17181TEST_F(VkPositiveLayerTest, ValidUsage) {
17182 TEST_DESCRIPTION("Verify that creating an image view from an image with valid usage "
17183 "doesn't generate validation errors");
17184
17185 ASSERT_NO_FATAL_FAILURE(InitState());
17186
17187 m_errorMonitor->ExpectSuccess();
17188 // Verify that we can create a view with usage INPUT_ATTACHMENT
17189 VkImageObj image(m_device);
17190 image.init(128, 128, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
17191 ASSERT_TRUE(image.initialized());
17192 VkImageView imageView;
17193 VkImageViewCreateInfo ivci = {};
17194 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
17195 ivci.image = image.handle();
17196 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
17197 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
17198 ivci.subresourceRange.layerCount = 1;
17199 ivci.subresourceRange.baseMipLevel = 0;
17200 ivci.subresourceRange.levelCount = 1;
17201 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
17202
17203 vkCreateImageView(m_device->device(), &ivci, NULL, &imageView);
17204 m_errorMonitor->VerifyNotFound();
17205 vkDestroyImageView(m_device->device(), imageView, NULL);
17206}
17207
17208// This is a positive test. No failures are expected.
17209TEST_F(VkPositiveLayerTest, BindSparse) {
17210 TEST_DESCRIPTION("Bind 2 memory ranges to one image using vkQueueBindSparse, destroy the image"
17211 "and then free the memory");
17212
17213 ASSERT_NO_FATAL_FAILURE(InitState());
17214
17215 auto index = m_device->graphics_queue_node_index_;
17216 if (!(m_device->queue_props[index].queueFlags & VK_QUEUE_SPARSE_BINDING_BIT))
17217 return;
17218
17219 m_errorMonitor->ExpectSuccess();
17220
17221 VkImage image;
17222 VkImageCreateInfo image_create_info = {};
17223 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
17224 image_create_info.pNext = NULL;
17225 image_create_info.imageType = VK_IMAGE_TYPE_2D;
17226 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
17227 image_create_info.extent.width = 64;
17228 image_create_info.extent.height = 64;
17229 image_create_info.extent.depth = 1;
17230 image_create_info.mipLevels = 1;
17231 image_create_info.arrayLayers = 1;
17232 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
17233 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
17234 image_create_info.usage = VK_IMAGE_USAGE_STORAGE_BIT;
17235 image_create_info.flags = VK_IMAGE_CREATE_SPARSE_BINDING_BIT;
17236 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
17237 ASSERT_VK_SUCCESS(err);
17238
17239 VkMemoryRequirements memory_reqs;
17240 VkDeviceMemory memory_one, memory_two;
17241 bool pass;
17242 VkMemoryAllocateInfo memory_info = {};
17243 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17244 memory_info.pNext = NULL;
17245 memory_info.allocationSize = 0;
17246 memory_info.memoryTypeIndex = 0;
17247 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
17248 // Find an image big enough to allow sparse mapping of 2 memory regions
17249 // Increase the image size until it is at least twice the
17250 // size of the required alignment, to ensure we can bind both
17251 // allocated memory blocks to the image on aligned offsets.
17252 while (memory_reqs.size < (memory_reqs.alignment * 2)) {
17253 vkDestroyImage(m_device->device(), image, nullptr);
17254 image_create_info.extent.width *= 2;
17255 image_create_info.extent.height *= 2;
17256 err = vkCreateImage(m_device->device(), &image_create_info, nullptr, &image);
17257 ASSERT_VK_SUCCESS(err);
17258 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
17259 }
17260 // Allocate 2 memory regions of minimum alignment size, bind one at 0, the other
17261 // at the end of the first
17262 memory_info.allocationSize = memory_reqs.alignment;
17263 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
17264 ASSERT_TRUE(pass);
17265 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &memory_one);
17266 ASSERT_VK_SUCCESS(err);
17267 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &memory_two);
17268 ASSERT_VK_SUCCESS(err);
17269 VkSparseMemoryBind binds[2];
17270 binds[0].flags = 0;
17271 binds[0].memory = memory_one;
17272 binds[0].memoryOffset = 0;
17273 binds[0].resourceOffset = 0;
17274 binds[0].size = memory_info.allocationSize;
17275 binds[1].flags = 0;
17276 binds[1].memory = memory_two;
17277 binds[1].memoryOffset = 0;
17278 binds[1].resourceOffset = memory_info.allocationSize;
17279 binds[1].size = memory_info.allocationSize;
17280
17281 VkSparseImageOpaqueMemoryBindInfo opaqueBindInfo;
17282 opaqueBindInfo.image = image;
17283 opaqueBindInfo.bindCount = 2;
17284 opaqueBindInfo.pBinds = binds;
17285
17286 VkFence fence = VK_NULL_HANDLE;
17287 VkBindSparseInfo bindSparseInfo = {};
17288 bindSparseInfo.sType = VK_STRUCTURE_TYPE_BIND_SPARSE_INFO;
17289 bindSparseInfo.imageOpaqueBindCount = 1;
17290 bindSparseInfo.pImageOpaqueBinds = &opaqueBindInfo;
17291
17292 vkQueueBindSparse(m_device->m_queue, 1, &bindSparseInfo, fence);
17293 vkQueueWaitIdle(m_device->m_queue);
17294 vkDestroyImage(m_device->device(), image, NULL);
17295 vkFreeMemory(m_device->device(), memory_one, NULL);
17296 vkFreeMemory(m_device->device(), memory_two, NULL);
17297 m_errorMonitor->VerifyNotFound();
17298}
17299
17300TEST_F(VkPositiveLayerTest, RenderPassInitialLayoutUndefined) {
17301 TEST_DESCRIPTION("Ensure that CmdBeginRenderPass with an attachment's "
17302 "initialLayout of VK_IMAGE_LAYOUT_UNDEFINED works when "
17303 "the command buffer has prior knowledge of that "
17304 "attachment's layout.");
17305
17306 m_errorMonitor->ExpectSuccess();
17307
17308 ASSERT_NO_FATAL_FAILURE(InitState());
17309
17310 // A renderpass with one color attachment.
17311 VkAttachmentDescription attachment = { 0,
17312 VK_FORMAT_R8G8B8A8_UNORM,
17313 VK_SAMPLE_COUNT_1_BIT,
17314 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
17315 VK_ATTACHMENT_STORE_OP_STORE,
17316 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
17317 VK_ATTACHMENT_STORE_OP_DONT_CARE,
17318 VK_IMAGE_LAYOUT_UNDEFINED,
17319 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
17320
17321 VkAttachmentReference att_ref = { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
17322
17323 VkSubpassDescription subpass = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr };
17324
17325 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr };
17326
17327 VkRenderPass rp;
17328 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
17329 ASSERT_VK_SUCCESS(err);
17330
17331 // A compatible framebuffer.
17332 VkImageObj image(m_device);
17333 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
17334 ASSERT_TRUE(image.initialized());
17335
17336 VkImageViewCreateInfo ivci = {
17337 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
17338 nullptr,
17339 0,
17340 image.handle(),
17341 VK_IMAGE_VIEW_TYPE_2D,
17342 VK_FORMAT_R8G8B8A8_UNORM,
17343 { VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
17344 VK_COMPONENT_SWIZZLE_IDENTITY },
17345 { VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 },
17346 };
17347 VkImageView view;
17348 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
17349 ASSERT_VK_SUCCESS(err);
17350
17351 VkFramebufferCreateInfo fci = { VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1 };
17352 VkFramebuffer fb;
17353 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
17354 ASSERT_VK_SUCCESS(err);
17355
17356 // Record a single command buffer which uses this renderpass twice. The
17357 // bug is triggered at the beginning of the second renderpass, when the
17358 // command buffer already has a layout recorded for the attachment.
17359 VkRenderPassBeginInfo rpbi = { VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb,{ { 0, 0 },{ 32, 32 } }, 0, nullptr };
17360 BeginCommandBuffer();
17361 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
17362 vkCmdEndRenderPass(m_commandBuffer->handle());
17363 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
17364
17365 m_errorMonitor->VerifyNotFound();
17366
17367 vkCmdEndRenderPass(m_commandBuffer->handle());
17368 EndCommandBuffer();
17369
17370 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
17371 vkDestroyRenderPass(m_device->device(), rp, nullptr);
17372 vkDestroyImageView(m_device->device(), view, nullptr);
17373}
17374
17375TEST_F(VkPositiveLayerTest, FramebufferBindingDestroyCommandPool) {
17376 TEST_DESCRIPTION("This test should pass. Create a Framebuffer and "
17377 "command buffer, bind them together, then destroy "
17378 "command pool and framebuffer and verify there are no "
17379 "errors.");
17380
17381 m_errorMonitor->ExpectSuccess();
17382
17383 ASSERT_NO_FATAL_FAILURE(InitState());
17384
17385 // A renderpass with one color attachment.
17386 VkAttachmentDescription attachment = { 0,
17387 VK_FORMAT_R8G8B8A8_UNORM,
17388 VK_SAMPLE_COUNT_1_BIT,
17389 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
17390 VK_ATTACHMENT_STORE_OP_STORE,
17391 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
17392 VK_ATTACHMENT_STORE_OP_DONT_CARE,
17393 VK_IMAGE_LAYOUT_UNDEFINED,
17394 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
17395
17396 VkAttachmentReference att_ref = { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
17397
17398 VkSubpassDescription subpass = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr };
17399
17400 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr };
17401
17402 VkRenderPass rp;
17403 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
17404 ASSERT_VK_SUCCESS(err);
17405
17406 // A compatible framebuffer.
17407 VkImageObj image(m_device);
17408 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
17409 ASSERT_TRUE(image.initialized());
17410
17411 VkImageViewCreateInfo ivci = {
17412 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
17413 nullptr,
17414 0,
17415 image.handle(),
17416 VK_IMAGE_VIEW_TYPE_2D,
17417 VK_FORMAT_R8G8B8A8_UNORM,
17418 { VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
17419 VK_COMPONENT_SWIZZLE_IDENTITY },
17420 { VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 },
17421 };
17422 VkImageView view;
17423 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
17424 ASSERT_VK_SUCCESS(err);
17425
17426 VkFramebufferCreateInfo fci = { VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1 };
17427 VkFramebuffer fb;
17428 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
17429 ASSERT_VK_SUCCESS(err);
17430
17431 // Explicitly create a command buffer to bind the FB to so that we can then
17432 // destroy the command pool in order to implicitly free command buffer
17433 VkCommandPool command_pool;
17434 VkCommandPoolCreateInfo pool_create_info{};
17435 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17436 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
17437 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17438 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
17439
17440 VkCommandBuffer command_buffer;
17441 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
17442 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17443 command_buffer_allocate_info.commandPool = command_pool;
17444 command_buffer_allocate_info.commandBufferCount = 1;
17445 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17446 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
17447
17448 // Begin our cmd buffer with renderpass using our framebuffer
17449 VkRenderPassBeginInfo rpbi = { VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb,{ { 0, 0 },{ 32, 32 } }, 0, nullptr };
17450 VkCommandBufferBeginInfo begin_info{};
17451 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17452 vkBeginCommandBuffer(command_buffer, &begin_info);
17453
17454 vkCmdBeginRenderPass(command_buffer, &rpbi, VK_SUBPASS_CONTENTS_INLINE);
17455 vkCmdEndRenderPass(command_buffer);
17456 vkEndCommandBuffer(command_buffer);
17457 vkDestroyImageView(m_device->device(), view, nullptr);
17458 // Destroy command pool to implicitly free command buffer
17459 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
17460 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
17461 vkDestroyRenderPass(m_device->device(), rp, nullptr);
17462 m_errorMonitor->VerifyNotFound();
17463}
17464
17465TEST_F(VkPositiveLayerTest, RenderPassSubpassZeroTransitionsApplied) {
17466 TEST_DESCRIPTION("Ensure that CmdBeginRenderPass applies the layout "
17467 "transitions for the first subpass");
17468
17469 m_errorMonitor->ExpectSuccess();
17470
17471 ASSERT_NO_FATAL_FAILURE(InitState());
17472
17473 // A renderpass with one color attachment.
17474 VkAttachmentDescription attachment = { 0,
17475 VK_FORMAT_R8G8B8A8_UNORM,
17476 VK_SAMPLE_COUNT_1_BIT,
17477 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
17478 VK_ATTACHMENT_STORE_OP_STORE,
17479 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
17480 VK_ATTACHMENT_STORE_OP_DONT_CARE,
17481 VK_IMAGE_LAYOUT_UNDEFINED,
17482 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
17483
17484 VkAttachmentReference att_ref = { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
17485
17486 VkSubpassDescription subpass = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr };
17487
17488 VkSubpassDependency dep = { 0,
17489 0,
17490 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
17491 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
17492 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
17493 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
17494 VK_DEPENDENCY_BY_REGION_BIT };
17495
17496 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 1, &dep };
17497
17498 VkResult err;
17499 VkRenderPass rp;
17500 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
17501 ASSERT_VK_SUCCESS(err);
17502
17503 // A compatible framebuffer.
17504 VkImageObj image(m_device);
17505 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
17506 ASSERT_TRUE(image.initialized());
17507
17508 VkImageViewCreateInfo ivci = {
17509 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
17510 nullptr,
17511 0,
17512 image.handle(),
17513 VK_IMAGE_VIEW_TYPE_2D,
17514 VK_FORMAT_R8G8B8A8_UNORM,
17515 { VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
17516 VK_COMPONENT_SWIZZLE_IDENTITY },
17517 { VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 },
17518 };
17519 VkImageView view;
17520 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
17521 ASSERT_VK_SUCCESS(err);
17522
17523 VkFramebufferCreateInfo fci = { VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1 };
17524 VkFramebuffer fb;
17525 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
17526 ASSERT_VK_SUCCESS(err);
17527
17528 // Record a single command buffer which issues a pipeline barrier w/
17529 // image memory barrier for the attachment. This detects the previously
17530 // missing tracking of the subpass layout by throwing a validation error
17531 // if it doesn't occur.
17532 VkRenderPassBeginInfo rpbi = { VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb,{ { 0, 0 },{ 32, 32 } }, 0, nullptr };
17533 BeginCommandBuffer();
17534 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
17535
17536 VkImageMemoryBarrier imb = { VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,
17537 nullptr,
17538 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
17539 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
17540 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
17541 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
17542 VK_QUEUE_FAMILY_IGNORED,
17543 VK_QUEUE_FAMILY_IGNORED,
17544 image.handle(),
17545 { VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 } };
17546 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
17547 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_DEPENDENCY_BY_REGION_BIT, 0, nullptr, 0, nullptr, 1,
17548 &imb);
17549
17550 vkCmdEndRenderPass(m_commandBuffer->handle());
17551 m_errorMonitor->VerifyNotFound();
17552 EndCommandBuffer();
17553
17554 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
17555 vkDestroyRenderPass(m_device->device(), rp, nullptr);
17556 vkDestroyImageView(m_device->device(), view, nullptr);
17557}
17558
17559TEST_F(VkPositiveLayerTest, DepthStencilLayoutTransitionForDepthOnlyImageview) {
17560 TEST_DESCRIPTION("Validate that when an imageView of a depth/stencil image "
17561 "is used as a depth/stencil framebuffer attachment, the "
17562 "aspectMask is ignored and both depth and stencil image "
17563 "subresources are used.");
17564
17565 VkFormatProperties format_properties;
17566 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_D32_SFLOAT_S8_UINT, &format_properties);
17567 if (!(format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)) {
17568 return;
17569 }
17570
17571 m_errorMonitor->ExpectSuccess();
17572
17573 ASSERT_NO_FATAL_FAILURE(InitState());
17574
17575 VkAttachmentDescription attachment = { 0,
17576 VK_FORMAT_D32_SFLOAT_S8_UINT,
17577 VK_SAMPLE_COUNT_1_BIT,
17578 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
17579 VK_ATTACHMENT_STORE_OP_STORE,
17580 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
17581 VK_ATTACHMENT_STORE_OP_DONT_CARE,
17582 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
17583 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL };
17584
17585 VkAttachmentReference att_ref = { 0, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL };
17586
17587 VkSubpassDescription subpass = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, &att_ref, 0, nullptr };
17588
17589 VkSubpassDependency dep = { 0,
17590 0,
17591 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
17592 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
17593 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
17594 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
17595 VK_DEPENDENCY_BY_REGION_BIT};
17596
17597 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 1, &dep };
17598
17599 VkResult err;
17600 VkRenderPass rp;
17601 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
17602 ASSERT_VK_SUCCESS(err);
17603
17604 VkImageObj image(m_device);
17605 image.init_no_layout(32, 32, VK_FORMAT_D32_SFLOAT_S8_UINT,
17606 0x26, // usage
17607 VK_IMAGE_TILING_OPTIMAL, 0);
17608 ASSERT_TRUE(image.initialized());
17609 image.SetLayout(0x6, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL);
17610
17611 VkImageViewCreateInfo ivci = {
17612 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
17613 nullptr,
17614 0,
17615 image.handle(),
17616 VK_IMAGE_VIEW_TYPE_2D,
17617 VK_FORMAT_D32_SFLOAT_S8_UINT,
17618 { VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A },
17619 { 0x2, 0, 1, 0, 1 },
17620 };
17621 VkImageView view;
17622 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
17623 ASSERT_VK_SUCCESS(err);
17624
17625 VkFramebufferCreateInfo fci = { VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1 };
17626 VkFramebuffer fb;
17627 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
17628 ASSERT_VK_SUCCESS(err);
17629
17630 VkRenderPassBeginInfo rpbi = { VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb,{ { 0, 0 },{ 32, 32 } }, 0, nullptr };
17631 BeginCommandBuffer();
17632 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
17633
17634 VkImageMemoryBarrier imb = {};
17635 imb.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
17636 imb.pNext = nullptr;
17637 imb.srcAccessMask = VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
17638 imb.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
17639 imb.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
17640 imb.newLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
17641 imb.srcQueueFamilyIndex = 0;
17642 imb.dstQueueFamilyIndex = 0;
17643 imb.image = image.handle();
17644 imb.subresourceRange.aspectMask = 0x6;
17645 imb.subresourceRange.baseMipLevel = 0;
17646 imb.subresourceRange.levelCount = 0x1;
17647 imb.subresourceRange.baseArrayLayer = 0;
17648 imb.subresourceRange.layerCount = 0x1;
17649
17650 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
17651 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_DEPENDENCY_BY_REGION_BIT, 0, nullptr, 0, nullptr, 1,
17652 &imb);
17653
17654 vkCmdEndRenderPass(m_commandBuffer->handle());
17655 EndCommandBuffer();
17656 QueueCommandBuffer(false);
17657 m_errorMonitor->VerifyNotFound();
17658
17659 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
17660 vkDestroyRenderPass(m_device->device(), rp, nullptr);
17661 vkDestroyImageView(m_device->device(), view, nullptr);
17662}
17663
17664TEST_F(VkPositiveLayerTest, RenderPassTransitionsAttachmentUnused) {
17665 TEST_DESCRIPTION("Ensure that layout transitions work correctly without "
17666 "errors, when an attachment reference is "
17667 "VK_ATTACHMENT_UNUSED");
17668
17669 m_errorMonitor->ExpectSuccess();
17670
17671 ASSERT_NO_FATAL_FAILURE(InitState());
17672
17673 // A renderpass with no attachments
17674 VkAttachmentReference att_ref = { VK_ATTACHMENT_UNUSED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
17675
17676 VkSubpassDescription subpass = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr };
17677
17678 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 1, &subpass, 0, nullptr };
17679
17680 VkRenderPass rp;
17681 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
17682 ASSERT_VK_SUCCESS(err);
17683
17684 // A compatible framebuffer.
17685 VkFramebufferCreateInfo fci = { VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 0, nullptr, 32, 32, 1 };
17686 VkFramebuffer fb;
17687 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
17688 ASSERT_VK_SUCCESS(err);
17689
17690 // Record a command buffer which just begins and ends the renderpass. The
17691 // bug manifests in BeginRenderPass.
17692 VkRenderPassBeginInfo rpbi = { VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb,{ { 0, 0 },{ 32, 32 } }, 0, nullptr };
17693 BeginCommandBuffer();
17694 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
17695 vkCmdEndRenderPass(m_commandBuffer->handle());
17696 m_errorMonitor->VerifyNotFound();
17697 EndCommandBuffer();
17698
17699 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
17700 vkDestroyRenderPass(m_device->device(), rp, nullptr);
17701}
17702
17703// This is a positive test. No errors are expected.
17704TEST_F(VkPositiveLayerTest, StencilLoadOp) {
17705 TEST_DESCRIPTION("Create a stencil-only attachment with a LOAD_OP set to "
17706 "CLEAR. stencil[Load|Store]Op used to be ignored.");
17707 VkResult result = VK_SUCCESS;
17708 VkImageFormatProperties formatProps;
17709 vkGetPhysicalDeviceImageFormatProperties(gpu(), VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
17710 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT, 0,
17711 &formatProps);
17712 if (formatProps.maxExtent.width < 100 || formatProps.maxExtent.height < 100) {
17713 return;
17714 }
17715
17716 ASSERT_NO_FATAL_FAILURE(InitState());
17717 VkFormat depth_stencil_fmt = VK_FORMAT_D24_UNORM_S8_UINT;
17718 m_depthStencil->Init(m_device, 100, 100, depth_stencil_fmt,
17719 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT);
17720 VkAttachmentDescription att = {};
17721 VkAttachmentReference ref = {};
17722 att.format = depth_stencil_fmt;
17723 att.samples = VK_SAMPLE_COUNT_1_BIT;
17724 att.loadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
17725 att.storeOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
17726 att.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
17727 att.stencilStoreOp = VK_ATTACHMENT_STORE_OP_STORE;
17728 att.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
17729 att.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
17730
17731 VkClearValue clear;
17732 clear.depthStencil.depth = 1.0;
17733 clear.depthStencil.stencil = 0;
17734 ref.attachment = 0;
17735 ref.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
17736
17737 VkSubpassDescription subpass = {};
17738 subpass.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;
17739 subpass.flags = 0;
17740 subpass.inputAttachmentCount = 0;
17741 subpass.pInputAttachments = NULL;
17742 subpass.colorAttachmentCount = 0;
17743 subpass.pColorAttachments = NULL;
17744 subpass.pResolveAttachments = NULL;
17745 subpass.pDepthStencilAttachment = &ref;
17746 subpass.preserveAttachmentCount = 0;
17747 subpass.pPreserveAttachments = NULL;
17748
17749 VkRenderPass rp;
17750 VkRenderPassCreateInfo rp_info = {};
17751 rp_info.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
17752 rp_info.attachmentCount = 1;
17753 rp_info.pAttachments = &att;
17754 rp_info.subpassCount = 1;
17755 rp_info.pSubpasses = &subpass;
17756 result = vkCreateRenderPass(device(), &rp_info, NULL, &rp);
17757 ASSERT_VK_SUCCESS(result);
17758
17759 VkImageView *depthView = m_depthStencil->BindInfo();
17760 VkFramebufferCreateInfo fb_info = {};
17761 fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
17762 fb_info.pNext = NULL;
17763 fb_info.renderPass = rp;
17764 fb_info.attachmentCount = 1;
17765 fb_info.pAttachments = depthView;
17766 fb_info.width = 100;
17767 fb_info.height = 100;
17768 fb_info.layers = 1;
17769 VkFramebuffer fb;
17770 result = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
17771 ASSERT_VK_SUCCESS(result);
17772
17773 VkRenderPassBeginInfo rpbinfo = {};
17774 rpbinfo.clearValueCount = 1;
17775 rpbinfo.pClearValues = &clear;
17776 rpbinfo.pNext = NULL;
17777 rpbinfo.renderPass = rp;
17778 rpbinfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
17779 rpbinfo.renderArea.extent.width = 100;
17780 rpbinfo.renderArea.extent.height = 100;
17781 rpbinfo.renderArea.offset.x = 0;
17782 rpbinfo.renderArea.offset.y = 0;
17783 rpbinfo.framebuffer = fb;
17784
17785 VkFence fence = {};
17786 VkFenceCreateInfo fence_ci = {};
17787 fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
17788 fence_ci.pNext = nullptr;
17789 fence_ci.flags = 0;
17790 result = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fence);
17791 ASSERT_VK_SUCCESS(result);
17792
17793 m_commandBuffer->BeginCommandBuffer();
17794 m_commandBuffer->BeginRenderPass(rpbinfo);
17795 m_commandBuffer->EndRenderPass();
17796 m_commandBuffer->EndCommandBuffer();
17797 m_commandBuffer->QueueCommandBuffer(fence);
17798
17799 VkImageObj destImage(m_device);
17800 destImage.init(100, 100, depth_stencil_fmt, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
17801 VK_IMAGE_TILING_OPTIMAL, 0);
17802 VkImageMemoryBarrier barrier = {};
17803 VkImageSubresourceRange range;
17804 barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
17805 barrier.srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
17806 barrier.dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT;
17807 barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
17808 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
17809 barrier.image = m_depthStencil->handle();
17810 range.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
17811 range.baseMipLevel = 0;
17812 range.levelCount = 1;
17813 range.baseArrayLayer = 0;
17814 range.layerCount = 1;
17815 barrier.subresourceRange = range;
17816 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
17817 VkCommandBufferObj cmdbuf(m_device, m_commandPool);
17818 cmdbuf.BeginCommandBuffer();
17819 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
17820 &barrier);
17821 barrier.srcAccessMask = 0;
17822 barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
17823 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
17824 barrier.image = destImage.handle();
17825 barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
17826 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
17827 &barrier);
17828 VkImageCopy cregion;
17829 cregion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
17830 cregion.srcSubresource.mipLevel = 0;
17831 cregion.srcSubresource.baseArrayLayer = 0;
17832 cregion.srcSubresource.layerCount = 1;
17833 cregion.srcOffset.x = 0;
17834 cregion.srcOffset.y = 0;
17835 cregion.srcOffset.z = 0;
17836 cregion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
17837 cregion.dstSubresource.mipLevel = 0;
17838 cregion.dstSubresource.baseArrayLayer = 0;
17839 cregion.dstSubresource.layerCount = 1;
17840 cregion.dstOffset.x = 0;
17841 cregion.dstOffset.y = 0;
17842 cregion.dstOffset.z = 0;
17843 cregion.extent.width = 100;
17844 cregion.extent.height = 100;
17845 cregion.extent.depth = 1;
17846 cmdbuf.CopyImage(m_depthStencil->handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, destImage.handle(),
17847 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &cregion);
17848 cmdbuf.EndCommandBuffer();
17849
17850 VkSubmitInfo submit_info;
17851 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17852 submit_info.pNext = NULL;
17853 submit_info.waitSemaphoreCount = 0;
17854 submit_info.pWaitSemaphores = NULL;
17855 submit_info.pWaitDstStageMask = NULL;
17856 submit_info.commandBufferCount = 1;
17857 submit_info.pCommandBuffers = &cmdbuf.handle();
17858 submit_info.signalSemaphoreCount = 0;
17859 submit_info.pSignalSemaphores = NULL;
17860
17861 m_errorMonitor->ExpectSuccess();
17862 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
17863 m_errorMonitor->VerifyNotFound();
17864
17865 vkQueueWaitIdle(m_device->m_queue);
17866 vkDestroyFence(m_device->device(), fence, nullptr);
17867 vkDestroyRenderPass(m_device->device(), rp, nullptr);
17868 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
17869}
17870
17871// This is a positive test. No errors should be generated.
17872TEST_F(VkPositiveLayerTest, WaitEventThenSet) {
17873 TEST_DESCRIPTION("Wait on a event then set it after the wait has been submitted.");
17874
17875 m_errorMonitor->ExpectSuccess();
17876 ASSERT_NO_FATAL_FAILURE(InitState());
17877
17878 VkEvent event;
17879 VkEventCreateInfo event_create_info{};
17880 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
17881 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
17882
17883 VkCommandPool command_pool;
17884 VkCommandPoolCreateInfo pool_create_info{};
17885 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17886 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
17887 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17888 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
17889
17890 VkCommandBuffer command_buffer;
17891 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
17892 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17893 command_buffer_allocate_info.commandPool = command_pool;
17894 command_buffer_allocate_info.commandBufferCount = 1;
17895 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17896 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
17897
17898 VkQueue queue = VK_NULL_HANDLE;
17899 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
17900
17901 {
17902 VkCommandBufferBeginInfo begin_info{};
17903 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17904 vkBeginCommandBuffer(command_buffer, &begin_info);
17905
17906 vkCmdWaitEvents(command_buffer, 1, &event, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, nullptr, 0,
17907 nullptr, 0, nullptr);
17908 vkCmdResetEvent(command_buffer, event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
17909 vkEndCommandBuffer(command_buffer);
17910 }
17911 {
17912 VkSubmitInfo submit_info{};
17913 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17914 submit_info.commandBufferCount = 1;
17915 submit_info.pCommandBuffers = &command_buffer;
17916 submit_info.signalSemaphoreCount = 0;
17917 submit_info.pSignalSemaphores = nullptr;
17918 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
17919 }
17920 { vkSetEvent(m_device->device(), event); }
17921
17922 vkQueueWaitIdle(queue);
17923
17924 vkDestroyEvent(m_device->device(), event, nullptr);
17925 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
17926 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
17927
17928 m_errorMonitor->VerifyNotFound();
17929}
17930// This is a positive test. No errors should be generated.
17931TEST_F(VkPositiveLayerTest, QueryAndCopySecondaryCommandBuffers) {
17932 TEST_DESCRIPTION("Issue a query on a secondary command buffery and copy it on a primary.");
17933
17934 ASSERT_NO_FATAL_FAILURE(InitState());
17935 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
17936 return;
17937
17938 m_errorMonitor->ExpectSuccess();
17939
17940 VkQueryPool query_pool;
17941 VkQueryPoolCreateInfo query_pool_create_info{};
17942 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
17943 query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP;
17944 query_pool_create_info.queryCount = 1;
17945 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
17946
17947 VkCommandPool command_pool;
17948 VkCommandPoolCreateInfo pool_create_info{};
17949 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17950 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
17951 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17952 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
17953
17954 VkCommandBuffer command_buffer;
17955 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
17956 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17957 command_buffer_allocate_info.commandPool = command_pool;
17958 command_buffer_allocate_info.commandBufferCount = 1;
17959 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17960 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
17961
17962 VkCommandBuffer secondary_command_buffer;
17963 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
17964 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer);
17965
17966 VkQueue queue = VK_NULL_HANDLE;
17967 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
17968
17969 uint32_t qfi = 0;
17970 VkBufferCreateInfo buff_create_info = {};
17971 buff_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
17972 buff_create_info.size = 1024;
17973 buff_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
17974 buff_create_info.queueFamilyIndexCount = 1;
17975 buff_create_info.pQueueFamilyIndices = &qfi;
17976
17977 VkResult err;
17978 VkBuffer buffer;
17979 err = vkCreateBuffer(m_device->device(), &buff_create_info, NULL, &buffer);
17980 ASSERT_VK_SUCCESS(err);
17981 VkMemoryAllocateInfo mem_alloc = {};
17982 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17983 mem_alloc.pNext = NULL;
17984 mem_alloc.allocationSize = 1024;
17985 mem_alloc.memoryTypeIndex = 0;
17986
17987 VkMemoryRequirements memReqs;
17988 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
17989 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
17990 if (!pass) {
17991 vkDestroyBuffer(m_device->device(), buffer, NULL);
17992 return;
17993 }
17994
17995 VkDeviceMemory mem;
17996 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
17997 ASSERT_VK_SUCCESS(err);
17998 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
17999 ASSERT_VK_SUCCESS(err);
18000
18001 VkCommandBufferInheritanceInfo hinfo = {};
18002 hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
18003 hinfo.renderPass = VK_NULL_HANDLE;
18004 hinfo.subpass = 0;
18005 hinfo.framebuffer = VK_NULL_HANDLE;
18006 hinfo.occlusionQueryEnable = VK_FALSE;
18007 hinfo.queryFlags = 0;
18008 hinfo.pipelineStatistics = 0;
18009
18010 {
18011 VkCommandBufferBeginInfo begin_info{};
18012 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18013 begin_info.pInheritanceInfo = &hinfo;
18014 vkBeginCommandBuffer(secondary_command_buffer, &begin_info);
18015
18016 vkCmdResetQueryPool(secondary_command_buffer, query_pool, 0, 1);
18017 vkCmdWriteTimestamp(secondary_command_buffer, VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0);
18018
18019 vkEndCommandBuffer(secondary_command_buffer);
18020
18021 begin_info.pInheritanceInfo = nullptr;
18022 vkBeginCommandBuffer(command_buffer, &begin_info);
18023
18024 vkCmdExecuteCommands(command_buffer, 1, &secondary_command_buffer);
18025 vkCmdCopyQueryPoolResults(command_buffer, query_pool, 0, 1, buffer, 0, 0, 0);
18026
18027 vkEndCommandBuffer(command_buffer);
18028 }
18029 {
18030 VkSubmitInfo submit_info{};
18031 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18032 submit_info.commandBufferCount = 1;
18033 submit_info.pCommandBuffers = &command_buffer;
18034 submit_info.signalSemaphoreCount = 0;
18035 submit_info.pSignalSemaphores = nullptr;
18036 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
18037 }
18038
18039 vkQueueWaitIdle(queue);
18040
18041 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
18042 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
18043 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &secondary_command_buffer);
18044 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18045 vkDestroyBuffer(m_device->device(), buffer, NULL);
18046 vkFreeMemory(m_device->device(), mem, NULL);
18047
18048 m_errorMonitor->VerifyNotFound();
18049}
18050
18051// This is a positive test. No errors should be generated.
18052TEST_F(VkPositiveLayerTest, QueryAndCopyMultipleCommandBuffers) {
18053 TEST_DESCRIPTION("Issue a query and copy from it on a second command buffer.");
18054
18055 ASSERT_NO_FATAL_FAILURE(InitState());
18056 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
18057 return;
18058
18059 m_errorMonitor->ExpectSuccess();
18060
18061 VkQueryPool query_pool;
18062 VkQueryPoolCreateInfo query_pool_create_info{};
18063 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
18064 query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP;
18065 query_pool_create_info.queryCount = 1;
18066 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
18067
18068 VkCommandPool command_pool;
18069 VkCommandPoolCreateInfo pool_create_info{};
18070 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18071 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18072 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18073 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18074
18075 VkCommandBuffer command_buffer[2];
18076 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18077 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18078 command_buffer_allocate_info.commandPool = command_pool;
18079 command_buffer_allocate_info.commandBufferCount = 2;
18080 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18081 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18082
18083 VkQueue queue = VK_NULL_HANDLE;
18084 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
18085
18086 uint32_t qfi = 0;
18087 VkBufferCreateInfo buff_create_info = {};
18088 buff_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
18089 buff_create_info.size = 1024;
18090 buff_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
18091 buff_create_info.queueFamilyIndexCount = 1;
18092 buff_create_info.pQueueFamilyIndices = &qfi;
18093
18094 VkResult err;
18095 VkBuffer buffer;
18096 err = vkCreateBuffer(m_device->device(), &buff_create_info, NULL, &buffer);
18097 ASSERT_VK_SUCCESS(err);
18098 VkMemoryAllocateInfo mem_alloc = {};
18099 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18100 mem_alloc.pNext = NULL;
18101 mem_alloc.allocationSize = 1024;
18102 mem_alloc.memoryTypeIndex = 0;
18103
18104 VkMemoryRequirements memReqs;
18105 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
18106 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
18107 if (!pass) {
18108 vkDestroyBuffer(m_device->device(), buffer, NULL);
18109 return;
18110 }
18111
18112 VkDeviceMemory mem;
18113 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
18114 ASSERT_VK_SUCCESS(err);
18115 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
18116 ASSERT_VK_SUCCESS(err);
18117
18118 {
18119 VkCommandBufferBeginInfo begin_info{};
18120 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18121 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18122
18123 vkCmdResetQueryPool(command_buffer[0], query_pool, 0, 1);
18124 vkCmdWriteTimestamp(command_buffer[0], VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0);
18125
18126 vkEndCommandBuffer(command_buffer[0]);
18127
18128 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18129
18130 vkCmdCopyQueryPoolResults(command_buffer[1], query_pool, 0, 1, buffer, 0, 0, 0);
18131
18132 vkEndCommandBuffer(command_buffer[1]);
18133 }
18134 {
18135 VkSubmitInfo submit_info{};
18136 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18137 submit_info.commandBufferCount = 2;
18138 submit_info.pCommandBuffers = command_buffer;
18139 submit_info.signalSemaphoreCount = 0;
18140 submit_info.pSignalSemaphores = nullptr;
18141 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
18142 }
18143
18144 vkQueueWaitIdle(queue);
18145
18146 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
18147 vkFreeCommandBuffers(m_device->device(), command_pool, 2, command_buffer);
18148 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18149 vkDestroyBuffer(m_device->device(), buffer, NULL);
18150 vkFreeMemory(m_device->device(), mem, NULL);
18151
18152 m_errorMonitor->VerifyNotFound();
18153}
18154
Tony Barbourc46924f2016-11-04 11:49:52 -060018155TEST_F(VkLayerTest, ResetEventThenSet) {
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018156 TEST_DESCRIPTION("Reset an event then set it after the reset has been submitted.");
18157
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018158 ASSERT_NO_FATAL_FAILURE(InitState());
18159 VkEvent event;
18160 VkEventCreateInfo event_create_info{};
18161 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
18162 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
18163
18164 VkCommandPool command_pool;
18165 VkCommandPoolCreateInfo pool_create_info{};
18166 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18167 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18168 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18169 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18170
18171 VkCommandBuffer command_buffer;
18172 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18173 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18174 command_buffer_allocate_info.commandPool = command_pool;
18175 command_buffer_allocate_info.commandBufferCount = 1;
18176 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18177 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
18178
18179 VkQueue queue = VK_NULL_HANDLE;
18180 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
18181
18182 {
18183 VkCommandBufferBeginInfo begin_info{};
18184 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18185 vkBeginCommandBuffer(command_buffer, &begin_info);
18186
18187 vkCmdResetEvent(command_buffer, event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018188 vkEndCommandBuffer(command_buffer);
18189 }
18190 {
18191 VkSubmitInfo submit_info{};
18192 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18193 submit_info.commandBufferCount = 1;
18194 submit_info.pCommandBuffers = &command_buffer;
18195 submit_info.signalSemaphoreCount = 0;
18196 submit_info.pSignalSemaphores = nullptr;
18197 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
18198 }
18199 {
18200 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is already in use by a "
18201 "command buffer.");
18202 vkSetEvent(m_device->device(), event);
18203 m_errorMonitor->VerifyFound();
18204 }
18205
18206 vkQueueWaitIdle(queue);
18207
18208 vkDestroyEvent(m_device->device(), event, nullptr);
18209 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
18210 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18211}
18212
18213// This is a positive test. No errors should be generated.
18214TEST_F(VkPositiveLayerTest, TwoFencesThreeFrames) {
18215 TEST_DESCRIPTION("Two command buffers with two separate fences are each "
18216 "run through a Submit & WaitForFences cycle 3 times. This "
18217 "previously revealed a bug so running this positive test "
18218 "to prevent a regression.");
18219 m_errorMonitor->ExpectSuccess();
18220
18221 ASSERT_NO_FATAL_FAILURE(InitState());
18222 VkQueue queue = VK_NULL_HANDLE;
18223 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
18224
18225 static const uint32_t NUM_OBJECTS = 2;
18226 static const uint32_t NUM_FRAMES = 3;
18227 VkCommandBuffer cmd_buffers[NUM_OBJECTS] = {};
18228 VkFence fences[NUM_OBJECTS] = {};
18229
18230 VkCommandPool cmd_pool;
18231 VkCommandPoolCreateInfo cmd_pool_ci = {};
18232 cmd_pool_ci.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18233 cmd_pool_ci.queueFamilyIndex = m_device->graphics_queue_node_index_;
18234 cmd_pool_ci.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18235 VkResult err = vkCreateCommandPool(m_device->device(), &cmd_pool_ci, nullptr, &cmd_pool);
18236 ASSERT_VK_SUCCESS(err);
18237
18238 VkCommandBufferAllocateInfo cmd_buf_info = {};
18239 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18240 cmd_buf_info.commandPool = cmd_pool;
18241 cmd_buf_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18242 cmd_buf_info.commandBufferCount = 1;
18243
18244 VkFenceCreateInfo fence_ci = {};
18245 fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18246 fence_ci.pNext = nullptr;
18247 fence_ci.flags = 0;
18248
18249 for (uint32_t i = 0; i < NUM_OBJECTS; ++i) {
18250 err = vkAllocateCommandBuffers(m_device->device(), &cmd_buf_info, &cmd_buffers[i]);
18251 ASSERT_VK_SUCCESS(err);
18252 err = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fences[i]);
18253 ASSERT_VK_SUCCESS(err);
18254 }
18255
18256 for (uint32_t frame = 0; frame < NUM_FRAMES; ++frame) {
18257 for (uint32_t obj = 0; obj < NUM_OBJECTS; ++obj) {
18258 // Create empty cmd buffer
18259 VkCommandBufferBeginInfo cmdBufBeginDesc = {};
18260 cmdBufBeginDesc.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18261
18262 err = vkBeginCommandBuffer(cmd_buffers[obj], &cmdBufBeginDesc);
18263 ASSERT_VK_SUCCESS(err);
18264 err = vkEndCommandBuffer(cmd_buffers[obj]);
18265 ASSERT_VK_SUCCESS(err);
18266
18267 VkSubmitInfo submit_info = {};
18268 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18269 submit_info.commandBufferCount = 1;
18270 submit_info.pCommandBuffers = &cmd_buffers[obj];
18271 // Submit cmd buffer and wait for fence
18272 err = vkQueueSubmit(queue, 1, &submit_info, fences[obj]);
18273 ASSERT_VK_SUCCESS(err);
18274 err = vkWaitForFences(m_device->device(), 1, &fences[obj], VK_TRUE, UINT64_MAX);
18275 ASSERT_VK_SUCCESS(err);
18276 err = vkResetFences(m_device->device(), 1, &fences[obj]);
18277 ASSERT_VK_SUCCESS(err);
18278 }
18279 }
18280 m_errorMonitor->VerifyNotFound();
18281 vkDestroyCommandPool(m_device->device(), cmd_pool, NULL);
18282 for (uint32_t i = 0; i < NUM_OBJECTS; ++i) {
18283 vkDestroyFence(m_device->device(), fences[i], nullptr);
18284 }
18285}
18286// This is a positive test. No errors should be generated.
18287TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWI) {
18288
18289 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
18290 "submitted on separate queues followed by a QueueWaitIdle.");
18291
18292 ASSERT_NO_FATAL_FAILURE(InitState());
18293 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
18294 return;
18295
18296 m_errorMonitor->ExpectSuccess();
18297
18298 VkSemaphore semaphore;
18299 VkSemaphoreCreateInfo semaphore_create_info{};
18300 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
18301 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
18302
18303 VkCommandPool command_pool;
18304 VkCommandPoolCreateInfo pool_create_info{};
18305 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18306 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18307 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18308 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18309
18310 VkCommandBuffer command_buffer[2];
18311 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18312 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18313 command_buffer_allocate_info.commandPool = command_pool;
18314 command_buffer_allocate_info.commandBufferCount = 2;
18315 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18316 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18317
18318 VkQueue queue = VK_NULL_HANDLE;
18319 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
18320
18321 {
18322 VkCommandBufferBeginInfo begin_info{};
18323 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18324 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18325
18326 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
18327 nullptr, 0, nullptr, 0, nullptr);
18328
18329 VkViewport viewport{};
18330 viewport.maxDepth = 1.0f;
18331 viewport.minDepth = 0.0f;
18332 viewport.width = 512;
18333 viewport.height = 512;
18334 viewport.x = 0;
18335 viewport.y = 0;
18336 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
18337 vkEndCommandBuffer(command_buffer[0]);
18338 }
18339 {
18340 VkCommandBufferBeginInfo begin_info{};
18341 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18342 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18343
18344 VkViewport viewport{};
18345 viewport.maxDepth = 1.0f;
18346 viewport.minDepth = 0.0f;
18347 viewport.width = 512;
18348 viewport.height = 512;
18349 viewport.x = 0;
18350 viewport.y = 0;
18351 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
18352 vkEndCommandBuffer(command_buffer[1]);
18353 }
18354 {
18355 VkSubmitInfo submit_info{};
18356 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18357 submit_info.commandBufferCount = 1;
18358 submit_info.pCommandBuffers = &command_buffer[0];
18359 submit_info.signalSemaphoreCount = 1;
18360 submit_info.pSignalSemaphores = &semaphore;
18361 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
18362 }
18363 {
18364 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
18365 VkSubmitInfo submit_info{};
18366 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18367 submit_info.commandBufferCount = 1;
18368 submit_info.pCommandBuffers = &command_buffer[1];
18369 submit_info.waitSemaphoreCount = 1;
18370 submit_info.pWaitSemaphores = &semaphore;
18371 submit_info.pWaitDstStageMask = flags;
18372 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
18373 }
18374
18375 vkQueueWaitIdle(m_device->m_queue);
18376
18377 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
18378 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
18379 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18380
18381 m_errorMonitor->VerifyNotFound();
18382}
18383
18384// This is a positive test. No errors should be generated.
18385TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWIFence) {
18386
18387 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
18388 "submitted on separate queues, the second having a fence"
18389 "followed by a QueueWaitIdle.");
18390
18391 ASSERT_NO_FATAL_FAILURE(InitState());
18392 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
18393 return;
18394
18395 m_errorMonitor->ExpectSuccess();
18396
18397 VkFence fence;
18398 VkFenceCreateInfo fence_create_info{};
18399 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18400 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
18401
18402 VkSemaphore semaphore;
18403 VkSemaphoreCreateInfo semaphore_create_info{};
18404 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
18405 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
18406
18407 VkCommandPool command_pool;
18408 VkCommandPoolCreateInfo pool_create_info{};
18409 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18410 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18411 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18412 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18413
18414 VkCommandBuffer command_buffer[2];
18415 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18416 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18417 command_buffer_allocate_info.commandPool = command_pool;
18418 command_buffer_allocate_info.commandBufferCount = 2;
18419 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18420 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18421
18422 VkQueue queue = VK_NULL_HANDLE;
18423 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
18424
18425 {
18426 VkCommandBufferBeginInfo begin_info{};
18427 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18428 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18429
18430 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
18431 nullptr, 0, nullptr, 0, nullptr);
18432
18433 VkViewport viewport{};
18434 viewport.maxDepth = 1.0f;
18435 viewport.minDepth = 0.0f;
18436 viewport.width = 512;
18437 viewport.height = 512;
18438 viewport.x = 0;
18439 viewport.y = 0;
18440 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
18441 vkEndCommandBuffer(command_buffer[0]);
18442 }
18443 {
18444 VkCommandBufferBeginInfo begin_info{};
18445 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18446 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18447
18448 VkViewport viewport{};
18449 viewport.maxDepth = 1.0f;
18450 viewport.minDepth = 0.0f;
18451 viewport.width = 512;
18452 viewport.height = 512;
18453 viewport.x = 0;
18454 viewport.y = 0;
18455 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
18456 vkEndCommandBuffer(command_buffer[1]);
18457 }
18458 {
18459 VkSubmitInfo submit_info{};
18460 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18461 submit_info.commandBufferCount = 1;
18462 submit_info.pCommandBuffers = &command_buffer[0];
18463 submit_info.signalSemaphoreCount = 1;
18464 submit_info.pSignalSemaphores = &semaphore;
18465 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
18466 }
18467 {
18468 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
18469 VkSubmitInfo submit_info{};
18470 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18471 submit_info.commandBufferCount = 1;
18472 submit_info.pCommandBuffers = &command_buffer[1];
18473 submit_info.waitSemaphoreCount = 1;
18474 submit_info.pWaitSemaphores = &semaphore;
18475 submit_info.pWaitDstStageMask = flags;
18476 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
18477 }
18478
18479 vkQueueWaitIdle(m_device->m_queue);
18480
18481 vkDestroyFence(m_device->device(), fence, nullptr);
18482 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
18483 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
18484 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18485
18486 m_errorMonitor->VerifyNotFound();
18487}
18488
18489// This is a positive test. No errors should be generated.
18490TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceTwoWFF) {
18491
18492 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
18493 "submitted on separate queues, the second having a fence"
18494 "followed by two consecutive WaitForFences calls on the same fence.");
18495
18496 ASSERT_NO_FATAL_FAILURE(InitState());
18497 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
18498 return;
18499
18500 m_errorMonitor->ExpectSuccess();
18501
18502 VkFence fence;
18503 VkFenceCreateInfo fence_create_info{};
18504 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18505 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
18506
18507 VkSemaphore semaphore;
18508 VkSemaphoreCreateInfo semaphore_create_info{};
18509 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
18510 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
18511
18512 VkCommandPool command_pool;
18513 VkCommandPoolCreateInfo pool_create_info{};
18514 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18515 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18516 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18517 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18518
18519 VkCommandBuffer command_buffer[2];
18520 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18521 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18522 command_buffer_allocate_info.commandPool = command_pool;
18523 command_buffer_allocate_info.commandBufferCount = 2;
18524 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18525 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18526
18527 VkQueue queue = VK_NULL_HANDLE;
18528 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
18529
18530 {
18531 VkCommandBufferBeginInfo begin_info{};
18532 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18533 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18534
18535 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
18536 nullptr, 0, nullptr, 0, nullptr);
18537
18538 VkViewport viewport{};
18539 viewport.maxDepth = 1.0f;
18540 viewport.minDepth = 0.0f;
18541 viewport.width = 512;
18542 viewport.height = 512;
18543 viewport.x = 0;
18544 viewport.y = 0;
18545 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
18546 vkEndCommandBuffer(command_buffer[0]);
18547 }
18548 {
18549 VkCommandBufferBeginInfo begin_info{};
18550 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18551 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18552
18553 VkViewport viewport{};
18554 viewport.maxDepth = 1.0f;
18555 viewport.minDepth = 0.0f;
18556 viewport.width = 512;
18557 viewport.height = 512;
18558 viewport.x = 0;
18559 viewport.y = 0;
18560 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
18561 vkEndCommandBuffer(command_buffer[1]);
18562 }
18563 {
18564 VkSubmitInfo submit_info{};
18565 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18566 submit_info.commandBufferCount = 1;
18567 submit_info.pCommandBuffers = &command_buffer[0];
18568 submit_info.signalSemaphoreCount = 1;
18569 submit_info.pSignalSemaphores = &semaphore;
18570 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
18571 }
18572 {
18573 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
18574 VkSubmitInfo submit_info{};
18575 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18576 submit_info.commandBufferCount = 1;
18577 submit_info.pCommandBuffers = &command_buffer[1];
18578 submit_info.waitSemaphoreCount = 1;
18579 submit_info.pWaitSemaphores = &semaphore;
18580 submit_info.pWaitDstStageMask = flags;
18581 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
18582 }
18583
18584 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
18585 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
18586
18587 vkDestroyFence(m_device->device(), fence, nullptr);
18588 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
18589 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
18590 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18591
18592 m_errorMonitor->VerifyNotFound();
18593}
18594
18595TEST_F(VkPositiveLayerTest, TwoQueuesEnsureCorrectRetirementWithWorkStolen) {
18596
18597 ASSERT_NO_FATAL_FAILURE(InitState());
18598 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) {
18599 printf("Test requires two queues, skipping\n");
18600 return;
18601 }
18602
18603 VkResult err;
18604
18605 m_errorMonitor->ExpectSuccess();
18606
18607 VkQueue q0 = m_device->m_queue;
18608 VkQueue q1 = nullptr;
18609 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &q1);
18610 ASSERT_NE(q1, nullptr);
18611
18612 // An (empty) command buffer. We must have work in the first submission --
18613 // the layer treats unfenced work differently from fenced work.
18614 VkCommandPoolCreateInfo cpci = { VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, nullptr, 0, 0 };
18615 VkCommandPool pool;
18616 err = vkCreateCommandPool(m_device->device(), &cpci, nullptr, &pool);
18617 ASSERT_VK_SUCCESS(err);
18618 VkCommandBufferAllocateInfo cbai = { VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, nullptr, pool,
18619 VK_COMMAND_BUFFER_LEVEL_PRIMARY, 1 };
18620 VkCommandBuffer cb;
18621 err = vkAllocateCommandBuffers(m_device->device(), &cbai, &cb);
18622 ASSERT_VK_SUCCESS(err);
18623 VkCommandBufferBeginInfo cbbi = { VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr, 0, nullptr };
18624 err = vkBeginCommandBuffer(cb, &cbbi);
18625 ASSERT_VK_SUCCESS(err);
18626 err = vkEndCommandBuffer(cb);
18627 ASSERT_VK_SUCCESS(err);
18628
18629 // A semaphore
18630 VkSemaphoreCreateInfo sci = { VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0 };
18631 VkSemaphore s;
18632 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s);
18633 ASSERT_VK_SUCCESS(err);
18634
18635 // First submission, to q0
18636 VkSubmitInfo s0 = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 1, &cb, 1, &s };
18637
18638 err = vkQueueSubmit(q0, 1, &s0, VK_NULL_HANDLE);
18639 ASSERT_VK_SUCCESS(err);
18640
18641 // Second submission, to q1, waiting on s
18642 VkFlags waitmask = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT; // doesn't really matter what this value is.
18643 VkSubmitInfo s1 = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 1, &s, &waitmask, 0, nullptr, 0, nullptr };
18644
18645 err = vkQueueSubmit(q1, 1, &s1, VK_NULL_HANDLE);
18646 ASSERT_VK_SUCCESS(err);
18647
18648 // Wait for q0 idle
18649 err = vkQueueWaitIdle(q0);
18650 ASSERT_VK_SUCCESS(err);
18651
18652 // Command buffer should have been completed (it was on q0); reset the pool.
18653 vkFreeCommandBuffers(m_device->device(), pool, 1, &cb);
18654
18655 m_errorMonitor->VerifyNotFound();
18656
18657 // Force device completely idle and clean up resources
18658 vkDeviceWaitIdle(m_device->device());
18659 vkDestroyCommandPool(m_device->device(), pool, nullptr);
18660 vkDestroySemaphore(m_device->device(), s, nullptr);
18661}
18662
18663// This is a positive test. No errors should be generated.
18664TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFence) {
18665
18666 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
18667 "submitted on separate queues, the second having a fence, "
18668 "followed by a WaitForFences call.");
18669
18670 ASSERT_NO_FATAL_FAILURE(InitState());
18671 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
18672 return;
18673
18674 m_errorMonitor->ExpectSuccess();
18675
18676 ASSERT_NO_FATAL_FAILURE(InitState());
18677 VkFence fence;
18678 VkFenceCreateInfo fence_create_info{};
18679 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18680 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
18681
18682 VkSemaphore semaphore;
18683 VkSemaphoreCreateInfo semaphore_create_info{};
18684 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
18685 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
18686
18687 VkCommandPool command_pool;
18688 VkCommandPoolCreateInfo pool_create_info{};
18689 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18690 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18691 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18692 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18693
18694 VkCommandBuffer command_buffer[2];
18695 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18696 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18697 command_buffer_allocate_info.commandPool = command_pool;
18698 command_buffer_allocate_info.commandBufferCount = 2;
18699 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18700 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18701
18702 VkQueue queue = VK_NULL_HANDLE;
18703 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
18704
18705 {
18706 VkCommandBufferBeginInfo begin_info{};
18707 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18708 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18709
18710 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
18711 nullptr, 0, nullptr, 0, nullptr);
18712
18713 VkViewport viewport{};
18714 viewport.maxDepth = 1.0f;
18715 viewport.minDepth = 0.0f;
18716 viewport.width = 512;
18717 viewport.height = 512;
18718 viewport.x = 0;
18719 viewport.y = 0;
18720 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
18721 vkEndCommandBuffer(command_buffer[0]);
18722 }
18723 {
18724 VkCommandBufferBeginInfo begin_info{};
18725 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18726 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18727
18728 VkViewport viewport{};
18729 viewport.maxDepth = 1.0f;
18730 viewport.minDepth = 0.0f;
18731 viewport.width = 512;
18732 viewport.height = 512;
18733 viewport.x = 0;
18734 viewport.y = 0;
18735 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
18736 vkEndCommandBuffer(command_buffer[1]);
18737 }
18738 {
18739 VkSubmitInfo submit_info{};
18740 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18741 submit_info.commandBufferCount = 1;
18742 submit_info.pCommandBuffers = &command_buffer[0];
18743 submit_info.signalSemaphoreCount = 1;
18744 submit_info.pSignalSemaphores = &semaphore;
18745 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
18746 }
18747 {
18748 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
18749 VkSubmitInfo submit_info{};
18750 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18751 submit_info.commandBufferCount = 1;
18752 submit_info.pCommandBuffers = &command_buffer[1];
18753 submit_info.waitSemaphoreCount = 1;
18754 submit_info.pWaitSemaphores = &semaphore;
18755 submit_info.pWaitDstStageMask = flags;
18756 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
18757 }
18758
18759 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
18760
18761 vkDestroyFence(m_device->device(), fence, nullptr);
18762 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
18763 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
18764 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18765
18766 m_errorMonitor->VerifyNotFound();
18767}
18768
18769// This is a positive test. No errors should be generated.
18770TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueWithSemaphoreAndOneFence) {
18771
18772 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
18773 "on the same queue, sharing a signal/wait semaphore, the "
18774 "second having a fence, "
18775 "followed by a WaitForFences call.");
18776
18777 m_errorMonitor->ExpectSuccess();
18778
18779 ASSERT_NO_FATAL_FAILURE(InitState());
18780 VkFence fence;
18781 VkFenceCreateInfo fence_create_info{};
18782 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18783 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
18784
18785 VkSemaphore semaphore;
18786 VkSemaphoreCreateInfo semaphore_create_info{};
18787 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
18788 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
18789
18790 VkCommandPool command_pool;
18791 VkCommandPoolCreateInfo pool_create_info{};
18792 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18793 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18794 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18795 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18796
18797 VkCommandBuffer command_buffer[2];
18798 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18799 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18800 command_buffer_allocate_info.commandPool = command_pool;
18801 command_buffer_allocate_info.commandBufferCount = 2;
18802 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18803 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18804
18805 {
18806 VkCommandBufferBeginInfo begin_info{};
18807 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18808 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18809
18810 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
18811 nullptr, 0, nullptr, 0, nullptr);
18812
18813 VkViewport viewport{};
18814 viewport.maxDepth = 1.0f;
18815 viewport.minDepth = 0.0f;
18816 viewport.width = 512;
18817 viewport.height = 512;
18818 viewport.x = 0;
18819 viewport.y = 0;
18820 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
18821 vkEndCommandBuffer(command_buffer[0]);
18822 }
18823 {
18824 VkCommandBufferBeginInfo begin_info{};
18825 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18826 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18827
18828 VkViewport viewport{};
18829 viewport.maxDepth = 1.0f;
18830 viewport.minDepth = 0.0f;
18831 viewport.width = 512;
18832 viewport.height = 512;
18833 viewport.x = 0;
18834 viewport.y = 0;
18835 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
18836 vkEndCommandBuffer(command_buffer[1]);
18837 }
18838 {
18839 VkSubmitInfo submit_info{};
18840 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18841 submit_info.commandBufferCount = 1;
18842 submit_info.pCommandBuffers = &command_buffer[0];
18843 submit_info.signalSemaphoreCount = 1;
18844 submit_info.pSignalSemaphores = &semaphore;
18845 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
18846 }
18847 {
18848 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
18849 VkSubmitInfo submit_info{};
18850 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18851 submit_info.commandBufferCount = 1;
18852 submit_info.pCommandBuffers = &command_buffer[1];
18853 submit_info.waitSemaphoreCount = 1;
18854 submit_info.pWaitSemaphores = &semaphore;
18855 submit_info.pWaitDstStageMask = flags;
18856 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
18857 }
18858
18859 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
18860
18861 vkDestroyFence(m_device->device(), fence, nullptr);
18862 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
18863 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
18864 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18865
18866 m_errorMonitor->VerifyNotFound();
18867}
18868
18869// This is a positive test. No errors should be generated.
18870TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueNullQueueSubmitWithFence) {
18871
18872 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
18873 "on the same queue, no fences, followed by a third QueueSubmit with NO "
18874 "SubmitInfos but with a fence, followed by a WaitForFences call.");
18875
18876 m_errorMonitor->ExpectSuccess();
18877
18878 ASSERT_NO_FATAL_FAILURE(InitState());
18879 VkFence fence;
18880 VkFenceCreateInfo fence_create_info{};
18881 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18882 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
18883
18884 VkCommandPool command_pool;
18885 VkCommandPoolCreateInfo pool_create_info{};
18886 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18887 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18888 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18889 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18890
18891 VkCommandBuffer command_buffer[2];
18892 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18893 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18894 command_buffer_allocate_info.commandPool = command_pool;
18895 command_buffer_allocate_info.commandBufferCount = 2;
18896 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18897 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18898
18899 {
18900 VkCommandBufferBeginInfo begin_info{};
18901 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18902 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18903
18904 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
18905 nullptr, 0, nullptr, 0, nullptr);
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[0], 0, 1, &viewport);
18915 vkEndCommandBuffer(command_buffer[0]);
18916 }
18917 {
18918 VkCommandBufferBeginInfo begin_info{};
18919 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18920 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18921
18922 VkViewport viewport{};
18923 viewport.maxDepth = 1.0f;
18924 viewport.minDepth = 0.0f;
18925 viewport.width = 512;
18926 viewport.height = 512;
18927 viewport.x = 0;
18928 viewport.y = 0;
18929 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
18930 vkEndCommandBuffer(command_buffer[1]);
18931 }
18932 {
18933 VkSubmitInfo submit_info{};
18934 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18935 submit_info.commandBufferCount = 1;
18936 submit_info.pCommandBuffers = &command_buffer[0];
18937 submit_info.signalSemaphoreCount = 0;
18938 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
18939 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
18940 }
18941 {
18942 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
18943 VkSubmitInfo submit_info{};
18944 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18945 submit_info.commandBufferCount = 1;
18946 submit_info.pCommandBuffers = &command_buffer[1];
18947 submit_info.waitSemaphoreCount = 0;
18948 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
18949 submit_info.pWaitDstStageMask = flags;
18950 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
18951 }
18952
18953 vkQueueSubmit(m_device->m_queue, 0, NULL, fence);
18954
18955 VkResult err = vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
18956 ASSERT_VK_SUCCESS(err);
18957
18958 vkDestroyFence(m_device->device(), fence, nullptr);
18959 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
18960 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18961
18962 m_errorMonitor->VerifyNotFound();
18963}
18964
18965// This is a positive test. No errors should be generated.
18966TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueOneFence) {
18967
18968 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
18969 "on the same queue, the second having a fence, followed "
18970 "by a WaitForFences call.");
18971
18972 m_errorMonitor->ExpectSuccess();
18973
18974 ASSERT_NO_FATAL_FAILURE(InitState());
18975 VkFence fence;
18976 VkFenceCreateInfo fence_create_info{};
18977 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18978 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
18979
18980 VkCommandPool command_pool;
18981 VkCommandPoolCreateInfo pool_create_info{};
18982 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18983 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18984 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18985 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18986
18987 VkCommandBuffer command_buffer[2];
18988 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18989 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18990 command_buffer_allocate_info.commandPool = command_pool;
18991 command_buffer_allocate_info.commandBufferCount = 2;
18992 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18993 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18994
18995 {
18996 VkCommandBufferBeginInfo begin_info{};
18997 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18998 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18999
19000 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
19001 nullptr, 0, nullptr, 0, nullptr);
19002
19003 VkViewport viewport{};
19004 viewport.maxDepth = 1.0f;
19005 viewport.minDepth = 0.0f;
19006 viewport.width = 512;
19007 viewport.height = 512;
19008 viewport.x = 0;
19009 viewport.y = 0;
19010 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
19011 vkEndCommandBuffer(command_buffer[0]);
19012 }
19013 {
19014 VkCommandBufferBeginInfo begin_info{};
19015 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19016 vkBeginCommandBuffer(command_buffer[1], &begin_info);
19017
19018 VkViewport viewport{};
19019 viewport.maxDepth = 1.0f;
19020 viewport.minDepth = 0.0f;
19021 viewport.width = 512;
19022 viewport.height = 512;
19023 viewport.x = 0;
19024 viewport.y = 0;
19025 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
19026 vkEndCommandBuffer(command_buffer[1]);
19027 }
19028 {
19029 VkSubmitInfo submit_info{};
19030 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19031 submit_info.commandBufferCount = 1;
19032 submit_info.pCommandBuffers = &command_buffer[0];
19033 submit_info.signalSemaphoreCount = 0;
19034 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
19035 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
19036 }
19037 {
19038 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
19039 VkSubmitInfo submit_info{};
19040 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19041 submit_info.commandBufferCount = 1;
19042 submit_info.pCommandBuffers = &command_buffer[1];
19043 submit_info.waitSemaphoreCount = 0;
19044 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
19045 submit_info.pWaitDstStageMask = flags;
19046 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
19047 }
19048
19049 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
19050
19051 vkDestroyFence(m_device->device(), fence, nullptr);
19052 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
19053 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
19054
19055 m_errorMonitor->VerifyNotFound();
19056}
19057
19058// This is a positive test. No errors should be generated.
19059TEST_F(VkPositiveLayerTest, TwoSubmitInfosWithSemaphoreOneQueueSubmitsOneFence) {
19060
19061 TEST_DESCRIPTION("Two command buffers each in a separate SubmitInfo sent in a single "
19062 "QueueSubmit call followed by a WaitForFences call.");
19063 ASSERT_NO_FATAL_FAILURE(InitState());
19064
19065 m_errorMonitor->ExpectSuccess();
19066
19067 VkFence fence;
19068 VkFenceCreateInfo fence_create_info{};
19069 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
19070 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
19071
19072 VkSemaphore semaphore;
19073 VkSemaphoreCreateInfo semaphore_create_info{};
19074 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
19075 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
19076
19077 VkCommandPool command_pool;
19078 VkCommandPoolCreateInfo pool_create_info{};
19079 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
19080 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
19081 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
19082 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
19083
19084 VkCommandBuffer command_buffer[2];
19085 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
19086 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
19087 command_buffer_allocate_info.commandPool = command_pool;
19088 command_buffer_allocate_info.commandBufferCount = 2;
19089 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
19090 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
19091
19092 {
19093 VkCommandBufferBeginInfo begin_info{};
19094 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19095 vkBeginCommandBuffer(command_buffer[0], &begin_info);
19096
19097 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
19098 nullptr, 0, nullptr, 0, nullptr);
19099
19100 VkViewport viewport{};
19101 viewport.maxDepth = 1.0f;
19102 viewport.minDepth = 0.0f;
19103 viewport.width = 512;
19104 viewport.height = 512;
19105 viewport.x = 0;
19106 viewport.y = 0;
19107 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
19108 vkEndCommandBuffer(command_buffer[0]);
19109 }
19110 {
19111 VkCommandBufferBeginInfo begin_info{};
19112 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19113 vkBeginCommandBuffer(command_buffer[1], &begin_info);
19114
19115 VkViewport viewport{};
19116 viewport.maxDepth = 1.0f;
19117 viewport.minDepth = 0.0f;
19118 viewport.width = 512;
19119 viewport.height = 512;
19120 viewport.x = 0;
19121 viewport.y = 0;
19122 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
19123 vkEndCommandBuffer(command_buffer[1]);
19124 }
19125 {
19126 VkSubmitInfo submit_info[2];
19127 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
19128
19129 submit_info[0].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19130 submit_info[0].pNext = NULL;
19131 submit_info[0].commandBufferCount = 1;
19132 submit_info[0].pCommandBuffers = &command_buffer[0];
19133 submit_info[0].signalSemaphoreCount = 1;
19134 submit_info[0].pSignalSemaphores = &semaphore;
19135 submit_info[0].waitSemaphoreCount = 0;
19136 submit_info[0].pWaitSemaphores = NULL;
19137 submit_info[0].pWaitDstStageMask = 0;
19138
19139 submit_info[1].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19140 submit_info[1].pNext = NULL;
19141 submit_info[1].commandBufferCount = 1;
19142 submit_info[1].pCommandBuffers = &command_buffer[1];
19143 submit_info[1].waitSemaphoreCount = 1;
19144 submit_info[1].pWaitSemaphores = &semaphore;
19145 submit_info[1].pWaitDstStageMask = flags;
19146 submit_info[1].signalSemaphoreCount = 0;
19147 submit_info[1].pSignalSemaphores = NULL;
19148 vkQueueSubmit(m_device->m_queue, 2, &submit_info[0], fence);
19149 }
19150
19151 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
19152
19153 vkDestroyFence(m_device->device(), fence, nullptr);
19154 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
19155 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
19156 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
19157
19158 m_errorMonitor->VerifyNotFound();
19159}
19160
19161TEST_F(VkPositiveLayerTest, RenderPassSecondaryCommandBuffersMultipleTimes) {
19162 m_errorMonitor->ExpectSuccess();
19163
19164 ASSERT_NO_FATAL_FAILURE(InitState());
19165 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19166
19167 BeginCommandBuffer(); // Framework implicitly begins the renderpass.
19168 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle()); // End implicit.
19169
19170 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
19171 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
19172 m_errorMonitor->VerifyNotFound();
19173 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
19174 m_errorMonitor->VerifyNotFound();
19175 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
19176 m_errorMonitor->VerifyNotFound();
19177
19178 m_commandBuffer->EndCommandBuffer();
19179 m_errorMonitor->VerifyNotFound();
19180}
19181
19182TEST_F(VkPositiveLayerTest, ValidRenderPassAttachmentLayoutWithLoadOp) {
19183 TEST_DESCRIPTION("Positive test where we create a renderpass with an "
19184 "attachment that uses LOAD_OP_CLEAR, the first subpass "
19185 "has a valid layout, and a second subpass then uses a "
19186 "valid *READ_ONLY* layout.");
19187 m_errorMonitor->ExpectSuccess();
19188 ASSERT_NO_FATAL_FAILURE(InitState());
19189
19190 VkAttachmentReference attach[2] = {};
19191 attach[0].attachment = 0;
19192 attach[0].layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
19193 attach[1].attachment = 0;
19194 attach[1].layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
19195 VkSubpassDescription subpasses[2] = {};
19196 // First subpass clears DS attach on load
19197 subpasses[0].pDepthStencilAttachment = &attach[0];
19198 // 2nd subpass reads in DS as input attachment
19199 subpasses[1].inputAttachmentCount = 1;
19200 subpasses[1].pInputAttachments = &attach[1];
19201 VkAttachmentDescription attach_desc = {};
19202 attach_desc.format = VK_FORMAT_D24_UNORM_S8_UINT;
19203 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
19204 attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
19205 attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
19206 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
19207 attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
19208 attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
19209 attach_desc.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
19210 VkRenderPassCreateInfo rpci = {};
19211 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
19212 rpci.attachmentCount = 1;
19213 rpci.pAttachments = &attach_desc;
19214 rpci.subpassCount = 2;
19215 rpci.pSubpasses = subpasses;
19216
19217 // Now create RenderPass and verify no errors
19218 VkRenderPass rp;
19219 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
19220 m_errorMonitor->VerifyNotFound();
19221
19222 vkDestroyRenderPass(m_device->device(), rp, NULL);
19223}
19224
19225TEST_F(VkPositiveLayerTest, CreatePipelineAttribMatrixType) {
19226 TEST_DESCRIPTION("Test that pipeline validation accepts matrices passed "
19227 "as vertex attributes");
19228 m_errorMonitor->ExpectSuccess();
19229
19230 ASSERT_NO_FATAL_FAILURE(InitState());
19231 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19232
19233 VkVertexInputBindingDescription input_binding;
19234 memset(&input_binding, 0, sizeof(input_binding));
19235
19236 VkVertexInputAttributeDescription input_attribs[2];
19237 memset(input_attribs, 0, sizeof(input_attribs));
19238
19239 for (int i = 0; i < 2; i++) {
19240 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
19241 input_attribs[i].location = i;
19242 }
19243
19244 char const *vsSource = "#version 450\n"
19245 "\n"
19246 "layout(location=0) in mat2x4 x;\n"
19247 "out gl_PerVertex {\n"
19248 " vec4 gl_Position;\n"
19249 "};\n"
19250 "void main(){\n"
19251 " gl_Position = x[0] + x[1];\n"
19252 "}\n";
19253 char const *fsSource = "#version 450\n"
19254 "\n"
19255 "layout(location=0) out vec4 color;\n"
19256 "void main(){\n"
19257 " color = vec4(1);\n"
19258 "}\n";
19259
19260 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19261 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19262
19263 VkPipelineObj pipe(m_device);
19264 pipe.AddColorAttachment();
19265 pipe.AddShader(&vs);
19266 pipe.AddShader(&fs);
19267
19268 pipe.AddVertexInputBindings(&input_binding, 1);
19269 pipe.AddVertexInputAttribs(input_attribs, 2);
19270
19271 VkDescriptorSetObj descriptorSet(m_device);
19272 descriptorSet.AppendDummy();
19273 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19274
19275 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
19276
19277 /* expect success */
19278 m_errorMonitor->VerifyNotFound();
19279}
19280
19281TEST_F(VkPositiveLayerTest, CreatePipelineAttribArrayType) {
19282 m_errorMonitor->ExpectSuccess();
19283
19284 ASSERT_NO_FATAL_FAILURE(InitState());
19285 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19286
19287 VkVertexInputBindingDescription input_binding;
19288 memset(&input_binding, 0, sizeof(input_binding));
19289
19290 VkVertexInputAttributeDescription input_attribs[2];
19291 memset(input_attribs, 0, sizeof(input_attribs));
19292
19293 for (int i = 0; i < 2; i++) {
19294 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
19295 input_attribs[i].location = i;
19296 }
19297
19298 char const *vsSource = "#version 450\n"
19299 "\n"
19300 "layout(location=0) in vec4 x[2];\n"
19301 "out gl_PerVertex {\n"
19302 " vec4 gl_Position;\n"
19303 "};\n"
19304 "void main(){\n"
19305 " gl_Position = x[0] + x[1];\n"
19306 "}\n";
19307 char const *fsSource = "#version 450\n"
19308 "\n"
19309 "layout(location=0) out vec4 color;\n"
19310 "void main(){\n"
19311 " color = vec4(1);\n"
19312 "}\n";
19313
19314 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19315 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19316
19317 VkPipelineObj pipe(m_device);
19318 pipe.AddColorAttachment();
19319 pipe.AddShader(&vs);
19320 pipe.AddShader(&fs);
19321
19322 pipe.AddVertexInputBindings(&input_binding, 1);
19323 pipe.AddVertexInputAttribs(input_attribs, 2);
19324
19325 VkDescriptorSetObj descriptorSet(m_device);
19326 descriptorSet.AppendDummy();
19327 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19328
19329 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
19330
19331 m_errorMonitor->VerifyNotFound();
19332}
19333
19334TEST_F(VkPositiveLayerTest, CreatePipelineAttribComponents) {
19335 TEST_DESCRIPTION("Test that pipeline validation accepts consuming a vertex attribute "
19336 "through multiple vertex shader inputs, each consuming a different "
19337 "subset of the components.");
19338 m_errorMonitor->ExpectSuccess();
19339
19340 ASSERT_NO_FATAL_FAILURE(InitState());
19341 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19342
19343 VkVertexInputBindingDescription input_binding;
19344 memset(&input_binding, 0, sizeof(input_binding));
19345
19346 VkVertexInputAttributeDescription input_attribs[3];
19347 memset(input_attribs, 0, sizeof(input_attribs));
19348
19349 for (int i = 0; i < 3; i++) {
19350 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
19351 input_attribs[i].location = i;
19352 }
19353
19354 char const *vsSource = "#version 450\n"
19355 "\n"
19356 "layout(location=0) in vec4 x;\n"
19357 "layout(location=1) in vec3 y1;\n"
19358 "layout(location=1, component=3) in float y2;\n"
19359 "layout(location=2) in vec4 z;\n"
19360 "out gl_PerVertex {\n"
19361 " vec4 gl_Position;\n"
19362 "};\n"
19363 "void main(){\n"
19364 " gl_Position = x + vec4(y1, y2) + z;\n"
19365 "}\n";
19366 char const *fsSource = "#version 450\n"
19367 "\n"
19368 "layout(location=0) out vec4 color;\n"
19369 "void main(){\n"
19370 " color = vec4(1);\n"
19371 "}\n";
19372
19373 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19374 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19375
19376 VkPipelineObj pipe(m_device);
19377 pipe.AddColorAttachment();
19378 pipe.AddShader(&vs);
19379 pipe.AddShader(&fs);
19380
19381 pipe.AddVertexInputBindings(&input_binding, 1);
19382 pipe.AddVertexInputAttribs(input_attribs, 3);
19383
19384 VkDescriptorSetObj descriptorSet(m_device);
19385 descriptorSet.AppendDummy();
19386 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19387
19388 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
19389
19390 m_errorMonitor->VerifyNotFound();
19391}
19392
19393TEST_F(VkPositiveLayerTest, CreatePipelineSimplePositive) {
19394 m_errorMonitor->ExpectSuccess();
19395
19396 ASSERT_NO_FATAL_FAILURE(InitState());
19397 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19398
19399 char const *vsSource = "#version 450\n"
19400 "out gl_PerVertex {\n"
19401 " vec4 gl_Position;\n"
19402 "};\n"
19403 "void main(){\n"
19404 " gl_Position = vec4(0);\n"
19405 "}\n";
19406 char const *fsSource = "#version 450\n"
19407 "\n"
19408 "layout(location=0) out vec4 color;\n"
19409 "void main(){\n"
19410 " color = vec4(1);\n"
19411 "}\n";
19412
19413 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19414 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19415
19416 VkPipelineObj pipe(m_device);
19417 pipe.AddColorAttachment();
19418 pipe.AddShader(&vs);
19419 pipe.AddShader(&fs);
19420
19421 VkDescriptorSetObj descriptorSet(m_device);
19422 descriptorSet.AppendDummy();
19423 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19424
19425 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
19426
19427 m_errorMonitor->VerifyNotFound();
19428}
19429
19430TEST_F(VkPositiveLayerTest, CreatePipelineRelaxedTypeMatch) {
19431 TEST_DESCRIPTION("Test that pipeline validation accepts the relaxed type matching rules "
19432 "set out in 14.1.3: fundamental type must match, and producer side must "
19433 "have at least as many components");
19434 m_errorMonitor->ExpectSuccess();
19435
19436 // VK 1.0.8 Specification, 14.1.3 "Additionally,..." block
19437
19438 ASSERT_NO_FATAL_FAILURE(InitState());
19439 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19440
19441 char const *vsSource = "#version 450\n"
19442 "out gl_PerVertex {\n"
19443 " vec4 gl_Position;\n"
19444 "};\n"
19445 "layout(location=0) out vec3 x;\n"
19446 "layout(location=1) out ivec3 y;\n"
19447 "layout(location=2) out vec3 z;\n"
19448 "void main(){\n"
19449 " gl_Position = vec4(0);\n"
19450 " x = vec3(0); y = ivec3(0); z = vec3(0);\n"
19451 "}\n";
19452 char const *fsSource = "#version 450\n"
19453 "\n"
19454 "layout(location=0) out vec4 color;\n"
19455 "layout(location=0) in float x;\n"
19456 "layout(location=1) flat in int y;\n"
19457 "layout(location=2) in vec2 z;\n"
19458 "void main(){\n"
19459 " color = vec4(1 + x + y + z.x);\n"
19460 "}\n";
19461
19462 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19463 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19464
19465 VkPipelineObj pipe(m_device);
19466 pipe.AddColorAttachment();
19467 pipe.AddShader(&vs);
19468 pipe.AddShader(&fs);
19469
19470 VkDescriptorSetObj descriptorSet(m_device);
19471 descriptorSet.AppendDummy();
19472 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19473
19474 VkResult err = VK_SUCCESS;
19475 err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
19476 ASSERT_VK_SUCCESS(err);
19477
19478 m_errorMonitor->VerifyNotFound();
19479}
19480
19481TEST_F(VkPositiveLayerTest, CreatePipelineTessPerVertex) {
19482 TEST_DESCRIPTION("Test that pipeline validation accepts per-vertex variables "
19483 "passed between the TCS and TES stages");
19484 m_errorMonitor->ExpectSuccess();
19485
19486 ASSERT_NO_FATAL_FAILURE(InitState());
19487 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19488
19489 if (!m_device->phy().features().tessellationShader) {
19490 printf("Device does not support tessellation shaders; skipped.\n");
19491 return;
19492 }
19493
19494 char const *vsSource = "#version 450\n"
19495 "void main(){}\n";
19496 char const *tcsSource = "#version 450\n"
19497 "layout(location=0) out int x[];\n"
19498 "layout(vertices=3) out;\n"
19499 "void main(){\n"
19500 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
19501 " gl_TessLevelInner[0] = 1;\n"
19502 " x[gl_InvocationID] = gl_InvocationID;\n"
19503 "}\n";
19504 char const *tesSource = "#version 450\n"
19505 "layout(triangles, equal_spacing, cw) in;\n"
19506 "layout(location=0) in int x[];\n"
19507 "out gl_PerVertex { vec4 gl_Position; };\n"
19508 "void main(){\n"
19509 " gl_Position.xyz = gl_TessCoord;\n"
19510 " gl_Position.w = x[0] + x[1] + x[2];\n"
19511 "}\n";
19512 char const *fsSource = "#version 450\n"
19513 "layout(location=0) out vec4 color;\n"
19514 "void main(){\n"
19515 " color = vec4(1);\n"
19516 "}\n";
19517
19518 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19519 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
19520 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
19521 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19522
19523 VkPipelineInputAssemblyStateCreateInfo iasci{ VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, nullptr, 0,
19524 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, VK_FALSE };
19525
19526 VkPipelineTessellationStateCreateInfo tsci{ VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, nullptr, 0, 3 };
19527
19528 VkPipelineObj pipe(m_device);
19529 pipe.SetInputAssembly(&iasci);
19530 pipe.SetTessellation(&tsci);
19531 pipe.AddColorAttachment();
19532 pipe.AddShader(&vs);
19533 pipe.AddShader(&tcs);
19534 pipe.AddShader(&tes);
19535 pipe.AddShader(&fs);
19536
19537 VkDescriptorSetObj descriptorSet(m_device);
19538 descriptorSet.AppendDummy();
19539 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19540
19541 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
19542
19543 m_errorMonitor->VerifyNotFound();
19544}
19545
19546TEST_F(VkPositiveLayerTest, CreatePipelineGeometryInputBlockPositive) {
19547 TEST_DESCRIPTION("Test that pipeline validation accepts a user-defined "
19548 "interface block passed into the geometry shader. This "
19549 "is interesting because the 'extra' array level is not "
19550 "present on the member type, but on the block instance.");
19551 m_errorMonitor->ExpectSuccess();
19552
19553 ASSERT_NO_FATAL_FAILURE(InitState());
19554 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19555
19556 if (!m_device->phy().features().geometryShader) {
19557 printf("Device does not support geometry shaders; skipped.\n");
19558 return;
19559 }
19560
19561 char const *vsSource = "#version 450\n"
19562 "layout(location=0) out VertexData { vec4 x; } vs_out;\n"
19563 "void main(){\n"
19564 " vs_out.x = vec4(1);\n"
19565 "}\n";
19566 char const *gsSource = "#version 450\n"
19567 "layout(triangles) in;\n"
19568 "layout(triangle_strip, max_vertices=3) out;\n"
19569 "layout(location=0) in VertexData { vec4 x; } gs_in[];\n"
19570 "out gl_PerVertex { vec4 gl_Position; };\n"
19571 "void main() {\n"
19572 " gl_Position = gs_in[0].x;\n"
19573 " EmitVertex();\n"
19574 "}\n";
19575 char const *fsSource = "#version 450\n"
19576 "layout(location=0) out vec4 color;\n"
19577 "void main(){\n"
19578 " color = vec4(1);\n"
19579 "}\n";
19580
19581 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19582 VkShaderObj gs(m_device, gsSource, VK_SHADER_STAGE_GEOMETRY_BIT, this);
19583 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19584
19585 VkPipelineObj pipe(m_device);
19586 pipe.AddColorAttachment();
19587 pipe.AddShader(&vs);
19588 pipe.AddShader(&gs);
19589 pipe.AddShader(&fs);
19590
19591 VkDescriptorSetObj descriptorSet(m_device);
19592 descriptorSet.AppendDummy();
19593 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19594
19595 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
19596
19597 m_errorMonitor->VerifyNotFound();
19598}
19599
19600TEST_F(VkPositiveLayerTest, CreatePipeline64BitAttributesPositive) {
19601 TEST_DESCRIPTION("Test that pipeline validation accepts basic use of 64bit vertex "
19602 "attributes. This is interesting because they consume multiple "
19603 "locations.");
19604 m_errorMonitor->ExpectSuccess();
19605
19606 ASSERT_NO_FATAL_FAILURE(InitState());
19607 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19608
19609 if (!m_device->phy().features().shaderFloat64) {
19610 printf("Device does not support 64bit vertex attributes; skipped.\n");
19611 return;
19612 }
19613
19614 VkVertexInputBindingDescription input_bindings[1];
19615 memset(input_bindings, 0, sizeof(input_bindings));
19616
19617 VkVertexInputAttributeDescription input_attribs[4];
19618 memset(input_attribs, 0, sizeof(input_attribs));
19619 input_attribs[0].location = 0;
19620 input_attribs[0].offset = 0;
19621 input_attribs[0].format = VK_FORMAT_R64G64B64A64_SFLOAT;
19622 input_attribs[1].location = 2;
19623 input_attribs[1].offset = 32;
19624 input_attribs[1].format = VK_FORMAT_R64G64B64A64_SFLOAT;
19625 input_attribs[2].location = 4;
19626 input_attribs[2].offset = 64;
19627 input_attribs[2].format = VK_FORMAT_R64G64B64A64_SFLOAT;
19628 input_attribs[3].location = 6;
19629 input_attribs[3].offset = 96;
19630 input_attribs[3].format = VK_FORMAT_R64G64B64A64_SFLOAT;
19631
19632 char const *vsSource = "#version 450\n"
19633 "\n"
19634 "layout(location=0) in dmat4 x;\n"
19635 "out gl_PerVertex {\n"
19636 " vec4 gl_Position;\n"
19637 "};\n"
19638 "void main(){\n"
19639 " gl_Position = vec4(x[0][0]);\n"
19640 "}\n";
19641 char const *fsSource = "#version 450\n"
19642 "\n"
19643 "layout(location=0) out vec4 color;\n"
19644 "void main(){\n"
19645 " color = vec4(1);\n"
19646 "}\n";
19647
19648 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19649 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19650
19651 VkPipelineObj pipe(m_device);
19652 pipe.AddColorAttachment();
19653 pipe.AddShader(&vs);
19654 pipe.AddShader(&fs);
19655
19656 pipe.AddVertexInputBindings(input_bindings, 1);
19657 pipe.AddVertexInputAttribs(input_attribs, 4);
19658
19659 VkDescriptorSetObj descriptorSet(m_device);
19660 descriptorSet.AppendDummy();
19661 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19662
19663 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
19664
19665 m_errorMonitor->VerifyNotFound();
19666}
19667
19668TEST_F(VkPositiveLayerTest, CreatePipelineInputAttachmentPositive) {
19669 TEST_DESCRIPTION("Positive test for a correctly matched input attachment");
19670 m_errorMonitor->ExpectSuccess();
19671
19672 ASSERT_NO_FATAL_FAILURE(InitState());
19673
19674 char const *vsSource = "#version 450\n"
19675 "\n"
19676 "out gl_PerVertex {\n"
19677 " vec4 gl_Position;\n"
19678 "};\n"
19679 "void main(){\n"
19680 " gl_Position = vec4(1);\n"
19681 "}\n";
19682 char const *fsSource = "#version 450\n"
19683 "\n"
19684 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
19685 "layout(location=0) out vec4 color;\n"
19686 "void main() {\n"
19687 " color = subpassLoad(x);\n"
19688 "}\n";
19689
19690 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19691 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19692
19693 VkPipelineObj pipe(m_device);
19694 pipe.AddShader(&vs);
19695 pipe.AddShader(&fs);
19696 pipe.AddColorAttachment();
19697 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19698
19699 VkDescriptorSetLayoutBinding dslb = { 0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr };
19700 VkDescriptorSetLayoutCreateInfo dslci = { VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb };
19701 VkDescriptorSetLayout dsl;
19702 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
19703 ASSERT_VK_SUCCESS(err);
19704
19705 VkPipelineLayoutCreateInfo plci = { VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr };
19706 VkPipelineLayout pl;
19707 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
19708 ASSERT_VK_SUCCESS(err);
19709
19710 VkAttachmentDescription descs[2] = {
19711 { 0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
19712 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
19713 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL },
19714 { 0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
19715 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_GENERAL, VK_IMAGE_LAYOUT_GENERAL },
19716 };
19717 VkAttachmentReference color = {
19718 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
19719 };
19720 VkAttachmentReference input = {
19721 1, VK_IMAGE_LAYOUT_GENERAL,
19722 };
19723
19724 VkSubpassDescription sd = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 1, &input, 1, &color, nullptr, nullptr, 0, nullptr };
19725
19726 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, descs, 1, &sd, 0, nullptr };
19727 VkRenderPass rp;
19728 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
19729 ASSERT_VK_SUCCESS(err);
19730
19731 // should be OK. would go wrong here if it's going to...
19732 pipe.CreateVKPipeline(pl, rp);
19733
19734 m_errorMonitor->VerifyNotFound();
19735
19736 vkDestroyRenderPass(m_device->device(), rp, nullptr);
19737 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
19738 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
19739}
19740
19741TEST_F(VkPositiveLayerTest, CreateComputePipelineMissingDescriptorUnusedPositive) {
19742 TEST_DESCRIPTION("Test that pipeline validation accepts a compute pipeline which declares a "
19743 "descriptor-backed resource which is not provided, but the shader does not "
19744 "statically use it. This is interesting because it requires compute pipelines "
19745 "to have a proper descriptor use walk, which they didn't for some time.");
19746 m_errorMonitor->ExpectSuccess();
19747
19748 ASSERT_NO_FATAL_FAILURE(InitState());
19749
19750 char const *csSource = "#version 450\n"
19751 "\n"
19752 "layout(local_size_x=1) in;\n"
19753 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
19754 "void main(){\n"
19755 " // x is not used.\n"
19756 "}\n";
19757
19758 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
19759
19760 VkDescriptorSetObj descriptorSet(m_device);
19761 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19762
19763 VkComputePipelineCreateInfo cpci = { VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
19764 nullptr,
19765 0,
19766 { VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
19767 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr },
19768 descriptorSet.GetPipelineLayout(),
19769 VK_NULL_HANDLE,
19770 -1 };
19771
19772 VkPipeline pipe;
19773 VkResult err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
19774
19775 m_errorMonitor->VerifyNotFound();
19776
19777 if (err == VK_SUCCESS) {
19778 vkDestroyPipeline(m_device->device(), pipe, nullptr);
19779 }
19780}
19781
19782TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsSampler) {
19783 TEST_DESCRIPTION("Test that pipeline validation accepts a shader consuming only the "
19784 "sampler portion of a combined image + sampler");
19785 m_errorMonitor->ExpectSuccess();
19786
19787 ASSERT_NO_FATAL_FAILURE(InitState());
19788
19789 VkDescriptorSetLayoutBinding bindings[] = {
19790 { 0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
19791 { 1, VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
19792 { 2, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
19793 };
19794 VkDescriptorSetLayoutCreateInfo dslci = { VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 3, bindings };
19795 VkDescriptorSetLayout dsl;
19796 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
19797 ASSERT_VK_SUCCESS(err);
19798
19799 VkPipelineLayoutCreateInfo plci = { VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr };
19800 VkPipelineLayout pl;
19801 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
19802 ASSERT_VK_SUCCESS(err);
19803
19804 char const *csSource = "#version 450\n"
19805 "\n"
19806 "layout(local_size_x=1) in;\n"
19807 "layout(set=0, binding=0) uniform sampler s;\n"
19808 "layout(set=0, binding=1) uniform texture2D t;\n"
19809 "layout(set=0, binding=2) buffer block { vec4 x; };\n"
19810 "void main() {\n"
19811 " x = texture(sampler2D(t, s), vec2(0));\n"
19812 "}\n";
19813 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
19814
19815 VkComputePipelineCreateInfo cpci = { VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
19816 nullptr,
19817 0,
19818 { VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
19819 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr },
19820 pl,
19821 VK_NULL_HANDLE,
19822 -1 };
19823
19824 VkPipeline pipe;
19825 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
19826
19827 m_errorMonitor->VerifyNotFound();
19828
19829 if (err == VK_SUCCESS) {
19830 vkDestroyPipeline(m_device->device(), pipe, nullptr);
19831 }
19832
19833 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
19834 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
19835}
19836
19837TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsImage) {
19838 TEST_DESCRIPTION("Test that pipeline validation accepts a shader consuming only the "
19839 "image portion of a combined image + sampler");
19840 m_errorMonitor->ExpectSuccess();
19841
19842 ASSERT_NO_FATAL_FAILURE(InitState());
19843
19844 VkDescriptorSetLayoutBinding bindings[] = {
19845 { 0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
19846 { 1, VK_DESCRIPTOR_TYPE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
19847 { 2, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
19848 };
19849 VkDescriptorSetLayoutCreateInfo dslci = { VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 3, bindings };
19850 VkDescriptorSetLayout dsl;
19851 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
19852 ASSERT_VK_SUCCESS(err);
19853
19854 VkPipelineLayoutCreateInfo plci = { VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr };
19855 VkPipelineLayout pl;
19856 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
19857 ASSERT_VK_SUCCESS(err);
19858
19859 char const *csSource = "#version 450\n"
19860 "\n"
19861 "layout(local_size_x=1) in;\n"
19862 "layout(set=0, binding=0) uniform texture2D t;\n"
19863 "layout(set=0, binding=1) uniform sampler s;\n"
19864 "layout(set=0, binding=2) buffer block { vec4 x; };\n"
19865 "void main() {\n"
19866 " x = texture(sampler2D(t, s), vec2(0));\n"
19867 "}\n";
19868 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
19869
19870 VkComputePipelineCreateInfo cpci = { VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
19871 nullptr,
19872 0,
19873 { VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
19874 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr },
19875 pl,
19876 VK_NULL_HANDLE,
19877 -1 };
19878
19879 VkPipeline pipe;
19880 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
19881
19882 m_errorMonitor->VerifyNotFound();
19883
19884 if (err == VK_SUCCESS) {
19885 vkDestroyPipeline(m_device->device(), pipe, nullptr);
19886 }
19887
19888 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
19889 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
19890}
19891
19892TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsBoth) {
19893 TEST_DESCRIPTION("Test that pipeline validation accepts a shader consuming "
19894 "both the sampler and the image of a combined image+sampler "
19895 "but via separate variables");
19896 m_errorMonitor->ExpectSuccess();
19897
19898 ASSERT_NO_FATAL_FAILURE(InitState());
19899
19900 VkDescriptorSetLayoutBinding bindings[] = {
19901 { 0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
19902 { 1, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
19903 };
19904 VkDescriptorSetLayoutCreateInfo dslci = { VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 2, bindings };
19905 VkDescriptorSetLayout dsl;
19906 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
19907 ASSERT_VK_SUCCESS(err);
19908
19909 VkPipelineLayoutCreateInfo plci = { VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr };
19910 VkPipelineLayout pl;
19911 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
19912 ASSERT_VK_SUCCESS(err);
19913
19914 char const *csSource = "#version 450\n"
19915 "\n"
19916 "layout(local_size_x=1) in;\n"
19917 "layout(set=0, binding=0) uniform texture2D t;\n"
19918 "layout(set=0, binding=0) uniform sampler s; // both binding 0!\n"
19919 "layout(set=0, binding=1) buffer block { vec4 x; };\n"
19920 "void main() {\n"
19921 " x = texture(sampler2D(t, s), vec2(0));\n"
19922 "}\n";
19923 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
19924
19925 VkComputePipelineCreateInfo cpci = { VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
19926 nullptr,
19927 0,
19928 { VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
19929 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr },
19930 pl,
19931 VK_NULL_HANDLE,
19932 -1 };
19933
19934 VkPipeline pipe;
19935 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
19936
19937 m_errorMonitor->VerifyNotFound();
19938
19939 if (err == VK_SUCCESS) {
19940 vkDestroyPipeline(m_device->device(), pipe, nullptr);
19941 }
19942
19943 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
19944 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
19945}
19946
19947TEST_F(VkPositiveLayerTest, ValidStructPNext) {
19948 TEST_DESCRIPTION("Verify that a valid pNext value is handled correctly");
19949
19950 ASSERT_NO_FATAL_FAILURE(InitState());
19951
19952 // Positive test to check parameter_validation and unique_objects support
19953 // for NV_dedicated_allocation
19954 uint32_t extension_count = 0;
19955 bool supports_nv_dedicated_allocation = false;
19956 VkResult err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, nullptr);
19957 ASSERT_VK_SUCCESS(err);
19958
19959 if (extension_count > 0) {
19960 std::vector<VkExtensionProperties> available_extensions(extension_count);
19961
19962 err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, &available_extensions[0]);
19963 ASSERT_VK_SUCCESS(err);
19964
19965 for (const auto &extension_props : available_extensions) {
19966 if (strcmp(extension_props.extensionName, VK_NV_DEDICATED_ALLOCATION_EXTENSION_NAME) == 0) {
19967 supports_nv_dedicated_allocation = true;
19968 }
19969 }
19970 }
19971
19972 if (supports_nv_dedicated_allocation) {
19973 m_errorMonitor->ExpectSuccess();
19974
19975 VkDedicatedAllocationBufferCreateInfoNV dedicated_buffer_create_info = {};
19976 dedicated_buffer_create_info.sType = VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_BUFFER_CREATE_INFO_NV;
19977 dedicated_buffer_create_info.pNext = nullptr;
19978 dedicated_buffer_create_info.dedicatedAllocation = VK_TRUE;
19979
19980 uint32_t queue_family_index = 0;
19981 VkBufferCreateInfo buffer_create_info = {};
19982 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
19983 buffer_create_info.pNext = &dedicated_buffer_create_info;
19984 buffer_create_info.size = 1024;
19985 buffer_create_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
19986 buffer_create_info.queueFamilyIndexCount = 1;
19987 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
19988
19989 VkBuffer buffer;
19990 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
19991 ASSERT_VK_SUCCESS(err);
19992
19993 VkMemoryRequirements memory_reqs;
19994 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
19995
19996 VkDedicatedAllocationMemoryAllocateInfoNV dedicated_memory_info = {};
19997 dedicated_memory_info.sType = VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_MEMORY_ALLOCATE_INFO_NV;
19998 dedicated_memory_info.pNext = nullptr;
19999 dedicated_memory_info.buffer = buffer;
20000 dedicated_memory_info.image = VK_NULL_HANDLE;
20001
20002 VkMemoryAllocateInfo memory_info = {};
20003 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
20004 memory_info.pNext = &dedicated_memory_info;
20005 memory_info.allocationSize = memory_reqs.size;
20006
20007 bool pass;
20008 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
20009 ASSERT_TRUE(pass);
20010
20011 VkDeviceMemory buffer_memory;
20012 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
20013 ASSERT_VK_SUCCESS(err);
20014
20015 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
20016 ASSERT_VK_SUCCESS(err);
20017
20018 vkDestroyBuffer(m_device->device(), buffer, NULL);
20019 vkFreeMemory(m_device->device(), buffer_memory, NULL);
20020
20021 m_errorMonitor->VerifyNotFound();
20022 }
20023}
20024
20025TEST_F(VkPositiveLayerTest, PSOPolygonModeValid) {
20026 VkResult err;
20027
20028 TEST_DESCRIPTION("Verify that using a solid polygon fill mode works correctly.");
20029
20030 ASSERT_NO_FATAL_FAILURE(InitState());
20031 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
20032
20033 std::vector<const char *> device_extension_names;
20034 auto features = m_device->phy().features();
20035 // Artificially disable support for non-solid fill modes
20036 features.fillModeNonSolid = false;
20037 // The sacrificial device object
20038 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
20039
20040 VkRenderpassObj render_pass(&test_device);
20041
20042 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
20043 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
20044 pipeline_layout_ci.setLayoutCount = 0;
20045 pipeline_layout_ci.pSetLayouts = NULL;
20046
20047 VkPipelineLayout pipeline_layout;
20048 err = vkCreatePipelineLayout(test_device.device(), &pipeline_layout_ci, NULL, &pipeline_layout);
20049 ASSERT_VK_SUCCESS(err);
20050
20051 VkPipelineRasterizationStateCreateInfo rs_ci = {};
20052 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
20053 rs_ci.pNext = nullptr;
20054 rs_ci.lineWidth = 1.0f;
20055 rs_ci.rasterizerDiscardEnable = true;
20056
20057 VkShaderObj vs(&test_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
20058 VkShaderObj fs(&test_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
20059
20060 // Set polygonMode=FILL. No error is expected
20061 m_errorMonitor->ExpectSuccess();
20062 {
20063 VkPipelineObj pipe(&test_device);
20064 pipe.AddShader(&vs);
20065 pipe.AddShader(&fs);
20066 pipe.AddColorAttachment();
20067 // Set polygonMode to a good value
20068 rs_ci.polygonMode = VK_POLYGON_MODE_FILL;
20069 pipe.SetRasterization(&rs_ci);
20070 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
20071 }
20072 m_errorMonitor->VerifyNotFound();
20073
20074 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, NULL);
20075}
20076
20077TEST_F(VkPositiveLayerTest, ValidPushConstants) {
20078 VkResult err;
20079 ASSERT_NO_FATAL_FAILURE(InitState());
20080 ASSERT_NO_FATAL_FAILURE(InitViewport());
20081 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
20082
20083 VkPipelineLayout pipeline_layout;
20084 VkPushConstantRange pc_range = {};
20085 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
20086 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
20087 pipeline_layout_ci.pushConstantRangeCount = 1;
20088 pipeline_layout_ci.pPushConstantRanges = &pc_range;
20089
20090 //
20091 // Check for invalid push constant ranges in pipeline layouts.
20092 //
20093 struct PipelineLayoutTestCase {
20094 VkPushConstantRange const range;
20095 char const *msg;
20096 };
20097
20098 // Check for overlapping ranges
20099 const uint32_t ranges_per_test = 5;
20100 struct OverlappingRangeTestCase {
20101 VkPushConstantRange const ranges[ranges_per_test];
20102 char const *msg;
20103 };
20104
20105 // Run some positive tests to make sure overlap checking in the layer is OK
20106 const std::array<OverlappingRangeTestCase, 2> overlapping_range_tests_pos = { { { { { VK_SHADER_STAGE_VERTEX_BIT, 0, 4 },
20107 { VK_SHADER_STAGE_VERTEX_BIT, 4, 4 },
20108 { VK_SHADER_STAGE_VERTEX_BIT, 8, 4 },
20109 { VK_SHADER_STAGE_VERTEX_BIT, 12, 4 },
20110 { VK_SHADER_STAGE_VERTEX_BIT, 16, 4 } },
20111 "" },
20112 { { { VK_SHADER_STAGE_VERTEX_BIT, 92, 24 },
20113 { VK_SHADER_STAGE_VERTEX_BIT, 80, 4 },
20114 { VK_SHADER_STAGE_VERTEX_BIT, 64, 8 },
20115 { VK_SHADER_STAGE_VERTEX_BIT, 4, 16 },
20116 { VK_SHADER_STAGE_VERTEX_BIT, 0, 4 } },
20117 "" } } };
20118 for (const auto &iter : overlapping_range_tests_pos) {
20119 pipeline_layout_ci.pPushConstantRanges = iter.ranges;
20120 m_errorMonitor->ExpectSuccess();
20121 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
20122 m_errorMonitor->VerifyNotFound();
20123 if (VK_SUCCESS == err) {
20124 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
20125 }
20126 }
20127
20128 //
20129 // CmdPushConstants tests
20130 //
20131 const uint8_t dummy_values[100] = {};
20132
20133 BeginCommandBuffer();
20134
20135 // positive overlapping range tests with cmd
20136 const std::array<PipelineLayoutTestCase, 4> cmd_overlap_tests_pos = { {
20137 { { VK_SHADER_STAGE_VERTEX_BIT, 0, 16 }, "" },
20138 { { VK_SHADER_STAGE_VERTEX_BIT, 0, 4 }, "" },
20139 { { VK_SHADER_STAGE_VERTEX_BIT, 20, 12 }, "" },
20140 { { VK_SHADER_STAGE_VERTEX_BIT, 56, 36 }, "" },
20141 } };
20142
20143 // Setup ranges: [0,16) [20,36) [36,44) [44,52) [56,80) [80,92)
20144 const VkPushConstantRange pc_range4[] = {
20145 { VK_SHADER_STAGE_VERTEX_BIT, 20, 16 },{ VK_SHADER_STAGE_VERTEX_BIT, 0, 16 },{ VK_SHADER_STAGE_VERTEX_BIT, 44, 8 },
20146 { VK_SHADER_STAGE_VERTEX_BIT, 80, 12 },{ VK_SHADER_STAGE_VERTEX_BIT, 36, 8 },{ VK_SHADER_STAGE_VERTEX_BIT, 56, 24 },
20147 };
20148
20149 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range4) / sizeof(VkPushConstantRange);
20150 pipeline_layout_ci.pPushConstantRanges = pc_range4;
20151 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
20152 ASSERT_VK_SUCCESS(err);
20153 for (const auto &iter : cmd_overlap_tests_pos) {
20154 m_errorMonitor->ExpectSuccess();
20155 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.range.stageFlags, iter.range.offset,
20156 iter.range.size, dummy_values);
20157 m_errorMonitor->VerifyNotFound();
20158 }
20159 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
20160
20161 EndCommandBuffer();
20162}
20163
20164
20165
20166
20167
20168
20169
20170#if 0 // A few devices have issues with this test so disabling for now
20171TEST_F(VkPositiveLayerTest, LongFenceChain)
20172{
20173 m_errorMonitor->ExpectSuccess();
20174
20175 ASSERT_NO_FATAL_FAILURE(InitState());
20176 VkResult err;
20177
20178 std::vector<VkFence> fences;
20179
20180 const int chainLength = 32768;
20181
20182 for (int i = 0; i < chainLength; i++) {
20183 VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
20184 VkFence fence;
20185 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
20186 ASSERT_VK_SUCCESS(err);
20187
20188 fences.push_back(fence);
20189
20190 VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr,
20191 0, nullptr, 0, nullptr };
20192 err = vkQueueSubmit(m_device->m_queue, 1, &si, fence);
20193 ASSERT_VK_SUCCESS(err);
20194
20195 }
20196
20197 // BOOM, stack overflow.
20198 vkWaitForFences(m_device->device(), 1, &fences.back(), VK_TRUE, UINT64_MAX);
20199
20200 for (auto fence : fences)
20201 vkDestroyFence(m_device->device(), fence, nullptr);
20202
20203 m_errorMonitor->VerifyNotFound();
20204}
20205#endif
20206
20207
Cody Northrop1242dfd2016-07-13 17:24:59 -060020208#if defined(ANDROID) && defined(VALIDATION_APK)
20209static bool initialized = false;
20210static bool active = false;
20211
20212// Convert Intents to argv
20213// Ported from Hologram sample, only difference is flexible key
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020214std::vector<std::string> get_args(android_app &app, const char *intent_extra_data_key) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060020215 std::vector<std::string> args;
20216 JavaVM &vm = *app.activity->vm;
20217 JNIEnv *p_env;
20218 if (vm.AttachCurrentThread(&p_env, nullptr) != JNI_OK)
20219 return args;
20220
20221 JNIEnv &env = *p_env;
20222 jobject activity = app.activity->clazz;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020223 jmethodID get_intent_method = env.GetMethodID(env.GetObjectClass(activity), "getIntent", "()Landroid/content/Intent;");
Cody Northrop1242dfd2016-07-13 17:24:59 -060020224 jobject intent = env.CallObjectMethod(activity, get_intent_method);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020225 jmethodID get_string_extra_method =
20226 env.GetMethodID(env.GetObjectClass(intent), "getStringExtra", "(Ljava/lang/String;)Ljava/lang/String;");
Cody Northrop1242dfd2016-07-13 17:24:59 -060020227 jvalue get_string_extra_args;
20228 get_string_extra_args.l = env.NewStringUTF(intent_extra_data_key);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020229 jstring extra_str = static_cast<jstring>(env.CallObjectMethodA(intent, get_string_extra_method, &get_string_extra_args));
Cody Northrop1242dfd2016-07-13 17:24:59 -060020230
20231 std::string args_str;
20232 if (extra_str) {
20233 const char *extra_utf = env.GetStringUTFChars(extra_str, nullptr);
20234 args_str = extra_utf;
20235 env.ReleaseStringUTFChars(extra_str, extra_utf);
20236 env.DeleteLocalRef(extra_str);
20237 }
20238
20239 env.DeleteLocalRef(get_string_extra_args.l);
20240 env.DeleteLocalRef(intent);
20241 vm.DetachCurrentThread();
20242
20243 // split args_str
20244 std::stringstream ss(args_str);
20245 std::string arg;
20246 while (std::getline(ss, arg, ' ')) {
20247 if (!arg.empty())
20248 args.push_back(arg);
20249 }
20250
20251 return args;
20252}
20253
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020254static int32_t processInput(struct android_app *app, AInputEvent *event) { return 0; }
Cody Northrop1242dfd2016-07-13 17:24:59 -060020255
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020256static void processCommand(struct android_app *app, int32_t cmd) {
20257 switch (cmd) {
20258 case APP_CMD_INIT_WINDOW: {
20259 if (app->window) {
20260 initialized = true;
Cody Northrop1242dfd2016-07-13 17:24:59 -060020261 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020262 break;
20263 }
20264 case APP_CMD_GAINED_FOCUS: {
20265 active = true;
20266 break;
20267 }
20268 case APP_CMD_LOST_FOCUS: {
20269 active = false;
20270 break;
20271 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060020272 }
20273}
20274
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020275void android_main(struct android_app *app) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060020276 app_dummy();
20277
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020278 const char *appTag = "VulkanLayerValidationTests";
Cody Northrop1242dfd2016-07-13 17:24:59 -060020279
20280 int vulkanSupport = InitVulkan();
20281 if (vulkanSupport == 0) {
20282 __android_log_print(ANDROID_LOG_INFO, appTag, "==== FAILED ==== No Vulkan support found");
20283 return;
20284 }
20285
20286 app->onAppCmd = processCommand;
20287 app->onInputEvent = processInput;
20288
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020289 while (1) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060020290 int events;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020291 struct android_poll_source *source;
20292 while (ALooper_pollAll(active ? 0 : -1, NULL, &events, (void **)&source) >= 0) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060020293 if (source) {
20294 source->process(app, source);
20295 }
20296
20297 if (app->destroyRequested != 0) {
20298 VkTestFramework::Finish();
20299 return;
20300 }
20301 }
20302
20303 if (initialized && active) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020304 // Use the following key to send arguments to gtest, i.e.
20305 // --es args "--gtest_filter=-VkLayerTest.foo"
20306 const char key[] = "args";
20307 std::vector<std::string> args = get_args(*app, key);
Cody Northrop1242dfd2016-07-13 17:24:59 -060020308
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020309 std::string filter = "";
20310 if (args.size() > 0) {
20311 __android_log_print(ANDROID_LOG_INFO, appTag, "Intent args = %s", args[0].c_str());
20312 filter += args[0];
20313 } else {
20314 __android_log_print(ANDROID_LOG_INFO, appTag, "No Intent args detected");
20315 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060020316
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020317 int argc = 2;
20318 char *argv[] = {(char *)"foo", (char *)filter.c_str()};
20319 __android_log_print(ANDROID_LOG_DEBUG, appTag, "filter = %s", argv[1]);
Cody Northrop1242dfd2016-07-13 17:24:59 -060020320
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020321 // Route output to files until we can override the gtest output
20322 freopen("/sdcard/Android/data/com.example.VulkanLayerValidationTests/files/out.txt", "w", stdout);
20323 freopen("/sdcard/Android/data/com.example.VulkanLayerValidationTests/files/err.txt", "w", stderr);
Cody Northrop1242dfd2016-07-13 17:24:59 -060020324
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020325 ::testing::InitGoogleTest(&argc, argv);
20326 VkTestFramework::InitArgs(&argc, argv);
20327 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
Cody Northrop1242dfd2016-07-13 17:24:59 -060020328
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020329 int result = RUN_ALL_TESTS();
Cody Northrop1242dfd2016-07-13 17:24:59 -060020330
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020331 if (result != 0) {
20332 __android_log_print(ANDROID_LOG_INFO, appTag, "==== Tests FAILED ====");
20333 } else {
20334 __android_log_print(ANDROID_LOG_INFO, appTag, "==== Tests PASSED ====");
20335 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060020336
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020337 VkTestFramework::Finish();
Cody Northrop1242dfd2016-07-13 17:24:59 -060020338
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020339 fclose(stdout);
20340 fclose(stderr);
Cody Northrop1242dfd2016-07-13 17:24:59 -060020341
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020342 ANativeActivity_finish(app->activity);
Cody Northrop1242dfd2016-07-13 17:24:59 -060020343
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020344 return;
Cody Northrop1242dfd2016-07-13 17:24:59 -060020345 }
20346 }
20347}
20348#endif
20349
Tony Barbour300a6082015-04-07 13:44:53 -060020350int main(int argc, char **argv) {
20351 int result;
20352
Cody Northrop8e54a402016-03-08 22:25:52 -070020353#ifdef ANDROID
20354 int vulkanSupport = InitVulkan();
20355 if (vulkanSupport == 0)
20356 return 1;
20357#endif
20358
Tony Barbour300a6082015-04-07 13:44:53 -060020359 ::testing::InitGoogleTest(&argc, argv);
Tony Barbour6918cd52015-04-09 12:58:51 -060020360 VkTestFramework::InitArgs(&argc, argv);
Tony Barbour300a6082015-04-07 13:44:53 -060020361
20362 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
20363
20364 result = RUN_ALL_TESTS();
20365
Tony Barbour6918cd52015-04-09 12:58:51 -060020366 VkTestFramework::Finish();
Tony Barbour300a6082015-04-07 13:44:53 -060020367 return result;
20368}